[PATCH] scsi: Adjust return status from getBlockDevice

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

 



https://bugzilla.redhat.com/show_bug.cgi?id=1224233

Currently it's not possible to determine the difference between a
fatal memory allocation or failure to open/read the directory error
with a perhaps less fatal, I didn't find the "block" device in the
directory (which may be a disk entry without a block device).

In the case of the latter, we shouldn't cause failure to continue
searching in the caller (virStorageBackendSCSIFindLUs), rather we
should allow trying reading the next directory entry.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/storage/storage_backend_scsi.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
index e6c8bb5..c5105ec 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -329,6 +329,15 @@ getOldStyleBlockDevice(const char *lun_path ATTRIBUTE_UNUSED,
 }
 
 
+/*
+ * Search a device entry for the "block" file
+ *
+ * Returns
+ *
+ *   0 => Found it
+ *   -1 => Fatal error
+ *   -2 => Didn't find in lun_path directory
+ */
 static int
 getBlockDevice(uint32_t host,
                uint32_t bus,
@@ -354,6 +363,10 @@ getBlockDevice(uint32_t host,
         goto out;
     }
 
+    /* As long as virDirRead doesn't fail, if we fail to find the
+     * "block" file in this directory, allow caller to continue
+     */
+    retval = -2;
     while ((direrr = virDirRead(lun_dir, &lun_dirent, lun_path)) > 0) {
         if (STREQLEN(lun_dirent->d_name, "block", 5)) {
             if (strlen(lun_dirent->d_name) == 5) {
@@ -368,6 +381,9 @@ getBlockDevice(uint32_t host,
             break;
         }
     }
+    /* Keep retval = -2 unless there was a fatal error in virDirRead */
+    if (retval == -2 && direrr < 0)
+        retval = -1;
 
     closedir(lun_dir);
 
@@ -417,9 +433,9 @@ processLU(virStoragePoolObjPtr pool,
     VIR_DEBUG("%u:%u:%u:%u is a Direct-Access LUN",
               host, bus, target, lun);
 
-    if (getBlockDevice(host, bus, target, lun, &block_device) < 0) {
+    if ((retval = getBlockDevice(host, bus, target, lun, &block_device)) < 0) {
         VIR_DEBUG("Failed to find block device for this LUN");
-        return -1;
+        return retval;
     }
 
     retval = virStorageBackendSCSINewLun(pool, host, bus, target, lun,
-- 
2.1.0

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