Commit 3f60f437 authored by Yangtao Li's avatar Yangtao Li Committed by David Sterba
Browse files

btrfs: use rb_find_add() in insert_block_entry()



Use the rb-tree helper so we don't open code the search and insert
code.

Signed-off-by: default avatarYangtao Li <frank.li@vivo.com>
Signed-off-by: default avatarPan Chuang <panchuang@vivo.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 4044a7ed
Loading
Loading
Loading
Loading
+10 −17
Original line number Diff line number Diff line
@@ -88,27 +88,20 @@ static int block_entry_bytenr_key_cmp(const void *key, const struct rb_node *nod
	return 0;
}

static struct block_entry *insert_block_entry(struct rb_root *root,
					      struct block_entry *be)
static int block_entry_bytenr_cmp(struct rb_node *new, const struct rb_node *existing)
{
	struct rb_node **p = &root->rb_node;
	struct rb_node *parent_node = NULL;
	struct block_entry *entry;
	const struct block_entry *new_entry = rb_entry(new, struct block_entry, node);

	while (*p) {
		parent_node = *p;
		entry = rb_entry(parent_node, struct block_entry, node);
		if (entry->bytenr > be->bytenr)
			p = &(*p)->rb_left;
		else if (entry->bytenr < be->bytenr)
			p = &(*p)->rb_right;
		else
			return entry;
	return block_entry_bytenr_key_cmp(&new_entry->bytenr, existing);
}

	rb_link_node(&be->node, parent_node, p);
	rb_insert_color(&be->node, root);
	return NULL;
static struct block_entry *insert_block_entry(struct rb_root *root,
					      struct block_entry *be)
{
	struct rb_node *node;

	node = rb_find_add(&be->node, root, block_entry_bytenr_cmp);
	return rb_entry_safe(node, struct block_entry, node);
}

static struct block_entry *lookup_block_entry(struct rb_root *root, u64 bytenr)