Skip to content

Commit

Permalink
UBIFS: separate debugging fields out
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Artem Bityutskiy authored and Artem Bityutskiy committed Dec 3, 2008
1 parent 5dd7cbc commit 17c2f9f
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 113 deletions.
25 changes: 13 additions & 12 deletions fs/ubifs/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,12 @@ int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot)
{
struct ubifs_idx_node *idx;
int lnum, offs, len, err = 0;
struct ubifs_debug_info *d = c->dbg;

c->old_zroot = *zroot;

lnum = c->old_zroot.lnum;
offs = c->old_zroot.offs;
len = c->old_zroot.len;
d->old_zroot = *zroot;
lnum = d->old_zroot.lnum;
offs = d->old_zroot.offs;
len = d->old_zroot.len;

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

c->old_zroot_level = le16_to_cpu(idx->level);
c->old_zroot_sqnum = le64_to_cpu(idx->ch.sqnum);
d->old_zroot_level = le16_to_cpu(idx->level);
d->old_zroot_sqnum = le64_to_cpu(idx->ch.sqnum);
out:
kfree(idx);
return err;
Expand All @@ -509,6 +509,7 @@ int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot)
{
int lnum, offs, len, err = 0, uninitialized_var(last_level), child_cnt;
int first = 1, iip;
struct ubifs_debug_info *d = c->dbg;
union ubifs_key lower_key, upper_key, l_key, u_key;
unsigned long long uninitialized_var(last_sqnum);
struct ubifs_idx_node *idx;
Expand All @@ -525,9 +526,9 @@ int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot)
UBIFS_IDX_NODE_SZ;

/* Start at the old zroot */
lnum = c->old_zroot.lnum;
offs = c->old_zroot.offs;
len = c->old_zroot.len;
lnum = d->old_zroot.lnum;
offs = d->old_zroot.offs;
len = d->old_zroot.len;
iip = 0;

/*
Expand Down Expand Up @@ -560,11 +561,11 @@ int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot)
if (first) {
first = 0;
/* Check root level and sqnum */
if (le16_to_cpu(idx->level) != c->old_zroot_level) {
if (le16_to_cpu(idx->level) != d->old_zroot_level) {
err = 2;
goto out_dump;
}
if (le64_to_cpu(idx->ch.sqnum) != c->old_zroot_sqnum) {
if (le64_to_cpu(idx->ch.sqnum) != d->old_zroot_sqnum) {
err = 3;
goto out_dump;
}
Expand Down
71 changes: 55 additions & 16 deletions fs/ubifs/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum)

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

sleb = ubifs_scan(c, lnum, 0, c->dbg_buf);
sleb = ubifs_scan(c, lnum, 0, c->dbg->buf);
if (IS_ERR(sleb)) {
ubifs_err("scan error %d", (int)PTR_ERR(sleb));
return;
Expand Down Expand Up @@ -2097,7 +2097,7 @@ static int simple_rand(void)
return (next >> 16) & 32767;
}

void dbg_failure_mode_registration(struct ubifs_info *c)
static void failure_mode_init(struct ubifs_info *c)
{
struct failure_mode_info *fmi;

Expand All @@ -2112,7 +2112,7 @@ void dbg_failure_mode_registration(struct ubifs_info *c)
spin_unlock(&fmi_lock);
}

void dbg_failure_mode_deregistration(struct ubifs_info *c)
static void failure_mode_exit(struct ubifs_info *c)
{
struct failure_mode_info *fmi, *tmp;

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

if (c && dbg_failure_mode)
return c->failure_mode;
return c->dbg->failure_mode;
return 0;
}

static int do_fail(struct ubi_volume_desc *desc, int lnum, int write)
{
struct ubifs_info *c = dbg_find_info(desc);
struct ubifs_debug_info *d;

if (!c || !dbg_failure_mode)
return 0;
if (c->failure_mode)
d = c->dbg;
if (d->failure_mode)
return 1;
if (!c->fail_cnt) {
if (!d->fail_cnt) {
/* First call - decide delay to failure */
if (chance(1, 2)) {
unsigned int delay = 1 << (simple_rand() >> 11);

if (chance(1, 2)) {
c->fail_delay = 1;
c->fail_timeout = jiffies +
d->fail_delay = 1;
d->fail_timeout = jiffies +
msecs_to_jiffies(delay);
dbg_rcvry("failing after %ums", delay);
} else {
c->fail_delay = 2;
c->fail_cnt_max = delay;
d->fail_delay = 2;
d->fail_cnt_max = delay;
dbg_rcvry("failing after %u calls", delay);
}
}
c->fail_cnt += 1;
d->fail_cnt += 1;
}
/* Determine if failure delay has expired */
if (c->fail_delay == 1) {
if (time_before(jiffies, c->fail_timeout))
if (d->fail_delay == 1) {
if (time_before(jiffies, d->fail_timeout))
return 0;
} else if (c->fail_delay == 2)
if (c->fail_cnt++ < c->fail_cnt_max)
} else if (d->fail_delay == 2)
if (d->fail_cnt++ < d->fail_cnt_max)
return 0;
if (lnum == UBIFS_SB_LNUM) {
if (write) {
Expand Down Expand Up @@ -2239,7 +2241,7 @@ static int do_fail(struct ubi_volume_desc *desc, int lnum, int write)
dbg_rcvry("failing in bud LEB %d commit not running", lnum);
}
ubifs_err("*** SETTING FAILURE MODE ON (LEB %d) ***", lnum);
c->failure_mode = 1;
d->failure_mode = 1;
dump_stack();
return 1;
}
Expand Down Expand Up @@ -2344,4 +2346,41 @@ int dbg_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype)
return 0;
}

/**
* ubifs_debugging_init - initialize UBIFS debugging.
* @c: UBIFS file-system description object
*
* This function initializes debugging-related data for the file system.
* Returns zero in case of success and a negative error code in case of
* failure.
*/
int ubifs_debugging_init(struct ubifs_info *c)
{
c->dbg = kzalloc(sizeof(struct ubifs_debug_info), GFP_KERNEL);
if (!c->dbg)
return -ENOMEM;

c->dbg->buf = vmalloc(c->leb_size);
if (!c->dbg->buf)
goto out;

failure_mode_init(c);
return 0;

out:
kfree(c->dbg);
return -ENOMEM;
}

/**
* ubifs_debugging_exit - free debugging data.
* @c: UBIFS file-system description object
*/
void ubifs_debugging_exit(struct ubifs_info *c)
{
failure_mode_exit(c);
vfree(c->dbg->buf);
kfree(c->dbg);
}

#endif /* CONFIG_UBIFS_FS_DEBUG */
51 changes: 43 additions & 8 deletions fs/ubifs/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,43 @@

#ifdef CONFIG_UBIFS_FS_DEBUG

#define UBIFS_DBG(op) op
/**
* ubifs_debug_info - per-FS debugging information.
* @buf: a buffer of LEB size, used for various purposes
* @old_zroot: old index root - used by 'dbg_check_old_index()'
* @old_zroot_level: old index root level - used by 'dbg_check_old_index()'
* @old_zroot_sqnum: old index root sqnum - used by 'dbg_check_old_index()'
* @failure_mode: failure mode for recovery testing
* @fail_delay: 0=>don't delay, 1=>delay a time, 2=>delay a number of calls
* @fail_timeout: time in jiffies when delay of failure mode expires
* @fail_cnt: current number of calls to failure mode I/O functions
* @fail_cnt_max: number of calls by which to delay failure mode
* @chk_lpt_sz: used by LPT tree size checker
* @chk_lpt_sz2: used by LPT tree size checker
* @chk_lpt_wastage: used by LPT tree size checker
* @chk_lpt_lebs: used by LPT tree size checker
* @new_nhead_offs: used by LPT tree size checker
* @new_ihead_lnum: used by debugging to check ihead_lnum
* @new_ihead_offs: used by debugging to check ihead_offs
*/
struct ubifs_debug_info {
void *buf;
struct ubifs_zbranch old_zroot;
int old_zroot_level;
unsigned long long old_zroot_sqnum;
int failure_mode;
int fail_delay;
unsigned long fail_timeout;
unsigned int fail_cnt;
unsigned int fail_cnt_max;
long long chk_lpt_sz;
long long chk_lpt_sz2;
long long chk_lpt_wastage;
int chk_lpt_lebs;
int new_nhead_offs;
int new_ihead_lnum;
int new_ihead_offs;
};

#define ubifs_assert(expr) do { \
if (unlikely(!(expr))) { \
Expand Down Expand Up @@ -211,6 +247,9 @@ extern unsigned int ubifs_msg_flags;
extern unsigned int ubifs_chk_flags;
extern unsigned int ubifs_tst_flags;

int ubifs_debugging_init(struct ubifs_info *c);
void ubifs_debugging_exit(struct ubifs_info *c);

/* Dump functions */

const char *dbg_ntype(int type);
Expand Down Expand Up @@ -274,9 +313,6 @@ int dbg_force_in_the_gaps(void);

#define dbg_failure_mode (ubifs_tst_flags & UBIFS_TST_RCVRY)

void dbg_failure_mode_registration(struct ubifs_info *c);
void dbg_failure_mode_deregistration(struct ubifs_info *c);

#ifndef UBIFS_DBG_PRESERVE_UBI

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

#else /* !CONFIG_UBIFS_FS_DEBUG */

#define UBIFS_DBG(op)

/* Use "if (0)" to make compiler check arguments even if debugging is off */
#define ubifs_assert(expr) do { \
if (0 && (expr)) \
Expand Down Expand Up @@ -360,6 +394,9 @@ static inline int dbg_change(struct ubi_volume_desc *desc, int lnum,
#define DBGKEY(key) ((char *)(key))
#define DBGKEY1(key) ((char *)(key))

#define ubifs_debugging_init(c) 0
#define ubifs_debugging_exit(c) ({})

#define dbg_ntype(type) ""
#define dbg_cstate(cmt_state) ""
#define dbg_get_key_dump(c, key) ({})
Expand Down Expand Up @@ -396,8 +433,6 @@ static inline int dbg_change(struct ubi_volume_desc *desc, int lnum,
#define dbg_force_in_the_gaps_enabled 0
#define dbg_force_in_the_gaps() 0
#define dbg_failure_mode 0
#define dbg_failure_mode_registration(c) ({})
#define dbg_failure_mode_deregistration(c) ({})

#endif /* !CONFIG_UBIFS_FS_DEBUG */

Expand Down
2 changes: 1 addition & 1 deletion fs/ubifs/lprops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ static int scan_check_cb(struct ubifs_info *c,
}
}

sleb = ubifs_scan(c, lnum, 0, c->dbg_buf);
sleb = ubifs_scan(c, lnum, 0, c->dbg->buf);
if (IS_ERR(sleb)) {
/*
* After an unclean unmount, empty and freeable LEBs
Expand Down
Loading

0 comments on commit 17c2f9f

Please sign in to comment.