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 | ae380ce | 2011-05-19 14:13:16 +0300 | [diff] [blame] | 36 | /* |
| 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. |
| 39 | */ |
| 40 | #define UBIFS_DFS_DIR_NAME "ubi%d_%d" |
| 41 | #define UBIFS_DFS_DIR_LEN (3 + 1 + 2*2 + 1) |
| 42 | |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 43 | /** |
| 44 | * ubifs_debug_info - per-FS debugging information. |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 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 |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 58 | * @new_ihead_lnum: used by debugging to check @c->ihead_lnum |
| 59 | * @new_ihead_offs: used by debugging to check @c->ihead_offs |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 60 | * |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 61 | * @saved_lst: saved lprops statistics (used by 'dbg_save_space_info()') |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 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 |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 65 | * |
Artem Bityutskiy | bdc1a1b | 2011-05-17 14:07:24 +0300 | [diff] [blame] | 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 |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 71 | */ |
| 72 | struct ubifs_debug_info { |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 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; |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 88 | |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 89 | struct ubifs_lp_stats saved_lst; |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 90 | struct ubifs_budg_info saved_bi; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 91 | long long saved_free; |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 92 | int saved_idx_gc_cnt; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 93 | |
Artem Bityutskiy | ae380ce | 2011-05-19 14:13:16 +0300 | [diff] [blame] | 94 | char dfs_dir_name[UBIFS_DFS_DIR_LEN + 1]; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 95 | struct dentry *dfs_dir; |
| 96 | struct dentry *dfs_dump_lprops; |
| 97 | struct dentry *dfs_dump_budg; |
| 98 | struct dentry *dfs_dump_tnc; |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 99 | }; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 100 | |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 101 | #define ubifs_assert(expr) do { \ |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 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(); \ |
| 106 | } \ |
| 107 | } while (0) |
| 108 | |
| 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); \ |
| 114 | } \ |
| 115 | } while (0) |
| 116 | |
Artem Bityutskiy | ec06814 | 2011-04-26 10:21:54 +0300 | [diff] [blame] | 117 | #define dbg_dump_stack() dump_stack() |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 118 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 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) |
| 124 | |
| 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); |
| 129 | |
| 130 | /* |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 131 | * 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] | 132 | * macros. |
| 133 | */ |
| 134 | #define DBGKEY(key) dbg_key_str0(c, (key)) |
| 135 | #define DBGKEY1(key) dbg_key_str1(c, (key)) |
| 136 | |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 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) |
| 142 | |
| 143 | /* Just a debugging messages not related to any specific UBIFS subsystem */ |
| 144 | #define dbg_msg(fmt, ...) ubifs_dbg_msg("msg", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 145 | /* General messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 146 | #define dbg_gen(fmt, ...) ubifs_dbg_msg("gen", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 147 | /* Additional journal messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 148 | #define dbg_jnl(fmt, ...) ubifs_dbg_msg("jnl", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 149 | /* Additional TNC messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 150 | #define dbg_tnc(fmt, ...) ubifs_dbg_msg("tnc", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 151 | /* Additional lprops messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 152 | #define dbg_lp(fmt, ...) ubifs_dbg_msg("lp", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 153 | /* Additional LEB find messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 154 | #define dbg_find(fmt, ...) ubifs_dbg_msg("find", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 155 | /* Additional mount messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 156 | #define dbg_mnt(fmt, ...) ubifs_dbg_msg("mnt", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 157 | /* Additional I/O messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 158 | #define dbg_io(fmt, ...) ubifs_dbg_msg("io", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 159 | /* Additional commit messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 160 | #define dbg_cmt(fmt, ...) ubifs_dbg_msg("cmt", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 161 | /* Additional budgeting messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 162 | #define dbg_budg(fmt, ...) ubifs_dbg_msg("budg", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 163 | /* Additional log messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 164 | #define dbg_log(fmt, ...) ubifs_dbg_msg("log", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 165 | /* Additional gc messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 166 | #define dbg_gc(fmt, ...) ubifs_dbg_msg("gc", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 167 | /* Additional scan messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 168 | #define dbg_scan(fmt, ...) ubifs_dbg_msg("scan", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 169 | /* Additional recovery messages */ |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 170 | #define dbg_rcvry(fmt, ...) ubifs_dbg_msg("rcvry", fmt, ##__VA_ARGS__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 171 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 172 | /* |
Artem Bityutskiy | 5d630e4 | 2011-03-14 17:55:40 +0200 | [diff] [blame] | 173 | * Debugging check flags. |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 174 | * |
| 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 |
| 182 | */ |
| 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, |
| 191 | }; |
| 192 | |
| 193 | /* |
Artem Bityutskiy | 5d630e4 | 2011-03-14 17:55:40 +0200 | [diff] [blame] | 194 | * Special testing flags. |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 195 | * |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 196 | * UBIFS_TST_RCVRY: failure mode for recovery testing |
| 197 | */ |
| 198 | enum { |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 199 | UBIFS_TST_RCVRY = 0x4, |
| 200 | }; |
| 201 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 202 | extern spinlock_t dbg_lock; |
| 203 | |
| 204 | extern unsigned int ubifs_msg_flags; |
| 205 | extern unsigned int ubifs_chk_flags; |
| 206 | extern unsigned int ubifs_tst_flags; |
| 207 | |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 208 | int ubifs_debugging_init(struct ubifs_info *c); |
| 209 | void ubifs_debugging_exit(struct ubifs_info *c); |
| 210 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 211 | /* Dump functions */ |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 212 | const char *dbg_ntype(int type); |
| 213 | const char *dbg_cstate(int cmt_state); |
Artem Bityutskiy | 77a7ae5 | 2009-09-15 15:03:51 +0300 | [diff] [blame] | 214 | const char *dbg_jhead(int jhead); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 215 | const char *dbg_get_key_dump(const struct ubifs_info *c, |
| 216 | const union ubifs_key *key); |
Artem Bityutskiy | 4315fb4 | 2011-05-25 17:32:42 +0300 | [diff] [blame] | 217 | void dbg_dump_inode(struct ubifs_info *c, const struct inode *inode); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 218 | void dbg_dump_node(const struct ubifs_info *c, const void *node); |
Artem Bityutskiy | 2ba5f7a | 2008-10-31 17:32:30 +0200 | [diff] [blame] | 219 | void dbg_dump_lpt_node(const struct ubifs_info *c, void *node, int lnum, |
| 220 | int offs); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 221 | void dbg_dump_budget_req(const struct ubifs_budget_req *req); |
| 222 | void dbg_dump_lstats(const struct ubifs_lp_stats *lst); |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 223 | 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] | 224 | void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp); |
| 225 | void dbg_dump_lprops(struct ubifs_info *c); |
Adrian Hunter | 73944a6 | 2008-09-12 18:13:31 +0300 | [diff] [blame] | 226 | void dbg_dump_lpt_info(struct ubifs_info *c); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 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); |
Artem Bityutskiy | 2ba5f7a | 2008-10-31 17:32:30 +0200 | [diff] [blame] | 235 | void dbg_dump_lpt_lebs(const struct ubifs_info *c); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 236 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 237 | int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb, |
| 238 | dbg_znode_callback znode_cb, void *priv); |
| 239 | |
| 240 | /* Checking functions */ |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 241 | void dbg_save_space_info(struct ubifs_info *c); |
| 242 | int dbg_check_space_info(struct ubifs_info *c); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 243 | int dbg_check_lprops(struct ubifs_info *c); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 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); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 246 | int dbg_check_cats(struct ubifs_info *c); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 247 | int dbg_check_ltab(struct ubifs_info *c); |
Adrian Hunter | 73944a6 | 2008-09-12 18:13:31 +0300 | [diff] [blame] | 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); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 250 | int dbg_check_synced_i_size(struct inode *inode); |
Artem Bityutskiy | 1b51e98 | 2011-05-25 17:38:29 +0300 | [diff] [blame^] | 251 | int dbg_check_dir(struct ubifs_info *c, const struct inode *dir); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 252 | int dbg_check_tnc(struct ubifs_info *c, int extra); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 253 | 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] | 254 | int dbg_check_filesystem(struct ubifs_info *c); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 255 | void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat, |
| 256 | int add_pos); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 257 | int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode, |
| 258 | int row, int col); |
Artem Bityutskiy | e3c3efc | 2009-08-27 16:34:19 +0300 | [diff] [blame] | 259 | int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode, |
| 260 | loff_t size); |
Artem Bityutskiy | 3bb66b4 | 2010-08-07 10:06:11 +0300 | [diff] [blame] | 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); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 263 | |
| 264 | /* Force the use of in-the-gaps method for testing */ |
Artem Bityutskiy | bc3f07f | 2011-04-05 13:52:20 +0300 | [diff] [blame] | 265 | static inline int dbg_force_in_the_gaps_enabled(void) |
| 266 | { |
| 267 | return ubifs_chk_flags & UBIFS_CHK_GEN; |
| 268 | } |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 269 | int dbg_force_in_the_gaps(void); |
| 270 | |
| 271 | /* Failure mode for recovery testing */ |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 272 | #define dbg_failure_mode (ubifs_tst_flags & UBIFS_TST_RCVRY) |
| 273 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 274 | #ifndef UBIFS_DBG_PRESERVE_UBI |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 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 |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 282 | #endif |
| 283 | |
| 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); |
| 294 | |
| 295 | static inline int dbg_read(struct ubi_volume_desc *desc, int lnum, char *buf, |
| 296 | int offset, int len) |
| 297 | { |
| 298 | return dbg_leb_read(desc, lnum, buf, offset, len, 0); |
| 299 | } |
| 300 | |
| 301 | static inline int dbg_write(struct ubi_volume_desc *desc, int lnum, |
| 302 | const void *buf, int offset, int len) |
| 303 | { |
| 304 | return dbg_leb_write(desc, lnum, buf, offset, len, UBI_UNKNOWN); |
| 305 | } |
| 306 | |
| 307 | static inline int dbg_change(struct ubi_volume_desc *desc, int lnum, |
| 308 | const void *buf, int len) |
| 309 | { |
| 310 | return dbg_leb_change(desc, lnum, buf, len, UBI_UNKNOWN); |
| 311 | } |
| 312 | |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 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); |
| 318 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 319 | #else /* !CONFIG_UBIFS_FS_DEBUG */ |
| 320 | |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 321 | /* Use "if (0)" to make compiler check arguments even if debugging is off */ |
| 322 | #define ubifs_assert(expr) do { \ |
Artem Bityutskiy | ae380ce | 2011-05-19 14:13:16 +0300 | [diff] [blame] | 323 | if (0) \ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 324 | printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \ |
| 325 | __func__, __LINE__, current->pid); \ |
| 326 | } while (0) |
| 327 | |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 328 | #define dbg_err(fmt, ...) do { \ |
| 329 | if (0) \ |
| 330 | ubifs_err(fmt, ##__VA_ARGS__); \ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 331 | } while (0) |
| 332 | |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 333 | #define ubifs_dbg_msg(fmt, ...) do { \ |
| 334 | if (0) \ |
| 335 | pr_debug(fmt "\n", ##__VA_ARGS__); \ |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 336 | } while (0) |
| 337 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 338 | #define dbg_dump_stack() |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 339 | #define ubifs_assert_cmt_locked(c) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 340 | |
Artem Bityutskiy | 56e4674 | 2011-05-17 15:15:30 +0300 | [diff] [blame] | 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__) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 355 | |
Artem Bityutskiy | 840dc6b | 2008-08-01 18:13:37 +0300 | [diff] [blame] | 356 | #define DBGKEY(key) ((char *)(key)) |
| 357 | #define DBGKEY1(key) ((char *)(key)) |
| 358 | |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 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 ""; } |
Artem Bityutskiy | 4315fb4 | 2011-05-25 17:32:42 +0300 | [diff] [blame] | 367 | static inline void dbg_dump_inode(struct ubifs_info *c, |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 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; } |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 378 | static inline void |
| 379 | dbg_dump_budg(struct ubifs_info *c, |
| 380 | const struct ubifs_budg_info *bi) { return; } |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 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; } |
Artem Bityutskiy | 17c2f9f | 2008-10-17 13:31:39 +0300 | [diff] [blame] | 400 | |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 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; } |
Artem Bityutskiy | 1b51e98 | 2011-05-25 17:38:29 +0300 | [diff] [blame^] | 420 | static inline int dbg_check_dir(struct ubifs_info *c, |
Artem Bityutskiy | 4315fb4 | 2011-05-25 17:32:42 +0300 | [diff] [blame] | 421 | const struct inode *dir) { return 0; } |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 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; } |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 440 | |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 441 | static inline int dbg_force_in_the_gaps(void) { return 0; } |
Artem Bityutskiy | bc3f07f | 2011-04-05 13:52:20 +0300 | [diff] [blame] | 442 | #define dbg_force_in_the_gaps_enabled() 0 |
| 443 | #define dbg_failure_mode 0 |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 444 | |
Maksim Rayskiy | 1dcffad | 2011-04-12 15:14:56 -0700 | [diff] [blame] | 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; } |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 449 | |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 450 | #endif /* !CONFIG_UBIFS_FS_DEBUG */ |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 451 | #endif /* !__UBIFS_DEBUG_H__ */ |