Release usb devices on shutdown and usb_del command
v3 cover Release usb devices on shutdown and usb_del command
v3:
separate usb hot-unplug and host terminate handling remove empty methods from bsd and stub
added usb-linux atexit method to reset usb devices on termination
Shahar Havivi (2):
Return usb device to host on usb_del command
Return usb device to host on exit
usb-linux.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
PATCH v3 1/2 Return usb device to host on usb_del command
--- usb-linux.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
usb-linux.c +1 -0
@@ -991,6 +991,7 @@ static int usb_host_close(USBHostDevice *dev)async_complete (dev); dev->closing =0 ;usb_device_detach (&dev->dev); +ioctl (dev->fd,USBDEVFS_RESET );close (dev->fd); dev->fd =-1 ;return 0 ;
Signature · 1 line
1.7.0.4
PATCH v3 2/2 Return usb device to host on exit
In reply to Shahar Havivi--- usb-linux.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
usb-linux.c +12 -0
@@ -286,6 +286,17 @@ static void async_cancel(USBPacket *unused, void *opaque) } } +static void usb_host_cleanup (void ) +{ +struct USBHostDevice *s; + + QTAILQ_FOREACH(s, &hostdevs, next) { +if (s->fd !=-1 ) { +ioctl (s->fd,USBDEVFS_RESET ); + } + } +} +static int usb_host_claim_interfaces (USBHostDevice *dev,int configuration) {int dev_descr_len, config_descr_len;
@@ -1066,6 +1077,7 @@ USBDevice *usb_host_device_open(const char *devname)qdev_prop_set_uint32 (&dev->qdev,"vendorid" , filter.vendor_id);qdev_prop_set_uint32 (&dev->qdev,"productid" , filter.product_id);qdev_init_nofail (&dev->qdev); +atexit (usb_host_cleanup);return dev; fail:
Signature · 1 line
1.7.0.4
Re: [Qemu-devel] [PATCH 2/2] Return usb device to host on exit
usb-linux.c USBDevice *usb_host_device_open(const char *devname) · line 1081
Quoted 6 lines
usb-linux.c +1
-0@@ -1066,6 +1077,7 @@ USBDevice *usb_host_device_open(const char *devname)qdev_prop_set_uint32 (&dev->qdev,"vendorid" , filter.vendor_id);qdev_prop_set_uint32 (&dev->qdev,"productid" , filter.product_id);qdev_init_nofail (&dev->qdev); +atexit (usb_host_cleanup);return dev;
You'll register atexit multiple times here (once per device).
I still think this should use exit notifiers, see http://patchwork.ozlabs.org/patch/54571/ (doesn't apply cleanly and more, will post a rebased version later today).
cheers,
Gerd