Skip to content

Commit

Permalink
btrfs: Simplify setup_nodes_for_search
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lorddoskias authored and intel-lab-lkp committed Nov 12, 2020
1 parent a123150 commit aea2237
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions fs/btrfs/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit aea2237

Please sign in to comment.