]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Don't add -spice port=0 when no port is specified
authorChristophe Fergeau <cfergeau@redhat.com>
Wed, 16 Mar 2016 11:11:58 +0000 (12:11 +0100)
committerChristophe Fergeau <cfergeau@redhat.com>
Mon, 21 Mar 2016 09:43:40 +0000 (10:43 +0100)
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
tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-no-args.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-no-args.xml [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-spice-gl.args
tests/qemuxml2argvtest.c

index e31148d5eefd8f5e589c8da42959913f4209c0dc..eb025530f20766217943d1e0508fc28d185a8c68 100644 (file)
@@ -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 (file)
index 0000000..05ce743
--- /dev/null
@@ -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 (file)
index 0000000..9d49feb
--- /dev/null
@@ -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>
index edecca15ce86785407c8a7351c8d4740eabe68b6..b80ad1638abeb86f0b1316cc43441fbd17e69221 100644 (file)
@@ -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
index e15da3738db33b6d679d40fe18d3503581679cf1..4fac77dd84e36a98dee821d31d67fa188b10c444 100644 (file)
@@ -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",