]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
storage: Rework error paths for virStorageBackendCreateExecCommand
authorJohn Ferlan <jferlan@redhat.com>
Thu, 8 Oct 2015 17:48:14 +0000 (13:48 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 13 Oct 2015 22:03:55 +0000 (18:03 -0400)
Rework the code in order to use the "ret = -1;" and goto cleanup;
coding style.

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

index ad7a576fb78e3265f8a4723e5c45a54ac870cae2..a375fe0f514477eaef999027dad6664168610bfa 100644 (file)
@@ -679,6 +679,7 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool,
     uid_t uid;
     mode_t mode;
     bool filecreated = false;
+    int ret = -1;
 
     if ((pool->def->type == VIR_STORAGE_POOL_NETFS)
         && (((geteuid() == 0)
@@ -703,11 +704,11 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool,
 
     if (!filecreated) {
         if (virCommandRun(cmd, NULL) < 0)
-            return -1;
+            goto cleanup;
         if (stat(vol->target.path, &st) < 0) {
             virReportSystemError(errno,
                                  _("failed to create %s"), vol->target.path);
-            return -1;
+            goto cleanup;
         }
     }
 
@@ -721,7 +722,7 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool,
                              _("cannot chown %s to (%u, %u)"),
                              vol->target.path, (unsigned int) uid,
                              (unsigned int) gid);
-        return -1;
+        goto cleanup;
     }
 
     mode = (vol->target.perms->mode == (mode_t) -1 ?
@@ -730,9 +731,13 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool,
         virReportSystemError(errno,
                              _("cannot set mode of '%s' to %04o"),
                              vol->target.path, mode);
-        return -1;
+        goto cleanup;
     }
-    return 0;
+
+    ret = 0;
+
+ cleanup:
+    return ret;
 }
 
 enum {