提交 2d246f01 编写于 作者: K Kevin Wolf

blockdev: Introduce DriveInfo.enable_auto_del

BlockDriverStates shouldn't be affected by an unplugged guest device,
except if created with the legacy -drive command line option or the
drive_add HMP command.

Make the automatic deletion as well as cancelling of jobs conditional on
an enable_auto_del boolean that is only set in drive_init().
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
Reviewed-by: NWenchao Xia <xiawenc@linux.vnet.ibm.com>
上级 622f557f
...@@ -89,6 +89,10 @@ void blockdev_mark_auto_del(BlockDriverState *bs) ...@@ -89,6 +89,10 @@ void blockdev_mark_auto_del(BlockDriverState *bs)
{ {
DriveInfo *dinfo = drive_get_by_blockdev(bs); DriveInfo *dinfo = drive_get_by_blockdev(bs);
if (dinfo && !dinfo->enable_auto_del) {
return;
}
if (bs->job) { if (bs->job) {
block_job_cancel(bs->job); block_job_cancel(bs->job);
} }
...@@ -746,6 +750,7 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to) ...@@ -746,6 +750,7 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to)
DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
{ {
const char *value; const char *value;
DriveInfo *dinfo;
/* Change legacy command line options into QMP ones */ /* Change legacy command line options into QMP ones */
qemu_opt_rename(all_opts, "iops", "throttling.iops-total"); qemu_opt_rename(all_opts, "iops", "throttling.iops-total");
...@@ -794,7 +799,17 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) ...@@ -794,7 +799,17 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
qemu_opt_unset(all_opts, "cache"); qemu_opt_unset(all_opts, "cache");
} }
return blockdev_init(all_opts, block_default_type); /* Actual block device init: Functionality shared with blockdev-add */
dinfo = blockdev_init(all_opts, block_default_type);
if (dinfo == NULL) {
goto fail;
}
/* Set legacy DriveInfo fields */
dinfo->enable_auto_del = true;
fail:
return dinfo;
} }
void do_commit(Monitor *mon, const QDict *qdict) void do_commit(Monitor *mon, const QDict *qdict)
......
...@@ -37,6 +37,7 @@ struct DriveInfo { ...@@ -37,6 +37,7 @@ struct DriveInfo {
int bus; int bus;
int unit; int unit;
int auto_del; /* see blockdev_mark_auto_del() */ int auto_del; /* see blockdev_mark_auto_del() */
bool enable_auto_del; /* Only for legacy drive_init() */
int media_cd; int media_cd;
int cyls, heads, secs, trans; int cyls, heads, secs, trans;
QemuOpts *opts; QemuOpts *opts;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册