From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KWFsx-0005EL-Fm for qemu-devel@nongnu.org; Thu, 21 Aug 2008 15:31:55 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KWFsx-0005Dw-1S for qemu-devel@nongnu.org; Thu, 21 Aug 2008 15:31:55 -0400 Received: from [199.232.76.173] (port=41502 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KWFsw-0005Ds-LS for qemu-devel@nongnu.org; Thu, 21 Aug 2008 15:31:54 -0400 Received: from savannah.gnu.org ([199.232.41.3]:57247 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KWFsw-0006cG-OW for qemu-devel@nongnu.org; Thu, 21 Aug 2008 15:31:54 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1KWFsv-0005Q7-I2 for qemu-devel@nongnu.org; Thu, 21 Aug 2008 19:31:53 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1KWFsv-0005Q3-93 for qemu-devel@nongnu.org; Thu, 21 Aug 2008 19:31:53 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 21 Aug 2008 19:31:53 +0000 Subject: [Qemu-devel] [5052] husb: remove disconnect detection timer (Max Krasnyansky) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 5052 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5052 Author: aliguori Date: 2008-08-21 19:31:52 +0000 (Thu, 21 Aug 2008) Log Message: ----------- husb: remove disconnect detection timer (Max Krasnyansky) On top of my previous USB patchset. Async completion handler can detect device disconnects without polling. We do not need the timer anymore. Signed-off-by: Max Krasnyansky Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/usb-linux.c Modified: trunk/usb-linux.c =================================================================== --- trunk/usb-linux.c 2008-08-21 19:31:10 UTC (rev 5051) +++ trunk/usb-linux.c 2008-08-21 19:31:52 UTC (rev 5052) @@ -82,11 +82,10 @@ uint8_t descr[1024]; int descr_len; int configuration; + int closing; struct endp_data endp_table[MAX_ENDPOINTS]; - QEMUTimer *timer; - /* Host side address */ int bus_num; int addr; @@ -186,7 +185,7 @@ if (errno == EAGAIN) return; - if (errno == ENODEV) { + if (errno == ENODEV && !s->closing) { printf("husb: device %d.%d disconnected\n", s->bus_num, s->addr); usb_device_del_addr(0, s->dev.addr); return; @@ -328,7 +327,8 @@ { USBHostDevice *s = (USBHostDevice *)dev; - qemu_del_timer(s->timer); + s->closing = 1; + qemu_set_fd_handler(s->fd, NULL, NULL, NULL); hostdev_unlink(s); @@ -582,22 +582,6 @@ return 0; } -static void usb_host_device_check(void *priv) -{ - USBHostDevice *s = priv; - struct usbdevfs_connectinfo ci; - int err; - - err = ioctl(s->fd, USBDEVFS_CONNECTINFO, &ci); - if (err < 0) { - printf("husb: device %d.%d disconnected\n", s->bus_num, s->addr); - usb_device_del_addr(0, s->dev.addr); - return; - } - - qemu_mod_timer(s->timer, qemu_get_clock(rt_clock) + 1000); -} - static USBDevice *usb_host_device_open_addr(int bus_num, int addr, const char *prod_name) { int fd = -1, ret; @@ -612,10 +596,6 @@ dev->bus_num = bus_num; dev->addr = addr; - dev->timer = qemu_new_timer(rt_clock, usb_host_device_check, (void *) dev); - if (!dev->timer) - goto fail; - printf("husb: open device %d.%d\n", bus_num, addr); snprintf(buf, sizeof(buf), USBDEVFS_PATH "/%03d/%03d", @@ -683,19 +663,14 @@ /* USB devio uses 'write' flag to check for async completions */ qemu_set_fd_handler(dev->fd, NULL, async_complete, dev); - /* Start the timer to detect disconnect */ - qemu_mod_timer(dev->timer, qemu_get_clock(rt_clock) + 1000); - hostdev_link(dev); return (USBDevice *) dev; fail: - if (dev) { - if (dev->timer) - qemu_del_timer(dev->timer); + if (dev) qemu_free(dev); - } + close(fd); return NULL; }