If a <graphics type='spice'> 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 | 11 +++++++++--
.../qemuxml2argv-graphics-spice-no-args.args | 21 +++++++++++++++++++++
.../qemuxml2argv-graphics-spice-no-args.xml | 22 ++++++++++++++++++++++
.../qemuxml2argv-video-virtio-gpu-spice-gl.args | 2 +-
tests/qemuxml2argvtest.c | 2 ++
5 files changed, 55 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 bcc8cd6..e69e873 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7029,7 +7029,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
goto error;
}
- if (port > 0 || tlsPort <= 0)
+ if (port > 0)
virBufferAsprintf(&opt, "port=%u,", port);
if (tlsPort > 0) {
@@ -7234,7 +7234,14 @@ 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 and will be
+ * ignored by libvirt
+ */
+ 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 0000000..05ce743
--- /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 0000000..9d49feb
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-no-args.xml
@@ -0,0 +1,22 @@
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu</emulator>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <graphics type='spice' autoport='no'/>
+ <memballoon model='virtio'/>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-spice-gl.args
b/tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-spice-gl.args
index edecca1..b80ad16 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 e15da37..4fac77d 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.5.0