]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Introduce storagePoolLookupByTargetPath
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 26 Nov 2014 16:13:00 +0000 (17:13 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 2 Dec 2014 16:51:57 +0000 (17:51 +0100)
While this could be exposed as a public API, it's not done yet as
there's no demand for that yet. Anyway, this is just preparing
the environment for easier volume creation on the destination.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/storage/storage_driver.c
src/storage/storage_driver.h

index 99ccb49ce0467b5bf54a19dab317af623e0551a0..7f33d6f1cd1af3d32d2252285d42618a40405663 100644 (file)
@@ -1464,6 +1464,48 @@ storageVolLookupByPath(virConnectPtr conn,
     return ret;
 }
 
+virStoragePoolPtr
+storagePoolLookupByTargetPath(virConnectPtr conn,
+                              const char *path)
+{
+    size_t i;
+    virStoragePoolPtr ret = NULL;
+    char *cleanpath;
+
+    cleanpath = virFileSanitizePath(path);
+    if (!cleanpath)
+        return NULL;
+
+    storageDriverLock();
+    for (i = 0; i < driver->pools.count && !ret; i++) {
+        virStoragePoolObjPtr pool = driver->pools.objs[i];
+
+        virStoragePoolObjLock(pool);
+
+        if (!virStoragePoolObjIsActive(pool)) {
+            virStoragePoolObjUnlock(pool);
+            continue;
+        }
+
+        if (STREQ(path, pool->def->target.path)) {
+            ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid,
+                                    NULL, NULL);
+        }
+
+        virStoragePoolObjUnlock(pool);
+    }
+    storageDriverUnlock();
+
+    if (!ret) {
+        virReportError(VIR_ERR_NO_STORAGE_VOL,
+                       _("no storage pool with matching target path '%s'"),
+                       path);
+    }
+
+    VIR_FREE(cleanpath);
+    return ret;
+}
+
 
 static int
 storageVolDeleteInternal(virStorageVolPtr obj,
index b805ddd3b5c458033429b98b2f4fd510a9b22e81..4f28dc155d9388be974a2f483f8b74dee474f0c9 100644 (file)
@@ -57,6 +57,11 @@ int virStorageFileGetMetadata(virStorageSourcePtr src,
 int virStorageTranslateDiskSourcePool(virConnectPtr conn,
                                       virDomainDiskDefPtr def);
 
+virStoragePoolPtr
+storagePoolLookupByTargetPath(virConnectPtr conn,
+                              const char *path)
+    ATTRIBUTE_NONNULL(2);
+
 int storageRegister(void);
 
 #endif /* __VIR_STORAGE_DRIVER_H__ */