]> xenbits.xensource.com Git - libvirt.git/commitdiff
Give iSCSI and disk storage backend drivers the
authorChris Lalancette <clalance@redhat.com>
Mon, 3 Nov 2008 11:37:11 +0000 (11:37 +0000)
committerChris Lalancette <clalance@redhat.com>
Mon, 3 Nov 2008 11:37:11 +0000 (11:37 +0000)
ability to resolve any kind of volume path to the pool target volume
path.  For instance, if the pool was defined with a
<target><path>/dev/disk/by-id</path></target> section, and one of the
volumes is /dev/disk/by-id/scsi-S_beaf11, then you would be able to
call virStorageVolLookupByPath("/dev/sdc"), and get the correct volume
back.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
ChangeLog
src/storage_backend.c
src/storage_backend.h
src/storage_backend_disk.c
src/storage_backend_iscsi.c
src/storage_driver.c

index 63f27651c1897d73a366fd4988f7716e32f4b36a..2f16de29b55ffddc0903f2c4cecd6e0b114efa42 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Mon Nov 03 12:37:00 CET 2008 Chris Lalancette <clalance@redhat.com>
+       * src/storage_backend.c src/storage_backend.h
+       src/storage_backend_disk.c src/storage_backend_iscsi.c
+       src/storage_driver.c: Give iSCSI and disk storage backend drivers the
+       ability to resolve any kind of volume path to the pool target volume
+       path.  For instance, if the pool was defined with a
+       <target><path>/dev/disk/by-id</path></target> section, and one of the
+       volumes is /dev/disk/by-id/scsi-S_beaf11, then you would be able to
+       call virStorageVolLookupByPath("/dev/sdc"), and get the correct volume
+       back.
+
 Fri Oct 31 14:55:46 CET 2008 Daniel Veillard <veillard@redhat.com>
 
        * python/virConnect.py: needed for events from the python bindings
index 1f4ed10a72d7a21719ed150d5087e4617390758a..b8772ff006f3a4569b2f1e2c2c3ab33bfae8f731 100644 (file)
@@ -357,16 +357,17 @@ virStorageBackendUpdateVolInfoFD(virConnectPtr conn,
 char *
 virStorageBackendStablePath(virConnectPtr conn,
                             virStoragePoolObjPtr pool,
-                            char *devpath)
+                            const char *devpath)
 {
     DIR *dh;
     struct dirent *dent;
+    char *stablepath;
 
     /* Short circuit if pool has no target, or if its /dev */
     if (pool->def->target.path == NULL ||
         STREQ(pool->def->target.path, "/dev") ||
         STREQ(pool->def->target.path, "/dev/"))
-        return devpath;
+        goto ret_strdup;
 
     /* The pool is pointing somewhere like /dev/disk/by-path
      * or /dev/disk/by-id, so we need to check all symlinks in
@@ -382,7 +383,6 @@ virStorageBackendStablePath(virConnectPtr conn,
     }
 
     while ((dent = readdir(dh)) != NULL) {
-        char *stablepath;
         if (dent->d_name[0] == '.')
             continue;
 
@@ -407,10 +407,17 @@ virStorageBackendStablePath(virConnectPtr conn,
 
     closedir(dh);
 
+ ret_strdup:
     /* Couldn't find any matching stable link so give back
      * the original non-stable dev path
      */
-    return devpath;
+
+    stablepath = strdup(devpath);
+
+    if (stablepath == NULL)
+        virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("dup path"));
+
+    return stablepath;
 }
 
 
index ff7614cf30b830301bd7f478b1bc595093e2582b..46311c60e5af998815553183629f059d614e53f3 100644 (file)
@@ -50,6 +50,7 @@ enum {
     VIR_STORAGE_BACKEND_POOL_SOURCE_DIR     = (1<<2),
     VIR_STORAGE_BACKEND_POOL_SOURCE_ADAPTER = (1<<3),
     VIR_STORAGE_BACKEND_POOL_SOURCE_NAME    = (1<<4),
+    VIR_STORAGE_BACKEND_POOL_STABLE_PATH    = (1<<5),
 };
 
 enum partTableType {
@@ -138,7 +139,7 @@ int virStorageBackendUpdateVolInfoFD(virConnectPtr conn,
 
 char *virStorageBackendStablePath(virConnectPtr conn,
                                   virStoragePoolObjPtr pool,
-                                  char *devpath);
+                                  const char *devpath);
 
 typedef int (*virStorageBackendListVolRegexFunc)(virConnectPtr conn,
                                                  virStoragePoolObjPtr pool,
index b835cf011de34ab19fb1785e7c99458cfa2c24c5..b2768ca31b775511a4a24359b2359d8cc440fe8b 100644 (file)
@@ -109,8 +109,7 @@ virStorageBackendDiskMakeDataVol(virConnectPtr conn,
                                                             devpath)) == NULL)
             return -1;
 
-        if (devpath != vol->target.path)
-            VIR_FREE(devpath);
+        VIR_FREE(devpath);
     }
 
     if (vol->key == NULL) {
@@ -447,7 +446,8 @@ virStorageBackend virStorageBackendDisk = {
     .deleteVol = virStorageBackendDiskDeleteVol,
 
     .poolOptions = {
-        .flags = (VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE),
+        .flags = (VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE|
+                  VIR_STORAGE_BACKEND_POOL_STABLE_PATH),
         .defaultFormat = VIR_STORAGE_POOL_DISK_UNKNOWN,
         .formatFromString = virStorageBackendPartTableTypeFromString,
         .formatToString = virStorageBackendPartTableTypeToString,
index decb7368907d3df024b7b7a386a36971d8e6c8c2..bc71eb605f6dd3a8de1da22b1f7aaffbbb20324b 100644 (file)
@@ -219,8 +219,7 @@ virStorageBackendISCSINewLun(virConnectPtr conn, virStoragePoolObjPtr pool,
                                                         devpath)) == NULL)
         goto cleanup;
 
-    if (devpath != vol->target.path)
-        VIR_FREE(devpath);
+    VIR_FREE(devpath);
 
     if (virStorageBackendUpdateVolInfoFD(conn, vol, fd, 1) < 0)
         goto cleanup;
@@ -645,7 +644,8 @@ virStorageBackend virStorageBackendISCSI = {
 
     .poolOptions = {
         .flags = (VIR_STORAGE_BACKEND_POOL_SOURCE_HOST |
-                  VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE)
+                  VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE |
+                  VIR_STORAGE_BACKEND_POOL_STABLE_PATH)
     },
 
     .volType = VIR_STORAGE_VOL_BLOCK,
index 077382107032f09fe37db7faca576e0364d9a35a..bced52e385a058bc54cc3703333ce84312611950 100644 (file)
@@ -966,8 +966,34 @@ storageVolumeLookupByPath(virConnectPtr conn,
 
     for (i = 0 ; i < driver->pools.count ; i++) {
         if (virStoragePoolObjIsActive(driver->pools.objs[i])) {
-            virStorageVolDefPtr vol =
-                virStorageVolDefFindByPath(driver->pools.objs[i], path);
+            virStorageVolDefPtr vol;
+            virStorageBackendPoolOptionsPtr options;
+
+            options = virStorageBackendPoolOptionsForType(driver->pools.objs[i]->def->type);
+            if (options == NULL)
+                continue;
+
+            if (options->flags & VIR_STORAGE_BACKEND_POOL_STABLE_PATH) {
+                const char *stable_path;
+
+                stable_path = virStorageBackendStablePath(conn,
+                                                          driver->pools.objs[i],
+                                                          path);
+                /*
+                 * virStorageBackendStablePath already does
+                 * virStorageReportError if it fails; we just need to keep
+                 * propagating the return code
+                 */
+                if (stable_path == NULL)
+                    return NULL;
+
+                vol = virStorageVolDefFindByPath(driver->pools.objs[i],
+                                                 stable_path);
+                VIR_FREE(stable_path);
+            }
+            else
+                vol = virStorageVolDefFindByPath(driver->pools.objs[i], path);
+
 
             if (vol)
                 return virGetStorageVol(conn,