[PATCH 02/11] nodedev: Create helpers to search for vport capable nodedevs

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

 



Extract out code from virNodeDeviceGetParentHost into helpers - it's
going to be reused in upcoming patches to search on more fields

Create virNodeDeviceFindVPORTCapDef in order to return a virNodeDevCapsDefPtr
of the VPORT_OPS and virNodeDeviceFindFCParentHost to use the function and
generate an error message if the device doesn't have the capability.

Also clean up the processing in virNodeDeviceGetParentHost to remove
need for goto's.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/node_device_conf.c | 83 +++++++++++++++++++++++++++++++--------------
 1 file changed, 57 insertions(+), 26 deletions(-)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index bf5b22f..5396681 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -92,6 +92,30 @@ int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap)
 }
 
 
+/* virNodeDeviceFindVPORTCapDef:
+ * @dev: Pointer to current device
+ *
+ * Search the device object 'caps' array for vport_ops capability.
+ *
+ * Returns:
+ * Pointer to the caps or NULL if not found
+ */
+static virNodeDevCapsDefPtr
+virNodeDeviceFindVPORTCapDef(const virNodeDeviceObj *dev)
+{
+    virNodeDevCapsDefPtr caps = dev->def->caps;
+
+    while (caps) {
+        if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST &&
+            (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS))
+            break;
+
+        caps = caps->next;
+    }
+    return caps;
+}
+
+
 virNodeDeviceObjPtr
 virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs,
                              const char *sysfs_path)
@@ -1752,6 +1776,35 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def,
 /*
  * Return the NPIV dev's parent device name
  */
+/* virNodeDeviceFindFCParentHost:
+ * @parent: Pointer to node device object
+ * @parent_host: Pointer to return parent host number
+ *
+ * Search the capabilities for the device to find the FC capabilities
+ * in order to set the parent_host value.
+ *
+ * Returns:
+ *   0 on success with parent_host set, -1 otherwise;
+ */
+static int
+virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent,
+                              int *parent_host)
+{
+    virNodeDevCapsDefPtr cap = virNodeDeviceFindVPORTCapDef(parent);
+
+    if (!cap) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Parent device %s is not capable "
+                         "of vport operations"),
+                       parent->def->name);
+        return -1;
+    }
+
+    *parent_host = cap->data.scsi_host.host;
+    return 0;
+}
+
+
 int
 virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs,
                            const char *dev_name,
@@ -1759,41 +1812,19 @@ virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs,
                            int *parent_host)
 {
     virNodeDeviceObjPtr parent = NULL;
-    virNodeDevCapsDefPtr cap = NULL;
-    int ret = 0;
+    int ret;
 
-    parent = virNodeDeviceFindByName(devs, parent_name);
-    if (parent == NULL) {
+    if (!(parent = virNodeDeviceFindByName(devs, parent_name))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Could not find parent device for '%s'"),
                        dev_name);
-        ret = -1;
-        goto out;
-    }
-
-    cap = parent->def->caps;
-    while (cap != NULL) {
-        if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST &&
-            (cap->data.scsi_host.flags &
-             VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)) {
-                *parent_host = cap->data.scsi_host.host;
-                break;
-        }
-
-        cap = cap->next;
+        return -1;
     }
 
-    if (cap == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Parent device %s is not capable "
-                         "of vport operations"),
-                       parent->def->name);
-        ret = -1;
-    }
+    ret = virNodeDeviceFindFCParentHost(parent, parent_host);
 
     virNodeDeviceObjUnlock(parent);
 
- out:
     return ret;
 }
 
-- 
2.7.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