@@ -104,53 +104,61 @@ static struct rb_node *tree_insert(struct rb_root *root, u64 offset,
return NULL;
}
-/*
- * search through the tree for an extent_map with a given offset. If
- * it can't be found, try to find some neighboring extents
+/**
+ * __tree_search - Search for an extent_map with the given offset.
+ * @root: The root of the tree to search.
+ * @offset: Offset in bytes to search for.
+ * @prev_ret: extent_map before the given offset.
+ * @next_ret: extent_map after the given offset.
+ *
+ * Search through the tree for an extent_map with a given offset. If
+ * it can't be found, try to find some neighboring extents.
*/
static struct rb_node *__tree_search(struct rb_root *root, u64 offset,
struct rb_node **prev_ret,
struct rb_node **next_ret)
{
- struct rb_node *n = root->rb_node;
- struct rb_node *prev = NULL;
- struct rb_node *orig_prev = NULL;
- struct extent_map *entry;
- struct extent_map *prev_entry = NULL;
+ struct rb_node *node = root->rb_node;
+ struct rb_node *prev_node = NULL;
+ struct extent_map *entry = NULL;
- while (n) {
- entry = rb_entry(n, struct extent_map, rb_node);
- prev = n;
- prev_entry = entry;
+ /* Search for an extent map with the given offset. */
+ while (node) {
+ entry = rb_entry(node, struct extent_map, rb_node);
+ prev_node = node;
WARN_ON(!entry->in_tree);
if (offset < entry->start)
- n = n->rb_left;
+ node = node->rb_left;
else if (offset >= extent_map_end(entry))
- n = n->rb_right;
+ node = node->rb_right;
else
- return n;
+ return node;
}
+ /* Search for an extent map before the given offset. */
if (prev_ret) {
- orig_prev = prev;
- while (prev && offset >= extent_map_end(prev_entry)) {
- prev = rb_next(prev);
- prev_entry = rb_entry(prev, struct extent_map, rb_node);
+ node = prev_node;
+ while (node && offset >= extent_map_end(entry)) {
+ node = rb_next(node);
+ entry = rb_entry(node, struct extent_map, rb_node);
}
- *prev_ret = prev;
- prev = orig_prev;
+ *prev_ret = node;
}
+ /* Search for an extent map after the given offset. */
if (next_ret) {
- prev_entry = rb_entry(prev, struct extent_map, rb_node);
- while (prev && offset < prev_entry->start) {
- prev = rb_prev(prev);
- prev_entry = rb_entry(prev, struct extent_map, rb_node);
+ node = prev_node;
+ entry = rb_entry(node, struct extent_map, rb_node);
+ while (node && offset < entry->start) {
+ node = rb_prev(node);
+ entry = rb_entry(node, struct extent_map, rb_node);
}
- *next_ret = prev;
+ *next_ret = node;
}
+
+ /* None found. */
return NULL;
}