[libvirt] [PATCH 2/2] storage: Polling the sysfs for pool with "fc_host" type adapter

Osier Yang jyang at redhat.com
Mon Jan 6 10:19:35 UTC 2014


The SCSI device corresponding to the vHBA might not show up in
sysfs yet when we trying to scan the LUNs. As a result, we will
end up with an empty volume set for the pool after pool-start,
even if there are LUNs.

Though the time of the device showing up is rather depended,
better than doing nothing, this patch introduces the polling
with 5 * 1 seconds in maximum (the time works fine on my
testing machine at least). Note that for the pool which doesn't
have any LUN, it will still take 5 seconds to poll, but it's
not a bad trade, 5 seconds is not much, and in most cases,
one won't use an empty pool in practice.
---
 src/storage/storage_backend_scsi.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
index 93039c1..2efcdb8 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -495,6 +495,8 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
     DIR *devicedir = NULL;
     struct dirent *lun_dirent = NULL;
     char devicepattern[64];
+    bool found = false;
+    size_t i = 0;
 
     VIR_DEBUG("Discovering LUs on host %u", scanhost);
 
@@ -510,6 +512,7 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
 
     snprintf(devicepattern, sizeof(devicepattern), "%u:%%u:%%u:%%u\n", scanhost);
 
+retry:
     while ((lun_dirent = readdir(devicedir))) {
         if (sscanf(lun_dirent->d_name, devicepattern,
                    &bus, &target, &lun) != 3) {
@@ -518,9 +521,22 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
 
         VIR_DEBUG("Found LU '%s'", lun_dirent->d_name);
 
+        found = true;
         processLU(pool, scanhost, bus, target, lun);
     }
 
+    /* Sleep for 5 seconds in maximum if the pool's source
+     * adapter type is "fc_host", since the corresponding
+     * SCSI device might not show up in the sysfs yet.
+     */
+    if (!found && i++ < 5 &&
+        pool->def->source.adapter.type ==
+        VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) {
+        sleep(1);
+        rewinddir(devicedir);
+        goto retry;
+    }
+
     closedir(devicedir);
 
     return retval;
-- 
1.8.1.4




More information about the libvir-list mailing list