From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGC6T-00077q-Tu for qemu-devel@nongnu.org; Tue, 27 Jan 2015 14:47:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGC6P-0002Cw-C2 for qemu-devel@nongnu.org; Tue, 27 Jan 2015 14:47:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGC6P-0002Ck-47 for qemu-devel@nongnu.org; Tue, 27 Jan 2015 14:47:09 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0RJl8vN011495 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 27 Jan 2015 14:47:08 -0500 From: Max Reitz Date: Tue, 27 Jan 2015 14:46:06 -0500 Message-Id: <1422387983-32153-34-git-send-email-mreitz@redhat.com> In-Reply-To: <1422387983-32153-1-git-send-email-mreitz@redhat.com> References: <1422387983-32153-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH RESEND 33/50] blockdev: Respect NULL BDS in do_drive_del() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , Jeff Cody , Markus Armbruster , Max Reitz , Stefan Hajnoczi , John Snow Signed-off-by: Max Reitz --- blockdev.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/blockdev.c b/blockdev.c index f3091df..f82b20c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2019,7 +2019,6 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) error_report("Device '%s' not found", id); return -1; } - bs = blk_bs(blk); if (!blk_legacy_dinfo(blk)) { error_report("Deleting device added with blockdev-add" @@ -2027,10 +2026,11 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) return -1; } - aio_context = bdrv_get_aio_context(bs); + aio_context = blk_get_aio_context(blk); aio_context_acquire(aio_context); - if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, &local_err)) { + bs = blk_bs(blk); + if (bs && bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, &local_err)) { error_report("%s", error_get_pretty(local_err)); error_free(local_err); aio_context_release(aio_context); @@ -2039,8 +2039,10 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) /* quiesce block driver; prevent further io */ bdrv_drain_all(); - bdrv_flush(bs); - bdrv_close(bs); + if (bs) { + bdrv_flush(bs); + bdrv_close(bs); + } /* if we have a device attached to this BlockDriverState * then we need to make the drive anonymous until the device -- 2.1.0