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