nodedev: Fix sysfs paths for vport operations

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.
This commit is contained in:
Dave Allan 2010-08-17 17:21:16 +02:00 committed by Jiri Denemark
parent 8ebda73609
commit b31ef77313
3 changed files with 47 additions and 7 deletions

View 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,

View 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/"

View 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;
}
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);