]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Rework logic in virStorageBackendDiskBuildPool
authorJohn Ferlan <jferlan@redhat.com>
Tue, 12 Feb 2019 02:29:29 +0000 (21:29 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 12 Feb 2019 13:51:23 +0000 (08:51 -0500)
Rework the logic to remove the need for the @ok_to_mklabel boolean.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/storage/storage_backend_disk.c

index 061c494b7dadeea75125d12de4a46db2f340d114..abbe1c3e8ba111c0476637b74fa692dfe05853c3 100644 (file)
@@ -502,7 +502,6 @@ virStorageBackendDiskBuildPool(virStoragePoolObjPtr pool,
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
     int format = def->source.format;
     const char *fmt;
-    bool ok_to_mklabel = false;
     int ret = -1;
     virCommandPtr cmd = NULL;
 
@@ -514,35 +513,31 @@ virStorageBackendDiskBuildPool(virStoragePoolObjPtr pool,
                              error);
 
     fmt = virStoragePoolFormatDiskTypeToString(format);
-    if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) {
-        ok_to_mklabel = true;
-    } else {
-        if (virStorageBackendDeviceIsEmpty(def->source.devices[0].path,
-                                           fmt, true))
-            ok_to_mklabel = true;
-    }
 
-    if (ok_to_mklabel) {
-        if (virStorageBackendZeroPartitionTable(def->source.devices[0].path,
-                                                1024 * 1024) < 0)
-            goto error;
+    if (!(flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) &&
+        !(virStorageBackendDeviceIsEmpty(def->source.devices[0].path,
+                                         fmt, true)))
+        goto error;
 
-        /* eg parted /dev/sda mklabel --script msdos */
-        if (format == VIR_STORAGE_POOL_DISK_UNKNOWN)
-            format = def->source.format = VIR_STORAGE_POOL_DISK_DOS;
-        if (format == VIR_STORAGE_POOL_DISK_DOS)
-            fmt = "msdos";
-        else
-            fmt = virStoragePoolFormatDiskTypeToString(format);
-
-        cmd = virCommandNewArgList(PARTED,
-                                   def->source.devices[0].path,
-                                   "mklabel",
-                                   "--script",
-                                   fmt,
-                                   NULL);
-        ret = virCommandRun(cmd, NULL);
-    }
+    if (virStorageBackendZeroPartitionTable(def->source.devices[0].path,
+                                            1024 * 1024) < 0)
+        goto error;
+
+    /* eg parted /dev/sda mklabel --script msdos */
+    if (format == VIR_STORAGE_POOL_DISK_UNKNOWN)
+        format = def->source.format = VIR_STORAGE_POOL_DISK_DOS;
+    if (format == VIR_STORAGE_POOL_DISK_DOS)
+        fmt = "msdos";
+    else
+        fmt = virStoragePoolFormatDiskTypeToString(format);
+
+    cmd = virCommandNewArgList(PARTED,
+                               def->source.devices[0].path,
+                               "mklabel",
+                               "--script",
+                               fmt,
+                               NULL);
+    ret = virCommandRun(cmd, NULL);
 
  error:
     virCommandFree(cmd);