0001
0002
0003
0004
0005
0006
0007
0008 #ifdef pr_fmt
0009 #undef pr_fmt
0010 #endif
0011
0012 #define pr_fmt(fmt) "FS-Cache: " fmt
0013
0014 #include <linux/slab.h>
0015 #include <linux/fscache-cache.h>
0016 #include <trace/events/fscache.h>
0017 #include <linux/sched.h>
0018 #include <linux/seq_file.h>
0019
0020
0021
0022
0023 #ifdef CONFIG_PROC_FS
0024 extern const struct seq_operations fscache_caches_seq_ops;
0025 #endif
0026 bool fscache_begin_cache_access(struct fscache_cache *cache, enum fscache_access_trace why);
0027 void fscache_end_cache_access(struct fscache_cache *cache, enum fscache_access_trace why);
0028 struct fscache_cache *fscache_lookup_cache(const char *name, bool is_cache);
0029 void fscache_put_cache(struct fscache_cache *cache, enum fscache_cache_trace where);
0030
0031 static inline enum fscache_cache_state fscache_cache_state(const struct fscache_cache *cache)
0032 {
0033 return smp_load_acquire(&cache->state);
0034 }
0035
0036 static inline bool fscache_cache_is_live(const struct fscache_cache *cache)
0037 {
0038 return fscache_cache_state(cache) == FSCACHE_CACHE_IS_ACTIVE;
0039 }
0040
0041 static inline void fscache_set_cache_state(struct fscache_cache *cache,
0042 enum fscache_cache_state new_state)
0043 {
0044 smp_store_release(&cache->state, new_state);
0045
0046 }
0047
0048 static inline bool fscache_set_cache_state_maybe(struct fscache_cache *cache,
0049 enum fscache_cache_state old_state,
0050 enum fscache_cache_state new_state)
0051 {
0052 return try_cmpxchg_release(&cache->state, &old_state, new_state);
0053 }
0054
0055
0056
0057
0058 extern struct kmem_cache *fscache_cookie_jar;
0059 #ifdef CONFIG_PROC_FS
0060 extern const struct seq_operations fscache_cookies_seq_ops;
0061 #endif
0062 extern struct timer_list fscache_cookie_lru_timer;
0063
0064 extern void fscache_print_cookie(struct fscache_cookie *cookie, char prefix);
0065 extern bool fscache_begin_cookie_access(struct fscache_cookie *cookie,
0066 enum fscache_access_trace why);
0067
0068 static inline void fscache_see_cookie(struct fscache_cookie *cookie,
0069 enum fscache_cookie_trace where)
0070 {
0071 trace_fscache_cookie(cookie->debug_id, refcount_read(&cookie->ref),
0072 where);
0073 }
0074
0075
0076
0077
0078 extern unsigned fscache_debug;
0079
0080 extern unsigned int fscache_hash(unsigned int salt, const void *data, size_t len);
0081
0082
0083
0084
0085 #ifdef CONFIG_PROC_FS
0086 extern int __init fscache_proc_init(void);
0087 extern void fscache_proc_cleanup(void);
0088 #else
0089 #define fscache_proc_init() (0)
0090 #define fscache_proc_cleanup() do {} while (0)
0091 #endif
0092
0093
0094
0095
0096 #ifdef CONFIG_FSCACHE_STATS
0097 extern atomic_t fscache_n_volumes;
0098 extern atomic_t fscache_n_volumes_collision;
0099 extern atomic_t fscache_n_volumes_nomem;
0100 extern atomic_t fscache_n_cookies;
0101 extern atomic_t fscache_n_cookies_lru;
0102 extern atomic_t fscache_n_cookies_lru_expired;
0103 extern atomic_t fscache_n_cookies_lru_removed;
0104 extern atomic_t fscache_n_cookies_lru_dropped;
0105
0106 extern atomic_t fscache_n_acquires;
0107 extern atomic_t fscache_n_acquires_ok;
0108 extern atomic_t fscache_n_acquires_oom;
0109
0110 extern atomic_t fscache_n_invalidates;
0111
0112 extern atomic_t fscache_n_relinquishes;
0113 extern atomic_t fscache_n_relinquishes_retire;
0114 extern atomic_t fscache_n_relinquishes_dropped;
0115
0116 extern atomic_t fscache_n_resizes;
0117 extern atomic_t fscache_n_resizes_null;
0118
0119 static inline void fscache_stat(atomic_t *stat)
0120 {
0121 atomic_inc(stat);
0122 }
0123
0124 static inline void fscache_stat_d(atomic_t *stat)
0125 {
0126 atomic_dec(stat);
0127 }
0128
0129 #define __fscache_stat(stat) (stat)
0130
0131 int fscache_stats_show(struct seq_file *m, void *v);
0132 #else
0133
0134 #define __fscache_stat(stat) (NULL)
0135 #define fscache_stat(stat) do {} while (0)
0136 #define fscache_stat_d(stat) do {} while (0)
0137 #endif
0138
0139
0140
0141
0142 #ifdef CONFIG_PROC_FS
0143 extern const struct seq_operations fscache_volumes_seq_ops;
0144 #endif
0145
0146 struct fscache_volume *fscache_get_volume(struct fscache_volume *volume,
0147 enum fscache_volume_trace where);
0148 void fscache_put_volume(struct fscache_volume *volume,
0149 enum fscache_volume_trace where);
0150 bool fscache_begin_volume_access(struct fscache_volume *volume,
0151 struct fscache_cookie *cookie,
0152 enum fscache_access_trace why);
0153 void fscache_create_volume(struct fscache_volume *volume, bool wait);
0154
0155
0156
0157
0158
0159
0160 #define dbgprintk(FMT, ...) \
0161 printk("[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
0162
0163 #define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
0164 #define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
0165 #define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
0166
0167 #define kjournal(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
0168
0169 #ifdef __KDEBUG
0170 #define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
0171 #define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
0172 #define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
0173
0174 #elif defined(CONFIG_FSCACHE_DEBUG)
0175 #define _enter(FMT, ...) \
0176 do { \
0177 if (__do_kdebug(ENTER)) \
0178 kenter(FMT, ##__VA_ARGS__); \
0179 } while (0)
0180
0181 #define _leave(FMT, ...) \
0182 do { \
0183 if (__do_kdebug(LEAVE)) \
0184 kleave(FMT, ##__VA_ARGS__); \
0185 } while (0)
0186
0187 #define _debug(FMT, ...) \
0188 do { \
0189 if (__do_kdebug(DEBUG)) \
0190 kdebug(FMT, ##__VA_ARGS__); \
0191 } while (0)
0192
0193 #else
0194 #define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
0195 #define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
0196 #define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
0197 #endif
0198
0199
0200
0201
0202
0203
0204 #define ____do_kdebug(LEVEL, POINT) \
0205 unlikely((fscache_debug & \
0206 (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
0207 #define ___do_kdebug(LEVEL, POINT) \
0208 ____do_kdebug(LEVEL, POINT)
0209 #define __do_kdebug(POINT) \
0210 ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
0211
0212 #define FSCACHE_DEBUG_CACHE 0
0213 #define FSCACHE_DEBUG_COOKIE 1
0214 #define FSCACHE_DEBUG_OBJECT 2
0215 #define FSCACHE_DEBUG_OPERATION 3
0216
0217 #define FSCACHE_POINT_ENTER 1
0218 #define FSCACHE_POINT_LEAVE 2
0219 #define FSCACHE_POINT_DEBUG 4
0220
0221 #ifndef FSCACHE_DEBUG_LEVEL
0222 #define FSCACHE_DEBUG_LEVEL CACHE
0223 #endif
0224
0225
0226
0227
0228 #if 1
0229
0230 #define ASSERT(X) \
0231 do { \
0232 if (unlikely(!(X))) { \
0233 pr_err("\n"); \
0234 pr_err("Assertion failed\n"); \
0235 BUG(); \
0236 } \
0237 } while (0)
0238
0239 #define ASSERTCMP(X, OP, Y) \
0240 do { \
0241 if (unlikely(!((X) OP (Y)))) { \
0242 pr_err("\n"); \
0243 pr_err("Assertion failed\n"); \
0244 pr_err("%lx " #OP " %lx is false\n", \
0245 (unsigned long)(X), (unsigned long)(Y)); \
0246 BUG(); \
0247 } \
0248 } while (0)
0249
0250 #define ASSERTIF(C, X) \
0251 do { \
0252 if (unlikely((C) && !(X))) { \
0253 pr_err("\n"); \
0254 pr_err("Assertion failed\n"); \
0255 BUG(); \
0256 } \
0257 } while (0)
0258
0259 #define ASSERTIFCMP(C, X, OP, Y) \
0260 do { \
0261 if (unlikely((C) && !((X) OP (Y)))) { \
0262 pr_err("\n"); \
0263 pr_err("Assertion failed\n"); \
0264 pr_err("%lx " #OP " %lx is false\n", \
0265 (unsigned long)(X), (unsigned long)(Y)); \
0266 BUG(); \
0267 } \
0268 } while (0)
0269
0270 #else
0271
0272 #define ASSERT(X) do {} while (0)
0273 #define ASSERTCMP(X, OP, Y) do {} while (0)
0274 #define ASSERTIF(C, X) do {} while (0)
0275 #define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
0276
0277 #endif