debug.h 15 KB

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