From: David Sterba <dsterba@suse.cz>
To: Anand Jain <anand.jain@oracle.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2 01/11] btrfs: btrfs_cleanup_fs_roots handle ret variable
Date: Fri, 19 Apr 2024 18:51:21 +0200 [thread overview]
Message-ID: <20240419165121.GY3492@twin.jikos.cz> (raw)
In-Reply-To: <5063cdad35934623ddefe8e49c4a2c105713beb3.1713370756.git.anand.jain@oracle.com>
On Thu, Apr 18, 2024 at 03:08:33PM +0800, Anand Jain wrote:
> Since err represents the function return value, rename it as ret,
> and rename the original ret, which serves as a helper return value,
> to found. Also, optimize the code to continue call btrfs_put_root()
> for the rest of the root if even after btrfs_orphan_cleanup() returns
> error.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> v2: Rename to 'found' instead of 'ret2' (Josef).
> Call btrfs_put_root() in the while-loop, avoids use of the variable
> 'found' outside of the while loop (Qu).
> Use 'unsigned int i' instead of 'int' (Goffredo).
>
> fs/btrfs/disk-io.c | 33 +++++++++++++++------------------
> 1 file changed, 15 insertions(+), 18 deletions(-)
>
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index c2dc88f909b0..d1d23736de3c 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -2926,22 +2926,23 @@ static int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info)
> {
> u64 root_objectid = 0;
> struct btrfs_root *gang[8];
> - int i = 0;
> - int err = 0;
> - unsigned int ret = 0;
> + int ret = 0;
>
> while (1) {
> + unsigned int i;
> + unsigned int found;
> +
> spin_lock(&fs_info->fs_roots_radix_lock);
> - ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix,
> + found = radix_tree_gang_lookup(&fs_info->fs_roots_radix,
> (void **)gang, root_objectid,
> ARRAY_SIZE(gang));
> - if (!ret) {
> + if (!found) {
> spin_unlock(&fs_info->fs_roots_radix_lock);
> break;
> }
> - root_objectid = btrfs_root_id(gang[ret - 1]) + 1;
> + root_objectid = btrfs_root_id(gang[found - 1]) + 1;
>
> - for (i = 0; i < ret; i++) {
> + for (i = 0; i < found; i++) {
> /* Avoid to grab roots in dead_roots. */
> if (btrfs_root_refs(&gang[i]->root_item) == 0) {
> gang[i] = NULL;
> @@ -2952,24 +2953,20 @@ static int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info)
> }
> spin_unlock(&fs_info->fs_roots_radix_lock);
>
> - for (i = 0; i < ret; i++) {
> + for (i = 0; i < found; i++) {
> if (!gang[i])
> continue;
> root_objectid = btrfs_root_id(gang[i]);
> - err = btrfs_orphan_cleanup(gang[i]);
> - if (err)
> - goto out;
> + if (!ret)
> + ret = btrfs_orphan_cleanup(gang[i]);
Please add a comment, this is not a common pattern.
> btrfs_put_root(gang[i]);
> }
> + if (ret)
> + break;
> +
> root_objectid++;
> }
> -out:
> - /* Release the uncleaned roots due to error. */
> - for (; i < ret; i++) {
> - if (gang[i])
> - btrfs_put_root(gang[i]);
> - }
> - return err;
> + return ret;
> }
>
> /*
> --
> 2.41.0
>
next prev parent reply other threads:[~2024-04-19 16:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-18 7:08 [PATCH v2 00/11] part2 trivial adjustments for return variable coding style Anand Jain
2024-04-18 7:08 ` [PATCH v2 01/11] btrfs: btrfs_cleanup_fs_roots handle ret variable Anand Jain
2024-04-19 16:51 ` David Sterba [this message]
2024-04-18 7:08 ` [PATCH v2 02/11] btrfs: btrfs_write_marked_extents rename werr and err to ret Anand Jain
2024-04-18 7:08 ` [PATCH v2 03/11] btrfs: __btrfs_wait_marked_extents " Anand Jain
2024-04-18 7:08 ` [PATCH v2 04/11] btrfs: build_backref_tree rename err and ret " Anand Jain
2024-04-18 7:08 ` [PATCH v2 05/11] btrfs: relocate_tree_blocks reuse ret instead of err Anand Jain
2024-04-18 7:08 ` [PATCH v2 06/11] btrfs: btrfs_recover_relocation rename ret to ret2 and err to ret Anand Jain
2024-04-19 17:12 ` David Sterba
2024-04-18 7:08 ` [PATCH v2 07/11] btrfs: quick_update_accounting drop variable err Anand Jain
2024-04-18 7:08 ` [PATCH v2 08/11] btrfs: btrfs_qgroup_rescan_worker rename ret to ret2 and err to ret Anand Jain
2024-04-18 7:08 ` [PATCH v2 09/11] btrfs: lookup_extent_data_ref code optimize return Anand Jain
2024-04-18 7:08 ` [PATCH v2 10/11] btrfs: btrfs_drop_snapshot optimize return variable Anand Jain
2024-04-19 17:23 ` David Sterba
2024-04-18 7:08 ` [PATCH v2 11/11] btrfs: btrfs_drop_subtree " Anand Jain
2024-04-19 17:25 ` [PATCH v2 00/11] part2 trivial adjustments for return variable coding style David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240419165121.GY3492@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=anand.jain@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox