* [PATCH v4 0/6] part3 trivial adjustments for return variable coding style
@ 2024-05-21 17:11 Anand Jain
2024-05-21 17:11 ` [PATCH v4 1/6] btrfs: rename err to ret in btrfs_cleanup_fs_roots() Anand Jain
` (6 more replies)
0 siblings, 7 replies; 10+ messages in thread
From: Anand Jain @ 2024-05-21 17:11 UTC (permalink / raw)
To: linux-btrfs; +Cc: Anand Jain
This is v4 of part 3 of the series, containing renaming with optimization of the
return variable.
v3 part3:
https://lore.kernel.org/linux-btrfs/cover.1715783315.git.anand.jain@oracle.com/
v2 part2:
https://lore.kernel.org/linux-btrfs/cover.1713370756.git.anand.jain@oracle.com/
v1:
https://lore.kernel.org/linux-btrfs/cover.1710857863.git.anand.jain@oracle.com/
Anand Jain (6):
btrfs: rename err to ret in btrfs_cleanup_fs_roots()
btrfs: rename ret to err in btrfs_recover_relocation()
btrfs: rename ret to ret2 in btrfs_recover_relocation()
btrfs: rename err to ret in btrfs_recover_relocation()
btrfs: rename err to ret in btrfs_drop_snapshot()
btrfs: rename err to ret in btrfs_find_orphan_roots()
fs/btrfs/disk-io.c | 37 ++++++++++++++--------------
fs/btrfs/extent-tree.c | 48 ++++++++++++++++++------------------
fs/btrfs/relocation.c | 56 +++++++++++++++++++-----------------------
fs/btrfs/root-tree.c | 33 +++++++++++++------------
4 files changed, 85 insertions(+), 89 deletions(-)
--
2.41.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v4 1/6] btrfs: rename err to ret in btrfs_cleanup_fs_roots()
2024-05-21 17:11 [PATCH v4 0/6] part3 trivial adjustments for return variable coding style Anand Jain
@ 2024-05-21 17:11 ` Anand Jain
2024-05-21 17:11 ` [PATCH v4 2/6] btrfs: rename ret to err in btrfs_recover_relocation() Anand Jain
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Anand Jain @ 2024-05-21 17:11 UTC (permalink / raw)
To: linux-btrfs; +Cc: Anand Jain
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>
---
v4: localize variable i in the for()
v3: Add a code comment.
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 | 37 +++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 94b95836f61f..1f744bd6b785 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2914,22 +2914,22 @@ 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 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 (int i = 0; i < found; i++) {
/* Avoid to grab roots in dead_roots. */
if (btrfs_root_refs(&gang[i]->root_item) == 0) {
gang[i] = NULL;
@@ -2940,24 +2940,25 @@ 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 (int 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;
+ /*
+ * Continue to release the remaining roots after the first
+ * error without cleanup and preserve the first error
+ * for the return.
+ */
+ if (!ret)
+ ret = btrfs_orphan_cleanup(gang[i]);
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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v4 2/6] btrfs: rename ret to err in btrfs_recover_relocation()
2024-05-21 17:11 [PATCH v4 0/6] part3 trivial adjustments for return variable coding style Anand Jain
2024-05-21 17:11 ` [PATCH v4 1/6] btrfs: rename err to ret in btrfs_cleanup_fs_roots() Anand Jain
@ 2024-05-21 17:11 ` Anand Jain
2024-05-21 17:11 ` [PATCH v4 3/6] btrfs: rename ret to ret2 " Anand Jain
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Anand Jain @ 2024-05-21 17:11 UTC (permalink / raw)
To: linux-btrfs; +Cc: Anand Jain
In the function btrfs_recover_relocation(), currently the variable 'err'
carries the return value and 'ret' holds the intermediary return value.
However, in some lines, we don't need this two-step approach; we can
directly use 'err'. So, optimize them, which requires reinitializing 'err'
to zero at two locations.
This is a preparatory patch to fix the code style by renaming 'err'
to 'ret'.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v4: title changed
v3: splits optimization part from the rename part.
fs/btrfs/relocation.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 8ce337ec033c..d0352077f0fc 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -4234,17 +4234,16 @@ 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,
+ err = btrfs_search_slot(NULL, fs_info->tree_root, &key,
path, 0, 0);
- if (ret < 0) {
- err = ret;
+ if (err < 0)
goto out;
- }
- if (ret > 0) {
+ if (err > 0) {
if (path->slots[0] == 0)
break;
path->slots[0]--;
}
+ err = 0;
leaf = path->nodes[0];
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
btrfs_release_path(path);
@@ -4266,16 +4265,13 @@ 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;
+ err = PTR_ERR(fs_root);
+ if (err != -ENOENT)
goto out;
- }
- ret = mark_garbage_root(reloc_root);
- if (ret < 0) {
- err = ret;
+ err = mark_garbage_root(reloc_root);
+ if (err < 0)
goto out;
- }
+ err = 0;
} else {
btrfs_put_root(fs_root);
}
@@ -4297,11 +4293,9 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
goto out;
}
- ret = reloc_chunk_start(fs_info);
- if (ret < 0) {
- err = ret;
+ err = reloc_chunk_start(fs_info);
+ if (err < 0)
goto out_end;
- }
rc->extent_root = btrfs_extent_root(fs_info, 0);
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v4 3/6] btrfs: rename ret to ret2 in btrfs_recover_relocation()
2024-05-21 17:11 [PATCH v4 0/6] part3 trivial adjustments for return variable coding style Anand Jain
2024-05-21 17:11 ` [PATCH v4 1/6] btrfs: rename err to ret in btrfs_cleanup_fs_roots() Anand Jain
2024-05-21 17:11 ` [PATCH v4 2/6] btrfs: rename ret to err in btrfs_recover_relocation() Anand Jain
@ 2024-05-21 17:11 ` Anand Jain
2024-05-21 17:11 ` [PATCH v4 4/6] btrfs: rename err to ret " Anand Jain
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Anand Jain @ 2024-05-21 17:11 UTC (permalink / raw)
To: linux-btrfs; +Cc: Anand Jain
A preparatory patch to rename 'err' to 'ret', but ret is already used as an
intermediary return value, so first rename 'ret' to 'ret2'.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v4: title changed
v3: new
fs/btrfs/relocation.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index d0352077f0fc..d621fdbf59f3 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -4221,7 +4221,7 @@ 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 ret2;
int err = 0;
path = btrfs_alloc_path();
@@ -4356,9 +4356,9 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
}
err = 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 && !err)
+ err = ret2;
out_unset:
unset_reloc_control(rc);
out_end:
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v4 4/6] btrfs: rename err to ret in btrfs_recover_relocation()
2024-05-21 17:11 [PATCH v4 0/6] part3 trivial adjustments for return variable coding style Anand Jain
` (2 preceding siblings ...)
2024-05-21 17:11 ` [PATCH v4 3/6] btrfs: rename ret to ret2 " Anand Jain
@ 2024-05-21 17:11 ` Anand Jain
2024-05-21 17:11 ` [PATCH v4 5/6] btrfs: rename err to ret in btrfs_drop_snapshot() Anand Jain
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Anand Jain @ 2024-05-21 17:11 UTC (permalink / raw)
To: linux-btrfs; +Cc: Anand Jain
Fix coding style: rename the return variable to 'ret' in the function
btrfs_recover_relocation instead of 'err'.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v4: title changed
v3: new
fs/btrfs/relocation.c | 56 +++++++++++++++++++++----------------------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index d621fdbf59f3..cd3f4c686e5f 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -4222,7 +4222,7 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
struct reloc_control *rc = NULL;
struct btrfs_trans_handle *trans;
int ret2;
- int err = 0;
+ int ret = 0;
path = btrfs_alloc_path();
if (!path)
@@ -4234,16 +4234,16 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
key.offset = (u64)-1;
while (1) {
- err = btrfs_search_slot(NULL, fs_info->tree_root, &key,
+ ret = btrfs_search_slot(NULL, fs_info->tree_root, &key,
path, 0, 0);
- if (err < 0)
+ if (ret < 0)
goto out;
- if (err > 0) {
+ if (ret > 0) {
if (path->slots[0] == 0)
break;
path->slots[0]--;
}
- err = 0;
+ ret = 0;
leaf = path->nodes[0];
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
btrfs_release_path(path);
@@ -4254,7 +4254,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;
}
@@ -4265,13 +4265,13 @@ 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);
- if (err != -ENOENT)
+ ret = PTR_ERR(fs_root);
+ if (ret != -ENOENT)
goto out;
- err = mark_garbage_root(reloc_root);
- if (err < 0)
+ ret = mark_garbage_root(reloc_root);
+ if (ret < 0)
goto out;
- err = 0;
+ ret = 0;
} else {
btrfs_put_root(fs_root);
}
@@ -4289,12 +4289,12 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
rc = alloc_reloc_control(fs_info);
if (!rc) {
- err = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
- err = reloc_chunk_start(fs_info);
- if (err < 0)
+ ret = reloc_chunk_start(fs_info);
+ if (ret < 0)
goto out_end;
rc->extent_root = btrfs_extent_root(fs_info, 0);
@@ -4303,7 +4303,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;
}
@@ -4323,15 +4323,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);
@@ -4341,8 +4341,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);
@@ -4351,14 +4351,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:
ret2 = clean_dirty_subvols(rc);
- if (ret2 < 0 && !err)
- err = ret2;
+ if (ret2 < 0 && !ret)
+ ret = ret2;
out_unset:
unset_reloc_control(rc);
out_end:
@@ -4369,14 +4369,14 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
btrfs_free_path(path);
- if (err == 0) {
+ if (ret == 0) {
/* cleanup orphan inode in data relocation tree */
fs_root = btrfs_grab_root(fs_info->data_reloc_root);
ASSERT(fs_root);
- err = btrfs_orphan_cleanup(fs_root);
+ ret = btrfs_orphan_cleanup(fs_root);
btrfs_put_root(fs_root);
}
- return err;
+ return ret;
}
/*
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v4 5/6] btrfs: rename err to ret in btrfs_drop_snapshot()
2024-05-21 17:11 [PATCH v4 0/6] part3 trivial adjustments for return variable coding style Anand Jain
` (3 preceding siblings ...)
2024-05-21 17:11 ` [PATCH v4 4/6] btrfs: rename err to ret " Anand Jain
@ 2024-05-21 17:11 ` Anand Jain
2024-05-21 17:11 ` [PATCH v4 6/6] btrfs: rename err to ret in btrfs_find_orphan_roots() Anand Jain
2024-05-21 18:10 ` [PATCH v4 0/6] part3 trivial adjustments for return variable coding style David Sterba
6 siblings, 0 replies; 10+ messages in thread
From: Anand Jain @ 2024-05-21 17:11 UTC (permalink / raw)
To: linux-btrfs; +Cc: Anand Jain
Drop the variable 'err', reuse the variable 'ret' by reinitializing it to
zero where necessary.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v4: Title changed.
v3: Fix comment formatting.
v2: handle return error better, no need of original 'ret'. (Josef).
fs/btrfs/extent-tree.c | 48 +++++++++++++++++++++---------------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 3774c191e36d..5aa7c8a0dbc6 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5833,8 +5833,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
struct btrfs_root_item *root_item = &root->root_item;
struct walk_control *wc;
struct btrfs_key key;
- int err = 0;
- int ret;
+ int ret = 0;
int level;
bool root_dropped = false;
bool unfinished_drop = false;
@@ -5843,14 +5842,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
path = btrfs_alloc_path();
if (!path) {
- err = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
wc = kzalloc(sizeof(*wc), GFP_NOFS);
if (!wc) {
btrfs_free_path(path);
- err = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
@@ -5863,12 +5862,12 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
else
trans = btrfs_start_transaction(tree_root, 0);
if (IS_ERR(trans)) {
- err = PTR_ERR(trans);
+ ret = PTR_ERR(trans);
goto out_free;
}
- err = btrfs_run_delayed_items(trans);
- if (err)
+ ret = btrfs_run_delayed_items(trans);
+ if (ret)
goto out_end_trans;
/*
@@ -5899,11 +5898,11 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
path->lowest_level = level;
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
path->lowest_level = 0;
- if (ret < 0) {
- err = ret;
+ if (ret < 0)
goto out_end_trans;
- }
+
WARN_ON(ret > 0);
+ ret = 0;
/*
* unlock our path, this is safe because only this
@@ -5916,14 +5915,17 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
btrfs_tree_lock(path->nodes[level]);
path->locks[level] = BTRFS_WRITE_LOCK;
+ /*
+ * btrfs_lookup_extent_info() returns 0 for success,
+ * or < 0 for error.
+ */
ret = btrfs_lookup_extent_info(trans, fs_info,
path->nodes[level]->start,
level, 1, &wc->refs[level],
&wc->flags[level], NULL);
- if (ret < 0) {
- err = ret;
+ if (ret < 0)
goto out_end_trans;
- }
+
BUG_ON(wc->refs[level] == 0);
if (level == btrfs_root_drop_level(root_item))
@@ -5949,19 +5951,18 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
ret = walk_down_tree(trans, root, path, wc);
if (ret < 0) {
btrfs_abort_transaction(trans, ret);
- err = ret;
break;
}
ret = walk_up_tree(trans, root, path, wc, BTRFS_MAX_LEVEL);
if (ret < 0) {
btrfs_abort_transaction(trans, ret);
- err = ret;
break;
}
if (ret > 0) {
BUG_ON(wc->stage != DROP_REFERENCE);
+ ret = 0;
break;
}
@@ -5983,7 +5984,6 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
root_item);
if (ret) {
btrfs_abort_transaction(trans, ret);
- err = ret;
goto out_end_trans;
}
@@ -5994,7 +5994,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
if (!for_reloc && btrfs_need_cleaner_sleep(fs_info)) {
btrfs_debug(fs_info,
"drop snapshot early exit");
- err = -EAGAIN;
+ ret = -EAGAIN;
goto out_free;
}
@@ -6008,19 +6008,18 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
else
trans = btrfs_start_transaction(tree_root, 0);
if (IS_ERR(trans)) {
- err = PTR_ERR(trans);
+ ret = PTR_ERR(trans);
goto out_free;
}
}
}
btrfs_release_path(path);
- if (err)
+ if (ret)
goto out_end_trans;
ret = btrfs_del_root(trans, &root->root_key);
if (ret) {
btrfs_abort_transaction(trans, ret);
- err = ret;
goto out_end_trans;
}
@@ -6029,10 +6028,11 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
NULL, NULL);
if (ret < 0) {
btrfs_abort_transaction(trans, ret);
- err = ret;
goto out_end_trans;
} else if (ret > 0) {
- /* if we fail to delete the orphan item this time
+ ret = 0;
+ /*
+ * If we fail to delete the orphan item this time
* around, it'll get picked up the next time.
*
* The most common failure here is just -ENOENT.
@@ -6067,7 +6067,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
* We were an unfinished drop root, check to see if there are any
* pending, and if not clear and wake up any waiters.
*/
- if (!err && unfinished_drop)
+ if (!ret && unfinished_drop)
btrfs_maybe_wake_unfinished_drop(fs_info);
/*
@@ -6079,7 +6079,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
*/
if (!for_reloc && !root_dropped)
btrfs_add_dead_root(root);
- return err;
+ return ret;
}
/*
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v4 6/6] btrfs: rename err to ret in btrfs_find_orphan_roots()
2024-05-21 17:11 [PATCH v4 0/6] part3 trivial adjustments for return variable coding style Anand Jain
` (4 preceding siblings ...)
2024-05-21 17:11 ` [PATCH v4 5/6] btrfs: rename err to ret in btrfs_drop_snapshot() Anand Jain
@ 2024-05-21 17:11 ` Anand Jain
2024-05-21 18:10 ` [PATCH v4 0/6] part3 trivial adjustments for return variable coding style David Sterba
6 siblings, 0 replies; 10+ messages in thread
From: Anand Jain @ 2024-05-21 17:11 UTC (permalink / raw)
To: linux-btrfs; +Cc: Anand Jain
The variable err is the actual return value of this function, and the
variable ret is a helper variable for err, which actually is not
needed and can be handled just by err, which is renamed to ret.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v4: Move ret = 0 under if (ret > 0)
Title changed
v3: drop ret2 as there is no need for it.
v2: n/a
fs/btrfs/root-tree.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 33962671a96c..c18915a76d9d 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -220,8 +220,7 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
struct btrfs_path *path;
struct btrfs_key key;
struct btrfs_root *root;
- int err = 0;
- int ret;
+ int ret = 0;
path = btrfs_alloc_path();
if (!path)
@@ -235,18 +234,20 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
u64 root_objectid;
ret = btrfs_search_slot(NULL, tree_root, &key, path, 0, 0);
- if (ret < 0) {
- err = ret;
+ if (ret < 0)
break;
- }
+ if (ret > 0)
+ ret = 0;
leaf = path->nodes[0];
if (path->slots[0] >= btrfs_header_nritems(leaf)) {
ret = btrfs_next_leaf(tree_root, path);
if (ret < 0)
- err = ret;
- if (ret != 0)
break;
+ if (ret > 0) {
+ ret = 0;
+ break;
+ }
leaf = path->nodes[0];
}
@@ -261,26 +262,26 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
key.offset++;
root = btrfs_get_fs_root(fs_info, root_objectid, false);
- err = PTR_ERR_OR_ZERO(root);
- if (err && err != -ENOENT) {
+ ret = PTR_ERR_OR_ZERO(root);
+ if (ret && ret != -ENOENT) {
break;
- } else if (err == -ENOENT) {
+ } else if (ret == -ENOENT) {
struct btrfs_trans_handle *trans;
btrfs_release_path(path);
trans = btrfs_join_transaction(tree_root);
if (IS_ERR(trans)) {
- err = PTR_ERR(trans);
- btrfs_handle_fs_error(fs_info, err,
+ ret = PTR_ERR(trans);
+ btrfs_handle_fs_error(fs_info, ret,
"Failed to start trans to delete orphan item");
break;
}
- err = btrfs_del_orphan_item(trans, tree_root,
+ ret = btrfs_del_orphan_item(trans, tree_root,
root_objectid);
btrfs_end_transaction(trans);
- if (err) {
- btrfs_handle_fs_error(fs_info, err,
+ if (ret) {
+ btrfs_handle_fs_error(fs_info, ret,
"Failed to delete root orphan item");
break;
}
@@ -311,7 +312,7 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
}
btrfs_free_path(path);
- return err;
+ return ret;
}
/* drop the root item for 'key' from the tree root */
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v4 0/6] part3 trivial adjustments for return variable coding style
2024-05-21 17:11 [PATCH v4 0/6] part3 trivial adjustments for return variable coding style Anand Jain
` (5 preceding siblings ...)
2024-05-21 17:11 ` [PATCH v4 6/6] btrfs: rename err to ret in btrfs_find_orphan_roots() Anand Jain
@ 2024-05-21 18:10 ` David Sterba
2024-05-23 17:18 ` David Sterba
6 siblings, 1 reply; 10+ messages in thread
From: David Sterba @ 2024-05-21 18:10 UTC (permalink / raw)
To: Anand Jain; +Cc: linux-btrfs
On Wed, May 22, 2024 at 01:11:06AM +0800, Anand Jain wrote:
> This is v4 of part 3 of the series, containing renaming with optimization of the
> return variable.
>
> v3 part3:
> https://lore.kernel.org/linux-btrfs/cover.1715783315.git.anand.jain@oracle.com/
> v2 part2:
> https://lore.kernel.org/linux-btrfs/cover.1713370756.git.anand.jain@oracle.com/
> v1:
> https://lore.kernel.org/linux-btrfs/cover.1710857863.git.anand.jain@oracle.com/
>
> Anand Jain (6):
> btrfs: rename err to ret in btrfs_cleanup_fs_roots()
> btrfs: rename ret to err in btrfs_recover_relocation()
> btrfs: rename ret to ret2 in btrfs_recover_relocation()
> btrfs: rename err to ret in btrfs_recover_relocation()
> btrfs: rename err to ret in btrfs_drop_snapshot()
> btrfs: rename err to ret in btrfs_find_orphan_roots()
1-5 look ok to me, for patch 6 there's the ret = 0 reset question sent
to v3.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v4 0/6] part3 trivial adjustments for return variable coding style
2024-05-21 18:10 ` [PATCH v4 0/6] part3 trivial adjustments for return variable coding style David Sterba
@ 2024-05-23 17:18 ` David Sterba
2024-05-24 3:09 ` Anand Jain
0 siblings, 1 reply; 10+ messages in thread
From: David Sterba @ 2024-05-23 17:18 UTC (permalink / raw)
To: David Sterba; +Cc: Anand Jain, linux-btrfs
On Tue, May 21, 2024 at 08:10:03PM +0200, David Sterba wrote:
> On Wed, May 22, 2024 at 01:11:06AM +0800, Anand Jain wrote:
> > This is v4 of part 3 of the series, containing renaming with optimization of the
> > return variable.
> >
> > v3 part3:
> > https://lore.kernel.org/linux-btrfs/cover.1715783315.git.anand.jain@oracle.com/
> > v2 part2:
> > https://lore.kernel.org/linux-btrfs/cover.1713370756.git.anand.jain@oracle.com/
> > v1:
> > https://lore.kernel.org/linux-btrfs/cover.1710857863.git.anand.jain@oracle.com/
> >
> > Anand Jain (6):
> > btrfs: rename err to ret in btrfs_cleanup_fs_roots()
> > btrfs: rename ret to err in btrfs_recover_relocation()
> > btrfs: rename ret to ret2 in btrfs_recover_relocation()
> > btrfs: rename err to ret in btrfs_recover_relocation()
> > btrfs: rename err to ret in btrfs_drop_snapshot()
> > btrfs: rename err to ret in btrfs_find_orphan_roots()
>
> 1-5 look ok to me, for patch 6 there's the ret = 0 reset question sent
> to v3.
You can add 1-5 to for-next with
Reviewed-by: David Sterba <dsterba@suse.com>
and only resend 6.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v4 0/6] part3 trivial adjustments for return variable coding style
2024-05-23 17:18 ` David Sterba
@ 2024-05-24 3:09 ` Anand Jain
0 siblings, 0 replies; 10+ messages in thread
From: Anand Jain @ 2024-05-24 3:09 UTC (permalink / raw)
To: dsterba; +Cc: linux-btrfs
On 5/24/24 01:18, David Sterba wrote:
> On Tue, May 21, 2024 at 08:10:03PM +0200, David Sterba wrote:
>> On Wed, May 22, 2024 at 01:11:06AM +0800, Anand Jain wrote:
>>> This is v4 of part 3 of the series, containing renaming with optimization of the
>>> return variable.
>>>
>>> v3 part3:
>>> https://lore.kernel.org/linux-btrfs/cover.1715783315.git.anand.jain@oracle.com/
>>> v2 part2:
>>> https://lore.kernel.org/linux-btrfs/cover.1713370756.git.anand.jain@oracle.com/
>>> v1:
>>> https://lore.kernel.org/linux-btrfs/cover.1710857863.git.anand.jain@oracle.com/
>>>
>>> Anand Jain (6):
>>> btrfs: rename err to ret in btrfs_cleanup_fs_roots()
>>> btrfs: rename ret to err in btrfs_recover_relocation()
>>> btrfs: rename ret to ret2 in btrfs_recover_relocation()
>>> btrfs: rename err to ret in btrfs_recover_relocation()
>>> btrfs: rename err to ret in btrfs_drop_snapshot()
>>> btrfs: rename err to ret in btrfs_find_orphan_roots()
>>
>> 1-5 look ok to me, for patch 6 there's the ret = 0 reset question sent
>> to v3.
>
> You can add 1-5 to for-next with
>
> Reviewed-by: David Sterba <dsterba@suse.com>
>
Pushed 1-5.
> and only resend 6.
IMO, in the patch 6, the
if (ret > 1)
ret = 0;
section is already simple and typical for the ret > 1 cases.
Could you pls check my response in v3.
Thanks, Anand
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-05-24 3:09 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-21 17:11 [PATCH v4 0/6] part3 trivial adjustments for return variable coding style Anand Jain
2024-05-21 17:11 ` [PATCH v4 1/6] btrfs: rename err to ret in btrfs_cleanup_fs_roots() Anand Jain
2024-05-21 17:11 ` [PATCH v4 2/6] btrfs: rename ret to err in btrfs_recover_relocation() Anand Jain
2024-05-21 17:11 ` [PATCH v4 3/6] btrfs: rename ret to ret2 " Anand Jain
2024-05-21 17:11 ` [PATCH v4 4/6] btrfs: rename err to ret " Anand Jain
2024-05-21 17:11 ` [PATCH v4 5/6] btrfs: rename err to ret in btrfs_drop_snapshot() Anand Jain
2024-05-21 17:11 ` [PATCH v4 6/6] btrfs: rename err to ret in btrfs_find_orphan_roots() Anand Jain
2024-05-21 18:10 ` [PATCH v4 0/6] part3 trivial adjustments for return variable coding style David Sterba
2024-05-23 17:18 ` David Sterba
2024-05-24 3:09 ` Anand Jain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox