From nobody Fri Dec 19 20:33:48 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=openvz.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1648682799629280.8480203532723; Wed, 30 Mar 2022 16:26:39 -0700 (PDT) Received: from localhost ([::1]:41082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZhi2-0004Vf-BK for importer@patchew.org; Wed, 30 Mar 2022 19:26:38 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZfsr-0007xZ-V3 for qemu-devel@nongnu.org; Wed, 30 Mar 2022 17:29:41 -0400 Received: from [2a00:1450:4864:20::136] (port=46631 helo=mail-lf1-x136.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nZfsp-0003BQ-Bu for qemu-devel@nongnu.org; Wed, 30 Mar 2022 17:29:41 -0400 Received: by mail-lf1-x136.google.com with SMTP id e16so38033585lfc.13 for ; Wed, 30 Mar 2022 14:29:38 -0700 (PDT) Received: from fedora.. ([185.215.60.153]) by smtp.gmail.com with ESMTPSA id y3-20020a056512044300b0044a9bda3242sm1057573lfk.90.2022.03.30.14.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 14:29:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VMVNYGRX8UhibZ3B/gUjYsVOd8fQvksJC2CVc0J1YI4=; b=xNjKxyodUZ37W0aZAK4rAiLiQziUpIqJmKkkyVleZUbMRxZDKkWTwJ7q9J2SMrITu8 yWqZLSPW204D9QCxFeK8daJVaYfvczLbnZQ0QhuiAhw6xrYYM6EN9Th+K12/CemT9chG Ls7Y9+e1i79V2Ja6a4sn42EITFnHf0qjQp55hK8xXl3PoRKoItQWzu/Fm+CBvACuUhcu R5NgEruySSPOAxn92ZUneAzBh1qTfUcSjprxtDnPnY5hv3ktUKrkkB07m+MvGgXlrmS1 bmROV+Sg7A1SBzFwUXednnahbPk6xp8xHOJ9uCQwfauDzK3ZjryPrYi7rly5hEQmIJft RVQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VMVNYGRX8UhibZ3B/gUjYsVOd8fQvksJC2CVc0J1YI4=; b=5T9Tq+t8JmreLBZCX15kLiN9qbB9aX6qhZ5WB6bSktZDihUy+fi9AaqUx6WwBP79v4 ICI5kvo5Iwk+lP9Idh5elFbdxmHMTsAuKDaBjAPm9S5GJtpfMTgllCQ5JEQaKY6z71eP 1+d1+ID+5naLxB2U2Htg7bAIg5JmStt1T8JNF9Hw0/VuKypVw7NxgWxBkV6i9zvXZIC7 TJC9oKISZWhWonFETlpT8HDrCXXyIEh5OUou6i5sWuHF3Jotvx3y9ZlKRGvVoz5e1EyA d7NYk3+++OPoWrahqmfRWjVFqEhWIahCsLtwtveu569pMep2wtSd/T/u0F/i1bEEZGwU Ktyg== X-Gm-Message-State: AOAM533cL9h0kXaIjTNNo8d+D3ntl763inZnw1hupiG8hyJskZ0seqPq NsKLrc5LNrRLvmBJep8hmk8jEA== X-Google-Smtp-Source: ABdhPJx4Y7+zmIIilDTh6oFMEu6Z9goagKCryoCr3wceX9jEDuevvmIHpnl/WuxXP/3bC+HEgK+U8g== X-Received: by 2002:a05:6512:322f:b0:44a:57a0:6950 with SMTP id f15-20020a056512322f00b0044a57a06950mr8684248lfe.74.1648675777630; Wed, 30 Mar 2022 14:29:37 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v5 10/45] Revert "block: Let replace_child_tran keep indirect pointer" Date: Thu, 31 Mar 2022 00:28:27 +0300 Message-Id: <20220330212902.590099-11-vsementsov@openvz.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220330212902.590099-1-vsementsov@openvz.org> References: <20220330212902.590099-1-vsementsov@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::136 (failed) 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=2a00:1450:4864:20::136; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lf1-x136.google.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 30 Mar 2022 19:17:16 -0400 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: , Cc: kwolf@redhat.com, hreitz@redhat.com, vsementsov@openvz.org, v.sementsov-og@mail.ru, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1648682801274100001 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 --- block.c | 81 +++++++-------------------------------------------------- 1 file changed, 10 insertions(+), 71 deletions(-) diff --git a/block.c b/block.c index 7f11ec4a80..258851576a 100644 --- a/block.c +++ b/block.c @@ -2334,7 +2334,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 @@ -2352,29 +2351,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); } @@ -2391,32 +2368,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 /* @@ -5041,7 +5008,6 @@ static bool should_update_child(BdrvChild *c, BlockDr= iverState *to) =20 typedef struct BdrvRemoveFilterOrCowChild { BdrvChild *child; - BlockDriverState *bs; bool is_backing; } BdrvRemoveFilterOrCowChild; =20 @@ -5071,19 +5037,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 /* @@ -5101,11 +5058,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) { @@ -5115,13 +5067,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); @@ -5147,7 +5098,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) { @@ -5165,12 +5115,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; @@ -5185,8 +5130,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, @@ -5200,7 +5143,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)); @@ -5257,9 +5199,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) { @@ -5335,7 +5274,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.35.1