linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: Simplify setup_nodes_for_search
@ 2020-11-12 11:16 Nikolay Borisov
  2020-11-12 12:17 ` Johannes Thumshirn
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Nikolay Borisov @ 2020-11-12 11:16 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Nikolay Borisov

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.

* Remove BUG_ON on split_node returning a positive number - it can't
  happen as split_node returns either 0 or a negative error code.

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

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 892b467347a3..6c309dfee3f5 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -2394,52 +2394,38 @@ 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;
 		}
 
 		reada_for_balance(p, level);
-		sret = split_node(trans, root, p, level);
+		ret = split_node(trans, root, p, level);
 
-		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;
 		}
 
 		reada_for_balance(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;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH] btrfs: Simplify setup_nodes_for_search
@ 2020-05-27 10:11 Nikolay Borisov
  2020-05-27 12:56 ` Johannes Thumshirn
  0 siblings, 1 reply; 6+ messages in thread
From: Nikolay Borisov @ 2020-05-27 10:11 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Nikolay Borisov

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(-)

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,
--
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-11-13  5:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-12 11:16 [PATCH] btrfs: Simplify setup_nodes_for_search Nikolay Borisov
2020-11-12 12:17 ` Johannes Thumshirn
2020-11-13  3:30 ` kernel test robot
2020-11-13  5:06 ` kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2020-05-27 10:11 Nikolay Borisov
2020-05-27 12:56 ` Johannes Thumshirn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).