[PATCH 3/5] nodedev: Fix sysfs paths for vport operations

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

 



From: Dave Allan <dallan@xxxxxxxxxx>

Some kernels, such as the one used in RHEL-5, have vport_create and
vport_delete operation files in /sys/class/scsi_host/hostN directory
instead of /sys/class/fc_host/hostN. Let's check both paths for
compatibility reasons.

This also removes unnecessary '/' characters from sysfs paths containing
LINUX_SYSFS_FC_HOST_PREFIX.
---
 src/node_device/node_device_driver.c      |   21 +++++++++++++++++++
 src/node_device/node_device_driver.h      |    2 +-
 src/node_device/node_device_linux_sysfs.c |   31 +++++++++++++++++++++++-----
 3 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index b0ff662..a6ac80b 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -392,6 +392,7 @@ nodeDeviceVportCreateDelete(const int parent_host,
     int retval = 0;
     char *operation_path = NULL, *vport_name = NULL;
     const char *operation_file = NULL;
+    struct stat st;
 
     switch (operation) {
     case VPORT_CREATE:
@@ -419,6 +420,26 @@ nodeDeviceVportCreateDelete(const int parent_host,
         goto cleanup;
     }
 
+    if (stat(operation_path, &st) != 0) {
+        VIR_FREE(operation_path);
+        if (virAsprintf(&operation_path,
+                        "%shost%d%s",
+                        LINUX_SYSFS_SCSI_HOST_PREFIX,
+                        parent_host,
+                        operation_file) < 0) {
+            virReportOOMError();
+            retval = -1;
+            goto cleanup;
+        }
+
+        if (stat(operation_path, &st) != 0) {
+            VIR_ERROR(_("No vport operation path found for host%d"),
+                      parent_host);
+            retval = -1;
+            goto cleanup;
+        }
+    }
+
     VIR_DEBUG("Vport operation path is '%s'", operation_path);
 
     if (virAsprintf(&vport_name,
diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h
index f233641..4721be4 100644
--- a/src/node_device/node_device_driver.h
+++ b/src/node_device/node_device_driver.h
@@ -28,7 +28,7 @@
 # include "driver.h"
 # include "node_device_conf.h"
 
-# define LINUX_SYSFS_SCSI_HOST_PREFIX "/sys/class/scsi_host"
+# define LINUX_SYSFS_SCSI_HOST_PREFIX "/sys/class/scsi_host/"
 # define LINUX_SYSFS_SCSI_HOST_POSTFIX "device"
 # define LINUX_SYSFS_FC_HOST_PREFIX "/sys/class/fc_host/"
 
diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/node_device_linux_sysfs.c
index c90e72b..7f09cc7 100644
--- a/src/node_device/node_device_linux_sysfs.c
+++ b/src/node_device/node_device_linux_sysfs.c
@@ -119,7 +119,7 @@ int check_fc_host_linux(union _virNodeDevCapData *d)
 
     VIR_DEBUG("Checking if host%d is an FC HBA", d->scsi_host.host);
 
-    if (virAsprintf(&sysfs_path, "%s/host%d",
+    if (virAsprintf(&sysfs_path, "%shost%d",
                     LINUX_SYSFS_FC_HOST_PREFIX,
                     d->scsi_host.host) < 0) {
         virReportOOMError();
@@ -167,20 +167,39 @@ int check_vport_capable_linux(union _virNodeDevCapData *d)
     struct stat st;
     int retval = 0;
 
-    if (virAsprintf(&sysfs_path, "%s/host%d/vport_create",
+    if (virAsprintf(&sysfs_path,
+                    "%shost%d%s",
                     LINUX_SYSFS_FC_HOST_PREFIX,
-                    d->scsi_host.host) < 0) {
+                    d->scsi_host.host,
+                    LINUX_SYSFS_VPORT_CREATE_POSTFIX) < 0) {
         virReportOOMError();
         retval = -1;
         goto out;
     }
 
-    if (stat(sysfs_path, &st) != 0) {
-        /* Not a vport capable HBA; not an error, either. */
+    if (stat(sysfs_path, &st) == 0) {
+        d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
         goto out;
     }
 
-    d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
+    VIR_FREE(sysfs_path);
+    if (virAsprintf(&sysfs_path,
+                    "%shost%d%s",
+                    LINUX_SYSFS_SCSI_HOST_PREFIX,
+                    d->scsi_host.host,
+                    LINUX_SYSFS_VPORT_CREATE_POSTFIX) < 0) {
+        virReportOOMError();
+        retval = -1;
+        goto out;
+    }
+
+    if (stat(sysfs_path, &st) == 0) {
+        d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
+    } else {
+        /* Not a vport capable HBA; not an error, either. */
+        VIR_DEBUG("No vport operation path found for host%d",
+                  d->scsi_host.host);
+    }
 
 out:
     VIR_FREE(sysfs_path);
-- 
1.7.2

--
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]