Add new function to manage adding the '-mon' or '-monitor' options to the command line removing that task from the mainline qemuBuildCommandLine Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/qemu/qemu_command.c | 78 ++++++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index e554648..017d511 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3847,7 +3847,8 @@ qemuBuildSCSIHostdevDevStr(virDomainDefPtr def, /* This function outputs a -chardev command line option which describes only the * host side of the character device */ static char * -qemuBuildChrChardevStr(virDomainChrSourceDefPtr dev, const char *alias, +qemuBuildChrChardevStr(const virDomainChrSourceDef *dev, + const char *alias, virQEMUCapsPtr qemuCaps) { virBuffer buf = VIR_BUFFER_INITIALIZER; @@ -3975,7 +3976,8 @@ qemuBuildChrChardevStr(virDomainChrSourceDefPtr dev, const char *alias, static char * -qemuBuildChrArgStr(virDomainChrSourceDefPtr dev, const char *prefix) +qemuBuildChrArgStr(const virDomainChrSourceDef *dev, + const char *prefix) { virBuffer buf = VIR_BUFFER_INITIALIZER; @@ -4068,6 +4070,47 @@ qemuBuildChrArgStr(virDomainChrSourceDefPtr dev, const char *prefix) } +static int +qemuBuildMonitorCommandLine(virCommandPtr cmd, + virQEMUCapsPtr qemuCaps, + const virDomainChrSourceDef *monitor_chr, + bool monitor_json) +{ + char *chrdev; + + if (!monitor_chr) + return 0; + + /* Use -chardev if it's available */ + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV)) { + + virCommandAddArg(cmd, "-chardev"); + if (!(chrdev = qemuBuildChrChardevStr(monitor_chr, "monitor", + qemuCaps))) + return -1; + virCommandAddArg(cmd, chrdev); + VIR_FREE(chrdev); + + virCommandAddArg(cmd, "-mon"); + virCommandAddArgFormat(cmd, + "chardev=charmonitor,id=monitor,mode=%s", + monitor_json ? "control" : "readline"); + } else { + const char *prefix = NULL; + if (monitor_json) + prefix = "control,"; + + virCommandAddArg(cmd, "-monitor"); + if (!(chrdev = qemuBuildChrArgStr(monitor_chr, prefix))) + return -1; + virCommandAddArg(cmd, chrdev); + VIR_FREE(chrdev); + } + + return 0; +} + + static char * qemuBuildVirtioSerialPortDevStr(virDomainDefPtr def, virDomainChrDefPtr dev, @@ -7112,34 +7155,9 @@ qemuBuildCommandLine(virConnectPtr conn, if (qemuBuildSgaCommandLine(cmd, def, qemuCaps) < 0) goto error; - if (monitor_chr) { - char *chrdev; - /* Use -chardev if it's available */ - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV)) { - - virCommandAddArg(cmd, "-chardev"); - if (!(chrdev = qemuBuildChrChardevStr(monitor_chr, "monitor", - qemuCaps))) - goto error; - virCommandAddArg(cmd, chrdev); - VIR_FREE(chrdev); - - virCommandAddArg(cmd, "-mon"); - virCommandAddArgFormat(cmd, - "chardev=charmonitor,id=monitor,mode=%s", - monitor_json ? "control" : "readline"); - } else { - const char *prefix = NULL; - if (monitor_json) - prefix = "control,"; - - virCommandAddArg(cmd, "-monitor"); - if (!(chrdev = qemuBuildChrArgStr(monitor_chr, prefix))) - goto error; - virCommandAddArg(cmd, chrdev); - VIR_FREE(chrdev); - } - } + if (qemuBuildMonitorCommandLine(cmd, qemuCaps, monitor_chr, + monitor_json) < 0) + goto error; if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_RTC)) { char *rtcopt; -- 2.5.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list