[libvirt] [PATCH 5/7] storage: Create helper to set input for CreateQemuImg code

John Ferlan jferlan at redhat.com
Fri Jun 3 10:42:10 UTC 2016


Create helper virStorageBackendCreateQemuImgSetInput to set the input

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/storage/storage_backend.c | 50 +++++++++++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 4c40e43..4a3c41d 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -943,6 +943,7 @@ struct _virStorageBackendQemuImgInfo {
     int backingFormat;
 
     const char *inputPath;
+    const char *inputType;
     int inputFormat;
 };
 
@@ -1039,6 +1040,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->inputType =
+          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
  */
@@ -1054,7 +1081,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,
@@ -1095,23 +1121,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;
@@ -1180,7 +1192,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
     }
 
     if (info.inputPath)
-        virCommandAddArgList(cmd, "convert", "-f", inputType, "-O", type, NULL);
+        virCommandAddArgList(cmd, "convert", "-f", info.inputType, "-O", type, NULL);
     else
         virCommandAddArgList(cmd, "create", "-f", type, NULL);
 
-- 
2.5.5




More information about the libvir-list mailing list