summaryrefslogtreecommitdiff
path: root/fs/btrfs/extent_io.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2020-06-25 18:49:39 +0200
committerDavid Sterba <dsterba@suse.com>2022-07-25 17:45:35 +0200
commitec60c76f532f94081d2605b77101246073a9ae6f (patch)
tree54f9d35ab83421a3bbb98d5a52820bf2b9fce00a /fs/btrfs/extent_io.c
parentbebb22c13dc147aa80cd5c9d397d286f133fabb1 (diff)
btrfs: make tree search for insert more generic and use it for tree_search
With a slight extension of tree_search_for_insert (fill the return node and parent return parameters) we can avoid calling __etree_search from tree_search, that could be removed eventually in followup patches. Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/extent_io.c')
-rw-r--r--fs/btrfs/extent_io.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index ee84474fcf7e..a80b7e7e23f4 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -444,20 +444,6 @@ tree_search_for_insert(struct extent_io_tree *tree,
struct rb_node ***p_ret,
struct rb_node **parent_ret)
{
- struct rb_node *next= NULL;
- struct rb_node *ret;
-
- ret = __etree_search(tree, offset, &next, NULL, p_ret, parent_ret);
- if (!ret)
- return next;
- return ret;
-}
-
-/*
- * Inexact rb-tree search, return the next entry if @offset is not found
- */
-static inline struct rb_node *tree_search(struct extent_io_tree *tree, u64 offset)
-{
struct rb_root *root = &tree->state;
struct rb_node **node = &root->rb_node;
struct rb_node *prev = NULL;
@@ -475,6 +461,11 @@ static inline struct rb_node *tree_search(struct extent_io_tree *tree, u64 offse
return *node;
}
+ if (p_ret)
+ *p_ret = node;
+ if (parent_ret)
+ *parent_ret = prev;
+
/* Search neighbors until we find the first one past the end */
while (prev && offset > entry->end) {
prev = rb_next(prev);
@@ -485,6 +476,14 @@ static inline struct rb_node *tree_search(struct extent_io_tree *tree, u64 offse
}
/*
+ * Inexact rb-tree search, return the next entry if @offset is not found
+ */
+static inline struct rb_node *tree_search(struct extent_io_tree *tree, u64 offset)
+{
+ return tree_search_for_insert(tree, offset, NULL, NULL);
+}
+
+/*
* utility function to look for merge candidates inside a given range.
* Any extents with matching state are merged together into a single
* extent in the tree. Extents with EXTENT_IO in their state field