qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Krasnyansky <maxk@kernel.org>
To: anthony@codemonkey.ws, qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org, Max Krasnyansky <maxk@kernel.org>
Subject: [Qemu-devel] [PATCH 6/8] husb: remove disconnect detection timer
Date: Fri, 15 Aug 2008 00:51:48 +0000	[thread overview]
Message-ID: <96efd57549c0ccebae1b7ecc49065c3f28bd996b.1218760447.git.maxk@kernel.org> (raw)
In-Reply-To: <cover.1218760447.git.maxk@kernel.org>
In-Reply-To: <cover.1218760447.git.maxk@kernel.org>

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 <maxk@kernel.org>
---
 usb-linux.c |   37 ++++++-------------------------------
 1 files changed, 6 insertions(+), 31 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 786ef1b..dd78bb6 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -82,11 +82,10 @@ typedef struct USBHostDevice {
     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 @@ static void async_complete(void *opaque)
             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 @@ static void usb_host_handle_destroy(USBDevice *dev)
 {
     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 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
     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 @@ static USBDevice *usb_host_device_open_addr(int bus_num, int addr, const char *p
     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 @@ static USBDevice *usb_host_device_open_addr(int bus_num, int addr, const char *p
     /* 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;
 }
-- 
1.5.5.1

  parent reply	other threads:[~2008-08-15  0:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-15  0:51 [Qemu-devel] [PATCH 0/8] Various USB fixes and improvements (update 2) Max Krasnyansky
2008-08-15  0:51 ` [Qemu-devel] [PATCH 1/8] husb: support for USB host device auto disconnect Max Krasnyansky
2008-08-15  0:51 ` [Qemu-devel] [PATCH 2/8] husb: support for USB host device auto connect Max Krasnyansky
2008-08-15  0:51 ` [Qemu-devel] [PATCH 3/8] usb: generic packet handler cleanup and documentation Max Krasnyansky
2008-08-15  0:51 ` [Qemu-devel] [PATCH 4/8] uhci: rewrite UHCI emulator, fully async operation with multiple outstanding transactions Max Krasnyansky
2008-08-15  0:51 ` [Qemu-devel] [PATCH 5/8] husb: rewrite Linux host USB layer, fully async operation Max Krasnyansky
2008-08-15  0:51 ` Max Krasnyansky [this message]
2008-08-15  0:51 ` [Qemu-devel] [PATCH 7/8] husb: Fixup printfs and stuff based on the review comments Max Krasnyansky
2008-08-15  0:51 ` [Qemu-devel] [PATCH 8/8] uhci: fixes for save/load-vm Max Krasnyansky
2008-08-18 14:02 ` [Qemu-devel] Re: [PATCH 0/8] Various USB fixes and improvements (update 2) Anthony Liguori
2008-08-18 14:14   ` Ian Jackson
2008-08-18 18:57   ` Max Krasnyansky
2008-08-21 18:44     ` Anthony Liguori
2008-08-21 19:36 ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=96efd57549c0ccebae1b7ecc49065c3f28bd996b.1218760447.git.maxk@kernel.org \
    --to=maxk@kernel.org \
    --cc=anthony@codemonkey.ws \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).