mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
storage: remove qemu-img help scraping
We have been checking whether qemu-img supports the -o compat option by scraping the -help output. Since we require QEMU 1.5.0 now and this option was introduced in 1.1, assume we support it and ditch the help parsing code along with the extra qemu-img invocation. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
74abb43aca
commit
e5261d8fe3
@ -787,61 +787,6 @@ storagePloopResize(virStorageVolDefPtr vol,
|
|||||||
return ret;
|
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_OPTIONS = 0,
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
/* 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;
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The _virStorageBackendQemuImgInfo separates the command line building from
|
/* The _virStorageBackendQemuImgInfo separates the command line building from
|
||||||
* the volume definition so that qemuDomainSnapshotCreateInactiveExternal can
|
* the volume definition so that qemuDomainSnapshotCreateInactiveExternal can
|
||||||
@ -1089,14 +1034,12 @@ storageBackendCreateQemuImgSetBacking(virStoragePoolObjPtr pool,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
storageBackendCreateQemuImgSetOptions(virCommandPtr cmd,
|
storageBackendCreateQemuImgSetOptions(virCommandPtr cmd,
|
||||||
int imgformat,
|
|
||||||
virStorageEncryptionInfoDefPtr enc,
|
virStorageEncryptionInfoDefPtr enc,
|
||||||
struct _virStorageBackendQemuImgInfo info)
|
struct _virStorageBackendQemuImgInfo info)
|
||||||
{
|
{
|
||||||
char *opts = NULL;
|
char *opts = NULL;
|
||||||
|
|
||||||
if (info.format == VIR_STORAGE_FILE_QCOW2 && !info.compat &&
|
if (info.format == VIR_STORAGE_FILE_QCOW2 && !info.compat)
|
||||||
imgformat >= QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT)
|
|
||||||
info.compat = "0.10";
|
info.compat = "0.10";
|
||||||
|
|
||||||
if (storageBackendCreateQemuImgOpts(enc, &opts, info) < 0)
|
if (storageBackendCreateQemuImgOpts(enc, &opts, info) < 0)
|
||||||
@ -1170,16 +1113,13 @@ storageBackendResizeQemuImgImageOpts(virCommandPtr cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Create a qemu-img virCommand from the supplied binary path,
|
/* Create a qemu-img virCommand from the supplied arguments */
|
||||||
* volume definitions and imgformat
|
|
||||||
*/
|
|
||||||
virCommandPtr
|
virCommandPtr
|
||||||
virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
|
virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
|
||||||
virStorageVolDefPtr vol,
|
virStorageVolDefPtr vol,
|
||||||
virStorageVolDefPtr inputvol,
|
virStorageVolDefPtr inputvol,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
const char *create_tool,
|
const char *create_tool,
|
||||||
int imgformat,
|
|
||||||
const char *secretPath)
|
const char *secretPath)
|
||||||
{
|
{
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
@ -1293,7 +1233,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
|
|||||||
enc = &vol->target.encryption->encinfo;
|
enc = &vol->target.encryption->encinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storageBackendCreateQemuImgSetOptions(cmd, imgformat, enc, info) < 0)
|
if (storageBackendCreateQemuImgSetOptions(cmd, enc, info) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
VIR_FREE(info.secretAlias);
|
VIR_FREE(info.secretAlias);
|
||||||
|
|
||||||
@ -1386,7 +1326,6 @@ storageBackendCreateQemuImg(virStoragePoolObjPtr pool,
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *create_tool;
|
char *create_tool;
|
||||||
int imgformat;
|
|
||||||
virCommandPtr cmd;
|
virCommandPtr cmd;
|
||||||
char *secretPath = NULL;
|
char *secretPath = NULL;
|
||||||
|
|
||||||
@ -1400,10 +1339,6 @@ storageBackendCreateQemuImg(virStoragePoolObjPtr pool,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
imgformat = virStorageBackendQEMUImgBackingFormat(create_tool);
|
|
||||||
if (imgformat < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (vol->target.format == VIR_STORAGE_FILE_RAW &&
|
if (vol->target.format == VIR_STORAGE_FILE_RAW &&
|
||||||
vol->target.encryption &&
|
vol->target.encryption &&
|
||||||
vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
|
vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
|
||||||
@ -1414,7 +1349,7 @@ storageBackendCreateQemuImg(virStoragePoolObjPtr pool,
|
|||||||
|
|
||||||
cmd = virStorageBackendCreateQemuImgCmdFromVol(pool, vol, inputvol,
|
cmd = virStorageBackendCreateQemuImgCmdFromVol(pool, vol, inputvol,
|
||||||
flags, create_tool,
|
flags, create_tool,
|
||||||
imgformat, secretPath);
|
secretPath);
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -159,7 +159,6 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
|
|||||||
virStorageVolDefPtr inputvol,
|
virStorageVolDefPtr inputvol,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
const char *create_tool,
|
const char *create_tool,
|
||||||
int imgformat,
|
|
||||||
const char *secretPath);
|
const char *secretPath);
|
||||||
|
|
||||||
int virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
|
int virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
|
||||||
|
@ -40,7 +40,6 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
|||||||
const char *inputvolxml,
|
const char *inputvolxml,
|
||||||
const char *cmdline,
|
const char *cmdline,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
int imgformat,
|
|
||||||
unsigned long parse_flags)
|
unsigned long parse_flags)
|
||||||
{
|
{
|
||||||
char *actualCmdline = NULL;
|
char *actualCmdline = NULL;
|
||||||
@ -82,7 +81,7 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
|||||||
|
|
||||||
cmd = virStorageBackendCreateQemuImgCmdFromVol(obj, vol,
|
cmd = virStorageBackendCreateQemuImgCmdFromVol(obj, vol,
|
||||||
inputvol, flags,
|
inputvol, flags,
|
||||||
create_tool, imgformat,
|
create_tool,
|
||||||
NULL);
|
NULL);
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
if (shouldFail) {
|
if (shouldFail) {
|
||||||
@ -118,7 +117,6 @@ struct testInfo {
|
|||||||
const char *inputvol;
|
const char *inputvol;
|
||||||
const char *cmdline;
|
const char *cmdline;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
int imgformat;
|
|
||||||
unsigned long parseflags;
|
unsigned long parseflags;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -154,7 +152,7 @@ testCompareXMLToArgvHelper(const void *data)
|
|||||||
result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml,
|
result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml,
|
||||||
inputpoolxml, inputvolxml,
|
inputpoolxml, inputvolxml,
|
||||||
cmdline, info->flags,
|
cmdline, info->flags,
|
||||||
info->imgformat, info->parseflags);
|
info->parseflags);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(poolxml);
|
VIR_FREE(poolxml);
|
||||||
@ -166,12 +164,6 @@ testCompareXMLToArgvHelper(const void *data)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum {
|
|
||||||
FMT_OPTIONS = 0,
|
|
||||||
FMT_COMPAT,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mymain(void)
|
mymain(void)
|
||||||
@ -183,7 +175,7 @@ mymain(void)
|
|||||||
cmdline, flags) \
|
cmdline, flags) \
|
||||||
do { \
|
do { \
|
||||||
struct testInfo info = { shouldFail, pool, vol, inputpool, inputvol, \
|
struct testInfo info = { shouldFail, pool, vol, inputpool, inputvol, \
|
||||||
cmdline, flags, FMT_COMPAT, parseflags }; \
|
cmdline, flags, parseflags }; \
|
||||||
if (virTestRun("Storage Vol XML-2-argv " cmdline, \
|
if (virTestRun("Storage Vol XML-2-argv " cmdline, \
|
||||||
testCompareXMLToArgvHelper, &info) < 0) \
|
testCompareXMLToArgvHelper, &info) < 0) \
|
||||||
ret = -1; \
|
ret = -1; \
|
||||||
|
Loading…
Reference in New Issue
Block a user