Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp463730rdh; Thu, 23 Nov 2023 08:33:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVhuHkfhDE5mgtolGB69K4luVCdJwqS7V/7VSGEeS4vOiFbwMaXsAr9bOdE1i1LhP5mxon X-Received: by 2002:a05:6a20:4424:b0:140:f6c4:aa71 with SMTP id ce36-20020a056a20442400b00140f6c4aa71mr206212pzb.8.1700757233080; Thu, 23 Nov 2023 08:33:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700757233; cv=none; d=google.com; s=arc-20160816; b=lTrbF0NwQzdWEG5xeGPdUY2Z9i8TAakY7PoQgsVubo2QcnS1yUMeWo4ULCW9nZED10 nyMlPbdEbTPfv1VSYvJL5pCUy2xw+x5l1DnfaHbLe5XCDGXovkro518b8Fh8FRGEM9aB zLcfJPtfDJY/fYEAVGN6SjGVUCFfWrEQHKlEUnVY1KjIBJZLwWigAcpOg1MqCUXmezv/ kGlpMNItJKG3GiMec+5e9bQt6O6q6FCX+1QWfjmE/RT9EIlrFpW06CcUh58aNUAcGhfv 3sFHATR4vmFoozNlrd1AV2SnpWCeL8MHbyAb6CjUlUcAPAoQQE/X7p1SF5skoQpG3ACm 9zIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=o1z+og9LArwJYNzxqWyknQRzMLUadnIH/qH4b9fiMQk=; fh=LdrTGKdg+xxk/opA2pEfgAvGU9Cc5QFnNLiLTLd+pLE=; b=x4BK38zuaqL+ajOgKjnkwcBCYLf+Szkp1WeCEH30ZGxEuNxYB0TUC4LUImfpdzLRPT ON5ImSpjOiN4MIonRZMhHNv45Sx8vecceSj67kZ7J2JjEwuL22zwAINstghNQLzKvvpE 1bBbhHXCRdbfRb/vj2R8zWGoqhKSnlrvVldRwgyBvmtdJdNsX3c8u/JfUKsjYn4Wm1jK Qlm/TRDxwZQDfNPUJOw46Sz4Bxwvk2d/LTvNQAZdHDHdpVKduWD3lkMGfVwurP1y2Rq+ pyjmSVL40mh1UJ7Y3lpCXJTz8pBc1qQDCFCEI18f+7uRioywNNcTQZ/hz69CspOgLgrw Pu/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R7VaRNNj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id b30-20020a631b5e000000b005c278ba0fe2si1618460pgm.175.2023.11.23.08.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 08:33:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R7VaRNNj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 75F8581FDBBF; Thu, 23 Nov 2023 08:33:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229756AbjKWQdf (ORCPT + 99 others); Thu, 23 Nov 2023 11:33:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbjKWQde (ORCPT ); Thu, 23 Nov 2023 11:33:34 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A1FB101 for ; Thu, 23 Nov 2023 08:33:41 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA81BC433C9; Thu, 23 Nov 2023 16:33:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700757220; bh=n7DmIwyKviz3tCYFqOWllhkhDR0sRAl71s0NV7Z8TSk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=R7VaRNNjSmeiNuEbAFBbpvbkeXmdRSpGKBuWoeJ52+3oR0uw+WcHeIK+So/SzcQ18 vAOeLiQ8BbUTAXJQTYB3uoMJtKRDOY7A8tsZv0a9KMd//dADSFgSItDyURsNt6FXEU 44G1Et2Qt1sCC8KQtPxve3TWAuEjLo687RuRHJ458JIIF3lbV5rDv3T6los1GaK9yJ jw7bqYPxHXQBmUZDahyeKog8ipWzXRUvA8hvrRhXYadDN8dv/kck6KsuEtLmp0hdUF 9Qad8xaSdUNSSnt5ozJaLza9b+9yaaAY7VGyC9ViFXBP3dpIJ0hKh0zFIvy/mooee4 CuSAbogATqWug== Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a002562bd8bso208451166b.0; Thu, 23 Nov 2023 08:33:40 -0800 (PST) X-Gm-Message-State: AOJu0Yz8ULzQQyu/qw+edWEYuGOu7OCSDyBoL6fBUN5F8dUAPgCibNsq OzkeLD/wS8hM9S97s4jpqdgEIoYt5gBhpYt+6KI= X-Received: by 2002:a17:906:100e:b0:9f2:8220:3f57 with SMTP id 14-20020a170906100e00b009f282203f57mr2347284ejm.8.1700757219251; Thu, 23 Nov 2023 08:33:39 -0800 (PST) MIME-Version: 1.0 References: <20231123-josef-generic-163-v2-0-ed1a79a8e51e@wdc.com> <20231123-josef-generic-163-v2-5-ed1a79a8e51e@wdc.com> In-Reply-To: <20231123-josef-generic-163-v2-5-ed1a79a8e51e@wdc.com> From: Filipe Manana Date: Thu, 23 Nov 2023 16:33:02 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 5/5] btrfs: reflow btrfs_free_tree_block To: Johannes Thumshirn Cc: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Naohiro Aota Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 23 Nov 2023 08:33:50 -0800 (PST) On Thu, Nov 23, 2023 at 3:48=E2=80=AFPM Johannes Thumshirn wrote: > > Reflow btrfs_free_tree_block() so that there is one level of indentation > needed. > > This patch has no functional changes. > > Reviewed-by: Christoph Hellwig > Reviewed-by: Josef Bacik > Signed-off-by: Johannes Thumshirn > --- > fs/btrfs/extent-tree.c | 97 +++++++++++++++++++++++++-------------------= ------ > 1 file changed, 49 insertions(+), 48 deletions(-) > > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c > index 4044102271e9..093aaf7aeb3a 100644 > --- a/fs/btrfs/extent-tree.c > +++ b/fs/btrfs/extent-tree.c > @@ -3426,6 +3426,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handl= e *trans, > { > struct btrfs_fs_info *fs_info =3D trans->fs_info; > struct btrfs_ref generic_ref =3D { 0 }; > + struct btrfs_block_group *cache; While at it, can we rename 'cache' to something like 'bg'? The cache name comes from the times where the structure was named btrfs_block_group_cache, and having it named cache is always confusing. Nevertheless, the change looks fine to me. Reviewed-by: Filipe Manana > int ret; > > btrfs_init_generic_ref(&generic_ref, BTRFS_DROP_DELAYED_REF, > @@ -3439,64 +3440,64 @@ void btrfs_free_tree_block(struct btrfs_trans_han= dle *trans, > BUG_ON(ret); /* -ENOMEM */ > } > > - if (last_ref && btrfs_header_generation(buf) =3D=3D trans->transi= d) { > - struct btrfs_block_group *cache; > - bool must_pin =3D false; > - > - if (root_id !=3D BTRFS_TREE_LOG_OBJECTID) { > - ret =3D check_ref_cleanup(trans, buf->start); > - if (!ret) > - goto out; > - } > + if (!last_ref) > + return; > > - cache =3D btrfs_lookup_block_group(fs_info, buf->start); > + if (btrfs_header_generation(buf) !=3D trans->transid) > + goto out; > > - if (btrfs_header_flag(buf, BTRFS_HEADER_FLAG_WRITTEN)) { > - pin_down_extent(trans, cache, buf->start, buf->le= n, 1); > - btrfs_put_block_group(cache); > + if (root_id !=3D BTRFS_TREE_LOG_OBJECTID) { > + ret =3D check_ref_cleanup(trans, buf->start); > + if (!ret) > goto out; > - } > + } > > - /* > - * If there are tree mod log users we may have recorded m= od log > - * operations for this node. If we re-allocate this node= we > - * could replay operations on this node that happened whe= n it > - * existed in a completely different root. For example i= f it > - * was part of root A, then was reallocated to root B, an= d we > - * are doing a btrfs_old_search_slot(root b), we could re= play > - * operations that happened when the block was part of ro= ot A, > - * giving us an inconsistent view of the btree. > - * > - * We are safe from races here because at this point no o= ther > - * node or root points to this extent buffer, so if after= this > - * check a new tree mod log user joins we will not have a= n > - * existing log of operations on this node that we have t= o > - * contend with. > - */ > - if (test_bit(BTRFS_FS_TREE_MOD_LOG_USERS, &fs_info->flags= )) > - must_pin =3D true; > + cache =3D btrfs_lookup_block_group(fs_info, buf->start); > > - if (must_pin || btrfs_is_zoned(fs_info)) { > - pin_down_extent(trans, cache, buf->start, buf->le= n, 1); > - btrfs_put_block_group(cache); > - goto out; > - } > + if (btrfs_header_flag(buf, BTRFS_HEADER_FLAG_WRITTEN)) { > + pin_down_extent(trans, cache, buf->start, buf->len, 1); > + btrfs_put_block_group(cache); > + goto out; > + } > > - WARN_ON(test_bit(EXTENT_BUFFER_DIRTY, &buf->bflags)); > + /* > + * If there are tree mod log users we may have recorded mod log > + * operations for this node. If we re-allocate this node we > + * could replay operations on this node that happened when it > + * existed in a completely different root. For example if it > + * was part of root A, then was reallocated to root B, and we > + * are doing a btrfs_old_search_slot(root b), we could replay > + * operations that happened when the block was part of root A, > + * giving us an inconsistent view of the btree. > + * > + * We are safe from races here because at this point no other > + * node or root points to this extent buffer, so if after this > + * check a new tree mod log user joins we will not have an > + * existing log of operations on this node that we have to > + * contend with. > + */ > > - btrfs_add_free_space(cache, buf->start, buf->len); > - btrfs_free_reserved_bytes(cache, buf->len, 0); > + if (test_bit(BTRFS_FS_TREE_MOD_LOG_USERS, &fs_info->flags) > + || btrfs_is_zoned(fs_info)) { > + pin_down_extent(trans, cache, buf->start, buf->len, 1); > btrfs_put_block_group(cache); > - trace_btrfs_reserved_extent_free(fs_info, buf->start, buf= ->len); > + goto out; > } > + > + WARN_ON(test_bit(EXTENT_BUFFER_DIRTY, &buf->bflags)); > + > + btrfs_add_free_space(cache, buf->start, buf->len); > + btrfs_free_reserved_bytes(cache, buf->len, 0); > + btrfs_put_block_group(cache); > + trace_btrfs_reserved_extent_free(fs_info, buf->start, buf->len); > + > out: > - if (last_ref) { > - /* > - * Deleting the buffer, clear the corrupt flag since it d= oesn't > - * matter anymore. > - */ > - clear_bit(EXTENT_BUFFER_CORRUPT, &buf->bflags); > - } > + > + /* > + * Deleting the buffer, clear the corrupt flag since it doesn't > + * matter anymore. > + */ > + clear_bit(EXTENT_BUFFER_CORRUPT, &buf->bflags); > } > > /* Can return -ENOMEM */ > > -- > 2.41.0 > >