2 * Copyright (C) 2011 STRATO AG
3 * written by Arne Jansen <sensille@gmx.net>
4 * Distributed under the GNU GPL license version 2.
11 #include "kerncompat.h"
16 * ulist is a generic data structure to hold a collection of unique u64
17 * values. The only operations it supports is adding to the list and
19 * It is possible to store an auxiliary value along with the key.
22 struct ulist_iterator
{
23 #ifdef CONFIG_BTRFS_DEBUG
26 struct list_head
*cur_list
; /* hint to start search */
33 u64 val
; /* value to store */
34 u64 aux
; /* auxiliary value saved along with the val */
36 #ifdef CONFIG_BTRFS_DEBUG
37 int seqnum
; /* sequence number this node is added */
40 struct list_head list
; /* used to link node */
41 struct rb_node rb_node
; /* used to speed up search */
46 * number of elements stored in list
50 struct list_head nodes
;
54 void ulist_init(struct ulist
*ulist
);
55 void ulist_reinit(struct ulist
*ulist
);
56 struct ulist
*ulist_alloc(gfp_t gfp_mask
);
57 void ulist_free(struct ulist
*ulist
);
58 int ulist_add(struct ulist
*ulist
, u64 val
, u64 aux
, gfp_t gfp_mask
);
59 int ulist_add_merge(struct ulist
*ulist
, u64 val
, u64 aux
,
60 u64
*old_aux
, gfp_t gfp_mask
);
62 /* just like ulist_add_merge() but take a pointer for the aux data */
63 static inline int ulist_add_merge_ptr(struct ulist
*ulist
, u64 val
, void *aux
,
64 void **old_aux
, gfp_t gfp_mask
)
66 #if BITS_PER_LONG == 32
67 u64 old64
= (uintptr_t)*old_aux
;
68 int ret
= ulist_add_merge(ulist
, val
, (uintptr_t)aux
, &old64
, gfp_mask
);
69 *old_aux
= (void *)((uintptr_t)old64
);
72 return ulist_add_merge(ulist
, val
, (u64
)aux
, (u64
*)old_aux
, gfp_mask
);
76 struct ulist_node
*ulist_next(struct ulist
*ulist
,
77 struct ulist_iterator
*uiter
);
79 #define ULIST_ITER_INIT(uiter) ((uiter)->cur_list = NULL)