Loading...
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/* General netfs cache on cache files internal defs
3 *
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
7
8#ifdef pr_fmt
9#undef pr_fmt
10#endif
11
12#define pr_fmt(fmt) "CacheFiles: " fmt
13
14
15#include <linux/fscache-cache.h>
16#include <linux/timer.h>
17#include <linux/wait_bit.h>
18#include <linux/cred.h>
19#include <linux/workqueue.h>
20#include <linux/security.h>
21
22struct cachefiles_cache;
23struct cachefiles_object;
24
25extern unsigned cachefiles_debug;
26#define CACHEFILES_DEBUG_KENTER 1
27#define CACHEFILES_DEBUG_KLEAVE 2
28#define CACHEFILES_DEBUG_KDEBUG 4
29
30#define cachefiles_gfp (__GFP_RECLAIM | __GFP_NORETRY | __GFP_NOMEMALLOC)
31
32/*
33 * node records
34 */
35struct cachefiles_object {
36 struct fscache_object fscache; /* fscache handle */
37 struct cachefiles_lookup_data *lookup_data; /* cached lookup data */
38 struct dentry *dentry; /* the file/dir representing this object */
39 struct dentry *backer; /* backing file */
40 loff_t i_size; /* object size */
41 unsigned long flags;
42#define CACHEFILES_OBJECT_ACTIVE 0 /* T if marked active */
43 atomic_t usage; /* object usage count */
44 uint8_t type; /* object type */
45 uint8_t new; /* T if object new */
46 spinlock_t work_lock;
47 struct rb_node active_node; /* link in active tree (dentry is key) */
48};
49
50extern struct kmem_cache *cachefiles_object_jar;
51
52/*
53 * Cache files cache definition
54 */
55struct cachefiles_cache {
56 struct fscache_cache cache; /* FS-Cache record */
57 struct vfsmount *mnt; /* mountpoint holding the cache */
58 struct dentry *graveyard; /* directory into which dead objects go */
59 struct file *cachefilesd; /* manager daemon handle */
60 const struct cred *cache_cred; /* security override for accessing cache */
61 struct mutex daemon_mutex; /* command serialisation mutex */
62 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
63 struct rb_root active_nodes; /* active nodes (can't be culled) */
64 rwlock_t active_lock; /* lock for active_nodes */
65 atomic_t gravecounter; /* graveyard uniquifier */
66 atomic_t f_released; /* number of objects released lately */
67 atomic_long_t b_released; /* number of blocks released lately */
68 unsigned frun_percent; /* when to stop culling (% files) */
69 unsigned fcull_percent; /* when to start culling (% files) */
70 unsigned fstop_percent; /* when to stop allocating (% files) */
71 unsigned brun_percent; /* when to stop culling (% blocks) */
72 unsigned bcull_percent; /* when to start culling (% blocks) */
73 unsigned bstop_percent; /* when to stop allocating (% blocks) */
74 unsigned bsize; /* cache's block size */
75 unsigned bshift; /* min(ilog2(PAGE_SIZE / bsize), 0) */
76 uint64_t frun; /* when to stop culling */
77 uint64_t fcull; /* when to start culling */
78 uint64_t fstop; /* when to stop allocating */
79 sector_t brun; /* when to stop culling */
80 sector_t bcull; /* when to start culling */
81 sector_t bstop; /* when to stop allocating */
82 unsigned long flags;
83#define CACHEFILES_READY 0 /* T if cache prepared */
84#define CACHEFILES_DEAD 1 /* T if cache dead */
85#define CACHEFILES_CULLING 2 /* T if cull engaged */
86#define CACHEFILES_STATE_CHANGED 3 /* T if state changed (poll trigger) */
87 char *rootdirname; /* name of cache root directory */
88 char *secctx; /* LSM security context */
89 char *tag; /* cache binding tag */
90};
91
92/*
93 * backing file read tracking
94 */
95struct cachefiles_one_read {
96 wait_queue_entry_t monitor; /* link into monitored waitqueue */
97 struct page *back_page; /* backing file page we're waiting for */
98 struct page *netfs_page; /* netfs page we're going to fill */
99 struct fscache_retrieval *op; /* retrieval op covering this */
100 struct list_head op_link; /* link in op's todo list */
101};
102
103/*
104 * backing file write tracking
105 */
106struct cachefiles_one_write {
107 struct page *netfs_page; /* netfs page to copy */
108 struct cachefiles_object *object;
109 struct list_head obj_link; /* link in object's lists */
110 fscache_rw_complete_t end_io_func;
111 void *context;
112};
113
114/*
115 * auxiliary data xattr buffer
116 */
117struct cachefiles_xattr {
118 uint16_t len;
119 uint8_t type;
120 uint8_t data[];
121};
122
123#include <trace/events/cachefiles.h>
124
125/*
126 * note change of state for daemon
127 */
128static inline void cachefiles_state_changed(struct cachefiles_cache *cache)
129{
130 set_bit(CACHEFILES_STATE_CHANGED, &cache->flags);
131 wake_up_all(&cache->daemon_pollwq);
132}
133
134/*
135 * bind.c
136 */
137extern int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args);
138extern void cachefiles_daemon_unbind(struct cachefiles_cache *cache);
139
140/*
141 * daemon.c
142 */
143extern const struct file_operations cachefiles_daemon_fops;
144
145extern int cachefiles_has_space(struct cachefiles_cache *cache,
146 unsigned fnr, unsigned bnr);
147
148/*
149 * interface.c
150 */
151extern const struct fscache_cache_ops cachefiles_cache_ops;
152
153/*
154 * key.c
155 */
156extern char *cachefiles_cook_key(const u8 *raw, int keylen, uint8_t type);
157
158/*
159 * namei.c
160 */
161extern void cachefiles_mark_object_inactive(struct cachefiles_cache *cache,
162 struct cachefiles_object *object,
163 blkcnt_t i_blocks);
164extern int cachefiles_delete_object(struct cachefiles_cache *cache,
165 struct cachefiles_object *object);
166extern int cachefiles_walk_to_object(struct cachefiles_object *parent,
167 struct cachefiles_object *object,
168 const char *key,
169 struct cachefiles_xattr *auxdata);
170extern struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
171 struct dentry *dir,
172 const char *name);
173
174extern int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
175 char *filename);
176
177extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
178 struct dentry *dir, char *filename);
179
180/*
181 * proc.c
182 */
183#ifdef CONFIG_CACHEFILES_HISTOGRAM
184extern atomic_t cachefiles_lookup_histogram[HZ];
185extern atomic_t cachefiles_mkdir_histogram[HZ];
186extern atomic_t cachefiles_create_histogram[HZ];
187
188extern int __init cachefiles_proc_init(void);
189extern void cachefiles_proc_cleanup(void);
190static inline
191void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
192{
193 unsigned long jif = jiffies - start_jif;
194 if (jif >= HZ)
195 jif = HZ - 1;
196 atomic_inc(&histogram[jif]);
197}
198
199#else
200#define cachefiles_proc_init() (0)
201#define cachefiles_proc_cleanup() do {} while (0)
202#define cachefiles_hist(hist, start_jif) do {} while (0)
203#endif
204
205/*
206 * rdwr.c
207 */
208extern int cachefiles_read_or_alloc_page(struct fscache_retrieval *,
209 struct page *, gfp_t);
210extern int cachefiles_read_or_alloc_pages(struct fscache_retrieval *,
211 struct list_head *, unsigned *,
212 gfp_t);
213extern int cachefiles_allocate_page(struct fscache_retrieval *, struct page *,
214 gfp_t);
215extern int cachefiles_allocate_pages(struct fscache_retrieval *,
216 struct list_head *, unsigned *, gfp_t);
217extern int cachefiles_write_page(struct fscache_storage *, struct page *);
218extern void cachefiles_uncache_page(struct fscache_object *, struct page *);
219
220/*
221 * security.c
222 */
223extern int cachefiles_get_security_ID(struct cachefiles_cache *cache);
224extern int cachefiles_determine_cache_security(struct cachefiles_cache *cache,
225 struct dentry *root,
226 const struct cred **_saved_cred);
227
228static inline void cachefiles_begin_secure(struct cachefiles_cache *cache,
229 const struct cred **_saved_cred)
230{
231 *_saved_cred = override_creds(cache->cache_cred);
232}
233
234static inline void cachefiles_end_secure(struct cachefiles_cache *cache,
235 const struct cred *saved_cred)
236{
237 revert_creds(saved_cred);
238}
239
240/*
241 * xattr.c
242 */
243extern int cachefiles_check_object_type(struct cachefiles_object *object);
244extern int cachefiles_set_object_xattr(struct cachefiles_object *object,
245 struct cachefiles_xattr *auxdata);
246extern int cachefiles_update_object_xattr(struct cachefiles_object *object,
247 struct cachefiles_xattr *auxdata);
248extern int cachefiles_check_auxdata(struct cachefiles_object *object);
249extern int cachefiles_check_object_xattr(struct cachefiles_object *object,
250 struct cachefiles_xattr *auxdata);
251extern int cachefiles_remove_object_xattr(struct cachefiles_cache *cache,
252 struct dentry *dentry);
253
254
255/*
256 * error handling
257 */
258
259#define cachefiles_io_error(___cache, FMT, ...) \
260do { \
261 pr_err("I/O Error: " FMT"\n", ##__VA_ARGS__); \
262 fscache_io_error(&(___cache)->cache); \
263 set_bit(CACHEFILES_DEAD, &(___cache)->flags); \
264} while (0)
265
266#define cachefiles_io_error_obj(object, FMT, ...) \
267do { \
268 struct cachefiles_cache *___cache; \
269 \
270 ___cache = container_of((object)->fscache.cache, \
271 struct cachefiles_cache, cache); \
272 cachefiles_io_error(___cache, FMT, ##__VA_ARGS__); \
273} while (0)
274
275
276/*
277 * debug tracing
278 */
279#define dbgprintk(FMT, ...) \
280 printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
281
282#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
283#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
284#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
285
286
287#if defined(__KDEBUG)
288#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
289#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
290#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
291
292#elif defined(CONFIG_CACHEFILES_DEBUG)
293#define _enter(FMT, ...) \
294do { \
295 if (cachefiles_debug & CACHEFILES_DEBUG_KENTER) \
296 kenter(FMT, ##__VA_ARGS__); \
297} while (0)
298
299#define _leave(FMT, ...) \
300do { \
301 if (cachefiles_debug & CACHEFILES_DEBUG_KLEAVE) \
302 kleave(FMT, ##__VA_ARGS__); \
303} while (0)
304
305#define _debug(FMT, ...) \
306do { \
307 if (cachefiles_debug & CACHEFILES_DEBUG_KDEBUG) \
308 kdebug(FMT, ##__VA_ARGS__); \
309} while (0)
310
311#else
312#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
313#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
314#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
315#endif
316
317#if 1 /* defined(__KDEBUGALL) */
318
319#define ASSERT(X) \
320do { \
321 if (unlikely(!(X))) { \
322 pr_err("\n"); \
323 pr_err("Assertion failed\n"); \
324 BUG(); \
325 } \
326} while (0)
327
328#define ASSERTCMP(X, OP, Y) \
329do { \
330 if (unlikely(!((X) OP (Y)))) { \
331 pr_err("\n"); \
332 pr_err("Assertion failed\n"); \
333 pr_err("%lx " #OP " %lx is false\n", \
334 (unsigned long)(X), (unsigned long)(Y)); \
335 BUG(); \
336 } \
337} while (0)
338
339#define ASSERTIF(C, X) \
340do { \
341 if (unlikely((C) && !(X))) { \
342 pr_err("\n"); \
343 pr_err("Assertion failed\n"); \
344 BUG(); \
345 } \
346} while (0)
347
348#define ASSERTIFCMP(C, X, OP, Y) \
349do { \
350 if (unlikely((C) && !((X) OP (Y)))) { \
351 pr_err("\n"); \
352 pr_err("Assertion failed\n"); \
353 pr_err("%lx " #OP " %lx is false\n", \
354 (unsigned long)(X), (unsigned long)(Y)); \
355 BUG(); \
356 } \
357} while (0)
358
359#else
360
361#define ASSERT(X) do {} while (0)
362#define ASSERTCMP(X, OP, Y) do {} while (0)
363#define ASSERTIF(C, X) do {} while (0)
364#define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
365
366#endif
1/* General netfs cache on cache files internal defs
2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11
12#include <linux/fscache-cache.h>
13#include <linux/timer.h>
14#include <linux/wait.h>
15#include <linux/workqueue.h>
16#include <linux/security.h>
17
18struct cachefiles_cache;
19struct cachefiles_object;
20
21extern unsigned cachefiles_debug;
22#define CACHEFILES_DEBUG_KENTER 1
23#define CACHEFILES_DEBUG_KLEAVE 2
24#define CACHEFILES_DEBUG_KDEBUG 4
25
26/*
27 * node records
28 */
29struct cachefiles_object {
30 struct fscache_object fscache; /* fscache handle */
31 struct cachefiles_lookup_data *lookup_data; /* cached lookup data */
32 struct dentry *dentry; /* the file/dir representing this object */
33 struct dentry *backer; /* backing file */
34 loff_t i_size; /* object size */
35 unsigned long flags;
36#define CACHEFILES_OBJECT_ACTIVE 0 /* T if marked active */
37#define CACHEFILES_OBJECT_BURIED 1 /* T if preemptively buried */
38 atomic_t usage; /* object usage count */
39 uint8_t type; /* object type */
40 uint8_t new; /* T if object new */
41 spinlock_t work_lock;
42 struct rb_node active_node; /* link in active tree (dentry is key) */
43};
44
45extern struct kmem_cache *cachefiles_object_jar;
46
47/*
48 * Cache files cache definition
49 */
50struct cachefiles_cache {
51 struct fscache_cache cache; /* FS-Cache record */
52 struct vfsmount *mnt; /* mountpoint holding the cache */
53 struct dentry *graveyard; /* directory into which dead objects go */
54 struct file *cachefilesd; /* manager daemon handle */
55 const struct cred *cache_cred; /* security override for accessing cache */
56 struct mutex daemon_mutex; /* command serialisation mutex */
57 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
58 struct rb_root active_nodes; /* active nodes (can't be culled) */
59 rwlock_t active_lock; /* lock for active_nodes */
60 atomic_t gravecounter; /* graveyard uniquifier */
61 unsigned frun_percent; /* when to stop culling (% files) */
62 unsigned fcull_percent; /* when to start culling (% files) */
63 unsigned fstop_percent; /* when to stop allocating (% files) */
64 unsigned brun_percent; /* when to stop culling (% blocks) */
65 unsigned bcull_percent; /* when to start culling (% blocks) */
66 unsigned bstop_percent; /* when to stop allocating (% blocks) */
67 unsigned bsize; /* cache's block size */
68 unsigned bshift; /* min(ilog2(PAGE_SIZE / bsize), 0) */
69 uint64_t frun; /* when to stop culling */
70 uint64_t fcull; /* when to start culling */
71 uint64_t fstop; /* when to stop allocating */
72 sector_t brun; /* when to stop culling */
73 sector_t bcull; /* when to start culling */
74 sector_t bstop; /* when to stop allocating */
75 unsigned long flags;
76#define CACHEFILES_READY 0 /* T if cache prepared */
77#define CACHEFILES_DEAD 1 /* T if cache dead */
78#define CACHEFILES_CULLING 2 /* T if cull engaged */
79#define CACHEFILES_STATE_CHANGED 3 /* T if state changed (poll trigger) */
80 char *rootdirname; /* name of cache root directory */
81 char *secctx; /* LSM security context */
82 char *tag; /* cache binding tag */
83};
84
85/*
86 * backing file read tracking
87 */
88struct cachefiles_one_read {
89 wait_queue_t monitor; /* link into monitored waitqueue */
90 struct page *back_page; /* backing file page we're waiting for */
91 struct page *netfs_page; /* netfs page we're going to fill */
92 struct fscache_retrieval *op; /* retrieval op covering this */
93 struct list_head op_link; /* link in op's todo list */
94};
95
96/*
97 * backing file write tracking
98 */
99struct cachefiles_one_write {
100 struct page *netfs_page; /* netfs page to copy */
101 struct cachefiles_object *object;
102 struct list_head obj_link; /* link in object's lists */
103 fscache_rw_complete_t end_io_func;
104 void *context;
105};
106
107/*
108 * auxiliary data xattr buffer
109 */
110struct cachefiles_xattr {
111 uint16_t len;
112 uint8_t type;
113 uint8_t data[];
114};
115
116/*
117 * note change of state for daemon
118 */
119static inline void cachefiles_state_changed(struct cachefiles_cache *cache)
120{
121 set_bit(CACHEFILES_STATE_CHANGED, &cache->flags);
122 wake_up_all(&cache->daemon_pollwq);
123}
124
125/*
126 * bind.c
127 */
128extern int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args);
129extern void cachefiles_daemon_unbind(struct cachefiles_cache *cache);
130
131/*
132 * daemon.c
133 */
134extern const struct file_operations cachefiles_daemon_fops;
135
136extern int cachefiles_has_space(struct cachefiles_cache *cache,
137 unsigned fnr, unsigned bnr);
138
139/*
140 * interface.c
141 */
142extern const struct fscache_cache_ops cachefiles_cache_ops;
143
144/*
145 * key.c
146 */
147extern char *cachefiles_cook_key(const u8 *raw, int keylen, uint8_t type);
148
149/*
150 * namei.c
151 */
152extern int cachefiles_delete_object(struct cachefiles_cache *cache,
153 struct cachefiles_object *object);
154extern int cachefiles_walk_to_object(struct cachefiles_object *parent,
155 struct cachefiles_object *object,
156 const char *key,
157 struct cachefiles_xattr *auxdata);
158extern struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
159 struct dentry *dir,
160 const char *name);
161
162extern int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
163 char *filename);
164
165extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
166 struct dentry *dir, char *filename);
167
168/*
169 * proc.c
170 */
171#ifdef CONFIG_CACHEFILES_HISTOGRAM
172extern atomic_t cachefiles_lookup_histogram[HZ];
173extern atomic_t cachefiles_mkdir_histogram[HZ];
174extern atomic_t cachefiles_create_histogram[HZ];
175
176extern int __init cachefiles_proc_init(void);
177extern void cachefiles_proc_cleanup(void);
178static inline
179void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
180{
181 unsigned long jif = jiffies - start_jif;
182 if (jif >= HZ)
183 jif = HZ - 1;
184 atomic_inc(&histogram[jif]);
185}
186
187#else
188#define cachefiles_proc_init() (0)
189#define cachefiles_proc_cleanup() do {} while (0)
190#define cachefiles_hist(hist, start_jif) do {} while (0)
191#endif
192
193/*
194 * rdwr.c
195 */
196extern int cachefiles_read_or_alloc_page(struct fscache_retrieval *,
197 struct page *, gfp_t);
198extern int cachefiles_read_or_alloc_pages(struct fscache_retrieval *,
199 struct list_head *, unsigned *,
200 gfp_t);
201extern int cachefiles_allocate_page(struct fscache_retrieval *, struct page *,
202 gfp_t);
203extern int cachefiles_allocate_pages(struct fscache_retrieval *,
204 struct list_head *, unsigned *, gfp_t);
205extern int cachefiles_write_page(struct fscache_storage *, struct page *);
206extern void cachefiles_uncache_page(struct fscache_object *, struct page *);
207
208/*
209 * security.c
210 */
211extern int cachefiles_get_security_ID(struct cachefiles_cache *cache);
212extern int cachefiles_determine_cache_security(struct cachefiles_cache *cache,
213 struct dentry *root,
214 const struct cred **_saved_cred);
215
216static inline void cachefiles_begin_secure(struct cachefiles_cache *cache,
217 const struct cred **_saved_cred)
218{
219 *_saved_cred = override_creds(cache->cache_cred);
220}
221
222static inline void cachefiles_end_secure(struct cachefiles_cache *cache,
223 const struct cred *saved_cred)
224{
225 revert_creds(saved_cred);
226}
227
228/*
229 * xattr.c
230 */
231extern int cachefiles_check_object_type(struct cachefiles_object *object);
232extern int cachefiles_set_object_xattr(struct cachefiles_object *object,
233 struct cachefiles_xattr *auxdata);
234extern int cachefiles_update_object_xattr(struct cachefiles_object *object,
235 struct cachefiles_xattr *auxdata);
236extern int cachefiles_check_object_xattr(struct cachefiles_object *object,
237 struct cachefiles_xattr *auxdata);
238extern int cachefiles_remove_object_xattr(struct cachefiles_cache *cache,
239 struct dentry *dentry);
240
241
242/*
243 * error handling
244 */
245#define kerror(FMT, ...) printk(KERN_ERR "CacheFiles: "FMT"\n", ##__VA_ARGS__)
246
247#define cachefiles_io_error(___cache, FMT, ...) \
248do { \
249 kerror("I/O Error: " FMT, ##__VA_ARGS__); \
250 fscache_io_error(&(___cache)->cache); \
251 set_bit(CACHEFILES_DEAD, &(___cache)->flags); \
252} while (0)
253
254#define cachefiles_io_error_obj(object, FMT, ...) \
255do { \
256 struct cachefiles_cache *___cache; \
257 \
258 ___cache = container_of((object)->fscache.cache, \
259 struct cachefiles_cache, cache); \
260 cachefiles_io_error(___cache, FMT, ##__VA_ARGS__); \
261} while (0)
262
263
264/*
265 * debug tracing
266 */
267#define dbgprintk(FMT, ...) \
268 printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
269
270#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
271#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
272#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
273
274
275#if defined(__KDEBUG)
276#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
277#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
278#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
279
280#elif defined(CONFIG_CACHEFILES_DEBUG)
281#define _enter(FMT, ...) \
282do { \
283 if (cachefiles_debug & CACHEFILES_DEBUG_KENTER) \
284 kenter(FMT, ##__VA_ARGS__); \
285} while (0)
286
287#define _leave(FMT, ...) \
288do { \
289 if (cachefiles_debug & CACHEFILES_DEBUG_KLEAVE) \
290 kleave(FMT, ##__VA_ARGS__); \
291} while (0)
292
293#define _debug(FMT, ...) \
294do { \
295 if (cachefiles_debug & CACHEFILES_DEBUG_KDEBUG) \
296 kdebug(FMT, ##__VA_ARGS__); \
297} while (0)
298
299#else
300#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
301#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
302#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
303#endif
304
305#if 1 /* defined(__KDEBUGALL) */
306
307#define ASSERT(X) \
308do { \
309 if (unlikely(!(X))) { \
310 printk(KERN_ERR "\n"); \
311 printk(KERN_ERR "CacheFiles: Assertion failed\n"); \
312 BUG(); \
313 } \
314} while (0)
315
316#define ASSERTCMP(X, OP, Y) \
317do { \
318 if (unlikely(!((X) OP (Y)))) { \
319 printk(KERN_ERR "\n"); \
320 printk(KERN_ERR "CacheFiles: Assertion failed\n"); \
321 printk(KERN_ERR "%lx " #OP " %lx is false\n", \
322 (unsigned long)(X), (unsigned long)(Y)); \
323 BUG(); \
324 } \
325} while (0)
326
327#define ASSERTIF(C, X) \
328do { \
329 if (unlikely((C) && !(X))) { \
330 printk(KERN_ERR "\n"); \
331 printk(KERN_ERR "CacheFiles: Assertion failed\n"); \
332 BUG(); \
333 } \
334} while (0)
335
336#define ASSERTIFCMP(C, X, OP, Y) \
337do { \
338 if (unlikely((C) && !((X) OP (Y)))) { \
339 printk(KERN_ERR "\n"); \
340 printk(KERN_ERR "CacheFiles: Assertion failed\n"); \
341 printk(KERN_ERR "%lx " #OP " %lx is false\n", \
342 (unsigned long)(X), (unsigned long)(Y)); \
343 BUG(); \
344 } \
345} while (0)
346
347#else
348
349#define ASSERT(X) do {} while (0)
350#define ASSERTCMP(X, OP, Y) do {} while (0)
351#define ASSERTIF(C, X) do {} while (0)
352#define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
353
354#endif