]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: export virStoragePoolLookupByTargetPath as a public API
authorDaniel P. Berrangé <berrange@redhat.com>
Thu, 25 Jan 2018 09:35:52 +0000 (09:35 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 9 Feb 2018 11:05:10 +0000 (11:05 +0000)
The storagePoolLookupByTargetPath() method in the storage driver is used
by the QEMU driver during block migration. If there's a valid use case
for this in the QEMU driver, then external apps likely have similar
needs. Exposing it in the public API removes the direct dependancy from
the QEMU driver to the storage driver.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
include/libvirt/libvirt-storage.h
src/driver-storage.h
src/libvirt-storage.c
src/libvirt_public.syms
src/qemu/qemu_migration.c
src/remote/remote_driver.c
src/remote/remote_protocol.x
src/remote_protocol-structs
src/storage/storage_driver.c

index 736e2e3b80bde0eb6341be2c4f86b67a243dbb22..413d9f6c4cdfa4694d919adc6cbb37d8ba05f0b9 100644 (file)
@@ -264,6 +264,8 @@ virStoragePoolPtr       virStoragePoolLookupByUUID      (virConnectPtr conn,
 virStoragePoolPtr       virStoragePoolLookupByUUIDString(virConnectPtr conn,
                                                          const char *uuid);
 virStoragePoolPtr       virStoragePoolLookupByVolume    (virStorageVolPtr vol);
+virStoragePoolPtr       virStoragePoolLookupByTargetPath(virConnectPtr conn,
+                                                         const char *path);
 
 /*
  * Creating/destroying pools
index 48e588a5461135e64386b59b4d1be3a6add831b5..146eb88b2c99ebd54c9e60131c77a5240b66ffbb 100644 (file)
@@ -63,6 +63,10 @@ typedef virStoragePoolPtr
 typedef virStoragePoolPtr
 (*virDrvStoragePoolLookupByVolume)(virStorageVolPtr vol);
 
+typedef virStoragePoolPtr
+(*virDrvStoragePoolLookupByTargetPath)(virConnectPtr conn,
+                                       const char *path);
+
 typedef virStoragePoolPtr
 (*virDrvStoragePoolCreateXML)(virConnectPtr conn,
                               const char *xmlDesc,
@@ -236,6 +240,7 @@ struct _virStorageDriver {
     virDrvStoragePoolLookupByName storagePoolLookupByName;
     virDrvStoragePoolLookupByUUID storagePoolLookupByUUID;
     virDrvStoragePoolLookupByVolume storagePoolLookupByVolume;
+    virDrvStoragePoolLookupByTargetPath storagePoolLookupByTargetPath;
     virDrvStoragePoolCreateXML storagePoolCreateXML;
     virDrvStoragePoolDefineXML storagePoolDefineXML;
     virDrvStoragePoolBuild storagePoolBuild;
index e4646cb80ff97cdd07d0994ac4aec9de1e8ecf47..3845a5d55e50346086369ecca28eaf526beb2e14 100644 (file)
@@ -497,6 +497,46 @@ virStoragePoolLookupByVolume(virStorageVolPtr vol)
 }
 
 
+/**
+ * virStoragePoolLookupByTargetPath:
+ * @conn: pointer to hypervisor connection
+ * @path: path at which the pool is exposed
+ *
+ * Fetch a storage pool which maps to a particular target directory.
+ * If more than one pool maps to the path, it is undefined which
+ * will be returned first.
+ *
+ * virStoragePoolFree should be used to free the resources after the
+ * storage pool object is no longer needed.
+ *
+ * Returns a virStoragePoolPtr object, or NULL if no matching pool is found
+ */
+virStoragePoolPtr
+virStoragePoolLookupByTargetPath(virConnectPtr conn,
+                                 const char *path)
+{
+    VIR_DEBUG("conn=%p, path=%s", conn, NULLSTR(path));
+
+    virResetLastError();
+
+    virCheckConnectReturn(conn, NULL);
+    virCheckNonNullArgGoto(path, error);
+
+    if (conn->storageDriver && conn->storageDriver->storagePoolLookupByTargetPath) {
+        virStoragePoolPtr ret;
+        ret = conn->storageDriver->storagePoolLookupByTargetPath(conn, path);
+        if (!ret)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(conn);
+    return NULL;
+}
+
 /**
  * virStoragePoolCreateXML:
  * @conn: pointer to hypervisor connection
index 0efde25a7f76d6151bf3625643487c1da685afe6..95df3a0dbc7b2e68b7302c9948ffc98dc7701bae 100644 (file)
@@ -779,4 +779,10 @@ LIBVIRT_3.9.0 {
     global:
         virDomainSetLifecycleAction;
 } LIBVIRT_3.7.0;
+
+LIBVIRT_4.1.0 {
+    global:
+        virStoragePoolLookupByTargetPath;
+} LIBVIRT_3.9.0;
+
 # .... define new API here using predicted next version number ....
index 5ee9e5c32c480229bac5922d06ebf4781e9c7fe7..a14e27aac29d8f9e59f8e52f149d822aa72dee5e 100644 (file)
@@ -329,7 +329,7 @@ qemuMigrationPrecreateDisk(virConnectPtr conn,
         *volName = '\0';
         volName++;
 
-        if (!(pool = storagePoolLookupByTargetPath(conn, basePath)))
+        if (!(pool = virStoragePoolLookupByTargetPath(conn, basePath)))
             goto cleanup;
         format = virStorageFileFormatTypeToString(disk->src->format);
         if (disk->src->format == VIR_STORAGE_FILE_QCOW2)
index f8fa64af998e560f13ca6abf4e029296b911e585..9ea726dc45c0a570251dc03a8b04d7a00cfc489a 100644 (file)
@@ -8556,6 +8556,7 @@ static virStorageDriver storage_driver = {
     .storagePoolLookupByName = remoteStoragePoolLookupByName, /* 0.4.1 */
     .storagePoolLookupByUUID = remoteStoragePoolLookupByUUID, /* 0.4.1 */
     .storagePoolLookupByVolume = remoteStoragePoolLookupByVolume, /* 0.4.1 */
+    .storagePoolLookupByTargetPath = remoteStoragePoolLookupByTargetPath, /* 4.1.0 */
     .storagePoolCreateXML = remoteStoragePoolCreateXML, /* 0.4.1 */
     .storagePoolDefineXML = remoteStoragePoolDefineXML, /* 0.4.1 */
     .storagePoolBuild = remoteStoragePoolBuild, /* 0.4.1 */
index 0aed25220dc47bca52f3945923625ba887cf6ab8..9dbd497b2fffbe516249afbe4e44a720563d5fd7 100644 (file)
@@ -1761,6 +1761,14 @@ struct remote_storage_pool_lookup_by_volume_ret {
     remote_nonnull_storage_pool pool;
 };
 
+struct remote_storage_pool_lookup_by_target_path_args {
+    remote_nonnull_string path;
+};
+
+struct remote_storage_pool_lookup_by_target_path_ret {
+    remote_nonnull_storage_pool pool;
+};
+
 struct remote_storage_pool_create_xml_args {
     remote_nonnull_string xml;
     unsigned int flags;
@@ -6120,5 +6128,12 @@ enum remote_procedure {
      * @generate: both
      * @acl: domain:write
      */
-    REMOTE_PROC_DOMAIN_SET_LIFECYCLE_ACTION = 390
+    REMOTE_PROC_DOMAIN_SET_LIFECYCLE_ACTION = 390,
+
+    /**
+     * @generate: both
+     * @priority: high
+     * @acl: storage_pool:getattr
+     */
+    REMOTE_PROC_STORAGE_POOL_LOOKUP_BY_TARGET_PATH = 391
 };
index 59b0acec69bf4eee464e1f7be2256afc4645b533..f45aba27a202a7dd064d6cc5a89b6c8f7b7de920 100644 (file)
@@ -1330,6 +1330,12 @@ struct remote_storage_pool_lookup_by_volume_args {
 struct remote_storage_pool_lookup_by_volume_ret {
         remote_nonnull_storage_pool pool;
 };
+struct remote_storage_pool_lookup_by_target_path_args {
+        remote_nonnull_string      path;
+};
+struct remote_storage_pool_lookup_by_target_path_ret {
+        remote_nonnull_storage_pool pool;
+};
 struct remote_storage_pool_create_xml_args {
         remote_nonnull_string      xml;
         u_int                      flags;
@@ -3262,4 +3268,5 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_MANAGED_SAVE_GET_XML_DESC = 388,
         REMOTE_PROC_DOMAIN_MANAGED_SAVE_DEFINE_XML = 389,
         REMOTE_PROC_DOMAIN_SET_LIFECYCLE_ACTION = 390,
+        REMOTE_PROC_STORAGE_POOL_LOOKUP_BY_TARGET_PATH = 391,
 };
index 1b4bce4fc8897260aca7fd7055bf271da1e21271..d5e38af5aa58339d25b110d88160fed9c7c7684f 100644 (file)
@@ -1694,6 +1694,9 @@ storagePoolLookupByTargetPath(virConnectPtr conn,
                                            storagePoolLookupByTargetPathCallback,
                                            cleanpath))) {
         def = virStoragePoolObjGetDef(obj);
+        if (virStoragePoolLookupByTargetPathEnsureACL(conn, def) < 0)
+            goto cleanup;
+
         pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
         virStoragePoolObjEndAPI(&obj);
     }
@@ -1710,6 +1713,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn,
         }
     }
 
+ cleanup:
     VIR_FREE(cleanpath);
     return pool;
 }
@@ -2808,6 +2812,7 @@ static virStorageDriver storageDriver = {
     .storagePoolLookupByName = storagePoolLookupByName, /* 0.4.0 */
     .storagePoolLookupByUUID = storagePoolLookupByUUID, /* 0.4.0 */
     .storagePoolLookupByVolume = storagePoolLookupByVolume, /* 0.4.0 */
+    .storagePoolLookupByTargetPath = storagePoolLookupByTargetPath, /* 4.1.0 */
     .storagePoolCreateXML = storagePoolCreateXML, /* 0.4.0 */
     .storagePoolDefineXML = storagePoolDefineXML, /* 0.4.0 */
     .storagePoolBuild = storagePoolBuild, /* 0.4.0 */