UBIFS: lessen the size of debugging info data structure
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / ubifs / debug.h
blobb59c43a4149c8df155534b35d32a6af40f1a3bd5
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>
37 * The UBIFS debugfs directory name pattern and maximum name length (3 for "ubi"
38 * + 1 for "_" and plus 2x2 for 2 UBI numbers and 1 for the trailing zero byte.
40 #define UBIFS_DFS_DIR_NAME "ubi%d_%d"
41 #define UBIFS_DFS_DIR_LEN (3 + 1 + 2*2 + 1)
43 /**
44 * ubifs_debug_info - per-FS debugging information.
45 * @old_zroot: old index root - used by 'dbg_check_old_index()'
46 * @old_zroot_level: old index root level - used by 'dbg_check_old_index()'
47 * @old_zroot_sqnum: old index root sqnum - used by 'dbg_check_old_index()'
48 * @failure_mode: failure mode for recovery testing
49 * @fail_delay: 0=>don't delay, 1=>delay a time, 2=>delay a number of calls
50 * @fail_timeout: time in jiffies when delay of failure mode expires
51 * @fail_cnt: current number of calls to failure mode I/O functions
52 * @fail_cnt_max: number of calls by which to delay failure mode
53 * @chk_lpt_sz: used by LPT tree size checker
54 * @chk_lpt_sz2: used by LPT tree size checker
55 * @chk_lpt_wastage: used by LPT tree size checker
56 * @chk_lpt_lebs: used by LPT tree size checker
57 * @new_nhead_offs: used by LPT tree size checker
58 * @new_ihead_lnum: used by debugging to check @c->ihead_lnum
59 * @new_ihead_offs: used by debugging to check @c->ihead_offs
61 * @saved_lst: saved lprops statistics (used by 'dbg_save_space_info()')
62 * @saved_bi: saved budgeting information
63 * @saved_free: saved amount of free space
64 * @saved_idx_gc_cnt: saved value of @c->idx_gc_cnt
66 * @dfs_dir_name: name of debugfs directory containing this file-system's files
67 * @dfs_dir: direntry object of the file-system debugfs directory
68 * @dfs_dump_lprops: "dump lprops" debugfs knob
69 * @dfs_dump_budg: "dump budgeting information" debugfs knob
70 * @dfs_dump_tnc: "dump TNC" debugfs knob
72 struct ubifs_debug_info {
73 struct ubifs_zbranch old_zroot;
74 int old_zroot_level;
75 unsigned long long old_zroot_sqnum;
76 int failure_mode;
77 int fail_delay;
78 unsigned long fail_timeout;
79 unsigned int fail_cnt;
80 unsigned int fail_cnt_max;
81 long long chk_lpt_sz;
82 long long chk_lpt_sz2;
83 long long chk_lpt_wastage;
84 int chk_lpt_lebs;
85 int new_nhead_offs;
86 int new_ihead_lnum;
87 int new_ihead_offs;
89 struct ubifs_lp_stats saved_lst;
90 struct ubifs_budg_info saved_bi;
91 long long saved_free;
92 int saved_idx_gc_cnt;
94 char dfs_dir_name[UBIFS_DFS_DIR_LEN + 1];
95 struct dentry *dfs_dir;
96 struct dentry *dfs_dump_lprops;
97 struct dentry *dfs_dump_budg;
98 struct dentry *dfs_dump_tnc;
101 #define ubifs_assert(expr) do { \
102 if (unlikely(!(expr))) { \
103 printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \
104 __func__, __LINE__, current->pid); \
105 dbg_dump_stack(); \
107 } while (0)
109 #define ubifs_assert_cmt_locked(c) do { \
110 if (unlikely(down_write_trylock(&(c)->commit_sem))) { \
111 up_write(&(c)->commit_sem); \
112 printk(KERN_CRIT "commit lock is not locked!\n"); \
113 ubifs_assert(0); \
115 } while (0)
117 #define dbg_dump_stack() dump_stack()
119 #define dbg_err(fmt, ...) do { \
120 spin_lock(&dbg_lock); \
121 ubifs_err(fmt, ##__VA_ARGS__); \
122 spin_unlock(&dbg_lock); \
123 } while (0)
125 const char *dbg_key_str0(const struct ubifs_info *c,
126 const union ubifs_key *key);
127 const char *dbg_key_str1(const struct ubifs_info *c,
128 const union ubifs_key *key);
131 * DBGKEY macros require @dbg_lock to be held, which it is in the dbg message
132 * macros.
134 #define DBGKEY(key) dbg_key_str0(c, (key))
135 #define DBGKEY1(key) dbg_key_str1(c, (key))
137 #define ubifs_dbg_msg(type, fmt, ...) do { \
138 spin_lock(&dbg_lock); \
139 pr_debug("UBIFS DBG " type ": " fmt "\n", ##__VA_ARGS__); \
140 spin_unlock(&dbg_lock); \
141 } while (0)
143 /* Just a debugging messages not related to any specific UBIFS subsystem */
144 #define dbg_msg(fmt, ...) ubifs_dbg_msg("msg", fmt, ##__VA_ARGS__)
145 /* General messages */
146 #define dbg_gen(fmt, ...) ubifs_dbg_msg("gen", fmt, ##__VA_ARGS__)
147 /* Additional journal messages */
148 #define dbg_jnl(fmt, ...) ubifs_dbg_msg("jnl", fmt, ##__VA_ARGS__)
149 /* Additional TNC messages */
150 #define dbg_tnc(fmt, ...) ubifs_dbg_msg("tnc", fmt, ##__VA_ARGS__)
151 /* Additional lprops messages */
152 #define dbg_lp(fmt, ...) ubifs_dbg_msg("lp", fmt, ##__VA_ARGS__)
153 /* Additional LEB find messages */
154 #define dbg_find(fmt, ...) ubifs_dbg_msg("find", fmt, ##__VA_ARGS__)
155 /* Additional mount messages */
156 #define dbg_mnt(fmt, ...) ubifs_dbg_msg("mnt", fmt, ##__VA_ARGS__)
157 /* Additional I/O messages */
158 #define dbg_io(fmt, ...) ubifs_dbg_msg("io", fmt, ##__VA_ARGS__)
159 /* Additional commit messages */
160 #define dbg_cmt(fmt, ...) ubifs_dbg_msg("cmt", fmt, ##__VA_ARGS__)
161 /* Additional budgeting messages */
162 #define dbg_budg(fmt, ...) ubifs_dbg_msg("budg", fmt, ##__VA_ARGS__)
163 /* Additional log messages */
164 #define dbg_log(fmt, ...) ubifs_dbg_msg("log", fmt, ##__VA_ARGS__)
165 /* Additional gc messages */
166 #define dbg_gc(fmt, ...) ubifs_dbg_msg("gc", fmt, ##__VA_ARGS__)
167 /* Additional scan messages */
168 #define dbg_scan(fmt, ...) ubifs_dbg_msg("scan", fmt, ##__VA_ARGS__)
169 /* Additional recovery messages */
170 #define dbg_rcvry(fmt, ...) ubifs_dbg_msg("rcvry", fmt, ##__VA_ARGS__)
173 * Debugging check flags.
175 * UBIFS_CHK_GEN: general checks
176 * UBIFS_CHK_TNC: check TNC
177 * UBIFS_CHK_IDX_SZ: check index size
178 * UBIFS_CHK_ORPH: check orphans
179 * UBIFS_CHK_OLD_IDX: check the old index
180 * UBIFS_CHK_LPROPS: check lprops
181 * UBIFS_CHK_FS: check the file-system
183 enum {
184 UBIFS_CHK_GEN = 0x1,
185 UBIFS_CHK_TNC = 0x2,
186 UBIFS_CHK_IDX_SZ = 0x4,
187 UBIFS_CHK_ORPH = 0x8,
188 UBIFS_CHK_OLD_IDX = 0x10,
189 UBIFS_CHK_LPROPS = 0x20,
190 UBIFS_CHK_FS = 0x40,
194 * Special testing flags.
196 * UBIFS_TST_RCVRY: failure mode for recovery testing
198 enum {
199 UBIFS_TST_RCVRY = 0x4,
202 extern spinlock_t dbg_lock;
204 extern unsigned int ubifs_msg_flags;
205 extern unsigned int ubifs_chk_flags;
206 extern unsigned int ubifs_tst_flags;
208 int ubifs_debugging_init(struct ubifs_info *c);
209 void ubifs_debugging_exit(struct ubifs_info *c);
211 /* Dump functions */
212 const char *dbg_ntype(int type);
213 const char *dbg_cstate(int cmt_state);
214 const char *dbg_jhead(int jhead);
215 const char *dbg_get_key_dump(const struct ubifs_info *c,
216 const union ubifs_key *key);
217 void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode);
218 void dbg_dump_node(const struct ubifs_info *c, const void *node);
219 void dbg_dump_lpt_node(const struct ubifs_info *c, void *node, int lnum,
220 int offs);
221 void dbg_dump_budget_req(const struct ubifs_budget_req *req);
222 void dbg_dump_lstats(const struct ubifs_lp_stats *lst);
223 void dbg_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi);
224 void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp);
225 void dbg_dump_lprops(struct ubifs_info *c);
226 void dbg_dump_lpt_info(struct ubifs_info *c);
227 void dbg_dump_leb(const struct ubifs_info *c, int lnum);
228 void dbg_dump_znode(const struct ubifs_info *c,
229 const struct ubifs_znode *znode);
230 void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat);
231 void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
232 struct ubifs_nnode *parent, int iip);
233 void dbg_dump_tnc(struct ubifs_info *c);
234 void dbg_dump_index(struct ubifs_info *c);
235 void dbg_dump_lpt_lebs(const struct ubifs_info *c);
237 int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb,
238 dbg_znode_callback znode_cb, void *priv);
240 /* Checking functions */
241 void dbg_save_space_info(struct ubifs_info *c);
242 int dbg_check_space_info(struct ubifs_info *c);
243 int dbg_check_lprops(struct ubifs_info *c);
244 int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot);
245 int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot);
246 int dbg_check_cats(struct ubifs_info *c);
247 int dbg_check_ltab(struct ubifs_info *c);
248 int dbg_chk_lpt_free_spc(struct ubifs_info *c);
249 int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len);
250 int dbg_check_synced_i_size(struct inode *inode);
251 int dbg_check_dir_size(struct ubifs_info *c, const struct inode *dir);
252 int dbg_check_tnc(struct ubifs_info *c, int extra);
253 int dbg_check_idx_size(struct ubifs_info *c, long long idx_size);
254 int dbg_check_filesystem(struct ubifs_info *c);
255 void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat,
256 int add_pos);
257 int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode,
258 int row, int col);
259 int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode,
260 loff_t size);
261 int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head);
262 int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head);
264 /* Force the use of in-the-gaps method for testing */
265 static inline int dbg_force_in_the_gaps_enabled(void)
267 return ubifs_chk_flags & UBIFS_CHK_GEN;
269 int dbg_force_in_the_gaps(void);
271 /* Failure mode for recovery testing */
272 #define dbg_failure_mode (ubifs_tst_flags & UBIFS_TST_RCVRY)
274 #ifndef UBIFS_DBG_PRESERVE_UBI
275 #define ubi_leb_read dbg_leb_read
276 #define ubi_leb_write dbg_leb_write
277 #define ubi_leb_change dbg_leb_change
278 #define ubi_leb_erase dbg_leb_erase
279 #define ubi_leb_unmap dbg_leb_unmap
280 #define ubi_is_mapped dbg_is_mapped
281 #define ubi_leb_map dbg_leb_map
282 #endif
284 int dbg_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
285 int len, int check);
286 int dbg_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
287 int offset, int len, int dtype);
288 int dbg_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
289 int len, int dtype);
290 int dbg_leb_erase(struct ubi_volume_desc *desc, int lnum);
291 int dbg_leb_unmap(struct ubi_volume_desc *desc, int lnum);
292 int dbg_is_mapped(struct ubi_volume_desc *desc, int lnum);
293 int dbg_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype);
295 static inline int dbg_read(struct ubi_volume_desc *desc, int lnum, char *buf,
296 int offset, int len)
298 return dbg_leb_read(desc, lnum, buf, offset, len, 0);
301 static inline int dbg_write(struct ubi_volume_desc *desc, int lnum,
302 const void *buf, int offset, int len)
304 return dbg_leb_write(desc, lnum, buf, offset, len, UBI_UNKNOWN);
307 static inline int dbg_change(struct ubi_volume_desc *desc, int lnum,
308 const void *buf, int len)
310 return dbg_leb_change(desc, lnum, buf, len, UBI_UNKNOWN);
313 /* Debugfs-related stuff */
314 int dbg_debugfs_init(void);
315 void dbg_debugfs_exit(void);
316 int dbg_debugfs_init_fs(struct ubifs_info *c);
317 void dbg_debugfs_exit_fs(struct ubifs_info *c);
319 #else /* !CONFIG_UBIFS_FS_DEBUG */
321 /* Use "if (0)" to make compiler check arguments even if debugging is off */
322 #define ubifs_assert(expr) do { \
323 if (0) \
324 printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \
325 __func__, __LINE__, current->pid); \
326 } while (0)
328 #define dbg_err(fmt, ...) do { \
329 if (0) \
330 ubifs_err(fmt, ##__VA_ARGS__); \
331 } while (0)
333 #define ubifs_dbg_msg(fmt, ...) do { \
334 if (0) \
335 pr_debug(fmt "\n", ##__VA_ARGS__); \
336 } while (0)
338 #define dbg_dump_stack()
339 #define ubifs_assert_cmt_locked(c)
341 #define dbg_msg(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
342 #define dbg_gen(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
343 #define dbg_jnl(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
344 #define dbg_tnc(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
345 #define dbg_lp(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
346 #define dbg_find(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
347 #define dbg_mnt(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
348 #define dbg_io(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
349 #define dbg_cmt(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
350 #define dbg_budg(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
351 #define dbg_log(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
352 #define dbg_gc(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
353 #define dbg_scan(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
354 #define dbg_rcvry(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__)
356 #define DBGKEY(key) ((char *)(key))
357 #define DBGKEY1(key) ((char *)(key))
359 static inline int ubifs_debugging_init(struct ubifs_info *c) { return 0; }
360 static inline void ubifs_debugging_exit(struct ubifs_info *c) { return; }
361 static inline const char *dbg_ntype(int type) { return ""; }
362 static inline const char *dbg_cstate(int cmt_state) { return ""; }
363 static inline const char *dbg_jhead(int jhead) { return ""; }
364 static inline const char *
365 dbg_get_key_dump(const struct ubifs_info *c,
366 const union ubifs_key *key) { return ""; }
367 static inline void dbg_dump_inode(const struct ubifs_info *c,
368 const struct inode *inode) { return; }
369 static inline void dbg_dump_node(const struct ubifs_info *c,
370 const void *node) { return; }
371 static inline void dbg_dump_lpt_node(const struct ubifs_info *c,
372 void *node, int lnum,
373 int offs) { return; }
374 static inline void
375 dbg_dump_budget_req(const struct ubifs_budget_req *req) { return; }
376 static inline void
377 dbg_dump_lstats(const struct ubifs_lp_stats *lst) { return; }
378 static inline void
379 dbg_dump_budg(struct ubifs_info *c,
380 const struct ubifs_budg_info *bi) { return; }
381 static inline void dbg_dump_lprop(const struct ubifs_info *c,
382 const struct ubifs_lprops *lp) { return; }
383 static inline void dbg_dump_lprops(struct ubifs_info *c) { return; }
384 static inline void dbg_dump_lpt_info(struct ubifs_info *c) { return; }
385 static inline void dbg_dump_leb(const struct ubifs_info *c,
386 int lnum) { return; }
387 static inline void
388 dbg_dump_znode(const struct ubifs_info *c,
389 const struct ubifs_znode *znode) { return; }
390 static inline void dbg_dump_heap(struct ubifs_info *c,
391 struct ubifs_lpt_heap *heap,
392 int cat) { return; }
393 static inline void dbg_dump_pnode(struct ubifs_info *c,
394 struct ubifs_pnode *pnode,
395 struct ubifs_nnode *parent,
396 int iip) { return; }
397 static inline void dbg_dump_tnc(struct ubifs_info *c) { return; }
398 static inline void dbg_dump_index(struct ubifs_info *c) { return; }
399 static inline void dbg_dump_lpt_lebs(const struct ubifs_info *c) { return; }
401 static inline int dbg_walk_index(struct ubifs_info *c,
402 dbg_leaf_callback leaf_cb,
403 dbg_znode_callback znode_cb,
404 void *priv) { return 0; }
405 static inline void dbg_save_space_info(struct ubifs_info *c) { return; }
406 static inline int dbg_check_space_info(struct ubifs_info *c) { return 0; }
407 static inline int dbg_check_lprops(struct ubifs_info *c) { return 0; }
408 static inline int
409 dbg_old_index_check_init(struct ubifs_info *c,
410 struct ubifs_zbranch *zroot) { return 0; }
411 static inline int
412 dbg_check_old_index(struct ubifs_info *c,
413 struct ubifs_zbranch *zroot) { return 0; }
414 static inline int dbg_check_cats(struct ubifs_info *c) { return 0; }
415 static inline int dbg_check_ltab(struct ubifs_info *c) { return 0; }
416 static inline int dbg_chk_lpt_free_spc(struct ubifs_info *c) { return 0; }
417 static inline int dbg_chk_lpt_sz(struct ubifs_info *c,
418 int action, int len) { return 0; }
419 static inline int dbg_check_synced_i_size(struct inode *inode) { return 0; }
420 static inline int dbg_check_dir_size(struct ubifs_info *c,
421 const struct inode *dir) { return 0; }
422 static inline int dbg_check_tnc(struct ubifs_info *c, int extra) { return 0; }
423 static inline int dbg_check_idx_size(struct ubifs_info *c,
424 long long idx_size) { return 0; }
425 static inline int dbg_check_filesystem(struct ubifs_info *c) { return 0; }
426 static inline void dbg_check_heap(struct ubifs_info *c,
427 struct ubifs_lpt_heap *heap,
428 int cat, int add_pos) { return; }
429 static inline int dbg_check_lpt_nodes(struct ubifs_info *c,
430 struct ubifs_cnode *cnode, int row, int col) { return 0; }
431 static inline int dbg_check_inode_size(struct ubifs_info *c,
432 const struct inode *inode,
433 loff_t size) { return 0; }
434 static inline int
435 dbg_check_data_nodes_order(struct ubifs_info *c,
436 struct list_head *head) { return 0; }
437 static inline int
438 dbg_check_nondata_nodes_order(struct ubifs_info *c,
439 struct list_head *head) { return 0; }
441 static inline int dbg_force_in_the_gaps(void) { return 0; }
442 #define dbg_force_in_the_gaps_enabled() 0
443 #define dbg_failure_mode 0
445 static inline int dbg_debugfs_init(void) { return 0; }
446 static inline void dbg_debugfs_exit(void) { return; }
447 static inline int dbg_debugfs_init_fs(struct ubifs_info *c) { return 0; }
448 static inline int dbg_debugfs_exit_fs(struct ubifs_info *c) { return 0; }
450 #endif /* !CONFIG_UBIFS_FS_DEBUG */
451 #endif /* !__UBIFS_DEBUG_H__ */