From nobody Mon Feb 9 01:20:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493916904891300.3122000288321; Thu, 4 May 2017 09:55:04 -0700 (PDT) Received: from localhost ([::1]:43075 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6K1v-00011F-Hn for importer@patchew.org; Thu, 04 May 2017 12:55:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6K00-0008Cv-4T for qemu-devel@nongnu.org; Thu, 04 May 2017 12:53:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6Jzx-0003rR-Bq for qemu-devel@nongnu.org; Thu, 04 May 2017 12:53:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58656) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d6Jzu-0003nn-UO; Thu, 04 May 2017 12:52:59 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFAE3C059741; Thu, 4 May 2017 16:52:57 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-230.ams2.redhat.com [10.36.117.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F97F1715B; Thu, 4 May 2017 16:52:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CFAE3C059741 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CFAE3C059741 From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 4 May 2017 18:52:39 +0200 Message-Id: <1493916761-32319-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1493916761-32319-1-git-send-email-kwolf@redhat.com> References: <1493916761-32319-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 04 May 2017 16:52:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/6] block: Inactivate parents before children X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The proper order for inactivating block nodes is that first the parents get inactivated and then the children. If we do things in this order, we can assert that we didn't accidentally leave a parent activated when one of its child nodes is inactive. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index c3e7ebd..773bd64 100644 --- a/block.c +++ b/block.c @@ -762,6 +762,13 @@ static void bdrv_child_cb_drained_end(BdrvChild *child) bdrv_drained_end(bs); } =20 +static int bdrv_child_cb_inactivate(BdrvChild *child) +{ + BlockDriverState *bs =3D child->opaque; + assert(bs->open_flags & BDRV_O_INACTIVE); + return 0; +} + /* * Returns the options and flags that a temporary snapshot should get, bas= ed on * the originally requested flags (the originally requested image will have @@ -822,6 +829,7 @@ const BdrvChildRole child_file =3D { .inherit_options =3D bdrv_inherited_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, + .inactivate =3D bdrv_child_cb_inactivate, }; =20 /* @@ -843,6 +851,7 @@ const BdrvChildRole child_format =3D { .inherit_options =3D bdrv_inherited_fmt_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, + .inactivate =3D bdrv_child_cb_inactivate, }; =20 static void bdrv_backing_attach(BdrvChild *c) @@ -928,6 +937,7 @@ const BdrvChildRole child_backing =3D { .inherit_options =3D bdrv_backing_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, + .inactivate =3D bdrv_child_cb_inactivate, }; =20 static int bdrv_open_flags(BlockDriverState *bs, int flags) @@ -4038,13 +4048,6 @@ static int bdrv_inactivate_recurse(BlockDriverState = *bs, } } =20 - QLIST_FOREACH(child, &bs->children, next) { - ret =3D bdrv_inactivate_recurse(child->bs, setting_flag); - if (ret < 0) { - return ret; - } - } - if (setting_flag) { bs->open_flags |=3D BDRV_O_INACTIVE; =20 @@ -4058,6 +4061,14 @@ static int bdrv_inactivate_recurse(BlockDriverState = *bs, } } } + + QLIST_FOREACH(child, &bs->children, next) { + ret =3D bdrv_inactivate_recurse(child->bs, setting_flag); + if (ret < 0) { + return ret; + } + } + return 0; } =20 --=20 1.8.3.1