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>
char *name;
int refcnt;
BlockDriverState *bs;
- DriveInfo *legacy_dinfo;
+ DriveInfo *legacy_dinfo; /* null unless created by drive_new() */
QTAILQ_ENTRY(BlockBackend) link; /* for blk_backends */
};
DriveInfo *dinfo = blk_legacy_dinfo(blk);
BlockDriverState *bs = blk_bs(blk);
- if (dinfo && !dinfo->enable_auto_del) {
+ if (!dinfo) {
return;
}
if (bs->job) {
block_job_cancel(bs->job);
}
- if (dinfo) {
- dinfo->auto_del = 1;
- }
+ dinfo->auto_del = 1;
}
void blockdev_auto_del(BlockBackend *blk)
int on_read_error, on_write_error;
BlockBackend *blk;
BlockDriverState *bs;
- DriveInfo *dinfo;
ThrottleConfig cfg;
int snapshot = 0;
bool copy_on_read;
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;
assert(!local_err);
}
- /* Set legacy DriveInfo fields */
- dinfo = blk_legacy_dinfo(blk);
- dinfo->enable_auto_del = true;
+ /* Create legacy DriveInfo */
+ dinfo = g_malloc0(sizeof(*dinfo));
dinfo->opts = all_opts;
dinfo->cyls = cyls;
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:
case IF_SCSI:
const char *id = qdict_get_str(qdict, "id");
BlockBackend *blk;
BlockDriverState *bs;
- DriveInfo *dinfo;
AioContext *aio_context;
Error *local_err = NULL;
}
bs = blk_bs(blk);
- dinfo = blk_legacy_dinfo(blk);
- if (dinfo && !dinfo->enable_auto_del) {
+ if (!blk_legacy_dinfo(blk)) {
error_report("Deleting device added with blockdev-add"
" is not supported");
return -1;
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);
+ }
}
}
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) {
{
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() \
}
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);
int bus;
int unit;
int auto_del; /* see blockdev_mark_auto_del() */
- bool enable_auto_del; /* Only for legacy drive_new() */
bool is_default; /* Added by default_drive() ? */
int media_cd;
int cyls, heads, secs, trans;