@@ -317,34 +317,27 @@ static int comp_refs(struct btrfs_delayed_ref_node *ref1,
return 0;
}
+static int cmp_refs_node(struct rb_node *node, const struct rb_node *node2)
+{
+ struct btrfs_delayed_ref_node *ref1;
+ struct btrfs_delayed_ref_node *ref2;
+ bool check_seq = true;
+
+ ref1 = rb_entry(node, struct btrfs_delayed_ref_node, ref_node);
+ ref2 = rb_entry(node2, struct btrfs_delayed_ref_node, ref_node);
+
+ return comp_refs(ref1, ref2, check_seq);
+}
+
static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root,
struct btrfs_delayed_ref_node *ins)
{
- struct rb_node **p = &root->rb_root.rb_node;
struct rb_node *node = &ins->ref_node;
- struct rb_node *parent_node = NULL;
- struct btrfs_delayed_ref_node *entry;
- bool leftmost = true;
-
- while (*p) {
- int comp;
-
- parent_node = *p;
- entry = rb_entry(parent_node, struct btrfs_delayed_ref_node,
- ref_node);
- comp = comp_refs(ins, entry, true);
- if (comp < 0) {
- p = &(*p)->rb_left;
- } else if (comp > 0) {
- p = &(*p)->rb_right;
- leftmost = false;
- } else {
- return entry;
- }
- }
+ struct rb_node *exist;
- rb_link_node(node, parent_node, p);
- rb_insert_color_cached(node, root, leftmost);
+ exist = rb_find_add_cached(node, root, cmp_refs_node);
+ if (exist != NULL)
+ return rb_entry(exist, struct btrfs_delayed_ref_node, ref_node);
return NULL;
}
update tree_insert() to use rb_find_add_cached(). add cmp_refs_node in rb_find_add_cached() to compare. removed const from the cmp_refs_node as it caused an error V2: incorporated changes from Filipe Manana Signed-off-by: Roger L. Beckermeyer III <beckerlee3@gmail.com> --- fs/btrfs/delayed-ref.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-)