[libvirt] [PATCH] Learn to use spicevmc as a redirection type for usb-redir

Marc-André Lureau marcandre.lureau at gmail.com
Mon Aug 29 20:06:36 UTC 2011


This patch should be applied on top of "Add usb-redir device"
https://www.redhat.com/archives/libvir-list/2011-August/msg01294.html
---
 src/conf/domain_conf.c                             |   31 ++++++++++++++++---
 src/conf/domain_conf.h                             |    1 +
 tests/qemuxml2argvdata/qemuxml2argv-usb-redir.args |    2 +
 tests/qemuxml2argvdata/qemuxml2argv-usb-redir.xml  |    1 +
 tests/qemuxml2argvtest.c                           |    3 +-
 5 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 31330a5..1bf893e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -288,7 +288,8 @@ VIR_ENUM_IMPL(virDomainChrTcpProtocol, VIR_DOMAIN_CHR_TCP_PROTOCOL_LAST,
 
 VIR_ENUM_IMPL(virDomainChrSpicevmc, VIR_DOMAIN_CHR_SPICEVMC_LAST,
               "vdagent",
-              "smartcard")
+              "smartcard",
+              "usbredir")
 
 VIR_ENUM_IMPL(virDomainSmartcard, VIR_DOMAIN_SMARTCARD_TYPE_LAST,
               "host",
@@ -5396,11 +5397,16 @@ virDomainHostdevDefParseXML(const xmlNodePtr node,
                                  redirection);
             goto error;
         }
+
         if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
             virDomainReportError(VIR_ERR_INTERNAL_ERROR,
                                  _("only usb redirection is supported"));
             goto error;
         }
+
+        if (def->source.subsys.u.chr.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) {
+            def->source.subsys.u.chr.data.spicevmc = VIR_DOMAIN_CHR_SPICEVMC_USBREDIR;
+        }
     }
 
     cur = node->children;
@@ -10159,13 +10165,28 @@ virDomainHostdevDefFormat(virBufferPtr buf,
                       mode, type, def->managed ? "yes" : "no");
     if (redirection != NULL) {
         virBufferAsprintf(buf, " redirection='%s'", redirection);
+
+        if (def->source.subsys.u.chr.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) {
+            virBufferAddLit(buf, "/>\n");
+            return 0;
+        }
     }
+
     virBufferAddLit(buf, ">\n");
+
     virBufferAddLit(buf, "      <source");
-    if (def->redirection) {
-        virBufferAsprintf(buf, " mode='connect' host='%s' service='%s'/",
-                          def->source.subsys.u.chr.data.tcp.host,
-                          def->source.subsys.u.chr.data.tcp.service);
+    if (def->redirection)
+        switch (def->source.subsys.u.chr.type) {
+        case VIR_DOMAIN_CHR_TYPE_TCP:
+            virBufferAsprintf(buf, " mode='connect' host='%s' service='%s'/",
+                              def->source.subsys.u.chr.data.tcp.host,
+                              def->source.subsys.u.chr.data.tcp.service);
+            break;
+        default:
+            virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+                                 _("unsupported redirection type %s"),
+                                 redirection);
+            return -1;
     }
     virBufferAddLit(buf, ">\n");
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ff25743..379332d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -538,6 +538,7 @@ enum virDomainChrTcpProtocol {
 enum virDomainChrSpicevmcName {
     VIR_DOMAIN_CHR_SPICEVMC_VDAGENT,
     VIR_DOMAIN_CHR_SPICEVMC_SMARTCARD,
+    VIR_DOMAIN_CHR_SPICEVMC_USBREDIR,
 
     VIR_DOMAIN_CHR_SPICEVMC_LAST,
 };
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.args
index 0949585..585ae53 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.args
@@ -5,4 +5,6 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc
 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,multifunction=on,addr=0x4.0x2 \
 -chardev socket,id=charusbredir0,host=localhost,port=4000 \
 -device usb-redir,chardev=charusbredir0,id=usbredir0 \
+-chardev spicevmc,id=charusbredir1,name=usbredir \
+-device usb-redir,chardev=charusbredir1,id=usbredir1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,multifunction=on,addr=0x3.0x0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.xml
index bb50b81..a67facc 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.xml
@@ -28,6 +28,7 @@
     <hostdev mode='subsystem' type='usb' redirection='tcp'>
       <source mode='connect' host='localhost' service='4000'/>
     </hostdev>
+    <hostdev mode='subsystem' type='usb' redirection='spicevmc'/>
     <memballoon model='virtio'/>
   </devices>
 </domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 35e6d27..090ec7a 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -511,7 +511,8 @@ mymain(void)
     DO_TEST("usb-redir", false,
             QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
             QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_USB_HUB,
-            QEMU_CAPS_ICH9_USB_EHCI1, QEMU_CAPS_USB_REDIR);
+            QEMU_CAPS_ICH9_USB_EHCI1, QEMU_CAPS_USB_REDIR,
+            QEMU_CAPS_SPICE, QEMU_CAPS_CHARDEV_SPICEVMC);
 
     DO_TEST("smbios", false, QEMU_CAPS_SMBIOS_TYPE);
 
-- 
1.7.6




More information about the libvir-list mailing list