diff mbox series

btrfs: Simplify setup_nodes_for_search

Message ID 20200527101109.7492-1-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: Simplify setup_nodes_for_search | expand

Commit Message

Nikolay Borisov May 27, 2020, 10:11 a.m. UTC
The function is needlessly convoluted. Fix that by:

* Removing redundant sret variable definition in both if arms
* Replace the again/done labels with direct return statements, the
function is short enough and doesn't do anything special upon exit.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/ctree.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

--
2.17.1

Comments

Johannes Thumshirn May 27, 2020, 12:56 p.m. UTC | #1
Highly appreciated,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
diff mbox series

Patch

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 72a3389d2d87..bd1d54e6b4cc 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -2436,55 +2436,46 @@  setup_nodes_for_search(struct btrfs_trans_handle *trans,

 	if ((p->search_for_split || ins_len > 0) && btrfs_header_nritems(b) >=
 	    BTRFS_NODEPTRS_PER_BLOCK(fs_info) - 3) {
-		int sret;

 		if (*write_lock_level < level + 1) {
 			*write_lock_level = level + 1;
 			btrfs_release_path(p);
-			goto again;
+			return -EAGAIN;
 		}

 		btrfs_set_path_blocking(p);
 		reada_for_balance(fs_info, p, level);
-		sret = split_node(trans, root, p, level);
+		ret = split_node(trans, root, p, level);
+
+		BUG_ON(ret > 0);
+		if (ret)
+			return ret;

-		BUG_ON(sret > 0);
-		if (sret) {
-			ret = sret;
-			goto done;
-		}
 		b = p->nodes[level];
 	} else if (ins_len < 0 && btrfs_header_nritems(b) <
 		   BTRFS_NODEPTRS_PER_BLOCK(fs_info) / 2) {
-		int sret;

 		if (*write_lock_level < level + 1) {
 			*write_lock_level = level + 1;
 			btrfs_release_path(p);
-			goto again;
+			return -EAGAIN;
 		}

 		btrfs_set_path_blocking(p);
 		reada_for_balance(fs_info, p, level);
-		sret = balance_level(trans, root, p, level);
+		ret = balance_level(trans, root, p, level);
+
+		if (ret)
+			return ret;

-		if (sret) {
-			ret = sret;
-			goto done;
-		}
 		b = p->nodes[level];
 		if (!b) {
 			btrfs_release_path(p);
-			goto again;
+			return -EAGAIN;
 		}
 		BUG_ON(btrfs_header_nritems(b) == 1);
 	}
 	return 0;
-
-again:
-	ret = -EAGAIN;
-done:
-	return ret;
 }

 int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path,