From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658866481; cv=none; d=zohomail.com; s=zohoarc; b=c9WPBIte5ZKZjKAIjYIEEyUAA9opaX5dPtBDFVaWXVFTEHIFom/MyDUkvwwzDu8pVPAgzI1OaZoTAHkn9eK3OERhV1qF+zpZhUP3jzXkBgMbsz49nrNRO9OUldW9F0m3LRkCX4mMSst78AEWoREPnlu4PzoJyLIfj/FcpwGdLHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658866481; 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; bh=j1XQ+C+lQAWe3PnC+OChmua2o5Y3Wn26kuJ+BygCzeM=; b=Xgl+Bnh2rRHk+NV//QUPCIM7MWS8LlitmQhEPsuB5Su8p6adUvZXH/gy68leiuHsIbaOGIJg+qkwncArdkte4G9CgJXnVx0NYHyNMk8oldQ4ilRZ+QmwYUmKqN8DH//LbSPzRixkrd8+5iAdWuGnSEhU4UJtPxVBu1wJcN9zU4M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658866481918585.9461579505463; Tue, 26 Jul 2022 13:14:41 -0700 (PDT) Received: from localhost ([::1]:51840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGQwx-0003tX-Vu for importer@patchew.org; Tue, 26 Jul 2022 16:14:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuS-0000yD-Jk; Tue, 26 Jul 2022 16:12:04 -0400 Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]:34396) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuO-0001A0-7D; Tue, 26 Jul 2022 16:12:03 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id CBD302E0C7C; Tue, 26 Jul 2022 23:11:50 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-BnO0j3dA; Tue, 26 Jul 2022 23:11:49 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866309; bh=j1XQ+C+lQAWe3PnC+OChmua2o5Y3Wn26kuJ+BygCzeM=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=unGaqL3x3NwdFx9+YgNhTSaKeTAfYi73KptZRyKwzLdpzkfFWbHIr/hU/e5l+x9pH NlTX8wNKirl/LYyBBuE1jpVSma5iSycC+apMHOURaDlkOQcQoMyhnA33v/dwIUdg4+ pi7ZkEcvy6be8tQxvHESs2yaNstTo7ZJ6Ag5MLtY= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru, John Snow Subject: [PATCH v7 01/15] block: BlockDriver: add .filtered_child_is_backing field Date: Tue, 26 Jul 2022 23:11:20 +0300 Message-Id: <20220726201134.924743-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=77.88.29.217; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1p.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658866482979100001 Content-Type: text/plain; charset="utf-8" Unfortunately not all filters use .file child as filtered child. Two exclusions are mirror_top and commit_top. Happily they both are private filters. Bad thing is that this inconsistency is observable through qmp commands query-block / query-named-block-nodes. So, could we just change mirror_top and commit_top to use file child as all other filter driver is an open question. Probably, we could do that with some kind of deprecation period, but how to warn users during it? For now, let's just add a field so we can distinguish them in generic code, it will be used in further commits. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- block/commit.c | 1 + block/mirror.c | 1 + include/block/block_int-common.h | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/block/commit.c b/block/commit.c index 38571510cb..e210e86bac 100644 --- a/block/commit.c +++ b/block/commit.c @@ -238,6 +238,7 @@ static BlockDriver bdrv_commit_top =3D { .bdrv_child_perm =3D bdrv_commit_top_child_perm, =20 .is_filter =3D true, + .filtered_child_is_backing =3D true, }; =20 void commit_start(const char *job_id, BlockDriverState *bs, diff --git a/block/mirror.c b/block/mirror.c index 3c4ab1159d..b808e8bdc2 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1578,6 +1578,7 @@ static BlockDriver bdrv_mirror_top =3D { .bdrv_child_perm =3D bdrv_mirror_top_child_perm, =20 .is_filter =3D true, + .filtered_child_is_backing =3D true, }; =20 static BlockJob *mirror_start_job( diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 8947abab76..9d91ccbcbf 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -119,6 +119,19 @@ struct BlockDriver { * (And this filtered child must then be bs->file or bs->backing.) */ bool is_filter; + /* + * Only make sense for filter drivers, for others must be false. + * If true, filtered child is bs->backing. Otherwise it's bs->file. + * Only two internal filters use bs->backing as filtered child and has= this + * field set to true: mirror_top and commit_top. + * + * Never create any more such filters! + * + * TODO: imagine how to deprecate this behavior and make all filters w= ork + * similarly using bs->file as filtered child. + */ + bool filtered_child_is_backing; + /* * Set to true if the BlockDriver is a format driver. Format nodes * generally do not expect their children to be other format nodes --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658866603; cv=none; d=zohomail.com; s=zohoarc; b=OkzBW8/Z3V2B0rCr8vetfLTjlC0hNCNSXIbJjP/kzd6MCL/VfUAm+p0659mjDbKRb2w3NlUqXqeHeJIXe796P6nSmvOiyvrBUqN9lSWz0gTH2CabI+47kzUmpaO+oPzrCOQKg/l1ZDNuGIeRJNxa3dXUUaxg/A1fjhvcnqRDZbg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658866603; 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; bh=Ojqmxk0w6cxbMAZ7mLKQN5BLV7bavieG679HzhtVj30=; b=VjcHJDXmYJSlZiin4TIbmqU+WLjvr3rCwyvqPbCH//xcwAeGlF7zyp1WeQgvtsvYASeXTTXY4DLz8rrp1wunYT4McnqCukjXMX22McyFtyP5uZ8/8EO5+rBl2aX5LQCrNABTR8MTiV+/ZksuMXRq1d67/dFy9Skrr39C6NHQ0Pk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658866603299599.5207878078272; Tue, 26 Jul 2022 13:16:43 -0700 (PDT) Received: from localhost ([::1]:54494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGQyw-0005kn-3M for importer@patchew.org; Tue, 26 Jul 2022 16:16:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuU-00013i-B8; Tue, 26 Jul 2022 16:12:06 -0400 Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]:34420) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuQ-0001Ae-8s; Tue, 26 Jul 2022 16:12:05 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id EAB822E0F38; Tue, 26 Jul 2022 23:11:53 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-BpO0wcPa; Tue, 26 Jul 2022 23:11:52 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866312; bh=Ojqmxk0w6cxbMAZ7mLKQN5BLV7bavieG679HzhtVj30=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=g5Y0C3HYuDADgdpzI6wxL1AynS802V6/38YMiKsP/UE+RV+p2XaBHr8ohKqbRUqHb 48f/x0tLlGnN2ZdxjbK3ZK71s3zbED+IRoOQIQ8UuH1JNaZMdhVs142Ykh6Fm/cIxD XPh0bB9ylEb//drfGR9hF48uck3UYUua+bZjYaDc= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru, Ari Sundholm , Pavel Dovgalyuk , Paolo Bonzini , Stefan Hajnoczi , John Snow , "Denis V. Lunev" , Wen Congyang , Xie Changlong , Stefan Weil , Jeff Cody , Fam Zheng Subject: [PATCH v7 02/15] block: introduce bdrv_open_file_child() helper Date: Tue, 26 Jul 2022 23:11:21 +0300 Message-Id: <20220726201134.924743-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=77.88.29.217; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1p.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658866604596100001 Content-Type: text/plain; charset="utf-8" Almost all drivers call bdrv_open_child() similarly. Let's create a helper for this. The only not updated drivers that call bdrv_open_child() to set bs->file are raw-format and snapshot-access: raw-format sometimes want to have filtered child but don't set drv->is_filter to true. snapshot-access wants only DATA | PRIMARY Possibly we should implement drv->is_filter_func() handler, to consider raw-format as filter when it works as filter.. But it's another story. Note also, that we decrease assignments to bs->file in code: it helps us restrict modifying this field in further commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- block.c | 21 +++++++++++++++++++++ block/blkdebug.c | 9 +++------ block/blklogwrites.c | 7 ++----- block/blkreplay.c | 7 ++----- block/blkverify.c | 9 +++------ block/bochs.c | 7 +++---- block/cloop.c | 7 +++---- block/copy-before-write.c | 9 ++++----- block/copy-on-read.c | 9 ++++----- block/crypto.c | 11 ++++++----- block/dmg.c | 7 +++---- block/filter-compress.c | 8 +++----- block/parallels.c | 7 +++---- block/preallocate.c | 9 ++++----- block/qcow.c | 6 ++---- block/qcow2.c | 8 ++++---- block/qed.c | 8 ++++---- block/replication.c | 8 +++----- block/throttle.c | 8 +++----- block/vdi.c | 7 +++---- block/vhdx.c | 7 +++---- block/vmdk.c | 7 +++---- block/vpc.c | 7 +++---- include/block/block-global-state.h | 3 +++ 24 files changed, 95 insertions(+), 101 deletions(-) diff --git a/block.c b/block.c index bc85f46eed..4e38fc45c0 100644 --- a/block.c +++ b/block.c @@ -3668,6 +3668,27 @@ BdrvChild *bdrv_open_child(const char *filename, errp); } =20 +/* + * Wrapper on bdrv_open_child() for most popular case: open primary child = of bs. + */ +int bdrv_open_file_child(const char *filename, + QDict *options, const char *bdref_key, + BlockDriverState *parent, Error **errp) +{ + BdrvChildRole role; + + /* commit_top and mirror_top don't use this function */ + assert(!parent->drv->filtered_child_is_backing); + + role =3D parent->drv->is_filter ? + (BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY) : BDRV_CHILD_IMAGE; + + parent->file =3D bdrv_open_child(filename, options, bdref_key, parent, + &child_of_bds, role, false, errp); + + return parent->file ? 0 : -EINVAL; +} + /* * TODO Future callers may need to specify parent/child_class in order for * option inheritance to work. Existing callers use it for the root node. diff --git a/block/blkdebug.c b/block/blkdebug.c index bbf2948703..5fcfc8ac6f 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -503,12 +503,9 @@ static int blkdebug_open(BlockDriverState *bs, QDict *= options, int flags, } =20 /* Open the image file */ - bs->file =3D bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "= image", - bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - ret =3D -EINVAL; + ret =3D bdrv_open_file_child(qemu_opt_get(opts, "x-image"), options, "= image", + bs, errp); + if (ret < 0) { goto out; } =20 diff --git a/block/blklogwrites.c b/block/blklogwrites.c index e3c6c4039c..12b4c3c8cf 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -155,11 +155,8 @@ static int blk_log_writes_open(BlockDriverState *bs, Q= Dict *options, int flags, } =20 /* Open the file */ - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, f= alse, - errp); - if (!bs->file) { - ret =3D -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { goto fail; } =20 diff --git a/block/blkreplay.c b/block/blkreplay.c index dcbe780ddb..76a0b8d12a 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -26,11 +26,8 @@ static int blkreplay_open(BlockDriverState *bs, QDict *o= ptions, int flags, int ret; =20 /* Open the image file */ - bs->file =3D bdrv_open_child(NULL, options, "image", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - ret =3D -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "image", bs, errp); + if (ret < 0) { goto fail; } =20 diff --git a/block/blkverify.c b/block/blkverify.c index e4a37af3b2..e4d40a63aa 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -122,12 +122,9 @@ static int blkverify_open(BlockDriverState *bs, QDict = *options, int flags, } =20 /* Open the raw file */ - bs->file =3D bdrv_open_child(qemu_opt_get(opts, "x-raw"), options, "ra= w", - bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - ret =3D -EINVAL; + ret =3D bdrv_open_file_child(qemu_opt_get(opts, "x-raw"), options, "ra= w", + bs, errp); + if (ret < 0) { goto fail; } =20 diff --git a/block/bochs.c b/block/bochs.c index b76f34fe03..e30e3908d9 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -110,10 +110,9 @@ static int bochs_open(BlockDriverState *bs, QDict *opt= ions, int flags, return ret; } =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 ret =3D bdrv_pread(bs->file, 0, sizeof(bochs), &bochs, 0); diff --git a/block/cloop.c b/block/cloop.c index 40b146e714..3ff975a94d 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -71,10 +71,9 @@ static int cloop_open(BlockDriverState *bs, QDict *optio= ns, int flags, return ret; } =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 /* read header */ diff --git a/block/copy-before-write.c b/block/copy-before-write.c index c24b8dd117..c296a5b4c2 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -411,6 +411,7 @@ static int cbw_open(BlockDriverState *bs, QDict *option= s, int flags, int64_t cluster_size; g_autoptr(BlockdevOptions) full_opts =3D NULL; BlockdevOptionsCbw *opts; + int ret; =20 full_opts =3D cbw_parse_options(options, errp); if (!full_opts) { @@ -419,11 +420,9 @@ static int cbw_open(BlockDriverState *bs, QDict *optio= ns, int flags, assert(full_opts->driver =3D=3D BLOCKDEV_DRIVER_COPY_BEFORE_WRITE); opts =3D &full_opts->u.copy_before_write; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 s->target =3D bdrv_open_child(NULL, options, "target", bs, &child_of_b= ds, diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 1fc7fb3333..815ac1d835 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -41,12 +41,11 @@ static int cor_open(BlockDriverState *bs, QDict *option= s, int flags, BDRVStateCOR *state =3D bs->opaque; /* Find a bottom node name, if any */ const char *bottom_node =3D qdict_get_try_str(options, "bottom"); + int ret; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 bs->supported_read_flags =3D BDRV_REQ_PREFETCH; diff --git a/block/crypto.c b/block/crypto.c index 7a57774b76..396e529bb2 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -261,15 +261,14 @@ static int block_crypto_open_generic(QCryptoBlockForm= at format, { BlockCrypto *crypto =3D bs->opaque; QemuOpts *opts =3D NULL; - int ret =3D -EINVAL; + int ret; QCryptoBlockOpenOptions *open_opts =3D NULL; unsigned int cflags =3D 0; QDict *cryptoopts =3D NULL; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 bs->supported_write_flags =3D BDRV_REQ_FUA & @@ -277,6 +276,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, =20 opts =3D qemu_opts_create(opts_spec, NULL, 0, &error_abort); if (!qemu_opts_absorb_qdict(opts, options, errp)) { + ret =3D -EINVAL; goto cleanup; } =20 @@ -285,6 +285,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, =20 open_opts =3D block_crypto_open_opts_init(cryptoopts, errp); if (!open_opts) { + ret =3D -EINVAL; goto cleanup; } =20 diff --git a/block/dmg.c b/block/dmg.c index 98db18d82a..422136276a 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -440,10 +440,9 @@ static int dmg_open(BlockDriverState *bs, QDict *optio= ns, int flags, return ret; } =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 block_module_load_one("dmg-bz2"); diff --git a/block/filter-compress.c b/block/filter-compress.c index d5be538619..305716c86c 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -30,11 +30,9 @@ static int compress_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - return -EINVAL; + int ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 if (!bs->file->bs->drv || !block_driver_can_compress(bs->file->bs->drv= )) { diff --git a/block/parallels.c b/block/parallels.c index 8b235b9505..1e115d5186 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -736,10 +736,9 @@ static int parallels_open(BlockDriverState *bs, QDict = *options, int flags, Error *local_err =3D NULL; char *buf; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 ret =3D bdrv_pread(bs->file, 0, sizeof(ph), &ph, 0); diff --git a/block/preallocate.c b/block/preallocate.c index e15cb8c74a..d50ee7f49b 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -134,6 +134,7 @@ static int preallocate_open(BlockDriverState *bs, QDict= *options, int flags, Error **errp) { BDRVPreallocateState *s =3D bs->opaque; + int ret; =20 /* * s->data_end and friends should be initialized on permission update. @@ -141,11 +142,9 @@ static int preallocate_open(BlockDriverState *bs, QDic= t *options, int flags, */ s->file_end =3D s->zero_start =3D s->data_end =3D -EINVAL; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 if (!preallocate_absorb_opts(&s->opts, options, bs->file->bs, errp)) { diff --git a/block/qcow.c b/block/qcow.c index 311aaa8705..72ed4c3321 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -121,10 +121,8 @@ static int qcow_open(BlockDriverState *bs, QDict *opti= ons, int flags, qdict_extract_subqdict(options, &encryptopts, "encrypt."); encryptfmt =3D qdict_get_try_str(encryptopts, "format"); =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - ret =3D -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { goto fail; } =20 diff --git a/block/qcow2.c b/block/qcow2.c index c6c6692fb7..f62dac589a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1893,11 +1893,11 @@ static int qcow2_open(BlockDriverState *bs, QDict *= options, int flags, .errp =3D errp, .ret =3D -EINPROGRESS }; + int ret; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 /* Initialise locks */ diff --git a/block/qed.c b/block/qed.c index 40943e679b..1251393e00 100644 --- a/block/qed.c +++ b/block/qed.c @@ -554,11 +554,11 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict = *options, int flags, .errp =3D errp, .ret =3D -EINPROGRESS }; + int ret; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 bdrv_qed_init_state(bs); diff --git a/block/replication.c b/block/replication.c index 55c8f894aa..2f17397764 100644 --- a/block/replication.c +++ b/block/replication.c @@ -88,11 +88,9 @@ static int replication_open(BlockDriverState *bs, QDict = *options, const char *mode; const char *top_id; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 ret =3D -EINVAL; diff --git a/block/throttle.c b/block/throttle.c index 6e8d52fa24..4fb5798c27 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -78,11 +78,9 @@ static int throttle_open(BlockDriverState *bs, QDict *op= tions, char *group; int ret; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } bs->supported_write_flags =3D bs->file->bs->supported_write_flags | BDRV_REQ_WRITE_UNCHANGED; diff --git a/block/vdi.c b/block/vdi.c index e942325455..a9bafb5a9e 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -377,10 +377,9 @@ static int vdi_open(BlockDriverState *bs, QDict *optio= ns, int flags, int ret; QemuUUID uuid_link, uuid_parent; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 logout("\n"); diff --git a/block/vhdx.c b/block/vhdx.c index e10e78ebfd..ce1e75f5ec 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1001,10 +1001,9 @@ static int vhdx_open(BlockDriverState *bs, QDict *op= tions, int flags, uint64_t signature; Error *local_err =3D NULL; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 s->bat =3D NULL; diff --git a/block/vmdk.c b/block/vmdk.c index fe07a54866..e2c4d9fb71 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1308,10 +1308,9 @@ static int vmdk_open(BlockDriverState *bs, QDict *op= tions, int flags, BDRVVmdkState *s =3D bs->opaque; uint32_t magic; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 buf =3D vmdk_read_desc(bs->file, 0, errp); diff --git a/block/vpc.c b/block/vpc.c index 4f49ef207f..95841f259a 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -233,10 +233,9 @@ static int vpc_open(BlockDriverState *bs, QDict *optio= ns, int flags, int ret; int64_t bs_size; =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_IMAGE, false, errp); - if (!bs->file) { - return -EINVAL; + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); + if (ret < 0) { + return ret; } =20 opts =3D qemu_opts_create(&vpc_runtime_opts, NULL, 0, &error_abort); diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 21265e3966..29a38d7e18 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -76,6 +76,9 @@ BdrvChild *bdrv_open_child(const char *filename, const BdrvChildClass *child_class, BdrvChildRole child_role, bool allow_none, Error **errp); +int bdrv_open_file_child(const char *filename, + QDict *options, const char *bdref_key, + BlockDriverState *parent, Error **errp); BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp); int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, Error **errp); --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658866960; cv=none; d=zohomail.com; s=zohoarc; b=YIBQD+jWGvcFTSjqBmHXg+mKh21zxzTS0lHlfh3+7vGjooDekPop0a25WKKCdlI5UvH/sRbPtP0UuMOHkk3LtUvfRVIFy2kUnRTjj4cLGRsmQ0jah6qQ7REPHR2rjkQgwxBVplIJ1K4wErcG/jOawBh6z+eXPp7kiQM9mFaQCo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658866960; 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; bh=odkHBZ5wcPtbgLRCcsfajIfFKVEGIFLVONr1YQ3e97c=; b=Kmv3kXZdkHHiFPjOsVAjxqfkZeldB0WoWDYMdnOCDmVEKUgLAT96Buuy1z2Bb6OyVc0WhDGJiu239m6Q9B+Bj1sIS7r5KBsbvbj+U+Q3jyPHKl0h+NskoY9utwe4C0xvoW9V8om8mm1k4/2NEXHeFn23+uphu8wUCMULhvMZGqs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658866960714319.9791085842145; Tue, 26 Jul 2022 13:22:40 -0700 (PDT) Received: from localhost ([::1]:40458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGR4h-0007Bg-MJ for importer@patchew.org; Tue, 26 Jul 2022 16:22:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuU-00013C-3c; Tue, 26 Jul 2022 16:12:06 -0400 Received: from forwardcorp1j.mail.yandex.net ([5.45.199.163]:47646) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuS-0001Bp-0T; Tue, 26 Jul 2022 16:12:05 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 499452E1985; Tue, 26 Jul 2022 23:11:55 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-BsO0EohD; Tue, 26 Jul 2022 23:11:54 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866314; bh=odkHBZ5wcPtbgLRCcsfajIfFKVEGIFLVONr1YQ3e97c=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=Criibcpm6slagztlHJ09BfUZsALBjpoSaaxWvEXq0wdTyqq1+dfu74R8Z2na8wpTn gz6VzT6TZPq7FrFySy42UK915gWdIA1p1vKsywBgltuSAeI2eZNG4lQ5u2FZLKHYLm oryDLFOE93Cmugs6yprqfl/nUIqSLCXTtmB5y+dk= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru, Ari Sundholm Subject: [PATCH v7 03/15] block/blklogwrites: don't care to remove bs->file child on failure Date: Tue, 26 Jul 2022 23:11:22 +0300 Message-Id: <20220726201134.924743-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=5.45.199.163; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658866962820100001 Content-Type: text/plain; charset="utf-8" We don't need to remove bs->file, generic layer takes care of it. No other driver cares to remove bs->file on failure by hand. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- block/blklogwrites.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 12b4c3c8cf..cef9efe55d 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -254,10 +254,6 @@ fail_log: s->log_file =3D NULL; } fail: - if (ret < 0) { - bdrv_unref_child(bs, bs->file); - bs->file =3D NULL; - } qemu_opts_del(opts); return ret; } --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658868434; cv=none; d=zohomail.com; s=zohoarc; b=SESftd+h+42HY64KCwUCNjxCg+QO25JBt/J9IRBYJApT4bCwMmL9COFoMs/peUtgAtyHRCJLvLPqdRmhh5amKiUHRsai0x1X10OdE3eXA+mMstH1hxrtoAKeWLS2bcoC/bNsTp3X1VTviboQu+pjiYqChTVUS6S6bssTCmUncKc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658868434; h=Content-Type: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; bh=PXAXy22NSjxX+BVBMvqaUFFWiEyw/PAFiL8IphYKH+U=; b=he4s+yCCqHGtjUTYVt3pOFyGuebdHW248VU31Lbwd2tDhUxo1Rs6ZHENUjVeJr9YHRW8E39DOLBgz929FBHyP/LA57W7xy8Vn9D9TdL3GYkO4SdJz7K4jfXwsNbwRQ/kXjl/2RLgR+LhvO5QNVe4gGDAcRx8ryVJoX20eQr/RXg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658868434473874.7902871470259; Tue, 26 Jul 2022 13:47:14 -0700 (PDT) Received: from localhost ([::1]:52384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGRST-0003OP-64 for importer@patchew.org; Tue, 26 Jul 2022 16:47:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuV-00017M-Uy; Tue, 26 Jul 2022 16:12:08 -0400 Received: from forwardcorp1o.mail.yandex.net ([2a02:6b8:0:1a2d::193]:47242) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuT-0001C9-Ng; Tue, 26 Jul 2022 16:12:07 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 124C22E0DC5; Tue, 26 Jul 2022 23:11:57 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-BtO0w6Zb; Tue, 26 Jul 2022 23:11:56 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866316; bh=PXAXy22NSjxX+BVBMvqaUFFWiEyw/PAFiL8IphYKH+U=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=loFcBjWZ11ShMbv4DLNrlPRthUfE3VMLyfZp74HqqAtYXuweuUomI/upGqNeaqe1h HDKD+gayn41b5w3AqaXTJ03QqYR1X7BSUWVK8m420rS4EYmpPhGprnFYhIe6spFpv5 LwejNZp9jUUiio8ZS9l7NQY4X48IIpXynE7i7I1g= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v7 04/15] test-bdrv-graph-mod: update test_parallel_perm_update test case Date: Tue, 26 Jul 2022 23:11:23 +0300 Message-Id: <20220726201134.924743-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a02:6b8:0:1a2d::193; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1o.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658868435126100001 test_parallel_perm_update() does two things that we are going to restrict in the near future: 1. It updates bs->file field by hand. bs->file will be managed automatically by generic code (together with bs->children list). Let's better refactor our "tricky" bds to have own state where one of children is linked as "selected". This also looks less "tricky", so avoid using this word. 2. It create FILTERED children that are not PRIMARY. Except for tests all FILTERED children in the Qemu block layer are always PRIMARY as well. We are going to formalize this rule, so let's better use DATA children here. 3. It creates more than one FILTERED child, which is already abandoned in BDRV_CHILD_FILTERED's description. While being here, update the picture to better correspond to the test code. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- tests/unit/test-bdrv-graph-mod.c | 80 +++++++++++++++++++------------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-= mod.c index a6e3bb79be..e2f1355af1 100644 --- a/tests/unit/test-bdrv-graph-mod.c +++ b/tests/unit/test-bdrv-graph-mod.c @@ -241,13 +241,26 @@ static void test_parallel_exclusive_write(void) bdrv_unref(top); } =20 -static void write_to_file_perms(BlockDriverState *bs, BdrvChild *c, - BdrvChildRole role, - BlockReopenQueue *reopen_queue, - uint64_t perm, uint64_t shared, - uint64_t *nperm, uint64_t *nshared) +/* + * write-to-selected node may have several DATA children, one of them may = be + * "selected". Exclusive write permission is taken on selected child. + * + * We don't realize write handler itself, as we need only to test how perm= ission + * update works. + */ +typedef struct BDRVWriteToSelectedState { + BdrvChild *selected; +} BDRVWriteToSelectedState; + +static void write_to_selected_perms(BlockDriverState *bs, BdrvChild *c, + BdrvChildRole role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) { - if (bs->file && c =3D=3D bs->file) { + BDRVWriteToSelectedState *s =3D bs->opaque; + + if (s->selected && c =3D=3D s->selected) { *nperm =3D BLK_PERM_WRITE; *nshared =3D BLK_PERM_ALL & ~BLK_PERM_WRITE; } else { @@ -256,9 +269,10 @@ static void write_to_file_perms(BlockDriverState *bs, = BdrvChild *c, } } =20 -static BlockDriver bdrv_write_to_file =3D { - .format_name =3D "tricky-perm", - .bdrv_child_perm =3D write_to_file_perms, +static BlockDriver bdrv_write_to_selected =3D { + .format_name =3D "write-to-selected", + .instance_size =3D sizeof(BDRVWriteToSelectedState), + .bdrv_child_perm =3D write_to_selected_perms, }; =20 =20 @@ -266,15 +280,18 @@ static BlockDriver bdrv_write_to_file =3D { * The following test shows that topological-sort order is required for * permission update, simple DFS is not enough. * - * Consider the block driver which has two filter children: one active - * with exclusive write access and one inactive with no specific - * permissions. + * Consider the block driver (write-to-selected) which has two children: o= ne is + * selected so we have exclusive write access to it and for the other one = we + * don't need any specific permissions. * * And, these two children has a common base child, like this: + * (additional "top" on top is used in test just because the only public + * function to update permission should get a specific child to update. + * Making bdrv_refresh_perms() public just for this test isn't worth it) * - * =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2= =94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 - * =E2=94=82 fl2 =E2=94=82 =E2=97=80=E2=94=80=E2=94=80 =E2=94=82 top =E2= =94=82 - * =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 =E2= =94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 + * =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2= =94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2=94=8C=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=90 + * =E2=94=82 fl2 =E2=94=82 =E2=97=80=E2=94=80=E2=94=80 =E2=94=82 write-to-= selected =E2=94=82 =E2=97=80=E2=94=80=E2=94=80 =E2=94=82 top =E2=94=82 + * =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 =E2= =94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=98 =E2=94=94=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=98 * =E2=94=82 =E2=94=82 * =E2=94=82 =E2=94=82 w * =E2=94=82 =E2=96=BC @@ -290,14 +307,14 @@ static BlockDriver bdrv_write_to_file =3D { * * So, exclusive write is propagated. * - * Assume, we want to make fl2 active instead of fl1. - * So, we set some option for top driver and do permission update. + * Assume, we want to select fl2 instead of fl1. + * So, we set some option for write-to-selected driver and do permission u= pdate. * * With simple DFS, if permission update goes first through - * top->fl1->base branch it will succeed: it firstly drop exclusive write - * permissions and than apply them for another BdrvChildren. - * But if permission update goes first through top->fl2->base branch it - * will fail, as when we try to update fl2->base child, old not yet + * write-to-selected -> fl1 -> base branch it will succeed: it firstly drop + * exclusive write permissions and than apply them for another BdrvChildre= n. + * But if permission update goes first through write-to-selected -> fl2 ->= base + * branch it will fail, as when we try to update fl2->base child, old not = yet * updated fl1->base child will be in conflict. * * With topological-sort order we always update parents before children, s= o fl1 @@ -306,9 +323,10 @@ static BlockDriver bdrv_write_to_file =3D { static void test_parallel_perm_update(void) { BlockDriverState *top =3D no_perm_node("top"); - BlockDriverState *tricky =3D - bdrv_new_open_driver(&bdrv_write_to_file, "tricky", BDRV_O_RDW= R, + BlockDriverState *ws =3D + bdrv_new_open_driver(&bdrv_write_to_selected, "ws", BDRV_O_RDW= R, &error_abort); + BDRVWriteToSelectedState *s =3D ws->opaque; BlockDriverState *base =3D no_perm_node("base"); BlockDriverState *fl1 =3D pass_through_node("fl1"); BlockDriverState *fl2 =3D pass_through_node("fl2"); @@ -320,33 +338,33 @@ static void test_parallel_perm_update(void) */ bdrv_ref(base); =20 - bdrv_attach_child(top, tricky, "file", &child_of_bds, BDRV_CHILD_DATA, + bdrv_attach_child(top, ws, "file", &child_of_bds, BDRV_CHILD_DATA, &error_abort); - c_fl1 =3D bdrv_attach_child(tricky, fl1, "first", &child_of_bds, - BDRV_CHILD_FILTERED, &error_abort); - c_fl2 =3D bdrv_attach_child(tricky, fl2, "second", &child_of_bds, - BDRV_CHILD_FILTERED, &error_abort); + c_fl1 =3D bdrv_attach_child(ws, fl1, "first", &child_of_bds, + BDRV_CHILD_DATA, &error_abort); + c_fl2 =3D bdrv_attach_child(ws, fl2, "second", &child_of_bds, + BDRV_CHILD_DATA, &error_abort); bdrv_attach_child(fl1, base, "backing", &child_of_bds, BDRV_CHILD_FILT= ERED, &error_abort); bdrv_attach_child(fl2, base, "backing", &child_of_bds, BDRV_CHILD_FILT= ERED, &error_abort); =20 /* Select fl1 as first child to be active */ - tricky->file =3D c_fl1; + s->selected =3D c_fl1; bdrv_child_refresh_perms(top, top->children.lh_first, &error_abort); =20 assert(c_fl1->perm & BLK_PERM_WRITE); assert(!(c_fl2->perm & BLK_PERM_WRITE)); =20 /* Now, try to switch active child and update permissions */ - tricky->file =3D c_fl2; + s->selected =3D c_fl2; bdrv_child_refresh_perms(top, top->children.lh_first, &error_abort); =20 assert(c_fl2->perm & BLK_PERM_WRITE); assert(!(c_fl1->perm & BLK_PERM_WRITE)); =20 /* Switch once more, to not care about real child order in the list */ - tricky->file =3D c_fl1; + s->selected =3D c_fl1; bdrv_child_refresh_perms(top, top->children.lh_first, &error_abort); =20 assert(c_fl1->perm & BLK_PERM_WRITE); --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658867156; cv=none; d=zohomail.com; s=zohoarc; b=dbWc1vvgwKVaHG5vTHuCGoPPYlVaR4XZWk1QwejxfQBsXcmZJ18468m5ylXwHCL6XW9wPEpFfSdWUYn7MLRvvMYB5fULui736fKTwiZwcH5nx6KxrBgm9cHkePsnXtcQaHCYJ9NP5J2aZR6Vlf7q7SbFoXNf7atN1uzd9XQjq6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658867156; 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; bh=1PgPpbCWetTiZ45OLenSsW9L9CTtt5yDtt1BOgpawyQ=; b=VXAaK7oa/i6VOywGdKuRMLlIW7YfV4DPM7M2swXp0WBJ5KuEuFtE1OOg+fKV+xofWlV2flqNshyAz05IqIlNIbjjdbVDlIYwx1umHzBOgNQ61e2YlXHP22kxzaSt8jo/tZFNvRe57NQKU7X5scN9jvidFm6wwU8QhA13/WN/I78= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165886715634620.95344926132441; Tue, 26 Jul 2022 13:25:56 -0700 (PDT) Received: from localhost ([::1]:51056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGR7r-0006LY-6I for importer@patchew.org; Tue, 26 Jul 2022 16:25:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuY-00019j-UT; Tue, 26 Jul 2022 16:12:13 -0400 Received: from forwardcorp1o.mail.yandex.net ([2a02:6b8:0:1a2d::193]:47278) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuW-0001EG-1l; Tue, 26 Jul 2022 16:12:09 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 3E3232E0E7D; Tue, 26 Jul 2022 23:12:00 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-BvO0oDoS; Tue, 26 Jul 2022 23:11:59 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866319; bh=1PgPpbCWetTiZ45OLenSsW9L9CTtt5yDtt1BOgpawyQ=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=KsRpMNi8taVogdh108QSz18sxJ06cnLgF4cD3lS5nJiXiUBprKhlOAfCdEa0qiRcW dOQZdZpwkan+pcGdLXrHiOBgtCDPOteEY0sVw5C5RxNh+eFVvpORKeNoKwbIZIhYbA eBTuI/S1StgQSmj/fVqp2nT2qprNlfVouXBywppc= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru, Eric Blake , Nikita Lapshin Subject: [PATCH v7 05/15] tests-bdrv-drain: bdrv_replace_test driver: declare supports_backing Date: Tue, 26 Jul 2022 23:11:24 +0300 Message-Id: <20220726201134.924743-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a02:6b8:0:1a2d::193; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1o.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658867158398100001 Content-Type: text/plain; charset="utf-8" We do add COW child to the node. In future we are going to forbid adding COW child to the node that doesn't support backing. So, fix it here now. Don't worry about setting bs->backing itself: in further commit we'll update the block-layer to automatically set/unset this field in generic code. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- tests/unit/test-bdrv-drain.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 36be84ae55..23d425a494 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -1948,6 +1948,7 @@ static void coroutine_fn bdrv_replace_test_co_drain_e= nd(BlockDriverState *bs) static BlockDriver bdrv_replace_test =3D { .format_name =3D "replace_test", .instance_size =3D sizeof(BDRVReplaceTestState), + .supports_backing =3D true, =20 .bdrv_close =3D bdrv_replace_test_close, .bdrv_co_preadv =3D bdrv_replace_test_co_preadv, --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658866863; cv=none; d=zohomail.com; s=zohoarc; b=GjciLU95B/vArH16JpvulXPycVX3k9RwwXfkBxhLkqYO7pJH9LNwWxb4UZb4VyQleSQOlxwM57nkjLq0GwKVXZq6ayf8zy5lNLqjG3SJ83UAntvgHzHcUsiHgtFAIMigDaw1tflMfbw7mWKs4D9UfE+RL/A0QwBZksKXGPGNcNk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658866863; 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; bh=1b7az85xv1izAXS2XaeET9ol2g2me2P7ptX9XmoetW4=; b=h+/+PJeS/1QNDImb0GwwjYf7r4vL7BOHF9DlAn74o8si4IbrR/Z/1/1HB/FsBTXx+F1ZftMAm5y+fm992hEi01veUzUm+psPO2lEphWm+ApowzHj+e1ECwkl0dd244KzkSAbjANBDOf2bvfWqmOdbSO5MKDUj/mcc2nQXtqn7Uk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658866863240366.78439485469744; Tue, 26 Jul 2022 13:21:03 -0700 (PDT) Received: from localhost ([::1]:36204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGR35-0004GM-UF for importer@patchew.org; Tue, 26 Jul 2022 16:21:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuc-0001BD-NF; Tue, 26 Jul 2022 16:12:15 -0400 Received: from forwardcorp1o.mail.yandex.net ([2a02:6b8:0:1a2d::193]:47292) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuY-0001EY-Lq; Tue, 26 Jul 2022 16:12:13 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id AB1672E0E85; Tue, 26 Jul 2022 23:12:01 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-C0O08Uc6; Tue, 26 Jul 2022 23:12:00 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866320; bh=1b7az85xv1izAXS2XaeET9ol2g2me2P7ptX9XmoetW4=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=sZiA5Vj6YJggxlmjZKnidmeygIoBJxDUtQSrzyQ1Uuxi55Z4aiNnhqfFoMDkbsI8t xE8KlcTHBkZOQG+rnvyiuBlCeTo3Pv0SNyF0y+0OJiBshk+tyfmB2ZpEj4BlTUBWBv cVGuvsY0LZDOBOT66eKyaMjTVhVbSriZGjPlAxbI= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v7 06/15] test-bdrv-graph-mod: fix filters to be filters Date: Tue, 26 Jul 2022 23:11:25 +0300 Message-Id: <20220726201134.924743-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a02:6b8:0:1a2d::193; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1o.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658866865047100001 Content-Type: text/plain; charset="utf-8" bdrv_pass_through is used as filter, even all node variables has corresponding names. We want to append it, so it should be backing-child-based filter like mirror_top. So, in test_update_perm_tree, first child should be DATA, as we don't want filters with two filtered children. bdrv_exclusive_writer is used as a filter once. So it should be filter anyway. We want to append it, so it should be backing-child-based fitler too. Make all FILTERED children to be PRIMARY as well. We are going to force this rule by assertion soon. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- include/block/block_int-common.h | 5 +++-- tests/unit/test-bdrv-graph-mod.c | 24 +++++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 9d91ccbcbf..d68adc6ff3 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -122,8 +122,9 @@ struct BlockDriver { /* * Only make sense for filter drivers, for others must be false. * If true, filtered child is bs->backing. Otherwise it's bs->file. - * Only two internal filters use bs->backing as filtered child and has= this - * field set to true: mirror_top and commit_top. + * Two internal filters use bs->backing as filtered child and has this + * field set to true: mirror_top and commit_top. There also two such t= est + * filters in tests/unit/test-bdrv-graph-mod.c. * * Never create any more such filters! * diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-= mod.c index e2f1355af1..c522591531 100644 --- a/tests/unit/test-bdrv-graph-mod.c +++ b/tests/unit/test-bdrv-graph-mod.c @@ -26,6 +26,8 @@ =20 static BlockDriver bdrv_pass_through =3D { .format_name =3D "pass-through", + .is_filter =3D true, + .filtered_child_is_backing =3D true, .bdrv_child_perm =3D bdrv_default_perms, }; =20 @@ -57,6 +59,8 @@ static void exclusive_write_perms(BlockDriverState *bs, B= drvChild *c, =20 static BlockDriver bdrv_exclusive_writer =3D { .format_name =3D "exclusive-writer", + .is_filter =3D true, + .filtered_child_is_backing =3D true, .bdrv_child_perm =3D exclusive_write_perms, }; =20 @@ -134,7 +138,7 @@ static void test_update_perm_tree(void) blk_insert_bs(root, bs, &error_abort); =20 bdrv_attach_child(filter, bs, "child", &child_of_bds, - BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, &error_abo= rt); + BDRV_CHILD_DATA, &error_abort); =20 ret =3D bdrv_append(filter, bs, NULL); g_assert_cmpint(ret, <, 0); @@ -228,11 +232,14 @@ static void test_parallel_exclusive_write(void) */ bdrv_ref(base); =20 - bdrv_attach_child(top, fl1, "backing", &child_of_bds, BDRV_CHILD_DATA, + bdrv_attach_child(top, fl1, "backing", &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, &error_abort); - bdrv_attach_child(fl1, base, "backing", &child_of_bds, BDRV_CHILD_FILT= ERED, + bdrv_attach_child(fl1, base, "backing", &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, &error_abort); - bdrv_attach_child(fl2, base, "backing", &child_of_bds, BDRV_CHILD_FILT= ERED, + bdrv_attach_child(fl2, base, "backing", &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, &error_abort); =20 bdrv_replace_node(fl1, fl2, &error_abort); @@ -344,9 +351,11 @@ static void test_parallel_perm_update(void) BDRV_CHILD_DATA, &error_abort); c_fl2 =3D bdrv_attach_child(ws, fl2, "second", &child_of_bds, BDRV_CHILD_DATA, &error_abort); - bdrv_attach_child(fl1, base, "backing", &child_of_bds, BDRV_CHILD_FILT= ERED, + bdrv_attach_child(fl1, base, "backing", &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, &error_abort); - bdrv_attach_child(fl2, base, "backing", &child_of_bds, BDRV_CHILD_FILT= ERED, + bdrv_attach_child(fl2, base, "backing", &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, &error_abort); =20 /* Select fl1 as first child to be active */ @@ -397,7 +406,8 @@ static void test_append_greedy_filter(void) BlockDriverState *base =3D no_perm_node("base"); BlockDriverState *fl =3D exclusive_writer_node("fl1"); =20 - bdrv_attach_child(top, base, "backing", &child_of_bds, BDRV_CHILD_COW, + bdrv_attach_child(top, base, "backing", &child_of_bds, + BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, &error_abort); =20 bdrv_append(fl, base, &error_abort); --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658866768; cv=none; d=zohomail.com; s=zohoarc; b=F26dakgXU1AEALu9hfYhzMNTkK1Iy3XwsZtpPoqfqQVjVGP7JNgmF1m0dAuHduS+/q+fMZhmo3t+q64aJNXD/GyTK/bGLJhdVtG4SzFCMfPXicoaxZU2LQgIB+hndIVIU5weNk98nX2Ei1qdrkuiaB1dZtWgj08fwae76s/iS4U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658866768; h=Content-Type: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; bh=B2D1HuWhEklox32dPf51sOjDjf2sSA0pIxjBm2+6c18=; b=WNLH58LBm9G1bzW86ChE4esddI0p44H/o+8XYaBcF9gPMkjwmDc0dYkhyvSxNg/CDCM+aDWREtnpze3gHxFhYlTljUI9TTa2vb5ui/f1WstExg4nra2nHPmhb2sqRwp2vb/qZaoQwa1lD7QuF3ipwb2gSoanONdYy5STfETyYa4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658866768445273.4082585713112; Tue, 26 Jul 2022 13:19:28 -0700 (PDT) Received: from localhost ([::1]:33560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGR1b-0002Sc-DP for importer@patchew.org; Tue, 26 Jul 2022 16:19:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuc-0001BA-M9; Tue, 26 Jul 2022 16:12:15 -0400 Received: from forwardcorp1j.mail.yandex.net ([2a02:6b8:0:1619::183]:34388) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQua-0001Eq-HP; Tue, 26 Jul 2022 16:12:14 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id D3B122E1EA1; Tue, 26 Jul 2022 23:12:02 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-C1O004g1; Tue, 26 Jul 2022 23:12:02 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866322; bh=B2D1HuWhEklox32dPf51sOjDjf2sSA0pIxjBm2+6c18=; h=Cc:Message-Id:References:Date:In-Reply-To:Subject:To:From; b=JWWBznnSHFz13NDCwE/UBCUe81S7N5vKwIU/M1ppMrU4OPa/oYpM2IIq16wGf50Eo IZnTFj+pYY8q/8D73iNA5BX6jsEoUktAW3cazWY45NJbvwNjpeP7blGSZ/FcziVQQ8 sE3Nod0M+IfIy1wHyiWJyz5euCvFZkmf2Q+LdATU= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v7 07/15] block: document connection between child roles and bs->backing/bs->file Date: Tue, 26 Jul 2022 23:11:26 +0300 Message-Id: <20220726201134.924743-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a02:6b8:0:1619::183; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658866768785100001 Make the informal rules formal. In further commit we'll add corresponding assertions. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- include/block/block-common.h | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/include/block/block-common.h b/include/block/block-common.h index fdb7306e78..fda67a7c38 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -313,6 +313,45 @@ enum { * * At least one of DATA, METADATA, FILTERED, or COW must be set for * every child. + * + * + * =3D Connection with bs->children, bs->file and bs->backing fields =3D + * + * 1. Filters + * + * Filter drivers have drv->is_filter =3D true. + * + * Filter node has exactly one FILTERED|PRIMARY child, and may have other + * children which must not have these bits (one example is the + * copy-before-write filter, which also has its target DATA child). + * + * Filter nodes never have COW children. + * + * For most filters, the filtered child is linked in bs->file, bs->backing= is + * NULL. For some filters (as an exception), it is the other way around; = those + * drivers will have drv->filtered_child_is_backing set to true (see that + * field=E2=80=99s documentation for what drivers this concerns) + * + * 2. "raw" driver (block/raw-format.c) + * + * Formally it's not a filter (drv->is_filter =3D false) + * + * bs->backing is always NULL + * + * Only has one child, linked in bs->file. Its role is either FILTERED|PRI= MARY + * (like filter) or DATA|PRIMARY depending on options. + * + * 3. Other drivers + * + * Don't have any FILTERED children. + * + * May have at most one COW child. In this case it's linked in bs->backing. + * Otherwise bs->backing is NULL. COW child is never PRIMARY. + * + * May have at most one PRIMARY child. In this case it's linked in bs->fil= e. + * Otherwise bs->file is NULL. + * + * May also have some other children that don't have the PRIMARY or COW bi= t set. */ enum BdrvChildRoleBits { /* --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658868668; cv=none; d=zohomail.com; s=zohoarc; b=NUaA0To/2bcAruoGAVAgZoPgMZD7v+II2KF6U7iLzVTTIaMKaw0nbVuLhWyowUOMlQT8ztMkqV+SEEKdcuIs424rVUgTZhCokUxaXIOrWp2zyrukhwolCAfmAzLhTPrNDMcA9goWdGnrsMIhETR0ySDMS/OPy8Se8e1zInsOCjA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658868668; 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; bh=fdnzy21DcNkb5I8H6BYC0uuZF3cLw3rYot4unxKH7aQ=; b=eZdjGSt7skI8Ww2gPEdMbUaG2YSM9sONB4ozORlPVJFF2ri0yxumt0HNDldwhf8EBbzEWedAuUVGWHvKM6gHlzzh4ofSlsYqUE9L1cBG/LrhZkHRhfiVtiTmis9494dCk7CXzp3an/MX4kZnkSEgOr18KtV3QFwt87tRXjDS5cE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658868668097929.6254045422212; Tue, 26 Jul 2022 13:51:08 -0700 (PDT) Received: from localhost ([::1]:56014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGRWD-0006Ma-Tl for importer@patchew.org; Tue, 26 Jul 2022 16:51:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQue-0001CZ-HB; Tue, 26 Jul 2022 16:12:16 -0400 Received: from forwardcorp1o.mail.yandex.net ([2a02:6b8:0:1a2d::193]:47324) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQua-0001F7-Gn; Tue, 26 Jul 2022 16:12:15 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id C366F2E0DC9; Tue, 26 Jul 2022 23:12:03 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-C2O0Ts3Z; Tue, 26 Jul 2022 23:12:03 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866323; bh=fdnzy21DcNkb5I8H6BYC0uuZF3cLw3rYot4unxKH7aQ=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=vLWsB87lXiQSsZr2inLKq63b5n9te+xmKuaPPmaF7V0EQETarZY43zCAaSljpa/Fk QcqUmTtFrR62t+i6a3JgE7PcXff8PmmdK290CxAFXB5eAP9zdjK0x5OLGYRFkfZFnh m2yY7jvy8Ev4iNVe3EZhm7zkrLuu36LSIcyRYibg= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v7 08/15] block/snapshot: stress that we fallback to primary child Date: Tue, 26 Jul 2022 23:11:27 +0300 Message-Id: <20220726201134.924743-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a02:6b8:0:1a2d::193; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1o.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658868669088100001 Content-Type: text/plain; charset="utf-8" Actually what we chose is a primary child. Let's stress it in the code. We are going to drop indirect pointer logic here in future. Actually this commit simplifies the future work: we drop use of indirection in the assertion now. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- block/snapshot.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/block/snapshot.c b/block/snapshot.c index d6f53c3065..75e8d3a937 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -161,21 +161,14 @@ bool bdrv_snapshot_find_by_id_and_name(BlockDriverSta= te *bs, static BdrvChild **bdrv_snapshot_fallback_ptr(BlockDriverState *bs) { BdrvChild **fallback; - BdrvChild *child; + BdrvChild *child =3D bdrv_primary_child(bs); =20 - /* - * The only BdrvChild pointers that are safe to modify (and which - * we can thus return a reference to) are bs->file and - * bs->backing. - */ - fallback =3D &bs->file; - if (!*fallback && bs->drv && bs->drv->is_filter) { - fallback =3D &bs->backing; - } - - if (!*fallback) { + /* We allow fallback only to primary child */ + if (!child) { return NULL; } + fallback =3D (child =3D=3D bs->file ? &bs->file : &bs->backing); + assert(*fallback =3D=3D child); =20 /* * Check that there are no other children that would need to be @@ -309,15 +302,12 @@ int bdrv_snapshot_goto(BlockDriverState *bs, } =20 /* - * fallback_ptr is &bs->file or &bs->backing. *fallback_ptr - * was closed above and set to NULL, but the .bdrv_open() call - * has opened it again, because we set the respective option - * (with the qdict_put_str() call above). - * Assert that .bdrv_open() has attached some child on - * *fallback_ptr, and that it has attached the one we wanted - * it to (i.e., fallback_bs). + * fallback was a primary child. It was closed above and set to NU= LL, + * but the .bdrv_open() call has opened it again, because we set t= he + * respective option (with the qdict_put_str() call above). + * Assert that .bdrv_open() has attached the right BDS as primary = child. */ - assert(*fallback_ptr && fallback_bs =3D=3D (*fallback_ptr)->bs); + assert(bdrv_primary_bs(bs) =3D=3D fallback_bs); bdrv_unref(fallback_bs); return ret; } --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658867057; cv=none; d=zohomail.com; s=zohoarc; b=FDXRgh/1Yxbqse3kla9XR4m8PrCki9dzL6BhZqIdmH62evPFVqLxPQcAB4H3blY2szJKyeEY6UGCQexjnNmNmPU00SbCf22QRT3YWiV1s/BFJbOnC0trOiRSBCNO7V0gG0LnmJV5N4XQ7OtncOD2YnIUyXws1zBuZ6Brx9kYKHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658867057; 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; bh=SumzHWPrJXjBUp98LTeC/go1TA4Q4K5i+wABmXv+FwE=; b=Sbp7RTeLuR3J+3kSxCQQo6CDnw70X+v8Oe7lzE6CWfEkFQgZR9lBrvUVrr6N/nKyx61iOZUxlxFn3/a8hvjmNUeIs0i8jurl1ZDfgnjTg+a5O8lSDNUzX4AIaCh4kCOUvLt2R8nXkZLGFN0K2DmHnbTm2I/GsO4dDVssuVUmZ/k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658867057790512.4858559380309; Tue, 26 Jul 2022 13:24:17 -0700 (PDT) Received: from localhost ([::1]:45202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGR6G-00027u-JB for importer@patchew.org; Tue, 26 Jul 2022 16:24:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQug-0001FR-Gd; Tue, 26 Jul 2022 16:12:18 -0400 Received: from forwardcorp1o.mail.yandex.net ([95.108.205.193]:53372) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQud-0001FZ-0m; Tue, 26 Jul 2022 16:12:17 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 326DC2E11FE; Tue, 26 Jul 2022 23:12:05 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-C3O0ileW; Tue, 26 Jul 2022 23:12:04 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866324; bh=SumzHWPrJXjBUp98LTeC/go1TA4Q4K5i+wABmXv+FwE=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=v4lMpdDnD57CClbJbPXWah50sIKYFBXI4+OEcEEjgm4otaiw1+ioTtGFJPvhrn2Ez HOMIOJcJ80Gw01pF6yvUXcXtLLgyouxhEwjHvZ6bSapQIrbSVgfHndsnZhMcoSq0mL JezcoJfDH6Bzlnu5oRDZSazPaY9jw2fDTMuCBp0k= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v7 09/15] Revert "block: Let replace_child_noperm free children" Date: Tue, 26 Jul 2022 23:11:28 +0300 Message-Id: <20220726201134.924743-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=95.108.205.193; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1o.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658867059322100001 Content-Type: text/plain; charset="utf-8" We are going to reimplement this behavior (clear bs->file / bs->backing pointers automatically when child->bs is cleared) in a nicer way, see further commit "block: Manipulate bs->file / bs->backing pointers in .attach/.detach". With this revert we bring back a problem that was fixed by b0a9f6fed3d8. Still the problem was mostly theoretical, we don't have concrete bugs fixed by b0a9f6fed3d8, we don't have a specific test. Probably some accidental failures of iotests are related. Alternatively, we may merge this and following three reverts into final "block: Manipulate ..." to avoid any kind of regression. But seems that in this case having separate clear revert commits is better. This reverts commit b0a9f6fed3d80de610dcd04a7e66f9f30a04174f. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- block.c | 102 +++++++++++++------------------------------------------- 1 file changed, 23 insertions(+), 79 deletions(-) diff --git a/block.c b/block.c index 4e38fc45c0..87e2f23d13 100644 --- a/block.c +++ b/block.c @@ -90,10 +90,8 @@ static BlockDriverState *bdrv_open_inherit(const char *f= ilename, static bool bdrv_recurse_has_child(BlockDriverState *bs, BlockDriverState *child); =20 -static void bdrv_child_free(BdrvChild *child); static void bdrv_replace_child_noperm(BdrvChild **child, - BlockDriverState *new_bs, - bool free_empty_child); + BlockDriverState *new_bs); static void bdrv_remove_file_or_backing_child(BlockDriverState *bs, BdrvChild *child, Transaction *tran); @@ -2340,7 +2338,6 @@ typedef struct BdrvReplaceChildState { BdrvChild *child; BdrvChild **childp; BlockDriverState *old_bs; - bool free_empty_child; } BdrvReplaceChildState; =20 static void bdrv_replace_child_commit(void *opaque) @@ -2348,9 +2345,6 @@ static void bdrv_replace_child_commit(void *opaque) BdrvReplaceChildState *s =3D opaque; GLOBAL_STATE_CODE(); =20 - if (s->free_empty_child && !s->child->bs) { - bdrv_child_free(s->child); - } bdrv_unref(s->old_bs); } =20 @@ -2368,26 +2362,22 @@ static void bdrv_replace_child_abort(void *opaque) * modify the BdrvChild * pointer we indirectly pass to it, i.e. it * will not modify s->child. From that perspective, it does not m= atter * whether we pass s->childp or &s->child. + * (TODO: Right now, bdrv_replace_child_noperm() never modifies th= at + * pointer anyway (though it will in the future), so at this point= it + * absolutely does not matter whether we pass s->childp or &s->chi= ld.) * (2) If new_bs is not NULL, s->childp will be NULL. We then cannot = use * it here. * (3) If new_bs is NULL, *s->childp will have been NULLed by * bdrv_replace_child_tran()'s bdrv_replace_child_noperm() call, a= nd we * must not pass a NULL *s->childp here. + * (TODO: In its current state, bdrv_replace_child_noperm() will n= ot + * have NULLed *s->childp, so this does not apply yet. It will in= the + * future.) * * So whether new_bs was NULL or not, we cannot pass s->childp here; a= nd in * any case, there is no reason to pass it anyway. */ - bdrv_replace_child_noperm(&s->child, s->old_bs, true); - /* - * The child was pre-existing, so s->old_bs must be non-NULL, and - * s->child thus must not have been freed - */ - assert(s->child !=3D NULL); - if (!new_bs) { - /* As described above, *s->childp was cleared, so restore it */ - assert(s->childp !=3D NULL); - *s->childp =3D s->child; - } + bdrv_replace_child_noperm(&s->child, s->old_bs); bdrv_unref(new_bs); } =20 @@ -2404,44 +2394,30 @@ static TransactionActionDrv bdrv_replace_child_drv = =3D { * * The function doesn't update permissions, caller is responsible for this. * - * (*childp)->bs must not be NULL. - * * Note that if new_bs =3D=3D NULL, @childp is stored in a state object at= tached * to @tran, so that the old child can be reinstated in the abort handler. * Therefore, if @new_bs can be NULL, @childp must stay valid until the * transaction is committed or aborted. * - * If @free_empty_child is true and @new_bs is NULL, the BdrvChild is - * freed (on commit). @free_empty_child should only be false if the - * caller will free the BDrvChild themselves (which may be important - * if this is in turn called in another transactional context). + * (TODO: The reinstating does not happen yet, but it will once + * bdrv_replace_child_noperm() NULLs *childp when new_bs is NULL.) */ static void bdrv_replace_child_tran(BdrvChild **childp, BlockDriverState *new_bs, - Transaction *tran, - bool free_empty_child) + Transaction *tran) { BdrvReplaceChildState *s =3D g_new(BdrvReplaceChildState, 1); *s =3D (BdrvReplaceChildState) { .child =3D *childp, .childp =3D new_bs =3D=3D NULL ? childp : NULL, .old_bs =3D (*childp)->bs, - .free_empty_child =3D free_empty_child, }; tran_add(tran, &bdrv_replace_child_drv, s); =20 - /* The abort handler relies on this */ - assert(s->old_bs !=3D NULL); - if (new_bs) { bdrv_ref(new_bs); } - /* - * Pass free_empty_child=3Dfalse, we will free the child (if - * necessary) in bdrv_replace_child_commit() (if our - * @free_empty_child parameter was true). - */ - bdrv_replace_child_noperm(childp, new_bs, false); + bdrv_replace_child_noperm(childp, new_bs); /* old_bs reference is transparently moved from *childp to @s */ } =20 @@ -2823,22 +2799,8 @@ uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission = qapi_perm) return permissions[qapi_perm]; } =20 -/** - * Replace (*childp)->bs by @new_bs. - * - * If @new_bs is NULL, *childp will be set to NULL, too: BDS parents - * generally cannot handle a BdrvChild with .bs =3D=3D NULL, so clearing - * BdrvChild.bs should generally immediately be followed by the - * BdrvChild pointer being cleared as well. - * - * If @free_empty_child is true and @new_bs is NULL, the BdrvChild is - * freed. @free_empty_child should only be false if the caller will - * free the BdrvChild themselves (this may be important in a - * transactional context, where it may only be freed on commit). - */ static void bdrv_replace_child_noperm(BdrvChild **childp, - BlockDriverState *new_bs, - bool free_empty_child) + BlockDriverState *new_bs) { BdrvChild *child =3D *childp; BlockDriverState *old_bs =3D child->bs; @@ -2877,9 +2839,6 @@ static void bdrv_replace_child_noperm(BdrvChild **chi= ldp, } =20 child->bs =3D new_bs; - if (!new_bs) { - *childp =3D NULL; - } =20 if (new_bs) { assert_bdrv_graph_writable(new_bs); @@ -2910,10 +2869,6 @@ static void bdrv_replace_child_noperm(BdrvChild **ch= ildp, bdrv_parent_drained_end_single(child); drain_saldo++; } - - if (free_empty_child && !child->bs) { - bdrv_child_free(child); - } } =20 /** @@ -2945,14 +2900,7 @@ static void bdrv_attach_child_common_abort(void *opa= que) BlockDriverState *bs =3D child->bs; =20 GLOBAL_STATE_CODE(); - /* - * Pass free_empty_child=3Dfalse, because we still need the child - * for the AioContext operations on the parent below; those - * BdrvChildClass methods all work on a BdrvChild object, so we - * need to keep it as an empty shell (after this function, it will - * not be attached to any parent, and it will not have a .bs). - */ - bdrv_replace_child_noperm(s->child, NULL, false); + bdrv_replace_child_noperm(s->child, NULL); =20 if (bdrv_get_aio_context(bs) !=3D s->old_child_ctx) { bdrv_try_set_aio_context(bs, s->old_child_ctx, &error_abort); @@ -2974,6 +2922,7 @@ static void bdrv_attach_child_common_abort(void *opaq= ue) =20 bdrv_unref(bs); bdrv_child_free(child); + *s->child =3D NULL; } =20 static TransactionActionDrv bdrv_attach_child_common_drv =3D { @@ -3052,9 +3001,7 @@ static int bdrv_attach_child_common(BlockDriverState = *child_bs, } =20 bdrv_ref(child_bs); - bdrv_replace_child_noperm(&new_child, child_bs, true); - /* child_bs was non-NULL, so new_child must not have been freed */ - assert(new_child !=3D NULL); + bdrv_replace_child_noperm(&new_child, child_bs); =20 *child =3D new_child; =20 @@ -3115,7 +3062,8 @@ static void bdrv_detach_child(BdrvChild **childp) BlockDriverState *old_bs =3D (*childp)->bs; =20 GLOBAL_STATE_CODE(); - bdrv_replace_child_noperm(childp, NULL, true); + bdrv_replace_child_noperm(childp, NULL); + bdrv_child_free(*childp); =20 if (old_bs) { /* @@ -5169,11 +5117,7 @@ static void bdrv_remove_file_or_backing_child(BlockD= riverState *bs, } =20 if (child->bs) { - /* - * Pass free_empty_child=3Dfalse, we will free the child in - * bdrv_remove_filter_or_cow_child_commit() - */ - bdrv_replace_child_tran(childp, NULL, tran, false); + bdrv_replace_child_tran(childp, NULL, tran); } =20 s =3D g_new(BdrvRemoveFilterOrCowChild, 1); @@ -5183,6 +5127,8 @@ static void bdrv_remove_file_or_backing_child(BlockDr= iverState *bs, .is_backing =3D (childp =3D=3D &bs->backing), }; tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, s); + + *childp =3D NULL; } =20 /* @@ -5226,7 +5172,7 @@ static int bdrv_replace_node_noperm(BlockDriverState = *from, * Passing a pointer to the local variable @c is fine here, because * @to is not NULL, and so &c will not be attached to the transact= ion. */ - bdrv_replace_child_tran(&c, to, tran, true); + bdrv_replace_child_tran(&c, to, tran); } =20 return 0; @@ -5391,9 +5337,7 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDriv= erState *new_bs, bdrv_drained_begin(old_bs); bdrv_drained_begin(new_bs); =20 - bdrv_replace_child_tran(&child, new_bs, tran, true); - /* @new_bs must have been non-NULL, so @child must not have been freed= */ - assert(child !=3D NULL); + bdrv_replace_child_tran(&child, new_bs, tran); =20 found =3D g_hash_table_new(NULL, NULL); refresh_list =3D bdrv_topological_dfs(refresh_list, found, old_bs); --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658868796; cv=none; d=zohomail.com; s=zohoarc; b=hMap6nG7JxxxlMYS+uI48AscVhRuns9G79yS9LJhGPSFNv3xbWzuUZQi9Mylgns+zwd9YgY77/TNqG5RnhBXrjfExoJefiJSWnuuBSMSZy+d5+fST6mxnhvqY0EjdJ7vxliique2vx62EFeaXQBF0XXU1z/ZYXm4W1tKa5Y4dlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658868796; 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; bh=kQC/aeeDn6FwBv4UfdYHuo99XfOwJKqkozfP6+z1lvA=; b=htRTAFLyNXVjMhK5nxtzSC+hKejtbC3bGRpI1x5kxqus1tvflgimwVUr12MmRyGmI8pE57/Wul1aLfBNWSYeDcinWaNlLsB5jp0/5MBc3RrOehnDOm4qmmmNaLcptBjm/FiBXzTQZKpwEwrIfSx9PCHnwJyxCDovw/4t9v11VNs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16588687962011019.3632980505037; Tue, 26 Jul 2022 13:53:16 -0700 (PDT) Received: from localhost ([::1]:59022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGRYH-0008PI-VL for importer@patchew.org; Tue, 26 Jul 2022 16:53:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQue-0001Dn-V1; Tue, 26 Jul 2022 16:12:16 -0400 Received: from forwardcorp1j.mail.yandex.net ([2a02:6b8:0:1619::183]:34406) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuc-0001Fu-Dy; Tue, 26 Jul 2022 16:12:16 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 7FFBC2E1985; Tue, 26 Jul 2022 23:12:06 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-C5O09WbR; Tue, 26 Jul 2022 23:12:05 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866325; bh=kQC/aeeDn6FwBv4UfdYHuo99XfOwJKqkozfP6+z1lvA=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=BoSrlX03hfnqc+OLxscynb2Fq/+re/fBaUOe66F3ON4eBNtibD5GJXnDupprROkcu XCi9rtplA9p6iEV2mu9FHSAQP60xNXS3Rt8QSuXt4DQ3hheTT1MsUDjPPJdz9A+aDn 0X4OaF+Z03cP6fAEczLJxbFUbdbdSadbh/LPn2kM= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v7 10/15] Revert "block: Let replace_child_tran keep indirect pointer" Date: Tue, 26 Jul 2022 23:11:29 +0300 Message-Id: <20220726201134.924743-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a02:6b8:0:1619::183; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658868796466100001 Content-Type: text/plain; charset="utf-8" That's a preparation to previously reverted "block: Let replace_child_noperm free children". Drop it too, we don't need it for a new approach. This reverts commit 82b54cf51656bf3cd5ed1ac549e8a1085a0e3290. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- block.c | 81 +++++++-------------------------------------------------- 1 file changed, 10 insertions(+), 71 deletions(-) diff --git a/block.c b/block.c index 87e2f23d13..1b9e0a2d79 100644 --- a/block.c +++ b/block.c @@ -2336,7 +2336,6 @@ static int bdrv_drv_set_perm(BlockDriverState *bs, ui= nt64_t perm, =20 typedef struct BdrvReplaceChildState { BdrvChild *child; - BdrvChild **childp; BlockDriverState *old_bs; } BdrvReplaceChildState; =20 @@ -2354,29 +2353,7 @@ static void bdrv_replace_child_abort(void *opaque) BlockDriverState *new_bs =3D s->child->bs; =20 GLOBAL_STATE_CODE(); - /* - * old_bs reference is transparently moved from @s to s->child. - * - * Pass &s->child here instead of s->childp, because: - * (1) s->old_bs must be non-NULL, so bdrv_replace_child_noperm() will= not - * modify the BdrvChild * pointer we indirectly pass to it, i.e. it - * will not modify s->child. From that perspective, it does not m= atter - * whether we pass s->childp or &s->child. - * (TODO: Right now, bdrv_replace_child_noperm() never modifies th= at - * pointer anyway (though it will in the future), so at this point= it - * absolutely does not matter whether we pass s->childp or &s->chi= ld.) - * (2) If new_bs is not NULL, s->childp will be NULL. We then cannot = use - * it here. - * (3) If new_bs is NULL, *s->childp will have been NULLed by - * bdrv_replace_child_tran()'s bdrv_replace_child_noperm() call, a= nd we - * must not pass a NULL *s->childp here. - * (TODO: In its current state, bdrv_replace_child_noperm() will n= ot - * have NULLed *s->childp, so this does not apply yet. It will in= the - * future.) - * - * So whether new_bs was NULL or not, we cannot pass s->childp here; a= nd in - * any case, there is no reason to pass it anyway. - */ + /* old_bs reference is transparently moved from @s to @s->child */ bdrv_replace_child_noperm(&s->child, s->old_bs); bdrv_unref(new_bs); } @@ -2393,32 +2370,22 @@ static TransactionActionDrv bdrv_replace_child_drv = =3D { * Note: real unref of old_bs is done only on commit. * * The function doesn't update permissions, caller is responsible for this. - * - * Note that if new_bs =3D=3D NULL, @childp is stored in a state object at= tached - * to @tran, so that the old child can be reinstated in the abort handler. - * Therefore, if @new_bs can be NULL, @childp must stay valid until the - * transaction is committed or aborted. - * - * (TODO: The reinstating does not happen yet, but it will once - * bdrv_replace_child_noperm() NULLs *childp when new_bs is NULL.) */ -static void bdrv_replace_child_tran(BdrvChild **childp, - BlockDriverState *new_bs, +static void bdrv_replace_child_tran(BdrvChild *child, BlockDriverState *ne= w_bs, Transaction *tran) { BdrvReplaceChildState *s =3D g_new(BdrvReplaceChildState, 1); *s =3D (BdrvReplaceChildState) { - .child =3D *childp, - .childp =3D new_bs =3D=3D NULL ? childp : NULL, - .old_bs =3D (*childp)->bs, + .child =3D child, + .old_bs =3D child->bs, }; tran_add(tran, &bdrv_replace_child_drv, s); =20 if (new_bs) { bdrv_ref(new_bs); } - bdrv_replace_child_noperm(childp, new_bs); - /* old_bs reference is transparently moved from *childp to @s */ + bdrv_replace_child_noperm(&child, new_bs); + /* old_bs reference is transparently moved from @child to @s */ } =20 /* @@ -5043,7 +5010,6 @@ static bool should_update_child(BdrvChild *c, BlockDr= iverState *to) =20 typedef struct BdrvRemoveFilterOrCowChild { BdrvChild *child; - BlockDriverState *bs; bool is_backing; } BdrvRemoveFilterOrCowChild; =20 @@ -5073,19 +5039,10 @@ static void bdrv_remove_filter_or_cow_child_commit(= void *opaque) bdrv_child_free(s->child); } =20 -static void bdrv_remove_filter_or_cow_child_clean(void *opaque) -{ - BdrvRemoveFilterOrCowChild *s =3D opaque; - - /* Drop the bs reference after the transaction is done */ - bdrv_unref(s->bs); - g_free(s); -} - static TransactionActionDrv bdrv_remove_filter_or_cow_child_drv =3D { .abort =3D bdrv_remove_filter_or_cow_child_abort, .commit =3D bdrv_remove_filter_or_cow_child_commit, - .clean =3D bdrv_remove_filter_or_cow_child_clean, + .clean =3D g_free, }; =20 /* @@ -5103,11 +5060,6 @@ static void bdrv_remove_file_or_backing_child(BlockD= riverState *bs, return; } =20 - /* - * Keep a reference to @bs so @childp will stay valid throughout the - * transaction (required by bdrv_replace_child_tran()) - */ - bdrv_ref(bs); if (child =3D=3D bs->backing) { childp =3D &bs->backing; } else if (child =3D=3D bs->file) { @@ -5117,13 +5069,12 @@ static void bdrv_remove_file_or_backing_child(Block= DriverState *bs, } =20 if (child->bs) { - bdrv_replace_child_tran(childp, NULL, tran); + bdrv_replace_child_tran(*childp, NULL, tran); } =20 s =3D g_new(BdrvRemoveFilterOrCowChild, 1); *s =3D (BdrvRemoveFilterOrCowChild) { .child =3D child, - .bs =3D bs, .is_backing =3D (childp =3D=3D &bs->backing), }; tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, s); @@ -5149,7 +5100,6 @@ static int bdrv_replace_node_noperm(BlockDriverState = *from, { BdrvChild *c, *next; =20 - assert(to !=3D NULL); GLOBAL_STATE_CODE(); =20 QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) { @@ -5167,12 +5117,7 @@ static int bdrv_replace_node_noperm(BlockDriverState= *from, c->name, from->node_name); return -EPERM; } - - /* - * Passing a pointer to the local variable @c is fine here, because - * @to is not NULL, and so &c will not be attached to the transact= ion. - */ - bdrv_replace_child_tran(&c, to, tran); + bdrv_replace_child_tran(c, to, tran); } =20 return 0; @@ -5187,8 +5132,6 @@ static int bdrv_replace_node_noperm(BlockDriverState = *from, * * With @detach_subchain=3Dtrue @to must be in a backing chain of @from. I= n this * case backing link of the cow-parent of @to is removed. - * - * @to must not be NULL. */ static int bdrv_replace_node_common(BlockDriverState *from, BlockDriverState *to, @@ -5202,7 +5145,6 @@ static int bdrv_replace_node_common(BlockDriverState = *from, int ret; =20 GLOBAL_STATE_CODE(); - assert(to !=3D NULL); =20 if (detach_subchain) { assert(bdrv_chain_contains(from, to)); @@ -5259,9 +5201,6 @@ out: return ret; } =20 -/** - * Replace node @from by @to (where neither may be NULL). - */ int bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, Error **errp) { @@ -5337,7 +5276,7 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDriv= erState *new_bs, bdrv_drained_begin(old_bs); bdrv_drained_begin(new_bs); =20 - bdrv_replace_child_tran(&child, new_bs, tran); + bdrv_replace_child_tran(child, new_bs, tran); =20 found =3D g_hash_table_new(NULL, NULL); refresh_list =3D bdrv_topological_dfs(refresh_list, found, old_bs); --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658867431; cv=none; d=zohomail.com; s=zohoarc; b=Y3hTIFXF30F2cWNzsUYQ7tMac0AVIbNgJzOUU0D3f6gD/VW3Znz1jseP+GVk1ncw/d1X/LxO4AQdfhX5/rqTm6qsL4V82Zag+nLTmYvlc9DJZvGyP3ytmXlyVeFk8dy5wGt2nA0U9QsH85ZjcqSqUWIK9TiN/FHKxx2pdsztcBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658867431; 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; bh=u2WoYoeSGjAr7Fv4syh3Df9fQs2caGcLdlmtxXnX5Lc=; b=LIdYIhoZ/n0iAKiLIjnDJ70m/qV+gIODPqcs0102sMXT2SYlhjVdMFDhVX80BPxCx8IAnIzOpD/+OmoDiM8hEoMwW4wykdsvwthniFNfDX40u/L7LXkTdnmpxL6p2T1nPyJWTojASvLlKvB96negNYeroGCXsrPUeDkSDhuuRz0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658867431674235.05838795780232; Tue, 26 Jul 2022 13:30:31 -0700 (PDT) Received: from localhost ([::1]:59868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGRCH-00048c-Nc for importer@patchew.org; Tue, 26 Jul 2022 16:30:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQui-0001JO-AN; Tue, 26 Jul 2022 16:12:23 -0400 Received: from forwardcorp1j.mail.yandex.net ([5.45.199.163]:47754) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQug-0001G0-6T; Tue, 26 Jul 2022 16:12:19 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 62C6F2E1C28; Tue, 26 Jul 2022 23:12:07 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-C6O0tanj; Tue, 26 Jul 2022 23:12:06 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866326; bh=u2WoYoeSGjAr7Fv4syh3Df9fQs2caGcLdlmtxXnX5Lc=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=Ehgz2B2sjWsdi6eQnHfW0fkUMHN0IvVm0s622nrjI2NuWJK0uKbcJuhVAAmQIRJ6t nuoCfX8U91xfWlnpO5TZ/lE6NO6c70nifv/cOfTDbGi1IHaGObW9ed8GOEi4Rhdy0j xfPsuoPT5bP1VtVdbobOBBCqJfpi/IHE5+dvwLU4= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v7 11/15] Revert "block: Restructure remove_file_or_backing_child()" Date: Tue, 26 Jul 2022 23:11:30 +0300 Message-Id: <20220726201134.924743-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=5.45.199.163; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658867433117100001 Content-Type: text/plain; charset="utf-8" That's a preparation to previously reverted "block: Let replace_child_noperm free children". Drop it too, we don't need it for a new approach. This reverts commit 562bda8bb41879eeda0bd484dd3d55134579b28e. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- block.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/block.c b/block.c index 1b9e0a2d79..5eefadf768 100644 --- a/block.c +++ b/block.c @@ -5053,33 +5053,30 @@ static void bdrv_remove_file_or_backing_child(Block= DriverState *bs, BdrvChild *child, Transaction *tran) { - BdrvChild **childp; BdrvRemoveFilterOrCowChild *s; =20 + assert(child =3D=3D bs->backing || child =3D=3D bs->file); + if (!child) { return; } =20 - if (child =3D=3D bs->backing) { - childp =3D &bs->backing; - } else if (child =3D=3D bs->file) { - childp =3D &bs->file; - } else { - g_assert_not_reached(); - } - if (child->bs) { - bdrv_replace_child_tran(*childp, NULL, tran); + bdrv_replace_child_tran(child, NULL, tran); } =20 s =3D g_new(BdrvRemoveFilterOrCowChild, 1); *s =3D (BdrvRemoveFilterOrCowChild) { .child =3D child, - .is_backing =3D (childp =3D=3D &bs->backing), + .is_backing =3D (child =3D=3D bs->backing), }; tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, s); =20 - *childp =3D NULL; + if (s->is_backing) { + bs->backing =3D NULL; + } else { + bs->file =3D NULL; + } } =20 /* --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658867005; cv=none; d=zohomail.com; s=zohoarc; b=GoJPcOehktfPSujzJjZ49CUQrD2eMGfmZxi9yTfj0QhwtCKm9myBQq43TsVUnro2IejdhiJxGiL0NbNCUDBdZxjed1fJgemVpi8BeI5yI4v93qioufL+Lm9AauiHZ0RgJPkbFYu5ZecSPWiPcnlYvWd6QmquXMJziSzcCud/T5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658867005; 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; bh=ju7HSe4Rh57FfV8BcLgPnrNRqeYW0EA92gk1W4avp3w=; b=k/vzurEKPG2kokFt96HmZ6LoLfGoFKAsI3ngo6+d2BJFriv1SyzflX4PDXnV6v9vXrjVNORKc9T93//36qdGcrcPQY+Qfw7a076JlDeH9OjGb/986zvI7HJO5wZp3foE5QwmJlMku46OuUDOkbosAXP3uBczUkbB0x4Dur/kRpc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658867005917408.60966518631164; Tue, 26 Jul 2022 13:23:25 -0700 (PDT) Received: from localhost ([::1]:42624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGR5P-0000Fx-HK for importer@patchew.org; Tue, 26 Jul 2022 16:23:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuj-0001Jp-9a; Tue, 26 Jul 2022 16:12:23 -0400 Received: from forwardcorp1o.mail.yandex.net ([2a02:6b8:0:1a2d::193]:47364) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQug-0001GF-6l; Tue, 26 Jul 2022 16:12:21 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 82F8F2E0DC5; Tue, 26 Jul 2022 23:12:08 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-C7O02it2; Tue, 26 Jul 2022 23:12:07 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866327; bh=ju7HSe4Rh57FfV8BcLgPnrNRqeYW0EA92gk1W4avp3w=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=aURYLLV9OoJptr1unua4+wFSv88Lgid8aMiTZDrXbAx/Bo9gHPuImgFNSYNr28ZT4 2suG9lImokVyMVHwhGUUkc6eQPRRrDPRkY9IKlvEXuuKz1fKEMwp9XEFS7RvDqFwCA tNByI3prnZ6jZs0DUmJTM+OB3hEk5mPDIqmjiv1Q= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v7 12/15] Revert "block: Pass BdrvChild ** to replace_child_noperm" Date: Tue, 26 Jul 2022 23:11:31 +0300 Message-Id: <20220726201134.924743-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a02:6b8:0:1a2d::193; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1o.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658867006353100001 Content-Type: text/plain; charset="utf-8" That's a preparation to previously reverted "block: Let replace_child_noperm free children". Drop it too, we don't need it for a new approach. This reverts commit be64bbb0149748f3999c49b13976aafb8330ea86. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- block.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/block.c b/block.c index 5eefadf768..121affb045 100644 --- a/block.c +++ b/block.c @@ -90,7 +90,7 @@ static BlockDriverState *bdrv_open_inherit(const char *fi= lename, static bool bdrv_recurse_has_child(BlockDriverState *bs, BlockDriverState *child); =20 -static void bdrv_replace_child_noperm(BdrvChild **child, +static void bdrv_replace_child_noperm(BdrvChild *child, BlockDriverState *new_bs); static void bdrv_remove_file_or_backing_child(BlockDriverState *bs, BdrvChild *child, @@ -2354,7 +2354,7 @@ static void bdrv_replace_child_abort(void *opaque) =20 GLOBAL_STATE_CODE(); /* old_bs reference is transparently moved from @s to @s->child */ - bdrv_replace_child_noperm(&s->child, s->old_bs); + bdrv_replace_child_noperm(s->child, s->old_bs); bdrv_unref(new_bs); } =20 @@ -2384,7 +2384,7 @@ static void bdrv_replace_child_tran(BdrvChild *child,= BlockDriverState *new_bs, if (new_bs) { bdrv_ref(new_bs); } - bdrv_replace_child_noperm(&child, new_bs); + bdrv_replace_child_noperm(child, new_bs); /* old_bs reference is transparently moved from @child to @s */ } =20 @@ -2766,10 +2766,9 @@ uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission = qapi_perm) return permissions[qapi_perm]; } =20 -static void bdrv_replace_child_noperm(BdrvChild **childp, +static void bdrv_replace_child_noperm(BdrvChild *child, BlockDriverState *new_bs) { - BdrvChild *child =3D *childp; BlockDriverState *old_bs =3D child->bs; int new_bs_quiesce_counter; int drain_saldo; @@ -2867,7 +2866,7 @@ static void bdrv_attach_child_common_abort(void *opaq= ue) BlockDriverState *bs =3D child->bs; =20 GLOBAL_STATE_CODE(); - bdrv_replace_child_noperm(s->child, NULL); + bdrv_replace_child_noperm(child, NULL); =20 if (bdrv_get_aio_context(bs) !=3D s->old_child_ctx) { bdrv_try_set_aio_context(bs, s->old_child_ctx, &error_abort); @@ -2968,7 +2967,7 @@ static int bdrv_attach_child_common(BlockDriverState = *child_bs, } =20 bdrv_ref(child_bs); - bdrv_replace_child_noperm(&new_child, child_bs); + bdrv_replace_child_noperm(new_child, child_bs); =20 *child =3D new_child; =20 @@ -3024,13 +3023,13 @@ static int bdrv_attach_child_noperm(BlockDriverStat= e *parent_bs, return 0; } =20 -static void bdrv_detach_child(BdrvChild **childp) +static void bdrv_detach_child(BdrvChild *child) { - BlockDriverState *old_bs =3D (*childp)->bs; + BlockDriverState *old_bs =3D child->bs; =20 GLOBAL_STATE_CODE(); - bdrv_replace_child_noperm(childp, NULL); - bdrv_child_free(*childp); + bdrv_replace_child_noperm(child, NULL); + bdrv_child_free(child); =20 if (old_bs) { /* @@ -3142,7 +3141,7 @@ void bdrv_root_unref_child(BdrvChild *child) GLOBAL_STATE_CODE(); =20 child_bs =3D child->bs; - bdrv_detach_child(&child); + bdrv_detach_child(child); bdrv_unref(child_bs); } =20 --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658868961; cv=none; d=zohomail.com; s=zohoarc; b=PVhzTNkr8u2NHpLvCUt0qfPFTX+EpEyFpDcMbJZcEDo+KacnzlZ/mjPqfcxvMxnH/W0DM+2NYS0aVOMnqNiWcnSdncv8ytsxWEXwWbVL9nu3PoMtsEH7SibIelZzzryl7S04VZkBKf3o2yKuG6ja9HKn/I0Zdniob1IqKVYWvmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658868961; 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; bh=kYZJ211LLnBilj7PnZtc8PhMA8zl+HzEJuZJUIaaKrc=; b=QjV8wLvJlWhoXoLllMGfcdIJLooh+qzsqR2Pwn14aBKOGvprJSFKSEP9vUitRplpB9DSToSMuxA9/Ka9+G86AXJRX5QjOI34aMM0y0PJZkfh4+u1yaCOVuM6OW7UjLDNoJP6ya1uF+xC3BtFDe44Pp3ORH0z0ZHdgWtuVgglYWA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658868961694675.744308191795; Tue, 26 Jul 2022 13:56:01 -0700 (PDT) Received: from localhost ([::1]:33804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGRax-0002Cg-Mk for importer@patchew.org; Tue, 26 Jul 2022 16:55:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQun-0001LN-B9; Tue, 26 Jul 2022 16:12:25 -0400 Received: from forwardcorp1j.mail.yandex.net ([5.45.199.163]:47774) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQui-0001HT-1m; Tue, 26 Jul 2022 16:12:23 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 268F12E1A75; Tue, 26 Jul 2022 23:12:10 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-C8O0Ooi9; Tue, 26 Jul 2022 23:12:08 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866328; bh=kYZJ211LLnBilj7PnZtc8PhMA8zl+HzEJuZJUIaaKrc=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=WkUVZrJRyU8AW3pVlo89u1mbu4e9a6MnMwVXmxs/Wx325N2hZbidSLEAPnZrTdmrG QMjOOH0kquvFnQPnx3+qpOyMiqoP12P7bQzSnEIe0+03KIlgq8ElSyNvRnlWDUTTNv my5KBII9jHv3gwxmANrjisSums5MzbLRvgcE6LbA= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru, John Snow Subject: [PATCH v7 13/15] block: Manipulate bs->file / bs->backing pointers in .attach/.detach Date: Tue, 26 Jul 2022 23:11:32 +0300 Message-Id: <20220726201134.924743-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=5.45.199.163; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658868963760100001 Content-Type: text/plain; charset="utf-8" bs->file and bs->backing are a kind of duplication of part of bs->children. But very useful diplication, so let's not drop them at all:) We should manage bs->file and bs->backing in same place, where we manage bs->children, to keep them in sync. Moreover, generic io paths are unprepared to BdrvChild without a bs, so it's double good to clear bs->file / bs->backing when we detach the child. Detach is simple: if we detach bs->file or bs->backing child, just set corresponding field to NULL. Attach is a bit more complicated. But we still can precisely detect should we set one of bs->file / bs->backing or not: - if role is BDRV_CHILD_COW, we definitely deal with bs->backing - else, if role is BDRV_CHILD_FILTERED (it must be also BDRV_CHILD_PRIMARY), it's a filtered child. Use bs->drv->filtered_child_is_backing to chose the pointer field to modify. - else, if role is BDRV_CHILD_PRIMARY, we deal with bs->file - in all other cases, it's neither bs->backing nor bs->file. It's some other child and we shouldn't care OK. This change brings one more good thing: we can (and should) get rid of all indirect pointers in the block-graph-change transactions: bdrv_attach_child_common() stores BdrvChild** into transaction to clear it on abort. bdrv_attach_child_common() has two callers: bdrv_attach_child_noperm() just pass-through this feature, bdrv_root_attach_child() doesn't need the feature. Look at bdrv_attach_child_noperm() callers: - bdrv_attach_child() doesn't need the feature - bdrv_set_file_or_backing_noperm() uses the feature to manage bs->file and bs->backing, we don't want it anymore - bdrv_append() uses the feature to manage bs->backing, again we don't want it anymore So, we should drop this stuff! Great! We could probably keep BdrvChild** argument to keep the int return value, but it seems not worth the complexity. Finally, we now set .file / .backing automatically in generic code and want to restring setting them by hand outside of .attach/.detach. So, this patch cleanups all remaining places where they were set. To find such places I use: git grep '\->file =3D' git grep '\->backing =3D' git grep '&.*\' git grep '&.*\' Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- block.c | 234 ++++++++++++++----------------- block/raw-format.c | 4 +- block/snapshot-access.c | 6 +- block/snapshot.c | 1 - include/block/block_int-common.h | 15 +- tests/unit/test-bdrv-drain.c | 10 +- 6 files changed, 126 insertions(+), 144 deletions(-) diff --git a/block.c b/block.c index 121affb045..3343dc5649 100644 --- a/block.c +++ b/block.c @@ -1440,9 +1440,39 @@ static void bdrv_child_cb_attach(BdrvChild *child) =20 assert_bdrv_graph_writable(bs); QLIST_INSERT_HEAD(&bs->children, child, next); - - if (child->role & BDRV_CHILD_COW) { + if (bs->drv->is_filter || (child->role & BDRV_CHILD_FILTERED)) { + /* + * Here we handle filters and block/raw-format.c when it behave li= ke + * filter. They generally have a single PRIMARY child, which is al= so the + * FILTERED child, and that they may have multiple more children, = which + * are neither PRIMARY nor FILTERED. And never we have a COW child= here. + * So bs->file will be the PRIMARY child, unless the PRIMARY child= goes + * into bs->backing on exceptional cases; and bs->backing will be + * nothing else. + */ + assert(!(child->role & BDRV_CHILD_COW)); + if (child->role & BDRV_CHILD_PRIMARY) { + assert(child->role & BDRV_CHILD_FILTERED); + assert(!bs->backing); + assert(!bs->file); + + if (bs->drv->filtered_child_is_backing) { + bs->backing =3D child; + } else { + bs->file =3D child; + } + } else { + assert(!(child->role & BDRV_CHILD_FILTERED)); + } + } else if (child->role & BDRV_CHILD_COW) { + assert(bs->drv->supports_backing); + assert(!(child->role & BDRV_CHILD_PRIMARY)); + assert(!bs->backing); + bs->backing =3D child; bdrv_backing_attach(child); + } else if (child->role & BDRV_CHILD_PRIMARY) { + assert(!bs->file); + bs->file =3D child; } =20 bdrv_apply_subtree_drain(child, bs); @@ -1460,6 +1490,12 @@ static void bdrv_child_cb_detach(BdrvChild *child) =20 assert_bdrv_graph_writable(bs); QLIST_REMOVE(child, next); + if (child =3D=3D bs->backing) { + assert(child !=3D bs->file); + bs->backing =3D NULL; + } else if (child =3D=3D bs->file) { + bs->file =3D NULL; + } } =20 static int bdrv_child_cb_update_filename(BdrvChild *c, BlockDriverState *b= ase, @@ -1665,7 +1701,7 @@ open_failed: bs->drv =3D NULL; if (bs->file !=3D NULL) { bdrv_unref_child(bs, bs->file); - bs->file =3D NULL; + assert(!bs->file); } g_free(bs->opaque); bs->opaque =3D NULL; @@ -2854,7 +2890,7 @@ static void bdrv_child_free(BdrvChild *child) } =20 typedef struct BdrvAttachChildCommonState { - BdrvChild **child; + BdrvChild *child; AioContext *old_parent_ctx; AioContext *old_child_ctx; } BdrvAttachChildCommonState; @@ -2862,33 +2898,31 @@ typedef struct BdrvAttachChildCommonState { static void bdrv_attach_child_common_abort(void *opaque) { BdrvAttachChildCommonState *s =3D opaque; - BdrvChild *child =3D *s->child; - BlockDriverState *bs =3D child->bs; + BlockDriverState *bs =3D s->child->bs; =20 GLOBAL_STATE_CODE(); - bdrv_replace_child_noperm(child, NULL); + bdrv_replace_child_noperm(s->child, NULL); =20 if (bdrv_get_aio_context(bs) !=3D s->old_child_ctx) { bdrv_try_set_aio_context(bs, s->old_child_ctx, &error_abort); } =20 - if (bdrv_child_get_parent_aio_context(child) !=3D s->old_parent_ctx) { + if (bdrv_child_get_parent_aio_context(s->child) !=3D s->old_parent_ctx= ) { GSList *ignore; =20 /* No need to ignore `child`, because it has been detached already= */ ignore =3D NULL; - child->klass->can_set_aio_ctx(child, s->old_parent_ctx, &ignore, - &error_abort); + s->child->klass->can_set_aio_ctx(s->child, s->old_parent_ctx, &ign= ore, + &error_abort); g_slist_free(ignore); =20 ignore =3D NULL; - child->klass->set_aio_ctx(child, s->old_parent_ctx, &ignore); + s->child->klass->set_aio_ctx(s->child, s->old_parent_ctx, &ignore); g_slist_free(ignore); } =20 bdrv_unref(bs); - bdrv_child_free(child); - *s->child =3D NULL; + bdrv_child_free(s->child); } =20 static TransactionActionDrv bdrv_attach_child_common_drv =3D { @@ -2899,28 +2933,22 @@ static TransactionActionDrv bdrv_attach_child_commo= n_drv =3D { /* * Common part of attaching bdrv child to bs or to blk or to job * - * Resulting new child is returned through @child. - * At start *@child must be NULL. - * @child is saved to a new entry of @tran, so that *@child could be rever= ted to - * NULL on abort(). So referenced variable must live at least until transa= ction - * end. - * * Function doesn't update permissions, caller is responsible for this. + * + * Returns new created child. */ -static int bdrv_attach_child_common(BlockDriverState *child_bs, - const char *child_name, - const BdrvChildClass *child_class, - BdrvChildRole child_role, - uint64_t perm, uint64_t shared_perm, - void *opaque, BdrvChild **child, - Transaction *tran, Error **errp) +static BdrvChild *bdrv_attach_child_common(BlockDriverState *child_bs, + const char *child_name, + const BdrvChildClass *child_cla= ss, + BdrvChildRole child_role, + uint64_t perm, uint64_t shared_= perm, + void *opaque, + Transaction *tran, Error **errp) { BdrvChild *new_child; AioContext *parent_ctx; AioContext *child_ctx =3D bdrv_get_aio_context(child_bs); =20 - assert(child); - assert(*child =3D=3D NULL); assert(child_class->get_parent_desc); GLOBAL_STATE_CODE(); =20 @@ -2962,42 +2990,35 @@ static int bdrv_attach_child_common(BlockDriverStat= e *child_bs, if (ret < 0) { error_propagate(errp, local_err); bdrv_child_free(new_child); - return ret; + return NULL; } } =20 bdrv_ref(child_bs); bdrv_replace_child_noperm(new_child, child_bs); =20 - *child =3D new_child; - BdrvAttachChildCommonState *s =3D g_new(BdrvAttachChildCommonState, 1); *s =3D (BdrvAttachChildCommonState) { - .child =3D child, + .child =3D new_child, .old_parent_ctx =3D parent_ctx, .old_child_ctx =3D child_ctx, }; tran_add(tran, &bdrv_attach_child_common_drv, s); =20 - return 0; + return new_child; } =20 /* - * Variable referenced by @child must live at least until transaction end. - * (see bdrv_attach_child_common() doc for details) - * * Function doesn't update permissions, caller is responsible for this. */ -static int bdrv_attach_child_noperm(BlockDriverState *parent_bs, - BlockDriverState *child_bs, - const char *child_name, - const BdrvChildClass *child_class, - BdrvChildRole child_role, - BdrvChild **child, - Transaction *tran, - Error **errp) +static BdrvChild *bdrv_attach_child_noperm(BlockDriverState *parent_bs, + BlockDriverState *child_bs, + const char *child_name, + const BdrvChildClass *child_cla= ss, + BdrvChildRole child_role, + Transaction *tran, + Error **errp) { - int ret; uint64_t perm, shared_perm; =20 assert(parent_bs->drv); @@ -3006,21 +3027,16 @@ static int bdrv_attach_child_noperm(BlockDriverStat= e *parent_bs, if (bdrv_recurse_has_child(child_bs, parent_bs)) { error_setg(errp, "Making '%s' a %s child of '%s' would create a cy= cle", child_bs->node_name, child_name, parent_bs->node_name); - return -EINVAL; + return NULL; } =20 bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL, perm, shared_perm, &perm, &shared_perm); =20 - ret =3D bdrv_attach_child_common(child_bs, child_name, child_class, - child_role, perm, shared_perm, parent_b= s, - child, tran, errp); - if (ret < 0) { - return ret; - } - - return 0; + return bdrv_attach_child_common(child_bs, child_name, child_class, + child_role, perm, shared_perm, parent_= bs, + tran, errp); } =20 static void bdrv_detach_child(BdrvChild *child) @@ -3065,15 +3081,16 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState = *child_bs, void *opaque, Error **errp) { int ret; - BdrvChild *child =3D NULL; + BdrvChild *child; Transaction *tran =3D tran_new(); =20 GLOBAL_STATE_CODE(); =20 - ret =3D bdrv_attach_child_common(child_bs, child_name, child_class, + child =3D bdrv_attach_child_common(child_bs, child_name, child_class, child_role, perm, shared_perm, opaque, - &child, tran, errp); - if (ret < 0) { + tran, errp); + if (!child) { + ret =3D -EINVAL; goto out; } =20 @@ -3081,11 +3098,10 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState = *child_bs, =20 out: tran_finalize(tran, ret); - /* child is unset on failure by bdrv_attach_child_common_abort() */ - assert((ret < 0) =3D=3D !child); =20 bdrv_unref(child_bs); - return child; + + return ret < 0 ? NULL : child; } =20 /* @@ -3107,14 +3123,15 @@ BdrvChild *bdrv_attach_child(BlockDriverState *pare= nt_bs, Error **errp) { int ret; - BdrvChild *child =3D NULL; + BdrvChild *child; Transaction *tran =3D tran_new(); =20 GLOBAL_STATE_CODE(); =20 - ret =3D bdrv_attach_child_noperm(parent_bs, child_bs, child_name, chil= d_class, - child_role, &child, tran, errp); - if (ret < 0) { + child =3D bdrv_attach_child_noperm(parent_bs, child_bs, child_name, + child_class, child_role, tran, errp); + if (!child) { + ret =3D -EINVAL; goto out; } =20 @@ -3125,12 +3142,10 @@ BdrvChild *bdrv_attach_child(BlockDriverState *pare= nt_bs, =20 out: tran_finalize(tran, ret); - /* child is unset on failure by bdrv_attach_child_common_abort() */ - assert((ret < 0) =3D=3D !child); =20 bdrv_unref(child_bs); =20 - return child; + return ret < 0 ? NULL : child; } =20 /* Callers must ensure that child->frozen is false. */ @@ -3272,7 +3287,6 @@ static int bdrv_set_file_or_backing_noperm(BlockDrive= rState *parent_bs, bool is_backing, Transaction *tran, Error **errp) { - int ret =3D 0; bool update_inherits_from =3D bdrv_inherits_from_recursive(child_bs, parent_bs); BdrvChild *child =3D is_backing ? parent_bs->backing : parent_bs->file; @@ -3330,14 +3344,12 @@ static int bdrv_set_file_or_backing_noperm(BlockDri= verState *parent_bs, goto out; } =20 - ret =3D bdrv_attach_child_noperm(parent_bs, child_bs, - is_backing ? "backing" : "file", - &child_of_bds, role, - is_backing ? &parent_bs->backing : - &parent_bs->file, - tran, errp); - if (ret < 0) { - return ret; + child =3D bdrv_attach_child_noperm(parent_bs, child_bs, + is_backing ? "backing" : "file", + &child_of_bds, role, + tran, errp); + if (!child) { + return -EINVAL; } =20 =20 @@ -3593,14 +3605,16 @@ int bdrv_open_file_child(const char *filename, =20 /* commit_top and mirror_top don't use this function */ assert(!parent->drv->filtered_child_is_backing); - role =3D parent->drv->is_filter ? (BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY) : BDRV_CHILD_IMAGE; =20 - parent->file =3D bdrv_open_child(filename, options, bdref_key, parent, - &child_of_bds, role, false, errp); + if (!bdrv_open_child(filename, options, bdref_key, parent, + &child_of_bds, role, false, errp)) + { + return -EINVAL; + } =20 - return parent->file ? 0 : -EINVAL; + return 0; } =20 /* @@ -4875,8 +4889,8 @@ static void bdrv_close(BlockDriverState *bs) bdrv_unref_child(bs, child); } =20 - bs->backing =3D NULL; - bs->file =3D NULL; + assert(!bs->backing); + assert(!bs->file); g_free(bs->opaque); bs->opaque =3D NULL; qatomic_set(&bs->copy_on_read, 0); @@ -5007,41 +5021,14 @@ static bool should_update_child(BdrvChild *c, Block= DriverState *to) return ret; } =20 -typedef struct BdrvRemoveFilterOrCowChild { - BdrvChild *child; - bool is_backing; -} BdrvRemoveFilterOrCowChild; - -static void bdrv_remove_filter_or_cow_child_abort(void *opaque) -{ - BdrvRemoveFilterOrCowChild *s =3D opaque; - BlockDriverState *parent_bs =3D s->child->opaque; - - if (s->is_backing) { - parent_bs->backing =3D s->child; - } else { - parent_bs->file =3D s->child; - } - - /* - * We don't have to restore child->bs here to undo bdrv_replace_child_= tran() - * because that function is transactionable and it registered own comp= letion - * entries in @tran, so .abort() for bdrv_replace_child_safe() will be - * called automatically. - */ -} - static void bdrv_remove_filter_or_cow_child_commit(void *opaque) { - BdrvRemoveFilterOrCowChild *s =3D opaque; GLOBAL_STATE_CODE(); - bdrv_child_free(s->child); + bdrv_child_free(opaque); } =20 static TransactionActionDrv bdrv_remove_filter_or_cow_child_drv =3D { - .abort =3D bdrv_remove_filter_or_cow_child_abort, .commit =3D bdrv_remove_filter_or_cow_child_commit, - .clean =3D g_free, }; =20 /* @@ -5052,8 +5039,6 @@ static void bdrv_remove_file_or_backing_child(BlockDr= iverState *bs, BdrvChild *child, Transaction *tran) { - BdrvRemoveFilterOrCowChild *s; - assert(child =3D=3D bs->backing || child =3D=3D bs->file); =20 if (!child) { @@ -5064,18 +5049,7 @@ static void bdrv_remove_file_or_backing_child(BlockD= riverState *bs, bdrv_replace_child_tran(child, NULL, tran); } =20 - s =3D g_new(BdrvRemoveFilterOrCowChild, 1); - *s =3D (BdrvRemoveFilterOrCowChild) { - .child =3D child, - .is_backing =3D (child =3D=3D bs->backing), - }; - tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, s); - - if (s->is_backing) { - bs->backing =3D NULL; - } else { - bs->file =3D NULL; - } + tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, child); } =20 /* @@ -5229,16 +5203,18 @@ int bdrv_append(BlockDriverState *bs_new, BlockDriv= erState *bs_top, Error **errp) { int ret; + BdrvChild *child; Transaction *tran =3D tran_new(); =20 GLOBAL_STATE_CODE(); =20 assert(!bs_new->backing); =20 - ret =3D bdrv_attach_child_noperm(bs_new, bs_top, "backing", - &child_of_bds, bdrv_backing_role(bs_new= ), - &bs_new->backing, tran, errp); - if (ret < 0) { + child =3D bdrv_attach_child_noperm(bs_new, bs_top, "backing", + &child_of_bds, bdrv_backing_role(bs_n= ew), + tran, errp); + if (!child) { + ret =3D -EINVAL; goto out; } =20 diff --git a/block/raw-format.c b/block/raw-format.c index 69fd650eaf..d8ca8ee3a9 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -457,8 +457,8 @@ static int raw_open(BlockDriverState *bs, QDict *option= s, int flags, file_role =3D BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY; } =20 - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - file_role, false, errp); + bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + file_role, false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/snapshot-access.c b/block/snapshot-access.c index 77b87c1946..0a30ec6cd9 100644 --- a/block/snapshot-access.c +++ b/block/snapshot-access.c @@ -82,9 +82,9 @@ static void snapshot_access_refresh_filename(BlockDriverS= tate *bs) static int snapshot_access_open(BlockDriverState *bs, QDict *options, int = flags, Error **errp) { - bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, - BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY, - false, errp); + bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY, + false, errp); if (!bs->file) { return -EINVAL; } diff --git a/block/snapshot.c b/block/snapshot.c index 75e8d3a937..f3971ac2bd 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -288,7 +288,6 @@ int bdrv_snapshot_goto(BlockDriverState *bs, =20 /* .bdrv_open() will re-attach it */ bdrv_unref_child(bs, *fallback_ptr); - *fallback_ptr =3D NULL; =20 ret =3D bdrv_snapshot_goto(fallback_bs, snapshot_id, errp); open_ret =3D drv->bdrv_open(bs, options, bs->open_flags, &local_er= r); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index d68adc6ff3..c4d8b11dbb 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -1056,9 +1056,6 @@ struct BlockDriverState { QDict *full_open_options; char exact_filename[PATH_MAX]; =20 - BdrvChild *backing; - BdrvChild *file; - /* I/O Limits */ BlockLimits bl; =20 @@ -1117,7 +1114,19 @@ struct BlockDriverState { * parent node of this node. */ BlockDriverState *inherits_from; + + /* + * @backing and @file are some of @children or NULL. All these three f= ields + * (@file, @backing and @children) are modified only in + * bdrv_child_cb_attach() and bdrv_child_cb_detach(). + * + * See also comment in include/block/block.h, to learn how backing and= file + * are connected with BdrvChildRole. + */ QLIST_HEAD(, BdrvChild) children; + BdrvChild *backing; + BdrvChild *file; + QLIST_HEAD(, BdrvChild) parents; =20 QDict *options; diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 23d425a494..4cf99edf5b 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -1808,9 +1808,8 @@ static void test_drop_intermediate_poll(void) for (i =3D 0; i < 3; i++) { if (i) { /* Takes the reference to chain[i - 1] */ - chain[i]->backing =3D bdrv_attach_child(chain[i], chain[i - 1], - "chain", &chain_child_cl= ass, - BDRV_CHILD_COW, &error_a= bort); + bdrv_attach_child(chain[i], chain[i - 1], "chain", + &chain_child_class, BDRV_CHILD_COW, &error_a= bort); } } =20 @@ -2028,9 +2027,8 @@ static void do_test_replace_child_mid_drain(int old_d= rain_count, new_child_bs->total_sectors =3D 1; =20 bdrv_ref(old_child_bs); - parent_bs->backing =3D bdrv_attach_child(parent_bs, old_child_bs, "chi= ld", - &child_of_bds, BDRV_CHILD_COW, - &error_abort); + bdrv_attach_child(parent_bs, old_child_bs, "child", &child_of_bds, + BDRV_CHILD_COW, &error_abort); =20 for (i =3D 0; i < old_drain_count; i++) { bdrv_drained_begin(old_child_bs); --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658867208; cv=none; d=zohomail.com; s=zohoarc; b=cu9fXyiCFdOs82Y0WhtNi7nUtfIJqPQZrjUk6bvGE+a7kRy3DxwMhEPdco1KqkxiYGFm9JEaHZZCRiUdlwmcw6DrBWS2kFQSSNJKFvONTvAPGeRNJ3naC+ZeXw1ZXbWRdfHb3u/+tHt4+Fc149CVpD2ig7+TX5YildlkUkNo3vk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658867208; 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; bh=sPtLArjWYB88od/2JdIUzS/SuNMzIlHO8CijWViWhOE=; b=GQn7lZWA0n2i3pB1VycXlLsT0h+9QXdR6sCfxnu+cqqYHCt/99gH3QpPEnoIIXUtBNilVZd02JQ0VFWA5mp2TZcJM3tUvJs927lNWJylLVrVp7MhyGujIC/cbjVKulG/RY/WgODB0mEQbbqL7pEZKQK7pC6k1uRbFD9IcgkNFwY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658867208600600.0778234208003; Tue, 26 Jul 2022 13:26:48 -0700 (PDT) Received: from localhost ([::1]:53390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGR8g-00080Y-5o for importer@patchew.org; Tue, 26 Jul 2022 16:26:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuk-0001Jt-4f; Tue, 26 Jul 2022 16:12:23 -0400 Received: from forwardcorp1j.mail.yandex.net ([5.45.199.163]:47792) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQui-0001Hh-1Z; Tue, 26 Jul 2022 16:12:21 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 3CE1B2E1C6A; Tue, 26 Jul 2022 23:12:11 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-CAO0JcVS; Tue, 26 Jul 2022 23:12:10 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866330; bh=sPtLArjWYB88od/2JdIUzS/SuNMzIlHO8CijWViWhOE=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=Ix4syYO3KK+qnVJ9u6lvoZJ1ZxNNoa8xjRINZCkEnJYL60VZjLZn/JjvRk7GcJN3l 0UeGNhVhO8MZXCNU8OP2aDMpowZwO6ldyEcTBsgQUcThNvNixNKIVIYcgxOO2sf0ZX 0MACpX1+r0dfeaoKOmHNiZD1voUH2Pd8M9BU77tk= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v7 14/15] block/snapshot: drop indirection around bdrv_snapshot_fallback_ptr Date: Tue, 26 Jul 2022 23:11:33 +0300 Message-Id: <20220726201134.924743-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=5.45.199.163; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658867209793100001 Content-Type: text/plain; charset="utf-8" Now the indirection is not actually used, we can safely reduce it to simple pointer. For consistency do a bit of refactoring to get rid of _ptr suffixes that become meaningless. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- block/snapshot.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/block/snapshot.c b/block/snapshot.c index f3971ac2bd..e22ac3eac6 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -151,34 +151,29 @@ bool bdrv_snapshot_find_by_id_and_name(BlockDriverSta= te *bs, } =20 /** - * Return a pointer to the child BDS pointer to which we can fall + * Return a pointer to child of given BDS to which we can fall * back if the given BDS does not support snapshots. * Return NULL if there is no BDS to (safely) fall back to. - * - * We need to return an indirect pointer because bdrv_snapshot_goto() - * has to modify the BdrvChild pointer. */ -static BdrvChild **bdrv_snapshot_fallback_ptr(BlockDriverState *bs) +static BdrvChild *bdrv_snapshot_fallback_child(BlockDriverState *bs) { - BdrvChild **fallback; - BdrvChild *child =3D bdrv_primary_child(bs); + BdrvChild *fallback =3D bdrv_primary_child(bs); + BdrvChild *child; =20 /* We allow fallback only to primary child */ - if (!child) { + if (!fallback) { return NULL; } - fallback =3D (child =3D=3D bs->file ? &bs->file : &bs->backing); - assert(*fallback =3D=3D child); =20 /* * Check that there are no other children that would need to be * snapshotted. If there are, it is not safe to fall back to - * *fallback. + * fallback. */ QLIST_FOREACH(child, &bs->children, next) { if (child->role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA | BDRV_CHILD_FILTERED) && - child !=3D *fallback) + child !=3D fallback) { return NULL; } @@ -189,8 +184,7 @@ static BdrvChild **bdrv_snapshot_fallback_ptr(BlockDriv= erState *bs) =20 static BlockDriverState *bdrv_snapshot_fallback(BlockDriverState *bs) { - BdrvChild **child_ptr =3D bdrv_snapshot_fallback_ptr(bs); - return child_ptr ? (*child_ptr)->bs : NULL; + return child_bs(bdrv_snapshot_fallback_child(bs)); } =20 int bdrv_can_snapshot(BlockDriverState *bs) @@ -237,7 +231,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs, Error **errp) { BlockDriver *drv =3D bs->drv; - BdrvChild **fallback_ptr; + BdrvChild *fallback; int ret, open_ret; =20 GLOBAL_STATE_CODE(); @@ -260,13 +254,13 @@ int bdrv_snapshot_goto(BlockDriverState *bs, return ret; } =20 - fallback_ptr =3D bdrv_snapshot_fallback_ptr(bs); - if (fallback_ptr) { + fallback =3D bdrv_snapshot_fallback_child(bs); + if (fallback) { QDict *options; QDict *file_options; Error *local_err =3D NULL; - BlockDriverState *fallback_bs =3D (*fallback_ptr)->bs; - char *subqdict_prefix =3D g_strdup_printf("%s.", (*fallback_ptr)->= name); + BlockDriverState *fallback_bs =3D fallback->bs; + char *subqdict_prefix =3D g_strdup_printf("%s.", fallback->name); =20 options =3D qdict_clone_shallow(bs->options); =20 @@ -277,8 +271,8 @@ int bdrv_snapshot_goto(BlockDriverState *bs, qobject_unref(file_options); g_free(subqdict_prefix); =20 - /* Force .bdrv_open() below to re-attach fallback_bs on *fallback_= ptr */ - qdict_put_str(options, (*fallback_ptr)->name, + /* Force .bdrv_open() below to re-attach fallback_bs on fallback */ + qdict_put_str(options, fallback->name, bdrv_get_node_name(fallback_bs)); =20 /* Now close bs, apply the snapshot on fallback_bs, and re-open bs= */ @@ -287,7 +281,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs, } =20 /* .bdrv_open() will re-attach it */ - bdrv_unref_child(bs, *fallback_ptr); + bdrv_unref_child(bs, fallback); =20 ret =3D bdrv_snapshot_goto(fallback_bs, snapshot_id, errp); open_ret =3D drv->bdrv_open(bs, options, bs->open_flags, &local_er= r); --=20 2.25.1 From nobody Thu May 16 23:42:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1658867392; cv=none; d=zohomail.com; s=zohoarc; b=EEksdLSrJOT7fxIsPBdu4eHGulTLK9n60sZMcVphSSqNy+z1owmaNGS/oC0nVRuzJvU1JHLgowIJ7IA3Q4cSONb81fI32R1aUu3BTsu2qVBKw4jLDpyHUZpp4q9QobsW4vzUJrR+mX4gsZ6ZZPfneUp84dYl+NlbisYQw60SbuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658867392; 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; bh=0TCakQ4ndmZLdd1cOsw/z2YQaMII6NoaA7Hn15EFnfQ=; b=Tko9SwYUIF+Zikv8mWJwsOg7iVdCevEsLe9wCiUUo57vh4fOEudinOq745ahp/AFOW7NP6f55uHFQ/zORjNJZPqOHKivuWkoxH/JaJDyYBvRpnUEYbiOcfGcmuSuPknJbnpWyrFFRqfOJByIslsUh6z0O2kjgpFnuyKSSDc0Xd4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658867392125458.3560691538315; Tue, 26 Jul 2022 13:29:52 -0700 (PDT) Received: from localhost ([::1]:58842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGRBe-0003NQ-Ne for importer@patchew.org; Tue, 26 Jul 2022 16:29:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQun-0001LO-CP; Tue, 26 Jul 2022 16:12:25 -0400 Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]:34600) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGQuj-0001Hq-Sn; Tue, 26 Jul 2022 16:12:23 -0400 Received: from sas1-7470331623bb.qloud-c.yandex.net (sas1-7470331623bb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bd1e:0:640:7470:3316]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 57D182E0C7C; Tue, 26 Jul 2022 23:12:12 +0300 (MSK) Received: from localhost.localdomain (172.31.44.48-vpn.dhcp.yndx.net [172.31.44.48]) by sas1-7470331623bb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZssKVYgWJm-CBO028tv; Tue, 26 Jul 2022 23:12:11 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1658866331; bh=0TCakQ4ndmZLdd1cOsw/z2YQaMII6NoaA7Hn15EFnfQ=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=i/3QNdoKJVHmiTOYc5ye5RHifw0vMtVhQIMsLnvk64M97YwLle8v0KyV6F8y5RZQA umhg3d5o3+KBqaqiuxlhAcOfAwJM+walLPjRVcbM6B9FF5ZUOze37ryAwmiLfpqLlS a/K2zzII13Z6Nvd9mkpXF7+wGgQ2R1VxipcDQpdg= Authentication-Results: sas1-7470331623bb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH v7 15/15] block: refactor bdrv_remove_file_or_backing_child to bdrv_remove_child Date: Tue, 26 Jul 2022 23:11:34 +0300 Message-Id: <20220726201134.924743-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726201134.924743-1-vsementsov@yandex-team.ru> References: <20220726201134.924743-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=77.88.29.217; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1p.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1658867393714100001 Content-Type: text/plain; charset="utf-8" Now the function can remove any child, so give it more common name. Drop assertions and drop bs argument which becomes unused. Function would be reused in a further commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- block.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/block.c b/block.c index 3343dc5649..55cff270f8 100644 --- a/block.c +++ b/block.c @@ -92,9 +92,7 @@ static bool bdrv_recurse_has_child(BlockDriverState *bs, =20 static void bdrv_replace_child_noperm(BdrvChild *child, BlockDriverState *new_bs); -static void bdrv_remove_file_or_backing_child(BlockDriverState *bs, - BdrvChild *child, - Transaction *tran); +static void bdrv_remove_child(BdrvChild *child, Transaction *tran); static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, Transaction *tran); =20 @@ -3337,7 +3335,7 @@ static int bdrv_set_file_or_backing_noperm(BlockDrive= rState *parent_bs, =20 if (child) { bdrv_unset_inherits_from(parent_bs, child, tran); - bdrv_remove_file_or_backing_child(parent_bs, child, tran); + bdrv_remove_child(child, tran); } =20 if (!child_bs) { @@ -5021,26 +5019,19 @@ static bool should_update_child(BdrvChild *c, Block= DriverState *to) return ret; } =20 -static void bdrv_remove_filter_or_cow_child_commit(void *opaque) +static void bdrv_remove_child_commit(void *opaque) { GLOBAL_STATE_CODE(); bdrv_child_free(opaque); } =20 -static TransactionActionDrv bdrv_remove_filter_or_cow_child_drv =3D { - .commit =3D bdrv_remove_filter_or_cow_child_commit, +static TransactionActionDrv bdrv_remove_child_drv =3D { + .commit =3D bdrv_remove_child_commit, }; =20 -/* - * A function to remove backing or file child of @bs. - * Function doesn't update permissions, caller is responsible for this. - */ -static void bdrv_remove_file_or_backing_child(BlockDriverState *bs, - BdrvChild *child, - Transaction *tran) +/* Function doesn't update permissions, caller is responsible for this. */ +static void bdrv_remove_child(BdrvChild *child, Transaction *tran) { - assert(child =3D=3D bs->backing || child =3D=3D bs->file); - if (!child) { return; } @@ -5049,7 +5040,7 @@ static void bdrv_remove_file_or_backing_child(BlockDr= iverState *bs, bdrv_replace_child_tran(child, NULL, tran); } =20 - tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, child); + tran_add(tran, &bdrv_remove_child_drv, child); } =20 /* @@ -5060,7 +5051,7 @@ static void bdrv_remove_file_or_backing_child(BlockDr= iverState *bs, static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, Transaction *tran) { - bdrv_remove_file_or_backing_child(bs, bdrv_filter_or_cow_child(bs), tr= an); + bdrv_remove_child(bdrv_filter_or_cow_child(bs), tran); } =20 static int bdrv_replace_node_noperm(BlockDriverState *from, --=20 2.25.1