From patchwork Fri May 21 17:55:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shahar Havivi X-Patchwork-Id: 53198 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 A8F4EB7D2F for ; Sat, 22 May 2010 03:58:11 +1000 (EST) Received: from localhost ([127.0.0.1]:41906 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OFWU4-0002tj-NM for incoming@patchwork.ozlabs.org; Fri, 21 May 2010 13:58:08 -0400 Received: from [140.186.70.92] (port=36507 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OFWSK-00021D-Ge for qemu-devel@nongnu.org; Fri, 21 May 2010 13:56:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OFWSH-00015A-14 for qemu-devel@nongnu.org; Fri, 21 May 2010 13:56:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1433) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OFWSG-00014f-Pw for qemu-devel@nongnu.org; Fri, 21 May 2010 13:56:16 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4LHtTlk003139 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 21 May 2010 13:55:29 -0400 Received: from localhost (dhcp-1-229.tlv.redhat.com [10.35.1.229]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4LHtRpR012186; Fri, 21 May 2010 13:55:28 -0400 Date: Fri, 21 May 2010 20:55:24 +0300 From: Shahar Havivi To: Gerd Hoffmann Message-ID: <20100521175520.GA25276@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4BF62D5B.9050809@redhat.com> User-Agent: Mutt/1.5.20 (2009-08-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Markus Armbruster , "David S. Ahern" , qemu-devel@nongnu.org Subject: [Qemu-devel] Re: [PATCH] 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 Remove usb_host_device_release and using usb_host_close to handle usb_del command. Gerd, What do you think about the usb_cleanup()? If it will be in usb-linux.c we will have to ad atexit to each device, if we usb-bus.c we will have to implement in bsd and stub... Signed-off-by: Shahar Havivi --- hw/usb.h | 1 + usb-bsd.c | 5 +++++ usb-linux.c | 12 ++++++++++++ usb-stub.c | 5 +++++ vl.c | 1 + 5 files changed, 24 insertions(+), 0 deletions(-) diff --git a/hw/usb.h b/hw/usb.h index 00d2802..7ddf63c 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -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); +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..c3eb891 100644 --- a/usb-bsd.c +++ b/usb-bsd.c @@ -634,3 +634,8 @@ int usb_host_device_close(const char *devname) { return 0; } + +void usb_cleanup(void) +{ + return 0; +} diff --git a/usb-linux.c b/usb-linux.c index 88273ff..98909b7 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -286,6 +286,17 @@ static void async_cancel(USBPacket *unused, void *opaque) } } +void usb_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; @@ -991,6 +1002,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; diff --git a/usb-stub.c b/usb-stub.c index 9c3fcea..bb513de 100644 --- a/usb-stub.c +++ b/usb-stub.c @@ -50,3 +50,8 @@ int usb_host_device_close(const char *devname) { 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; }