[PATCH v4 10/14] nodedev: Introduce virNodeDeviceObjListFindSCSIHostByWWNs

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

 



In an overall effort to privatize access to virNodeDeviceObj and
virNodeDeviceObjList into the virnodedeviceobj module, move the
object list parsing from node_device_driver and replace with a
call to a virnodedeviceobj helper. This follows other similar
APIs/helpers which peruse the object list looking for some specific
data in order to get/return an @device (virNodeDevice) object to
the caller.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/virnodedeviceobj.c          | 33 +++++++++++++++++++++
 src/conf/virnodedeviceobj.h          |  5 ++++
 src/libvirt_private.syms             |  1 +
 src/node_device/node_device_driver.c | 56 +++++++++++-------------------------
 4 files changed, 55 insertions(+), 40 deletions(-)

diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index 1dbaf83..7ebd4e8 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -274,6 +274,39 @@ virNodeDeviceObjListFindByCap(virNodeDeviceObjListPtr devs,
 }
 
 
+virNodeDeviceObjPtr
+virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceObjListPtr devs,
+                                       const char *wwnn,
+                                       const char *wwpn)
+{
+    size_t i;
+
+    for (i = 0; i < devs->count; i++) {
+        virNodeDeviceObjPtr obj = devs->objs[i];
+        virNodeDevCapsDefPtr cap;
+
+        virNodeDeviceObjLock(obj);
+        cap = obj->def->caps;
+
+        while (cap) {
+            if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) {
+                virNodeDeviceGetSCSIHostCaps(&cap->data.scsi_host);
+                if (cap->data.scsi_host.flags &
+                    VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
+                    if (STREQ(cap->data.scsi_host.wwnn, wwnn) &&
+                        STREQ(cap->data.scsi_host.wwpn, wwpn))
+                        return obj;
+                }
+            }
+            cap = cap->next;
+        }
+        virNodeDeviceObjUnlock(obj);
+    }
+
+    return NULL;
+}
+
+
 void
 virNodeDeviceObjFree(virNodeDeviceObjPtr obj)
 {
diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h
index 6194c6c..6ec5ee7 100644
--- a/src/conf/virnodedeviceobj.h
+++ b/src/conf/virnodedeviceobj.h
@@ -53,6 +53,11 @@ virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjListPtr devs,
     ATTRIBUTE_NONNULL(2);
 
 virNodeDeviceObjPtr
+virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceObjListPtr devs,
+                                       const char *wwnn,
+                                       const char *wwpn);
+
+virNodeDeviceObjPtr
 virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs,
                               virNodeDeviceDefPtr def);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index acd123f..589e587 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -969,6 +969,7 @@ virNodeDeviceObjListAssignDef;
 virNodeDeviceObjListExport;
 virNodeDeviceObjListFindByName;
 virNodeDeviceObjListFindBySysfsPath;
+virNodeDeviceObjListFindSCSIHostByWWNs;
 virNodeDeviceObjListFree;
 virNodeDeviceObjListGetNames;
 virNodeDeviceObjListGetParentHost;
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 930f9b6..85a7c88 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -288,9 +288,6 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
                               const char *wwpn,
                               unsigned int flags)
 {
-    size_t i;
-    virNodeDeviceObjListPtr devs = driver->devs;
-    virNodeDevCapsDefPtr cap = NULL;
     virNodeDeviceObjPtr obj = NULL;
     virNodeDeviceDefPtr def;
     virNodeDevicePtr device = NULL;
@@ -298,48 +295,27 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
     virCheckFlags(0, NULL);
 
     nodeDeviceLock();
+    obj = virNodeDeviceObjListFindSCSIHostByWWNs(driver->devs, wwnn, wwpn);
+    nodeDeviceUnlock();
 
-    for (i = 0; i < devs->count; i++) {
-        obj = devs->objs[i];
-        virNodeDeviceObjLock(obj);
-        def = virNodeDeviceObjGetDef(obj);
-        cap = def->caps;
-
-        while (cap) {
-            if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) {
-                nodeDeviceSysfsGetSCSIHostCaps(&cap->data.scsi_host);
-                if (cap->data.scsi_host.flags &
-                    VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
-                    if (STREQ(cap->data.scsi_host.wwnn, wwnn) &&
-                        STREQ(cap->data.scsi_host.wwpn, wwpn)) {
-
-                        if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0)
-                            goto error;
-
-                        if ((device = virGetNodeDevice(conn, def->name))) {
-                            if (VIR_STRDUP(device->parent, def->parent) < 0) {
-                                virObjectUnref(device);
-                                device = NULL;
-                            }
-                        }
-                        virNodeDeviceObjUnlock(obj);
-                        goto out;
-                    }
-                }
-            }
-            cap = cap->next;
-        }
+    if (!obj)
+        return NULL;
 
-        virNodeDeviceObjUnlock(obj);
-    }
+    def = virNodeDeviceObjGetDef(obj);
 
- out:
-    nodeDeviceUnlock();
-    return device;
+    if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0)
+        goto cleanup;
 
- error:
+    if ((device = virGetNodeDevice(conn, def->name))) {
+        if (VIR_STRDUP(device->parent, def->parent) < 0) {
+            virObjectUnref(device);
+            device = NULL;
+        }
+    }
+
+ cleanup:
     virNodeDeviceObjUnlock(obj);
-    goto out;
+    return device;
 }
 
 
-- 
2.9.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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