All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH] btrfs: Simplify setup_nodes_for_search
Date: Wed, 27 May 2020 13:11:09 +0300	[thread overview]
Message-ID: <20200527101109.7492-1-nborisov@suse.com> (raw)

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


             reply	other threads:[~2020-05-27 10:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-27 10:11 Nikolay Borisov [this message]
2020-05-27 12:56 ` [PATCH] btrfs: Simplify setup_nodes_for_search Johannes Thumshirn
2020-11-12 11:16 Nikolay Borisov
2020-11-12 12:17 ` Johannes Thumshirn
2020-11-13  3:30 ` kernel test robot
2020-11-13  3:30   ` kernel test robot
2020-11-13  5:06 ` kernel test robot
2020-11-13  5:06   ` kernel test robot

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=20200527101109.7492-1-nborisov@suse.com \
    --to=nborisov@suse.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.