aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ceph/string_table.h
diff options
context:
space:
mode:
authorYan, Zheng <zyan@redhat.com>2016-02-05 02:36:22 -0500
committerIlya Dryomov <idryomov@gmail.com>2016-07-27 20:55:37 -0400
commit51e9273796a57c08801f45580d3db3c51987a0cb (patch)
tree5eb35d4d7c0f44065b0fe17f0bb0a3c98202f215 /include/linux/ceph/string_table.h
parent7627151ea30bce2051e3cb27d7bb2c30083f86a5 (diff)
libceph: introduce reference counted string
The data structure is for storing namesapce string. It allows namespace string to be shared between cephfs inodes with same layout. This data structure can also be referenced by OSD request. Signed-off-by: Yan, Zheng <zyan@redhat.com>
Diffstat (limited to 'include/linux/ceph/string_table.h')
-rw-r--r--include/linux/ceph/string_table.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/include/linux/ceph/string_table.h b/include/linux/ceph/string_table.h
new file mode 100644
index 000000000000..1b02c96daf75
--- /dev/null
+++ b/include/linux/ceph/string_table.h
@@ -0,0 +1,62 @@
1#ifndef _FS_CEPH_STRING_TABLE_H
2#define _FS_CEPH_STRING_TABLE_H
3
4#include <linux/types.h>
5#include <linux/kref.h>
6#include <linux/rbtree.h>
7#include <linux/rcupdate.h>
8
9struct ceph_string {
10 struct kref kref;
11 union {
12 struct rb_node node;
13 struct rcu_head rcu;
14 };
15 size_t len;
16 char str[];
17};
18
19extern void ceph_release_string(struct kref *ref);
20extern struct ceph_string *ceph_find_or_create_string(const char *str,
21 size_t len);
22extern bool ceph_strings_empty(void);
23
24static inline struct ceph_string *ceph_get_string(struct ceph_string *str)
25{
26 kref_get(&str->kref);
27 return str;
28}
29
30static inline void ceph_put_string(struct ceph_string *str)
31{
32 if (!str)
33 return;
34 kref_put(&str->kref, ceph_release_string);
35}
36
37static inline int ceph_compare_string(struct ceph_string *cs,
38 const char* str, size_t len)
39{
40 size_t cs_len = cs ? cs->len : 0;
41 if (cs_len != len)
42 return cs_len - len;
43 if (len == 0)
44 return 0;
45 return strncmp(cs->str, str, len);
46}
47
48#define ceph_try_get_string(x) \
49({ \
50 struct ceph_string *___str; \
51 rcu_read_lock(); \
52 for (;;) { \
53 ___str = rcu_dereference(x); \
54 if (!___str || \
55 kref_get_unless_zero(&___str->kref)) \
56 break; \
57 } \
58 rcu_read_unlock(); \
59 (___str); \
60})
61
62#endif