aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ceph
diff options
context:
space:
mode:
authorIlya Dryomov <idryomov@gmail.com>2016-04-28 10:07:22 -0400
committerIlya Dryomov <idryomov@gmail.com>2016-05-25 18:36:23 -0400
commitfcd00b68bbe2bf5606cb45c2cd4a250a390bcc1f (patch)
tree7db18711377a59e78b22df4f6d73411620cc92df /include/linux/ceph
parent42a2c09f2b0b95fa147bcdb56cdc02b980b9ac5e (diff)
libceph: DEFINE_RB_FUNCS macro
Given struct foo { u64 id; struct rb_node bar_node; }; generate insert_bar(), erase_bar() and lookup_bar() functions with DEFINE_RB_FUNCS(bar, struct foo, id, bar_node) The key is assumed to be an integer (u64, int, etc), compared with < and >. nodefld has to be initialized with RB_CLEAR_NODE(). Start using it for MDS, MON and OSD requests and OSD sessions. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Diffstat (limited to 'include/linux/ceph')
-rw-r--r--include/linux/ceph/libceph.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/include/linux/ceph/libceph.h b/include/linux/ceph/libceph.h
index db92a8d4926e..690985daad1c 100644
--- a/include/linux/ceph/libceph.h
+++ b/include/linux/ceph/libceph.h
@@ -180,6 +180,63 @@ static inline int calc_pages_for(u64 off, u64 len)
180 (off >> PAGE_SHIFT); 180 (off >> PAGE_SHIFT);
181} 181}
182 182
183/*
184 * These are not meant to be generic - an integer key is assumed.
185 */
186#define DEFINE_RB_INSDEL_FUNCS(name, type, keyfld, nodefld) \
187static void insert_##name(struct rb_root *root, type *t) \
188{ \
189 struct rb_node **n = &root->rb_node; \
190 struct rb_node *parent = NULL; \
191 \
192 BUG_ON(!RB_EMPTY_NODE(&t->nodefld)); \
193 \
194 while (*n) { \
195 type *cur = rb_entry(*n, type, nodefld); \
196 \
197 parent = *n; \
198 if (t->keyfld < cur->keyfld) \
199 n = &(*n)->rb_left; \
200 else if (t->keyfld > cur->keyfld) \
201 n = &(*n)->rb_right; \
202 else \
203 BUG(); \
204 } \
205 \
206 rb_link_node(&t->nodefld, parent, n); \
207 rb_insert_color(&t->nodefld, root); \
208} \
209static void erase_##name(struct rb_root *root, type *t) \
210{ \
211 BUG_ON(RB_EMPTY_NODE(&t->nodefld)); \
212 rb_erase(&t->nodefld, root); \
213 RB_CLEAR_NODE(&t->nodefld); \
214}
215
216#define DEFINE_RB_LOOKUP_FUNC(name, type, keyfld, nodefld) \
217static type *lookup_##name(struct rb_root *root, \
218 typeof(((type *)0)->keyfld) key) \
219{ \
220 struct rb_node *n = root->rb_node; \
221 \
222 while (n) { \
223 type *cur = rb_entry(n, type, nodefld); \
224 \
225 if (key < cur->keyfld) \
226 n = n->rb_left; \
227 else if (key > cur->keyfld) \
228 n = n->rb_right; \
229 else \
230 return cur; \
231 } \
232 \
233 return NULL; \
234}
235
236#define DEFINE_RB_FUNCS(name, type, keyfld, nodefld) \
237DEFINE_RB_INSDEL_FUNCS(name, type, keyfld, nodefld) \
238DEFINE_RB_LOOKUP_FUNC(name, type, keyfld, nodefld)
239
183extern struct kmem_cache *ceph_inode_cachep; 240extern struct kmem_cache *ceph_inode_cachep;
184extern struct kmem_cache *ceph_cap_cachep; 241extern struct kmem_cache *ceph_cap_cachep;
185extern struct kmem_cache *ceph_cap_flush_cachep; 242extern struct kmem_cache *ceph_cap_flush_cachep;