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.

Signed-off-by: Max Krasnyansky <maxk@kernel.org>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5047 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
aliguori 2008-08-21 19:27:48 +00:00
parent cd01b4a312
commit 1f3870ab24
3 changed files with 68 additions and 19 deletions

26
vl.c
View file

@ -5809,22 +5809,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;
@ -5847,6 +5840,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;