btrfs: remove the redundant parameter level in btrfs_bin_search()
authorQu Wenruo <wqu@suse.com>
Fri, 17 Apr 2020 07:08:21 +0000 (15:08 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 May 2020 09:25:24 +0000 (11:25 +0200)
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: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.c
fs/btrfs/ctree.h
fs/btrfs/relocation.c
fs/btrfs/tree-log.c

index bfedbbe2311fff11ed6bdd0084fcf5bd5ae1aa9f..6c28efe5b14ae10d4919a87bc5eff9f2f6de85f4 100644 (file)
@@ -1733,9 +1733,9 @@ static noinline int generic_bin_search(struct extent_buffer *eb,
  * leaves vs nodes
  */
 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,
                                          offsetof(struct btrfs_leaf, items),
                                          sizeof(struct btrfs_item),
@@ -2502,10 +2502,10 @@ done:
 }
 
 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) {
-               *prev_cmp = btrfs_bin_search(b, key, level, slot);
+               *prev_cmp = btrfs_bin_search(b, key, slot);
                return *prev_cmp;
        }
 
@@ -2783,7 +2783,7 @@ cow_done:
                        }
                }
 
-               ret = key_search(b, key, level, &prev_cmp, &slot);
+               ret = key_search(b, key, &prev_cmp, &slot);
                if (ret < 0)
                        goto done;
 
@@ -2947,7 +2947,7 @@ again:
                 * time.
                 */
                prev_cmp = -1;
-               ret = key_search(b, key, level, &prev_cmp, &slot);
+               ret = key_search(b, key, &prev_cmp, &slot);
                if (ret < 0)
                        goto done;
 
@@ -5103,7 +5103,7 @@ again:
        while (1) {
                nritems = btrfs_header_nritems(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) {
                        ret = sret;
                        goto out;
index c322568231a46aa943011a98752f568d9129377f..e4b8f5f2273d934bb93bc91e966479180dc2c8d9 100644 (file)
@@ -2552,7 +2552,7 @@ void btrfs_wait_for_snapshot_creation(struct btrfs_root *root);
 
 /* ctree.c */
 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 btrfs_previous_item(struct btrfs_root *root,
                        struct btrfs_path *path, u64 min_objectid,
index 5f8820c4eb3cc8888146b6b9edd2bdee9348bbb3..f25deca18a5d48087dfe3bcc7266687a750bfdc4 100644 (file)
@@ -1236,7 +1236,7 @@ again:
                level = btrfs_header_level(parent);
                BUG_ON(level < lowest_level);
 
-               ret = btrfs_bin_search(parent, &key, level, &slot);
+               ret = btrfs_bin_search(parent, &key, &slot);
                if (ret < 0)
                        break;
                if (ret && slot > 0)
@@ -2220,8 +2220,7 @@ static int do_relocation(struct btrfs_trans_handle *trans,
 
                if (upper->eb && !upper->locked) {
                        if (!lowest) {
-                               ret = btrfs_bin_search(upper->eb, key,
-                                                      upper->level, &slot);
+                               ret = btrfs_bin_search(upper->eb, key, &slot);
                                if (ret < 0) {
                                        err = ret;
                                        goto next;
@@ -2259,8 +2258,7 @@ static int do_relocation(struct btrfs_trans_handle *trans,
                        slot = path->slots[upper->level];
                        btrfs_release_path(path);
                } else {
-                       ret = btrfs_bin_search(upper->eb, key, upper->level,
-                                              &slot);
+                       ret = btrfs_bin_search(upper->eb, key, &slot);
                        if (ret < 0) {
                                err = ret;
                                goto next;
index 02ebdd9edc193512ba58b29002d0d53e86fa4510..0254e8d10e4a93418b7b4191d3a58654419d6d37 100644 (file)
@@ -3816,8 +3816,7 @@ static int drop_objectid_items(struct btrfs_trans_handle *trans,
 
                found_key.offset = 0;
                found_key.type = 0;
-               ret = btrfs_bin_search(path->nodes[0], &found_key, 0,
-                                      &start_slot);
+               ret = btrfs_bin_search(path->nodes[0], &found_key, &start_slot);
                if (ret < 0)
                        break;