0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef __UBIFS_DEBUG_H__
0012 #define __UBIFS_DEBUG_H__
0013
0014
0015 typedef int (*dbg_leaf_callback)(struct ubifs_info *c,
0016 struct ubifs_zbranch *zbr, void *priv);
0017 typedef int (*dbg_znode_callback)(struct ubifs_info *c,
0018 struct ubifs_znode *znode, void *priv);
0019
0020
0021
0022
0023
0024 #define UBIFS_DFS_DIR_NAME "ubi%d_%d"
0025 #define UBIFS_DFS_DIR_LEN (3 + 1 + 2*2 + 1)
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 struct ubifs_debug_info {
0076 struct ubifs_zbranch old_zroot;
0077 int old_zroot_level;
0078 unsigned long long old_zroot_sqnum;
0079
0080 int pc_happened;
0081 int pc_delay;
0082 unsigned long pc_timeout;
0083 unsigned int pc_cnt;
0084 unsigned int pc_cnt_max;
0085
0086 long long chk_lpt_sz;
0087 long long chk_lpt_sz2;
0088 long long chk_lpt_wastage;
0089 int chk_lpt_lebs;
0090 int new_nhead_offs;
0091 int new_ihead_lnum;
0092 int new_ihead_offs;
0093
0094 struct ubifs_lp_stats saved_lst;
0095 struct ubifs_budg_info saved_bi;
0096 long long saved_free;
0097 int saved_idx_gc_cnt;
0098
0099 unsigned int chk_gen:1;
0100 unsigned int chk_index:1;
0101 unsigned int chk_orph:1;
0102 unsigned int chk_lprops:1;
0103 unsigned int chk_fs:1;
0104 unsigned int tst_rcvry:1;
0105
0106 char dfs_dir_name[UBIFS_DFS_DIR_LEN + 1];
0107 struct dentry *dfs_dir;
0108 struct dentry *dfs_dump_lprops;
0109 struct dentry *dfs_dump_budg;
0110 struct dentry *dfs_dump_tnc;
0111 struct dentry *dfs_chk_gen;
0112 struct dentry *dfs_chk_index;
0113 struct dentry *dfs_chk_orph;
0114 struct dentry *dfs_chk_lprops;
0115 struct dentry *dfs_chk_fs;
0116 struct dentry *dfs_tst_rcvry;
0117 struct dentry *dfs_ro_error;
0118 };
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130 struct ubifs_global_debug_info {
0131 unsigned int chk_gen:1;
0132 unsigned int chk_index:1;
0133 unsigned int chk_orph:1;
0134 unsigned int chk_lprops:1;
0135 unsigned int chk_fs:1;
0136 unsigned int tst_rcvry:1;
0137 };
0138
0139 void ubifs_assert_failed(struct ubifs_info *c, const char *expr,
0140 const char *file, int line);
0141
0142 #define ubifs_assert(c, expr) do { \
0143 if (unlikely(!(expr))) { \
0144 ubifs_assert_failed((struct ubifs_info *)c, #expr, __FILE__, \
0145 __LINE__); \
0146 } \
0147 } while (0)
0148
0149 #define ubifs_assert_cmt_locked(c) do { \
0150 if (unlikely(down_write_trylock(&(c)->commit_sem))) { \
0151 up_write(&(c)->commit_sem); \
0152 ubifs_err(c, "commit lock is not locked!\n"); \
0153 ubifs_assert(c, 0); \
0154 } \
0155 } while (0)
0156
0157 #define ubifs_dbg_msg(type, fmt, ...) \
0158 pr_debug("UBIFS DBG " type " (pid %d): " fmt "\n", current->pid, \
0159 ##__VA_ARGS__)
0160
0161 #define DBG_KEY_BUF_LEN 48
0162 #define ubifs_dbg_msg_key(type, key, fmt, ...) do { \
0163 char __tmp_key_buf[DBG_KEY_BUF_LEN]; \
0164 pr_debug("UBIFS DBG " type " (pid %d): " fmt "%s\n", current->pid, \
0165 ##__VA_ARGS__, \
0166 dbg_snprintf_key(c, key, __tmp_key_buf, DBG_KEY_BUF_LEN)); \
0167 } while (0)
0168
0169
0170 #define dbg_gen(fmt, ...) ubifs_dbg_msg("gen", fmt, ##__VA_ARGS__)
0171
0172 #define dbg_jnl(fmt, ...) ubifs_dbg_msg("jnl", fmt, ##__VA_ARGS__)
0173 #define dbg_jnlk(key, fmt, ...) \
0174 ubifs_dbg_msg_key("jnl", key, fmt, ##__VA_ARGS__)
0175
0176 #define dbg_tnc(fmt, ...) ubifs_dbg_msg("tnc", fmt, ##__VA_ARGS__)
0177 #define dbg_tnck(key, fmt, ...) \
0178 ubifs_dbg_msg_key("tnc", key, fmt, ##__VA_ARGS__)
0179
0180 #define dbg_lp(fmt, ...) ubifs_dbg_msg("lp", fmt, ##__VA_ARGS__)
0181
0182 #define dbg_find(fmt, ...) ubifs_dbg_msg("find", fmt, ##__VA_ARGS__)
0183
0184 #define dbg_mnt(fmt, ...) ubifs_dbg_msg("mnt", fmt, ##__VA_ARGS__)
0185 #define dbg_mntk(key, fmt, ...) \
0186 ubifs_dbg_msg_key("mnt", key, fmt, ##__VA_ARGS__)
0187
0188 #define dbg_io(fmt, ...) ubifs_dbg_msg("io", fmt, ##__VA_ARGS__)
0189
0190 #define dbg_cmt(fmt, ...) ubifs_dbg_msg("cmt", fmt, ##__VA_ARGS__)
0191
0192 #define dbg_budg(fmt, ...) ubifs_dbg_msg("budg", fmt, ##__VA_ARGS__)
0193
0194 #define dbg_log(fmt, ...) ubifs_dbg_msg("log", fmt, ##__VA_ARGS__)
0195
0196 #define dbg_gc(fmt, ...) ubifs_dbg_msg("gc", fmt, ##__VA_ARGS__)
0197
0198 #define dbg_scan(fmt, ...) ubifs_dbg_msg("scan", fmt, ##__VA_ARGS__)
0199
0200 #define dbg_rcvry(fmt, ...) ubifs_dbg_msg("rcvry", fmt, ##__VA_ARGS__)
0201
0202 extern struct ubifs_global_debug_info ubifs_dbg;
0203
0204 static inline int dbg_is_chk_gen(const struct ubifs_info *c)
0205 {
0206 return !!(ubifs_dbg.chk_gen || c->dbg->chk_gen);
0207 }
0208 static inline int dbg_is_chk_index(const struct ubifs_info *c)
0209 {
0210 return !!(ubifs_dbg.chk_index || c->dbg->chk_index);
0211 }
0212 static inline int dbg_is_chk_orph(const struct ubifs_info *c)
0213 {
0214 return !!(ubifs_dbg.chk_orph || c->dbg->chk_orph);
0215 }
0216 static inline int dbg_is_chk_lprops(const struct ubifs_info *c)
0217 {
0218 return !!(ubifs_dbg.chk_lprops || c->dbg->chk_lprops);
0219 }
0220 static inline int dbg_is_chk_fs(const struct ubifs_info *c)
0221 {
0222 return !!(ubifs_dbg.chk_fs || c->dbg->chk_fs);
0223 }
0224 static inline int dbg_is_tst_rcvry(const struct ubifs_info *c)
0225 {
0226 return !!(ubifs_dbg.tst_rcvry || c->dbg->tst_rcvry);
0227 }
0228 static inline int dbg_is_power_cut(const struct ubifs_info *c)
0229 {
0230 return !!c->dbg->pc_happened;
0231 }
0232
0233 int ubifs_debugging_init(struct ubifs_info *c);
0234 void ubifs_debugging_exit(struct ubifs_info *c);
0235
0236
0237 const char *dbg_ntype(int type);
0238 const char *dbg_cstate(int cmt_state);
0239 const char *dbg_jhead(int jhead);
0240 const char *dbg_get_key_dump(const struct ubifs_info *c,
0241 const union ubifs_key *key);
0242 const char *dbg_snprintf_key(const struct ubifs_info *c,
0243 const union ubifs_key *key, char *buffer, int len);
0244 void ubifs_dump_inode(struct ubifs_info *c, const struct inode *inode);
0245 void ubifs_dump_node(const struct ubifs_info *c, const void *node,
0246 int node_len);
0247 void ubifs_dump_budget_req(const struct ubifs_budget_req *req);
0248 void ubifs_dump_lstats(const struct ubifs_lp_stats *lst);
0249 void ubifs_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi);
0250 void ubifs_dump_lprop(const struct ubifs_info *c,
0251 const struct ubifs_lprops *lp);
0252 void ubifs_dump_lprops(struct ubifs_info *c);
0253 void ubifs_dump_lpt_info(struct ubifs_info *c);
0254 void ubifs_dump_leb(const struct ubifs_info *c, int lnum);
0255 void ubifs_dump_znode(const struct ubifs_info *c,
0256 const struct ubifs_znode *znode);
0257 void ubifs_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap,
0258 int cat);
0259 void ubifs_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
0260 struct ubifs_nnode *parent, int iip);
0261 void ubifs_dump_tnc(struct ubifs_info *c);
0262 void ubifs_dump_index(struct ubifs_info *c);
0263 void ubifs_dump_lpt_lebs(const struct ubifs_info *c);
0264
0265 int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb,
0266 dbg_znode_callback znode_cb, void *priv);
0267
0268
0269 void dbg_save_space_info(struct ubifs_info *c);
0270 int dbg_check_space_info(struct ubifs_info *c);
0271 int dbg_check_lprops(struct ubifs_info *c);
0272 int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot);
0273 int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot);
0274 int dbg_check_cats(struct ubifs_info *c);
0275 int dbg_check_ltab(struct ubifs_info *c);
0276 int dbg_chk_lpt_free_spc(struct ubifs_info *c);
0277 int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len);
0278 int dbg_check_synced_i_size(const struct ubifs_info *c, struct inode *inode);
0279 int dbg_check_dir(struct ubifs_info *c, const struct inode *dir);
0280 int dbg_check_tnc(struct ubifs_info *c, int extra);
0281 int dbg_check_idx_size(struct ubifs_info *c, long long idx_size);
0282 int dbg_check_filesystem(struct ubifs_info *c);
0283 void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat,
0284 int add_pos);
0285 int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode,
0286 int row, int col);
0287 int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode,
0288 loff_t size);
0289 int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head);
0290 int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head);
0291
0292 int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
0293 int len);
0294 int dbg_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len);
0295 int dbg_leb_unmap(struct ubifs_info *c, int lnum);
0296 int dbg_leb_map(struct ubifs_info *c, int lnum);
0297
0298
0299 void dbg_debugfs_init(void);
0300 void dbg_debugfs_exit(void);
0301 void dbg_debugfs_init_fs(struct ubifs_info *c);
0302 void dbg_debugfs_exit_fs(struct ubifs_info *c);
0303
0304 #endif