From e1e1fcf7695fd75abf33d136922ffd5aee75a9e7 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Mon, 7 May 2018 15:34:26 -0400 Subject: [PATCH] storage_util: Introduce storageBackendCreateQemuImgSetInput Split up virStorageBackendCreateQemuImgCmdFromVol into two parts. It's too long anyway and virStorageBackendCreateQemuImgCmdFromVol should just handle the command line processing. NB: Requires changing info.* into info->* references. Signed-off-by: John Ferlan --- src/storage/storage_util.c | 114 +++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 50 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index c28f427a1a..f7da6743b0 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -1116,91 +1116,105 @@ storageBackendResizeQemuImgImageOpts(virCommandPtr cmd, } -/* Create a qemu-img virCommand from the supplied arguments */ -virCommandPtr -virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool, - virStorageVolDefPtr vol, - virStorageVolDefPtr inputvol, - unsigned int flags, - const char *create_tool, - const char *secretPath) +static int +virStorageBackendCreateQemuImgSetInfo(virStoragePoolObjPtr pool, + virStorageVolDefPtr vol, + virStorageVolDefPtr inputvol, + struct _virStorageBackendQemuImgInfo *info) { - virCommandPtr cmd = NULL; - struct _virStorageBackendQemuImgInfo info = { - .format = vol->target.format, - .type = NULL, - .path = vol->target.path, - .allocation = vol->target.allocation, - .encryption = !!vol->target.encryption, - .preallocate = !!(flags & VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA), - .compat = vol->target.compat, - .features = vol->target.features, - .nocow = vol->target.nocow, - .secretPath = secretPath, - .secretAlias = NULL, - }; - virStorageEncryptionInfoDefPtr enc = NULL; - - virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL); - /* Treat output block devices as 'raw' format */ if (vol->type == VIR_STORAGE_VOL_BLOCK) - info.format = VIR_STORAGE_FILE_RAW; + info->format = VIR_STORAGE_FILE_RAW; - if (info.format == VIR_STORAGE_FILE_ISO) - info.format = VIR_STORAGE_FILE_RAW; + if (info->format == VIR_STORAGE_FILE_ISO) + info->format = VIR_STORAGE_FILE_RAW; - if (!(info.type = virStorageFileFormatTypeToString(info.format))) { + if (!(info->type = virStorageFileFormatTypeToString(info->format))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown storage vol type %d"), - info.format); - return NULL; + info->format); + return -1; } - if (info.preallocate && info.format != VIR_STORAGE_FILE_QCOW2) { + if (info->preallocate && info->format != VIR_STORAGE_FILE_QCOW2) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("metadata preallocation only available with qcow2")); - return NULL; + return -1; } - if (info.compat && info.format != VIR_STORAGE_FILE_QCOW2) { + if (info->compat && info->format != VIR_STORAGE_FILE_QCOW2) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("compatibility option only available with qcow2")); - return NULL; + return -1; } - if (info.features && info.format != VIR_STORAGE_FILE_QCOW2) { + if (info->features && info->format != VIR_STORAGE_FILE_QCOW2) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("format features only available with qcow2")); - return NULL; + return -1; } - if (info.format == VIR_STORAGE_FILE_RAW && vol->target.encryption) { + if (info->format == VIR_STORAGE_FILE_RAW && vol->target.encryption) { if (inputvol) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("cannot use inputvol with encrypted raw volume")); - return NULL; + return -1; } if (vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) { - info.type = "luks"; + info->type = "luks"; } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Only luks encryption is supported for raw files")); - return NULL; + return -1; } } if (inputvol && - storageBackendCreateQemuImgSetInput(inputvol, &info) < 0) - return NULL; + storageBackendCreateQemuImgSetInput(inputvol, info) < 0) + return -1; if (virStorageSourceHasBacking(&vol->target) && - storageBackendCreateQemuImgSetBacking(pool, vol, inputvol, &info) < 0) - return NULL; + storageBackendCreateQemuImgSetBacking(pool, vol, inputvol, info) < 0) + return -1; - if (info.encryption && - storageBackendCreateQemuImgCheckEncryption(info.format, info.type, vol) < 0) - return NULL; + if (info->encryption && + storageBackendCreateQemuImgCheckEncryption(info->format, info->type, + vol) < 0) + return -1; /* Size in KB */ - info.size_arg = VIR_DIV_UP(vol->target.capacity, 1024); + info->size_arg = VIR_DIV_UP(vol->target.capacity, 1024); + + return 0; +} + + +/* Create a qemu-img virCommand from the supplied arguments */ +virCommandPtr +virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool, + virStorageVolDefPtr vol, + virStorageVolDefPtr inputvol, + unsigned int flags, + const char *create_tool, + const char *secretPath) +{ + virCommandPtr cmd = NULL; + struct _virStorageBackendQemuImgInfo info = { + .format = vol->target.format, + .type = NULL, + .path = vol->target.path, + .allocation = vol->target.allocation, + .encryption = !!vol->target.encryption, + .preallocate = !!(flags & VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA), + .compat = vol->target.compat, + .features = vol->target.features, + .nocow = vol->target.nocow, + .secretPath = secretPath, + .secretAlias = NULL, + }; + virStorageEncryptionInfoDefPtr enc = NULL; + + virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL); + + if (virStorageBackendCreateQemuImgSetInfo(pool, vol, inputvol, &info) < 0) + goto error; cmd = virCommandNew(create_tool); -- GitLab