From nobody Sun Feb 8 19:43:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553620639980147.510688785389; Tue, 26 Mar 2019 10:17:19 -0700 (PDT) Received: from localhost ([127.0.0.1]:35482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8phN-0004nN-2U for importer@patchew.org; Tue, 26 Mar 2019 13:17:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8pYS-0005G5-7Q for qemu-devel@nongnu.org; Tue, 26 Mar 2019 13:08:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h8pYQ-0000QK-4p for qemu-devel@nongnu.org; Tue, 26 Mar 2019 13:08:04 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:59735) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h8pYP-0000FV-Lr; Tue, 26 Mar 2019 13:08:02 -0400 Received: from 62-165-147-230.co.dnainternet.fi ([62.165.147.230] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1h8pXl-0007zU-5r; Tue, 26 Mar 2019 18:07:21 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1h8pXY-00010F-1t; Tue, 26 Mar 2019 19:07:08 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=th/EdmT+Z6jR/wViRxC69Hk2NMfW9ywClTMKPqqWbOc=; b=bEvidJOzCHoVfDZr1XMiBbBonEYL0TqItMz5QHuv/LYifYmc8uJej8OLwcf6B0cuUraHigUbVdT/QoniVkmCpQ95Ml/Txteurs+wCR5dBL/ilx3tWK6jIKo0XSj6klKfgcx/34gGzmKdlAYUFDLMxrg31W3jZjse7i0GkIL2HI4dRcTpC9+tNScNheZEaZ4Id2iiXVY4UARGDxOKqc3i4KI3Z1Jue69k1MP3PSM6+aUJUYuoy5xwHmhjRBbTp2xw1Jz/GfRW4mEGHzRSiJgU/8ANHymsb+WSzV2E0uwEjR4X+Q2ZWcDdl+LB3ZzW2G7A+W6zOhmuk8N7HTDblnL7vw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 26 Mar 2019 19:07:01 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH for-4.0 1/3] block: continue until base is found in bdrv_freeze_backing_chain() et al 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: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Andrey Shinkevich Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" All three functions that handle the BdrvChild.frozen attribute walk the backing chain from 'bs' to 'base' and stop either when 'base' is found or at the end of the chain if 'base' is NULL. However if 'base' is not found then the functions return without errors as if it was NULL. This is wrong: if the caller passed an incorrect parameter that means that there is a bug in the code. Signed-off-by: Alberto Garcia Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index 0a93ee9ac8..3050854528 100644 --- a/block.c +++ b/block.c @@ -4218,14 +4218,15 @@ BlockDriverState *bdrv_find_base(BlockDriverState *= bs) /* * Return true if at least one of the backing links between @bs and * @base is frozen. @errp is set if that's the case. + * @base must be reachable from @bs, or NULL. */ bool bdrv_is_backing_chain_frozen(BlockDriverState *bs, BlockDriverState *= base, Error **errp) { BlockDriverState *i; =20 - for (i =3D bs; i !=3D base && i->backing; i =3D backing_bs(i)) { - if (i->backing->frozen) { + for (i =3D bs; i !=3D base; i =3D backing_bs(i)) { + if (i->backing && i->backing->frozen) { error_setg(errp, "Cannot change '%s' link from '%s' to '%s'", i->backing->name, i->node_name, backing_bs(i)->node_name); @@ -4240,6 +4241,7 @@ bool bdrv_is_backing_chain_frozen(BlockDriverState *b= s, BlockDriverState *base, * Freeze all backing links between @bs and @base. * If any of the links is already frozen the operation is aborted and * none of the links are modified. + * @base must be reachable from @bs, or NULL. * Returns 0 on success. On failure returns < 0 and sets @errp. */ int bdrv_freeze_backing_chain(BlockDriverState *bs, BlockDriverState *base, @@ -4251,8 +4253,10 @@ int bdrv_freeze_backing_chain(BlockDriverState *bs, = BlockDriverState *base, return -EPERM; } =20 - for (i =3D bs; i !=3D base && i->backing; i =3D backing_bs(i)) { - i->backing->frozen =3D true; + for (i =3D bs; i !=3D base; i =3D backing_bs(i)) { + if (i->backing) { + i->backing->frozen =3D true; + } } =20 return 0; @@ -4261,14 +4265,17 @@ int bdrv_freeze_backing_chain(BlockDriverState *bs,= BlockDriverState *base, /* * Unfreeze all backing links between @bs and @base. The caller must * ensure that all links are frozen before using this function. + * @base must be reachable from @bs, or NULL. */ void bdrv_unfreeze_backing_chain(BlockDriverState *bs, BlockDriverState *b= ase) { BlockDriverState *i; =20 - for (i =3D bs; i !=3D base && i->backing; i =3D backing_bs(i)) { - assert(i->backing->frozen); - i->backing->frozen =3D false; + for (i =3D bs; i !=3D base; i =3D backing_bs(i)) { + if (i->backing) { + assert(i->backing->frozen); + i->backing->frozen =3D false; + } } } =20 --=20 2.11.0