]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
btrfs: ulist: Add ulist_del() function.
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Mon, 20 Apr 2015 01:26:02 +0000 (09:26 +0800)
committerChris Mason <clm@fb.com>
Wed, 10 Jun 2015 16:26:17 +0000 (09:26 -0700)
This function will delete unode with given (val,aux) pair.
And with this patch, seqnum for debug usage doesn't have any meaning
now, so remove them.

This is used by later patches to skip snapshot root.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/ulist.c
fs/btrfs/ulist.h

index 840a38b2778a6e97ee013f0d2333e179c3c475e3..91feb2bdefeeb1f8849a3ae6e88fac5ec0e9701c 100644 (file)
@@ -132,6 +132,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;
@@ -197,9 +206,6 @@ int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux,
 
        node->val = val;
        node->aux = aux;
-#ifdef CONFIG_BTRFS_DEBUG
-       node->seqnum = ulist->nnodes;
-#endif
 
        ret = ulist_rbtree_insert(ulist, node);
        ASSERT(!ret);
@@ -209,6 +215,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
@@ -237,15 +270,7 @@ struct ulist_node *ulist_next(struct ulist *ulist, struct ulist_iterator *uiter)
                uiter->cur_list = uiter->cur_list->next;
        } else {
                uiter->cur_list = ulist->nodes.next;
-#ifdef CONFIG_BTRFS_DEBUG
-               uiter->i = 0;
-#endif
        }
        node = list_entry(uiter->cur_list, struct ulist_node, list);
-#ifdef CONFIG_BTRFS_DEBUG
-       ASSERT(node->seqnum == uiter->i);
-       ASSERT(uiter->i >= 0 && uiter->i < ulist->nnodes);
-       uiter->i++;
-#endif
        return node;
 }
index 4c29db604bbe135fb1bdb3743c7eee408499d25c..a01a2c45825f5c8cfa569218850acd91c3cf3e1c 100644 (file)
@@ -57,6 +57,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,