From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 5/9] usb-host: handle USBDEVFS_SETCONFIGURATION returning EBUSY
Date: Thu, 13 Oct 2011 13:08:27 +0200 [thread overview]
Message-ID: <1318504111-15309-6-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1318504111-15309-1-git-send-email-kraxel@redhat.com>
In case the host uses the usb device usbfs will refuse to set the
configuration due to the device being busy. Handle this case by
disconnection the interfaces, then trying again.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
usb-linux.c | 36 +++++++++++++++++++++++++++++++++++-
1 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/usb-linux.c b/usb-linux.c
index ff1a29c..7d4d1d7 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -485,6 +485,26 @@ static int usb_host_disconnect_ifaces(USBHostDevice *dev, int nb_interfaces)
return 0;
}
+static int usb_linux_get_num_interfaces(USBHostDevice *s)
+{
+ char device_name[64], line[1024];
+ int num_interfaces = 0;
+
+ if (usb_fs_type != USB_FS_SYS) {
+ return -1;
+ }
+
+ sprintf(device_name, "%d-%s", s->bus_num, s->port);
+ if (!usb_host_read_file(line, sizeof(line), "bNumInterfaces",
+ device_name)) {
+ return -1;
+ }
+ if (sscanf(line, "%d", &num_interfaces) != 1) {
+ return -1;
+ }
+ return num_interfaces;
+}
+
static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
{
const char *op = NULL;
@@ -901,14 +921,28 @@ static int usb_host_set_address(USBHostDevice *s, int addr)
static int usb_host_set_config(USBHostDevice *s, int config)
{
+ int ret, first = 1;
+
trace_usb_host_set_config(s->bus_num, s->addr, config);
usb_host_release_interfaces(s);
- int ret = ioctl(s->fd, USBDEVFS_SETCONFIGURATION, &config);
+again:
+ ret = ioctl(s->fd, USBDEVFS_SETCONFIGURATION, &config);
DPRINTF("husb: ctrl set config %d ret %d errno %d\n", config, ret, errno);
+ if (ret < 0 && errno == EBUSY && first) {
+ /* happens if usb device is in use by host drivers */
+ int count = usb_linux_get_num_interfaces(s);
+ if (count > 0) {
+ DPRINTF("husb: busy -> disconnecting %d interfaces\n", count);
+ usb_host_disconnect_ifaces(s, count);
+ first = 0;
+ goto again;
+ }
+ }
+
if (ret < 0) {
return ctrl_error();
}
--
1.7.1
next prev parent reply other threads:[~2011-10-13 11:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-13 11:08 [Qemu-devel] [PULL] usb patch queue Gerd Hoffmann
2011-10-13 11:08 ` [Qemu-devel] [PATCH 1/9] usb-storage: fix NULL pointer dereference Gerd Hoffmann
2011-10-13 11:08 ` [Qemu-devel] [PATCH 2/9] usb-hub: need to check dev->attached Gerd Hoffmann
2011-10-13 11:08 ` [Qemu-devel] [PATCH 3/9] usb: fix port reset Gerd Hoffmann
2011-10-13 11:08 ` [Qemu-devel] [PATCH 4/9] usb-host: factor out code Gerd Hoffmann
2011-10-13 11:08 ` Gerd Hoffmann [this message]
2011-10-13 11:08 ` [Qemu-devel] [PATCH 6/9] hw/usb-ohci: Fix OHCI_TD_T1 bit position definition Gerd Hoffmann
2011-10-13 11:08 ` [Qemu-devel] [PATCH 7/9] hw/usb-ohci: Honour endpoint maximum packet size Gerd Hoffmann
2011-10-13 11:08 ` [Qemu-devel] [PATCH 8/9] usb-hid: activate usb tablet / mouse after migration Gerd Hoffmann
2011-10-13 11:08 ` [Qemu-devel] [PATCH 9/9] usb-hub: don't trigger assert on packet completion Gerd Hoffmann
2011-10-13 11:34 ` Gerd Hoffmann
2011-10-14 16:25 ` [Qemu-devel] [PULL] usb patch queue 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=1318504111-15309-6-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).