mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
Always specify qcow2 compat level on qemu-img command line
qemu-img is going to switch the default for QCOW2 to QCOW2v3 (compat=1.1) Extend the probing for qemu-img command line options to check if -o compat is supported. If the volume definition specifies the qcow2 format but no compat level and -o compat is supported, specify -o compat=0.10 to create a QCOW2v2 image. https://bugzilla.redhat.com/show_bug.cgi?id=997977
This commit is contained in:
parent
9eb444364e
commit
bab2eda6ad
@ -581,8 +581,34 @@ enum {
|
||||
QEMU_IMG_BACKING_FORMAT_NONE = 0,
|
||||
QEMU_IMG_BACKING_FORMAT_FLAG,
|
||||
QEMU_IMG_BACKING_FORMAT_OPTIONS,
|
||||
QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT,
|
||||
};
|
||||
|
||||
static bool
|
||||
virStorageBackendQemuImgSupportsCompat(const char *qemuimg)
|
||||
{
|
||||
bool ret = false;
|
||||
char *output;
|
||||
virCommandPtr cmd = NULL;
|
||||
|
||||
cmd = virCommandNewArgList(qemuimg, "create", "-o", "?", "-f", "qcow2",
|
||||
"/dev/null", NULL);
|
||||
|
||||
virCommandAddEnvString(cmd, "LC_ALL=C");
|
||||
virCommandSetOutputBuffer(cmd, &output);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (strstr(output, "\ncompat "))
|
||||
ret = true;
|
||||
|
||||
cleanup:
|
||||
virCommandFree(cmd);
|
||||
VIR_FREE(output);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
|
||||
{
|
||||
@ -612,12 +638,16 @@ virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
|
||||
goto cleanup;
|
||||
}
|
||||
if (((tmp = strstr(start, "-F fmt")) && tmp < end) ||
|
||||
((tmp = strstr(start, "-F backing_fmt")) && tmp < end))
|
||||
((tmp = strstr(start, "-F backing_fmt")) && tmp < end)) {
|
||||
ret = QEMU_IMG_BACKING_FORMAT_FLAG;
|
||||
else if ((tmp = strstr(start, "[-o options]")) && tmp < end)
|
||||
ret = QEMU_IMG_BACKING_FORMAT_OPTIONS;
|
||||
else
|
||||
} else if ((tmp = strstr(start, "[-o options]")) && tmp < end) {
|
||||
if (virStorageBackendQemuImgSupportsCompat(qemuimg))
|
||||
ret = QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT;
|
||||
else
|
||||
ret = QEMU_IMG_BACKING_FORMAT_OPTIONS;
|
||||
} else {
|
||||
ret = QEMU_IMG_BACKING_FORMAT_NONE;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virCommandFree(cmd);
|
||||
@ -705,6 +735,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
|
||||
const char *backingType = NULL;
|
||||
const char *inputPath = NULL;
|
||||
const char *inputType = NULL;
|
||||
const char *compat = vol->target.compat;
|
||||
char *opts = NULL;
|
||||
bool convert = false;
|
||||
bool backing = false;
|
||||
@ -854,12 +885,16 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
|
||||
if (backing)
|
||||
virCommandAddArgList(cmd, "-b", vol->backingStore.path, NULL);
|
||||
|
||||
if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS) {
|
||||
if (imgformat >= QEMU_IMG_BACKING_FORMAT_OPTIONS) {
|
||||
if (vol->target.format == VIR_STORAGE_FILE_QCOW2 && !compat &&
|
||||
imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT)
|
||||
compat = "0.10";
|
||||
|
||||
if (virStorageBackendCreateQemuImgOpts(&opts,
|
||||
backing ? backingType : NULL,
|
||||
do_encryption, preallocate,
|
||||
vol->target.format,
|
||||
vol->target.compat,
|
||||
compat,
|
||||
vol->target.features) < 0) {
|
||||
virCommandFree(cmd);
|
||||
return NULL;
|
||||
|
3
tests/storagevolxml2argvdata/qcow2-compat.argv
Normal file
3
tests/storagevolxml2argvdata/qcow2-compat.argv
Normal file
@ -0,0 +1,3 @@
|
||||
qemu-img create -f qcow2 -b /dev/null \
|
||||
-o backing_fmt=raw,encryption=on,compat=0.10 \
|
||||
/var/lib/libvirt/images/OtherDemo.img 5242880K
|
@ -0,0 +1,3 @@
|
||||
qemu-img convert -f raw -O qcow2 \
|
||||
-o encryption=on,compat=0.10 \
|
||||
/dev/HostVG/Swap /var/lib/libvirt/images/OtherDemo.img
|
@ -0,0 +1,3 @@
|
||||
qemu-img convert -f raw -O qcow2 \
|
||||
-o encryption=on,preallocation=metadata,compat=0.10 \
|
||||
/var/lib/libvirt/images/sparse.img /var/lib/libvirt/images/OtherDemo.img
|
@ -0,0 +1,3 @@
|
||||
qemu-img create -f qcow2 \
|
||||
-o encryption=on,preallocation=metadata,compat=0.10 \
|
||||
/var/lib/libvirt/images/OtherDemo.img 5242880K
|
@ -195,6 +195,7 @@ enum {
|
||||
FMT_NONE = 0,
|
||||
FMT_FLAG,
|
||||
FMT_OPTIONS,
|
||||
FMT_COMPAT,
|
||||
};
|
||||
|
||||
|
||||
@ -271,6 +272,31 @@ mymain(void)
|
||||
"pool-dir", "vol-qcow2-nobacking",
|
||||
"logical-from-qcow2", 0, FMT_OPTIONS);
|
||||
|
||||
DO_TEST("pool-dir", "vol-qcow2",
|
||||
NULL, NULL,
|
||||
"qcow2-compat", 0, FMT_COMPAT);
|
||||
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
||||
NULL, NULL,
|
||||
"qcow2-nobacking-prealloc-compat", flags, FMT_COMPAT);
|
||||
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
||||
"pool-dir", "vol-file",
|
||||
"qcow2-nobacking-convert-prealloc-compat", flags, FMT_COMPAT);
|
||||
DO_TEST("pool-dir", "vol-qcow2-lazy",
|
||||
NULL, NULL,
|
||||
"qcow2-lazy", 0, FMT_COMPAT);
|
||||
DO_TEST("pool-dir", "vol-qcow2-1.1",
|
||||
NULL, NULL,
|
||||
"qcow2-1.1", 0, FMT_COMPAT);
|
||||
DO_TEST_FAIL("pool-dir", "vol-qcow2-0.10-lazy",
|
||||
NULL, NULL,
|
||||
"qcow2-0.10-lazy", 0, FMT_COMPAT);
|
||||
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
||||
"pool-logical", "vol-logical",
|
||||
"qcow2-from-logical-compat", 0, FMT_COMPAT);
|
||||
DO_TEST("pool-logical", "vol-logical",
|
||||
"pool-dir", "vol-qcow2-nobacking",
|
||||
"logical-from-qcow2", 0, FMT_COMPAT);
|
||||
|
||||
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user