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 5/7] usb-storage: use qdev for -usbdevice
Date: Mon, 26 Oct 2009 15:56:49 +0100	[thread overview]
Message-ID: <1256569011-20256-6-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1256569011-20256-1-git-send-email-kraxel@redhat.com>

Hook up usb_msd_init.

Also rework handling of encrypted block devices,
move the code out vl.c.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb-msd.c |   33 +++++++++++++++++++++++++--------
 hw/usb.h     |    4 ----
 vl.c         |   25 -------------------------
 3 files changed, 25 insertions(+), 37 deletions(-)

diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index dd3010e..8dc494f 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -14,6 +14,7 @@
 #include "block.h"
 #include "scsi-disk.h"
 #include "console.h"
+#include "monitor.h"
 
 //#define DEBUG_MSD
 
@@ -508,6 +509,16 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)
     return ret;
 }
 
+static void usb_msd_password_cb(void *opaque, int err)
+{
+    MSDState *s = opaque;
+
+    if (!err)
+        usb_device_attach(&s->dev);
+    else
+        qdev_unplug(&s->dev.qdev);
+}
+
 static int usb_msd_initfn(USBDevice *dev)
 {
     MSDState *s = DO_UPCAST(MSDState, dev, dev);
@@ -522,10 +533,21 @@ static int usb_msd_initfn(USBDevice *dev)
     s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, s->dinfo, 0);
     s->bus.qbus.allow_hotplug = 0;
     usb_msd_handle_reset(dev);
+
+    if (bdrv_key_required(s->dinfo->bdrv)) {
+        if (s->dev.qdev.hotplugged) {
+            monitor_read_bdrv_key_start(cur_mon, s->dinfo->bdrv,
+                                        usb_msd_password_cb, s);
+            s->dev.auto_attach = 0;
+        } else {
+            autostart = 0;
+        }
+    }
+
     return 0;
 }
 
-USBDevice *usb_msd_init(const char *filename)
+static USBDevice *usb_msd_init(const char *filename)
 {
     static int nr=0;
     char id[8];
@@ -577,13 +599,6 @@ USBDevice *usb_msd_init(const char *filename)
     return dev;
 }
 
-BlockDriverState *usb_msd_get_bdrv(USBDevice *dev)
-{
-    MSDState *s = (MSDState *)dev;
-
-    return s->dinfo->bdrv;
-}
-
 static struct USBDeviceInfo msd_info = {
     .qdev.name      = "QEMU USB MSD",
     .qdev.alias     = "usb-storage",
@@ -593,6 +608,8 @@ static struct USBDeviceInfo msd_info = {
     .handle_reset   = usb_msd_handle_reset,
     .handle_control = usb_msd_handle_control,
     .handle_data    = usb_msd_handle_data,
+    .usbdevice_name = "disk",
+    .usbdevice_init = usb_msd_init,
     .qdev.props     = (Property[]) {
         DEFINE_PROP_DRIVE("drive", MSDState, dinfo),
         DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/usb.h b/hw/usb.h
index a01f334..351c466 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -256,10 +256,6 @@ void usb_host_info(Monitor *mon);
 /* usb-hid.c */
 void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *));
 
-/* usb-msd.c */
-USBDevice *usb_msd_init(const char *filename);
-BlockDriverState *usb_msd_get_bdrv(USBDevice *dev);
-
 /* usb-net.c */
 USBDevice *usb_net_init(NICInfo *nd);
 
diff --git a/vl.c b/vl.c
index 64761cf..994065c 100644
--- a/vl.c
+++ b/vl.c
@@ -2523,16 +2523,6 @@ static void smp_parse(const char *optarg)
 /***********************************************************/
 /* USB devices */
 
-static void usb_msd_password_cb(void *opaque, int err)
-{
-    USBDevice *dev = opaque;
-
-    if (!err)
-        usb_device_attach(dev);
-    else
-        dev->info->handle_destroy(dev);
-}
-
 static int usb_device_add(const char *devname, int is_hotplug)
 {
     const char *p;
@@ -2549,21 +2539,6 @@ static int usb_device_add(const char *devname, int is_hotplug)
     /* the other ones */
     if (strstart(devname, "host:", &p)) {
         dev = usb_host_device_open(p);
-    } else if (strstart(devname, "disk:", &p)) {
-        BlockDriverState *bs;
-
-        dev = usb_msd_init(p);
-        if (!dev)
-            return -1;
-        bs = usb_msd_get_bdrv(dev);
-        if (bdrv_key_required(bs)) {
-            autostart = 0;
-            if (is_hotplug) {
-                monitor_read_bdrv_key_start(cur_mon, bs, usb_msd_password_cb,
-                                            dev);
-                return 0;
-            }
-        }
     } else if (strstart(devname, "net:", &p)) {
         QemuOpts *opts;
         int idx;
-- 
1.6.2.5

  parent reply	other threads:[~2009-10-26 14:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-26 14:56 [Qemu-devel] [PATCH v2 0/7] use qdev for -usbdevice Gerd Hoffmann
2009-10-26 14:56 ` [Qemu-devel] [PATCH 1/7] usb core: " Gerd Hoffmann
2009-10-26 14:56 ` [Qemu-devel] [PATCH 2/7] usb-hid: " Gerd Hoffmann
2009-10-26 14:56 ` [Qemu-devel] [PATCH 3/7] usb-serial and braille: " Gerd Hoffmann
2009-10-26 14:56 ` [Qemu-devel] [PATCH 4/7] usb: make attach optional Gerd Hoffmann
2009-10-26 14:56 ` Gerd Hoffmann [this message]
2009-10-26 14:56 ` [Qemu-devel] [PATCH 6/7] usb-host: use qdev for -usbdevice + rework Gerd Hoffmann
2009-10-26 14:56 ` [Qemu-devel] [PATCH 7/7] usb: print attached status in info qtree 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=1256569011-20256-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).