mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-11 03:31:17 +00:00
btrfs-progs: shared: copy ulist_del from kernel
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
886a8565e0
commit
4049542d4f
@ -134,6 +134,15 @@ static struct ulist_node *ulist_rbtree_search(struct ulist *ulist, u64 val)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ulist_rbtree_erase(struct ulist *ulist, struct ulist_node *node)
|
||||
{
|
||||
rb_erase(&node->rb_node, &ulist->root);
|
||||
list_del(&node->list);
|
||||
kfree(node);
|
||||
BUG_ON(ulist->nnodes == 0);
|
||||
ulist->nnodes--;
|
||||
}
|
||||
|
||||
static int ulist_rbtree_insert(struct ulist *ulist, struct ulist_node *ins)
|
||||
{
|
||||
struct rb_node **p = &ulist->root.rb_node;
|
||||
@ -211,6 +220,33 @@ int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* ulist_del - delete one node from ulist
|
||||
* @ulist: ulist to remove node from
|
||||
* @val: value to delete
|
||||
* @aux: aux to delete
|
||||
*
|
||||
* The deletion will only be done when *BOTH* val and aux matches.
|
||||
* Return 0 for successful delete.
|
||||
* Return > 0 for not found.
|
||||
*/
|
||||
int ulist_del(struct ulist *ulist, u64 val, u64 aux)
|
||||
{
|
||||
struct ulist_node *node;
|
||||
|
||||
node = ulist_rbtree_search(ulist, val);
|
||||
/* Not found */
|
||||
if (!node)
|
||||
return 1;
|
||||
|
||||
if (node->aux != aux)
|
||||
return 1;
|
||||
|
||||
/* Found and delete */
|
||||
ulist_rbtree_erase(ulist, node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* ulist_next - iterate ulist
|
||||
* @ulist: ulist to iterate
|
||||
|
@ -58,6 +58,7 @@ void ulist_free(struct ulist *ulist);
|
||||
int ulist_add(struct ulist *ulist, u64 val, u64 aux, gfp_t gfp_mask);
|
||||
int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux,
|
||||
u64 *old_aux, gfp_t gfp_mask);
|
||||
int ulist_del(struct ulist *ulist, u64 val, u64 aux);
|
||||
|
||||
/* just like ulist_add_merge() but take a pointer for the aux data */
|
||||
static inline int ulist_add_merge_ptr(struct ulist *ulist, u64 val, void *aux,
|
||||
|
Loading…
Reference in New Issue
Block a user