From 6d28ef912c3cc9ca53ee00d82fc8ed75dc33ed9d Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Wed, 16 Mar 2016 12:11:58 +0100 Subject: [PATCH] qemu: Don't add -spice port=0 when no port is specified If a has no port nor tlsPort set, the generated QEMU command line will contain -spice port=0. This is later going to be ignored by spice-server, but it's better not to add it at all in this situation. As an empty -spice is not allowed, we still need to append port=0 if we did not add any other argument. --- src/qemu/qemu_command.c | 10 +++++++-- .../qemuxml2argv-graphics-spice-no-args.args | 21 ++++++++++++++++++ .../qemuxml2argv-graphics-spice-no-args.xml | 22 +++++++++++++++++++ ...emuxml2argv-video-virtio-gpu-spice-gl.args | 2 +- tests/qemuxml2argvtest.c | 2 ++ 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-no-args.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-no-args.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index e31148d5ee..eb025530f2 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7388,7 +7388,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, goto error; } - if (port > 0 || tlsPort <= 0) + if (port > 0) virBufferAsprintf(&opt, "port=%u,", port); if (tlsPort > 0) { @@ -7586,7 +7586,13 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, virBufferTrim(&opt, ",", -1); virCommandAddArg(cmd, "-spice"); - virCommandAddArgBuffer(cmd, &opt); + /* If we did not add any SPICE arguments, add a dummy 'port=0' one + * as -spice alone is not allowed on QEMU command line + */ + if (virBufferUse(&opt) == 0) + virCommandAddArg(cmd, "port=0"); + else + virCommandAddArgBuffer(cmd, &opt); if (graphics->data.spice.keymap) virCommandAddArgList(cmd, "-k", graphics->data.spice.keymap, NULL); diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-no-args.args b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-no-args.args new file mode 100644 index 0000000000..05ce74329b --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-no-args.args @@ -0,0 +1,21 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=spice \ +/usr/bin/qemu \ +-name QEMUGuest1 \ +-S \ +-M pc \ +-m 214 \ +-smp 1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nodefaults \ +-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-spice port=0 \ +-vga cirrus \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-no-args.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-no-args.xml new file mode 100644 index 0000000000..9d49feb8b1 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-no-args.xml @@ -0,0 +1,22 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-spice-gl.args b/tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-spice-gl.args index edecca15ce..b80ad1638a 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-spice-gl.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-spice-gl.args @@ -19,6 +19,6 @@ QEMU_AUDIO_DRV=spice \ -drive file=/var/lib/libvirt/images/QEMUGuest1,format=qcow2,if=none,\ id=drive-ide0-0-0,cache=none \ -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ --spice port=0,gl=on \ +-spice gl=on \ -device virtio-vga,id=video0,virgl=on,bus=pci.0,addr=0x2 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index e15da3738d..4fac77dd84 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -949,6 +949,8 @@ mymain(void) QEMU_CAPS_SPICE, QEMU_CAPS_DEVICE_QXL, QEMU_CAPS_SPICE_FILE_XFER_DISABLE); + DO_TEST("graphics-spice-no-args", + QEMU_CAPS_SPICE); driver.config->spiceSASL = 1; ignore_value(VIR_STRDUP(driver.config->spiceSASLdir, "/root/.sasl2")); DO_TEST("graphics-spice-sasl", -- 2.39.5