From nobody Tue Nov 11 20:52:15 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 ARC-Seal: i=1; a=rsa-sha256; t=1565367436; cv=none; d=zoho.com; s=zohoarc; b=f86B5JixrHuyhvNrmLBLjndUe5PyuM5vCIj+jkq+gBQmSAEdq75ViP12r0rnA+X/X8Vx3W8B7+uILSYppHQXvH6uWfiW2hd5Q1qObssHNeRvlhhU9lC8EYksSiv9wovhowvSfjmmFsHtP8Pa1A+wPqXY2K6+n2uCvdBbwHf06I8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565367436; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=05xsbdAWVYhB2BvOyJiSKUxp7/Og+ZXTfdlZp/xedj0=; b=Os3SHlaeC4dd7hpeAa5eN6WvSM8uVcgLdMb21IMDv69pFbgeb89Qf3RC3ayzTgllzJfqb8cTHggmjy9LbjXyRusCcDdDctBeLNPMpObxI6UijwSG4FnyRAM2hLSvu0fOjPmAajf21PP/KhkJ9Jig6tU2Z0LfRpmCKnPtOuvNAJM= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15653674365961004.7547515990943; Fri, 9 Aug 2019 09:17:16 -0700 (PDT) Received: from localhost ([::1]:60840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw7Zr-0007Mc-Jn for importer@patchew.org; Fri, 09 Aug 2019 12:17:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57092) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hw7XS-0001PC-7O for qemu-devel@nongnu.org; Fri, 09 Aug 2019 12:14:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hw7XR-00049i-1A for qemu-devel@nongnu.org; Fri, 09 Aug 2019 12:14:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53876) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hw7XO-000484-9K; Fri, 09 Aug 2019 12:14:42 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 912AE30BC9C6; Fri, 9 Aug 2019 16:14:41 +0000 (UTC) Received: from localhost (unknown [10.40.205.179]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2A2DA5D6A5; Fri, 9 Aug 2019 16:14:40 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 9 Aug 2019 18:13:39 +0200 Message-Id: <20190809161407.11920-15-mreitz@redhat.com> In-Reply-To: <20190809161407.11920-1-mreitz@redhat.com> References: <20190809161407.11920-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 09 Aug 2019 16:14:41 +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] [PATCH v6 14/42] block: Use CAFs when working with backing chains X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Use child access functions when iterating through backing chains so filters do not break the chain. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/block.c b/block.c index 86b84bea21..42abbaf0ba 100644 --- a/block.c +++ b/block.c @@ -4376,7 +4376,8 @@ int bdrv_change_backing_file(BlockDriverState *bs, } =20 /* - * Finds the image layer in the chain that has 'bs' as its backing file. + * Finds the image layer in the chain that has 'bs' (or a filter on + * top of it) as its backing file. * * active is the current topmost image. * @@ -4388,11 +4389,18 @@ int bdrv_change_backing_file(BlockDriverState *bs, BlockDriverState *bdrv_find_overlay(BlockDriverState *active, BlockDriverState *bs) { - while (active && bs !=3D backing_bs(active)) { - active =3D backing_bs(active); + bs =3D bdrv_skip_rw_filters(bs); + active =3D bdrv_skip_rw_filters(active); + + while (active) { + BlockDriverState *next =3D bdrv_backing_chain_next(active); + if (bs =3D=3D next) { + return active; + } + active =3D next; } =20 - return active; + return NULL; } =20 /* Given a BDS, searches for the base layer. */ @@ -4544,9 +4552,7 @@ int bdrv_drop_intermediate(BlockDriverState *top, Blo= ckDriverState *base, * other intermediate nodes have been dropped. * If 'top' is an implicit node (e.g. "commit_top") we should skip * it because no one inherits from it. We use explicit_top for that. */ - while (explicit_top && explicit_top->implicit) { - explicit_top =3D backing_bs(explicit_top); - } + explicit_top =3D bdrv_skip_implicit_filters(explicit_top); update_inherits_from =3D bdrv_inherits_from_recursive(base, explicit_t= op); =20 /* success - we can delete the intermediate states, and link top->base= */ @@ -5014,7 +5020,7 @@ BlockDriverState *bdrv_lookup_bs(const char *device, bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base) { while (top && top !=3D base) { - top =3D backing_bs(top); + top =3D bdrv_filtered_bs(top); } =20 return top !=3D NULL; @@ -5253,7 +5259,17 @@ BlockDriverState *bdrv_find_backing_image(BlockDrive= rState *bs, =20 is_protocol =3D path_has_protocol(backing_file); =20 - for (curr_bs =3D bs; curr_bs->backing; curr_bs =3D curr_bs->backing->b= s) { + /* + * Being largely a legacy function, skip any filters here + * (because filters do not have normal filenames, so they cannot + * match anyway; and allowing json:{} filenames is a bit out of + * scope). + */ + for (curr_bs =3D bdrv_skip_rw_filters(bs); + bdrv_filtered_cow_child(curr_bs) !=3D NULL; + curr_bs =3D bdrv_backing_chain_next(curr_bs)) + { + BlockDriverState *bs_below =3D bdrv_backing_chain_next(curr_bs); =20 /* If either of the filename paths is actually a protocol, then * compare unmodified paths; otherwise make paths relative */ @@ -5261,7 +5277,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, char *backing_file_full_ret; =20 if (strcmp(backing_file, curr_bs->backing_file) =3D=3D 0) { - retval =3D curr_bs->backing->bs; + retval =3D bs_below; break; } /* Also check against the full backing filename for the image = */ @@ -5271,7 +5287,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, bool equal =3D strcmp(backing_file, backing_file_full_ret)= =3D=3D 0; g_free(backing_file_full_ret); if (equal) { - retval =3D curr_bs->backing->bs; + retval =3D bs_below; break; } } @@ -5297,7 +5313,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, g_free(filename_tmp); =20 if (strcmp(backing_file_full, filename_full) =3D=3D 0) { - retval =3D curr_bs->backing->bs; + retval =3D bs_below; break; } } --=20 2.21.0