]>
Commit | Line | Data |
---|---|---|
9eefe2a2 SR |
1 | /* |
2 | * This file is part of UBIFS. | |
3 | * | |
4 | * Copyright (C) 2006-2008 Nokia Corporation. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License version 2 as published by | |
8 | * the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along with | |
16 | * this program; if not, write to the Free Software Foundation, Inc., 51 | |
17 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | * | |
19 | * Authors: Artem Bityutskiy (Битюцкий Артём) | |
20 | * Adrian Hunter | |
21 | */ | |
22 | ||
23 | #ifndef __UBIFS_DEBUG_H__ | |
24 | #define __UBIFS_DEBUG_H__ | |
25 | ||
26 | #ifdef CONFIG_UBIFS_FS_DEBUG | |
27 | ||
28 | /** | |
29 | * ubifs_debug_info - per-FS debugging information. | |
30 | * @buf: a buffer of LEB size, used for various purposes | |
31 | * @old_zroot: old index root - used by 'dbg_check_old_index()' | |
32 | * @old_zroot_level: old index root level - used by 'dbg_check_old_index()' | |
33 | * @old_zroot_sqnum: old index root sqnum - used by 'dbg_check_old_index()' | |
34 | * @failure_mode: failure mode for recovery testing | |
35 | * @fail_delay: 0=>don't delay, 1=>delay a time, 2=>delay a number of calls | |
36 | * @fail_timeout: time in jiffies when delay of failure mode expires | |
37 | * @fail_cnt: current number of calls to failure mode I/O functions | |
38 | * @fail_cnt_max: number of calls by which to delay failure mode | |
39 | * @chk_lpt_sz: used by LPT tree size checker | |
40 | * @chk_lpt_sz2: used by LPT tree size checker | |
41 | * @chk_lpt_wastage: used by LPT tree size checker | |
42 | * @chk_lpt_lebs: used by LPT tree size checker | |
43 | * @new_nhead_offs: used by LPT tree size checker | |
44 | * @new_ihead_lnum: used by debugging to check @c->ihead_lnum | |
45 | * @new_ihead_offs: used by debugging to check @c->ihead_offs | |
46 | * | |
47 | * @saved_lst: saved lprops statistics (used by 'dbg_save_space_info()') | |
48 | * @saved_free: saved free space (used by 'dbg_save_space_info()') | |
49 | * | |
50 | * dfs_dir_name: name of debugfs directory containing this file-system's files | |
51 | * dfs_dir: direntry object of the file-system debugfs directory | |
52 | * dfs_dump_lprops: "dump lprops" debugfs knob | |
53 | * dfs_dump_budg: "dump budgeting information" debugfs knob | |
54 | * dfs_dump_tnc: "dump TNC" debugfs knob | |
55 | */ | |
56 | struct ubifs_debug_info { | |
57 | void *buf; | |
58 | struct ubifs_zbranch old_zroot; | |
59 | int old_zroot_level; | |
60 | unsigned long long old_zroot_sqnum; | |
61 | int failure_mode; | |
62 | int fail_delay; | |
63 | unsigned long fail_timeout; | |
64 | unsigned int fail_cnt; | |
65 | unsigned int fail_cnt_max; | |
66 | long long chk_lpt_sz; | |
67 | long long chk_lpt_sz2; | |
68 | long long chk_lpt_wastage; | |
69 | int chk_lpt_lebs; | |
70 | int new_nhead_offs; | |
71 | int new_ihead_lnum; | |
72 | int new_ihead_offs; | |
73 | ||
74 | struct ubifs_lp_stats saved_lst; | |
75 | long long saved_free; | |
76 | ||
77 | char dfs_dir_name[100]; | |
78 | struct dentry *dfs_dir; | |
79 | struct dentry *dfs_dump_lprops; | |
80 | struct dentry *dfs_dump_budg; | |
81 | struct dentry *dfs_dump_tnc; | |
82 | }; | |
83 | ||
84 | #define UBIFS_DBG(op) op | |
85 | ||
86 | #define ubifs_assert(expr) do { \ | |
87 | if (unlikely(!(expr))) { \ | |
88 | printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \ | |
89 | __func__, __LINE__, 0); \ | |
90 | dbg_dump_stack(); \ | |
91 | } \ | |
92 | } while (0) | |
93 | ||
94 | #define ubifs_assert_cmt_locked(c) do { \ | |
95 | if (unlikely(down_write_trylock(&(c)->commit_sem))) { \ | |
96 | up_write(&(c)->commit_sem); \ | |
97 | printk(KERN_CRIT "commit lock is not locked!\n"); \ | |
98 | ubifs_assert(0); \ | |
99 | } \ | |
100 | } while (0) | |
101 | ||
102 | #define dbg_dump_stack() do { \ | |
103 | if (!dbg_failure_mode) \ | |
104 | dump_stack(); \ | |
105 | } while (0) | |
106 | ||
107 | /* Generic debugging messages */ | |
108 | #define dbg_msg(fmt, ...) do { \ | |
109 | spin_lock(&dbg_lock); \ | |
110 | printk(KERN_DEBUG "UBIFS DBG (pid %d): %s: " fmt "\n", 0, \ | |
111 | __func__, ##__VA_ARGS__); \ | |
112 | spin_unlock(&dbg_lock); \ | |
113 | } while (0) | |
114 | ||
115 | #define dbg_do_msg(typ, fmt, ...) do { \ | |
116 | if (ubifs_msg_flags & typ) \ | |
117 | dbg_msg(fmt, ##__VA_ARGS__); \ | |
118 | } while (0) | |
119 | ||
120 | #define dbg_err(fmt, ...) do { \ | |
121 | spin_lock(&dbg_lock); \ | |
122 | ubifs_err(fmt, ##__VA_ARGS__); \ | |
123 | spin_unlock(&dbg_lock); \ | |
124 | } while (0) | |
125 | ||
126 | const char *dbg_key_str0(const struct ubifs_info *c, | |
127 | const union ubifs_key *key); | |
128 | const char *dbg_key_str1(const struct ubifs_info *c, | |
129 | const union ubifs_key *key); | |
130 | ||
131 | /* | |
132 | * DBGKEY macros require @dbg_lock to be held, which it is in the dbg message | |
133 | * macros. | |
134 | */ | |
135 | #define DBGKEY(key) dbg_key_str0(c, (key)) | |
136 | #define DBGKEY1(key) dbg_key_str1(c, (key)) | |
137 | ||
138 | /* General messages */ | |
139 | #define dbg_gen(fmt, ...) dbg_do_msg(UBIFS_MSG_GEN, fmt, ##__VA_ARGS__) | |
140 | ||
141 | /* Additional journal messages */ | |
142 | #define dbg_jnl(fmt, ...) dbg_do_msg(UBIFS_MSG_JNL, fmt, ##__VA_ARGS__) | |
143 | ||
144 | /* Additional TNC messages */ | |
145 | #define dbg_tnc(fmt, ...) dbg_do_msg(UBIFS_MSG_TNC, fmt, ##__VA_ARGS__) | |
146 | ||
147 | /* Additional lprops messages */ | |
148 | #define dbg_lp(fmt, ...) dbg_do_msg(UBIFS_MSG_LP, fmt, ##__VA_ARGS__) | |
149 | ||
150 | /* Additional LEB find messages */ | |
151 | #define dbg_find(fmt, ...) dbg_do_msg(UBIFS_MSG_FIND, fmt, ##__VA_ARGS__) | |
152 | ||
153 | /* Additional mount messages */ | |
154 | #define dbg_mnt(fmt, ...) dbg_do_msg(UBIFS_MSG_MNT, fmt, ##__VA_ARGS__) | |
155 | ||
156 | /* Additional I/O messages */ | |
157 | #define dbg_io(fmt, ...) dbg_do_msg(UBIFS_MSG_IO, fmt, ##__VA_ARGS__) | |
158 | ||
159 | /* Additional commit messages */ | |
160 | #define dbg_cmt(fmt, ...) dbg_do_msg(UBIFS_MSG_CMT, fmt, ##__VA_ARGS__) | |
161 | ||
162 | /* Additional budgeting messages */ | |
163 | #define dbg_budg(fmt, ...) dbg_do_msg(UBIFS_MSG_BUDG, fmt, ##__VA_ARGS__) | |
164 | ||
165 | /* Additional log messages */ | |
166 | #define dbg_log(fmt, ...) dbg_do_msg(UBIFS_MSG_LOG, fmt, ##__VA_ARGS__) | |
167 | ||
168 | /* Additional gc messages */ | |
169 | #define dbg_gc(fmt, ...) dbg_do_msg(UBIFS_MSG_GC, fmt, ##__VA_ARGS__) | |
170 | ||
171 | /* Additional scan messages */ | |
172 | #define dbg_scan(fmt, ...) dbg_do_msg(UBIFS_MSG_SCAN, fmt, ##__VA_ARGS__) | |
173 | ||
174 | /* Additional recovery messages */ | |
175 | #define dbg_rcvry(fmt, ...) dbg_do_msg(UBIFS_MSG_RCVRY, fmt, ##__VA_ARGS__) | |
176 | ||
177 | /* | |
178 | * Debugging message type flags (must match msg_type_names in debug.c). | |
179 | * | |
180 | * UBIFS_MSG_GEN: general messages | |
181 | * UBIFS_MSG_JNL: journal messages | |
182 | * UBIFS_MSG_MNT: mount messages | |
183 | * UBIFS_MSG_CMT: commit messages | |
184 | * UBIFS_MSG_FIND: LEB find messages | |
185 | * UBIFS_MSG_BUDG: budgeting messages | |
186 | * UBIFS_MSG_GC: garbage collection messages | |
187 | * UBIFS_MSG_TNC: TNC messages | |
188 | * UBIFS_MSG_LP: lprops messages | |
189 | * UBIFS_MSG_IO: I/O messages | |
190 | * UBIFS_MSG_LOG: log messages | |
191 | * UBIFS_MSG_SCAN: scan messages | |
192 | * UBIFS_MSG_RCVRY: recovery messages | |
193 | */ | |
194 | enum { | |
195 | UBIFS_MSG_GEN = 0x1, | |
196 | UBIFS_MSG_JNL = 0x2, | |
197 | UBIFS_MSG_MNT = 0x4, | |
198 | UBIFS_MSG_CMT = 0x8, | |
199 | UBIFS_MSG_FIND = 0x10, | |
200 | UBIFS_MSG_BUDG = 0x20, | |
201 | UBIFS_MSG_GC = 0x40, | |
202 | UBIFS_MSG_TNC = 0x80, | |
203 | UBIFS_MSG_LP = 0x100, | |
204 | UBIFS_MSG_IO = 0x200, | |
205 | UBIFS_MSG_LOG = 0x400, | |
206 | UBIFS_MSG_SCAN = 0x800, | |
207 | UBIFS_MSG_RCVRY = 0x1000, | |
208 | }; | |
209 | ||
210 | /* Debugging message type flags for each default debug message level */ | |
211 | #define UBIFS_MSG_LVL_0 0 | |
212 | #define UBIFS_MSG_LVL_1 0x1 | |
213 | #define UBIFS_MSG_LVL_2 0x7f | |
214 | #define UBIFS_MSG_LVL_3 0xffff | |
215 | ||
216 | /* | |
217 | * Debugging check flags (must match chk_names in debug.c). | |
218 | * | |
219 | * UBIFS_CHK_GEN: general checks | |
220 | * UBIFS_CHK_TNC: check TNC | |
221 | * UBIFS_CHK_IDX_SZ: check index size | |
222 | * UBIFS_CHK_ORPH: check orphans | |
223 | * UBIFS_CHK_OLD_IDX: check the old index | |
224 | * UBIFS_CHK_LPROPS: check lprops | |
225 | * UBIFS_CHK_FS: check the file-system | |
226 | */ | |
227 | enum { | |
228 | UBIFS_CHK_GEN = 0x1, | |
229 | UBIFS_CHK_TNC = 0x2, | |
230 | UBIFS_CHK_IDX_SZ = 0x4, | |
231 | UBIFS_CHK_ORPH = 0x8, | |
232 | UBIFS_CHK_OLD_IDX = 0x10, | |
233 | UBIFS_CHK_LPROPS = 0x20, | |
234 | UBIFS_CHK_FS = 0x40, | |
235 | }; | |
236 | ||
237 | /* | |
238 | * Special testing flags (must match tst_names in debug.c). | |
239 | * | |
240 | * UBIFS_TST_FORCE_IN_THE_GAPS: force the use of in-the-gaps method | |
241 | * UBIFS_TST_RCVRY: failure mode for recovery testing | |
242 | */ | |
243 | enum { | |
244 | UBIFS_TST_FORCE_IN_THE_GAPS = 0x2, | |
245 | UBIFS_TST_RCVRY = 0x4, | |
246 | }; | |
247 | ||
248 | #if CONFIG_UBIFS_FS_DEBUG_MSG_LVL == 1 | |
249 | #define UBIFS_MSG_FLAGS_DEFAULT UBIFS_MSG_LVL_1 | |
250 | #elif CONFIG_UBIFS_FS_DEBUG_MSG_LVL == 2 | |
251 | #define UBIFS_MSG_FLAGS_DEFAULT UBIFS_MSG_LVL_2 | |
252 | #elif CONFIG_UBIFS_FS_DEBUG_MSG_LVL == 3 | |
253 | #define UBIFS_MSG_FLAGS_DEFAULT UBIFS_MSG_LVL_3 | |
254 | #else | |
255 | #define UBIFS_MSG_FLAGS_DEFAULT UBIFS_MSG_LVL_0 | |
256 | #endif | |
257 | ||
258 | #ifdef CONFIG_UBIFS_FS_DEBUG_CHKS | |
259 | #define UBIFS_CHK_FLAGS_DEFAULT 0xffffffff | |
260 | #else | |
261 | #define UBIFS_CHK_FLAGS_DEFAULT 0 | |
262 | #endif | |
263 | ||
264 | #define dbg_ntype(type) "" | |
265 | #define dbg_cstate(cmt_state) "" | |
266 | #define dbg_get_key_dump(c, key) ({}) | |
267 | #define dbg_dump_inode(c, inode) ({}) | |
268 | #define dbg_dump_node(c, node) ({}) | |
269 | #define dbg_dump_budget_req(req) ({}) | |
270 | #define dbg_dump_lstats(lst) ({}) | |
271 | #define dbg_dump_budg(c) ({}) | |
272 | #define dbg_dump_lprop(c, lp) ({}) | |
273 | #define dbg_dump_lprops(c) ({}) | |
274 | #define dbg_dump_lpt_info(c) ({}) | |
275 | #define dbg_dump_leb(c, lnum) ({}) | |
276 | #define dbg_dump_znode(c, znode) ({}) | |
277 | #define dbg_dump_heap(c, heap, cat) ({}) | |
278 | #define dbg_dump_pnode(c, pnode, parent, iip) ({}) | |
279 | #define dbg_dump_tnc(c) ({}) | |
280 | #define dbg_dump_index(c) ({}) | |
281 | ||
282 | #define dbg_walk_index(c, leaf_cb, znode_cb, priv) 0 | |
283 | #define dbg_old_index_check_init(c, zroot) 0 | |
284 | #define dbg_check_old_index(c, zroot) 0 | |
285 | #define dbg_check_cats(c) 0 | |
286 | #define dbg_check_ltab(c) 0 | |
287 | #define dbg_chk_lpt_free_spc(c) 0 | |
288 | #define dbg_chk_lpt_sz(c, action, len) 0 | |
289 | #define dbg_check_synced_i_size(inode) 0 | |
290 | #define dbg_check_dir_size(c, dir) 0 | |
291 | #define dbg_check_tnc(c, x) 0 | |
292 | #define dbg_check_idx_size(c, idx_size) 0 | |
293 | #define dbg_check_filesystem(c) 0 | |
294 | #define dbg_check_heap(c, heap, cat, add_pos) ({}) | |
295 | #define dbg_check_lprops(c) 0 | |
296 | #define dbg_check_lpt_nodes(c, cnode, row, col) 0 | |
297 | #define dbg_force_in_the_gaps_enabled 0 | |
298 | #define dbg_force_in_the_gaps() 0 | |
299 | #define dbg_failure_mode 0 | |
300 | #define dbg_failure_mode_registration(c) ({}) | |
301 | #define dbg_failure_mode_deregistration(c) ({}) | |
302 | ||
303 | int ubifs_debugging_init(struct ubifs_info *c); | |
304 | void ubifs_debugging_exit(struct ubifs_info *c); | |
305 | ||
306 | #else /* !CONFIG_UBIFS_FS_DEBUG */ | |
307 | ||
308 | #define UBIFS_DBG(op) | |
309 | ||
310 | /* Use "if (0)" to make compiler check arguments even if debugging is off */ | |
311 | #define ubifs_assert(expr) do { \ | |
312 | if (0 && (expr)) \ | |
313 | printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \ | |
314 | __func__, __LINE__, 0); \ | |
315 | } while (0) | |
316 | ||
317 | #define dbg_err(fmt, ...) do { \ | |
318 | if (0) \ | |
319 | ubifs_err(fmt, ##__VA_ARGS__); \ | |
320 | } while (0) | |
321 | ||
322 | #define dbg_msg(fmt, ...) do { \ | |
323 | if (0) \ | |
324 | printk(KERN_DEBUG "UBIFS DBG (pid %d): %s: " fmt "\n", \ | |
325 | 0, __func__, ##__VA_ARGS__); \ | |
326 | } while (0) | |
327 | ||
328 | #define dbg_dump_stack() | |
329 | #define ubifs_assert_cmt_locked(c) | |
330 | ||
331 | #define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
332 | #define dbg_jnl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
333 | #define dbg_tnc(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
334 | #define dbg_lp(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
335 | #define dbg_find(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
336 | #define dbg_mnt(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
337 | #define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
338 | #define dbg_cmt(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
339 | #define dbg_budg(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
340 | #define dbg_log(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
341 | #define dbg_gc(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
342 | #define dbg_scan(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
343 | #define dbg_rcvry(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | |
344 | ||
345 | #define DBGKEY(key) ((char *)(key)) | |
346 | #define DBGKEY1(key) ((char *)(key)) | |
347 | ||
348 | #define ubifs_debugging_init(c) 0 | |
349 | #define ubifs_debugging_exit(c) ({}) | |
350 | ||
351 | #define dbg_ntype(type) "" | |
352 | #define dbg_cstate(cmt_state) "" | |
353 | #define dbg_get_key_dump(c, key) ({}) | |
354 | #define dbg_dump_inode(c, inode) ({}) | |
355 | #define dbg_dump_node(c, node) ({}) | |
356 | #define dbg_dump_budget_req(req) ({}) | |
357 | #define dbg_dump_lstats(lst) ({}) | |
358 | #define dbg_dump_budg(c) ({}) | |
359 | #define dbg_dump_lprop(c, lp) ({}) | |
360 | #define dbg_dump_lprops(c) ({}) | |
361 | #define dbg_dump_lpt_info(c) ({}) | |
362 | #define dbg_dump_leb(c, lnum) ({}) | |
363 | #define dbg_dump_znode(c, znode) ({}) | |
364 | #define dbg_dump_heap(c, heap, cat) ({}) | |
365 | #define dbg_dump_pnode(c, pnode, parent, iip) ({}) | |
366 | #define dbg_dump_tnc(c) ({}) | |
367 | #define dbg_dump_index(c) ({}) | |
368 | ||
369 | #define dbg_walk_index(c, leaf_cb, znode_cb, priv) 0 | |
370 | #define dbg_old_index_check_init(c, zroot) 0 | |
371 | #define dbg_check_old_index(c, zroot) 0 | |
372 | #define dbg_check_cats(c) 0 | |
373 | #define dbg_check_ltab(c) 0 | |
374 | #define dbg_chk_lpt_free_spc(c) 0 | |
375 | #define dbg_chk_lpt_sz(c, action, len) 0 | |
376 | #define dbg_check_synced_i_size(inode) 0 | |
377 | #define dbg_check_dir_size(c, dir) 0 | |
378 | #define dbg_check_tnc(c, x) 0 | |
379 | #define dbg_check_idx_size(c, idx_size) 0 | |
380 | #define dbg_check_filesystem(c) 0 | |
381 | #define dbg_check_heap(c, heap, cat, add_pos) ({}) | |
382 | #define dbg_check_lprops(c) 0 | |
383 | #define dbg_check_lpt_nodes(c, cnode, row, col) 0 | |
384 | #define dbg_force_in_the_gaps_enabled 0 | |
385 | #define dbg_force_in_the_gaps() 0 | |
386 | #define dbg_failure_mode 0 | |
387 | #define dbg_failure_mode_registration(c) ({}) | |
388 | #define dbg_failure_mode_deregistration(c) ({}) | |
389 | ||
390 | #endif /* !CONFIG_UBIFS_FS_DEBUG */ | |
391 | ||
392 | #endif /* !__UBIFS_DEBUG_H__ */ |