From patchwork Tue Mar 26 17:07:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 10871697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D291E1669 for ; Tue, 26 Mar 2019 17:16:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBEC628B66 for ; Tue, 26 Mar 2019 17:16:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAE0928B8A; Tue, 26 Mar 2019 17:16:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4674828B66 for ; Tue, 26 Mar 2019 17:16:58 +0000 (UTC) Received: from localhost ([127.0.0.1]:35482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8ph3-0004nN-Kj for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Mar 2019 13:16:57 -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 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==; 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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; - for (i = bs; i != base && i->backing; i = backing_bs(i)) { - if (i->backing->frozen) { + for (i = bs; i != base; i = 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 *bs, 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; } - for (i = bs; i != base && i->backing; i = backing_bs(i)) { - i->backing->frozen = true; + for (i = bs; i != base; i = backing_bs(i)) { + if (i->backing) { + i->backing->frozen = true; + } } 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 *base) { BlockDriverState *i; - for (i = bs; i != base && i->backing; i = backing_bs(i)) { - assert(i->backing->frozen); - i->backing->frozen = false; + for (i = bs; i != base; i = backing_bs(i)) { + if (i->backing) { + assert(i->backing->frozen); + i->backing->frozen = false; + } } }