]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: Introduce virNodeDeviceGetSCSIHostCaps
authorJohn Ferlan <jferlan@redhat.com>
Thu, 25 May 2017 14:20:58 +0000 (10:20 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 17 Jul 2017 14:40:24 +0000 (10:40 -0400)
We're about to move the call to nodeDeviceSysfsGetSCSIHostCaps from
node_device_driver into virnodedeviceobj, so move the guts of the code
from the driver specific node_device_linux_sysfs into its own API
since virnodedeviceobj cannot callback into the driver.

Nothing in the code deals with sysfs anyway, as that's hidden by the
various virSCSIHost* and virVHBA* utility function calls.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/conf/node_device_conf.c
src/conf/node_device_conf.h
src/libvirt_private.syms
src/node_device/node_device_linux_sysfs.c

index e5947e67b6d5be96c543735d88d437ba571fcf58..503b1298901ccf8fe08fcdb2ed11491f7d78deb2 100644 (file)
@@ -2483,3 +2483,85 @@ virNodeDeviceDeleteVport(virConnectPtr conn,
     VIR_FREE(scsi_host_name);
     return ret;
 }
+
+
+int
+virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host)
+{
+    char *tmp = NULL;
+    int ret = -1;
+
+    if ((scsi_host->unique_id =
+         virSCSIHostGetUniqueId(NULL, scsi_host->host)) < 0) {
+        VIR_DEBUG("Failed to read unique_id for host%d", scsi_host->host);
+        scsi_host->unique_id = -1;
+    }
+
+    VIR_DEBUG("Checking if host%d is an FC HBA", scsi_host->host);
+
+    if (virVHBAPathExists(NULL, scsi_host->host)) {
+        scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST;
+
+        if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host, "port_name"))) {
+            VIR_WARN("Failed to read WWPN for host%d", scsi_host->host);
+            goto cleanup;
+        }
+        VIR_FREE(scsi_host->wwpn);
+        VIR_STEAL_PTR(scsi_host->wwpn, tmp);
+
+        if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host, "node_name"))) {
+            VIR_WARN("Failed to read WWNN for host%d", scsi_host->host);
+            goto cleanup;
+        }
+        VIR_FREE(scsi_host->wwnn);
+        VIR_STEAL_PTR(scsi_host->wwnn, tmp);
+
+        if ((tmp = virVHBAGetConfig(NULL, scsi_host->host, "fabric_name"))) {
+            VIR_FREE(scsi_host->fabric_wwn);
+            VIR_STEAL_PTR(scsi_host->fabric_wwn, tmp);
+        }
+    }
+
+    if (virVHBAIsVportCapable(NULL, scsi_host->host)) {
+        scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
+
+        if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
+                                     "max_npiv_vports"))) {
+            VIR_WARN("Failed to read max_npiv_vports for host%d",
+                     scsi_host->host);
+            goto cleanup;
+        }
+
+        if (virStrToLong_i(tmp, NULL, 10, &scsi_host->max_vports) < 0) {
+            VIR_WARN("Failed to parse value of max_npiv_vports '%s'", tmp);
+            goto cleanup;
+        }
+
+        VIR_FREE(tmp);
+        if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
+                                      "npiv_vports_inuse"))) {
+            VIR_WARN("Failed to read npiv_vports_inuse for host%d",
+                     scsi_host->host);
+            goto cleanup;
+        }
+
+        if (virStrToLong_i(tmp, NULL, 10, &scsi_host->vports) < 0) {
+            VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", tmp);
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+ cleanup:
+    if (ret < 0) {
+        /* Clear the two flags in case of producing confusing XML output */
+        scsi_host->flags &= ~(VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST |
+                              VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS);
+
+        VIR_FREE(scsi_host->wwnn);
+        VIR_FREE(scsi_host->wwpn);
+        VIR_FREE(scsi_host->fabric_wwn);
+    }
+    VIR_FREE(tmp);
+    return ret;
+}
index 0a5e731d83edc2b43d3d9f23592f78fae07c6270..90c7e1fc267d4d68abfbb1a64545a14cf3b298d3 100644 (file)
@@ -408,4 +408,7 @@ int
 virNodeDeviceDeleteVport(virConnectPtr conn,
                          virStorageAdapterFCHostPtr fchost);
 
+int
+virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host);
+
 #endif /* __VIR_NODE_DEVICE_CONF_H__ */
index 853720f5bc9be345ba7d6dfb03862bb5b3d0003d..cc83d07b87ebf4c7318dde402b6f67bdc3683564 100644 (file)
@@ -688,6 +688,7 @@ virNodeDeviceDefParseNode;
 virNodeDeviceDefParseString;
 virNodeDeviceDeleteVport;
 virNodeDeviceGetParentName;
+virNodeDeviceGetSCSIHostCaps;
 virNodeDeviceGetWWNs;
 
 
index e02c384035c6964d52c8b64ff0faf3fc853555bb..6f438e5f3aeada239e11757e9f8b65a0ebf97c7e 100644 (file)
@@ -48,82 +48,7 @@ VIR_LOG_INIT("node_device.node_device_linux_sysfs");
 int
 nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host)
 {
-    char *tmp = NULL;
-    int ret = -1;
-
-    if ((scsi_host->unique_id =
-         virSCSIHostGetUniqueId(NULL, scsi_host->host)) < 0) {
-        VIR_DEBUG("Failed to read unique_id for host%d", scsi_host->host);
-        scsi_host->unique_id = -1;
-    }
-
-    VIR_DEBUG("Checking if host%d is an FC HBA", scsi_host->host);
-
-    if (virVHBAPathExists(NULL, scsi_host->host)) {
-        scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST;
-
-        if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host, "port_name"))) {
-            VIR_WARN("Failed to read WWPN for host%d", scsi_host->host);
-            goto cleanup;
-        }
-        VIR_FREE(scsi_host->wwpn);
-        VIR_STEAL_PTR(scsi_host->wwpn, tmp);
-
-        if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host, "node_name"))) {
-            VIR_WARN("Failed to read WWNN for host%d", scsi_host->host);
-            goto cleanup;
-        }
-        VIR_FREE(scsi_host->wwnn);
-        VIR_STEAL_PTR(scsi_host->wwnn, tmp);
-
-        if ((tmp = virVHBAGetConfig(NULL, scsi_host->host, "fabric_name"))) {
-            VIR_FREE(scsi_host->fabric_wwn);
-            VIR_STEAL_PTR(scsi_host->fabric_wwn, tmp);
-        }
-    }
-
-    if (virVHBAIsVportCapable(NULL, scsi_host->host)) {
-        scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
-
-        if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
-                                     "max_npiv_vports"))) {
-            VIR_WARN("Failed to read max_npiv_vports for host%d",
-                     scsi_host->host);
-            goto cleanup;
-        }
-
-        if (virStrToLong_i(tmp, NULL, 10, &scsi_host->max_vports) < 0) {
-            VIR_WARN("Failed to parse value of max_npiv_vports '%s'", tmp);
-            goto cleanup;
-        }
-
-        VIR_FREE(tmp);
-        if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
-                                     "npiv_vports_inuse"))) {
-            VIR_WARN("Failed to read npiv_vports_inuse for host%d",
-                     scsi_host->host);
-            goto cleanup;
-        }
-
-        if (virStrToLong_i(tmp, NULL, 10, &scsi_host->vports) < 0) {
-            VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", tmp);
-            goto cleanup;
-        }
-    }
-
-    ret = 0;
- cleanup:
-    if (ret < 0) {
-        /* Clear the two flags in case of producing confusing XML output */
-        scsi_host->flags &= ~(VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST |
-                                VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS);
-
-        VIR_FREE(scsi_host->wwnn);
-        VIR_FREE(scsi_host->wwpn);
-        VIR_FREE(scsi_host->fabric_wwn);
-    }
-    VIR_FREE(tmp);
-    return ret;
+    return virNodeDeviceGetSCSIHostCaps(scsi_host);
 }