Comment 0 for bug 1219435

Revision history for this message
Nils Naumann (nau) wrote :

Ubuntu 13.04

libvirt0: 1.0.2-0ubuntu11.13.04.2

The automatic unplugging of usb devices (in this case a Lego NXT) doesn't work any more. The following udev rule is used;

ACTION=="remove", \
    SUBSYSTEMS=="usb", \
    ATTRS{idVendor}=="0694", \
    ATTRS{idProduct}=="0002", \
    RUN+="/usr/bin/virsh detach-device WinXP-clone /var/lib/libvirt/images/hostdev-0694:0002.xml"
ACTION=="add", \
    SUBSYSTEMS=="usb", \
    ATTRS{idVendor}=="0694", \
    ATTRS{idProduct}=="0002", \
    RUN+="/usr/bin/virsh attach-device WinXP-clone /var/lib/libvirt/images/hostdev-0694:0002.xml"

the reason is apparently a bug in 'virsh detach-device':

$ /usr/bin/virsh attach-device WinXP-clone /var/lib/libvirt/images/hostdev-0694:0002.xml
Device attached successfully

$ /usr/bin/virsh detach-device WinXP-clone /var/lib/libvirt/images/hostdev-0694:0002.xml
Fehler: Fehler beim Lösen des Geräts von /var/lib/libvirt/images/hostdev-0694:0002.xml
Fehler: operation failed: host usb device vendor=0x0694 product=0x0002 not found

$ cat /var/lib/libvirt/images/hostdev-0694:0002.xml
<!--NXT -->
<hostdev mode='subsystem' type='usb' managed='yes'>
  <source>
    <vendor id='0x0694'/>
    <product id='0x0002'/>
  </source>
</hostdev>

A fix might be described in RH bug# 916837:
---
 src/conf/domain_conf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4cae0d3..2b2f35c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8541,7 +8541,7 @@ static int
 virDomainHostdevMatchSubsysUSB(virDomainHostdevDefPtr a,
                                virDomainHostdevDefPtr b)
 {
- if (b->source.subsys.u.usb.bus && b->source.subsys.u.usb.device) {
+ if (a->source.subsys.u.usb.bus && a->source.subsys.u.usb.device) {
         /* specified by bus location on host */
         if (a->source.subsys.u.usb.bus == b->source.subsys.u.usb.bus &&
             a->source.subsys.u.usb.device == b->source.subsys.u.usb.device)
--
1.7.11.2