From: Li Zhang <zhlcindy@xxxxxxxxxxxxxxxxxx> 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 addes QEMU_CAPS_MACHINE_OPT capability for newer version which supports -machine option. Signed-off-by: Li Zhang <zhlcindy@xxxxxxxxxxxxxxxxxx> --- v3 -> v2: * Set QEMU_CAPS_MACHINE_OPT with help string * Set QEMU_CAPS_DUMP_GUEST_CORE with QMP v2 -> v1: * Split the patch to 2 parts suggested by Daniel P.Berrange * Rename QEMU_CAPS_MACH_OPT to QEMU_CAPS_MACHINE_OPT * Remove version 1.1 assertion for QEMU_CAPS_MACHINE_OPT src/qemu/qemu_capabilities.c | 11 +++++++++++ src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 32 ++++++++++++++++++-------------- tests/qemuhelptest.c | 4 ++++ tests/qemuxml2argvtest.c | 6 +++--- 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 861d3c4..7d459db 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -213,6 +213,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "virtio-ccw", "dtb", "megasas", + + "machine-opt", /* 135 */ ); struct _virQEMUCaps { @@ -1091,6 +1093,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) @@ -2442,6 +2447,12 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, virQEMUCapsInitQMPBasic(qemuCaps); + /* machine option is supported for newer version */ + virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_OPT); + + /* -dump-guest-core is supported for newer version*/ + virQEMUCapsSet(qemuCaps, QEMU_CAPS_DUMP_GUEST_CORE); + if (!(archstr = qemuMonitorGetTargetArch(mon))) goto cleanup; diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 7101f67..2595868 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -174,6 +174,7 @@ enum virQEMUCapsFlags { QEMU_CAPS_VIRTIO_CCW = 132, /* -device virtio-*-ccw */ QEMU_CAPS_DTB = 133, /* -dtb file */ QEMU_CAPS_SCSI_MEGASAS = 134, /* -device megasas */ + QEMU_CAPS_MACHINE_OPT = 135, /* -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 a0c278f..0ee634b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5197,6 +5197,8 @@ qemuBuildMachineArgStr(virCommandPtr cmd, const virDomainDefPtr def, virQEMUCapsPtr qemuCaps) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + /* This should *never* be NULL, since we always provide * a machine in the capabilities data for QEMU. So this * check is just here as a safety in case the unexpected @@ -5204,27 +5206,29 @@ 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")); - return -1; - } - /* 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)); + virBufferAsprintf(&buf, "%s", def->os.machine); + + 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)); + } + + virCommandAddArg(cmd, virBufferContentAndReset(&buf)); } return 0; diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c index a28109a..0c7e607 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, @@ -903,6 +905,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, @@ -1009,6 +1012,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 38787ac..4b45c55 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -363,9 +363,9 @@ 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_FAILURE("machine-core-on", NONE); + 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", QEMU_CAPS_MACHINE_OPT, NONE); DO_TEST("boot-cdrom", NONE); DO_TEST("boot-network", NONE); DO_TEST("boot-floppy", NONE); -- 1.7.10.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list