mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 20:51:26 +00:00
storage: Rework logic in virStorageBackendDiskBuildPool
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>
This commit is contained in:
parent
1587ba7f62
commit
7550480036
@ -502,7 +502,6 @@ virStorageBackendDiskBuildPool(virStoragePoolObjPtr pool,
|
|||||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||||
int format = def->source.format;
|
int format = def->source.format;
|
||||||
const char *fmt;
|
const char *fmt;
|
||||||
bool ok_to_mklabel = false;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
|
|
||||||
@ -514,35 +513,31 @@ virStorageBackendDiskBuildPool(virStoragePoolObjPtr pool,
|
|||||||
error);
|
error);
|
||||||
|
|
||||||
fmt = virStoragePoolFormatDiskTypeToString(format);
|
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 (!(flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) &&
|
||||||
if (virStorageBackendZeroPartitionTable(def->source.devices[0].path,
|
!(virStorageBackendDeviceIsEmpty(def->source.devices[0].path,
|
||||||
1024 * 1024) < 0)
|
fmt, true)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* eg parted /dev/sda mklabel --script msdos */
|
if (virStorageBackendZeroPartitionTable(def->source.devices[0].path,
|
||||||
if (format == VIR_STORAGE_POOL_DISK_UNKNOWN)
|
1024 * 1024) < 0)
|
||||||
format = def->source.format = VIR_STORAGE_POOL_DISK_DOS;
|
goto error;
|
||||||
if (format == VIR_STORAGE_POOL_DISK_DOS)
|
|
||||||
fmt = "msdos";
|
|
||||||
else
|
|
||||||
fmt = virStoragePoolFormatDiskTypeToString(format);
|
|
||||||
|
|
||||||
cmd = virCommandNewArgList(PARTED,
|
/* eg parted /dev/sda mklabel --script msdos */
|
||||||
def->source.devices[0].path,
|
if (format == VIR_STORAGE_POOL_DISK_UNKNOWN)
|
||||||
"mklabel",
|
format = def->source.format = VIR_STORAGE_POOL_DISK_DOS;
|
||||||
"--script",
|
if (format == VIR_STORAGE_POOL_DISK_DOS)
|
||||||
fmt,
|
fmt = "msdos";
|
||||||
NULL);
|
else
|
||||||
ret = virCommandRun(cmd, NULL);
|
fmt = virStoragePoolFormatDiskTypeToString(format);
|
||||||
}
|
|
||||||
|
cmd = virCommandNewArgList(PARTED,
|
||||||
|
def->source.devices[0].path,
|
||||||
|
"mklabel",
|
||||||
|
"--script",
|
||||||
|
fmt,
|
||||||
|
NULL);
|
||||||
|
ret = virCommandRun(cmd, NULL);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user