Optimize machine option to set more options with it

Currently, -machine option is used only when dump-guest-core is set.

To use options defined in machine option for newer version of QEMU,
it needs to use -machine xxx, and to be compatible with older version
-M, this patch adds QEMU_CAPS_MACHINE_OPT capability for newer
version which supports -machine option.

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Li Zhang 2013-03-29 13:22:46 +08:00 committed by Eric Blake
parent f8e3221f99
commit f84b92ea19
5 changed files with 39 additions and 16 deletions

View File

@ -215,6 +215,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
"megasas",
"ipv6-migration", /* 135 */
"machine-opt",
);
struct _virQEMUCaps {
@ -1093,6 +1094,9 @@ virQEMUCapsComputeCmdFlags(const char *help,
if (strstr(help, "-dtb"))
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DTB);
if (strstr(help, "-machine"))
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_OPT);
/*
* Handling of -incoming arg with varying features
* -incoming tcp (kvm >= 79, qemu >= 0.10.0)
@ -2316,6 +2320,8 @@ virQEMUCapsInitQMPBasic(virQEMUCapsPtr qemuCaps)
virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_KVM_PIT);
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DTB);
virQEMUCapsSet(qemuCaps, QEMU_CAPS_IPV6_MIGRATION);
virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_OPT);
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DUMP_GUEST_CORE);
}

View File

@ -1,7 +1,7 @@
/*
* qemu_capabilities.h: QEMU capabilities generation
*
* Copyright (C) 2006-2012 Red Hat, Inc.
* Copyright (C) 2006-2013 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@ -175,6 +175,7 @@ enum virQEMUCapsFlags {
QEMU_CAPS_DTB = 133, /* -dtb file */
QEMU_CAPS_SCSI_MEGASAS = 134, /* -device megasas */
QEMU_CAPS_IPV6_MIGRATION = 135, /* -incoming [::] */
QEMU_CAPS_MACHINE_OPT = 136, /* -machine xxxx*/
QEMU_CAPS_LAST, /* this must always be the last item */
};

View File

@ -5207,27 +5207,36 @@ qemuBuildMachineArgStr(virCommandPtr cmd,
if (!def->os.machine)
return 0;
if (!def->mem.dump_core) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_OPT)) {
/* if no parameter to the machine type is needed, we still use
* '-M' to keep the most of the compatibility with older versions.
*/
virCommandAddArgList(cmd, "-M", def->os.machine, NULL);
} else {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DUMP_GUEST_CORE)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("dump-guest-core is not available "
" with this QEMU binary"));
if (def->mem.dump_core) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("dump-guest-core is not available "
"with this QEMU binary"));
return -1;
}
} else {
virBuffer buf = VIR_BUFFER_INITIALIZER;
/* However, in case there is a parameter to be added, we need to
* use the "-machine" parameter because qemu is not parsing the
* "-M" correctly */
virCommandAddArg(cmd, "-machine");
virCommandAddArgFormat(cmd,
"%s,dump-guest-core=%s",
def->os.machine,
virDomainMemDumpTypeToString(def->mem.dump_core));
virBufferAdd(&buf, def->os.machine, -1);
if (def->mem.dump_core) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DUMP_GUEST_CORE)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("dump-guest-core is not available "
"with this QEMU binary"));
return -1;
}
virBufferAsprintf(&buf, ",dump-guest-core=%s",
virDomainMemDumpTypeToString(def->mem.dump_core));
}
virCommandAddArgBuffer(cmd, &buf);
}
return 0;

View File

@ -718,6 +718,7 @@ mymain(void)
QEMU_CAPS_SCSI_LSI,
QEMU_CAPS_BLOCKIO,
QEMU_CAPS_VNC,
QEMU_CAPS_MACHINE_OPT,
QEMU_CAPS_DEVICE_QXL,
QEMU_CAPS_DEVICE_VGA,
QEMU_CAPS_DEVICE_CIRRUS_VGA,
@ -806,6 +807,7 @@ mymain(void)
QEMU_CAPS_VIRTIO_SCSI,
QEMU_CAPS_BLOCKIO,
QEMU_CAPS_VNC,
QEMU_CAPS_MACHINE_OPT,
QEMU_CAPS_DEVICE_QXL,
QEMU_CAPS_DEVICE_VGA,
QEMU_CAPS_DEVICE_CIRRUS_VGA,
@ -904,6 +906,7 @@ mymain(void)
QEMU_CAPS_SECCOMP_SANDBOX,
QEMU_CAPS_DUMP_GUEST_CORE,
QEMU_CAPS_VNC,
QEMU_CAPS_MACHINE_OPT,
QEMU_CAPS_USB_REDIR_BOOTINDEX,
QEMU_CAPS_USB_HOST_BOOTINDEX,
QEMU_CAPS_DEVICE_QXL,
@ -1011,6 +1014,7 @@ mymain(void)
QEMU_CAPS_SECCOMP_SANDBOX,
QEMU_CAPS_DUMP_GUEST_CORE,
QEMU_CAPS_VNC,
QEMU_CAPS_MACHINE_OPT,
QEMU_CAPS_USB_REDIR_BOOTINDEX,
QEMU_CAPS_USB_HOST_BOOTINDEX,
QEMU_CAPS_DEVICE_QXL,

View File

@ -363,9 +363,12 @@ mymain(void)
DO_TEST("minimal-s390", QEMU_CAPS_NAME);
DO_TEST("machine-aliases1", NONE);
DO_TEST("machine-aliases2", QEMU_CAPS_KVM);
DO_TEST("machine-core-on", QEMU_CAPS_DUMP_GUEST_CORE);
DO_TEST("machine-core-off", QEMU_CAPS_DUMP_GUEST_CORE);
DO_TEST("machine-core-on", QEMU_CAPS_MACHINE_OPT,
QEMU_CAPS_DUMP_GUEST_CORE);
DO_TEST("machine-core-off", QEMU_CAPS_MACHINE_OPT,
QEMU_CAPS_DUMP_GUEST_CORE);
DO_TEST_FAILURE("machine-core-on", NONE);
DO_TEST_FAILURE("machine-core-on", QEMU_CAPS_MACHINE_OPT);
DO_TEST("boot-cdrom", NONE);
DO_TEST("boot-network", NONE);
DO_TEST("boot-floppy", NONE);