Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * This file is part of UBIFS.
0004  *
0005  * Copyright (C) 2006-2008 Nokia Corporation.
0006  *
0007  * Authors: Artem Bityutskiy (Битюцкий Артём)
0008  *          Adrian Hunter
0009  */
0010 
0011 #ifndef __UBIFS_DEBUG_H__
0012 #define __UBIFS_DEBUG_H__
0013 
0014 /* Checking helper functions */
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  * The UBIFS debugfs directory name pattern and maximum name length (3 for "ubi"
0022  * + 1 for "_" and plus 2x2 for 2 UBI numbers and 1 for the trailing zero byte.
0023  */
0024 #define UBIFS_DFS_DIR_NAME "ubi%d_%d"
0025 #define UBIFS_DFS_DIR_LEN  (3 + 1 + 2*2 + 1)
0026 
0027 /**
0028  * ubifs_debug_info - per-FS debugging information.
0029  * @old_zroot: old index root - used by 'dbg_check_old_index()'
0030  * @old_zroot_level: old index root level - used by 'dbg_check_old_index()'
0031  * @old_zroot_sqnum: old index root sqnum - used by 'dbg_check_old_index()'
0032  *
0033  * @pc_happened: non-zero if an emulated power cut happened
0034  * @pc_delay: 0=>don't delay, 1=>delay a time, 2=>delay a number of calls
0035  * @pc_timeout: time in jiffies when delay of failure mode expires
0036  * @pc_cnt: current number of calls to failure mode I/O functions
0037  * @pc_cnt_max: number of calls by which to delay failure mode
0038  *
0039  * @chk_lpt_sz: used by LPT tree size checker
0040  * @chk_lpt_sz2: used by LPT tree size checker
0041  * @chk_lpt_wastage: used by LPT tree size checker
0042  * @chk_lpt_lebs: used by LPT tree size checker
0043  * @new_nhead_offs: used by LPT tree size checker
0044  * @new_ihead_lnum: used by debugging to check @c->ihead_lnum
0045  * @new_ihead_offs: used by debugging to check @c->ihead_offs
0046  *
0047  * @saved_lst: saved lprops statistics (used by 'dbg_save_space_info()')
0048  * @saved_bi: saved budgeting information
0049  * @saved_free: saved amount of free space
0050  * @saved_idx_gc_cnt: saved value of @c->idx_gc_cnt
0051  *
0052  * @chk_gen: if general extra checks are enabled
0053  * @chk_index: if index xtra checks are enabled
0054  * @chk_orph: if orphans extra checks are enabled
0055  * @chk_lprops: if lprops extra checks are enabled
0056  * @chk_fs: if UBIFS contents extra checks are enabled
0057  * @tst_rcvry: if UBIFS recovery testing mode enabled
0058  *
0059  * @dfs_dir_name: name of debugfs directory containing this file-system's files
0060  * @dfs_dir: direntry object of the file-system debugfs directory
0061  * @dfs_dump_lprops: "dump lprops" debugfs knob
0062  * @dfs_dump_budg: "dump budgeting information" debugfs knob
0063  * @dfs_dump_tnc: "dump TNC" debugfs knob
0064  * @dfs_chk_gen: debugfs knob to enable UBIFS general extra checks
0065  * @dfs_chk_index: debugfs knob to enable UBIFS index extra checks
0066  * @dfs_chk_orph: debugfs knob to enable UBIFS orphans extra checks
0067  * @dfs_chk_lprops: debugfs knob to enable UBIFS LEP properties extra checks
0068  * @dfs_chk_fs: debugfs knob to enable UBIFS contents extra checks
0069  * @dfs_tst_rcvry: debugfs knob to enable UBIFS recovery testing
0070  * @dfs_ro_error: debugfs knob to switch UBIFS to R/O mode (different to
0071  *                re-mounting to R/O mode because it does not flush any buffers
0072  *                and UBIFS just starts returning -EROFS on all write
0073  *               operations)
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  * ubifs_global_debug_info - global (not per-FS) UBIFS debugging information.
0122  *
0123  * @chk_gen: if general extra checks are enabled
0124  * @chk_index: if index xtra checks are enabled
0125  * @chk_orph: if orphans extra checks are enabled
0126  * @chk_lprops: if lprops extra checks are enabled
0127  * @chk_fs: if UBIFS contents extra checks are enabled
0128  * @tst_rcvry: if UBIFS recovery testing mode enabled
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 /* General messages */
0170 #define dbg_gen(fmt, ...)   ubifs_dbg_msg("gen", fmt, ##__VA_ARGS__)
0171 /* Additional journal messages */
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 /* Additional TNC messages */
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 /* Additional lprops messages */
0180 #define dbg_lp(fmt, ...)    ubifs_dbg_msg("lp", fmt, ##__VA_ARGS__)
0181 /* Additional LEB find messages */
0182 #define dbg_find(fmt, ...)  ubifs_dbg_msg("find", fmt, ##__VA_ARGS__)
0183 /* Additional mount messages */
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 /* Additional I/O messages */
0188 #define dbg_io(fmt, ...)    ubifs_dbg_msg("io", fmt, ##__VA_ARGS__)
0189 /* Additional commit messages */
0190 #define dbg_cmt(fmt, ...)   ubifs_dbg_msg("cmt", fmt, ##__VA_ARGS__)
0191 /* Additional budgeting messages */
0192 #define dbg_budg(fmt, ...)  ubifs_dbg_msg("budg", fmt, ##__VA_ARGS__)
0193 /* Additional log messages */
0194 #define dbg_log(fmt, ...)   ubifs_dbg_msg("log", fmt, ##__VA_ARGS__)
0195 /* Additional gc messages */
0196 #define dbg_gc(fmt, ...)    ubifs_dbg_msg("gc", fmt, ##__VA_ARGS__)
0197 /* Additional scan messages */
0198 #define dbg_scan(fmt, ...)  ubifs_dbg_msg("scan", fmt, ##__VA_ARGS__)
0199 /* Additional recovery messages */
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 /* Dump functions */
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 /* Checking functions */
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 /* Debugfs-related stuff */
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 /* !__UBIFS_DEBUG_H__ */