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

[libvirt] [PATCH] redirdev: allows to specify device address



It is important to be able to attach USB redirected devices to a
particular controller (one that supports USB2 for instance).
Without this patch, only the default bus was used.

     <redirdev bus='usb' type='spicevmc'>
       <address type='usb' bus='0' port='4'/>
     </redirdev>
---
 docs/formatdomain.html.in                          |   19 +++++++++++++------
 docs/schemas/domaincommon.rng                      |    3 +++
 src/conf/domain_conf.c                             |   14 ++++++++++++++
 tests/qemuxml2argvdata/qemuxml2argv-usb-redir.args |    2 +-
 tests/qemuxml2argvdata/qemuxml2argv-usb-redir.xml  |    1 +
 5 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index b960381..399388f 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1417,14 +1417,21 @@
         tunnel; <code>type='tcp'</code>
         or <code>type='spicevmc'</code> (which uses the usbredir
         channel of a <a href="#elementsGraphics">SPICE graphics
-        device</a>) are typical.  Further sub-elements, such
-        as <code>&lt;source&gt;</code>, may be required according to
-        the given type, although a <code>&lt;target&gt;</code>
-        sub-element is not required (since the consumer of the
-        character device is the hypervisor itself, rather than a
-        device visible in the guest).</dd>
+        device</a>) are typical.</dd>
 
     </dl>
+    <p>
+      The redirdev element has an optional sub-element
+      <code>&lt;address&gt;</code> which can tie the device to a
+      particular controller.
+    </p>
+    <p>
+      Further sub-elements, such as <code>&lt;source&gt;</code>, may
+      be required according to the given type, although
+      a <code>&lt;target&gt;</code> sub-element is not required (since
+      the consumer of the character device is the hypervisor itself,
+      rather than a device visible in the guest).
+    </p>
 
     <h4><a name="elementsSmartcard">Smartcard devices</a></h4>
 
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 8e7fd63..02c3c7f 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1986,6 +1986,9 @@
         <ref name="qemucdevSrcTypeChoice"/>
       </attribute>
       <ref name="qemucdevSrcDef"/>
+      <optional>
+        <ref name="address"/>
+      </optional>
     </element>
   </define>
   <define name="hostdev">
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index cce9955..706f445 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5518,6 +5518,18 @@ virDomainRedirdevDefParseXML(const xmlNodePtr node,
         def->source.chr.data.spicevmc = VIR_DOMAIN_CHR_SPICEVMC_USBREDIR;
     }
 
+    if (virDomainDeviceInfoParseXML(node, &def->info, flags) < 0)
+        goto error;
+
+    if (def->bus == VIR_DOMAIN_REDIRDEV_BUS_USB &&
+        def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+        def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
+        virDomainReportError(VIR_ERR_XML_ERROR, "%s",
+                             _("Invalid address for a USB device"));
+        goto error;
+    }
+
+
 cleanup:
     VIR_FREE(bus);
     VIR_FREE(type);
@@ -10274,6 +10286,8 @@ virDomainRedirdevDefFormat(virBufferPtr buf,
     virBufferAsprintf(buf, "    <redirdev bus='%s'", bus);
     if (virDomainChrSourceDefFormat(buf, &def->source.chr, false, flags) < 0)
         return -1;
+    if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+        return -1;
     virBufferAddLit(buf, "    </redirdev>\n");
 
     return 0;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.args
index 4d4f30a..f6270d5 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.args
@@ -6,5 +6,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc
 -chardev socket,id=charredir0,host=localhost,port=4000 \
 -device usb-redir,chardev=charredir0,id=redir0 \
 -chardev spicevmc,id=charredir1,name=usbredir \
--device usb-redir,chardev=charredir1,id=redir1 \
+-device usb-redir,chardev=charredir1,id=redir1,bus=usb.0,port=4 \
 -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 c73e569..1dac3fb 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-redir.xml
@@ -34,6 +34,7 @@
       <protocol type='raw'/>
     </redirdev>
     <redirdev bus='usb' type='spicevmc'>
+      <address type='usb' bus='0' port='4'/>
     </redirdev>
     <memballoon model='virtio'/>
   </devices>
-- 
1.7.6


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