1
2
3
4
5
6
7
8#ifndef __ULIST__
9#define __ULIST__
10
11#include <linux/list.h>
12#include <linux/rbtree.h>
13
14
15
16
17
18
19
20
21struct ulist_iterator {
22#ifdef CONFIG_BTRFS_DEBUG
23 int i;
24#endif
25 struct list_head *cur_list;
26};
27
28
29
30
31struct ulist_node {
32 u64 val;
33 u64 aux;
34
35#ifdef CONFIG_BTRFS_DEBUG
36 int seqnum;
37#endif
38
39 struct list_head list;
40 struct rb_node rb_node;
41};
42
43struct ulist {
44
45
46
47 unsigned long nnodes;
48
49 struct list_head nodes;
50 struct rb_root root;
51};
52
53void ulist_init(struct ulist *ulist);
54void ulist_reinit(struct ulist *ulist);
55struct ulist *ulist_alloc(gfp_t gfp_mask);
56void ulist_free(struct ulist *ulist);
57int ulist_add(struct ulist *ulist, u64 val, u64 aux, gfp_t gfp_mask);
58int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux,
59 u64 *old_aux, gfp_t gfp_mask);
60int ulist_del(struct ulist *ulist, u64 val, u64 aux);
61
62
63static inline int ulist_add_merge_ptr(struct ulist *ulist, u64 val, void *aux,
64 void **old_aux, gfp_t gfp_mask)
65{
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);
70 return ret;
71#else
72 return ulist_add_merge(ulist, val, (u64)aux, (u64 *)old_aux, gfp_mask);
73#endif
74}
75
76struct ulist_node *ulist_next(struct ulist *ulist,
77 struct ulist_iterator *uiter);
78
79#define ULIST_ITER_INIT(uiter) ((uiter)->cur_list = NULL)
80
81#endif
82