Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 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 | |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 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); |
| 31 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 32 | #ifdef CONFIG_UBIFS_FS_DEBUG |
| 33 | |
Artem Bityutskiy | bc3f07f | 2011-04-05 13:52:20 +0300 | [diff] [blame^] | 34 | #include <linux/random.h> |
| 35 | |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 36 | /** |
| 37 | * ubifs_debug_info - per-FS debugging information. |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 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 |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 51 | * @new_ihead_lnum: used by debugging to check @c->ihead_lnum |
| 52 | * @new_ihead_offs: used by debugging to check @c->ihead_offs |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 53 | * |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 54 | * @saved_lst: saved lprops statistics (used by 'dbg_save_space_info()') |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 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 |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 58 | * |
| 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 |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 64 | */ |
| 65 | struct ubifs_debug_info { |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 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; |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 81 | |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 82 | struct ubifs_lp_stats saved_lst; |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 83 | struct ubifs_budg_info saved_bi; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 84 | long long saved_free; |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 85 | int saved_idx_gc_cnt; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 86 | |
| 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; |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 92 | }; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 93 | |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 94 | #define ubifs_assert(expr) do { \ |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 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) |
| 101 | |
| 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); \ |
| 107 | } \ |
| 108 | } while (0) |
| 109 | |
| 110 | #define dbg_dump_stack() do { \ |
| 111 | if (!dbg_failure_mode) \ |
| 112 | dump_stack(); \ |
| 113 | } while (0) |
| 114 | |
| 115 | /* Generic debugging messages */ |
| 116 | #define dbg_msg(fmt, ...) do { \ |
| 117 | spin_lock(&dbg_lock); \ |
| 118 | printk(KERN_DEBUG "UBIFS DBG (pid %d): %s: " fmt "\n", current->pid, \ |
| 119 | __func__, ##__VA_ARGS__); \ |
| 120 | spin_unlock(&dbg_lock); \ |
| 121 | } while (0) |
| 122 | |
| 123 | #define dbg_do_msg(typ, fmt, ...) do { \ |
| 124 | if (ubifs_msg_flags & typ) \ |
| 125 | dbg_msg(fmt, ##__VA_ARGS__); \ |
| 126 | } while (0) |
| 127 | |
| 128 | #define dbg_err(fmt, ...) do { \ |
| 129 | spin_lock(&dbg_lock); \ |
| 130 | ubifs_err(fmt, ##__VA_ARGS__); \ |
| 131 | spin_unlock(&dbg_lock); \ |
| 132 | } while (0) |
| 133 | |
| 134 | const char *dbg_key_str0(const struct ubifs_info *c, |
| 135 | const union ubifs_key *key); |
| 136 | const char *dbg_key_str1(const struct ubifs_info *c, |
| 137 | const union ubifs_key *key); |
| 138 | |
| 139 | /* |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 140 | * DBGKEY macros require @dbg_lock to be held, which it is in the dbg message |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 141 | * macros. |
| 142 | */ |
| 143 | #define DBGKEY(key) dbg_key_str0(c, (key)) |
| 144 | #define DBGKEY1(key) dbg_key_str1(c, (key)) |
| 145 | |
| 146 | /* General messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 147 | #define dbg_gen(fmt, ...) dbg_do_msg(UBIFS_MSG_GEN, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 148 | |
| 149 | /* Additional journal messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 150 | #define dbg_jnl(fmt, ...) dbg_do_msg(UBIFS_MSG_JNL, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 151 | |
| 152 | /* Additional TNC messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 153 | #define dbg_tnc(fmt, ...) dbg_do_msg(UBIFS_MSG_TNC, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 154 | |
| 155 | /* Additional lprops messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 156 | #define dbg_lp(fmt, ...) dbg_do_msg(UBIFS_MSG_LP, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 157 | |
| 158 | /* Additional LEB find messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 159 | #define dbg_find(fmt, ...) dbg_do_msg(UBIFS_MSG_FIND, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 160 | |
| 161 | /* Additional mount messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 162 | #define dbg_mnt(fmt, ...) dbg_do_msg(UBIFS_MSG_MNT, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 163 | |
| 164 | /* Additional I/O messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 165 | #define dbg_io(fmt, ...) dbg_do_msg(UBIFS_MSG_IO, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 166 | |
| 167 | /* Additional commit messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 168 | #define dbg_cmt(fmt, ...) dbg_do_msg(UBIFS_MSG_CMT, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 169 | |
| 170 | /* Additional budgeting messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 171 | #define dbg_budg(fmt, ...) dbg_do_msg(UBIFS_MSG_BUDG, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 172 | |
| 173 | /* Additional log messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 174 | #define dbg_log(fmt, ...) dbg_do_msg(UBIFS_MSG_LOG, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 175 | |
| 176 | /* Additional gc messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 177 | #define dbg_gc(fmt, ...) dbg_do_msg(UBIFS_MSG_GC, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 178 | |
| 179 | /* Additional scan messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 180 | #define dbg_scan(fmt, ...) dbg_do_msg(UBIFS_MSG_SCAN, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 181 | |
| 182 | /* Additional recovery messages */ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 183 | #define dbg_rcvry(fmt, ...) dbg_do_msg(UBIFS_MSG_RCVRY, fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 184 | |
| 185 | /* |
Artem Bityutskiy | 5d630e4 | 2011-03-14 17:55:40 +0200 | [diff] [blame] | 186 | * Debugging message type flags. |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 187 | * |
| 188 | * UBIFS_MSG_GEN: general messages |
| 189 | * UBIFS_MSG_JNL: journal messages |
| 190 | * UBIFS_MSG_MNT: mount messages |
| 191 | * UBIFS_MSG_CMT: commit messages |
| 192 | * UBIFS_MSG_FIND: LEB find messages |
| 193 | * UBIFS_MSG_BUDG: budgeting messages |
| 194 | * UBIFS_MSG_GC: garbage collection messages |
| 195 | * UBIFS_MSG_TNC: TNC messages |
| 196 | * UBIFS_MSG_LP: lprops messages |
| 197 | * UBIFS_MSG_IO: I/O messages |
| 198 | * UBIFS_MSG_LOG: log messages |
| 199 | * UBIFS_MSG_SCAN: scan messages |
| 200 | * UBIFS_MSG_RCVRY: recovery messages |
| 201 | */ |
| 202 | enum { |
| 203 | UBIFS_MSG_GEN = 0x1, |
| 204 | UBIFS_MSG_JNL = 0x2, |
| 205 | UBIFS_MSG_MNT = 0x4, |
| 206 | UBIFS_MSG_CMT = 0x8, |
| 207 | UBIFS_MSG_FIND = 0x10, |
| 208 | UBIFS_MSG_BUDG = 0x20, |
| 209 | UBIFS_MSG_GC = 0x40, |
| 210 | UBIFS_MSG_TNC = 0x80, |
| 211 | UBIFS_MSG_LP = 0x100, |
| 212 | UBIFS_MSG_IO = 0x200, |
| 213 | UBIFS_MSG_LOG = 0x400, |
| 214 | UBIFS_MSG_SCAN = 0x800, |
| 215 | UBIFS_MSG_RCVRY = 0x1000, |
| 216 | }; |
| 217 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 218 | /* |
Artem Bityutskiy | 5d630e4 | 2011-03-14 17:55:40 +0200 | [diff] [blame] | 219 | * Debugging check flags. |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 220 | * |
| 221 | * UBIFS_CHK_GEN: general checks |
| 222 | * UBIFS_CHK_TNC: check TNC |
| 223 | * UBIFS_CHK_IDX_SZ: check index size |
| 224 | * UBIFS_CHK_ORPH: check orphans |
| 225 | * UBIFS_CHK_OLD_IDX: check the old index |
| 226 | * UBIFS_CHK_LPROPS: check lprops |
| 227 | * UBIFS_CHK_FS: check the file-system |
| 228 | */ |
| 229 | enum { |
| 230 | UBIFS_CHK_GEN = 0x1, |
| 231 | UBIFS_CHK_TNC = 0x2, |
| 232 | UBIFS_CHK_IDX_SZ = 0x4, |
| 233 | UBIFS_CHK_ORPH = 0x8, |
| 234 | UBIFS_CHK_OLD_IDX = 0x10, |
| 235 | UBIFS_CHK_LPROPS = 0x20, |
| 236 | UBIFS_CHK_FS = 0x40, |
| 237 | }; |
| 238 | |
| 239 | /* |
Artem Bityutskiy | 5d630e4 | 2011-03-14 17:55:40 +0200 | [diff] [blame] | 240 | * Special testing flags. |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 241 | * |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 242 | * UBIFS_TST_RCVRY: failure mode for recovery testing |
| 243 | */ |
| 244 | enum { |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 245 | UBIFS_TST_RCVRY = 0x4, |
| 246 | }; |
| 247 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 248 | extern spinlock_t dbg_lock; |
| 249 | |
| 250 | extern unsigned int ubifs_msg_flags; |
| 251 | extern unsigned int ubifs_chk_flags; |
| 252 | extern unsigned int ubifs_tst_flags; |
| 253 | |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 254 | int ubifs_debugging_init(struct ubifs_info *c); |
| 255 | void ubifs_debugging_exit(struct ubifs_info *c); |
| 256 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 257 | /* Dump functions */ |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 258 | const char *dbg_ntype(int type); |
| 259 | const char *dbg_cstate(int cmt_state); |
Artem Bityutskiy | 77a7ae5 | 2009-09-15 15:03:51 +0300 | [diff] [blame] | 260 | const char *dbg_jhead(int jhead); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 261 | const char *dbg_get_key_dump(const struct ubifs_info *c, |
| 262 | const union ubifs_key *key); |
| 263 | void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode); |
| 264 | void dbg_dump_node(const struct ubifs_info *c, const void *node); |
Artem Bityutskiy | 2ba5f7a | 2008-10-31 17:32:30 +0200 | [diff] [blame] | 265 | void dbg_dump_lpt_node(const struct ubifs_info *c, void *node, int lnum, |
| 266 | int offs); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 267 | void dbg_dump_budget_req(const struct ubifs_budget_req *req); |
| 268 | void dbg_dump_lstats(const struct ubifs_lp_stats *lst); |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 269 | void dbg_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 270 | void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp); |
| 271 | void dbg_dump_lprops(struct ubifs_info *c); |
Adrian Hunter | 73944a6 | 2008-09-12 18:13:31 +0300 | [diff] [blame] | 272 | void dbg_dump_lpt_info(struct ubifs_info *c); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 273 | void dbg_dump_leb(const struct ubifs_info *c, int lnum); |
| 274 | void dbg_dump_znode(const struct ubifs_info *c, |
| 275 | const struct ubifs_znode *znode); |
| 276 | void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat); |
| 277 | void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, |
| 278 | struct ubifs_nnode *parent, int iip); |
| 279 | void dbg_dump_tnc(struct ubifs_info *c); |
| 280 | void dbg_dump_index(struct ubifs_info *c); |
Artem Bityutskiy | 2ba5f7a | 2008-10-31 17:32:30 +0200 | [diff] [blame] | 281 | void dbg_dump_lpt_lebs(const struct ubifs_info *c); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 282 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 283 | int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb, |
| 284 | dbg_znode_callback znode_cb, void *priv); |
| 285 | |
| 286 | /* Checking functions */ |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 287 | void dbg_save_space_info(struct ubifs_info *c); |
| 288 | int dbg_check_space_info(struct ubifs_info *c); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 289 | int dbg_check_lprops(struct ubifs_info *c); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 290 | int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot); |
| 291 | int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 292 | int dbg_check_cats(struct ubifs_info *c); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 293 | int dbg_check_ltab(struct ubifs_info *c); |
Adrian Hunter | 73944a6 | 2008-09-12 18:13:31 +0300 | [diff] [blame] | 294 | int dbg_chk_lpt_free_spc(struct ubifs_info *c); |
| 295 | int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 296 | int dbg_check_synced_i_size(struct inode *inode); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 297 | int dbg_check_dir_size(struct ubifs_info *c, const struct inode *dir); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 298 | int dbg_check_tnc(struct ubifs_info *c, int extra); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 299 | int dbg_check_idx_size(struct ubifs_info *c, long long idx_size); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 300 | int dbg_check_filesystem(struct ubifs_info *c); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 301 | void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat, |
| 302 | int add_pos); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 303 | int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode, |
| 304 | int row, int col); |
Artem Bityutskiy | e3c3efc | 2009-08-27 16:34:19 +0300 | [diff] [blame] | 305 | int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode, |
| 306 | loff_t size); |
Artem Bityutskiy | 3bb66b4 | 2010-08-07 10:06:11 +0300 | [diff] [blame] | 307 | int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head); |
| 308 | int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 309 | |
| 310 | /* Force the use of in-the-gaps method for testing */ |
Artem Bityutskiy | bc3f07f | 2011-04-05 13:52:20 +0300 | [diff] [blame^] | 311 | static inline int dbg_force_in_the_gaps_enabled(void) |
| 312 | { |
| 313 | return ubifs_chk_flags & UBIFS_CHK_GEN; |
| 314 | } |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 315 | int dbg_force_in_the_gaps(void); |
| 316 | |
| 317 | /* Failure mode for recovery testing */ |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 318 | #define dbg_failure_mode (ubifs_tst_flags & UBIFS_TST_RCVRY) |
| 319 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 320 | #ifndef UBIFS_DBG_PRESERVE_UBI |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 321 | #define ubi_leb_read dbg_leb_read |
| 322 | #define ubi_leb_write dbg_leb_write |
| 323 | #define ubi_leb_change dbg_leb_change |
| 324 | #define ubi_leb_erase dbg_leb_erase |
| 325 | #define ubi_leb_unmap dbg_leb_unmap |
| 326 | #define ubi_is_mapped dbg_is_mapped |
| 327 | #define ubi_leb_map dbg_leb_map |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 328 | #endif |
| 329 | |
| 330 | int dbg_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset, |
| 331 | int len, int check); |
| 332 | int dbg_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf, |
| 333 | int offset, int len, int dtype); |
| 334 | int dbg_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, |
| 335 | int len, int dtype); |
| 336 | int dbg_leb_erase(struct ubi_volume_desc *desc, int lnum); |
| 337 | int dbg_leb_unmap(struct ubi_volume_desc *desc, int lnum); |
| 338 | int dbg_is_mapped(struct ubi_volume_desc *desc, int lnum); |
| 339 | int dbg_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype); |
| 340 | |
| 341 | static inline int dbg_read(struct ubi_volume_desc *desc, int lnum, char *buf, |
| 342 | int offset, int len) |
| 343 | { |
| 344 | return dbg_leb_read(desc, lnum, buf, offset, len, 0); |
| 345 | } |
| 346 | |
| 347 | static inline int dbg_write(struct ubi_volume_desc *desc, int lnum, |
| 348 | const void *buf, int offset, int len) |
| 349 | { |
| 350 | return dbg_leb_write(desc, lnum, buf, offset, len, UBI_UNKNOWN); |
| 351 | } |
| 352 | |
| 353 | static inline int dbg_change(struct ubi_volume_desc *desc, int lnum, |
| 354 | const void *buf, int len) |
| 355 | { |
| 356 | return dbg_leb_change(desc, lnum, buf, len, UBI_UNKNOWN); |
| 357 | } |
| 358 | |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 359 | /* Debugfs-related stuff */ |
| 360 | int dbg_debugfs_init(void); |
| 361 | void dbg_debugfs_exit(void); |
| 362 | int dbg_debugfs_init_fs(struct ubifs_info *c); |
| 363 | void dbg_debugfs_exit_fs(struct ubifs_info *c); |
| 364 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 365 | #else /* !CONFIG_UBIFS_FS_DEBUG */ |
| 366 | |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 367 | /* Use "if (0)" to make compiler check arguments even if debugging is off */ |
| 368 | #define ubifs_assert(expr) do { \ |
| 369 | if (0 && (expr)) \ |
| 370 | printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \ |
| 371 | __func__, __LINE__, current->pid); \ |
| 372 | } while (0) |
| 373 | |
| 374 | #define dbg_err(fmt, ...) do { \ |
| 375 | if (0) \ |
| 376 | ubifs_err(fmt, ##__VA_ARGS__); \ |
| 377 | } while (0) |
| 378 | |
| 379 | #define dbg_msg(fmt, ...) do { \ |
| 380 | if (0) \ |
| 381 | printk(KERN_DEBUG "UBIFS DBG (pid %d): %s: " fmt "\n", \ |
| 382 | current->pid, __func__, ##__VA_ARGS__); \ |
| 383 | } while (0) |
| 384 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 385 | #define dbg_dump_stack() |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 386 | #define ubifs_assert_cmt_locked(c) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 387 | |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 388 | #define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
| 389 | #define dbg_jnl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
| 390 | #define dbg_tnc(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
| 391 | #define dbg_lp(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
| 392 | #define dbg_find(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
| 393 | #define dbg_mnt(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
| 394 | #define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
| 395 | #define dbg_cmt(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
| 396 | #define dbg_budg(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
| 397 | #define dbg_log(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
| 398 | #define dbg_gc(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
| 399 | #define dbg_scan(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
| 400 | #define dbg_rcvry(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 401 | |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 402 | #define DBGKEY(key) ((char *)(key)) |
| 403 | #define DBGKEY1(key) ((char *)(key)) |
| 404 | |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 405 | static inline int ubifs_debugging_init(struct ubifs_info *c) { return 0; } |
| 406 | static inline void ubifs_debugging_exit(struct ubifs_info *c) { return; } |
| 407 | static inline const char *dbg_ntype(int type) { return ""; } |
| 408 | static inline const char *dbg_cstate(int cmt_state) { return ""; } |
| 409 | static inline const char *dbg_jhead(int jhead) { return ""; } |
| 410 | static inline const char * |
| 411 | dbg_get_key_dump(const struct ubifs_info *c, |
| 412 | const union ubifs_key *key) { return ""; } |
| 413 | static inline void dbg_dump_inode(const struct ubifs_info *c, |
| 414 | const struct inode *inode) { return; } |
| 415 | static inline void dbg_dump_node(const struct ubifs_info *c, |
| 416 | const void *node) { return; } |
| 417 | static inline void dbg_dump_lpt_node(const struct ubifs_info *c, |
| 418 | void *node, int lnum, |
| 419 | int offs) { return; } |
| 420 | static inline void |
| 421 | dbg_dump_budget_req(const struct ubifs_budget_req *req) { return; } |
| 422 | static inline void |
| 423 | dbg_dump_lstats(const struct ubifs_lp_stats *lst) { return; } |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 424 | static inline void |
| 425 | dbg_dump_budg(struct ubifs_info *c, |
| 426 | const struct ubifs_budg_info *bi) { return; } |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 427 | static inline void dbg_dump_lprop(const struct ubifs_info *c, |
| 428 | const struct ubifs_lprops *lp) { return; } |
| 429 | static inline void dbg_dump_lprops(struct ubifs_info *c) { return; } |
| 430 | static inline void dbg_dump_lpt_info(struct ubifs_info *c) { return; } |
| 431 | static inline void dbg_dump_leb(const struct ubifs_info *c, |
| 432 | int lnum) { return; } |
| 433 | static inline void |
| 434 | dbg_dump_znode(const struct ubifs_info *c, |
| 435 | const struct ubifs_znode *znode) { return; } |
| 436 | static inline void dbg_dump_heap(struct ubifs_info *c, |
| 437 | struct ubifs_lpt_heap *heap, |
| 438 | int cat) { return; } |
| 439 | static inline void dbg_dump_pnode(struct ubifs_info *c, |
| 440 | struct ubifs_pnode *pnode, |
| 441 | struct ubifs_nnode *parent, |
| 442 | int iip) { return; } |
| 443 | static inline void dbg_dump_tnc(struct ubifs_info *c) { return; } |
| 444 | static inline void dbg_dump_index(struct ubifs_info *c) { return; } |
| 445 | static inline void dbg_dump_lpt_lebs(const struct ubifs_info *c) { return; } |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 446 | |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 447 | static inline int dbg_walk_index(struct ubifs_info *c, |
| 448 | dbg_leaf_callback leaf_cb, |
| 449 | dbg_znode_callback znode_cb, |
| 450 | void *priv) { return 0; } |
| 451 | static inline void dbg_save_space_info(struct ubifs_info *c) { return; } |
| 452 | static inline int dbg_check_space_info(struct ubifs_info *c) { return 0; } |
| 453 | static inline int dbg_check_lprops(struct ubifs_info *c) { return 0; } |
| 454 | static inline int |
| 455 | dbg_old_index_check_init(struct ubifs_info *c, |
| 456 | struct ubifs_zbranch *zroot) { return 0; } |
| 457 | static inline int |
| 458 | dbg_check_old_index(struct ubifs_info *c, |
| 459 | struct ubifs_zbranch *zroot) { return 0; } |
| 460 | static inline int dbg_check_cats(struct ubifs_info *c) { return 0; } |
| 461 | static inline int dbg_check_ltab(struct ubifs_info *c) { return 0; } |
| 462 | static inline int dbg_chk_lpt_free_spc(struct ubifs_info *c) { return 0; } |
| 463 | static inline int dbg_chk_lpt_sz(struct ubifs_info *c, |
| 464 | int action, int len) { return 0; } |
| 465 | static inline int dbg_check_synced_i_size(struct inode *inode) { return 0; } |
| 466 | static inline int dbg_check_dir_size(struct ubifs_info *c, |
| 467 | const struct inode *dir) { return 0; } |
| 468 | static inline int dbg_check_tnc(struct ubifs_info *c, int extra) { return 0; } |
| 469 | static inline int dbg_check_idx_size(struct ubifs_info *c, |
| 470 | long long idx_size) { return 0; } |
| 471 | static inline int dbg_check_filesystem(struct ubifs_info *c) { return 0; } |
| 472 | static inline void dbg_check_heap(struct ubifs_info *c, |
| 473 | struct ubifs_lpt_heap *heap, |
| 474 | int cat, int add_pos) { return; } |
| 475 | static inline int dbg_check_lpt_nodes(struct ubifs_info *c, |
| 476 | struct ubifs_cnode *cnode, int row, int col) { return 0; } |
| 477 | static inline int dbg_check_inode_size(struct ubifs_info *c, |
| 478 | const struct inode *inode, |
| 479 | loff_t size) { return 0; } |
| 480 | static inline int |
| 481 | dbg_check_data_nodes_order(struct ubifs_info *c, |
| 482 | struct list_head *head) { return 0; } |
| 483 | static inline int |
| 484 | dbg_check_nondata_nodes_order(struct ubifs_info *c, |
| 485 | struct list_head *head) { return 0; } |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 486 | |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 487 | static inline int dbg_force_in_the_gaps(void) { return 0; } |
Artem Bityutskiy | bc3f07f | 2011-04-05 13:52:20 +0300 | [diff] [blame^] | 488 | #define dbg_force_in_the_gaps_enabled() 0 |
| 489 | #define dbg_failure_mode 0 |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 490 | |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 491 | static inline int dbg_debugfs_init(void) { return 0; } |
| 492 | static inline void dbg_debugfs_exit(void) { return; } |
| 493 | static inline int dbg_debugfs_init_fs(struct ubifs_info *c) { return 0; } |
| 494 | static inline int dbg_debugfs_exit_fs(struct ubifs_info *c) { return 0; } |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 495 | |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 496 | #endif /* !CONFIG_UBIFS_FS_DEBUG */ |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 497 | #endif /* !__UBIFS_DEBUG_H__ */ |