From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQzsr-0004lB-8h for qemu-devel@nongnu.org; Tue, 01 Oct 2013 09:21:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VQzsl-0008AO-8e for qemu-devel@nongnu.org; Tue, 01 Oct 2013 09:21:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34784) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQzsk-00089x-Ur for qemu-devel@nongnu.org; Tue, 01 Oct 2013 09:20:55 -0400 From: Kevin Wolf Date: Tue, 1 Oct 2013 15:20:05 +0200 Message-Id: <1380633619-12213-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1380633619-12213-1-git-send-email-kwolf@redhat.com> References: <1380633619-12213-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH v2 03/17] blockdev: Introduce DriveInfo.enable_auto_del List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, benoit.canet@irqsave.net, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, xiawenc@linux.vnet.ibm.com 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: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Wenchao Xia --- blockdev.c | 17 ++++++++++++++++- include/sysemu/blockdev.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index 8aa66a9..29a5b70 100644 --- a/blockdev.c +++ b/blockdev.c @@ -89,6 +89,10 @@ void blockdev_mark_auto_del(BlockDriverState *bs) { DriveInfo *dinfo = drive_get_by_blockdev(bs); + if (dinfo && !dinfo->enable_auto_del) { + return; + } + if (bs->job) { block_job_cancel(bs->job); } @@ -750,6 +754,7 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to) DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) { const char *value; + DriveInfo *dinfo; /* Change legacy command line options into QMP ones */ qemu_opt_rename(all_opts, "iops", "throttling.iops-total"); @@ -798,7 +803,17 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) 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) diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h index 804ec88..1082091 100644 --- a/include/sysemu/blockdev.h +++ b/include/sysemu/blockdev.h @@ -37,6 +37,7 @@ struct DriveInfo { int bus; int unit; int auto_del; /* see blockdev_mark_auto_del() */ + bool enable_auto_del; /* Only for legacy drive_init() */ int media_cd; int cyls, heads, secs, trans; QemuOpts *opts; -- 1.8.1.4