[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH]: Allow arbitrary paths to virStorageVolLookupByPath



In ovirt, we have to scan iSCSI LUN's for LVM storage when they are first added
to the database.  To do this, we do roughly the following:

iscsi_pool = libvirt.define_and_start_iscsi_pool("/dev/disk/by-id")
iscsi_pool.add_luns_to_db

logical = conn.discover_storage_pool_sources("logical")
for each logical_volume_group in logical:
     for each device in logical_volume_group:
          iscsi_pool.lookup_vol_by_path(device.path)

And then we use that information to associate an iSCSI LUN with this volume
group.  The problem is that there is an mis-match between how we define the
iscsi pool (with /dev/disk/by-id devices), and what data the
discover_storage_pool_sources() returns (/dev devices), so we can't easily
associate the two.

The following patch implements stable path naming when the
virStorageVolLookupByPath method is called.  Basically, it tries to convert
whatever path it is given (say /dev/sdc) into the form currently used by the
Pool (say /dev/disk/by-id).  It then goes and looks up the form in the pool, and
returns the storageVolume object as appropriate.  Note that it only tries to do
this for the Pool types where it makes sense, namely iSCSI and disk; all other
pool types stay exactly the same.

With this in place, we can solve the mis-match in the above code, and LVM
scanning seems to work in ovirt.

Signed-off-by: Chris Lalancette <clalance redhat com>
Index: src/storage_backend.h
===================================================================
RCS file: /data/cvs/libvirt/src/storage_backend.h,v
retrieving revision 1.9
diff -u -r1.9 storage_backend.h
--- a/src/storage_backend.h	23 Oct 2008 11:32:22 -0000	1.9
+++ b/src/storage_backend.h	31 Oct 2008 10:09:29 -0000
@@ -50,6 +50,7 @@
     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 {
Index: src/storage_backend_disk.c
===================================================================
RCS file: /data/cvs/libvirt/src/storage_backend_disk.c,v
retrieving revision 1.16
diff -u -r1.16 storage_backend_disk.c
--- a/src/storage_backend_disk.c	23 Oct 2008 11:32:22 -0000	1.16
+++ b/src/storage_backend_disk.c	31 Oct 2008 10:09:29 -0000
@@ -447,7 +447,8 @@
     .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: src/storage_backend_iscsi.c
===================================================================
RCS file: /data/cvs/libvirt/src/storage_backend_iscsi.c,v
retrieving revision 1.15
diff -u -r1.15 storage_backend_iscsi.c
--- a/src/storage_backend_iscsi.c	16 Oct 2008 15:06:04 -0000	1.15
+++ b/src/storage_backend_iscsi.c	31 Oct 2008 10:09:29 -0000
@@ -645,7 +645,8 @@
 
     .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: src/storage_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/storage_driver.c,v
retrieving revision 1.13
diff -u -r1.13 storage_driver.c
--- a/src/storage_driver.c	21 Oct 2008 17:15:53 -0000	1.13
+++ b/src/storage_driver.c	31 Oct 2008 10:09:29 -0000
@@ -963,11 +963,25 @@
     virStorageDriverStatePtr driver =
         (virStorageDriverStatePtr)conn->storagePrivateData;
     unsigned int i;
+    char *stable_path;
 
     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)
+                stable_path = virStorageBackendStablePath(conn, driver->pools.objs[i], (char *)path);
+            else
+                stable_path = (char *)path;
+
+            vol =  virStorageVolDefFindByPath(driver->pools.objs[i], stable_path);
+            if (stable_path != path)
+                VIR_FREE(stable_path);
 
             if (vol)
                 return virGetStorageVol(conn,

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]