https://bugzilla.redhat.com/show_bug.cgi?id=1373711 When using pool-create --build or pool-define and pool-build to create/define and build/initialize the logical pool, the 'pvcreate' command could fail if some previous attempt had been used on the source path previously. So add support for the --override option in order to force usage of the magic override option "-ff" and the option "-y" in order to force creation and answer any questions with yes. NB: Although the reality is part of the process of building the logical pool involves wiping out the first 512 bytes of the disk block to be added (e.g. the partition table) because pvcreate requires that. So, to a degree the device being added is already altered. I suspect the knowlege of whether the disk was in a vg already could be contained outside the range of the first 512 bytes. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/storage/storage_backend_logical.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index ca05fe1..9c76156 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -682,13 +682,18 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, unsigned int flags) { - virCommandPtr vgcmd; + virCommandPtr vgcmd = NULL; int fd; char zeros[PV_BLANK_SECTOR_SIZE]; int ret = -1; size_t i; - 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); memset(zeros, 0, sizeof(zeros)); @@ -731,10 +736,21 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, /* * Initialize the physical volume because vgcreate is not * clever enough todo this for us :-( + * + * If this API is called twice for the same device, then because + * vgcmd adds the device to the volume group, the pvcreate will + * fail since the pv is already part of the vg. Allow use of the + * override option inorder to overrule! */ - pvcmd = virCommandNewArgList(PVCREATE, - pool->def->source.devices[i].path, - NULL); + if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) + pvcmd = virCommandNewArgList(PVCREATE, + "-ff", "-y", + pool->def->source.devices[i].path, + NULL); + else + pvcmd = virCommandNewArgList(PVCREATE, + pool->def->source.devices[i].path, + NULL); if (virCommandRun(pvcmd, NULL) < 0) { virCommandFree(pvcmd); goto cleanup; -- 2.7.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list