UBIFS: fix debugging messages
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / ubifs / debug.h
blob3a89c8b4efc294ad53b57127d03ee943f2c0fcbf
1 /*
2 * This file is part of UBIFS.
4 * Copyright (C) 2006-2008 Nokia Corporation.
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.
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.
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
19 * Authors: Artem Bityutskiy (Битюцкий Артём)
20 * Adrian Hunter
23 #ifndef __UBIFS_DEBUG_H__
24 #define __UBIFS_DEBUG_H__
26 /* Checking helper functions */
27 typedef int (*dbg_leaf_callback)(struct ubifs_info *c,
28 struct ubifs_zbranch *zbr, void *priv);
29 typedef int (*dbg_znode_callback)(struct ubifs_info *c,
30 struct ubifs_znode *znode, void *priv);
32 #ifdef CONFIG_UBIFS_FS_DEBUG
34 #include <linux/random.h>
36 /**
37 * ubifs_debug_info - per-FS debugging information.
38 * @old_zroot: old index root - used by 'dbg_check_old_index()'
39 * @old_zroot_level: old index root level - used by 'dbg_check_old_index()'
40 * @old_zroot_sqnum: old index root sqnum - used by 'dbg_check_old_index()'
41 * @failure_mode: failure mode for recovery testing
42 * @fail_delay: 0=>don't delay, 1=>delay a time, 2=>delay a number of calls
43 * @fail_timeout: time in jiffies when delay of failure mode expires
44 * @fail_cnt: current number of calls to failure mode I/O functions
45 * @fail_cnt_max: number of calls by which to delay failure mode
46 * @chk_lpt_sz: used by LPT tree size checker
47 * @chk_lpt_sz2: used by LPT tree size checker
48 * @chk_lpt_wastage: used by LPT tree size checker
49 * @chk_lpt_lebs: used by LPT tree size checker
50 * @new_nhead_offs: used by LPT tree size checker
51 * @new_ihead_lnum: used by debugging to check @c->ihead_lnum
52 * @new_ihead_offs: used by debugging to check @c->ihead_offs
54 * @saved_lst: saved lprops statistics (used by 'dbg_save_space_info()')
55 * @saved_bi: saved budgeting information
56 * @saved_free: saved amount of free space
57 * @saved_idx_gc_cnt: saved value of @c->idx_gc_cnt
59 * @dfs_dir_name: name of debugfs directory containing this file-system's files
60 * @dfs_dir: direntry object of the file-system debugfs directory
61 * @dfs_dump_lprops: "dump lprops" debugfs knob
62 * @dfs_dump_budg: "dump budgeting information" debugfs knob
63 * @dfs_dump_tnc: "dump TNC" debugfs knob
65 struct ubifs_debug_info {
66 struct ubifs_zbranch old_zroot;
67 int old_zroot_level;
68 unsigned long long old_zroot_sqnum;
69 int failure_mode;
70 int fail_delay;
71 unsigned long fail_timeout;
72 unsigned int fail_cnt;
73 unsigned int fail_cnt_max;
74 long long chk_lpt_sz;
75 long long chk_lpt_sz2;
76 long long chk_lpt_wastage;
77 int chk_lpt_lebs;
78 int new_nhead_offs;
79 int new_ihead_lnum;
80 int new_ihead_offs;
82 struct ubifs_lp_stats saved_lst;
83 struct ubifs_budg_info saved_bi;
84 long long saved_free;
85 int saved_idx_gc_cnt;
87 char dfs_dir_name[100];
88 struct dentry *dfs_dir;
89 struct dentry *dfs_dump_lprops;
90 struct dentry *dfs_dump_budg;
91 struct dentry *dfs_dump_tnc;
94 #define ubifs_assert(expr) do { \
95 if (unlikely(!(expr))) { \
96 printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \
97 __func__, __LINE__, current->pid); \
98 dbg_dump_stack(); \
99 } \
100 } while (0)
102 #define ubifs_assert_cmt_locked(c) do { \
103 if (unlikely(down_write_trylock(&(c)->commit_sem))) { \
104 up_write(&(c)->commit_sem); \
105 printk(KERN_CRIT "commit lock is not locked!\n"); \
106 ubifs_assert(0); \
108 } while (0)
110 #define dbg_dump_stack() dump_stack()
112 #define dbg_err(fmt, ...) do { \
113 spin_lock(&dbg_lock); \
114 ubifs_err(fmt, ##__VA_ARGS__); \
115 spin_unlock(&dbg_lock); \
116 } while (0)
118 const char *dbg_key_str0(const struct ubifs_info *c,
119 const union ubifs_key *key);
120 const char *dbg_key_str1(const struct ubifs_info *c,
121 const union ubifs_key *key);
124 * DBGKEY macros require @dbg_lock to be held, which it is in the dbg message
125 * macros.
127 #define DBGKEY(key) dbg_key_str0(c, (key))
128 #define DBGKEY1(key) dbg_key_str1(c, (key))
130 #define ubifs_dbg_msg(type, fmt, ...) do { \
131 spin_lock(&dbg_lock); \
132 pr_debug("UBIFS DBG " type ": " fmt "\n", ##__VA_ARGS__); \
133 spin_unlock(&dbg_lock); \
134 } while (0)
136 /* Just a debugging messages not related to any specific UBIFS subsystem */
137 #define dbg_msg(fmt, ...) \
138 printk(KERN_DEBUG "UBIFS DBG (pid %d): %s: " fmt "\n", current->pid, \
139 __func__, ##__VA_ARGS__)
141 /* General messages */
142 #define dbg_gen(fmt, ...) ubifs_dbg_msg("gen", fmt, ##__VA_ARGS__)
143 /* Additional journal messages */
144 #define dbg_jnl(fmt, ...) ubifs_dbg_msg("jnl", fmt, ##__VA_ARGS__)
145 /* Additional TNC messages */
146 #define dbg_tnc(fmt, ...) ubifs_dbg_msg("tnc", fmt, ##__VA_ARGS__)
147 /* Additional lprops messages */
148 #define dbg_lp(fmt, ...) ubifs_dbg_msg("lp", fmt, ##__VA_ARGS__)
149 /* Additional LEB find messages */
150 #define dbg_find(fmt, ...) ubifs_dbg_msg("find", fmt, ##__VA_ARGS__)
151 /* Additional mount messages */
152 #define dbg_mnt(fmt, ...) ubifs_dbg_msg("mnt", fmt, ##__VA_ARGS__)
153 /* Additional I/O messages */
154 #define dbg_io(fmt, ...) ubifs_dbg_msg("io", fmt, ##__VA_ARGS__)
155 /* Additional commit messages */
156 #define dbg_cmt(fmt, ...) ubifs_dbg_msg("cmt", fmt, ##__VA_ARGS__)
157 /* Additional budgeting messages */
158 #define dbg_budg(fmt, ...) ubifs_dbg_msg("budg", fmt, ##__VA_ARGS__)
159 /* Additional log messages */
160 #define dbg_log(fmt, ...) ubifs_dbg_msg("log", fmt, ##__VA_ARGS__)
161 /* Additional gc messages */
162 #define dbg_gc(fmt, ...) ubifs_dbg_msg("gc", fmt, ##__VA_ARGS__)
163 /* Additional scan messages */
164 #define dbg_scan(fmt, ...) ubifs_dbg_msg("scan", fmt, ##__VA_ARGS__)
165 /* Additional recovery messages */
166 #define dbg_rcvry(fmt, ...) ubifs_dbg_msg("rcvry", fmt, ##__VA_ARGS__)
169 * Debugging check flags.
171 * UBIFS_CHK_GEN: general checks
172 * UBIFS_CHK_TNC: check TNC
173 * UBIFS_CHK_IDX_SZ: check index size
174 * UBIFS_CHK_ORPH: check orphans
175 * UBIFS_CHK_OLD_IDX: check the old index
176 * UBIFS_CHK_LPROPS: check lprops
177 * UBIFS_CHK_FS: check the file-system
179 enum {
180 UBIFS_CHK_GEN = 0x1,
181 UBIFS_CHK_TNC = 0x2,
182 UBIFS_CHK_IDX_SZ = 0x4,
183 UBIFS_CHK_ORPH = 0x8,
184 UBIFS_CHK_OLD_IDX = 0x10,
185 UBIFS_CHK_LPROPS = 0x20,
186 UBIFS_CHK_FS = 0x40,
190 * Special testing flags.
192 * UBIFS_TST_RCVRY: failure mode for recovery testing
194 enum {
195 UBIFS_TST_RCVRY = 0x4,
198 extern spinlock_t dbg_lock;
200 extern unsigned int ubifs_msg_flags;
201 extern unsigned int ubifs_chk_flags;
202 extern unsigned int ubifs_tst_flags;
204 int ubifs_debugging_init(struct ubifs_info *c);
205 void ubifs_debugging_exit(struct ubifs_info *c);
207 /* Dump functions */
208 const char *dbg_ntype(int type);
209 const char *dbg_cstate(int cmt_state);
210 const char *dbg_jhead(int jhead);
211 const char *dbg_get_key_dump(const struct ubifs_info *c,
212 const union ubifs_key *key);
213 void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode);
214 void dbg_dump_node(const struct ubifs_info *c, const void *node);
215 void dbg_dump_lpt_node(const struct ubifs_info *c, void *node, int lnum,
216 int offs);
217 void dbg_dump_budget_req(const struct ubifs_budget_req *req);
218 void dbg_dump_lstats(const struct ubifs_lp_stats *lst);
219 void dbg_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi);
220 void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp);
221 void dbg_dump_lprops(struct ubifs_info *c);
222 void dbg_dump_lpt_info(struct ubifs_info *c);
223 void dbg_dump_leb(const struct ubifs_info *c, int lnum);
224 void dbg_dump_znode(const struct ubifs_info *c,
225 const struct ubifs_znode *znode);
226 void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat);
227 void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
228 struct ubifs_nnode *parent, int iip);
229 void dbg_dump_tnc(struct ubifs_info *c);
230 void dbg_dump_index(struct ubifs_info *c);
231 void dbg_dump_lpt_lebs(const struct ubifs_info *c);
233 int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb,
234 dbg_znode_callback znode_cb, void *priv);
236 /* Checking functions */
237 void dbg_save_space_info(struct ubifs_info *c);
238 int dbg_check_space_info(struct ubifs_info *c);
239 int dbg_check_lprops(struct ubifs_info *c);
240 int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot);
241 int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot);
242 int dbg_check_cats(struct ubifs_info *c);
243 int dbg_check_ltab(struct ubifs_info *c);
244 int dbg_chk_lpt_free_spc(struct ubifs_info *c);
245 int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len);
246 int dbg_check_synced_i_size(struct inode *inode);
247 int dbg_check_dir_size(struct ubifs_info *c, const struct inode *dir);
248 int dbg_check_tnc(struct ubifs_info *c, int extra);
249 int dbg_check_idx_size(struct ubifs_info *c, long long idx_size);
250 int dbg_check_filesystem(struct ubifs_info *c);
251 void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat,
252 int add_pos);
253 int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode,
254 int row, int col);
255 int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode,
256 loff_t size);
257 int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head);
258 int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head);
260 /* Force the use of in-the-gaps method for testing */
261 static inline int dbg_force_in_the_gaps_enabled(void)
263 return ubifs_chk_flags & UBIFS_CHK_GEN;
265 int dbg_force_in_the_gaps(void);
267 /* Failure mode for recovery testing */
268 #define dbg_failure_mode (ubifs_tst_flags & UBIFS_TST_RCVRY)
270 #ifndef UBIFS_DBG_PRESERVE_UBI
271 #define ubi_leb_read dbg_leb_read
272 #define ubi_leb_write dbg_leb_write
273 #define ubi_leb_change dbg_leb_change
274 #define ubi_leb_erase dbg_leb_erase
275 #define ubi_leb_unmap dbg_leb_unmap
276 #define ubi_is_mapped dbg_is_mapped
277 #define ubi_leb_map dbg_leb_map
278 #endif
280 int dbg_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
281 int len, int check);
282 int dbg_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
283 int offset, int len, int dtype);
284 int dbg_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
285 int len, int dtype);
286 int dbg_leb_erase(struct ubi_volume_desc *desc, int lnum);
287 int dbg_leb_unmap(struct ubi_volume_desc *desc, int lnum);
288 int dbg_is_mapped(struct ubi_volume_desc *desc, int lnum);
289 int dbg_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype);
291 static inline int dbg_read(struct ubi_volume_desc *desc, int lnum, char *buf,
292 int offset, int len)
294 return dbg_leb_read(desc, lnum, buf, offset, len, 0);
297 static inline int dbg_write(struct ubi_volume_desc *desc, int lnum,
298 const void *buf, int offset, int len)
300 return dbg_leb_write(desc, lnum, buf, offset, len, UBI_UNKNOWN);
303 static inline int dbg_change(struct ubi_volume_desc *desc, int lnum,
304 const void *buf, int len)
306 return dbg_leb_change(desc, lnum, buf, len, UBI_UNKNOWN);
309 /* Debugfs-related stuff */
310 int dbg_debugfs_init(void);
311 void dbg_debugfs_exit(void);
312 int dbg_debugfs_init_fs(struct ubifs_info *c);
313 void dbg_debugfs_exit_fs(struct ubifs_info *c);
315 #else /* !CONFIG_UBIFS_FS_DEBUG */
317 /* Use "if (0)" to make compiler check arguments even if debugging is off */
318 #define ubifs_assert(expr) do { \
319 if (0 && (expr)) \
320 printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \
321 __func__, __LINE__, current->pid); \
322 } while (0)
324 #define dbg_err(fmt, ...) do { \
325 if (0) \
326 ubifs_err(fmt, ##__VA_ARGS__); \
327 } while (0)
329 #define ubifs_dbg_msg(fmt, ...) do { \
330 if (0) \
331 pr_debug(fmt "\n", ##__VA_ARGS__); \
332 } while (0)
334 #define dbg_dump_stack()
335 #define ubifs_assert_cmt_locked(c)
337 #define dbg_msg(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
338 #define dbg_gen(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
339 #define dbg_jnl(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
340 #define dbg_tnc(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
341 #define dbg_lp(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
342 #define dbg_find(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
343 #define dbg_mnt(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
344 #define dbg_io(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
345 #define dbg_cmt(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
346 #define dbg_budg(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
347 #define dbg_log(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
348 #define dbg_gc(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
349 #define dbg_scan(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
350 #define dbg_rcvry(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
352 #define DBGKEY(key) ((char *)(key))
353 #define DBGKEY1(key) ((char *)(key))
355 static inline int ubifs_debugging_init(struct ubifs_info *c) { return 0; }
356 static inline void ubifs_debugging_exit(struct ubifs_info *c) { return; }
357 static inline const char *dbg_ntype(int type) { return ""; }
358 static inline const char *dbg_cstate(int cmt_state) { return ""; }
359 static inline const char *dbg_jhead(int jhead) { return ""; }
360 static inline const char *
361 dbg_get_key_dump(const struct ubifs_info *c,
362 const union ubifs_key *key) { return ""; }
363 static inline void dbg_dump_inode(const struct ubifs_info *c,
364 const struct inode *inode) { return; }
365 static inline void dbg_dump_node(const struct ubifs_info *c,
366 const void *node) { return; }
367 static inline void dbg_dump_lpt_node(const struct ubifs_info *c,
368 void *node, int lnum,
369 int offs) { return; }
370 static inline void
371 dbg_dump_budget_req(const struct ubifs_budget_req *req) { return; }
372 static inline void
373 dbg_dump_lstats(const struct ubifs_lp_stats *lst) { return; }
374 static inline void
375 dbg_dump_budg(struct ubifs_info *c,
376 const struct ubifs_budg_info *bi) { return; }
377 static inline void dbg_dump_lprop(const struct ubifs_info *c,
378 const struct ubifs_lprops *lp) { return; }
379 static inline void dbg_dump_lprops(struct ubifs_info *c) { return; }
380 static inline void dbg_dump_lpt_info(struct ubifs_info *c) { return; }
381 static inline void dbg_dump_leb(const struct ubifs_info *c,
382 int lnum) { return; }
383 static inline void
384 dbg_dump_znode(const struct ubifs_info *c,
385 const struct ubifs_znode *znode) { return; }
386 static inline void dbg_dump_heap(struct ubifs_info *c,
387 struct ubifs_lpt_heap *heap,
388 int cat) { return; }
389 static inline void dbg_dump_pnode(struct ubifs_info *c,
390 struct ubifs_pnode *pnode,
391 struct ubifs_nnode *parent,
392 int iip) { return; }
393 static inline void dbg_dump_tnc(struct ubifs_info *c) { return; }
394 static inline void dbg_dump_index(struct ubifs_info *c) { return; }
395 static inline void dbg_dump_lpt_lebs(const struct ubifs_info *c) { return; }
397 static inline int dbg_walk_index(struct ubifs_info *c,
398 dbg_leaf_callback leaf_cb,
399 dbg_znode_callback znode_cb,
400 void *priv) { return 0; }
401 static inline void dbg_save_space_info(struct ubifs_info *c) { return; }
402 static inline int dbg_check_space_info(struct ubifs_info *c) { return 0; }
403 static inline int dbg_check_lprops(struct ubifs_info *c) { return 0; }
404 static inline int
405 dbg_old_index_check_init(struct ubifs_info *c,
406 struct ubifs_zbranch *zroot) { return 0; }
407 static inline int
408 dbg_check_old_index(struct ubifs_info *c,
409 struct ubifs_zbranch *zroot) { return 0; }
410 static inline int dbg_check_cats(struct ubifs_info *c) { return 0; }
411 static inline int dbg_check_ltab(struct ubifs_info *c) { return 0; }
412 static inline int dbg_chk_lpt_free_spc(struct ubifs_info *c) { return 0; }
413 static inline int dbg_chk_lpt_sz(struct ubifs_info *c,
414 int action, int len) { return 0; }
415 static inline int dbg_check_synced_i_size(struct inode *inode) { return 0; }
416 static inline int dbg_check_dir_size(struct ubifs_info *c,
417 const struct inode *dir) { return 0; }
418 static inline int dbg_check_tnc(struct ubifs_info *c, int extra) { return 0; }
419 static inline int dbg_check_idx_size(struct ubifs_info *c,
420 long long idx_size) { return 0; }
421 static inline int dbg_check_filesystem(struct ubifs_info *c) { return 0; }
422 static inline void dbg_check_heap(struct ubifs_info *c,
423 struct ubifs_lpt_heap *heap,
424 int cat, int add_pos) { return; }
425 static inline int dbg_check_lpt_nodes(struct ubifs_info *c,
426 struct ubifs_cnode *cnode, int row, int col) { return 0; }
427 static inline int dbg_check_inode_size(struct ubifs_info *c,
428 const struct inode *inode,
429 loff_t size) { return 0; }
430 static inline int
431 dbg_check_data_nodes_order(struct ubifs_info *c,
432 struct list_head *head) { return 0; }
433 static inline int
434 dbg_check_nondata_nodes_order(struct ubifs_info *c,
435 struct list_head *head) { return 0; }
437 static inline int dbg_force_in_the_gaps(void) { return 0; }
438 #define dbg_force_in_the_gaps_enabled() 0
439 #define dbg_failure_mode 0
441 static inline int dbg_debugfs_init(void) { return 0; }
442 static inline void dbg_debugfs_exit(void) { return; }
443 static inline int dbg_debugfs_init_fs(struct ubifs_info *c) { return 0; }
444 static inline int dbg_debugfs_exit_fs(struct ubifs_info *c) { return 0; }
446 #endif /* !CONFIG_UBIFS_FS_DEBUG */
447 #endif /* !__UBIFS_DEBUG_H__ */