]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Process storage pool capabilities
authorJohn Ferlan <jferlan@redhat.com>
Thu, 10 Jan 2019 12:23:26 +0000 (07:23 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 6 Mar 2019 16:12:48 +0000 (11:12 -0500)
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, such as:

  virsh -c storage:///system capabilities

  <capabilities>

    <pool>
      <enum name='type'>
        <value>dir</value>
        <value>fs</value>
        <value>netfs</value>
        <value>logical</value>
        <value>iscsi</value>
        <value>iscsi-direct</value>
        <value>scsi</value>
        <value>mpath</value>
        <value>disk</value>
        <value>rbd</value>
        <value>sheepdog</value>
        <value>gluster</value>
        <value>zfs</value>
      </enum>
    </pool>

  </capabilities>

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/virstorageobj.h
src/storage/storage_backend.c
src/storage/storage_backend.h
src/storage/storage_driver.c

index 1106aa71bdcc8e80d1a6fa059dccf679aeb408a4..c41d4c16ad5a9d8f253f306c6aa6f1702a99ee16 100644 (file)
@@ -24,6 +24,8 @@
 
 # include "storage_conf.h"
 
+# include "capabilities.h"
+
 typedef struct _virStoragePoolObj virStoragePoolObj;
 typedef virStoragePoolObj *virStoragePoolObjPtr;
 
@@ -45,6 +47,9 @@ struct _virStorageDriverState {
 
     /* Immutable pointer, self-locking APIs */
     virObjectEventStatePtr storageEventState;
+
+    /* Immutable pointer, read only after initialized */
+    virCapsPtr caps;
 };
 
 typedef bool
index 5c8275e978e3b41b928a00dd3d7c573c1934dcd8..295d8de4796b72f6c979b9c282cf2ef0f4303d5d 100644 (file)
@@ -182,3 +182,19 @@ virStorageBackendForType(int type)
                    type, NULLSTR(virStoragePoolTypeToString(type)));
     return NULL;
 }
+
+
+virCapsPtr
+virStorageBackendGetCapabilities(void)
+{
+    virCapsPtr caps;
+    size_t i;
+
+    if (!(caps = virCapabilitiesNew(VIR_ARCH_NONE, false, false)))
+        return NULL;
+
+    for (i = 0; i < virStorageBackendsCount; i++)
+        virCapabilitiesAddStoragePool(caps, virStorageBackends[i]->type);
+
+    return caps;
+}
index 2b178494ae31c1f9ddad44aab30051d0f1f29699..c670c66287ac06e151250be65450ee9dee3d7728 100644 (file)
@@ -126,4 +126,7 @@ int virStorageBackendDriversRegister(bool allmodules);
 
 int virStorageBackendRegister(virStorageBackendPtr backend);
 
+virCapsPtr
+virStorageBackendGetCapabilities(void);
+
 #endif /* LIBVIRT_STORAGE_BACKEND_H */
index 98be43400554d572b7c31d18c9348e5943ab9a3c..caa255dd3da9bc3f77a3c10717151fde2a089a81 100644 (file)
@@ -298,6 +298,12 @@ storageStateInitialize(bool privileged,
 
     driver->storageEventState = virObjectEventStateNew();
 
+    /* Only one load of storage driver plus backends exists. Unlike
+     * domains where new binaries could change the capabilities. A
+     * new/changed backend requires a reinitialization. */
+    if (!(driver->caps = virStorageBackendGetCapabilities()))
+        goto error;
+
     storageDriverUnlock();
 
     return 0;
@@ -346,6 +352,7 @@ storageStateCleanup(void)
 
     storageDriverLock();
 
+    virObjectUnref(driver->caps);
     virObjectUnref(driver->storageEventState);
 
     /* free inactive pools */
@@ -555,6 +562,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)
 {
@@ -2805,6 +2824,7 @@ static virHypervisorDriver storageHypervisorDriver = {
     .connectIsEncrypted = storageConnectIsEncrypted, /* 4.1.0 */
     .connectIsSecure = storageConnectIsSecure, /* 4.1.0 */
     .connectIsAlive = storageConnectIsAlive, /* 4.1.0 */
+    .connectGetCapabilities = storageConnectGetCapabilities, /* 5.2.0 */
 };
 
 static virConnectDriver storageConnectDriver = {