btrfs-progs: kill BUG_ON in readahead_tree_block()
[platform/upstream/btrfs-progs.git] / ulist.h
1 /*
2  * Copyright (C) 2011 STRATO AG
3  * written by Arne Jansen <sensille@gmx.net>
4  * Distributed under the GNU GPL license version 2.
5  *
6  */
7
8 #ifndef __ULIST__
9 #define __ULIST__
10
11 #include "kerncompat.h"
12 #include "list.h"
13 #include "rbtree.h"
14
15 /*
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
18  * enumerating it.
19  * It is possible to store an auxiliary value along with the key.
20  *
21  */
22 struct ulist_iterator {
23 #ifdef CONFIG_BTRFS_DEBUG
24         int i;
25 #endif
26         struct list_head *cur_list;  /* hint to start search */
27 };
28
29 /*
30  * element of the list
31  */
32 struct ulist_node {
33         u64 val;                /* value to store */
34         u64 aux;                /* auxiliary value saved along with the val */
35
36 #ifdef CONFIG_BTRFS_DEBUG
37         int seqnum;             /* sequence number this node is added */
38 #endif
39
40         struct list_head list;  /* used to link node */
41         struct rb_node rb_node; /* used to speed up search */
42 };
43
44 struct ulist {
45         /*
46          * number of elements stored in list
47          */
48         unsigned long nnodes;
49
50         struct list_head nodes;
51         struct rb_root root;
52 };
53
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);
61 struct ulist_node *ulist_next(struct ulist *ulist,
62                               struct ulist_iterator *uiter);
63
64 #define ULIST_ITER_INIT(uiter) ((uiter)->cur_list = NULL)
65
66 #endif