|
|
43fe83 |
From d86f8ca314a4209b19d2ea425c2447b006afc84e Mon Sep 17 00:00:00 2001
|
|
|
43fe83 |
Message-Id: <d86f8ca314a4209b19d2ea425c2447b006afc84e.1378475168.git.jdenemar@redhat.com>
|
|
|
43fe83 |
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
|
|
|
43fe83 |
Date: Wed, 4 Sep 2013 12:46:10 +0200
|
|
|
43fe83 |
Subject: [PATCH] Always specify qcow2 compat level on qemu-img command line
|
|
|
43fe83 |
|
|
|
43fe83 |
qemu-img is going to switch the default for QCOW2
|
|
|
43fe83 |
to QCOW2v3 (compat=1.1) [1]
|
|
|
43fe83 |
|
|
|
43fe83 |
Extend the probing for qemu-img command line options to check
|
|
|
43fe83 |
if -o compat is supported. If the volume definition specifies
|
|
|
43fe83 |
the qcow2 format but no compat level and -o compat is supported,
|
|
|
43fe83 |
specify -o compat=0.10 to create a QCOW2v2 image.
|
|
|
43fe83 |
|
|
|
43fe83 |
https://bugzilla.redhat.com/show_bug.cgi?id=997977
|
|
|
43fe83 |
(cherry picked from commit bab2eda6ada1bf832decdc64cc5062e54eb105df)
|
|
|
43fe83 |
---
|
|
|
43fe83 |
src/storage/storage_backend.c | 47 +++++++++++++++++++---
|
|
|
43fe83 |
tests/storagevolxml2argvdata/qcow2-compat.argv | 3 ++
|
|
|
43fe83 |
.../qcow2-from-logical-compat.argv | 3 ++
|
|
|
43fe83 |
.../qcow2-nobacking-convert-prealloc-compat.argv | 3 ++
|
|
|
43fe83 |
.../qcow2-nobacking-prealloc-compat.argv | 3 ++
|
|
|
43fe83 |
tests/storagevolxml2argvtest.c | 26 ++++++++++++
|
|
|
43fe83 |
6 files changed, 79 insertions(+), 6 deletions(-)
|
|
|
43fe83 |
create mode 100644 tests/storagevolxml2argvdata/qcow2-compat.argv
|
|
|
43fe83 |
create mode 100644 tests/storagevolxml2argvdata/qcow2-from-logical-compat.argv
|
|
|
43fe83 |
create mode 100644 tests/storagevolxml2argvdata/qcow2-nobacking-convert-prealloc-compat.argv
|
|
|
43fe83 |
create mode 100644 tests/storagevolxml2argvdata/qcow2-nobacking-prealloc-compat.argv
|
|
|
43fe83 |
|
|
|
43fe83 |
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
|
|
|
43fe83 |
index 8d5880e..4ebe11b 100644
|
|
|
43fe83 |
--- a/src/storage/storage_backend.c
|
|
|
43fe83 |
+++ b/src/storage/storage_backend.c
|
|
|
43fe83 |
@@ -581,8 +581,34 @@ enum {
|
|
|
43fe83 |
QEMU_IMG_BACKING_FORMAT_NONE = 0,
|
|
|
43fe83 |
QEMU_IMG_BACKING_FORMAT_FLAG,
|
|
|
43fe83 |
QEMU_IMG_BACKING_FORMAT_OPTIONS,
|
|
|
43fe83 |
+ QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT,
|
|
|
43fe83 |
};
|
|
|
43fe83 |
|
|
|
43fe83 |
+static bool
|
|
|
43fe83 |
+virStorageBackendQemuImgSupportsCompat(const char *qemuimg)
|
|
|
43fe83 |
+{
|
|
|
43fe83 |
+ bool ret = false;
|
|
|
43fe83 |
+ char *output;
|
|
|
43fe83 |
+ virCommandPtr cmd = NULL;
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+ cmd = virCommandNewArgList(qemuimg, "create", "-o", "?", "-f", "qcow2",
|
|
|
43fe83 |
+ "/dev/null", NULL);
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+ virCommandAddEnvString(cmd, "LC_ALL=C");
|
|
|
43fe83 |
+ virCommandSetOutputBuffer(cmd, &output);
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+ if (virCommandRun(cmd, NULL) < 0)
|
|
|
43fe83 |
+ goto cleanup;
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+ if (strstr(output, "\ncompat "))
|
|
|
43fe83 |
+ ret = true;
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+cleanup:
|
|
|
43fe83 |
+ virCommandFree(cmd);
|
|
|
43fe83 |
+ VIR_FREE(output);
|
|
|
43fe83 |
+ return ret;
|
|
|
43fe83 |
+}
|
|
|
43fe83 |
+
|
|
|
43fe83 |
static int
|
|
|
43fe83 |
virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
|
|
|
43fe83 |
{
|
|
|
43fe83 |
@@ -612,12 +638,16 @@ virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
|
|
|
43fe83 |
goto cleanup;
|
|
|
43fe83 |
}
|
|
|
43fe83 |
if (((tmp = strstr(start, "-F fmt")) && tmp < end) ||
|
|
|
43fe83 |
- ((tmp = strstr(start, "-F backing_fmt")) && tmp < end))
|
|
|
43fe83 |
+ ((tmp = strstr(start, "-F backing_fmt")) && tmp < end)) {
|
|
|
43fe83 |
ret = QEMU_IMG_BACKING_FORMAT_FLAG;
|
|
|
43fe83 |
- else if ((tmp = strstr(start, "[-o options]")) && tmp < end)
|
|
|
43fe83 |
- ret = QEMU_IMG_BACKING_FORMAT_OPTIONS;
|
|
|
43fe83 |
- else
|
|
|
43fe83 |
+ } else if ((tmp = strstr(start, "[-o options]")) && tmp < end) {
|
|
|
43fe83 |
+ if (virStorageBackendQemuImgSupportsCompat(qemuimg))
|
|
|
43fe83 |
+ ret = QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT;
|
|
|
43fe83 |
+ else
|
|
|
43fe83 |
+ ret = QEMU_IMG_BACKING_FORMAT_OPTIONS;
|
|
|
43fe83 |
+ } else {
|
|
|
43fe83 |
ret = QEMU_IMG_BACKING_FORMAT_NONE;
|
|
|
43fe83 |
+ }
|
|
|
43fe83 |
|
|
|
43fe83 |
cleanup:
|
|
|
43fe83 |
virCommandFree(cmd);
|
|
|
43fe83 |
@@ -705,6 +735,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
|
|
|
43fe83 |
const char *backingType = NULL;
|
|
|
43fe83 |
const char *inputPath = NULL;
|
|
|
43fe83 |
const char *inputType = NULL;
|
|
|
43fe83 |
+ const char *compat = vol->target.compat;
|
|
|
43fe83 |
char *opts = NULL;
|
|
|
43fe83 |
bool convert = false;
|
|
|
43fe83 |
bool backing = false;
|
|
|
43fe83 |
@@ -854,12 +885,16 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
|
|
|
43fe83 |
if (backing)
|
|
|
43fe83 |
virCommandAddArgList(cmd, "-b", vol->backingStore.path, NULL);
|
|
|
43fe83 |
|
|
|
43fe83 |
- if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS) {
|
|
|
43fe83 |
+ if (imgformat >= QEMU_IMG_BACKING_FORMAT_OPTIONS) {
|
|
|
43fe83 |
+ if (vol->target.format == VIR_STORAGE_FILE_QCOW2 && !compat &&
|
|
|
43fe83 |
+ imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT)
|
|
|
43fe83 |
+ compat = "0.10";
|
|
|
43fe83 |
+
|
|
|
43fe83 |
if (virStorageBackendCreateQemuImgOpts(&opts,
|
|
|
43fe83 |
backing ? backingType : NULL,
|
|
|
43fe83 |
do_encryption, preallocate,
|
|
|
43fe83 |
vol->target.format,
|
|
|
43fe83 |
- vol->target.compat,
|
|
|
43fe83 |
+ compat,
|
|
|
43fe83 |
vol->target.features) < 0) {
|
|
|
43fe83 |
virCommandFree(cmd);
|
|
|
43fe83 |
return NULL;
|
|
|
43fe83 |
diff --git a/tests/storagevolxml2argvdata/qcow2-compat.argv b/tests/storagevolxml2argvdata/qcow2-compat.argv
|
|
|
43fe83 |
new file mode 100644
|
|
|
43fe83 |
index 0000000..37ad2c0
|
|
|
43fe83 |
--- /dev/null
|
|
|
43fe83 |
+++ b/tests/storagevolxml2argvdata/qcow2-compat.argv
|
|
|
43fe83 |
@@ -0,0 +1,3 @@
|
|
|
43fe83 |
+qemu-img create -f qcow2 -b /dev/null \
|
|
|
43fe83 |
+-o backing_fmt=raw,encryption=on,compat=0.10 \
|
|
|
43fe83 |
+/var/lib/libvirt/images/OtherDemo.img 5242880K
|
|
|
43fe83 |
diff --git a/tests/storagevolxml2argvdata/qcow2-from-logical-compat.argv b/tests/storagevolxml2argvdata/qcow2-from-logical-compat.argv
|
|
|
43fe83 |
new file mode 100644
|
|
|
43fe83 |
index 0000000..5f365b1
|
|
|
43fe83 |
--- /dev/null
|
|
|
43fe83 |
+++ b/tests/storagevolxml2argvdata/qcow2-from-logical-compat.argv
|
|
|
43fe83 |
@@ -0,0 +1,3 @@
|
|
|
43fe83 |
+qemu-img convert -f raw -O qcow2 \
|
|
|
43fe83 |
+-o encryption=on,compat=0.10 \
|
|
|
43fe83 |
+/dev/HostVG/Swap /var/lib/libvirt/images/OtherDemo.img
|
|
|
43fe83 |
diff --git a/tests/storagevolxml2argvdata/qcow2-nobacking-convert-prealloc-compat.argv b/tests/storagevolxml2argvdata/qcow2-nobacking-convert-prealloc-compat.argv
|
|
|
43fe83 |
new file mode 100644
|
|
|
43fe83 |
index 0000000..3d93ec8
|
|
|
43fe83 |
--- /dev/null
|
|
|
43fe83 |
+++ b/tests/storagevolxml2argvdata/qcow2-nobacking-convert-prealloc-compat.argv
|
|
|
43fe83 |
@@ -0,0 +1,3 @@
|
|
|
43fe83 |
+qemu-img convert -f raw -O qcow2 \
|
|
|
43fe83 |
+-o encryption=on,preallocation=metadata,compat=0.10 \
|
|
|
43fe83 |
+/var/lib/libvirt/images/sparse.img /var/lib/libvirt/images/OtherDemo.img
|
|
|
43fe83 |
diff --git a/tests/storagevolxml2argvdata/qcow2-nobacking-prealloc-compat.argv b/tests/storagevolxml2argvdata/qcow2-nobacking-prealloc-compat.argv
|
|
|
43fe83 |
new file mode 100644
|
|
|
43fe83 |
index 0000000..903c94e
|
|
|
43fe83 |
--- /dev/null
|
|
|
43fe83 |
+++ b/tests/storagevolxml2argvdata/qcow2-nobacking-prealloc-compat.argv
|
|
|
43fe83 |
@@ -0,0 +1,3 @@
|
|
|
43fe83 |
+qemu-img create -f qcow2 \
|
|
|
43fe83 |
+-o encryption=on,preallocation=metadata,compat=0.10 \
|
|
|
43fe83 |
+/var/lib/libvirt/images/OtherDemo.img 5242880K
|
|
|
43fe83 |
diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c
|
|
|
43fe83 |
index b1cf09f..cafcaad 100644
|
|
|
43fe83 |
--- a/tests/storagevolxml2argvtest.c
|
|
|
43fe83 |
+++ b/tests/storagevolxml2argvtest.c
|
|
|
43fe83 |
@@ -195,6 +195,7 @@ enum {
|
|
|
43fe83 |
FMT_NONE = 0,
|
|
|
43fe83 |
FMT_FLAG,
|
|
|
43fe83 |
FMT_OPTIONS,
|
|
|
43fe83 |
+ FMT_COMPAT,
|
|
|
43fe83 |
};
|
|
|
43fe83 |
|
|
|
43fe83 |
|
|
|
43fe83 |
@@ -271,6 +272,31 @@ mymain(void)
|
|
|
43fe83 |
"pool-dir", "vol-qcow2-nobacking",
|
|
|
43fe83 |
"logical-from-qcow2", 0, FMT_OPTIONS);
|
|
|
43fe83 |
|
|
|
43fe83 |
+ DO_TEST("pool-dir", "vol-qcow2",
|
|
|
43fe83 |
+ NULL, NULL,
|
|
|
43fe83 |
+ "qcow2-compat", 0, FMT_COMPAT);
|
|
|
43fe83 |
+ DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
|
|
43fe83 |
+ NULL, NULL,
|
|
|
43fe83 |
+ "qcow2-nobacking-prealloc-compat", flags, FMT_COMPAT);
|
|
|
43fe83 |
+ DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
|
|
43fe83 |
+ "pool-dir", "vol-file",
|
|
|
43fe83 |
+ "qcow2-nobacking-convert-prealloc-compat", flags, FMT_COMPAT);
|
|
|
43fe83 |
+ DO_TEST("pool-dir", "vol-qcow2-lazy",
|
|
|
43fe83 |
+ NULL, NULL,
|
|
|
43fe83 |
+ "qcow2-lazy", 0, FMT_COMPAT);
|
|
|
43fe83 |
+ DO_TEST("pool-dir", "vol-qcow2-1.1",
|
|
|
43fe83 |
+ NULL, NULL,
|
|
|
43fe83 |
+ "qcow2-1.1", 0, FMT_COMPAT);
|
|
|
43fe83 |
+ DO_TEST_FAIL("pool-dir", "vol-qcow2-0.10-lazy",
|
|
|
43fe83 |
+ NULL, NULL,
|
|
|
43fe83 |
+ "qcow2-0.10-lazy", 0, FMT_COMPAT);
|
|
|
43fe83 |
+ DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
|
|
43fe83 |
+ "pool-logical", "vol-logical",
|
|
|
43fe83 |
+ "qcow2-from-logical-compat", 0, FMT_COMPAT);
|
|
|
43fe83 |
+ DO_TEST("pool-logical", "vol-logical",
|
|
|
43fe83 |
+ "pool-dir", "vol-qcow2-nobacking",
|
|
|
43fe83 |
+ "logical-from-qcow2", 0, FMT_COMPAT);
|
|
|
43fe83 |
+
|
|
|
43fe83 |
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
43fe83 |
}
|
|
|
43fe83 |
|
|
|
43fe83 |
--
|
|
|
43fe83 |
1.8.3.2
|
|
|
43fe83 |
|