Skip to contentSkip to conversation

Return contorl to host on usb_del monitor command

PATCH In review Shahar Havivi 2 participants 2 messages Apr 19, 2010 – May 18, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Return contorl to host on usb_del monitor command

When removing usb on guest via usb_del monitor command, qemu does not return the control to the host, the only solution user have is to unplug/plug the device again in order to get the device back to the host

---
 hw/usb-bus.c |    4 ++++
 hw/usb.h     |    1 +
 usb-linux.c  |   11 +++++++++++
 3 files changed, 16 insertions(+), 0 deletions(-)
hw/usb-bus.c +4 -0
index ee0e9e3..9781ac6 100644
@@ -208,6 +208,10 @@ int usb_device_delete_addr(int busnr, int addr)
         return -1;
     dev = port->dev;
 
+    if (!strcmp(dev->info->usbdevice_name, "host")) {
+        usb_host_device_release(dev);
+    }
+
     qdev_free(&dev->qdev);
     return 0;
 }
hw/usb.h +1 -0
index 00d2802..f6f7cc4 100644
@@ -258,6 +258,7 @@ void usb_send_msg(USBDevice *dev, int msg);
 USBDevice *usb_host_device_open(const char *devname);
 int usb_host_device_close(const char *devname);
 void usb_host_info(Monitor *mon);
+int usb_host_device_release(USBDevice *dev);
 
 /* usb-hid.c */
 void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *));
usb-linux.c +11 -0
index d0d7cff..9db94dd 100644
@@ -284,6 +284,17 @@ static void async_cancel(USBPacket *unused, void *opaque)
     }
 }
 
+/* release usb device, return control to host */
+int usb_host_device_release(USBDevice *dev)
+{
+    int ret;
+
+    USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev);
+    ret = ioctl(s->fd, USBDEVFS_RESET);
+
+    return ret;
+}
+
 static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
 {
     int dev_descr_len, config_descr_len;
Signature · 1 line
1.6.3.3
#1 lore raw
Quoted 47 lines · Shahar Havivi

When removing usb on guest via usb_del monitor command, qemu does not return the control to the host, the only solution user have is to unplug/plug the device again in order to get the device back to the host

---
 hw/usb-bus.c |    4 ++++
 hw/usb.h     |    1 +
 usb-linux.c  |   11 +++++++++++
 3 files changed, 16 insertions(+), 0 deletions(-)
hw/usb-bus.c +4 -0
index ee0e9e3..9781ac6 100644
@@ -208,6 +208,10 @@ int usb_device_delete_addr(int busnr, int addr)
         return -1;
     dev = port->dev;
 
+    if (!strcmp(dev->info->usbdevice_name, "host")) {
+        usb_host_device_release(dev);
+    }
+
     qdev_free(&dev->qdev);
     return 0;
 }
hw/usb.h +1 -0
index 00d2802..f6f7cc4 100644
@@ -258,6 +258,7 @@ void usb_send_msg(USBDevice *dev, int msg);
 USBDevice *usb_host_device_open(const char *devname);
 int usb_host_device_close(const char *devname);
 void usb_host_info(Monitor *mon);
+int usb_host_device_release(USBDevice *dev);
 
 /* usb-hid.c */
 void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *));
usb-linux.c +1 -0
index d0d7cff..9db94dd 100644
@@ -284,6 +284,17 @@ static void async_cancel(USBPacket *unused, void *opaque)
     }
 }
 
+/* release usb device, return control to host */

usb-linux.c static void async_cancel(USBPacket *unused, void *opaque) · line 297

Quoted 10 lines
usb-linux.c +10 -0
+int usb_host_device_release(USBDevice *dev)
+{
+    int ret;
+
+    USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev);
+    ret = ioctl(s->fd, USBDEVFS_RESET);
+
+    return ret;
+}
+

This function should also be added on usb-bsd.c and usb-stub.c, or at least an empty function.

Quoted 9 lines
usb-linux.c +0 -0
 static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
 {
     int dev_descr_len, config_descr_len;
Signature · 1 line
1.6.3.3
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net