Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Anand Jain <anand.jain@oracle.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2 06/11] btrfs: btrfs_recover_relocation rename ret to ret2 and err to ret
Date: Fri, 19 Apr 2024 19:12:32 +0200	[thread overview]
Message-ID: <20240419171232.GZ3492@twin.jikos.cz> (raw)
In-Reply-To: <a98d6d4d3ac16aaf0e464dfeb9551b4c141a13f0.1713370757.git.anand.jain@oracle.com>

On Thu, Apr 18, 2024 at 03:08:38PM +0800, Anand Jain wrote:
> Fix the code style for the return variable. First, rename ret to ret2,
> compile it, and then rename err to ret. This method of changing helped
> confirm that there are no instances of the old ret not renamed to ret2.

There's only one place where the ret2 would make sense.

> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> v2: no change from v1
> 
>  fs/btrfs/relocation.c | 64 +++++++++++++++++++++----------------------
>  1 file changed, 32 insertions(+), 32 deletions(-)
> 
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index bd573a0ec270..0b802d0c5a65 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -4222,8 +4222,8 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  	struct extent_buffer *leaf;
>  	struct reloc_control *rc = NULL;
>  	struct btrfs_trans_handle *trans;
> -	int ret;
> -	int err = 0;
> +	int ret2;
> +	int ret = 0;
>  
>  	path = btrfs_alloc_path();
>  	if (!path)
> @@ -4235,13 +4235,13 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  	key.offset = (u64)-1;
>  
>  	while (1) {
> -		ret = btrfs_search_slot(NULL, fs_info->tree_root, &key,
> +		ret2 = btrfs_search_slot(NULL, fs_info->tree_root, &key,
>  					path, 0, 0);
> -		if (ret < 0) {
> -			err = ret;
> +		if (ret2 < 0) {
> +			ret = ret2;

If you do just ret = ret2 then it's not needed, ret is always reset and
then is some check and 'goto out'. Using ret2 should be only for cases
where the previous value must be preserved.

>  			goto out;
>  		}
> -		if (ret > 0) {
> +		if (ret2 > 0) {
>  			if (path->slots[0] == 0)
>  				break;
>  			path->slots[0]--;
> @@ -4256,7 +4256,7 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  
>  		reloc_root = btrfs_read_tree_root(fs_info->tree_root, &key);
>  		if (IS_ERR(reloc_root)) {
> -			err = PTR_ERR(reloc_root);
> +			ret = PTR_ERR(reloc_root);
>  			goto out;
>  		}
>  
> @@ -4267,14 +4267,14 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  			fs_root = btrfs_get_fs_root(fs_info,
>  					reloc_root->root_key.offset, false);
>  			if (IS_ERR(fs_root)) {
> -				ret = PTR_ERR(fs_root);
> -				if (ret != -ENOENT) {
> -					err = ret;
> +				ret2 = PTR_ERR(fs_root);
> +				if (ret2 != -ENOENT) {
> +					ret = ret2;

Same.

>  					goto out;
>  				}
> -				ret = mark_garbage_root(reloc_root);
> -				if (ret < 0) {
> -					err = ret;
> +				ret2 = mark_garbage_root(reloc_root);
> +				if (ret2 < 0) {
> +					ret = ret2;

And here.

>  					goto out;
>  				}
>  			} else {
> @@ -4294,13 +4294,13 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  
>  	rc = alloc_reloc_control(fs_info);
>  	if (!rc) {
> -		err = -ENOMEM;
> +		ret = -ENOMEM;
>  		goto out;
>  	}
>  
> -	ret = reloc_chunk_start(fs_info);
> -	if (ret < 0) {
> -		err = ret;
> +	ret2 = reloc_chunk_start(fs_info);
> +	if (ret2 < 0) {
> +		ret = ret2;
>  		goto out_end;
>  	}
>  
> @@ -4310,7 +4310,7 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  
>  	trans = btrfs_join_transaction(rc->extent_root);
>  	if (IS_ERR(trans)) {
> -		err = PTR_ERR(trans);
> +		ret = PTR_ERR(trans);
>  		goto out_unset;
>  	}
>  
> @@ -4330,15 +4330,15 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  		fs_root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset,
>  					    false);
>  		if (IS_ERR(fs_root)) {
> -			err = PTR_ERR(fs_root);
> +			ret = PTR_ERR(fs_root);
>  			list_add_tail(&reloc_root->root_list, &reloc_roots);
>  			btrfs_end_transaction(trans);
>  			goto out_unset;
>  		}
>  
> -		err = __add_reloc_root(reloc_root);
> -		ASSERT(err != -EEXIST);
> -		if (err) {
> +		ret = __add_reloc_root(reloc_root);
> +		ASSERT(ret != -EEXIST);
> +		if (ret) {
>  			list_add_tail(&reloc_root->root_list, &reloc_roots);
>  			btrfs_put_root(fs_root);
>  			btrfs_end_transaction(trans);
> @@ -4348,8 +4348,8 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  		btrfs_put_root(fs_root);
>  	}
>  
> -	err = btrfs_commit_transaction(trans);
> -	if (err)
> +	ret = btrfs_commit_transaction(trans);
> +	if (ret)
>  		goto out_unset;
>  
>  	merge_reloc_roots(rc);
> @@ -4358,14 +4358,14 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  
>  	trans = btrfs_join_transaction(rc->extent_root);
>  	if (IS_ERR(trans)) {
> -		err = PTR_ERR(trans);
> +		ret = PTR_ERR(trans);
>  		goto out_clean;
>  	}
> -	err = btrfs_commit_transaction(trans);
> +	ret = btrfs_commit_transaction(trans);
>  out_clean:
> -	ret = clean_dirty_subvols(rc);
> -	if (ret < 0 && !err)
> -		err = ret;
> +	ret2 = clean_dirty_subvols(rc);
> +	if (ret2 < 0 && !ret)
> +		ret = ret2;

This is probably the only place where it makes sense but only because
the original code does not directly handle btrfs_commit_transaction()
and calls clean_dirty_subvols(), so the two values have to be checked.

Changing the logic here should be a separate patch so ret2 can stay
otherwise the whole function can use single ret for everything as far as
I can see.

  reply	other threads:[~2024-04-19 17:20 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
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 [this message]
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=20240419171232.GZ3492@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