xref: /openbmc/linux/fs/jffs2/debug.h (revision cd6d421e)
1 /*
2  * JFFS2 -- Journalling Flash File System, Version 2.
3  *
4  * Copyright © 2001-2007 Red Hat, Inc.
5  * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
6  *
7  * Created by David Woodhouse <dwmw2@infradead.org>
8  *
9  * For licensing information, see the file 'LICENCE' in this directory.
10  *
11  */
12 
13 #ifndef _JFFS2_DEBUG_H_
14 #define _JFFS2_DEBUG_H_
15 
16 #include <linux/printk.h>
17 #include <linux/sched.h>
18 
19 #ifndef CONFIG_JFFS2_FS_DEBUG
20 #define CONFIG_JFFS2_FS_DEBUG 0
21 #endif
22 
23 #if CONFIG_JFFS2_FS_DEBUG > 0
24 /* Enable "paranoia" checks and dumps */
25 #define JFFS2_DBG_PARANOIA_CHECKS
26 #define JFFS2_DBG_DUMPS
27 
28 /*
29  * By defining/undefining the below macros one may select debugging messages
30  * fro specific JFFS2 subsystems.
31  */
32 #define JFFS2_DBG_READINODE_MESSAGES
33 #define JFFS2_DBG_FRAGTREE_MESSAGES
34 #define JFFS2_DBG_DENTLIST_MESSAGES
35 #define JFFS2_DBG_NODEREF_MESSAGES
36 #define JFFS2_DBG_INOCACHE_MESSAGES
37 #define JFFS2_DBG_SUMMARY_MESSAGES
38 #define JFFS2_DBG_FSBUILD_MESSAGES
39 #endif
40 
41 #if CONFIG_JFFS2_FS_DEBUG > 1
42 #define JFFS2_DBG_FRAGTREE2_MESSAGES
43 #define JFFS2_DBG_READINODE2_MESSAGES
44 #define JFFS2_DBG_MEMALLOC_MESSAGES
45 #endif
46 
47 /* Sanity checks are supposed to be light-weight and enabled by default */
48 #define JFFS2_DBG_SANITY_CHECKS
49 
50 /*
51  * Dx() are mainly used for debugging messages, they must go away and be
52  * superseded by nicer dbg_xxx() macros...
53  */
54 #if CONFIG_JFFS2_FS_DEBUG > 0
55 #define DEBUG
56 #define D1(x) x
57 #else
58 #define D1(x)
59 #endif
60 
61 #if CONFIG_JFFS2_FS_DEBUG > 1
62 #define D2(x) x
63 #else
64 #define D2(x)
65 #endif
66 
67 #define jffs2_dbg(level, fmt, ...)		\
68 do {						\
69 	if (CONFIG_JFFS2_FS_DEBUG >= level)	\
70 		pr_debug(fmt, ##__VA_ARGS__);	\
71 } while (0)
72 
73 /* The prefixes of JFFS2 messages */
74 #define JFFS2_DBG		KERN_DEBUG
75 #define JFFS2_DBG_PREFIX	"[JFFS2 DBG]"
76 #define JFFS2_DBG_MSG_PREFIX	JFFS2_DBG JFFS2_DBG_PREFIX
77 
78 /* JFFS2 message macros */
79 #define JFFS2_ERROR(fmt, ...)					\
80 	pr_err("error: (%d) %s: " fmt,				\
81 	       task_pid_nr(current), __func__, ##__VA_ARGS__)
82 
83 #define JFFS2_WARNING(fmt, ...)						\
84 	pr_warn("warning: (%d) %s: " fmt,				\
85 		task_pid_nr(current), __func__, ##__VA_ARGS__)
86 
87 #define JFFS2_NOTICE(fmt, ...)						\
88 	pr_notice("notice: (%d) %s: " fmt,				\
89 		  task_pid_nr(current), __func__, ##__VA_ARGS__)
90 
91 #define JFFS2_DEBUG(fmt, ...)						\
92 	printk(KERN_DEBUG "[JFFS2 DBG] (%d) %s: " fmt,			\
93 	       task_pid_nr(current), __func__, ##__VA_ARGS__)
94 
95 /*
96  * We split our debugging messages on several parts, depending on the JFFS2
97  * subsystem the message belongs to.
98  */
99 /* Read inode debugging messages */
100 #ifdef JFFS2_DBG_READINODE_MESSAGES
101 #define dbg_readinode(fmt, ...)	JFFS2_DEBUG(fmt, ##__VA_ARGS__)
102 #else
103 #define dbg_readinode(fmt, ...)	no_printk(fmt, ##__VA_ARGS__)
104 #endif
105 #ifdef JFFS2_DBG_READINODE2_MESSAGES
106 #define dbg_readinode2(fmt, ...)	JFFS2_DEBUG(fmt, ##__VA_ARGS__)
107 #else
108 #define dbg_readinode2(fmt, ...)	no_printk(fmt, ##__VA_ARGS__)
109 #endif
110 
111 /* Fragtree build debugging messages */
112 #ifdef JFFS2_DBG_FRAGTREE_MESSAGES
113 #define dbg_fragtree(fmt, ...)	JFFS2_DEBUG(fmt, ##__VA_ARGS__)
114 #else
115 #define dbg_fragtree(fmt, ...)	no_printk(fmt, ##__VA_ARGS__)
116 #endif
117 #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
118 #define dbg_fragtree2(fmt, ...)	JFFS2_DEBUG(fmt, ##__VA_ARGS__)
119 #else
120 #define dbg_fragtree2(fmt, ...)	no_printk(fmt, ##__VA_ARGS__)
121 #endif
122 
123 /* Directory entry list manilulation debugging messages */
124 #ifdef JFFS2_DBG_DENTLIST_MESSAGES
125 #define dbg_dentlist(fmt, ...)	JFFS2_DEBUG(fmt, ##__VA_ARGS__)
126 #else
127 #define dbg_dentlist(fmt, ...)	no_printk(fmt, ##__VA_ARGS__)
128 #endif
129 
130 /* Print the messages about manipulating node_refs */
131 #ifdef JFFS2_DBG_NODEREF_MESSAGES
132 #define dbg_noderef(fmt, ...)	JFFS2_DEBUG(fmt, ##__VA_ARGS__)
133 #else
134 #define dbg_noderef(fmt, ...)	no_printk(fmt, ##__VA_ARGS__)
135 #endif
136 
137 /* Manipulations with the list of inodes (JFFS2 inocache) */
138 #ifdef JFFS2_DBG_INOCACHE_MESSAGES
139 #define dbg_inocache(fmt, ...)	JFFS2_DEBUG(fmt, ##__VA_ARGS__)
140 #else
141 #define dbg_inocache(fmt, ...)	no_printk(fmt, ##__VA_ARGS__)
142 #endif
143 
144 /* Summary debugging messages */
145 #ifdef JFFS2_DBG_SUMMARY_MESSAGES
146 #define dbg_summary(fmt, ...)	JFFS2_DEBUG(fmt, ##__VA_ARGS__)
147 #else
148 #define dbg_summary(fmt, ...)	no_printk(fmt, ##__VA_ARGS__)
149 #endif
150 
151 /* File system build messages */
152 #ifdef JFFS2_DBG_FSBUILD_MESSAGES
153 #define dbg_fsbuild(fmt, ...)	JFFS2_DEBUG(fmt, ##__VA_ARGS__)
154 #else
155 #define dbg_fsbuild(fmt, ...)	no_printk(fmt, ##__VA_ARGS__)
156 #endif
157 
158 /* Watch the object allocations */
159 #ifdef JFFS2_DBG_MEMALLOC_MESSAGES
160 #define dbg_memalloc(fmt, ...)	JFFS2_DEBUG(fmt, ##__VA_ARGS__)
161 #else
162 #define dbg_memalloc(fmt, ...)	no_printk(fmt, ##__VA_ARGS__)
163 #endif
164 
165 /* Watch the XATTR subsystem */
166 #ifdef JFFS2_DBG_XATTR_MESSAGES
167 #define dbg_xattr(fmt, ...)  JFFS2_DEBUG(fmt, ##__VA_ARGS__)
168 #else
169 #define dbg_xattr(fmt, ...)  no_printk(fmt, ##__VA_ARGS__)
170 #endif
171 
172 /* "Sanity" checks */
173 void
174 __jffs2_dbg_acct_sanity_check_nolock(struct jffs2_sb_info *c,
175 				     struct jffs2_eraseblock *jeb);
176 void
177 __jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c,
178 			      struct jffs2_eraseblock *jeb);
179 
180 /* "Paranoia" checks */
181 void
182 __jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f);
183 void
184 __jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f);
185 void
186 __jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c,
187 			   	struct jffs2_eraseblock *jeb);
188 void
189 __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
190 				       struct jffs2_eraseblock *jeb);
191 void
192 __jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
193 				    uint32_t ofs, int len);
194 
195 /* "Dump" functions */
196 void
197 __jffs2_dbg_dump_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
198 void
199 __jffs2_dbg_dump_jeb_nolock(struct jffs2_eraseblock *jeb);
200 void
201 __jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c);
202 void
203 __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c);
204 void
205 __jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c,
206 		 	   struct jffs2_eraseblock *jeb);
207 void
208 __jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
209 				  struct jffs2_eraseblock *jeb);
210 void
211 __jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f);
212 void
213 __jffs2_dbg_dump_fragtree_nolock(struct jffs2_inode_info *f);
214 void
215 __jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs);
216 void
217 __jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs);
218 
219 #ifdef JFFS2_DBG_PARANOIA_CHECKS
220 #define jffs2_dbg_fragtree_paranoia_check(f)			\
221 	__jffs2_dbg_fragtree_paranoia_check(f)
222 #define jffs2_dbg_fragtree_paranoia_check_nolock(f)		\
223 	__jffs2_dbg_fragtree_paranoia_check_nolock(f)
224 #define jffs2_dbg_acct_paranoia_check(c, jeb)			\
225 	__jffs2_dbg_acct_paranoia_check(c,jeb)
226 #define jffs2_dbg_acct_paranoia_check_nolock(c, jeb)		\
227 	__jffs2_dbg_acct_paranoia_check_nolock(c,jeb)
228 #define jffs2_dbg_prewrite_paranoia_check(c, ofs, len)		\
229 	__jffs2_dbg_prewrite_paranoia_check(c, ofs, len)
230 #else
231 #define jffs2_dbg_fragtree_paranoia_check(f)
232 #define jffs2_dbg_fragtree_paranoia_check_nolock(f)
233 #define jffs2_dbg_acct_paranoia_check(c, jeb)
234 #define jffs2_dbg_acct_paranoia_check_nolock(c, jeb)
235 #define jffs2_dbg_prewrite_paranoia_check(c, ofs, len)
236 #endif /* !JFFS2_PARANOIA_CHECKS */
237 
238 #ifdef JFFS2_DBG_DUMPS
239 #define jffs2_dbg_dump_jeb(c, jeb)				\
240 	__jffs2_dbg_dump_jeb(c, jeb);
241 #define jffs2_dbg_dump_jeb_nolock(jeb)				\
242 	__jffs2_dbg_dump_jeb_nolock(jeb);
243 #define jffs2_dbg_dump_block_lists(c)				\
244 	__jffs2_dbg_dump_block_lists(c)
245 #define jffs2_dbg_dump_block_lists_nolock(c)			\
246 	__jffs2_dbg_dump_block_lists_nolock(c)
247 #define jffs2_dbg_dump_fragtree(f)				\
248 	__jffs2_dbg_dump_fragtree(f);
249 #define jffs2_dbg_dump_fragtree_nolock(f)			\
250 	__jffs2_dbg_dump_fragtree_nolock(f);
251 #define jffs2_dbg_dump_buffer(buf, len, offs)			\
252 	__jffs2_dbg_dump_buffer(*buf, len, offs);
253 #define jffs2_dbg_dump_node(c, ofs)				\
254 	__jffs2_dbg_dump_node(c, ofs);
255 #else
256 #define jffs2_dbg_dump_jeb(c, jeb)
257 #define jffs2_dbg_dump_jeb_nolock(jeb)
258 #define jffs2_dbg_dump_block_lists(c)
259 #define jffs2_dbg_dump_block_lists_nolock(c)
260 #define jffs2_dbg_dump_fragtree(f)
261 #define jffs2_dbg_dump_fragtree_nolock(f)
262 #define jffs2_dbg_dump_buffer(buf, len, offs)
263 #define jffs2_dbg_dump_node(c, ofs)
264 #endif /* !JFFS2_DBG_DUMPS */
265 
266 #ifdef JFFS2_DBG_SANITY_CHECKS
267 #define jffs2_dbg_acct_sanity_check(c, jeb)			\
268 	__jffs2_dbg_acct_sanity_check(c, jeb)
269 #define jffs2_dbg_acct_sanity_check_nolock(c, jeb)		\
270 	__jffs2_dbg_acct_sanity_check_nolock(c, jeb)
271 #else
272 #define jffs2_dbg_acct_sanity_check(c, jeb)
273 #define jffs2_dbg_acct_sanity_check_nolock(c, jeb)
274 #endif /* !JFFS2_DBG_SANITY_CHECKS */
275 
276 #endif /* _JFFS2_DEBUG_H_ */
277