From patchwork Wed May 19 18:10:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shahar Havivi X-Patchwork-Id: 53005 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 98995B7D2E for ; Thu, 20 May 2010 04:12:14 +1000 (EST) Received: from localhost ([127.0.0.1]:51632 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OEnkY-0002cH-D7 for incoming@patchwork.ozlabs.org; Wed, 19 May 2010 14:12:10 -0400 Received: from [140.186.70.92] (port=50344 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OEnjC-0002Hd-DZ for qemu-devel@nongnu.org; Wed, 19 May 2010 14:10:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OEnjA-00077W-J3 for qemu-devel@nongnu.org; Wed, 19 May 2010 14:10:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62530) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OEnjA-00077F-BF for qemu-devel@nongnu.org; Wed, 19 May 2010 14:10:44 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4JIAgBW003222 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 19 May 2010 14:10:42 -0400 Received: from localhost (dhcp-1-229.tlv.redhat.com [10.35.1.229]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4JIAdtg015259 for ; Wed, 19 May 2010 14:10:40 -0400 Date: Wed, 19 May 2010 21:10:34 +0300 From: Shahar Havivi To: qemu-devel@nongnu.org Message-ID: <20100519181031.GA19410@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH v2] Release usb devices on shutdown and usb_del command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When closig Vm or removing usb on guest via usb_del monitor command, qemu does not return the control to the host, the user have to unplug and plug the device in order to use it on the host. v2: added empty methods to usb-bsd and usb-stub. release usb devices when main is out. Signed-off-by: Shahar Havivi --- hw/usb-bus.c | 4 ++++ hw/usb.h | 2 ++ usb-bsd.c | 10 ++++++++++ usb-linux.c | 21 +++++++++++++++++++++ usb-stub.c | 10 ++++++++++ vl.c | 1 + 6 files changed, 48 insertions(+), 0 deletions(-) diff --git a/hw/usb-bus.c b/hw/usb-bus.c index b692503..75dc819 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -207,6 +207,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; } diff --git a/hw/usb.h b/hw/usb.h index 00d2802..08c48d2 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -258,6 +258,8 @@ 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); +void usb_cleanup(void); /* usb-hid.c */ void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *)); diff --git a/usb-bsd.c b/usb-bsd.c index 48567a3..fc9ea80 100644 --- a/usb-bsd.c +++ b/usb-bsd.c @@ -634,3 +634,13 @@ int usb_host_device_close(const char *devname) { return 0; } + +int usb_host_device_release(USBDevice *dev) +{ + return 0; +} + +void usb_cleanup(void) +{ + return 0; +} diff --git a/usb-linux.c b/usb-linux.c index 88273ff..cea5b84 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -286,6 +286,27 @@ static void async_cancel(USBPacket *unused, void *opaque) } } +void usb_cleanup(void) +{ + struct USBHostDevice *s; + + QTAILQ_FOREACH(s, &hostdevs, next) { + if (s->fd != -1) { + usb_host_device_release((USBDevice*)s); + } + } +} + +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; diff --git a/usb-stub.c b/usb-stub.c index 9c3fcea..4432c2e 100644 --- a/usb-stub.c +++ b/usb-stub.c @@ -50,3 +50,13 @@ int usb_host_device_close(const char *devname) { return 0; } + +int usb_host_device_release(USBDevice *dev) +{ + return 0; +} + +void usb_cleanup(void) +{ + return 0; +} diff --git a/vl.c b/vl.c index d77b47c..e3f4dc9 100644 --- a/vl.c +++ b/vl.c @@ -3914,6 +3914,7 @@ int main(int argc, char **argv, char **envp) main_loop(); quit_timers(); net_cleanup(); + usb_cleanup(); return 0; }