@@ -854,7 +854,8 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
* Search for a key in the given extent_buffer.
*
* The lower boundary for the search is specified by the slot number @first_slot.
- * Use a value of 0 to search over the whole extent buffer.
+ * Use a value of 0 to search over the whole extent buffer. Works for both
+ * leaves and nodes.
*
* The slot in the extent buffer is returned via @slot. If the key exists in the
* extent buffer, then @slot will point to the slot where the key is, otherwise
@@ -1860,11 +1861,12 @@ static inline int search_for_key_slot(struct extent_buffer *eb,
int *slot)
{
/*
- * If a previous call to btrfs_bin_search() on a parent node returned an
- * exact match (prev_cmp == 0), we can safely assume the target key will
- * always be at slot 0 on lower levels, since each key pointer
- * (struct btrfs_key_ptr) refers to the lowest key accessible from the
- * subtree it points to. Thus we can skip searching lower levels.
+ * If a previous call to btrfs_generic_bin_search() on a parent node
+ * returned an exact match (prev_cmp == 0), we can safely assume the
+ * target key will always be at slot 0 on lower levels, since each key
+ * pointer (struct btrfs_key_ptr) refers to the lowest key accessible
+ * from the subtree it points to. Thus we can skip searching lower
+ * levels.
*/
if (prev_cmp == 0) {
*slot = 0;
@@ -1953,8 +1955,8 @@ static int search_leaf(struct btrfs_trans_handle *trans,
btrfs_unlock_up_safe(path, 1);
/*
* ret is already 0 or 1, matching the result of
- * a btrfs_bin_search() call, so there is no need
- * to adjust it.
+ * a btrfs_generic_bin_search() call, so there
+ * is no need to adjust it.
*/
do_bin_search = false;
path->slots[0] = 0;
@@ -2328,7 +2330,7 @@ int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key,
*/
btrfs_unlock_up_safe(p, level + 1);
- ret = btrfs_bin_search(b, key, &slot);
+ ret = btrfs_generic_bin_search(b, 0, key, &slot);
if (ret < 0)
goto done;
@@ -4575,7 +4577,7 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
while (1) {
nritems = btrfs_header_nritems(cur);
level = btrfs_header_level(cur);
- sret = btrfs_bin_search(cur, min_key, &slot);
+ sret = btrfs_generic_bin_search(cur, 0, min_key, &slot);
if (sret < 0) {
ret = sret;
goto out;
@@ -511,19 +511,6 @@ void __cold btrfs_ctree_exit(void);
int btrfs_generic_bin_search(struct extent_buffer *eb, int first_slot,
const struct btrfs_key *key, int *slot);
-/*
- * Simple binary search on an extent buffer. Works for both leaves and nodes, and
- * always searches over the whole range of keys (slot 0 to slot 'nritems - 1').
- */
-static inline int btrfs_bin_search(struct extent_buffer *eb,
- const struct btrfs_key *key,
- int *slot)
-{
- return btrfs_generic_bin_search(eb, 0, key, slot);
-}
-
-int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key,
- 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,
@@ -1266,7 +1266,7 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
level = btrfs_header_level(parent);
ASSERT(level >= lowest_level);
- ret = btrfs_bin_search(parent, &key, &slot);
+ ret = btrfs_generic_bin_search(parent, 0, &key, &slot);
if (ret < 0)
break;
if (ret && slot > 0)
@@ -2407,7 +2407,8 @@ static int do_relocation(struct btrfs_trans_handle *trans,
if (upper->eb && !upper->locked) {
if (!lowest) {
- ret = btrfs_bin_search(upper->eb, key, &slot);
+ ret = btrfs_generic_bin_search(upper->eb, 0,
+ key, &slot);
if (ret < 0)
goto next;
BUG_ON(ret);
@@ -2441,7 +2442,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, &slot);
+ ret = btrfs_generic_bin_search(upper->eb, 0, key, &slot);
if (ret < 0)
goto next;
BUG_ON(ret);
@@ -4099,7 +4099,8 @@ static int drop_inode_items(struct btrfs_trans_handle *trans,
found_key.offset = 0;
found_key.type = 0;
- ret = btrfs_bin_search(path->nodes[0], &found_key, &start_slot);
+ ret = btrfs_generic_bin_search(path->nodes[0], 0, &found_key,
+ &start_slot);
if (ret < 0)
break;
btrfs_bin_search() is a simple wrapper that searches for the whole slots by calling btrfs_generic_bin_search() with the starting slot/first_slot preset to 0. This simple wrapper can be opencoded. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- v3: Title changed from (btrfs: make btrfs_bin_search a macro) Opencode instead of macro-ing. Dave, I think opencode is what you meant in the review comments. If not, I didn't quite get what you implied. Thx. v2: remove extra ; for define fs/btrfs/ctree.c | 22 ++++++++++++---------- fs/btrfs/ctree.h | 13 ------------- fs/btrfs/relocation.c | 7 ++++--- fs/btrfs/tree-log.c | 3 ++- 4 files changed, 18 insertions(+), 27 deletions(-)