From patchwork Fri Sep 18 15:22:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 519391 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 18AF7140783 for ; Sat, 19 Sep 2015 01:35:02 +1000 (AEST) Received: from localhost ([::1]:39720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zcxgh-0007gJ-It for incoming@patchwork.ozlabs.org; Fri, 18 Sep 2015 11:34:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcxVt-0006Lx-LF for qemu-devel@nongnu.org; Fri, 18 Sep 2015 11:23:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZcxVo-0005sw-5A for qemu-devel@nongnu.org; Fri, 18 Sep 2015 11:23:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52313) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcxVl-0005rT-RB; Fri, 18 Sep 2015 11:23:41 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 752258E6E3; Fri, 18 Sep 2015 15:23:41 +0000 (UTC) Received: from localhost (ovpn-116-139.ams2.redhat.com [10.36.116.139]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8IFNd3q018730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 18 Sep 2015 11:23:40 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 18 Sep 2015 17:22:44 +0200 Message-Id: <1442589793-7105-10-git-send-email-mreitz@redhat.com> In-Reply-To: <1442589793-7105-1-git-send-email-mreitz@redhat.com> References: <1442589793-7105-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Alberto Garcia , Markus Armbruster , qemu-devel@nongnu.org, Max Reitz , John Snow , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v5 09/38] block: Invoke change media CB before NULLing drv X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 0 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 --- block.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index c4fa299..661c621 100644 --- a/block.c +++ b/block.c @@ -1916,6 +1916,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; @@ -1958,10 +1962,6 @@ void bdrv_close(BlockDriverState *bs) } } - if (bs->blk) { - blk_dev_change_media_cb(bs->blk, false); - } - /*throttling disk I/O limits*/ if (bs->io_limits_enabled) { bdrv_io_limits_disable(bs);