gro: Allow tunnel stacking in the case of FOU/GUE
[linux/fpc-iii.git] / fs / btrfs / ulist.h
blob4c29db604bbe135fb1bdb3743c7eee408499d25c
1 /*
2 * Copyright (C) 2011 STRATO AG
3 * written by Arne Jansen <sensille@gmx.net>
4 * Distributed under the GNU GPL license version 2.
6 */
8 #ifndef __ULIST__
9 #define __ULIST__
11 #include <linux/list.h>
12 #include <linux/rbtree.h>
15 * ulist is a generic data structure to hold a collection of unique u64
16 * values. The only operations it supports is adding to the list and
17 * enumerating it.
18 * It is possible to store an auxiliary value along with the key.
21 struct ulist_iterator {
22 #ifdef CONFIG_BTRFS_DEBUG
23 int i;
24 #endif
25 struct list_head *cur_list; /* hint to start search */
29 * element of the list
31 struct ulist_node {
32 u64 val; /* value to store */
33 u64 aux; /* auxiliary value saved along with the val */
35 #ifdef CONFIG_BTRFS_DEBUG
36 int seqnum; /* sequence number this node is added */
37 #endif
39 struct list_head list; /* used to link node */
40 struct rb_node rb_node; /* used to speed up search */
43 struct ulist {
45 * number of elements stored in list
47 unsigned long nnodes;
49 struct list_head nodes;
50 struct rb_root root;
53 void ulist_init(struct ulist *ulist);
54 void ulist_reinit(struct ulist *ulist);
55 struct ulist *ulist_alloc(gfp_t gfp_mask);
56 void ulist_free(struct ulist *ulist);
57 int ulist_add(struct ulist *ulist, u64 val, u64 aux, gfp_t gfp_mask);
58 int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux,
59 u64 *old_aux, gfp_t gfp_mask);
61 /* just like ulist_add_merge() but take a pointer for the aux data */
62 static inline int ulist_add_merge_ptr(struct ulist *ulist, u64 val, void *aux,
63 void **old_aux, gfp_t gfp_mask)
65 #if BITS_PER_LONG == 32
66 u64 old64 = (uintptr_t)*old_aux;
67 int ret = ulist_add_merge(ulist, val, (uintptr_t)aux, &old64, gfp_mask);
68 *old_aux = (void *)((uintptr_t)old64);
69 return ret;
70 #else
71 return ulist_add_merge(ulist, val, (u64)aux, (u64 *)old_aux, gfp_mask);
72 #endif
75 struct ulist_node *ulist_next(struct ulist *ulist,
76 struct ulist_iterator *uiter);
78 #define ULIST_ITER_INIT(uiter) ((uiter)->cur_list = NULL)
80 #endif