qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 01/12] usb-linux: catch NODEV in more places.
Date: Thu, 26 May 2011 12:44:03 +0200	[thread overview]
Message-ID: <1306406654-19351-2-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1306406654-19351-1-git-send-email-kraxel@redhat.com>

Factor out disconnect code (called when a device disappears) to a
separate function.  Add a check for NODEV errno to a few more places to
make sure we notice disconnects.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 usb-linux.c |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index baa6574..b195e38 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -268,6 +268,14 @@ static void async_free(AsyncURB *aurb)
     qemu_free(aurb);
 }
 
+static void do_disconnect(USBHostDevice *s)
+{
+    printf("husb: device %d.%d disconnected\n",
+           s->bus_num, s->addr);
+    usb_host_close(s);
+    usb_host_auto_check(NULL);
+}
+
 static void async_complete(void *opaque)
 {
     USBHostDevice *s = opaque;
@@ -282,10 +290,7 @@ static void async_complete(void *opaque)
                 return;
             }
             if (errno == ENODEV && !s->closing) {
-                printf("husb: device %d.%d disconnected\n",
-                       s->bus_num, s->addr);
-                usb_host_close(s);
-                usb_host_auto_check(NULL);
+                do_disconnect(s);
                 return;
             }
 
@@ -359,6 +364,7 @@ static void usb_host_async_cancel(USBDevice *dev, USBPacket *p)
 
 static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
 {
+    const char *op = NULL;
     int dev_descr_len, config_descr_len;
     int interface, nb_interfaces;
     int ret, i;
@@ -411,9 +417,9 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
             ctrl.ioctl_code = USBDEVFS_DISCONNECT;
             ctrl.ifno = interface;
             ctrl.data = 0;
+            op = "USBDEVFS_DISCONNECT";
             ret = ioctl(dev->fd, USBDEVFS_IOCTL, &ctrl);
             if (ret < 0 && errno != ENODATA) {
-                perror("USBDEVFS_DISCONNECT");
                 goto fail;
             }
         }
@@ -422,6 +428,7 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
 
     /* XXX: only grab if all interfaces are free */
     for (interface = 0; interface < nb_interfaces; interface++) {
+        op = "USBDEVFS_CLAIMINTERFACE";
         ret = ioctl(dev->fd, USBDEVFS_CLAIMINTERFACE, &interface);
         if (ret < 0) {
             if (errno == EBUSY) {
@@ -429,8 +436,7 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
             } else {
                 perror("husb: failed to claim interface");
             }
-        fail:
-            return 0;
+            goto fail;
         }
     }
 
@@ -440,6 +446,13 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
     dev->ninterfaces   = nb_interfaces;
     dev->configuration = configuration;
     return 1;
+
+fail:
+    if (errno == ENODEV) {
+        do_disconnect(dev);
+    }
+    perror(op);
+    return 0;
 }
 
 static int usb_host_release_interfaces(USBHostDevice *s)
-- 
1.7.1

  reply	other threads:[~2011-05-26 10:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-26 10:44 [Qemu-devel] [PATCH 00/12] ehci: tracing, multiqueue, bugfixes Gerd Hoffmann
2011-05-26 10:44 ` Gerd Hoffmann [this message]
2011-05-26 18:20   ` [Qemu-devel] [PATCH 01/12] usb-linux: catch NODEV in more places Markus Armbruster
2011-05-27  5:58     ` Gerd Hoffmann
2011-05-26 10:44 ` [Qemu-devel] [PATCH 02/12] usb-ehci: trace mmio and usbsts Gerd Hoffmann
2011-05-26 10:44 ` [Qemu-devel] [PATCH 03/12] usb-ehci: trace state machine changes Gerd Hoffmann
2011-05-26 10:44 ` [Qemu-devel] [PATCH 04/12] usb-ehci: trace port state Gerd Hoffmann
2011-05-26 10:44 ` [Qemu-devel] [PATCH 05/12] usb-ehci: improve mmio tracing Gerd Hoffmann
2011-05-26 10:44 ` [Qemu-devel] [PATCH 06/12] usb-ehci: trace buffer copy Gerd Hoffmann
2011-05-26 10:44 ` [Qemu-devel] [PATCH 07/12] usb-ehci: add queue data struct Gerd Hoffmann
2011-05-26 10:44 ` [Qemu-devel] [PATCH 08/12] usb-ehci: multiqueue support Gerd Hoffmann
2011-05-26 10:44 ` [Qemu-devel] [PATCH 09/12] usb-ehci: fix offset writeback in ehci_buffer_rw Gerd Hoffmann
2011-05-26 10:44 ` [Qemu-devel] [PATCH 10/12] usb-ehci: fix error handling Gerd Hoffmann
2011-05-26 10:44 ` [Qemu-devel] [PATCH 11/12] ehci: fix a number of unused-but-set-variable warnings (new with gcc-4.6) Gerd Hoffmann
2011-05-26 10:44 ` [Qemu-devel] [PATCH 12/12] usb: cancel async packets on unplug Gerd Hoffmann

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=1306406654-19351-2-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --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).