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>
This commit is contained in:
Gerd Hoffmann 2009-10-26 15:56:49 +01:00 committed by Anthony Liguori
parent 61e094c049
commit b3e461d3d6
3 changed files with 25 additions and 37 deletions

View File

@ -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(),

View File

@ -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);

25
vl.c
View File

@ -2517,16 +2517,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;
@ -2543,21 +2533,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;