0001
0002
0003
0004
0005
0006 #ifndef BTRFS_RCU_STRING_H
0007 #define BTRFS_RCU_STRING_H
0008
0009 struct rcu_string {
0010 struct rcu_head rcu;
0011 char str[];
0012 };
0013
0014 static inline struct rcu_string *rcu_string_strdup(const char *src, gfp_t mask)
0015 {
0016 size_t len = strlen(src) + 1;
0017 struct rcu_string *ret = kzalloc(sizeof(struct rcu_string) +
0018 (len * sizeof(char)), mask);
0019 if (!ret)
0020 return ret;
0021 strncpy(ret->str, src, len);
0022 return ret;
0023 }
0024
0025 static inline void rcu_string_free(struct rcu_string *str)
0026 {
0027 if (str)
0028 kfree_rcu(str, rcu);
0029 }
0030
0031 #define printk_in_rcu(fmt, ...) do { \
0032 rcu_read_lock(); \
0033 printk(fmt, __VA_ARGS__); \
0034 rcu_read_unlock(); \
0035 } while (0)
0036
0037 #define printk_ratelimited_in_rcu(fmt, ...) do { \
0038 rcu_read_lock(); \
0039 printk_ratelimited(fmt, __VA_ARGS__); \
0040 rcu_read_unlock(); \
0041 } while (0)
0042
0043 #define rcu_str_deref(rcu_str) ({ \
0044 struct rcu_string *__str = rcu_dereference(rcu_str); \
0045 __str->str; \
0046 })
0047
0048 #endif