]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: Fix sysfs paths for vport operations
authorDave Allan <dallan@redhat.com>
Tue, 17 Aug 2010 15:21:16 +0000 (17:21 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 18 Aug 2010 15:32:31 +0000 (17:32 +0200)
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
src/node_device/node_device_driver.h
src/node_device/node_device_linux_sysfs.c

index b0ff662c5b07aef96bfdb27b9ede48efe0561a90..a6ac80bd9c3a74925a75dcaa032c373d69e8be40 100644 (file)
@@ -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,
index f2336419ad811045ccbc2f9cddf25252ac00d2b1..4721be4454242fec1201c2ba2d84d27cea0514c5 100644 (file)
@@ -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/"
 
index c90e72bc9dc57f0d1e0b68a001b8813e6abc2bba..7f09cc73e0dae2f485a886168fe1fb4d118d0fdd 100644 (file)
@@ -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);