[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 18/23] blockdev: Fix blockdev-add not to create IDE
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH 18/23] blockdev: Fix blockdev-add not to create IDE drive (0, 0) |
Date: |
Wed, 10 Sep 2014 10:13:47 +0200 |
blockdev_init() always creates a DriveInfo, but only drive_new() fills
it in. qmp_blockdev_add() leaves it blank. This results in a drive
with type = IF_IDE, bus = 0, unit = 0. Screwed up in commit ee13ed1c.
Board initialization code looking for IDE drive (0,0) can pick up one
of these bogus drives. Not sure whether getting the QMP command
executed early enough is likely in practice, though.
Fix by creating DriveInfo in drive_new(). Block backends created by
blockdev-add don't get one.
A few places assume a block backend always has a DriveInfo. Fix them
up.
Signed-off-by: Markus Armbruster <address@hidden>
---
blockdev.c | 10 ++--------
hw/block/block.c | 16 ++++++++++------
hw/ide/qdev.c | 2 +-
hw/scsi/scsi-disk.c | 2 +-
4 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 4488dfd..12906a6 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -285,7 +285,6 @@ static BlockBackend *blockdev_init(const char *file, QDict
*bs_opts,
int on_read_error, on_write_error;
BlockBackend *blk;
BlockDriverState *bs;
- DriveInfo *dinfo;
ThrottleConfig cfg;
int snapshot = 0;
bool copy_on_read;
@@ -457,9 +456,6 @@ static BlockBackend *blockdev_init(const char *file, QDict
*bs_opts,
bdrv_set_io_limits(bs, &cfg);
}
- dinfo = g_malloc0(sizeof(*dinfo));
- blk_set_legacy_dinfo(blk, dinfo);
-
if (!file || !*file) {
if (has_driver_specific_opts) {
file = NULL;
@@ -902,21 +898,19 @@ DriveInfo *drive_new(QemuOpts *all_opts,
BlockInterfaceType block_default_type)
}
/* Set legacy DriveInfo fields */
- dinfo = blk_legacy_dinfo(blk);
+ dinfo = g_malloc0(sizeof(*dinfo));
dinfo->enable_auto_del = true;
dinfo->opts = all_opts;
-
dinfo->cyls = cyls;
dinfo->heads = heads;
dinfo->secs = secs;
dinfo->trans = translation;
-
dinfo->type = type;
dinfo->bus = bus_id;
dinfo->unit = unit_id;
dinfo->devaddr = devaddr;
-
dinfo->serial = g_strdup(serial);
+ blk_set_legacy_dinfo(blk, dinfo);
switch(type) {
case IF_IDE:
diff --git a/hw/block/block.c b/hw/block/block.c
index 0666dd3..a625773 100644
--- a/hw/block/block.c
+++ b/hw/block/block.c
@@ -19,7 +19,9 @@ void blkconf_serial(BlockConf *conf, char **serial)
if (!*serial) {
/* try to fall back to value set with legacy -drive serial=... */
dinfo = blk_legacy_dinfo(conf->blk);
- *serial = g_strdup(dinfo->serial);
+ if (dinfo) {
+ *serial = g_strdup(dinfo->serial);
+ }
}
}
@@ -32,11 +34,13 @@ void blkconf_geometry(BlockConf *conf, int *ptrans,
if (!conf->cyls && !conf->heads && !conf->secs) {
/* try to fall back to value set with legacy -drive cyls=... */
dinfo = blk_legacy_dinfo(conf->blk);
- conf->cyls = dinfo->cyls;
- conf->heads = dinfo->heads;
- conf->secs = dinfo->secs;
- if (ptrans) {
- *ptrans = dinfo->trans;
+ if (dinfo) {
+ conf->cyls = dinfo->cyls;
+ conf->heads = dinfo->heads;
+ conf->secs = dinfo->secs;
+ if (ptrans) {
+ *ptrans = dinfo->trans;
+ }
}
}
if (!conf->cyls && !conf->heads && !conf->secs) {
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 4818334..a74c81e 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -206,7 +206,7 @@ static int ide_drive_initfn(IDEDevice *dev)
{
DriveInfo *dinfo = blk_legacy_dinfo(dev->conf.blk);
- return ide_dev_initfn(dev, dinfo->media_cd ? IDE_CD : IDE_HD);
+ return ide_dev_initfn(dev, dinfo && dinfo->media_cd ? IDE_CD : IDE_HD);
}
#define DEFINE_IDE_DEV_PROPERTIES() \
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 768c1ad..e0c5ed3 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -2331,7 +2331,7 @@ static void scsi_disk_realize(SCSIDevice *dev, Error
**errp)
}
dinfo = blk_legacy_dinfo(dev->conf.blk);
- if (dinfo->media_cd) {
+ if (dinfo && dinfo->media_cd) {
scsi_cd_realize(dev, errp);
} else {
scsi_hd_realize(dev, errp);
--
1.9.3
[Qemu-devel] [PATCH 15/23] ide: Complete conversion from BlockDriverState to BlockBackend, Markus Armbruster, 2014/09/10
[Qemu-devel] [PATCH 19/23] blockdev: Drop DriveInfo member enable_auto_del, Markus Armbruster, 2014/09/10
[Qemu-devel] [PATCH 13/23] virtio-blk: Rename VirtIOBlkConf variables to conf, Markus Armbruster, 2014/09/10
[Qemu-devel] [PATCH 20/23] block/qapi: Convert qmp_query_block() to BlockBackend, Markus Armbruster, 2014/09/10
[Qemu-devel] [PATCH 17/23] blockdev: Drop superfluous DriveInfo member id, Markus Armbruster, 2014/09/10
[Qemu-devel] [PATCH 18/23] blockdev: Fix blockdev-add not to create IDE drive (0, 0),
Markus Armbruster <=
[Qemu-devel] [PATCH 23/23] block: Make device model's references to BlockBackend strong, Markus Armbruster, 2014/09/10
[Qemu-devel] [PATCH 21/23] blockdev: Convert qmp_eject(), qmp_change_blockdev() to BlockBackend, Markus Armbruster, 2014/09/10
[Qemu-devel] [PATCH 16/23] pc87312: Drop unused members of PC87312State, Markus Armbruster, 2014/09/10
[Qemu-devel] [PATCH 11/23] block: Rename BlockDriverAIOCB* to BlockAIOCB*, Markus Armbruster, 2014/09/10
[Qemu-devel] [PATCH 22/23] block: Lift device model API into BlockBackend, Markus Armbruster, 2014/09/10
[Qemu-devel] [PATCH 14/23] hw: Convert from BlockDriverState to BlockBackend, mostly, Markus Armbruster, 2014/09/10
Re: [Qemu-devel] [PATCH 00/23] Split BlockBackend off BDS with an axe, Markus Armbruster, 2014/09/11