Commit e3b83361 authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: remove the redundant parameter level in btrfs_bin_search()

All callers pass the eb::level so we can get read it directly inside the
btrfs_bin_search and key_search.

This is inspired by the work of Marek in U-boot.

CC: Marek Behun <marek.behun@nic.cz>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent b335eab8
...@@ -1733,9 +1733,9 @@ static noinline int generic_bin_search(struct extent_buffer *eb, ...@@ -1733,9 +1733,9 @@ static noinline int generic_bin_search(struct extent_buffer *eb,
* leaves vs nodes * leaves vs nodes
*/ */
int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key, int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key,
int level, int *slot) int *slot)
{ {
if (level == 0) if (btrfs_header_level(eb) == 0)
return generic_bin_search(eb, return generic_bin_search(eb,
offsetof(struct btrfs_leaf, items), offsetof(struct btrfs_leaf, items),
sizeof(struct btrfs_item), sizeof(struct btrfs_item),
...@@ -2502,10 +2502,10 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans, ...@@ -2502,10 +2502,10 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans,
} }
static int key_search(struct extent_buffer *b, const struct btrfs_key *key, static int key_search(struct extent_buffer *b, const struct btrfs_key *key,
int level, int *prev_cmp, int *slot) int *prev_cmp, int *slot)
{ {
if (*prev_cmp != 0) { if (*prev_cmp != 0) {
*prev_cmp = btrfs_bin_search(b, key, level, slot); *prev_cmp = btrfs_bin_search(b, key, slot);
return *prev_cmp; return *prev_cmp;
} }
...@@ -2783,7 +2783,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, ...@@ -2783,7 +2783,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
} }
} }
ret = key_search(b, key, level, &prev_cmp, &slot); ret = key_search(b, key, &prev_cmp, &slot);
if (ret < 0) if (ret < 0)
goto done; goto done;
...@@ -2947,7 +2947,7 @@ int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key, ...@@ -2947,7 +2947,7 @@ int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key,
* time. * time.
*/ */
prev_cmp = -1; prev_cmp = -1;
ret = key_search(b, key, level, &prev_cmp, &slot); ret = key_search(b, key, &prev_cmp, &slot);
if (ret < 0) if (ret < 0)
goto done; goto done;
...@@ -5103,7 +5103,7 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, ...@@ -5103,7 +5103,7 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
while (1) { while (1) {
nritems = btrfs_header_nritems(cur); nritems = btrfs_header_nritems(cur);
level = btrfs_header_level(cur); level = btrfs_header_level(cur);
sret = btrfs_bin_search(cur, min_key, level, &slot); sret = btrfs_bin_search(cur, min_key, &slot);
if (sret < 0) { if (sret < 0) {
ret = sret; ret = sret;
goto out; goto out;
......
...@@ -2552,7 +2552,7 @@ void btrfs_wait_for_snapshot_creation(struct btrfs_root *root); ...@@ -2552,7 +2552,7 @@ void btrfs_wait_for_snapshot_creation(struct btrfs_root *root);
/* ctree.c */ /* ctree.c */
int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key, int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key,
int level, int *slot); int *slot);
int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2);
int btrfs_previous_item(struct btrfs_root *root, int btrfs_previous_item(struct btrfs_root *root,
struct btrfs_path *path, u64 min_objectid, struct btrfs_path *path, u64 min_objectid,
......
...@@ -1236,7 +1236,7 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc, ...@@ -1236,7 +1236,7 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
level = btrfs_header_level(parent); level = btrfs_header_level(parent);
BUG_ON(level < lowest_level); BUG_ON(level < lowest_level);
ret = btrfs_bin_search(parent, &key, level, &slot); ret = btrfs_bin_search(parent, &key, &slot);
if (ret < 0) if (ret < 0)
break; break;
if (ret && slot > 0) if (ret && slot > 0)
...@@ -2220,8 +2220,7 @@ static int do_relocation(struct btrfs_trans_handle *trans, ...@@ -2220,8 +2220,7 @@ static int do_relocation(struct btrfs_trans_handle *trans,
if (upper->eb && !upper->locked) { if (upper->eb && !upper->locked) {
if (!lowest) { if (!lowest) {
ret = btrfs_bin_search(upper->eb, key, ret = btrfs_bin_search(upper->eb, key, &slot);
upper->level, &slot);
if (ret < 0) { if (ret < 0) {
err = ret; err = ret;
goto next; goto next;
...@@ -2259,8 +2258,7 @@ static int do_relocation(struct btrfs_trans_handle *trans, ...@@ -2259,8 +2258,7 @@ static int do_relocation(struct btrfs_trans_handle *trans,
slot = path->slots[upper->level]; slot = path->slots[upper->level];
btrfs_release_path(path); btrfs_release_path(path);
} else { } else {
ret = btrfs_bin_search(upper->eb, key, upper->level, ret = btrfs_bin_search(upper->eb, key, &slot);
&slot);
if (ret < 0) { if (ret < 0) {
err = ret; err = ret;
goto next; goto next;
......
...@@ -3816,8 +3816,7 @@ static int drop_objectid_items(struct btrfs_trans_handle *trans, ...@@ -3816,8 +3816,7 @@ static int drop_objectid_items(struct btrfs_trans_handle *trans,
found_key.offset = 0; found_key.offset = 0;
found_key.type = 0; found_key.type = 0;
ret = btrfs_bin_search(path->nodes[0], &found_key, 0, ret = btrfs_bin_search(path->nodes[0], &found_key, &start_slot);
&start_slot);
if (ret < 0) if (ret < 0)
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment