1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#ifndef __UBIFS_DEBUG_H__
24#define __UBIFS_DEBUG_H__
25
26#ifdef CONFIG_UBIFS_FS_DEBUG
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56struct ubifs_debug_info {
57 void *buf;
58 struct ubifs_zbranch old_zroot;
59 int old_zroot_level;
60 unsigned long long old_zroot_sqnum;
61 int failure_mode;
62 int fail_delay;
63 unsigned long fail_timeout;
64 unsigned int fail_cnt;
65 unsigned int fail_cnt_max;
66 long long chk_lpt_sz;
67 long long chk_lpt_sz2;
68 long long chk_lpt_wastage;
69 int chk_lpt_lebs;
70 int new_nhead_offs;
71 int new_ihead_lnum;
72 int new_ihead_offs;
73
74 struct ubifs_lp_stats saved_lst;
75 long long saved_free;
76
77 char dfs_dir_name[100];
78 struct dentry *dfs_dir;
79 struct dentry *dfs_dump_lprops;
80 struct dentry *dfs_dump_budg;
81 struct dentry *dfs_dump_tnc;
82};
83
84#define ubifs_assert(expr) do { \
85 if (unlikely(!(expr))) { \
86 printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \
87 __func__, __LINE__, current->pid); \
88 dbg_dump_stack(); \
89 } \
90} while (0)
91
92#define ubifs_assert_cmt_locked(c) do { \
93 if (unlikely(down_write_trylock(&(c)->commit_sem))) { \
94 up_write(&(c)->commit_sem); \
95 printk(KERN_CRIT "commit lock is not locked!\n"); \
96 ubifs_assert(0); \
97 } \
98} while (0)
99
100#define dbg_dump_stack() do { \
101 if (!dbg_failure_mode) \
102 dump_stack(); \
103} while (0)
104
105
106#define dbg_msg(fmt, ...) do { \
107 spin_lock(&dbg_lock); \
108 printk(KERN_DEBUG "UBIFS DBG (pid %d): %s: " fmt "\n", current->pid, \
109 __func__, ##__VA_ARGS__); \
110 spin_unlock(&dbg_lock); \
111} while (0)
112
113#define dbg_do_msg(typ, fmt, ...) do { \
114 if (ubifs_msg_flags & typ) \
115 dbg_msg(fmt, ##__VA_ARGS__); \
116} while (0)
117
118#define dbg_err(fmt, ...) do { \
119 spin_lock(&dbg_lock); \
120 ubifs_err(fmt, ##__VA_ARGS__); \
121 spin_unlock(&dbg_lock); \
122} while (0)
123
124const char *dbg_key_str0(const struct ubifs_info *c,
125 const union ubifs_key *key);
126const char *dbg_key_str1(const struct ubifs_info *c,
127 const union ubifs_key *key);
128
129
130
131
132
133#define DBGKEY(key) dbg_key_str0(c, (key))
134#define DBGKEY1(key) dbg_key_str1(c, (key))
135
136
137#define dbg_gen(fmt, ...) dbg_do_msg(UBIFS_MSG_GEN, fmt, ##__VA_ARGS__)
138
139
140#define dbg_jnl(fmt, ...) dbg_do_msg(UBIFS_MSG_JNL, fmt, ##__VA_ARGS__)
141
142
143#define dbg_tnc(fmt, ...) dbg_do_msg(UBIFS_MSG_TNC, fmt, ##__VA_ARGS__)
144
145
146#define dbg_lp(fmt, ...) dbg_do_msg(UBIFS_MSG_LP, fmt, ##__VA_ARGS__)
147
148
149#define dbg_find(fmt, ...) dbg_do_msg(UBIFS_MSG_FIND, fmt, ##__VA_ARGS__)
150
151
152#define dbg_mnt(fmt, ...) dbg_do_msg(UBIFS_MSG_MNT, fmt, ##__VA_ARGS__)
153
154
155#define dbg_io(fmt, ...) dbg_do_msg(UBIFS_MSG_IO, fmt, ##__VA_ARGS__)
156
157
158#define dbg_cmt(fmt, ...) dbg_do_msg(UBIFS_MSG_CMT, fmt, ##__VA_ARGS__)
159
160
161#define dbg_budg(fmt, ...) dbg_do_msg(UBIFS_MSG_BUDG, fmt, ##__VA_ARGS__)
162
163
164#define dbg_log(fmt, ...) dbg_do_msg(UBIFS_MSG_LOG, fmt, ##__VA_ARGS__)
165
166
167#define dbg_gc(fmt, ...) dbg_do_msg(UBIFS_MSG_GC, fmt, ##__VA_ARGS__)
168
169
170#define dbg_scan(fmt, ...) dbg_do_msg(UBIFS_MSG_SCAN, fmt, ##__VA_ARGS__)
171
172
173#define dbg_rcvry(fmt, ...) dbg_do_msg(UBIFS_MSG_RCVRY, fmt, ##__VA_ARGS__)
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192enum {
193 UBIFS_MSG_GEN = 0x1,
194 UBIFS_MSG_JNL = 0x2,
195 UBIFS_MSG_MNT = 0x4,
196 UBIFS_MSG_CMT = 0x8,
197 UBIFS_MSG_FIND = 0x10,
198 UBIFS_MSG_BUDG = 0x20,
199 UBIFS_MSG_GC = 0x40,
200 UBIFS_MSG_TNC = 0x80,
201 UBIFS_MSG_LP = 0x100,
202 UBIFS_MSG_IO = 0x200,
203 UBIFS_MSG_LOG = 0x400,
204 UBIFS_MSG_SCAN = 0x800,
205 UBIFS_MSG_RCVRY = 0x1000,
206};
207
208
209#define UBIFS_MSG_LVL_0 0
210#define UBIFS_MSG_LVL_1 0x1
211#define UBIFS_MSG_LVL_2 0x7f
212#define UBIFS_MSG_LVL_3 0xffff
213
214
215
216
217
218
219
220
221
222
223
224
225enum {
226 UBIFS_CHK_GEN = 0x1,
227 UBIFS_CHK_TNC = 0x2,
228 UBIFS_CHK_IDX_SZ = 0x4,
229 UBIFS_CHK_ORPH = 0x8,
230 UBIFS_CHK_OLD_IDX = 0x10,
231 UBIFS_CHK_LPROPS = 0x20,
232 UBIFS_CHK_FS = 0x40,
233};
234
235
236
237
238
239
240
241enum {
242 UBIFS_TST_FORCE_IN_THE_GAPS = 0x2,
243 UBIFS_TST_RCVRY = 0x4,
244};
245
246#if CONFIG_UBIFS_FS_DEBUG_MSG_LVL == 1
247#define UBIFS_MSG_FLAGS_DEFAULT UBIFS_MSG_LVL_1
248#elif CONFIG_UBIFS_FS_DEBUG_MSG_LVL == 2
249#define UBIFS_MSG_FLAGS_DEFAULT UBIFS_MSG_LVL_2
250#elif CONFIG_UBIFS_FS_DEBUG_MSG_LVL == 3
251#define UBIFS_MSG_FLAGS_DEFAULT UBIFS_MSG_LVL_3
252#else
253#define UBIFS_MSG_FLAGS_DEFAULT UBIFS_MSG_LVL_0
254#endif
255
256#ifdef CONFIG_UBIFS_FS_DEBUG_CHKS
257#define UBIFS_CHK_FLAGS_DEFAULT 0xffffffff
258#else
259#define UBIFS_CHK_FLAGS_DEFAULT 0
260#endif
261
262extern spinlock_t dbg_lock;
263
264extern unsigned int ubifs_msg_flags;
265extern unsigned int ubifs_chk_flags;
266extern unsigned int ubifs_tst_flags;
267
268int ubifs_debugging_init(struct ubifs_info *c);
269void ubifs_debugging_exit(struct ubifs_info *c);
270
271
272const char *dbg_ntype(int type);
273const char *dbg_cstate(int cmt_state);
274const char *dbg_jhead(int jhead);
275const char *dbg_get_key_dump(const struct ubifs_info *c,
276 const union ubifs_key *key);
277void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode);
278void dbg_dump_node(const struct ubifs_info *c, const void *node);
279void dbg_dump_lpt_node(const struct ubifs_info *c, void *node, int lnum,
280 int offs);
281void dbg_dump_budget_req(const struct ubifs_budget_req *req);
282void dbg_dump_lstats(const struct ubifs_lp_stats *lst);
283void dbg_dump_budg(struct ubifs_info *c);
284void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp);
285void dbg_dump_lprops(struct ubifs_info *c);
286void dbg_dump_lpt_info(struct ubifs_info *c);
287void dbg_dump_leb(const struct ubifs_info *c, int lnum);
288void dbg_dump_znode(const struct ubifs_info *c,
289 const struct ubifs_znode *znode);
290void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat);
291void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
292 struct ubifs_nnode *parent, int iip);
293void dbg_dump_tnc(struct ubifs_info *c);
294void dbg_dump_index(struct ubifs_info *c);
295void dbg_dump_lpt_lebs(const struct ubifs_info *c);
296
297
298typedef int (*dbg_leaf_callback)(struct ubifs_info *c,
299 struct ubifs_zbranch *zbr, void *priv);
300typedef int (*dbg_znode_callback)(struct ubifs_info *c,
301 struct ubifs_znode *znode, void *priv);
302int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb,
303 dbg_znode_callback znode_cb, void *priv);
304
305
306void dbg_save_space_info(struct ubifs_info *c);
307int dbg_check_space_info(struct ubifs_info *c);
308int dbg_check_lprops(struct ubifs_info *c);
309int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot);
310int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot);
311int dbg_check_cats(struct ubifs_info *c);
312int dbg_check_ltab(struct ubifs_info *c);
313int dbg_chk_lpt_free_spc(struct ubifs_info *c);
314int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len);
315int dbg_check_synced_i_size(struct inode *inode);
316int dbg_check_dir_size(struct ubifs_info *c, const struct inode *dir);
317int dbg_check_tnc(struct ubifs_info *c, int extra);
318int dbg_check_idx_size(struct ubifs_info *c, long long idx_size);
319int dbg_check_filesystem(struct ubifs_info *c);
320void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat,
321 int add_pos);
322int dbg_check_lprops(struct ubifs_info *c);
323int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode,
324 int row, int col);
325int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode,
326 loff_t size);
327
328
329
330#define dbg_force_in_the_gaps_enabled \
331 (ubifs_tst_flags & UBIFS_TST_FORCE_IN_THE_GAPS)
332
333int dbg_force_in_the_gaps(void);
334
335
336
337#define dbg_failure_mode (ubifs_tst_flags & UBIFS_TST_RCVRY)
338
339#ifndef UBIFS_DBG_PRESERVE_UBI
340
341#define ubi_leb_read dbg_leb_read
342#define ubi_leb_write dbg_leb_write
343#define ubi_leb_change dbg_leb_change
344#define ubi_leb_erase dbg_leb_erase
345#define ubi_leb_unmap dbg_leb_unmap
346#define ubi_is_mapped dbg_is_mapped
347#define ubi_leb_map dbg_leb_map
348
349#endif
350
351int dbg_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
352 int len, int check);
353int dbg_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
354 int offset, int len, int dtype);
355int dbg_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
356 int len, int dtype);
357int dbg_leb_erase(struct ubi_volume_desc *desc, int lnum);
358int dbg_leb_unmap(struct ubi_volume_desc *desc, int lnum);
359int dbg_is_mapped(struct ubi_volume_desc *desc, int lnum);
360int dbg_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype);
361
362static inline int dbg_read(struct ubi_volume_desc *desc, int lnum, char *buf,
363 int offset, int len)
364{
365 return dbg_leb_read(desc, lnum, buf, offset, len, 0);
366}
367
368static inline int dbg_write(struct ubi_volume_desc *desc, int lnum,
369 const void *buf, int offset, int len)
370{
371 return dbg_leb_write(desc, lnum, buf, offset, len, UBI_UNKNOWN);
372}
373
374static inline int dbg_change(struct ubi_volume_desc *desc, int lnum,
375 const void *buf, int len)
376{
377 return dbg_leb_change(desc, lnum, buf, len, UBI_UNKNOWN);
378}
379
380
381int dbg_debugfs_init(void);
382void dbg_debugfs_exit(void);
383int dbg_debugfs_init_fs(struct ubifs_info *c);
384void dbg_debugfs_exit_fs(struct ubifs_info *c);
385
386#else
387
388
389#define ubifs_assert(expr) do { \
390 if (0 && (expr)) \
391 printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \
392 __func__, __LINE__, current->pid); \
393} while (0)
394
395#define dbg_err(fmt, ...) do { \
396 if (0) \
397 ubifs_err(fmt, ##__VA_ARGS__); \
398} while (0)
399
400#define dbg_msg(fmt, ...) do { \
401 if (0) \
402 printk(KERN_DEBUG "UBIFS DBG (pid %d): %s: " fmt "\n", \
403 current->pid, __func__, ##__VA_ARGS__); \
404} while (0)
405
406#define dbg_dump_stack()
407#define ubifs_assert_cmt_locked(c)
408
409#define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
410#define dbg_jnl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
411#define dbg_tnc(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
412#define dbg_lp(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
413#define dbg_find(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
414#define dbg_mnt(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
415#define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
416#define dbg_cmt(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
417#define dbg_budg(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
418#define dbg_log(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
419#define dbg_gc(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
420#define dbg_scan(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
421#define dbg_rcvry(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
422
423#define DBGKEY(key) ((char *)(key))
424#define DBGKEY1(key) ((char *)(key))
425
426#define ubifs_debugging_init(c) 0
427#define ubifs_debugging_exit(c) ({})
428
429#define dbg_ntype(type) ""
430#define dbg_cstate(cmt_state) ""
431#define dbg_jhead(jhead) ""
432#define dbg_get_key_dump(c, key) ({})
433#define dbg_dump_inode(c, inode) ({})
434#define dbg_dump_node(c, node) ({})
435#define dbg_dump_lpt_node(c, node, lnum, offs) ({})
436#define dbg_dump_budget_req(req) ({})
437#define dbg_dump_lstats(lst) ({})
438#define dbg_dump_budg(c) ({})
439#define dbg_dump_lprop(c, lp) ({})
440#define dbg_dump_lprops(c) ({})
441#define dbg_dump_lpt_info(c) ({})
442#define dbg_dump_leb(c, lnum) ({})
443#define dbg_dump_znode(c, znode) ({})
444#define dbg_dump_heap(c, heap, cat) ({})
445#define dbg_dump_pnode(c, pnode, parent, iip) ({})
446#define dbg_dump_tnc(c) ({})
447#define dbg_dump_index(c) ({})
448#define dbg_dump_lpt_lebs(c) ({})
449
450#define dbg_walk_index(c, leaf_cb, znode_cb, priv) 0
451#define dbg_old_index_check_init(c, zroot) 0
452#define dbg_save_space_info(c) ({})
453#define dbg_check_space_info(c) 0
454#define dbg_check_old_index(c, zroot) 0
455#define dbg_check_cats(c) 0
456#define dbg_check_ltab(c) 0
457#define dbg_chk_lpt_free_spc(c) 0
458#define dbg_chk_lpt_sz(c, action, len) 0
459#define dbg_check_synced_i_size(inode) 0
460#define dbg_check_dir_size(c, dir) 0
461#define dbg_check_tnc(c, x) 0
462#define dbg_check_idx_size(c, idx_size) 0
463#define dbg_check_filesystem(c) 0
464#define dbg_check_heap(c, heap, cat, add_pos) ({})
465#define dbg_check_lprops(c) 0
466#define dbg_check_lpt_nodes(c, cnode, row, col) 0
467#define dbg_check_inode_size(c, inode, size) 0
468#define dbg_force_in_the_gaps_enabled 0
469#define dbg_force_in_the_gaps() 0
470#define dbg_failure_mode 0
471
472#define dbg_debugfs_init() 0
473#define dbg_debugfs_exit()
474#define dbg_debugfs_init_fs(c) 0
475#define dbg_debugfs_exit_fs(c) 0
476
477#endif
478#endif
479