]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Avoid mangling paths of non-local filesystems when looking up
authorPeter Krempa <pkrempa@redhat.com>
Tue, 25 Feb 2014 14:51:15 +0000 (15:51 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 5 Mar 2014 08:20:05 +0000 (09:20 +0100)
When looking up a volume by path on a non-local filesystem don't use the
"cleaned" path that might be mangled in such a way that it will differ
from a path provided by a storage backend.

Skip the cleanup step for gluster, sheepdog and RBD.

src/storage/storage_driver.c

index 79beb45b4914ac21d16c79e3db3615c888d83bbb..8b5aaab4d5c817f8fdb211149149dc3547f48aa1 100644 (file)
@@ -1446,42 +1446,66 @@ storageVolLookupByPath(virConnectPtr conn,
 
     storageDriverLock(driver);
     for (i = 0; i < driver->pools.count && !ret; i++) {
-        virStoragePoolObjLock(driver->pools.objs[i]);
-        if (virStoragePoolObjIsActive(driver->pools.objs[i])) {
-            virStorageVolDefPtr vol;
-            char *stable_path;
-
-            stable_path = virStorageBackendStablePath(driver->pools.objs[i],
-                                                      cleanpath,
-                                                      false);
-            if (stable_path == NULL) {
-                /* Don't break the whole lookup process if it fails on
-                 * getting the stable path for some of the pools.
-                 */
-                VIR_WARN("Failed to get stable path for pool '%s'",
-                         driver->pools.objs[i]->def->name);
-                virStoragePoolObjUnlock(driver->pools.objs[i]);
-                continue;
-            }
+        virStoragePoolObjPtr pool = driver->pools.objs[i];
+        virStorageVolDefPtr vol;
+        char *stable_path = NULL;
+
+        virStoragePoolObjLock(pool);
 
-            vol = virStorageVolDefFindByPath(driver->pools.objs[i],
-                                             stable_path);
-            VIR_FREE(stable_path);
+        if (!virStoragePoolObjIsActive(pool)) {
+           virStoragePoolObjUnlock(pool);
+           continue;
+        }
 
-            if (vol) {
-                if (virStorageVolLookupByPathEnsureACL(conn, driver->pools.objs[i]->def, vol) < 0) {
-                    virStoragePoolObjUnlock(driver->pools.objs[i]);
+        switch ((enum virStoragePoolType) pool->def->type) {
+            case VIR_STORAGE_POOL_DIR:
+            case VIR_STORAGE_POOL_FS:
+            case VIR_STORAGE_POOL_NETFS:
+            case VIR_STORAGE_POOL_LOGICAL:
+            case VIR_STORAGE_POOL_DISK:
+            case VIR_STORAGE_POOL_ISCSI:
+            case VIR_STORAGE_POOL_SCSI:
+            case VIR_STORAGE_POOL_MPATH:
+                stable_path = virStorageBackendStablePath(pool,
+                                                          cleanpath,
+                                                          false);
+                if (stable_path == NULL) {
+                    /* Don't break the whole lookup process if it fails on
+                     * getting the stable path for some of the pools.
+                     */
+                    VIR_WARN("Failed to get stable path for pool '%s'",
+                             pool->def->name);
+                    virStoragePoolObjUnlock(pool);
+                    continue;
+                }
+                break;
+
+            case VIR_STORAGE_POOL_GLUSTER:
+            case VIR_STORAGE_POOL_RBD:
+            case VIR_STORAGE_POOL_SHEEPDOG:
+            case VIR_STORAGE_POOL_LAST:
+                if (VIR_STRDUP(stable_path, path) < 0) {
+                     virStoragePoolObjUnlock(pool);
                     goto cleanup;
                 }
+                break;
+        }
 
-                ret = virGetStorageVol(conn,
-                                       driver->pools.objs[i]->def->name,
-                                       vol->name,
-                                       vol->key,
-                                       NULL, NULL);
+        vol = virStorageVolDefFindByPath(pool, stable_path);
+        VIR_FREE(stable_path);
+
+        if (vol) {
+            if (virStorageVolLookupByPathEnsureACL(conn, pool->def, vol) < 0) {
+                virStoragePoolObjUnlock(pool);
+                goto cleanup;
             }
+
+            ret = virGetStorageVol(conn, pool->def->name,
+                                   vol->name, vol->key,
+                                   NULL, NULL);
         }
-        virStoragePoolObjUnlock(driver->pools.objs[i]);
+
+        virStoragePoolObjUnlock(pool);
     }
 
     if (!ret)