diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index deea85022a..27a0a4f711 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -633,9 +633,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)
@@ -643,16 +649,46 @@ virStorageBackendCreateQemuImgOpts(char **opts,
if (preallocate)
virBufferAddLit(&buf, "preallocation=metadata,");
+ if (compat)
+ virBufferAsprintf(&buf, "compat=%s,", compat);
+ if (features && format == VIR_STORAGE_FILE_QCOW2) {
+ for (i = 0; i < VIR_STORAGE_FILE_FEATURE_LAST; i++) {
+ ignore_value(virBitmapGetBit(features, i, &b));
+ if (b) {
+ switch ((enum virStorageFileFeature) i) {
+ case VIR_STORAGE_FILE_FEATURE_LAZY_REFCOUNTS:
+ if (STREQ_NULLABLE(compat, "0.10")) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Feature %s not supported with compat"
+ " level %s"),
+ virStorageFileFeatureTypeToString(i),
+ compat);
+ goto error;
+ }
+ break;
+ case VIR_STORAGE_FILE_FEATURE_NONE:
+ case VIR_STORAGE_FILE_FEATURE_LAST:
+ ;
+ }
+ virBufferAsprintf(&buf, "%s,",
+ virStorageFileFeatureTypeToString(i));
+ }
+ }
+ }
+
virBufferTrim(&buf, ",", -1);
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
- virReportOOMError();
- return -1;
- }
+ if (virBufferError(&buf))
+ goto no_memory;
*opts = virBufferContentAndReset(&buf);
return 0;
+
+no_memory:
+ virReportOOMError();
+error:
+ virBufferFreeAndReset(&buf);
+ return -1;
}
virCommandPtr
@@ -695,6 +731,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 (inputvol) {
if (!(inputPath = inputvol->target.path)) {
@@ -816,7 +862,10 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS) {
if (virStorageBackendCreateQemuImgOpts(&opts,
backing ? backingType : NULL,
- do_encryption, preallocate) < 0)
+ do_encryption, preallocate,
+ vol->target.format,
+ vol->target.compat,
+ vol->target.features) < 0)
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 0000000000..797499f478
--- /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 0000000000..9160d473b2
--- /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-0.10-lazy.xml b/tests/storagevolxml2argvdata/vol-qcow2-0.10-lazy.xml
new file mode 100644
index 0000000000..5bf98b7c84
--- /dev/null
+++ b/tests/storagevolxml2argvdata/vol-qcow2-0.10-lazy.xml
@@ -0,0 +1,35 @@
+
+ OtherDemo.img
+ /var/lib/libvirt/images/OtherDemo.img
+
+
+ 5
+ 294912
+
+ /var/lib/libvirt/images/OtherDemo.img
+
+
+ 0644
+ 0
+ 0
+
+
+
+
+
+ 0.10
+
+
+
+
+
+ /dev/null
+
+
+ 0644
+ 0
+ 0
+
+
+
+
diff --git a/tests/storagevolxml2argvdata/vol-qcow2-1.1.xml b/tests/storagevolxml2argvdata/vol-qcow2-1.1.xml
new file mode 100644
index 0000000000..696e1e0750
--- /dev/null
+++ b/tests/storagevolxml2argvdata/vol-qcow2-1.1.xml
@@ -0,0 +1,32 @@
+
+ OtherDemo.img
+ /var/lib/libvirt/images/OtherDemo.img
+
+
+ 5
+ 294912
+
+ /var/lib/libvirt/images/OtherDemo.img
+
+
+ 0644
+ 0
+ 0
+
+
+
+
+
+
+
+
+ /dev/null
+
+
+ 0644
+ 0
+ 0
+
+
+
+
diff --git a/tests/storagevolxml2argvdata/vol-qcow2-lazy.xml b/tests/storagevolxml2argvdata/vol-qcow2-lazy.xml
new file mode 100644
index 0000000000..c1d7875d66
--- /dev/null
+++ b/tests/storagevolxml2argvdata/vol-qcow2-lazy.xml
@@ -0,0 +1,35 @@
+
+ OtherDemo.img
+ /var/lib/libvirt/images/OtherDemo.img
+
+
+ 5
+ 294912
+
+ /var/lib/libvirt/images/OtherDemo.img
+
+
+ 0644
+ 0
+ 0
+
+
+
+
+
+ 1.1
+
+
+
+
+
+ /dev/null
+
+
+ 0644
+ 0
+ 0
+
+
+
+
diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c
index 92ab2f2a52..6a6c8e3e1c 100644
--- a/tests/storagevolxml2argvtest.c
+++ b/tests/storagevolxml2argvtest.c
@@ -188,6 +188,12 @@ 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);
+ DO_TEST(true, "pool-dir", "vol-qcow2-0.10-lazy", NULL, "qcow2-0.10-lazy", 0,
+ FMT_OPTIONS);
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}