[PATCHv5 10/9] spicevmc: support older -device spicevmc of qemu 0.13.0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



qemu 0.13.0 (at least as built for Fedora 14, and also backported to
RHEL 6.0 qemu) supported an older syntax for a spicevmc channel; it's
not as flexible (it has an implicit name and hides the chardev
aspect), but now that we support spicevmc, we might as well target
both variants.

* src/qemu/qemu_capabilities.h (QEMUD_CMD_FLAG_DEVICE_SPICEVMC):
New flag.
* src/qemu/qemu_capabilities.c (qemuCapsParseDeviceStr): Set it
correctly.
* src/qemu/qemu_command.h (qemuBuildVirtioSerialPortDevStr): Drop
declaration.
* src/qemu/qemu_command.c (qemuBuildVirtioSerialPortDevStr): Alter
signature, check flag.
(qemuBuildCommandLine): Adjust caller and check flag.
* tests/qemuhelptest.c (mymain): Update test.
* tests/qemuxml2argvtest.c (mymain): New test.
* tests/qemuxml2argvdata/qemuxml2argv-channel-spicevmc-old.xml:
New file.
* tests/qemuxml2argvdata/qemuxml2argv-channel-spicevmc-old.args:
Likewise.
---

v5: new patch, based in part on the same RHEL 6.0 patch that
introduced spicevmc xml support

 src/qemu/qemu_capabilities.c                       |    4 ++
 src/qemu/qemu_capabilities.h                       |    3 +-
 src/qemu/qemu_command.c                            |   49 ++++++++++++++------
 src/qemu/qemu_command.h                            |    2 -
 tests/qemuhelptest.c                               |    6 ++-
 .../qemuxml2argv-channel-spicevmc-old.args         |    8 +++
 .../qemuxml2argv-channel-spicevmc-old.xml          |   34 ++++++++++++++
 tests/qemuxml2argvtest.c                           |    3 +
 8 files changed, 89 insertions(+), 20 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-channel-spicevmc-old.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-channel-spicevmc-old.xml

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 10f9d62..0e1f79c 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1091,6 +1091,10 @@ qemuCapsParseDeviceStr(const char *str, unsigned long long *flags)
         *flags |= QEMUD_CMD_FLAG_CCID_EMULATED;
     if (strstr(str, "name \"ccid-card-passthru\""))
         *flags |= QEMUD_CMD_FLAG_CCID_PASSTHRU;
+    /* Prefer -chardev spicevmc (detected earlier) over -device spicevmc */
+    if (!(*flags & QEMUD_CMD_FLAG_CHARDEV_SPICEVMC) &&
+        strstr(str, "name \"spicevmc\""))
+        *flags |= QEMUD_CMD_FLAG_DEVICE_SPICEVMC;

     /* Features of given devices. */
     if (strstr(str, "pci-assign.configfd"))
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 9ee7639..dd39b3b 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -90,7 +90,8 @@ enum qemuCapsFlags {
     QEMUD_CMD_FLAG_PCI_BOOTINDEX = (1LL << 53), /* pci-assign.bootindex */
     QEMUD_CMD_FLAG_CCID_EMULATED = (1LL << 54), /* -device ccid-card-emulated */
     QEMUD_CMD_FLAG_CCID_PASSTHRU = (1LL << 55), /* -device ccid-card-passthru */
-    QEMUD_CMD_FLAG_CHARDEV_SPICEVMC = (1LL << 56), /* -chardev spicevmc */
+    QEMUD_CMD_FLAG_CHARDEV_SPICEVMC = (1LL << 56), /* newer -chardev spicevmc */
+    QEMUD_CMD_FLAG_DEVICE_SPICEVMC = (1LL << 57), /* older -device spicevmc*/
 };

 virCapsPtr qemuCapsInit(virCapsPtr old_caps);
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 043ffad..e2ae514 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2183,12 +2183,16 @@ error:
 }


-char *
-qemuBuildVirtioSerialPortDevStr(virDomainChrDefPtr dev)
+static char *
+qemuBuildVirtioSerialPortDevStr(virDomainChrDefPtr dev,
+                                unsigned long long qemuCmdFlags)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     if (dev->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE)
         virBufferAddLit(&buf, "virtconsole");
+    else if ((qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE_SPICEVMC) &&
+             dev->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC)
+        virBufferAddLit(&buf, "spicevmc");
     else
         virBufferAddLit(&buf, "virtserialport");

@@ -2211,8 +2215,6 @@ qemuBuildVirtioSerialPortDevStr(virDomainChrDefPtr dev)
                           dev->info.addr.vioserial.port);
     }

-    virBufferVSprintf(&buf, ",chardev=char%s,id=%s",
-                      dev->info.alias, dev->info.alias);
     if (dev->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC &&
         dev->target.name &&
         STRNEQ(dev->target.name, "com.redhat.spice.0")) {
@@ -2221,8 +2223,15 @@ qemuBuildVirtioSerialPortDevStr(virDomainChrDefPtr dev)
                         dev->target.name);
         goto error;
     }
-    if (dev->target.name) {
-        virBufferVSprintf(&buf, ",name=%s", dev->target.name);
+    if ((qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE_SPICEVMC) &&
+        dev->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) {
+        virBufferVSprintf(&buf, ",id=%s", dev->info.alias);
+    } else {
+        virBufferVSprintf(&buf, ",chardev=char%s,id=%s",
+                          dev->info.alias, dev->info.alias);
+        if (dev->target.name) {
+            virBufferVSprintf(&buf, ",name=%s", dev->target.name);
+        }
     }
     if (virBufferError(&buf)) {
         virReportOOMError();
@@ -3681,16 +3690,25 @@ qemuBuildCommandLine(virConnectPtr conn,
                 goto error;
             }

-            virCommandAddArg(cmd, "-chardev");
-            if (!(devstr = qemuBuildChrChardevStr(&channel->source,
-                                                  channel->info.alias,
-                                                  qemuCmdFlags)))
-                goto error;
-            virCommandAddArg(cmd, devstr);
-            VIR_FREE(devstr);
+            if ((qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE_SPICEVMC) &&
+                channel->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) {
+                /* spicevmc was originally introduced via a -device
+                 * with a backend internal to qemu; although we prefer
+                 * the newer -chardev interface.  */
+                ;
+            } else {
+                virCommandAddArg(cmd, "-chardev");
+                if (!(devstr = qemuBuildChrChardevStr(&channel->source,
+                                                      channel->info.alias,
+                                                      qemuCmdFlags)))
+                    goto error;
+                virCommandAddArg(cmd, devstr);
+                VIR_FREE(devstr);
+            }

             virCommandAddArg(cmd, "-device");
-            if (!(devstr = qemuBuildVirtioSerialPortDevStr(channel)))
+            if (!(devstr = qemuBuildVirtioSerialPortDevStr(channel,
+                                                           qemuCmdFlags)))
                 goto error;
             virCommandAddArg(cmd, devstr);
             VIR_FREE(devstr);
@@ -3720,7 +3738,8 @@ qemuBuildCommandLine(virConnectPtr conn,
             VIR_FREE(devstr);

             virCommandAddArg(cmd, "-device");
-            if (!(devstr = qemuBuildVirtioSerialPortDevStr(console)))
+            if (!(devstr = qemuBuildVirtioSerialPortDevStr(console,
+                                                           qemuCmdFlags)))
                 goto error;
             virCommandAddArg(cmd, devstr);
             VIR_FREE(devstr);
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 6d57007..8135046 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -105,8 +105,6 @@ char * qemuBuildPCIHostdevDevStr(virDomainHostdevDefPtr dev,

 int qemuOpenPCIConfig(virDomainHostdevDefPtr dev);

-char * qemuBuildVirtioSerialPortDevStr(virDomainChrDefPtr dev);
-
 /* Legacy, pre device support */
 char * qemuBuildUSBHostdevUsbDevStr(virDomainHostdevDefPtr dev);
 /* Current, best practice */
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index 20ec08d..3a04b61 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -351,7 +351,8 @@ mymain(int argc, char **argv)
             QEMUD_CMD_FLAG_SPICE |
             QEMUD_CMD_FLAG_VGA_NONE |
             QEMUD_CMD_FLAG_MIGRATE_QEMU_FD |
-            QEMUD_CMD_FLAG_DRIVE_AIO,
+            QEMUD_CMD_FLAG_DRIVE_AIO |
+            QEMUD_CMD_FLAG_DEVICE_SPICEVMC,
             12001, 1,  0);
     DO_TEST("qemu-kvm-0.12.3",
             QEMUD_CMD_FLAG_VNC_COLON |
@@ -435,7 +436,8 @@ mymain(int argc, char **argv)
             QEMUD_CMD_FLAG_SPICE |
             QEMUD_CMD_FLAG_VGA_NONE |
             QEMUD_CMD_FLAG_MIGRATE_QEMU_FD |
-            QEMUD_CMD_FLAG_DRIVE_AIO,
+            QEMUD_CMD_FLAG_DRIVE_AIO |
+            QEMUD_CMD_FLAG_DEVICE_SPICEVMC,
             13000, 1,  0);
     DO_TEST("qemu-kvm-0.12.1.2-rhel61",
             QEMUD_CMD_FLAG_VNC_COLON |
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-channel-spicevmc-old.args b/tests/qemuxml2argvdata/qemuxml2argv-channel-spicevmc-old.args
new file mode 100644
index 0000000..7f499c7
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-channel-spicevmc-old.args
@@ -0,0 +1,8 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=spice \
+/usr/bin/qemu -S -M pc -m 214 -smp 1 -nodefconfig -nodefaults \
+-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -device \
+virtio-serial-pci,id=virtio-serial1,bus=pci.0,addr=0xa -hda \
+/dev/HostVG/QEMUGuest1 -device spicevmc,bus=virtio-serial1.0,nr=3,id=channel0 \
+-usb -spice port=5903,tls-port=5904,addr=127.0.0.1,\
+x509-dir=/etc/pki/libvirt-spice,tls-channel=main -device \
+virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-channel-spicevmc-old.xml b/tests/qemuxml2argvdata/qemuxml2argv-channel-spicevmc-old.xml
new file mode 100644
index 0000000..0e82394
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-channel-spicevmc-old.xml
@@ -0,0 +1,34 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory>219136</memory>
+  <vcpu cpuset='1-4,8-20,525'>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>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' unit='0'/>
+    </disk>
+    <controller type='ide' index='0'/>
+    <controller type='virtio-serial' index='1'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
+    </controller>
+    <graphics type='spice' port='5903' tlsPort='5904' autoport='no' listen='127.0.0.1'>
+      <channel name='main' mode='secure'/>
+    </graphics>
+    <channel type='spicevmc'>
+      <target type='virtio' name='com.redhat.spice.0'/>
+      <address type='virtio-serial' controller='1' bus='0' port='3'/>
+    </channel>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 9032528..9512bdc 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -410,6 +410,9 @@ mymain(int argc, char **argv)
     DO_TEST("channel-spicevmc", QEMUD_CMD_FLAG_DEVICE |
             QEMUD_CMD_FLAG_NODEFCONFIG | QEMUD_CMD_FLAG_SPICE |
             QEMUD_CMD_FLAG_CHARDEV_SPICEVMC, false);
+    DO_TEST("channel-spicevmc-old", QEMUD_CMD_FLAG_DEVICE |
+            QEMUD_CMD_FLAG_NODEFCONFIG | QEMUD_CMD_FLAG_SPICE |
+            QEMUD_CMD_FLAG_DEVICE_SPICEVMC, false);

     DO_TEST("smartcard-host",
             QEMUD_CMD_FLAG_CHARDEV | QEMUD_CMD_FLAG_DEVICE |
-- 
1.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]