Refactor to extract out the LVCREATE command. This also removes the need for the local @created since the error path can now only be reached after the creation of the logical volume. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/storage/storage_backend_logical.c | 65 +++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index a872a2f881..93f4e0a595 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -938,30 +938,11 @@ virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, static int -virStorageBackendLogicalCreateVol(virConnectPtr conn, - virStoragePoolObjPtr pool, - virStorageVolDefPtr vol) +virStorageBackendLogicalLVCreate(virStorageVolDefPtr vol, + virStoragePoolDefPtr def) { - int fd = -1; - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + int ret; virCommandPtr cmd = NULL; - virErrorPtr err; - struct stat sb; - bool created = false; - - if (vol->target.encryption != NULL) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - "%s", _("storage pool does not support encrypted " - "volumes")); - return -1; - } - - vol->type = VIR_STORAGE_VOL_BLOCK; - - VIR_FREE(vol->target.path); - if (virAsprintf(&vol->target.path, "%s/%s", - def->target.path, vol->name) < 0) - return -1; cmd = virCommandNewArgList(LVCREATE, "--name", vol->name, @@ -982,12 +963,38 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, else virCommandAddArg(cmd, def->source.name); - if (virCommandRun(cmd, NULL) < 0) - goto error; - - created = true; + ret = virCommandRun(cmd, NULL); virCommandFree(cmd); - cmd = NULL; + return ret; +} + + +static int +virStorageBackendLogicalCreateVol(virConnectPtr conn, + virStoragePoolObjPtr pool, + virStorageVolDefPtr vol) +{ + int fd = -1; + virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virErrorPtr err; + struct stat sb; + + if (vol->target.encryption != NULL) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("storage pool does not support encrypted " + "volumes")); + return -1; + } + + vol->type = VIR_STORAGE_VOL_BLOCK; + + VIR_FREE(vol->target.path); + if (virAsprintf(&vol->target.path, "%s/%s", + def->target.path, vol->name) < 0) + return -1; + + if (virStorageBackendLogicalLVCreate(vol, def) < 0) + return -1; if ((fd = virStorageBackendVolOpen(vol->target.path, &sb, VIR_STORAGE_VOL_OPEN_DEFAULT)) < 0) @@ -1031,9 +1038,7 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, error: err = virSaveLastError(); VIR_FORCE_CLOSE(fd); - if (created) - virStorageBackendLogicalDeleteVol(conn, pool, vol, 0); - virCommandFree(cmd); + virStorageBackendLogicalDeleteVol(conn, pool, vol, 0); virSetError(err); virFreeError(err); return -1; -- 2.13.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list