summaryrefslogtreecommitdiffstats
path: root/hw
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2014-10-07 13:59:22 +0200
committerKevin Wolf <kwolf@redhat.com>2014-10-20 14:03:50 +0200
commit26f8b3a84750546342d4397f86efb1ea7798d5dd (patch)
tree8fd070e6bda1831dcb46333569049e0f04c5d4d7 /hw
parentd3aeb1b7dadacabd175efd515c7c52642141be87 (diff)
downloadhqemu-26f8b3a84750546342d4397f86efb1ea7798d5dd.zip
hqemu-26f8b3a84750546342d4397f86efb1ea7798d5dd.tar.gz
blockdev: Fix blockdev-add not to create DriveInfo
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. The QMP command has to execute really early to be visible. Not sure how likely that is in practice. Fix by creating DriveInfo in drive_new(). Block backends created by blockdev-add don't get one. Breaks the test for "has been created by qmp_blockdev_add()" in blockdev_mark_auto_del() and do_drive_del(), because it changes the value of dinfo && !dinfo->enable_auto_del from true to false. Simply test !dinfo instead. Leaves DriveInfo member enable_auto_del unused. Drop it. A few places assume a block backend always has a DriveInfo. Fix them up. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/block/block.c16
-rw-r--r--hw/ide/qdev.c2
-rw-r--r--hw/scsi/scsi-disk.c2
3 files changed, 12 insertions, 8 deletions
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 600e67c..b4f096e 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -252,7 +252,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 300ba01..010eefd 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -2310,7 +2310,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);
OpenPOWER on IntegriCloud