mirror of https://gitee.com/openkylin/qemu.git
qdev: Decouple qdev_prop_drive from DriveInfo
Make the property point to BlockDriverState, cutting out the DriveInfo middleman. This prepares the ground for block devices that don't have a DriveInfo. Currently all user-defined ones have a DriveInfo, because the only way to define one is -drive & friends (they go through drive_init()). DriveInfo is closely tied to -drive, and like -drive, it mixes information about host and guest part of the block device. I'm working towards a new way to define block devices, with clean host/guest separation, and I need to get DriveInfo out of the way for that. Fortunately, the device models are perfectly happy with BlockDriverState, except for two places: ide_drive_initfn() and scsi_disk_initfn() need to check the DriveInfo for a serial number set with legacy -drive serial=... Use drive_get_by_blockdev() there. Device model code should now use DriveInfo only when explicitly dealing with drives defined the old way, i.e. without -device. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
14bafc5407
commit
f8b6cc0070
|
@ -210,10 +210,8 @@ void *qemu_blockalign(BlockDriverState *bs, size_t size);
|
|||
int is_windows_drive(const char *filename);
|
||||
#endif
|
||||
|
||||
struct DriveInfo;
|
||||
|
||||
typedef struct BlockConf {
|
||||
struct DriveInfo *dinfo;
|
||||
BlockDriverState *bs;
|
||||
uint16_t physical_block_size;
|
||||
uint16_t logical_block_size;
|
||||
uint16_t min_io_size;
|
||||
|
@ -234,7 +232,7 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
|
|||
}
|
||||
|
||||
#define DEFINE_BLOCK_PROPERTIES(_state, _conf) \
|
||||
DEFINE_PROP_DRIVE("drive", _state, _conf.dinfo), \
|
||||
DEFINE_PROP_DRIVE("drive", _state, _conf.bs), \
|
||||
DEFINE_PROP_UINT16("logical_block_size", _state, \
|
||||
_conf.logical_block_size, 512), \
|
||||
DEFINE_PROP_UINT16("physical_block_size", _state, \
|
||||
|
|
22
hw/fdc.c
22
hw/fdc.c
|
@ -80,7 +80,6 @@ typedef enum FDiskFlags {
|
|||
} FDiskFlags;
|
||||
|
||||
typedef struct FDrive {
|
||||
DriveInfo *dinfo;
|
||||
BlockDriverState *bs;
|
||||
/* Drive status */
|
||||
FDriveType drive;
|
||||
|
@ -100,7 +99,6 @@ typedef struct FDrive {
|
|||
static void fd_init(FDrive *drv)
|
||||
{
|
||||
/* Drive */
|
||||
drv->bs = drv->dinfo ? drv->dinfo->bdrv : NULL;
|
||||
drv->drive = FDRIVE_DRV_NONE;
|
||||
drv->perpendicular = 0;
|
||||
/* Disk */
|
||||
|
@ -1862,10 +1860,10 @@ FDCtrl *fdctrl_init_isa(DriveInfo **fds)
|
|||
|
||||
dev = isa_create("isa-fdc");
|
||||
if (fds[0]) {
|
||||
qdev_prop_set_drive(&dev->qdev, "driveA", fds[0]);
|
||||
qdev_prop_set_drive(&dev->qdev, "driveA", fds[0]->bdrv);
|
||||
}
|
||||
if (fds[1]) {
|
||||
qdev_prop_set_drive(&dev->qdev, "driveB", fds[1]);
|
||||
qdev_prop_set_drive(&dev->qdev, "driveB", fds[1]->bdrv);
|
||||
}
|
||||
if (qdev_init(&dev->qdev) < 0)
|
||||
return NULL;
|
||||
|
@ -1884,10 +1882,10 @@ FDCtrl *fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
|
|||
fdctrl = &sys->state;
|
||||
fdctrl->dma_chann = dma_chann; /* FIXME */
|
||||
if (fds[0]) {
|
||||
qdev_prop_set_drive(dev, "driveA", fds[0]);
|
||||
qdev_prop_set_drive(dev, "driveA", fds[0]->bdrv);
|
||||
}
|
||||
if (fds[1]) {
|
||||
qdev_prop_set_drive(dev, "driveB", fds[1]);
|
||||
qdev_prop_set_drive(dev, "driveB", fds[1]->bdrv);
|
||||
}
|
||||
qdev_init_nofail(dev);
|
||||
sysbus_connect_irq(&sys->busdev, 0, irq);
|
||||
|
@ -1905,7 +1903,7 @@ FDCtrl *sun4m_fdctrl_init(qemu_irq irq, target_phys_addr_t io_base,
|
|||
|
||||
dev = qdev_create(NULL, "SUNW,fdtwo");
|
||||
if (fds[0]) {
|
||||
qdev_prop_set_drive(dev, "drive", fds[0]);
|
||||
qdev_prop_set_drive(dev, "drive", fds[0]->bdrv);
|
||||
}
|
||||
qdev_init_nofail(dev);
|
||||
sys = DO_UPCAST(FDCtrlSysBus, busdev.qdev, dev);
|
||||
|
@ -2030,8 +2028,8 @@ static ISADeviceInfo isa_fdc_info = {
|
|||
.qdev.vmsd = &vmstate_isa_fdc,
|
||||
.qdev.reset = fdctrl_external_reset_isa,
|
||||
.qdev.props = (Property[]) {
|
||||
DEFINE_PROP_DRIVE("driveA", FDCtrlISABus, state.drives[0].dinfo),
|
||||
DEFINE_PROP_DRIVE("driveB", FDCtrlISABus, state.drives[1].dinfo),
|
||||
DEFINE_PROP_DRIVE("driveA", FDCtrlISABus, state.drives[0].bs),
|
||||
DEFINE_PROP_DRIVE("driveB", FDCtrlISABus, state.drives[1].bs),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
},
|
||||
};
|
||||
|
@ -2053,8 +2051,8 @@ static SysBusDeviceInfo sysbus_fdc_info = {
|
|||
.qdev.vmsd = &vmstate_sysbus_fdc,
|
||||
.qdev.reset = fdctrl_external_reset_sysbus,
|
||||
.qdev.props = (Property[]) {
|
||||
DEFINE_PROP_DRIVE("driveA", FDCtrlSysBus, state.drives[0].dinfo),
|
||||
DEFINE_PROP_DRIVE("driveB", FDCtrlSysBus, state.drives[1].dinfo),
|
||||
DEFINE_PROP_DRIVE("driveA", FDCtrlSysBus, state.drives[0].bs),
|
||||
DEFINE_PROP_DRIVE("driveB", FDCtrlSysBus, state.drives[1].bs),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
},
|
||||
};
|
||||
|
@ -2066,7 +2064,7 @@ static SysBusDeviceInfo sun4m_fdc_info = {
|
|||
.qdev.vmsd = &vmstate_sysbus_fdc,
|
||||
.qdev.reset = fdctrl_external_reset_sysbus,
|
||||
.qdev.props = (Property[]) {
|
||||
DEFINE_PROP_DRIVE("drive", FDCtrlSysBus, state.drives[0].dinfo),
|
||||
DEFINE_PROP_DRIVE("drive", FDCtrlSysBus, state.drives[0].bs),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
},
|
||||
};
|
||||
|
|
|
@ -2594,15 +2594,15 @@ void ide_bus_reset(IDEBus *bus)
|
|||
ide_clear_hob(bus);
|
||||
}
|
||||
|
||||
void ide_init_drive(IDEState *s, DriveInfo *dinfo,
|
||||
void ide_init_drive(IDEState *s, BlockDriverState *bs,
|
||||
const char *version, const char *serial)
|
||||
{
|
||||
int cylinders, heads, secs;
|
||||
uint64_t nb_sectors;
|
||||
|
||||
s->bs = dinfo->bdrv;
|
||||
bdrv_get_geometry(s->bs, &nb_sectors);
|
||||
bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
|
||||
s->bs = bs;
|
||||
bdrv_get_geometry(bs, &nb_sectors);
|
||||
bdrv_guess_geometry(bs, &cylinders, &heads, &secs);
|
||||
s->cylinders = cylinders;
|
||||
s->heads = heads;
|
||||
s->sectors = secs;
|
||||
|
@ -2613,11 +2613,11 @@ void ide_init_drive(IDEState *s, DriveInfo *dinfo,
|
|||
s->smart_autosave = 1;
|
||||
s->smart_errors = 0;
|
||||
s->smart_selftest_count = 0;
|
||||
if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) {
|
||||
if (bdrv_get_type_hint(bs) == BDRV_TYPE_CDROM) {
|
||||
s->is_cdrom = 1;
|
||||
bdrv_set_change_cb(s->bs, cdrom_change_cb, s);
|
||||
bdrv_set_change_cb(bs, cdrom_change_cb, s);
|
||||
}
|
||||
if (serial && *serial) {
|
||||
if (serial) {
|
||||
strncpy(s->drive_serial_str, serial, sizeof(s->drive_serial_str));
|
||||
} else {
|
||||
snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),
|
||||
|
@ -2668,7 +2668,8 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
|
|||
dinfo = i == 0 ? hd0 : hd1;
|
||||
ide_init1(bus, i);
|
||||
if (dinfo) {
|
||||
ide_init_drive(&bus->ifs[i], dinfo, NULL, dinfo->serial);
|
||||
ide_init_drive(&bus->ifs[i], dinfo->bdrv, NULL,
|
||||
*dinfo->serial ? dinfo->serial : NULL);
|
||||
} else {
|
||||
ide_reset(&bus->ifs[i]);
|
||||
}
|
||||
|
|
|
@ -555,7 +555,7 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr);
|
|||
void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
|
||||
uint32_t ide_data_readl(void *opaque, uint32_t addr);
|
||||
|
||||
void ide_init_drive(IDEState *s, DriveInfo *dinfo,
|
||||
void ide_init_drive(IDEState *s, BlockDriverState *bs,
|
||||
const char *version, const char *serial);
|
||||
void ide_init2(IDEBus *bus, qemu_irq irq);
|
||||
void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
|
||||
|
|
|
@ -39,7 +39,7 @@ static int ide_qdev_init(DeviceState *qdev, DeviceInfo *base)
|
|||
IDEDeviceInfo *info = DO_UPCAST(IDEDeviceInfo, qdev, base);
|
||||
IDEBus *bus = DO_UPCAST(IDEBus, qbus, qdev->parent_bus);
|
||||
|
||||
if (!dev->conf.dinfo) {
|
||||
if (!dev->conf.bs) {
|
||||
fprintf(stderr, "%s: no drive specified\n", qdev->info->name);
|
||||
goto err;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive)
|
|||
|
||||
dev = qdev_create(&bus->qbus, "ide-drive");
|
||||
qdev_prop_set_uint32(dev, "unit", unit);
|
||||
qdev_prop_set_drive(dev, "drive", drive);
|
||||
qdev_prop_set_drive(dev, "drive", drive->bdrv);
|
||||
qdev_init_nofail(dev);
|
||||
return DO_UPCAST(IDEDevice, qdev, dev);
|
||||
}
|
||||
|
@ -99,14 +99,18 @@ static int ide_drive_initfn(IDEDevice *dev)
|
|||
IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);
|
||||
IDEState *s = bus->ifs + dev->unit;
|
||||
const char *serial;
|
||||
DriveInfo *dinfo;
|
||||
|
||||
serial = dev->serial;
|
||||
if (!serial) {
|
||||
/* try to fall back to value set with legacy -drive serial=... */
|
||||
serial = dev->conf.dinfo->serial;
|
||||
dinfo = drive_get_by_blockdev(dev->conf.bs);
|
||||
if (*dinfo->serial) {
|
||||
serial = dinfo->serial;
|
||||
}
|
||||
}
|
||||
|
||||
ide_init_drive(s, dev->conf.dinfo, dev->version, serial);
|
||||
ide_init_drive(s, dev->conf.bs, dev->version, serial);
|
||||
|
||||
if (!dev->version) {
|
||||
dev->version = qemu_strdup(s->version);
|
||||
|
|
|
@ -89,7 +89,7 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
|
|||
* specified).
|
||||
*/
|
||||
dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1);
|
||||
scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo, dinfo->unit);
|
||||
scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit);
|
||||
if (!scsidev) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
|
|||
return NULL;
|
||||
}
|
||||
dev = pci_create(bus, devfn, "virtio-blk-pci");
|
||||
qdev_prop_set_drive(&dev->qdev, "drive", dinfo);
|
||||
qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv);
|
||||
if (qdev_init(&dev->qdev) < 0)
|
||||
dev = NULL;
|
||||
break;
|
||||
|
|
|
@ -305,33 +305,36 @@ PropertyInfo qdev_prop_string = {
|
|||
|
||||
static int parse_drive(DeviceState *dev, Property *prop, const char *str)
|
||||
{
|
||||
DriveInfo **ptr = qdev_get_prop_ptr(dev, prop);
|
||||
BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop);
|
||||
BlockDriverState *bs;
|
||||
|
||||
*ptr = drive_get_by_id(str);
|
||||
if (*ptr == NULL)
|
||||
bs = bdrv_find(str);
|
||||
if (bs == NULL)
|
||||
return -ENOENT;
|
||||
*ptr = bs;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void free_drive(DeviceState *dev, Property *prop)
|
||||
{
|
||||
DriveInfo **ptr = qdev_get_prop_ptr(dev, prop);
|
||||
BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop);
|
||||
|
||||
if (*ptr) {
|
||||
blockdev_auto_del((*ptr)->bdrv);
|
||||
blockdev_auto_del(*ptr);
|
||||
}
|
||||
}
|
||||
|
||||
static int print_drive(DeviceState *dev, Property *prop, char *dest, size_t len)
|
||||
{
|
||||
DriveInfo **ptr = qdev_get_prop_ptr(dev, prop);
|
||||
return snprintf(dest, len, "%s", (*ptr) ? (*ptr)->id : "<null>");
|
||||
BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop);
|
||||
return snprintf(dest, len, "%s",
|
||||
*ptr ? bdrv_get_device_name(*ptr) : "<null>");
|
||||
}
|
||||
|
||||
PropertyInfo qdev_prop_drive = {
|
||||
.name = "drive",
|
||||
.type = PROP_TYPE_DRIVE,
|
||||
.size = sizeof(DriveInfo*),
|
||||
.size = sizeof(BlockDriverState *),
|
||||
.parse = parse_drive,
|
||||
.print = print_drive,
|
||||
.free = free_drive,
|
||||
|
@ -657,7 +660,7 @@ void qdev_prop_set_string(DeviceState *dev, const char *name, char *value)
|
|||
qdev_prop_set(dev, name, &value, PROP_TYPE_STRING);
|
||||
}
|
||||
|
||||
void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value)
|
||||
void qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value)
|
||||
{
|
||||
qdev_prop_set(dev, name, &value, PROP_TYPE_DRIVE);
|
||||
}
|
||||
|
|
|
@ -253,8 +253,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
|
|||
DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
|
||||
#define DEFINE_PROP_VLAN(_n, _s, _f) \
|
||||
DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*)
|
||||
#define DEFINE_PROP_DRIVE(_n, _s, _f) \
|
||||
DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*)
|
||||
#define DEFINE_PROP_DRIVE(_n, _s, _f) \
|
||||
DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
|
||||
#define DEFINE_PROP_MACADDR(_n, _s, _f) \
|
||||
DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
|
||||
|
||||
|
@ -275,7 +275,7 @@ void qdev_prop_set_string(DeviceState *dev, const char *name, char *value);
|
|||
void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
|
||||
void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value);
|
||||
void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
|
||||
void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value);
|
||||
void qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value);
|
||||
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
|
||||
/* FIXME: Remove opaque pointer properties. */
|
||||
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
|
||||
|
|
|
@ -262,7 +262,7 @@ static void s390_init(ram_addr_t ram_size,
|
|||
}
|
||||
|
||||
dev = qdev_create((BusState *)s390_bus, "virtio-blk-s390");
|
||||
qdev_prop_set_drive(dev, "drive", dinfo);
|
||||
qdev_prop_set_drive(dev, "drive", dinfo->bdrv);
|
||||
qdev_init_nofail(dev);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,15 +83,15 @@ void scsi_qdev_register(SCSIDeviceInfo *info)
|
|||
}
|
||||
|
||||
/* handle legacy '-drive if=scsi,...' cmd line args */
|
||||
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit)
|
||||
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, int unit)
|
||||
{
|
||||
const char *driver;
|
||||
DeviceState *dev;
|
||||
|
||||
driver = bdrv_is_sg(dinfo->bdrv) ? "scsi-generic" : "scsi-disk";
|
||||
driver = bdrv_is_sg(bdrv) ? "scsi-generic" : "scsi-disk";
|
||||
dev = qdev_create(&bus->qbus, driver);
|
||||
qdev_prop_set_uint32(dev, "scsi-id", unit);
|
||||
qdev_prop_set_drive(dev, "drive", dinfo);
|
||||
qdev_prop_set_drive(dev, "drive", bdrv);
|
||||
if (qdev_init(dev) < 0)
|
||||
return NULL;
|
||||
return DO_UPCAST(SCSIDevice, qdev, dev);
|
||||
|
@ -107,7 +107,7 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
|
|||
if (dinfo == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (!scsi_bus_legacy_add_drive(bus, dinfo, unit)) {
|
||||
if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit)) {
|
||||
res = -1;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1043,26 +1043,24 @@ static void scsi_destroy(SCSIDevice *dev)
|
|||
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
|
||||
|
||||
scsi_disk_purge_requests(s);
|
||||
blockdev_mark_auto_del(s->qdev.conf.dinfo->bdrv);
|
||||
blockdev_mark_auto_del(s->qdev.conf.bs);
|
||||
}
|
||||
|
||||
static int scsi_disk_initfn(SCSIDevice *dev)
|
||||
{
|
||||
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
|
||||
DriveInfo *dinfo;
|
||||
|
||||
if (!s->qdev.conf.dinfo || !s->qdev.conf.dinfo->bdrv) {
|
||||
if (!s->qdev.conf.bs) {
|
||||
error_report("scsi-disk: drive property not set");
|
||||
return -1;
|
||||
}
|
||||
s->bs = s->qdev.conf.dinfo->bdrv;
|
||||
s->bs = s->qdev.conf.bs;
|
||||
|
||||
if (!s->serial) {
|
||||
if (*dev->conf.dinfo->serial) {
|
||||
/* try to fall back to value set with legacy -drive serial=... */
|
||||
s->serial = qemu_strdup(dev->conf.dinfo->serial);
|
||||
} else {
|
||||
s->serial = qemu_strdup("0");
|
||||
}
|
||||
/* try to fall back to value set with legacy -drive serial=... */
|
||||
dinfo = drive_get_by_blockdev(s->bs);
|
||||
s->serial = qemu_strdup(*dinfo->serial ? dinfo->serial : "0");
|
||||
}
|
||||
|
||||
if (!s->version) {
|
||||
|
|
|
@ -453,7 +453,7 @@ static void scsi_destroy(SCSIDevice *d)
|
|||
r = DO_UPCAST(SCSIGenericReq, req, QTAILQ_FIRST(&s->qdev.requests));
|
||||
scsi_remove_request(r);
|
||||
}
|
||||
blockdev_mark_auto_del(s->qdev.conf.dinfo->bdrv);
|
||||
blockdev_mark_auto_del(s->qdev.conf.bs);
|
||||
}
|
||||
|
||||
static int scsi_generic_initfn(SCSIDevice *dev)
|
||||
|
@ -462,11 +462,11 @@ static int scsi_generic_initfn(SCSIDevice *dev)
|
|||
int sg_version;
|
||||
struct sg_scsi_id scsiid;
|
||||
|
||||
if (!s->qdev.conf.dinfo || !s->qdev.conf.dinfo->bdrv) {
|
||||
if (!s->qdev.conf.bs) {
|
||||
error_report("scsi-generic: drive property not set");
|
||||
return -1;
|
||||
}
|
||||
s->bs = s->qdev.conf.dinfo->bdrv;
|
||||
s->bs = s->qdev.conf.bs;
|
||||
|
||||
/* check we are really using a /dev/sg* file */
|
||||
if (!bdrv_is_sg(s->bs)) {
|
||||
|
|
|
@ -97,7 +97,7 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
|
|||
return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
|
||||
}
|
||||
|
||||
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit);
|
||||
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, int unit);
|
||||
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
|
||||
|
||||
void scsi_dev_clear_sense(SCSIDevice *dev);
|
||||
|
|
15
hw/usb-msd.c
15
hw/usb-msd.c
|
@ -522,9 +522,9 @@ static void usb_msd_password_cb(void *opaque, int err)
|
|||
static int usb_msd_initfn(USBDevice *dev)
|
||||
{
|
||||
MSDState *s = DO_UPCAST(MSDState, dev, dev);
|
||||
DriveInfo *dinfo = s->conf.dinfo;
|
||||
BlockDriverState *bs = s->conf.bs;
|
||||
|
||||
if (!dinfo || !dinfo->bdrv) {
|
||||
if (!bs) {
|
||||
error_report("usb-msd: drive property not set");
|
||||
return -1;
|
||||
}
|
||||
|
@ -538,21 +538,20 @@ static int usb_msd_initfn(USBDevice *dev)
|
|||
*
|
||||
* The hack is probably a bad idea.
|
||||
*/
|
||||
s->conf.dinfo = NULL;
|
||||
s->conf.bs = NULL;
|
||||
|
||||
s->dev.speed = USB_SPEED_FULL;
|
||||
scsi_bus_new(&s->bus, &s->dev.qdev, 0, 1, usb_msd_command_complete);
|
||||
s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, dinfo, 0);
|
||||
s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0);
|
||||
if (!s->scsi_dev) {
|
||||
return -1;
|
||||
}
|
||||
s->bus.qbus.allow_hotplug = 0;
|
||||
usb_msd_handle_reset(dev);
|
||||
|
||||
if (bdrv_key_required(dinfo->bdrv)) {
|
||||
if (bdrv_key_required(bs)) {
|
||||
if (cur_mon) {
|
||||
monitor_read_bdrv_key_start(cur_mon, dinfo->bdrv,
|
||||
usb_msd_password_cb, s);
|
||||
monitor_read_bdrv_key_start(cur_mon, bs, usb_msd_password_cb, s);
|
||||
s->dev.auto_attach = 0;
|
||||
} else {
|
||||
autostart = 0;
|
||||
|
@ -610,7 +609,7 @@ static USBDevice *usb_msd_init(const char *filename)
|
|||
if (!dev) {
|
||||
return NULL;
|
||||
}
|
||||
qdev_prop_set_drive(&dev->qdev, "drive", dinfo);
|
||||
qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv);
|
||||
if (qdev_init(&dev->qdev) < 0)
|
||||
return NULL;
|
||||
|
||||
|
|
|
@ -489,7 +489,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)
|
|||
s->vdev.get_config = virtio_blk_update_config;
|
||||
s->vdev.get_features = virtio_blk_get_features;
|
||||
s->vdev.reset = virtio_blk_reset;
|
||||
s->bs = conf->dinfo->bdrv;
|
||||
s->bs = conf->bs;
|
||||
s->conf = conf;
|
||||
s->rq = NULL;
|
||||
s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
|
||||
|
|
|
@ -547,7 +547,7 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev)
|
|||
proxy->class_code != PCI_CLASS_STORAGE_OTHER)
|
||||
proxy->class_code = PCI_CLASS_STORAGE_SCSI;
|
||||
|
||||
if (!proxy->block.dinfo) {
|
||||
if (!proxy->block.bs) {
|
||||
error_report("virtio-blk-pci: drive property not set");
|
||||
return -1;
|
||||
}
|
||||
|
@ -571,7 +571,7 @@ static int virtio_blk_exit_pci(PCIDevice *pci_dev)
|
|||
{
|
||||
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
|
||||
|
||||
blockdev_mark_auto_del(proxy->block.dinfo->bdrv);
|
||||
blockdev_mark_auto_del(proxy->block.bs);
|
||||
return virtio_exit_pci(pci_dev);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue