[libvirt] [PATCH v2 2/6] iscsi: Fix exit path for virStorageBackendISCSIFindLUs failure

John Ferlan jferlan at redhat.com
Wed Apr 1 17:29:07 UTC 2015


If the call to virStorageBackendISCSIGetHostNumber failed, we set
retval = -1, but yet still called virStorageBackendSCSIFindLUs.
Need to add a goto cleanup - while at it, adjust the logic to
initialize retval to -1 and only changed to 0 (zero) on success.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/storage/storage_backend_iscsi.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index 48f0957..fba037f 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -131,23 +131,27 @@ virStorageBackendISCSIFindLUs(virStoragePoolObjPtr pool,
                               const char *session)
 {
     char *sysfs_path;
-    int retval = 0;
+    int retval = -1;
     uint32_t host;
 
     if (virAsprintf(&sysfs_path,
                     "/sys/class/iscsi_session/session%s/device", session) < 0)
-        return -1;
+        goto cleanup;
 
     if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0) {
         virReportSystemError(errno,
                              _("Failed to get host number for iSCSI session "
                                "with path '%s'"),
                              sysfs_path);
-        retval = -1;
+        goto cleanup;
     }
 
     if (virStorageBackendSCSIFindLUs(pool, host) < 0)
-        retval = -1;
+        goto cleanup;
+
+    retval = 0;
+
+ cleanup:
 
     VIR_FREE(sysfs_path);
 
-- 
2.1.0




More information about the libvir-list mailing list