From f84b92ea19588ac9056f1f2b579cf630b76b8949 Mon Sep 17 00:00:00 2001 From: Li Zhang Date: Fri, 29 Mar 2013 13:22:46 +0800 Subject: [PATCH] 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 Signed-off-by: Eric Blake --- src/qemu/qemu_capabilities.c | 6 ++++++ src/qemu/qemu_capabilities.h | 3 ++- src/qemu/qemu_command.c | 35 ++++++++++++++++++++++------------- tests/qemuhelptest.c | 4 ++++ tests/qemuxml2argvtest.c | 7 +++++-- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 6b16191e98..aa381b4ea7 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -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); } diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 2ccc7c2fc8..b2dc5885ab 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -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 */ }; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c80218d011..a6d011ebd4 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -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; diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c index 05bb8a6ae6..43774f4772 100644 --- a/tests/qemuhelptest.c +++ b/tests/qemuhelptest.c @@ -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, diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 38787ace49..d5d2b3d0d1 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -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);