Skip to contentSkip to conversation

[5047] husb: support for USB host device auto disconnect (Max Krasnyansky)

Qemu-devel Anthony Liguori 1 participant 1 message Aug 21, 2008

lore
Share & tools
lore
#0 lore raw

Revision: 5047

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5047
Author:   aliguori
Date:     2008-08-21 19:27:48 +0000 (Thu, 21 Aug 2008)

Log Message:
-----------
husb: support for USB host device auto disconnect (Max Krasnyansky)

I got really annoyed by the fact that you have to manually do usb_del in the monitor when host device is unplugged and decided to fix it :)

Basically we now automatically remove guest USB device when the actual host device is disconnected.

At first I've extended set_fd_handlerX() stuff to support checking for exceptions on fds. But unfortunately usbfs code does not wake up user-space process when device is removed, which means we need a timer to periodically check if device is still there. So I removed fd exception stuff and implemented it with the timer.

Modified Paths:
--------------
trunk/hw/usb.h
trunk/usb-linux.c
trunk/vl.c

Modified: trunk/hw/usb.h
===================================================================

hw/usb.h +1 -0
@@ -197,6 +197,7 @@
     p->cancel_cb(p, p->cancel_opaque);
 }
 
+int usb_device_del_addr(int bus_num, int addr);
 void usb_attach(USBPort *port, USBDevice *dev);
 int usb_generic_handle_packet(USBDevice *s, USBPacket *p);
 int set_usb_string(uint8_t *buf, const char *str);

Modified: trunk/usb-linux.c
===================================================================

usb-linux.c +47 -9

122 lines not on this page · raw message

Modified: trunk/vl.c
===================================================================

vl.c +18 -8
@@ -5809,22 +5809,15 @@
     return 0;
 }
 
-static int usb_device_del(const char *devname)
+int usb_device_del_addr(int bus_num, int addr)
 {
     USBPort *port;
     USBPort **lastp;
     USBDevice *dev;
-    int bus_num, addr;
-    const char *p;
 
     if (!used_usb_ports)
         return -1;
 
-    p = strchr(devname, '.');
-    if (!p)
-        return -1;
-    bus_num = strtoul(devname, NULL, 0);
-    addr = strtoul(p + 1, NULL, 0);
     if (bus_num != 0)
         return -1;
 
@@ -5847,6 +5840,23 @@
     return 0;
 }
 
+static int usb_device_del(const char *devname)
+{
+    int bus_num, addr;
+    const char *p;
+
+    if (!used_usb_ports)
+        return -1;
+
+    p = strchr(devname, '.');
+    if (!p)
+        return -1;
+    bus_num = strtoul(devname, NULL, 0);
+    addr = strtoul(p + 1, NULL, 0);
+
+    return usb_device_del_addr(bus_num, addr);
+}
+
 void do_usb_add(const char *devname)
 {
     int ret;