aboutsummaryrefslogtreecommitdiff
path: root/hw/usb-msd.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-10-26 15:56:49 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-30 08:39:31 -0500
commitb3e461d3d6426db74870cd2f54fc24af336660e9 (patch)
tree540c6d50f963a68cca93b78ab57de14774a51832 /hw/usb-msd.c
parent61e094c049c1f58291e596910d300c7842cfd998 (diff)
downloadqemu-b3e461d3d6426db74870cd2f54fc24af336660e9.zip
qemu-b3e461d3d6426db74870cd2f54fc24af336660e9.tar.gz
qemu-b3e461d3d6426db74870cd2f54fc24af336660e9.tar.bz2
usb-storage: use qdev for -usbdevice
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> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/usb-msd.c')
-rw-r--r--hw/usb-msd.c33
1 files changed, 25 insertions, 8 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(),