From b2df3510b76520030446c2c9e10322759fd93a63 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 7 Apr 2009 12:50:17 +0000 Subject: [PATCH] * src/storage_backend_scsi.[ch]: add SCSI storage rescan support, patch by David Allan daniel --- ChangeLog | 5 ++++ src/storage_backend_scsi.c | 55 +++++++++++++++++++++++++++++++++++++- src/storage_backend_scsi.h | 1 + 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5142416394..420d425d2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Apr 7 14:48:35 CEST 2009 Daniel Veillard + + * src/storage_backend_scsi.[ch]: add SCSI storage rescan support, + patch by David Allan + Fri Apr 3 16:47:22 CEST 2009 Daniel Veillard * configure.in libvirt.spec.in NEWS docs/*: release of 0.6.2 diff --git a/src/storage_backend_scsi.c b/src/storage_backend_scsi.c index b3e6180cb6..1d2378b5b2 100644 --- a/src/storage_backend_scsi.c +++ b/src/storage_backend_scsi.c @@ -565,6 +565,53 @@ out: } +static int +virStorageBackendSCSITriggerRescan(virConnectPtr conn, + uint32_t host) +{ + int fd = -1; + int retval = 0; + char *path; + + VIR_DEBUG(_("Triggering rescan of host %d"), host); + + if (virAsprintf(&path, "/sys/class/scsi_host/host%u/scan", host) < 0) { + virReportOOMError(conn); + retval = -1; + goto out; + } + + VIR_DEBUG(_("Scan trigger path is '%s'"), path); + + fd = open(path, O_WRONLY); + + if (fd < 0) { + virReportSystemError(conn, errno, + _("Could not open '%s' to trigger host scan"), + path); + retval = -1; + goto free_path; + } + + if (safewrite(fd, + LINUX_SYSFS_SCSI_HOST_SCAN_STRING, + sizeof(LINUX_SYSFS_SCSI_HOST_SCAN_STRING)) < 0) { + + virReportSystemError(conn, errno, + _("Write to '%s' to trigger host scan failed"), + path); + retval = -1; + } + + close(fd); +free_path: + VIR_FREE(path); +out: + VIR_DEBUG(_("Rescan of host %d complete"), host); + return retval; +} + + static int virStorageBackendSCSIRefreshPool(virConnectPtr conn, virStoragePoolObjPtr pool) @@ -575,13 +622,19 @@ virStorageBackendSCSIRefreshPool(virConnectPtr conn, pool->def->allocation = pool->def->capacity = pool->def->available = 0; if (sscanf(pool->def->source.adapter, "host%u", &host) != 1) { - VIR_DEBUG(_("Failed to get host number from '%s'"), pool->def->source.adapter); + VIR_DEBUG(_("Failed to get host number from '%s'"), + pool->def->source.adapter); retval = -1; goto out; } VIR_DEBUG(_("Scanning host%u"), host); + if (virStorageBackendSCSITriggerRescan(conn, host) < 0) { + retval = -1; + goto out; + } + virStorageBackendSCSIFindLUs(conn, pool, host); out: diff --git a/src/storage_backend_scsi.h b/src/storage_backend_scsi.h index 808d47bad7..d13008691e 100644 --- a/src/storage_backend_scsi.h +++ b/src/storage_backend_scsi.h @@ -28,6 +28,7 @@ #define LINUX_SYSFS_SCSI_HOST_PREFIX "/sys/class/scsi_host" #define LINUX_SYSFS_SCSI_HOST_POSTFIX "device" +#define LINUX_SYSFS_SCSI_HOST_SCAN_STRING "- - -" extern virStorageBackend virStorageBackendSCSI;