[libvirt PATCH 7/7] nodedev: look up mdevs by UUID and parent

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

 



Since UUID is not guaranteed to be unique by mdevctl, we may have more
than one nodedev with the same UUID. Therefore, we need to disambiguate
when looking up mdevs by specifying the UUID and parent address, which
mdevctl guarantees to be a unique combination.

Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
---
 src/conf/virnodedeviceobj.c          | 18 ++++++++++++++----
 src/conf/virnodedeviceobj.h          |  3 ++-
 src/node_device/node_device_driver.c | 24 ++++++++++++++++--------
 3 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index 6e7b354f96..d1d23fc857 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -401,13 +401,20 @@ virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceObjList *devs,
                                       &data);
 }
 
+
+typedef struct {
+    const char *uuid;
+    const char *parent_addr;
+} FindMediatedDeviceData;
+
+
 static int
 virNodeDeviceObjListFindMediatedDeviceByUUIDCallback(const void *payload,
                                                      const char *name G_GNUC_UNUSED,
                                                      const void *opaque)
 {
     virNodeDeviceObj *obj = (virNodeDeviceObj *) payload;
-    const char *uuid = (const char *) opaque;
+    const FindMediatedDeviceData* data = opaque;
     virNodeDevCapsDef *cap;
     int want = 0;
 
@@ -415,7 +422,8 @@ virNodeDeviceObjListFindMediatedDeviceByUUIDCallback(const void *payload,
 
     for (cap = obj->def->caps; cap != NULL; cap = cap->next) {
         if (cap->data.type == VIR_NODE_DEV_CAP_MDEV) {
-            if (STREQ(cap->data.mdev.uuid, uuid)) {
+            if (STREQ(cap->data.mdev.uuid, data->uuid) &&
+                STREQ(cap->data.mdev.parent_addr, data->parent_addr)) {
                 want = 1;
                 break;
             }
@@ -429,11 +437,13 @@ virNodeDeviceObjListFindMediatedDeviceByUUIDCallback(const void *payload,
 
 virNodeDeviceObj *
 virNodeDeviceObjListFindMediatedDeviceByUUID(virNodeDeviceObjList *devs,
-                                             const char *uuid)
+                                             const char *uuid,
+                                             const char *parent_addr)
 {
+    const FindMediatedDeviceData data = {uuid, parent_addr};
     return virNodeDeviceObjListSearch(devs,
                                       virNodeDeviceObjListFindMediatedDeviceByUUIDCallback,
-                                      uuid);
+                                      &data);
 }
 
 static void
diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h
index 1fdd4f65da..068c7c6f34 100644
--- a/src/conf/virnodedeviceobj.h
+++ b/src/conf/virnodedeviceobj.h
@@ -122,7 +122,8 @@ virNodeDeviceObjSetSkipUpdateCaps(virNodeDeviceObj *obj,
                                   bool skipUpdateCaps);
 virNodeDeviceObj *
 virNodeDeviceObjListFindMediatedDeviceByUUID(virNodeDeviceObjList *devs,
-                                             const char *uuid);
+                                             const char *uuid,
+                                             const char *parent_addr);
 
 bool
 virNodeDeviceObjIsActive(virNodeDeviceObj *obj);
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 4e676bfd56..ddb9a9bca7 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -321,6 +321,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
 static virNodeDevicePtr
 nodeDeviceLookupMediatedDeviceByUUID(virConnectPtr conn,
                                      const char *uuid,
+                                     const char *parent_addr,
                                      unsigned int flags)
 {
     virNodeDeviceObj *obj = NULL;
@@ -330,7 +331,7 @@ nodeDeviceLookupMediatedDeviceByUUID(virConnectPtr conn,
     virCheckFlags(0, NULL);
 
     if (!(obj = virNodeDeviceObjListFindMediatedDeviceByUUID(driver->devs,
-                                                             uuid)))
+                                                             uuid, parent_addr)))
         return NULL;
 
     def = virNodeDeviceObjGetDef(obj);
@@ -542,23 +543,29 @@ nodeDeviceFindNewDevice(virConnectPtr conn,
 }
 
 
+typedef struct {
+    const char *uuid;
+    const char *parent_addr;
+} NewMediatedDeviceData;
+
 static virNodeDevicePtr
 nodeDeviceFindNewMediatedDeviceFunc(virConnectPtr conn,
                                     const void *opaque)
 {
-    const char *uuid = opaque;
+    const NewMediatedDeviceData *data = opaque;
 
-    return nodeDeviceLookupMediatedDeviceByUUID(conn, uuid, 0);
+    return nodeDeviceLookupMediatedDeviceByUUID(conn, data->uuid, data->parent_addr, 0);
 }
 
 
 static virNodeDevicePtr
 nodeDeviceFindNewMediatedDevice(virConnectPtr conn,
-                                const char *mdev_uuid)
+                                const char *mdev_uuid,
+                                const char *parent_addr)
 {
-    return nodeDeviceFindNewDevice(conn,
-                                   nodeDeviceFindNewMediatedDeviceFunc,
-                                   mdev_uuid);
+    NewMediatedDeviceData data = {mdev_uuid, parent_addr};
+    return nodeDeviceFindNewDevice(conn, nodeDeviceFindNewMediatedDeviceFunc,
+                                   &data);
 }
 
 
@@ -867,7 +874,8 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn,
         def->caps->data.mdev.uuid = g_steal_pointer(&uuid);
     }
 
-    return nodeDeviceFindNewMediatedDevice(conn, def->caps->data.mdev.uuid);
+    return nodeDeviceFindNewMediatedDevice(conn, def->caps->data.mdev.uuid,
+                                           def->caps->data.mdev.parent_addr);
 }
 
 
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux