* [PATCH v2] btrfs: Simplify setup_nodes_for_search
@ 2020-11-13 7:29 Nikolay Borisov
2020-11-13 18:25 ` Josef Bacik
2020-11-16 15:47 ` David Sterba
0 siblings, 2 replies; 3+ messages in thread
From: Nikolay Borisov @ 2020-11-13 7:29 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>
---
V2:
- Initialize ret to 0 by default in case we don't hit any of the branch conditions
and simply exit.
fs/btrfs/ctree.c | 30 ++++++++----------------------
1 file changed, 8 insertions(+), 22 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 892b467347a3..5de33cd85cac 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -2390,56 +2390,42 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans,
int *write_lock_level)
{
struct btrfs_fs_info *fs_info = root->fs_info;
- int ret;
+ int ret = 0;
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] 3+ messages in thread
* Re: [PATCH v2] btrfs: Simplify setup_nodes_for_search
2020-11-13 7:29 [PATCH v2] btrfs: Simplify setup_nodes_for_search Nikolay Borisov
@ 2020-11-13 18:25 ` Josef Bacik
2020-11-16 15:47 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: Josef Bacik @ 2020-11-13 18:25 UTC (permalink / raw)
To: Nikolay Borisov, linux-btrfs
On 11/13/20 2:29 AM, Nikolay Borisov wrote:
> 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>
> ---
>
> V2:
> - Initialize ret to 0 by default in case we don't hit any of the branch conditions
> and simply exit.
>
> fs/btrfs/ctree.c | 30 ++++++++----------------------
> 1 file changed, 8 insertions(+), 22 deletions(-)
>
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index 892b467347a3..5de33cd85cac 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -2390,56 +2390,42 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans,
> int *write_lock_level)
> {
> struct btrfs_fs_info *fs_info = root->fs_info;
> - int ret;
> + int ret = 0;
>
> 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];
While you're cleaning up you could delete this line as well.
> } 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);
And change this to ASSERT(). Thanks,
Josef
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] btrfs: Simplify setup_nodes_for_search
2020-11-13 7:29 [PATCH v2] btrfs: Simplify setup_nodes_for_search Nikolay Borisov
2020-11-13 18:25 ` Josef Bacik
@ 2020-11-16 15:47 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2020-11-16 15:47 UTC (permalink / raw)
To: Nikolay Borisov; +Cc: linux-btrfs
On Fri, Nov 13, 2020 at 09:29:40AM +0200, Nikolay Borisov wrote:
> 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>
Added to misc-next, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-16 15:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13 7:29 [PATCH v2] btrfs: Simplify setup_nodes_for_search Nikolay Borisov
2020-11-13 18:25 ` Josef Bacik
2020-11-16 15:47 ` David Sterba
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.