FS-Cache: Add main configuration option, module entry points and debugging
[linux-2.6/linux-loongson.git] / fs / fscache / internal.h
blob95dc92da7152937ceafc62b42b25f8ea6409cb12
1 /* Internal definitions for FS-Cache
3 * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
13 * Lock order, in the order in which multiple locks should be obtained:
14 * - fscache_addremove_sem
15 * - cookie->lock
16 * - cookie->parent->lock
17 * - cache->object_list_lock
18 * - object->lock
19 * - object->parent->lock
20 * - fscache_thread_lock
24 #include <linux/fscache-cache.h>
25 #include <linux/sched.h>
27 #define FSCACHE_MIN_THREADS 4
28 #define FSCACHE_MAX_THREADS 32
31 * fsc-main.c
33 extern unsigned fscache_defer_lookup;
34 extern unsigned fscache_defer_create;
35 extern unsigned fscache_debug;
36 extern struct kobject *fscache_root;
38 /*****************************************************************************/
40 * debug tracing
42 #define dbgprintk(FMT, ...) \
43 printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
45 /* make sure we maintain the format strings, even when debugging is disabled */
46 static inline __attribute__((format(printf, 1, 2)))
47 void _dbprintk(const char *fmt, ...)
51 #define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
52 #define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
53 #define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
55 #define kjournal(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__)
57 #ifdef __KDEBUG
58 #define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
59 #define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
60 #define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
62 #elif defined(CONFIG_FSCACHE_DEBUG)
63 #define _enter(FMT, ...) \
64 do { \
65 if (__do_kdebug(ENTER)) \
66 kenter(FMT, ##__VA_ARGS__); \
67 } while (0)
69 #define _leave(FMT, ...) \
70 do { \
71 if (__do_kdebug(LEAVE)) \
72 kleave(FMT, ##__VA_ARGS__); \
73 } while (0)
75 #define _debug(FMT, ...) \
76 do { \
77 if (__do_kdebug(DEBUG)) \
78 kdebug(FMT, ##__VA_ARGS__); \
79 } while (0)
81 #else
82 #define _enter(FMT, ...) _dbprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
83 #define _leave(FMT, ...) _dbprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
84 #define _debug(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__)
85 #endif
88 * determine whether a particular optional debugging point should be logged
89 * - we need to go through three steps to persuade cpp to correctly join the
90 * shorthand in FSCACHE_DEBUG_LEVEL with its prefix
92 #define ____do_kdebug(LEVEL, POINT) \
93 unlikely((fscache_debug & \
94 (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
95 #define ___do_kdebug(LEVEL, POINT) \
96 ____do_kdebug(LEVEL, POINT)
97 #define __do_kdebug(POINT) \
98 ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
100 #define FSCACHE_DEBUG_CACHE 0
101 #define FSCACHE_DEBUG_COOKIE 1
102 #define FSCACHE_DEBUG_PAGE 2
103 #define FSCACHE_DEBUG_OPERATION 3
105 #define FSCACHE_POINT_ENTER 1
106 #define FSCACHE_POINT_LEAVE 2
107 #define FSCACHE_POINT_DEBUG 4
109 #ifndef FSCACHE_DEBUG_LEVEL
110 #define FSCACHE_DEBUG_LEVEL CACHE
111 #endif
114 * assertions
116 #if 1 /* defined(__KDEBUGALL) */
118 #define ASSERT(X) \
119 do { \
120 if (unlikely(!(X))) { \
121 printk(KERN_ERR "\n"); \
122 printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
123 BUG(); \
125 } while (0)
127 #define ASSERTCMP(X, OP, Y) \
128 do { \
129 if (unlikely(!((X) OP (Y)))) { \
130 printk(KERN_ERR "\n"); \
131 printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
132 printk(KERN_ERR "%lx " #OP " %lx is false\n", \
133 (unsigned long)(X), (unsigned long)(Y)); \
134 BUG(); \
136 } while (0)
138 #define ASSERTIF(C, X) \
139 do { \
140 if (unlikely((C) && !(X))) { \
141 printk(KERN_ERR "\n"); \
142 printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
143 BUG(); \
145 } while (0)
147 #define ASSERTIFCMP(C, X, OP, Y) \
148 do { \
149 if (unlikely((C) && !((X) OP (Y)))) { \
150 printk(KERN_ERR "\n"); \
151 printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
152 printk(KERN_ERR "%lx " #OP " %lx is false\n", \
153 (unsigned long)(X), (unsigned long)(Y)); \
154 BUG(); \
156 } while (0)
158 #else
160 #define ASSERT(X) do {} while (0)
161 #define ASSERTCMP(X, OP, Y) do {} while (0)
162 #define ASSERTIF(C, X) do {} while (0)
163 #define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
165 #endif /* assert or not */