From 77ad76b615453d0d54e45481ec16be45541aa0ee Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Thu, 2 Jun 2016 07:46:32 -0400 Subject: [PATCH] storage: Create helper to set input for CreateQemuImg code Create helper virStorageBackendCreateQemuImgSetInput to set the input Signed-off-by: John Ferlan --- src/storage/storage_backend.c | 51 ++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 207615517f..8f03a6ec87 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -961,6 +961,7 @@ struct _virStorageBackendQemuImgInfo { int backingFormat; const char *inputPath; + const char *inputFormatStr; int inputFormat; }; @@ -1057,6 +1058,32 @@ virStorageBackendCreateQemuImgCheckEncryption(int format, } +static int +virStorageBackendCreateQemuImgSetInput(virStorageVolDefPtr inputvol, + struct _virStorageBackendQemuImgInfo *info) +{ + if (!(info->inputPath = inputvol->target.path)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing input volume target path")); + return -1; + } + + info->inputFormat = inputvol->target.format; + if (inputvol->type == VIR_STORAGE_VOL_BLOCK) + info->inputFormat = VIR_STORAGE_FILE_RAW; + if (!(info->inputFormatStr = + virStorageFileFormatTypeToString(info->inputFormat))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unknown storage vol type %d"), + info->inputFormat); + return -1; + } + + return 0; +} + + + /* Create a qemu-img virCommand from the supplied binary path, * volume definitions and imgformat */ @@ -1072,7 +1099,6 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, virCommandPtr cmd = NULL; const char *type; const char *backingType = NULL; - const char *inputType = NULL; char *opts = NULL; struct _virStorageBackendQemuImgInfo info = { .format = vol->target.format, @@ -1113,23 +1139,9 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, return NULL; } - if (inputvol) { - if (!(info.inputPath = inputvol->target.path)) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing input volume target path")); - return NULL; - } - - info.inputFormat = inputvol->target.format; - if (inputvol->type == VIR_STORAGE_VOL_BLOCK) - info.inputFormat = VIR_STORAGE_FILE_RAW; - if (!(inputType = virStorageFileFormatTypeToString(info.inputFormat))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unknown storage vol type %d"), - info.inputFormat); - return NULL; - } - } + if (inputvol && + virStorageBackendCreateQemuImgSetInput(inputvol, &info) < 0) + return NULL; if (vol->target.backingStore) { int accessRetCode = -1; @@ -1198,7 +1210,8 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, } if (info.inputPath) - virCommandAddArgList(cmd, "convert", "-f", inputType, "-O", type, NULL); + virCommandAddArgList(cmd, "convert", "-f", info.inputFormatStr, + "-O", type, NULL); else virCommandAddArgList(cmd, "create", "-f", type, NULL); -- 2.47.2