All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alon Levy <alevy@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] monitor: add usb_detach
Date: Tue, 5 Oct 2010 16:40:29 +0200	[thread overview]
Message-ID: <20101005164029.92f21cb3.alevy@redhat.com> (raw)

Signed-off-by: Alon Levy <alevy@redhat.com>

---
 qemu-monitor.hx |   17 +++++++++++++++++
 sysemu.h        |    1 +
 vl.c            |   41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index 49bcd8d..9c792a9 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -711,6 +711,23 @@ command @code{info usb} to see the devices you can remove.
 ETEXI
 
     {
+        .name       = "usb_detach",
+        .args_type  = "devname:s",
+        .params     = "device",
+        .help       = "detach USB device 'bus.addr'",
+        .mhandler.cmd = do_usb_detach,
+    },
+
+STEXI
+@item usb_detach @var{devname}
+@findex usb_detach
+
+Detach the USB device @var{devname} from the QEMU virtual USB
+hub. @var{devname} has the syntax @code{bus.addr}. Use the monitor
+command @code{info usb} to see the devices you can detach.
+ETEXI
+
+    {
         .name       = "device_add",
         .args_type  = "device:O",
         .params     = "driver[,prop=value][,...]",
diff --git a/sysemu.h b/sysemu.h
index a1f6466..ac68863 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -183,6 +183,7 @@ extern struct soundhw soundhw[];
 
 void do_usb_add(Monitor *mon, const QDict *qdict);
 void do_usb_del(Monitor *mon, const QDict *qdict);
+void do_usb_detach(Monitor *mon, const QDict *qdict);
 void usb_info(Monitor *mon);
 
 void rtc_change_mon_event(struct tm *tm);
diff --git a/vl.c b/vl.c
index d352d18..6cfa009 100644
--- a/vl.c
+++ b/vl.c
@@ -891,6 +891,47 @@ void do_usb_del(Monitor *mon, const QDict *qdict)
     }
 }
 
+static USBDevice *usb_device_from_bus_dot_addr(const char *devname)
+{
+    int bus_num, addr;
+    const char *p;
+    USBBus *bus;
+    USBPort *port;
+
+    if (!usb_enabled) {
+        return NULL;
+    }
+    p = strchr(devname, '.');
+    if (!p) {
+        return NULL;
+    }
+    bus_num = strtoul(devname, NULL, 0);
+    addr = strtoul(p + 1, NULL, 0);
+    bus = usb_bus_find(bus_num);
+    if (!bus) {
+        return NULL;
+    }
+    QTAILQ_FOREACH(port, &bus->used, next) {
+        if (port->dev->addr == addr) {
+            break;
+        }
+    }
+    if (!port) {
+        return NULL;
+    }
+    return port->dev;
+}
+
+void do_usb_detach(Monitor *mon, const QDict *qdict)
+{
+    const char *devname = qdict_get_str(qdict, "devname");
+    USBDevice *dev = usb_device_from_bus_dot_addr(devname);
+
+    if (dev == NULL || usb_device_detach(dev) < 0) {
+        error_report("could not detach USB device '%s'", devname);
+    }
+}
+
 /***********************************************************/
 /* PCMCIA/Cardbus */
 
-- 
1.7.3.1



-- 
Alon Levy <alevy@redhat.com>

             reply	other threads:[~2010-10-05 14:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-05 14:40 Alon Levy [this message]
2010-10-08 18:08 ` [Qemu-devel] [PATCH] monitor: add usb_detach Luiz Capitulino
2010-10-08 18:43 ` Anthony Liguori
2010-10-10 11:12   ` Alon Levy
2010-10-11  7:51     ` Gerd Hoffmann
2010-10-11 11:02       ` Alon Levy

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=20101005164029.92f21cb3.alevy@redhat.com \
    --to=alevy@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.