From f573f84eb732d143ca3cd963f180ec1ef7d1076f Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Thu, 15 Dec 2016 08:39:13 -0500 Subject: [PATCH] storage: Add overwrite flag checking for logical pool https://bugzilla.redhat.com/show_bug.cgi?id=1373711 Add support and documentation for the [NO_]OVERWRITE flags for the logical backend. Update virsh.pod with a description of the process for usage of the flags and building of the pool's volume group. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 1 + src/storage/storage_backend_logical.c | 18 +++++++++++++++--- tools/virsh.pod | 12 +++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b69e8bcc25..4d16620b4e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -887,6 +887,7 @@ virStoragePoolFormatDiskTypeFromString; virStoragePoolFormatDiskTypeToString; virStoragePoolFormatFileSystemNetTypeToString; virStoragePoolFormatFileSystemTypeToString; +virStoragePoolFormatLogicalTypeToString; virStoragePoolGetVhbaSCSIHostParent; virStoragePoolLoadAllConfigs; virStoragePoolLoadAllState; diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 2d8e288d99..6a6720e220 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -759,17 +759,29 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, unsigned int flags) { - virCommandPtr vgcmd; + virCommandPtr vgcmd = NULL; int ret = -1; - size_t i; + size_t i = 0; - virCheckFlags(0, -1); + virCheckFlags(VIR_STORAGE_POOL_BUILD_OVERWRITE | + VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, ret); + + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_STORAGE_POOL_BUILD_OVERWRITE, + VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, + cleanup); vgcmd = virCommandNewArgList(VGCREATE, pool->def->source.name, NULL); for (i = 0; i < pool->def->source.ndevice; i++) { const char *path = pool->def->source.devices[i].path; + /* The blkid FS and Part probing code doesn't know "lvm2" (this + * pool's only format type), but it does know "LVM2_member", so + * we'll pass that here */ + if (!(flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) && + !virStorageBackendDeviceIsEmpty(path, "LVM2_member", true)) + goto cleanup; + if (virStorageBackendLogicalInitializeDevice(path) < 0) goto cleanup; diff --git a/tools/virsh.pod b/tools/virsh.pod index f5990c76b8..b95d67f661 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3466,7 +3466,7 @@ Configure whether I should automatically start at boot. Build a given pool. Options I<--overwrite> and I<--no-overwrite> can only be used for -B a filesystem or disk pool. +B a filesystem, disk, or logical pool. For a file system pool if neither flag is specified, then B just makes the target path directory and no attempt to run mkfs on the @@ -3485,6 +3485,16 @@ then no check will be made on the target volume device prior to writing a new label. Writing of the label uses the pool source format type or "dos" if not specified. +For a logical pool, if neither of them is specified or I<--no-overwrite> +is specified, B will check the target volume devices for +existing filesystems or partitions before attempting to initialize +and format each device for usage by the logical pool. If any target +volume device already has a label, the command will fail. If +I<--overwrite> is specified, then no check will be made on the target +volume devices prior to initializing and formatting each device. Once +all the target volume devices are properly formatted via pvcreate, +the volume group will be created using all the devices. + =item B I [I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]]