Skip to content

Commit 17c2f9f

Browse files
Artem BityutskiyArtem Bityutskiy
authored andcommitted
UBIFS: separate debugging fields out
Introduce a new data structure which contains all debugging stuff inside. This is cleaner than having debugging stuff directly in 'c'. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
1 parent 5dd7cbc commit 17c2f9f

9 files changed

Lines changed: 156 additions & 113 deletions

File tree

‎fs/ubifs/commit.c‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,12 @@ int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot)
470470
{
471471
struct ubifs_idx_node *idx;
472472
int lnum, offs, len, err = 0;
473+
struct ubifs_debug_info *d = c->dbg;
473474

474-
c->old_zroot = *zroot;
475-
476-
lnum = c->old_zroot.lnum;
477-
offs = c->old_zroot.offs;
478-
len = c->old_zroot.len;
475+
d->old_zroot = *zroot;
476+
lnum = d->old_zroot.lnum;
477+
offs = d->old_zroot.offs;
478+
len = d->old_zroot.len;
479479

480480
idx = kmalloc(c->max_idx_node_sz, GFP_NOFS);
481481
if (!idx)
@@ -485,8 +485,8 @@ int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot)
485485
if (err)
486486
goto out;
487487

488-
c->old_zroot_level = le16_to_cpu(idx->level);
489-
c->old_zroot_sqnum = le64_to_cpu(idx->ch.sqnum);
488+
d->old_zroot_level = le16_to_cpu(idx->level);
489+
d->old_zroot_sqnum = le64_to_cpu(idx->ch.sqnum);
490490
out:
491491
kfree(idx);
492492
return err;
@@ -509,6 +509,7 @@ int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot)
509509
{
510510
int lnum, offs, len, err = 0, uninitialized_var(last_level), child_cnt;
511511
int first = 1, iip;
512+
struct ubifs_debug_info *d = c->dbg;
512513
union ubifs_key lower_key, upper_key, l_key, u_key;
513514
unsigned long long uninitialized_var(last_sqnum);
514515
struct ubifs_idx_node *idx;
@@ -525,9 +526,9 @@ int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot)
525526
UBIFS_IDX_NODE_SZ;
526527

527528
/* Start at the old zroot */
528-
lnum = c->old_zroot.lnum;
529-
offs = c->old_zroot.offs;
530-
len = c->old_zroot.len;
529+
lnum = d->old_zroot.lnum;
530+
offs = d->old_zroot.offs;
531+
len = d->old_zroot.len;
531532
iip = 0;
532533

533534
/*
@@ -560,11 +561,11 @@ int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot)
560561
if (first) {
561562
first = 0;
562563
/* Check root level and sqnum */
563-
if (le16_to_cpu(idx->level) != c->old_zroot_level) {
564+
if (le16_to_cpu(idx->level) != d->old_zroot_level) {
564565
err = 2;
565566
goto out_dump;
566567
}
567-
if (le64_to_cpu(idx->ch.sqnum) != c->old_zroot_sqnum) {
568+
if (le64_to_cpu(idx->ch.sqnum) != d->old_zroot_sqnum) {
568569
err = 3;
569570
goto out_dump;
570571
}

‎fs/ubifs/debug.c‎

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum)
705705

706706
printk(KERN_DEBUG "(pid %d) Dumping LEB %d\n", current->pid, lnum);
707707

708-
sleb = ubifs_scan(c, lnum, 0, c->dbg_buf);
708+
sleb = ubifs_scan(c, lnum, 0, c->dbg->buf);
709709
if (IS_ERR(sleb)) {
710710
ubifs_err("scan error %d", (int)PTR_ERR(sleb));
711711
return;
@@ -2097,7 +2097,7 @@ static int simple_rand(void)
20972097
return (next >> 16) & 32767;
20982098
}
20992099

2100-
void dbg_failure_mode_registration(struct ubifs_info *c)
2100+
static void failure_mode_init(struct ubifs_info *c)
21012101
{
21022102
struct failure_mode_info *fmi;
21032103

@@ -2112,7 +2112,7 @@ void dbg_failure_mode_registration(struct ubifs_info *c)
21122112
spin_unlock(&fmi_lock);
21132113
}
21142114

2115-
void dbg_failure_mode_deregistration(struct ubifs_info *c)
2115+
static void failure_mode_exit(struct ubifs_info *c)
21162116
{
21172117
struct failure_mode_info *fmi, *tmp;
21182118

@@ -2146,42 +2146,44 @@ static int in_failure_mode(struct ubi_volume_desc *desc)
21462146
struct ubifs_info *c = dbg_find_info(desc);
21472147

21482148
if (c && dbg_failure_mode)
2149-
return c->failure_mode;
2149+
return c->dbg->failure_mode;
21502150
return 0;
21512151
}
21522152

21532153
static int do_fail(struct ubi_volume_desc *desc, int lnum, int write)
21542154
{
21552155
struct ubifs_info *c = dbg_find_info(desc);
2156+
struct ubifs_debug_info *d;
21562157

21572158
if (!c || !dbg_failure_mode)
21582159
return 0;
2159-
if (c->failure_mode)
2160+
d = c->dbg;
2161+
if (d->failure_mode)
21602162
return 1;
2161-
if (!c->fail_cnt) {
2163+
if (!d->fail_cnt) {
21622164
/* First call - decide delay to failure */
21632165
if (chance(1, 2)) {
21642166
unsigned int delay = 1 << (simple_rand() >> 11);
21652167

21662168
if (chance(1, 2)) {
2167-
c->fail_delay = 1;
2168-
c->fail_timeout = jiffies +
2169+
d->fail_delay = 1;
2170+
d->fail_timeout = jiffies +
21692171
msecs_to_jiffies(delay);
21702172
dbg_rcvry("failing after %ums", delay);
21712173
} else {
2172-
c->fail_delay = 2;
2173-
c->fail_cnt_max = delay;
2174+
d->fail_delay = 2;
2175+
d->fail_cnt_max = delay;
21742176
dbg_rcvry("failing after %u calls", delay);
21752177
}
21762178
}
2177-
c->fail_cnt += 1;
2179+
d->fail_cnt += 1;
21782180
}
21792181
/* Determine if failure delay has expired */
2180-
if (c->fail_delay == 1) {
2181-
if (time_before(jiffies, c->fail_timeout))
2182+
if (d->fail_delay == 1) {
2183+
if (time_before(jiffies, d->fail_timeout))
21822184
return 0;
2183-
} else if (c->fail_delay == 2)
2184-
if (c->fail_cnt++ < c->fail_cnt_max)
2185+
} else if (d->fail_delay == 2)
2186+
if (d->fail_cnt++ < d->fail_cnt_max)
21852187
return 0;
21862188
if (lnum == UBIFS_SB_LNUM) {
21872189
if (write) {
@@ -2239,7 +2241,7 @@ static int do_fail(struct ubi_volume_desc *desc, int lnum, int write)
22392241
dbg_rcvry("failing in bud LEB %d commit not running", lnum);
22402242
}
22412243
ubifs_err("*** SETTING FAILURE MODE ON (LEB %d) ***", lnum);
2242-
c->failure_mode = 1;
2244+
d->failure_mode = 1;
22432245
dump_stack();
22442246
return 1;
22452247
}
@@ -2344,4 +2346,41 @@ int dbg_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype)
23442346
return 0;
23452347
}
23462348

2349+
/**
2350+
* ubifs_debugging_init - initialize UBIFS debugging.
2351+
* @c: UBIFS file-system description object
2352+
*
2353+
* This function initializes debugging-related data for the file system.
2354+
* Returns zero in case of success and a negative error code in case of
2355+
* failure.
2356+
*/
2357+
int ubifs_debugging_init(struct ubifs_info *c)
2358+
{
2359+
c->dbg = kzalloc(sizeof(struct ubifs_debug_info), GFP_KERNEL);
2360+
if (!c->dbg)
2361+
return -ENOMEM;
2362+
2363+
c->dbg->buf = vmalloc(c->leb_size);
2364+
if (!c->dbg->buf)
2365+
goto out;
2366+
2367+
failure_mode_init(c);
2368+
return 0;
2369+
2370+
out:
2371+
kfree(c->dbg);
2372+
return -ENOMEM;
2373+
}
2374+
2375+
/**
2376+
* ubifs_debugging_exit - free debugging data.
2377+
* @c: UBIFS file-system description object
2378+
*/
2379+
void ubifs_debugging_exit(struct ubifs_info *c)
2380+
{
2381+
failure_mode_exit(c);
2382+
vfree(c->dbg->buf);
2383+
kfree(c->dbg);
2384+
}
2385+
23472386
#endif /* CONFIG_UBIFS_FS_DEBUG */

‎fs/ubifs/debug.h‎

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,43 @@
2525

2626
#ifdef CONFIG_UBIFS_FS_DEBUG
2727

28-
#define UBIFS_DBG(op) op
28+
/**
29+
* ubifs_debug_info - per-FS debugging information.
30+
* @buf: a buffer of LEB size, used for various purposes
31+
* @old_zroot: old index root - used by 'dbg_check_old_index()'
32+
* @old_zroot_level: old index root level - used by 'dbg_check_old_index()'
33+
* @old_zroot_sqnum: old index root sqnum - used by 'dbg_check_old_index()'
34+
* @failure_mode: failure mode for recovery testing
35+
* @fail_delay: 0=>don't delay, 1=>delay a time, 2=>delay a number of calls
36+
* @fail_timeout: time in jiffies when delay of failure mode expires
37+
* @fail_cnt: current number of calls to failure mode I/O functions
38+
* @fail_cnt_max: number of calls by which to delay failure mode
39+
* @chk_lpt_sz: used by LPT tree size checker
40+
* @chk_lpt_sz2: used by LPT tree size checker
41+
* @chk_lpt_wastage: used by LPT tree size checker
42+
* @chk_lpt_lebs: used by LPT tree size checker
43+
* @new_nhead_offs: used by LPT tree size checker
44+
* @new_ihead_lnum: used by debugging to check ihead_lnum
45+
* @new_ihead_offs: used by debugging to check ihead_offs
46+
*/
47+
struct ubifs_debug_info {
48+
void *buf;
49+
struct ubifs_zbranch old_zroot;
50+
int old_zroot_level;
51+
unsigned long long old_zroot_sqnum;
52+
int failure_mode;
53+
int fail_delay;
54+
unsigned long fail_timeout;
55+
unsigned int fail_cnt;
56+
unsigned int fail_cnt_max;
57+
long long chk_lpt_sz;
58+
long long chk_lpt_sz2;
59+
long long chk_lpt_wastage;
60+
int chk_lpt_lebs;
61+
int new_nhead_offs;
62+
int new_ihead_lnum;
63+
int new_ihead_offs;
64+
};
2965

3066
#define ubifs_assert(expr) do { \
3167
if (unlikely(!(expr))) { \
@@ -211,6 +247,9 @@ extern unsigned int ubifs_msg_flags;
211247
extern unsigned int ubifs_chk_flags;
212248
extern unsigned int ubifs_tst_flags;
213249

250+
int ubifs_debugging_init(struct ubifs_info *c);
251+
void ubifs_debugging_exit(struct ubifs_info *c);
252+
214253
/* Dump functions */
215254

216255
const char *dbg_ntype(int type);
@@ -274,9 +313,6 @@ int dbg_force_in_the_gaps(void);
274313

275314
#define dbg_failure_mode (ubifs_tst_flags & UBIFS_TST_RCVRY)
276315

277-
void dbg_failure_mode_registration(struct ubifs_info *c);
278-
void dbg_failure_mode_deregistration(struct ubifs_info *c);
279-
280316
#ifndef UBIFS_DBG_PRESERVE_UBI
281317

282318
#define ubi_leb_read dbg_leb_read
@@ -320,8 +356,6 @@ static inline int dbg_change(struct ubi_volume_desc *desc, int lnum,
320356

321357
#else /* !CONFIG_UBIFS_FS_DEBUG */
322358

323-
#define UBIFS_DBG(op)
324-
325359
/* Use "if (0)" to make compiler check arguments even if debugging is off */
326360
#define ubifs_assert(expr) do { \
327361
if (0 && (expr)) \
@@ -360,6 +394,9 @@ static inline int dbg_change(struct ubi_volume_desc *desc, int lnum,
360394
#define DBGKEY(key) ((char *)(key))
361395
#define DBGKEY1(key) ((char *)(key))
362396

397+
#define ubifs_debugging_init(c) 0
398+
#define ubifs_debugging_exit(c) ({})
399+
363400
#define dbg_ntype(type) ""
364401
#define dbg_cstate(cmt_state) ""
365402
#define dbg_get_key_dump(c, key) ({})
@@ -396,8 +433,6 @@ static inline int dbg_change(struct ubi_volume_desc *desc, int lnum,
396433
#define dbg_force_in_the_gaps_enabled 0
397434
#define dbg_force_in_the_gaps() 0
398435
#define dbg_failure_mode 0
399-
#define dbg_failure_mode_registration(c) ({})
400-
#define dbg_failure_mode_deregistration(c) ({})
401436

402437
#endif /* !CONFIG_UBIFS_FS_DEBUG */
403438

‎fs/ubifs/lprops.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ static int scan_check_cb(struct ubifs_info *c,
10881088
}
10891089
}
10901090

1091-
sleb = ubifs_scan(c, lnum, 0, c->dbg_buf);
1091+
sleb = ubifs_scan(c, lnum, 0, c->dbg->buf);
10921092
if (IS_ERR(sleb)) {
10931093
/*
10941094
* After an unclean unmount, empty and freeable LEBs

0 commit comments

Comments
 (0)