[PATCH 5/8] storage: add support for creating qcow2 images with extensions

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

 



Add -o compat= and -o lazy_refcounts options for qemu-img.
---
 src/storage/storage_backend.c                   | 36 +++++++++++++++++++++++--
 tests/storagevolxml2argvdata/qcow2-1.1.argv     |  1 +
 tests/storagevolxml2argvdata/qcow2-lazy.argv    |  1 +
 tests/storagevolxml2argvdata/vol-qcow2-1.1.xml  | 32 ++++++++++++++++++++++
 tests/storagevolxml2argvdata/vol-qcow2-lazy.xml | 35 ++++++++++++++++++++++++
 tests/storagevolxml2argvtest.c                  |  2 ++
 6 files changed, 105 insertions(+), 2 deletions(-)
 create mode 100644 tests/storagevolxml2argvdata/qcow2-1.1.argv
 create mode 100644 tests/storagevolxml2argvdata/qcow2-lazy.argv
 create mode 100644 tests/storagevolxml2argvdata/vol-qcow2-1.1.xml
 create mode 100644 tests/storagevolxml2argvdata/vol-qcow2-lazy.xml

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index ab249b4..55a4b1f 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -639,9 +639,15 @@ static int
 virStorageBackendCreateQemuImgOpts(char **opts,
                                    const char *backingType,
                                    bool encryption,
-                                   bool preallocate)
+                                   bool preallocate,
+                                   int format,
+                                   const char *compat,
+                                   virBitmapPtr features)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
+    bool b;
+    int i;
+
     if (backingType)
         virBufferAsprintf(&buf, "backing_fmt=%s,", backingType);
     if (encryption)
@@ -649,6 +655,19 @@ virStorageBackendCreateQemuImgOpts(char **opts,
     if (preallocate)
         virBufferAddLit(&buf, "preallocation=metadata,");
 
+    if (compat)
+        virBufferAsprintf(&buf, "compat=%s,", compat);
+    if (features && format == VIR_STORAGE_FILE_QCOW2) {
+        if (!compat)
+            virBufferAddLit(&buf, "compat=1.1,");
+        for (i = 0; i < VIR_STORAGE_FILE_FEATURE_LAST; i++) {
+            ignore_value(virBitmapGetBit(features, i, &b));
+            if (b)
+                virBufferAsprintf(&buf, "%s,",
+                                  virStorageFileFeatureTypeToString(i));
+        }
+    }
+
     virBufferTrim(&buf, ",", -1);
 
     if (virBufferError(&buf)) {
@@ -718,6 +737,16 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
                        _("metadata preallocation only available with qcow2"));
         return NULL;
     }
+    if (vol->target.compat && vol->target.format != VIR_STORAGE_FILE_QCOW2) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("compatibility option only available with qcow2"));
+        return NULL;
+    }
+    if (vol->target.features && vol->target.format != VIR_STORAGE_FILE_QCOW2) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("format features only available with qcow2"));
+        return NULL;
+    }
 
     if (vol->backingStore.path) {
         int accessRetCode = -1;
@@ -819,7 +848,10 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
     if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS) {
         if (virStorageBackendCreateQemuImgOpts(&opts,
                                                backing ? backingType : NULL,
-                                               do_encryption, preallocate))
+                                               do_encryption, preallocate,
+                                               vol->target.format,
+                                               vol->target.compat,
+                                               vol->target.features))
             return NULL;
         if (opts)
             virCommandAddArgList(cmd, "-o", opts, NULL);
diff --git a/tests/storagevolxml2argvdata/qcow2-1.1.argv b/tests/storagevolxml2argvdata/qcow2-1.1.argv
new file mode 100644
index 0000000..797499f
--- /dev/null
+++ b/tests/storagevolxml2argvdata/qcow2-1.1.argv
@@ -0,0 +1 @@
+qemu-img create -f qcow2 -b /dev/null -o backing_fmt=raw,encryption=on,compat=1.1 /var/lib/libvirt/images/OtherDemo.img 5242880K
diff --git a/tests/storagevolxml2argvdata/qcow2-lazy.argv b/tests/storagevolxml2argvdata/qcow2-lazy.argv
new file mode 100644
index 0000000..9160d47
--- /dev/null
+++ b/tests/storagevolxml2argvdata/qcow2-lazy.argv
@@ -0,0 +1 @@
+qemu-img create -f qcow2 -b /dev/null -o backing_fmt=raw,encryption=on,compat=1.1,lazy_refcounts /var/lib/libvirt/images/OtherDemo.img 5242880K
diff --git a/tests/storagevolxml2argvdata/vol-qcow2-1.1.xml b/tests/storagevolxml2argvdata/vol-qcow2-1.1.xml
new file mode 100644
index 0000000..696e1e0
--- /dev/null
+++ b/tests/storagevolxml2argvdata/vol-qcow2-1.1.xml
@@ -0,0 +1,32 @@
+<volume>
+  <name>OtherDemo.img</name>
+  <key>/var/lib/libvirt/images/OtherDemo.img</key>
+  <source>
+  </source>
+  <capacity unit="G">5</capacity>
+  <allocation>294912</allocation>
+  <target>
+    <path>/var/lib/libvirt/images/OtherDemo.img</path>
+    <format type='qcow2'/>
+    <permissions>
+      <mode>0644</mode>
+      <owner>0</owner>
+      <group>0</group>
+      <label>unconfined_u:object_r:virt_image_t:s0</label>
+    </permissions>
+    <encryption format='qcow'>
+      <secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
+    </encryption>
+    <features/>
+  </target>
+  <backingStore>
+    <path>/dev/null</path>
+    <format type='raw'/>
+    <permissions>
+      <mode>0644</mode>
+      <owner>0</owner>
+      <group>0</group>
+      <label>unconfined_u:object_r:virt_image_t:s0</label>
+    </permissions>
+  </backingStore>
+</volume>
diff --git a/tests/storagevolxml2argvdata/vol-qcow2-lazy.xml b/tests/storagevolxml2argvdata/vol-qcow2-lazy.xml
new file mode 100644
index 0000000..c1d7875
--- /dev/null
+++ b/tests/storagevolxml2argvdata/vol-qcow2-lazy.xml
@@ -0,0 +1,35 @@
+<volume>
+  <name>OtherDemo.img</name>
+  <key>/var/lib/libvirt/images/OtherDemo.img</key>
+  <source>
+  </source>
+  <capacity unit="G">5</capacity>
+  <allocation>294912</allocation>
+  <target>
+    <path>/var/lib/libvirt/images/OtherDemo.img</path>
+    <format type='qcow2'/>
+    <permissions>
+      <mode>0644</mode>
+      <owner>0</owner>
+      <group>0</group>
+      <label>unconfined_u:object_r:virt_image_t:s0</label>
+    </permissions>
+    <encryption format='qcow'>
+      <secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
+    </encryption>
+    <compat>1.1</compat>
+    <features>
+      <lazy_refcounts/>
+    </features>
+  </target>
+  <backingStore>
+    <path>/dev/null</path>
+    <format type='raw'/>
+    <permissions>
+      <mode>0644</mode>
+      <owner>0</owner>
+      <group>0</group>
+      <label>unconfined_u:object_r:virt_image_t:s0</label>
+    </permissions>
+  </backingStore>
+</volume>
diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c
index 46b77b2..aa81c57 100644
--- a/tests/storagevolxml2argvtest.c
+++ b/tests/storagevolxml2argvtest.c
@@ -187,6 +187,8 @@ mymain(void)
             "qcow2-nobacking-none", 0, FMT_NONE);
     DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", "vol-file",
             "qcow2-nobacking-convert-none", 0, FMT_NONE);
+    DO_TEST(false, "pool-dir", "vol-qcow2-lazy", NULL, "qcow2-lazy", 0, FMT_OPTIONS);
+    DO_TEST(false, "pool-dir", "vol-qcow2-1.1", NULL, "qcow2-1.1", 0, FMT_OPTIONS);
 
     return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-- 
1.8.1.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]