mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
storage: Adjust qemu-img switches check
Since we support QEMU 0.12 and later, checking for support of specific flags added prior to that isn't necessary. Thus start with the base of having the "-o options" available for the qemu-img create option and then determine whether we have the compat option for qcow2 files (which would be necessary up through qemu 2.0 where the default changes to compat 0.11). Adjust test to no long check for NONE and FLAG options as well was removing results of tests that would use that option. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
8b3f0b767e
commit
f6a92f8e20
@ -869,10 +869,15 @@ virStoragePloopResize(virStorageVolDefPtr vol,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Flag values shared w/ storagevolxml2argvtest.c.
|
||||
*
|
||||
* QEMU_IMG_BACKING_FORMAT_OPTIONS (added in qemu 0.11)
|
||||
* QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT
|
||||
* was made necessary due to 2.0 change to change the default
|
||||
* qcow2 file format from 0.10 to 1.1.
|
||||
*/
|
||||
enum {
|
||||
QEMU_IMG_BACKING_FORMAT_NONE = 0,
|
||||
QEMU_IMG_BACKING_FORMAT_FLAG,
|
||||
QEMU_IMG_BACKING_FORMAT_OPTIONS,
|
||||
QEMU_IMG_BACKING_FORMAT_OPTIONS = 0,
|
||||
QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT,
|
||||
};
|
||||
|
||||
@ -904,46 +909,18 @@ virStorageBackendQemuImgSupportsCompat(const char *qemuimg)
|
||||
static int
|
||||
virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
|
||||
{
|
||||
char *help = NULL;
|
||||
char *start;
|
||||
char *end;
|
||||
char *tmp;
|
||||
int ret = -1;
|
||||
int exitstatus;
|
||||
virCommandPtr cmd = virCommandNewArgList(qemuimg, "-h", NULL);
|
||||
/* As of QEMU 0.11 the [-o options] support was added via qemu
|
||||
* commit id '9ea2ea71', so we start with that base and figure
|
||||
* out what else we have */
|
||||
int ret = QEMU_IMG_BACKING_FORMAT_OPTIONS;
|
||||
|
||||
virCommandAddEnvString(cmd, "LC_ALL=C");
|
||||
virCommandSetOutputBuffer(cmd, &help);
|
||||
virCommandClearCaps(cmd);
|
||||
/* QEMU 2.0 changed to using a format that only QEMU 1.1 and newer
|
||||
* understands. Since we still support QEMU 0.12 and newer, we need
|
||||
* to be able to handle the previous format as can be set via a
|
||||
* compat=0.10 option. */
|
||||
if (virStorageBackendQemuImgSupportsCompat(qemuimg))
|
||||
ret = QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT;
|
||||
|
||||
/* qemuimg doesn't return zero exit status on -h,
|
||||
* therefore we need to provide pointer for storing
|
||||
* exit status, although we don't parse it any later */
|
||||
if (virCommandRun(cmd, &exitstatus) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if ((start = strstr(help, " create ")) == NULL ||
|
||||
(end = strstr(start, "\n")) == NULL) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("unable to parse qemu-img output '%s'"),
|
||||
help);
|
||||
goto cleanup;
|
||||
}
|
||||
if (((tmp = strstr(start, "-F 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) {
|
||||
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);
|
||||
VIR_FREE(help);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1218,29 +1195,17 @@ 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 (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 == QEMU_IMG_BACKING_FORMAT_FLAG)
|
||||
virCommandAddArgList(cmd, "-F", 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 (virStorageBackendCreateQemuImgOpts(&opts, info) < 0) {
|
||||
virCommandFree(cmd);
|
||||
return NULL;
|
||||
}
|
||||
if (opts)
|
||||
virCommandAddArgList(cmd, "-o", opts, NULL);
|
||||
VIR_FREE(opts);
|
||||
|
||||
if (info.inputPath)
|
||||
virCommandAddArg(cmd, info.inputPath);
|
||||
|
@ -1,2 +0,0 @@
|
||||
qemu-img create -f qcow2 -b /dev/null -F raw \
|
||||
-e /var/lib/libvirt/images/OtherDemo.img 5242880K
|
@ -1,2 +0,0 @@
|
||||
qemu-img convert -f raw -O qcow2 -e /var/lib/libvirt/images/sparse.img \
|
||||
/var/lib/libvirt/images/OtherDemo.img
|
@ -1,2 +0,0 @@
|
||||
qemu-img convert -f raw -O qcow2 -e /var/lib/libvirt/images/sparse.img \
|
||||
/var/lib/libvirt/images/OtherDemo.img
|
@ -1 +0,0 @@
|
||||
qemu-img create -f qcow2 -e /var/lib/libvirt/images/OtherDemo.img 5242880K
|
@ -1 +0,0 @@
|
||||
qemu-img create -f qcow2 -e /var/lib/libvirt/images/OtherDemo.img 5242880K
|
@ -1 +0,0 @@
|
||||
qemu-img create -f qcow2 -b /dev/null -e /var/lib/libvirt/images/OtherDemo.img 5242880K
|
@ -168,9 +168,7 @@ testCompareXMLToArgvHelper(const void *data)
|
||||
}
|
||||
|
||||
enum {
|
||||
FMT_NONE = 0,
|
||||
FMT_FLAG,
|
||||
FMT_OPTIONS,
|
||||
FMT_OPTIONS = 0,
|
||||
FMT_COMPAT,
|
||||
};
|
||||
|
||||
@ -217,24 +215,6 @@ mymain(void)
|
||||
DO_TEST_FAIL("pool-dir", "vol-qcow2",
|
||||
"pool-dir", "vol-file",
|
||||
"qcow2-convert-prealloc", flags, FMT_OPTIONS);
|
||||
DO_TEST("pool-dir", "vol-qcow2",
|
||||
NULL, NULL,
|
||||
"qcow2-flag", 0, FMT_FLAG);
|
||||
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
||||
NULL, NULL,
|
||||
"qcow2-nobacking-flag", 0, FMT_FLAG);
|
||||
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
||||
"pool-dir", "vol-file",
|
||||
"qcow2-nobacking-convert-flag", 0, FMT_FLAG);
|
||||
DO_TEST("pool-dir", "vol-qcow2",
|
||||
NULL, NULL,
|
||||
"qcow2-none", 0, FMT_NONE);
|
||||
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
||||
NULL, NULL,
|
||||
"qcow2-nobacking-none", 0, FMT_NONE);
|
||||
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
||||
"pool-dir", "vol-file",
|
||||
"qcow2-nobacking-convert-none", 0, FMT_NONE);
|
||||
DO_TEST("pool-dir", "vol-qcow2-lazy",
|
||||
NULL, NULL,
|
||||
"qcow2-lazy", 0, FMT_OPTIONS);
|
||||
|
Loading…
Reference in New Issue
Block a user