From nobody Fri Dec 19 04:08:05 2025 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554209673932281.66332982746485; Tue, 2 Apr 2019 05:54:33 -0700 (PDT) Received: from localhost ([127.0.0.1]:49197 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBIvr-0006lJ-VV for importer@patchew.org; Tue, 02 Apr 2019 08:54:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBIqz-0002KZ-VX for qemu-devel@nongnu.org; Tue, 02 Apr 2019 08:49:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hBIqy-00039S-Ti for qemu-devel@nongnu.org; Tue, 02 Apr 2019 08:49:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52156) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hBIqv-0002w8-Fv; Tue, 02 Apr 2019 08:49:22 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C3720301D681; Tue, 2 Apr 2019 12:49:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id B990060BEC; Tue, 2 Apr 2019 12:49:18 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 2 Apr 2019 14:49:04 +0200 Message-Id: <20190402124907.24421-7-kwolf@redhat.com> In-Reply-To: <20190402124907.24421-1-kwolf@redhat.com> References: <20190402124907.24421-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 02 Apr 2019 12:49:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/9] 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Alberto Garcia 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 Signed-off-by: Kevin Wolf --- 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.20.1