[PATCH 7/7] storage: Create helper to set options for CreateQemuImg code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Create a helper virStorageBackendCreateQemuImgSetOptions to set either
the qemu-img -o options or the previous mechanism using -F

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/storage/storage_backend.c | 58 ++++++++++++++++++++++++++-----------------
 1 file changed, 35 insertions(+), 23 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 624790f..a12480f 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -1126,6 +1126,38 @@ virStorageBackendCreateQemuImgSetBacking(virStoragePoolObjPtr pool,
 }
 
 
+static int
+virStorageBackendCreateQemuImgSetOptions(virCommandPtr cmd,
+                                         int imgformat,
+                                         struct _virStorageBackendQemuImgInfo info)
+{
+    char *opts = NULL;
+
+    if (imgformat >= QEMU_IMG_BACKING_FORMAT_OPTIONS) {
+        if (info.format == VIR_STORAGE_FILE_QCOW2 && !info.compat &&
+            imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT)
+            info.compat = "0.10";
+
+        if (virStorageBackendCreateQemuImgOpts(&opts, info) < 0)
+            return -1;
+        if (opts)
+            virCommandAddArgList(cmd, "-o", opts, NULL);
+        VIR_FREE(opts);
+    } else {
+        if (info.backingPath) {
+            if (imgformat == X_QEMU_IMG_BACKING_FORMAT_FLAG)
+                virCommandAddArgList(cmd, "-F", info.backingType, NULL);
+            else
+                VIR_DEBUG("Unable to set backing store format for %s",
+                          info.path);
+        }
+        if (info.encryption)
+            virCommandAddArg(cmd, "-e");
+    }
+
+    return 0;
+}
+
 
 /* Create a qemu-img virCommand from the supplied binary path,
  * volume definitions and imgformat
@@ -1141,7 +1173,6 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
 {
     virCommandPtr cmd = NULL;
     const char *type;
-    char *opts = NULL;
     struct _virStorageBackendQemuImgInfo info = {
         .format = vol->target.format,
         .path = vol->target.path,
@@ -1215,28 +1246,9 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
     if (info.backingPath)
         virCommandAddArgList(cmd, "-b", info.backingPath, NULL);
 
-    if (imgformat >= QEMU_IMG_BACKING_FORMAT_OPTIONS) {
-        if (info.format == VIR_STORAGE_FILE_QCOW2 && !info.compat &&
-            imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT)
-            info.compat = "0.10";
-
-        if (virStorageBackendCreateQemuImgOpts(&opts, info) < 0) {
-            virCommandFree(cmd);
-            return NULL;
-        }
-        if (opts)
-            virCommandAddArgList(cmd, "-o", opts, NULL);
-        VIR_FREE(opts);
-    } else {
-        if (info.backingPath) {
-            if (imgformat == X_QEMU_IMG_BACKING_FORMAT_FLAG)
-                virCommandAddArgList(cmd, "-F", info.backingType, NULL);
-            else
-                VIR_DEBUG("Unable to set backing store format for %s with %s",
-                          info.path, create_tool);
-        }
-        if (info.encryption)
-            virCommandAddArg(cmd, "-e");
+    if (virStorageBackendCreateQemuImgSetOptions(cmd, imgformat, info) < 0) {
+        virCommandFree(cmd);
+        return NULL;
     }
 
     if (info.inputPath)
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]