mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-04 02:34:10 -04:00
btrfs: update __btrfs_add_delayed_item() to use rb helper
Update __btrfs_add_delayed_item() to use rb_find_add_cached(). Signed-off-by: Roger L. Beckermeyer III <beckerlee3@gmail.com> Reviewed-by: Qu Wenruo <wqu@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>
This commit is contained in:
committed by
David Sterba
parent
14ae60c712
commit
0877597dc3
@@ -366,40 +366,35 @@ static struct btrfs_delayed_item *__btrfs_lookup_delayed_item(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int btrfs_delayed_item_cmp(const struct rb_node *new,
|
||||
const struct rb_node *exist)
|
||||
{
|
||||
const struct btrfs_delayed_item *new_item =
|
||||
rb_entry(new, struct btrfs_delayed_item, rb_node);
|
||||
const struct btrfs_delayed_item *exist_item =
|
||||
rb_entry(exist, struct btrfs_delayed_item, rb_node);
|
||||
|
||||
if (new_item->index < exist_item->index)
|
||||
return -1;
|
||||
if (new_item->index > exist_item->index)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node,
|
||||
struct btrfs_delayed_item *ins)
|
||||
{
|
||||
struct rb_node **p, *node;
|
||||
struct rb_node *parent_node = NULL;
|
||||
struct rb_root_cached *root;
|
||||
struct btrfs_delayed_item *item;
|
||||
bool leftmost = true;
|
||||
struct rb_node *exist;
|
||||
|
||||
if (ins->type == BTRFS_DELAYED_INSERTION_ITEM)
|
||||
root = &delayed_node->ins_root;
|
||||
else
|
||||
root = &delayed_node->del_root;
|
||||
|
||||
p = &root->rb_root.rb_node;
|
||||
node = &ins->rb_node;
|
||||
|
||||
while (*p) {
|
||||
parent_node = *p;
|
||||
item = rb_entry(parent_node, struct btrfs_delayed_item,
|
||||
rb_node);
|
||||
|
||||
if (item->index < ins->index) {
|
||||
p = &(*p)->rb_right;
|
||||
leftmost = false;
|
||||
} else if (item->index > ins->index) {
|
||||
p = &(*p)->rb_left;
|
||||
} else {
|
||||
return -EEXIST;
|
||||
}
|
||||
}
|
||||
|
||||
rb_link_node(node, parent_node, p);
|
||||
rb_insert_color_cached(node, root, leftmost);
|
||||
exist = rb_find_add_cached(&ins->rb_node, root, btrfs_delayed_item_cmp);
|
||||
if (exist)
|
||||
return -EEXIST;
|
||||
|
||||
if (ins->type == BTRFS_DELAYED_INSERTION_ITEM &&
|
||||
ins->index >= delayed_node->index_cnt)
|
||||
|
||||
Reference in New Issue
Block a user