Support for USB host device auto disconnect.
PATCH 1/1 Support for USB host device auto disconnect.
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.
Signed-off-by Max Krasnyansky <[email protected]>
--- qemu/hw/usb.h | 1 + qemu/usb-linux.c | 56 +++++++++++++++++++++++++++++++++++++++++++++-------- qemu/vl.c | 26 +++++++++++++++++------- 3 files changed, 66 insertions(+), 17 deletions(-)
qemu/hw/usb.h +1 -0
@@ -197,6 +197,7 @@ static inline void usb_cancel_packet(USBPacket * p) 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);
qemu/usb-linux.c +47 -9
122 lines not on this page · raw message
qemu/vl.c +18 -8
@@ -5833,22 +5833,15 @@ static int usb_device_add(const char *devname)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 ;
@@ -5871,6 +5864,23 @@ static int usb_device_del(const char *devname)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;
Signature · 1 line
1.5.5.1