]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
storage: Refactor virStorageBackendSCSINewLun
authorJohn Ferlan <jferlan@redhat.com>
Tue, 7 Apr 2015 17:39:01 +0000 (13:39 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 16 Apr 2015 16:28:04 +0000 (12:28 -0400)
Invert the logical of retval and clean up code paths, especially goto's

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/storage/storage_backend_scsi.c

index 2a3e1e489616e924175ef8f3f3ce404b8fc8c95f..b96caecf452de822cef2a3a6165bfd4dbbb3fcf7 100644 (file)
@@ -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;
 }