[libvirt] [PATCH 1/1] Add trigger of host rescan

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

 



The scsi host code does not currently rescan for new LUs when refreshing a pool.  This patch causes a scan for new LUs on all targets.  It does not cause a LIP.
---
 src/storage_backend_scsi.c |   77 ++++++++++++++++++++++++++++++++++++++++++++
 src/storage_backend_scsi.h |    1 +
 2 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/src/storage_backend_scsi.c b/src/storage_backend_scsi.c
index a962d1c..e30b3ce 100644
--- a/src/storage_backend_scsi.c
+++ b/src/storage_backend_scsi.c
@@ -480,6 +480,76 @@ out:
 
 
 static int
+virStorageBackendSCSIStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
+                               virStoragePoolObjPtr pool ATTRIBUTE_UNUSED)
+{
+    int retval = 0;
+
+    return retval;
+}
+
+
+static int
+virStorageBackendSCSIStopPool(virConnectPtr conn ATTRIBUTE_UNUSED,
+                              virStoragePoolObjPtr pool ATTRIBUTE_UNUSED)
+{
+    int retval = 0;
+
+    return retval;
+}
+
+
+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 cleanup;
+    }
+
+    if (write(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;
+        goto cleanup;
+    }
+
+    goto out;
+
+cleanup:
+    VIR_FREE(path);
+
+out:
+    VIR_DEBUG(_("Rescan of host %d complete"), host);
+    return retval;
+}
+
+
+static int
 virStorageBackendSCSIRefreshPool(virConnectPtr conn,
                                  virStoragePoolObjPtr pool)
 {
@@ -496,6 +566,11 @@ virStorageBackendSCSIRefreshPool(virConnectPtr conn,
 
     VIR_DEBUG(_("Scanning host%u"), host);
 
+    if (virStorageBackendSCSITriggerRescan(conn, host) < 0) {
+        retval = -1;
+        goto out;
+    }
+
     virStorageBackendSCSIFindLUs(conn, pool, host);
 
 out:
@@ -506,5 +581,7 @@ out:
 virStorageBackend virStorageBackendSCSI = {
     .type = VIR_STORAGE_POOL_SCSI,
 
+    .startPool = virStorageBackendSCSIStartPool,
     .refreshPool = virStorageBackendSCSIRefreshPool,
+    .stopPool = virStorageBackendSCSIStopPool,
 };
diff --git a/src/storage_backend_scsi.h b/src/storage_backend_scsi.h
index 808d47b..d130086 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;
 
-- 
1.6.0.6

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