btrfs-progs: update CHANGES for v4.16
[platform/upstream/btrfs-progs.git] / kernel-lib / radix-tree.h
1 /*
2  * Copyright (C) 2007 Oracle.  All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License v2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public
14  * License along with this program; if not, write to the
15  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16  * Boston, MA 021110-1307, USA.
17  */
18
19 /*
20  * Copyright (C) 2001 Momchil Velikov
21  * Portions Copyright (C) 2001 Christoph Hellwig
22  *
23  * This program is free software; you can redistribute it and/or
24  * modify it under the terms of the GNU General Public License as
25  * published by the Free Software Foundation; either version 2, or (at
26  * your option) any later version.
27  * 
28  * This program is distributed in the hope that it will be useful, but
29  * WITHOUT ANY WARRANTY; without even the implied warranty of
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
31  * General Public License for more details.
32  * 
33  * You should have received a copy of the GNU General Public License
34  * along with this program; if not, write to the Free Software
35  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36  */
37 #ifndef _LINUX_RADIX_TREE_H
38 #define _LINUX_RADIX_TREE_H
39
40 #if BTRFS_FLAT_INCLUDES
41 #include "kerncompat.h"
42 #else
43 #include <btrfs/kerncompat.h>
44 #endif /* BTRFS_FLAT_INCLUDES */
45
46 #define RADIX_TREE_MAX_TAGS 2
47
48 /* root tags are stored in gfp_mask, shifted by __GFP_BITS_SHIFT */
49 struct radix_tree_root {
50         unsigned int            height;
51         gfp_t                   gfp_mask;
52         struct radix_tree_node  *rnode;
53 };
54
55 #define RADIX_TREE_INIT(mask)   {                                       \
56         .height = 0,                                                    \
57         .gfp_mask = (mask),                                             \
58         .rnode = NULL,                                                  \
59 }
60
61 #define RADIX_TREE(name, mask) \
62         struct radix_tree_root name = RADIX_TREE_INIT(mask)
63
64 #define INIT_RADIX_TREE(root, mask)                                     \
65 do {                                                                    \
66         (root)->height = 0;                                             \
67         (root)->gfp_mask = (mask);                                      \
68         (root)->rnode = NULL;                                           \
69 } while (0)
70
71 int radix_tree_insert(struct radix_tree_root *, unsigned long, void *);
72 void *radix_tree_lookup(struct radix_tree_root *, unsigned long);
73 void **radix_tree_lookup_slot(struct radix_tree_root *, unsigned long);
74 void *radix_tree_delete(struct radix_tree_root *, unsigned long);
75 unsigned int
76 radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
77                         unsigned long first_index, unsigned int max_items);
78 int radix_tree_preload(gfp_t gfp_mask);
79 void radix_tree_init(void);
80 void *radix_tree_tag_set(struct radix_tree_root *root,
81                         unsigned long index, unsigned int tag);
82 void *radix_tree_tag_clear(struct radix_tree_root *root,
83                         unsigned long index, unsigned int tag);
84 int radix_tree_tag_get(struct radix_tree_root *root,
85                         unsigned long index, unsigned int tag);
86 unsigned int
87 radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results,
88                 unsigned long first_index, unsigned int max_items,
89                 unsigned int tag);
90 int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag);
91
92 static inline void radix_tree_preload_end(void)
93 {
94         preempt_enable();
95 }
96
97 #endif /* _LINUX_RADIX_TREE_H */