[JFFS2] Debug code clean up - step 3
[deliverable/linux.git] / fs / jffs2 / debug.h
1 /*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001-2003 Red Hat, Inc.
5 *
6 * Created by David Woodhouse <dwmw2@infradead.org>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
10 * $Id: debug.h,v 1.5 2005/07/24 15:14:14 dedekind Exp $
11 *
12 */
13 #ifndef _JFFS2_DEBUG_H_
14 #define _JFFS2_DEBUG_H_
15
16 #include <linux/config.h>
17
18 /* ------------------------------------------------ */
19 /* TODO: remove */
20 #undef CONFIG_JFFS2_FS_DEBUG
21 #define CONFIG_JFFS2_FS_DEBUG 0
22 //#define JFFS2_DBG_PARANOIA_CHECKS
23 //#define JFFS2_DBG_DUMPS
24 #define JFFS2_DBG_READINODE_MESSAGES
25 //#define JFFS2_DBG_FRAGTREE_MESSAGES
26 //#define JFFS2_DBG_FRAGTREE2_MESSAGES
27 #undef KERN_DEBUG
28 #undef KERN_WARNING
29 #undef KERN_NOTICE
30 #undef KERN_ERR
31 #define KERN_DEBUG KERN_CRIT
32 #define KERN_WARNING KERN_CRIT
33 #define KERN_NOTICE KERN_CRIT
34 #define KERN_ERR KERN_CRIT
35 /* ------------------------------------------------ */
36
37 #ifndef CONFIG_JFFS2_FS_DEBUG
38 #define CONFIG_JFFS2_FS_DEBUG 1
39 #endif
40
41 #if CONFIG_JFFS2_FS_DEBUG == 1
42 /* Enable "paranoia" checks and dumps */
43 #define JFFS2_DBG_PARANOIA_CHECKS
44 #define JFFS2_DBG_DUMPS
45 #define JFFS2_DBG_READINODE_MESSAGES
46 #define JFFS2_DBG_FRAGTREE_MESSAGES
47 #define JFFS2_DBG_DENTLIST_MESSAGES
48 #define JFFS2_DBG_NODEREF_MESSAGES
49 #define JFFS2_DBG_INOCACHE_MESSAGES
50 #endif
51
52 #if CONFIG_JFFS2_FS_DEBUG == 2
53 #define JFFS2_DBG_FRAGTREE2_MESSAGES
54 #endif
55
56 /* Enable JFFS2 sanity checks by default */
57 #define JFFS2_DBG_SANITY_CHECKS
58
59 /*
60 * Dx() are mainly used for debugging messages, they must go away and be
61 * superseded by nicer JFFS2_DBG_XXX() macros...
62 */
63 #if CONFIG_JFFS2_FS_DEBUG > 0
64 #define D1(x) x
65 #else
66 #define D1(x)
67 #endif
68
69 #if CONFIG_JFFS2_FS_DEBUG > 1
70 #define D2(x) x
71 #else
72 #define D2(x)
73 #endif
74
75 /* The prefixes of JFFS2 messages */
76 #define JFFS2_DBG_MSG_PREFIX "[JFFS2 DBG]"
77 #define JFFS2_ERR_MSG_PREFIX "JFFS2 error: "
78 #define JFFS2_WARN_MSG_PREFIX "JFFS2 warning: "
79 #define JFFS2_NOTICE_MSG_PREFIX "JFFS2 notice: "
80
81 #define JFFS2_ERR_LVL KERN_ERR
82 #define JFFS2_WARN_LVL KERN_WARNING
83 #define JFFS2_NOTICE_LVL KERN_NOTICE
84 #define JFFS2_DBG_LVL KERN_DEBUG
85
86 /* JFFS2 message macros */
87 #define JFFS2_ERROR(fmt, ...) \
88 do { \
89 printk(JFFS2_ERR_LVL JFFS2_ERR_MSG_PREFIX " %s: " \
90 fmt, __FUNCTION__, ##__VA_ARGS__); \
91 } while(0)
92
93 #define JFFS2_WARNING(fmt, ...) \
94 do { \
95 printk(JFFS2_WARN_LVL JFFS2_WARN_MSG_PREFIX " %s: " \
96 fmt, __FUNCTION__, ##__VA_ARGS__); \
97 } while(0)
98
99 #define JFFS2_NOTICE(fmt, ...) \
100 do { \
101 printk(JFFS2_NOTICE_LVL JFFS2_NOTICE_MSG_PREFIX " %s: " \
102 fmt, __FUNCTION__, ##__VA_ARGS__); \
103 } while(0)
104
105 #define JFFS2_DEBUG(fmt, ...) \
106 do { \
107 printk(JFFS2_DBG_LVL JFFS2_DBG_MSG_PREFIX " %s: " \
108 fmt, __FUNCTION__, ##__VA_ARGS__); \
109 } while(0)
110
111 /*
112 * We split our debugging messages on several parts, depending on the JFFS2
113 * subsystem the message belongs to.
114 */
115 /* Read inode debugging messages */
116 #ifdef JFFS2_DBG_READINODE_MESSAGES
117 #define JFFS2_DBG_READINODE(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
118 #else
119 #define JFFS2_DBG_READINODE(fmt, ...)
120 #endif
121
122 /* Fragtree build debugging messages */
123 #ifdef JFFS2_DBG_FRAGTREE_MESSAGES
124 #define JFFS2_DBG_FRAGTREE(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
125 #else
126 #define JFFS2_DBG_FRAGTREE(fmt, ...)
127 #endif
128
129 /* Directory entry list manilulation debugging messages */
130 #ifdef JFFS2_DBG_DENTLIST_MESSAGES
131 #define JFFS2_DBG_DENTLIST(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
132 #else
133 #define JFFS2_DBG_DENTLIST(fmt, ...)
134 #endif
135 #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
136 #define JFFS2_DBG_FRAGTREE2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
137 #else
138 #define JFFS2_DBG_FRAGTREE2(fmt, ...)
139 #endif
140
141 /* Plays with node_refs */
142 #ifdef JFFS2_DBG_NODEREF_MESSAGES
143 #define JFFS2_DBG_NODEREF(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
144 #else
145 #define JFFS2_DBG_NODEREF(fmt, ...)
146 #endif
147
148 /* Plays with the list of inodes (JFFS2 inocache) */
149 #ifdef JFFS2_DBG_INOCACHE_MESSAGES
150 #define JFFS2_DBG_INOCACHE(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
151 #else
152 #define JFFS2_DBG_INOCACHE(fmt, ...)
153 #endif
154
155 /* "Paranoia" checks */
156 void
157 __jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f);
158 void
159 __jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f);
160 void
161 __jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c,
162 struct jffs2_eraseblock *jeb);
163 void
164 __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
165 struct jffs2_eraseblock *jeb);
166 void
167 __jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
168 uint32_t ofs, int len);
169
170 /* "Dump" functions */
171 void
172 __jffs2_dbg_dump_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
173 void
174 __jffs2_dbg_dump_jeb_nolock(struct jffs2_eraseblock *jeb);
175 void
176 __jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c);
177 void
178 __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c);
179 void
180 __jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c,
181 struct jffs2_eraseblock *jeb);
182 void
183 __jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
184 struct jffs2_eraseblock *jeb);
185 void
186 __jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f);
187 void
188 __jffs2_dbg_dump_fragtree_nolock(struct jffs2_inode_info *f);
189 void
190 __jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs);
191 void
192 __jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs);
193
194 #ifdef JFFS2_DBG_PARANOIA_CHECKS
195 #define jffs2_dbg_fragtree_paranoia_check(f) \
196 __jffs2_dbg_fragtree_paranoia_check(f)
197 #define jffs2_dbg_fragtree_paranoia_check_nolock(f) \
198 __jffs2_dbg_fragtree_paranoia_check_nolock(f)
199 #define jffs2_dbg_acct_paranoia_check(c, jeb) \
200 __jffs2_dbg_acct_paranoia_check(c,jeb)
201 #define jffs2_dbg_acct_paranoia_check_nolock(c, jeb) \
202 __jffs2_dbg_acct_paranoia_check_nolock(c,jeb)
203 #define jffs2_dbg_prewrite_paranoia_check(c, ofs, len) \
204 __jffs2_dbg_prewrite_paranoia_check(c, ofs, len)
205 #else
206 #define jffs2_dbg_fragtree_paranoia_check(f)
207 #define jffs2_dbg_fragtree_paranoia_check_nolock(f)
208 #define jffs2_dbg_acct_paranoia_check(c, jeb)
209 #define jffs2_dbg_acct_paranoia_check_nolock(c, jeb)
210 #define jffs2_dbg_prewrite_paranoia_check(c, ofs, len)
211 #endif /* !JFFS2_PARANOIA_CHECKS */
212
213 #ifdef JFFS2_DBG_DUMPS
214 #define jffs2_dbg_dump_jeb(c, jeb) \
215 __jffs2_dbg_dump_jeb(c, jeb);
216 #define jffs2_dbg_dump_jeb_nolock(jeb) \
217 __jffs2_dbg_dump_jeb_nolock(jeb);
218 #define jffs2_dbg_dump_block_lists(c) \
219 __jffs2_dbg_dump_block_lists(c)
220 #define jffs2_dbg_dump_block_lists_nolock(c) \
221 __jffs2_dbg_dump_block_lists_nolock(c)
222 #define jffs2_dbg_dump_fragtree(f) \
223 __jffs2_dbg_dump_fragtree(f);
224 #define jffs2_dbg_dump_fragtree_nolock(f) \
225 __jffs2_dbg_dump_fragtree_nolock(f);
226 #define jffs2_dbg_dump_buffer(buf, len, offs) \
227 __jffs2_dbg_dump_buffer(*buf, len, offs);
228 #define jffs2_dbg_dump_node(c, ofs) \
229 __jffs2_dbg_dump_node(c, ofs);
230 #else
231 #define jffs2_dbg_dump_jeb(c, jeb)
232 #define jffs2_dbg_dump_jeb_nolock(jeb)
233 #define jffs2_dbg_dump_block_lists(c)
234 #define jffs2_dbg_dump_block_lists_nolock(c)
235 #define jffs2_dbg_dump_fragtree(f)
236 #define jffs2_dbg_dump_fragtree_nolock(f)
237 #define jffs2_dbg_dump_buffer(buf, len, offs)
238 #define jffs2_dbg_dump_node(c, ofs)
239 #endif /* !JFFS2_DBG_DUMPS */
240
241 /*
242 * Sanity checks are supposed to be light-weight and enabled by default.
243 */
244 #ifdef JFFS2_DBG_SANITY_CHECKS
245 /*
246 * Check the space accounting of the file system and of
247 * the JFFS2 erasable block 'jeb'.
248 */
249 static inline void
250 jffs2_dbg_acct_sanity_check_nolock(struct jffs2_sb_info *c,
251 struct jffs2_eraseblock *jeb)
252 {
253 if (unlikely(jeb && jeb->used_size + jeb->dirty_size +
254 jeb->free_size + jeb->wasted_size +
255 jeb->unchecked_size != c->sector_size)) {
256 JFFS2_ERROR("eeep, space accounting for block at 0x%08x is screwed.\n", jeb->offset);
257 JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + wasted %#08x + unchecked "
258 "%#08x != total %#08x.\n", jeb->free_size, jeb->dirty_size, jeb->used_size,
259 jeb->wasted_size, jeb->unchecked_size, c->sector_size);
260 BUG();
261 }
262
263 if (unlikely(c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size
264 + c->wasted_size + c->unchecked_size != c->flash_size)) {
265 JFFS2_ERROR("eeep, space accounting superblock info is screwed.\n");
266 JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + erasing %#08x + bad %#08x + "
267 "wasted %#08x + unchecked %#08x != total %#08x.\n",
268 c->free_size, c->dirty_size, c->used_size, c->erasing_size, c->bad_size,
269 c->wasted_size, c->unchecked_size, c->flash_size);
270 BUG();
271 }
272 }
273
274 static inline void
275 jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c,
276 struct jffs2_eraseblock *jeb)
277 {
278 spin_lock(&c->erase_completion_lock);
279 jffs2_dbg_acct_sanity_check_nolock(c, jeb);
280 spin_unlock(&c->erase_completion_lock);
281 }
282 #else
283 #define jffs2_dbg_acct_sanity_check(c, jeb)
284 #define jffs2_dbg_acct_sanity_check_nolock(c, jeb)
285 #endif /* !JFFS2_DBG_SANITY_CHECKS */
286
287 #endif /* _JFFS2_DEBUG_H_ */
This page took 0.056824 seconds and 5 git commands to generate.