]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodedev: Create helpers to search for vport capable nodedevs
authorJohn Ferlan <jferlan@redhat.com>
Thu, 17 Nov 2016 20:03:00 +0000 (15:03 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 4 Jan 2017 22:09:59 +0000 (17:09 -0500)
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@redhat.com>
src/conf/node_device_conf.c

index 1cd0bafb9398d724c5d9bb9c0c81134e019a1ebd..25e1f4b53c1fb8dd3e02fdbc6720924898dd719a 100644 (file)
@@ -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;
 }