https://bugzilla.redhat.com/show_bug.cgi?id=1581670
During storage driver backend initialization, let's save
which backends are available in the storage pool capabilities.
In order to format those, we need add a connectGetCapabilities
processor to the storageHypervisorDriver. This allows a storage
connection, such as "storage:///system" to find the API and
format the results.
NB: This is not available from other hypervisor drivers such as
QEMU type connections.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/virstorageobj.h | 4 ++++
src/storage/storage_backend.c | 16 ++++++++++++++++
src/storage/storage_backend.h | 3 +++
src/storage/storage_driver.c | 17 +++++++++++++++++
4 files changed, 40 insertions(+)
diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h
index 1106aa71bd..34adc26df3 100644
--- a/src/conf/virstorageobj.h
+++ b/src/conf/virstorageobj.h
@@ -24,6 +24,8 @@
# include "storage_conf.h"
+# include "capabilities.h"
+
typedef struct _virStoragePoolObj virStoragePoolObj;
typedef virStoragePoolObj *virStoragePoolObjPtr;
@@ -45,6 +47,8 @@ struct _virStorageDriverState {
/* Immutable pointer, self-locking APIs */
virObjectEventStatePtr storageEventState;
+
+ virCapsPtr caps;
};
typedef bool
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index a54c338cf0..0ccc616db4 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -187,3 +187,19 @@ virStorageBackendForType(int type)
type, NULLSTR(virStoragePoolTypeToString(type)));
return NULL;
}
+
+
+virCapsPtr
+virStorageBackendGetCapabilities(void)
+{
+ virCapsPtr caps;
+ size_t i;
+
+ if (!(caps = virCapabilitiesNew(virArchFromHost(), false, false)))
+ return NULL;
+
+ for (i = 0; i < virStorageBackendsCount; i++)
+ virCapabilitiesAddStoragePool(caps, virStorageBackends[i]->type);
+
+ return caps;
+}
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index 2b178494ae..c670c66287 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -126,4 +126,7 @@ int virStorageBackendDriversRegister(bool allmodules);
int virStorageBackendRegister(virStorageBackendPtr backend);
+virCapsPtr
+virStorageBackendGetCapabilities(void);
+
#endif /* LIBVIRT_STORAGE_BACKEND_H */
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 4a13e90481..04beff6b07 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -300,6 +300,9 @@ storageStateInitialize(bool privileged,
driver->storageEventState = virObjectEventStateNew();
+ if (!(driver->caps = virStorageBackendGetCapabilities()))
+ goto error;
+
storageDriverUnlock();
ret = 0;
@@ -368,6 +371,7 @@ storageStateCleanup(void)
storageDriverLock();
+ virObjectUnref(driver->caps);
virObjectUnref(driver->storageEventState);
/* free inactive pools */
@@ -577,6 +581,18 @@ storageConnectListStoragePools(virConnectPtr conn,
names, maxnames);
}
+
+static char *
+storageConnectGetCapabilities(virConnectPtr conn)
+{
+
+ if (virConnectGetCapabilitiesEnsureACL(conn) < 0)
+ return NULL;
+
+ return virCapabilitiesFormatXML(driver->caps);
+}
+
+
static int
storageConnectNumOfDefinedStoragePools(virConnectPtr conn)
{
@@ -2850,6 +2866,7 @@ static virHypervisorDriver storageHypervisorDriver = {
.connectIsEncrypted = storageConnectIsEncrypted, /* 4.1.0 */
.connectIsSecure = storageConnectIsSecure, /* 4.1.0 */
.connectIsAlive = storageConnectIsAlive, /* 4.1.0 */
+ .connectGetCapabilities = storageConnectGetCapabilities, /* 5.1.0 */
};
static virConnectDriver storageConnectDriver = {
--
2.20.1