From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51692) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZljHg-0006s4-8o for qemu-devel@nongnu.org; Mon, 12 Oct 2015 16:01:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZljHf-0000QX-Cc for qemu-devel@nongnu.org; Mon, 12 Oct 2015 16:01:24 -0400 From: Max Reitz Date: Mon, 12 Oct 2015 22:00:12 +0200 Message-Id: <1444680042-13207-10-git-send-email-mreitz@redhat.com> In-Reply-To: <1444680042-13207-1-git-send-email-mreitz@redhat.com> References: <1444680042-13207-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v6 09/39] block: Invoke change media CB before NULLing drv List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: Kevin Wolf , Alberto Garcia , Markus Armbruster , qemu-devel@nongnu.org, Max Reitz , John Snow , Stefan Hajnoczi In order to handle host device passthrough, some guest device models may call blk_is_inserted() to check whether the medium is inserted on the host, when checking the guest tray status. This tray status is inquired by blk_dev_change_media_cb(); because bdrv_is_inserted() (invoked by blk_is_inserted()) always returns false for BDS with drv set to NULL, blk_dev_change_media_cb() should therefore be called before drv is set to NULL. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia Reviewed-by: Kevin Wolf --- block.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 363088c..ccdef82 100644 --- a/block.c +++ b/block.c @@ -1902,6 +1902,10 @@ void bdrv_close(BlockDriverState *bs) bdrv_drain(bs); /* in case flush left pending I/O */ notifier_list_notify(&bs->close_notifiers, bs); + if (bs->blk) { + blk_dev_change_media_cb(bs->blk, false); + } + if (bs->drv) { BdrvChild *child, *next; @@ -1940,10 +1944,6 @@ void bdrv_close(BlockDriverState *bs) bs->full_open_options = NULL; } - if (bs->blk) { - blk_dev_change_media_cb(bs->blk, false); - } - QLIST_FOREACH_SAFE(ban, &bs->aio_notifiers, list, ban_next) { g_free(ban); } -- 2.6.1