Signed-off-by: Shahar Havivi <shah...@redhat.com>
---
 usb-linux.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 22a85e3..4b5aeb6 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -33,6 +33,7 @@
 #include "qemu-common.h"
 #include "qemu-timer.h"
 #include "monitor.h"
+#include "sysemu.h"
 
 #include <dirent.h>
 #include <sys/ioctl.h>
@@ -89,6 +90,8 @@ static char *usb_host_device_path;
 #define USB_FS_SYS 3
 
 static int usb_fs_type;
+static int usb_notify_set;
+static Notifier usb_host_notifier;
 
 /* endpoint association data */
 struct endp_data {
@@ -286,6 +289,17 @@ static void async_cancel(USBPacket *unused, void *opaque)
     }
 }
 
+static void usb_host_cleanup(struct Notifier* n)
+{
+    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 +1080,11 @@ 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);
+    if (!usb_notify_set) {
+        usb_notify_set = 1;
+        usb_host_notifier.notify = usb_host_cleanup;
+        qemu_add_exit_notifier(&usb_host_notifier);
+    }
     return dev;
 
 fail:
-- 
1.7.0.4


Reply via email to