[PATCH v3 2/4] refactor virStorageBackendSCSINewLun

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

 



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

diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
index 2a3e1e4..b96caec 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -154,14 +154,12 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
                             uint32_t lun,
                             const char *dev)
 {
-    virStorageVolDefPtr vol;
+    virStorageVolDefPtr vol = NULL;
     char *devpath = NULL;
-    int retval = 0;
+    int retval = -1;
 
-    if (VIR_ALLOC(vol) < 0) {
-        retval = -1;
-        goto out;
-    }
+    if (VIR_ALLOC(vol) < 0)
+        goto cleanup;
 
     vol->type = VIR_STORAGE_VOL_BLOCK;
 
@@ -170,15 +168,11 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
      * in the volume name. We only need uniqueness per-pool, so
      * just leave 'host' out
      */
-    if (virAsprintf(&(vol->name), "unit:%u:%u:%u", bus, target, lun) < 0) {
-        retval = -1;
-        goto free_vol;
-    }
+    if (virAsprintf(&(vol->name), "unit:%u:%u:%u", bus, target, lun) < 0)
+        goto cleanup;
 
-    if (virAsprintf(&devpath, "/dev/%s", dev) < 0) {
-        retval = -1;
-        goto free_vol;
-    }
+    if (virAsprintf(&devpath, "/dev/%s", dev) < 0)
+        goto cleanup;
 
     VIR_DEBUG("Trying to create volume for '%s'", devpath);
 
@@ -190,10 +184,8 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
      */
     if ((vol->target.path = virStorageBackendStablePath(pool,
                                                         devpath,
-                                                        true)) == NULL) {
-        retval = -1;
-        goto free_vol;
-    }
+                                                        true)) == NULL)
+        goto cleanup;
 
     if (STREQ(devpath, vol->target.path) &&
         !(STREQ(pool->def->target.path, "/dev") ||
@@ -202,34 +194,27 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
         VIR_DEBUG("No stable path found for '%s' in '%s'",
                   devpath, pool->def->target.path);
 
-        retval = -1;
-        goto free_vol;
+        goto cleanup;
     }
 
     if (virStorageBackendUpdateVolInfo(vol, true,
-                                       VIR_STORAGE_VOL_OPEN_DEFAULT) < 0) {
-        retval = -1;
-        goto free_vol;
-    }
+                                       VIR_STORAGE_VOL_OPEN_DEFAULT) < 0)
+        goto cleanup;
 
-    if (!(vol->key = virStorageBackendSCSISerial(vol->target.path))) {
-        retval = -1;
-        goto free_vol;
-    }
+    if (!(vol->key = virStorageBackendSCSISerial(vol->target.path)))
+        goto cleanup;
 
     pool->def->capacity += vol->target.capacity;
     pool->def->allocation += vol->target.allocation;
 
-    if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) {
-        retval = -1;
-        goto free_vol;
-    }
+    if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0)
+        goto cleanup;
 
-    goto out;
+    vol = NULL;
+    retval = 0;
 
- free_vol:
+ cleanup:
     virStorageVolDefFree(vol);
- out:
     VIR_FREE(devpath);
     return retval;
 }
-- 
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]