Skip to content

Commit

Permalink
UBIFS: introduce LPT dump function
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
  • Loading branch information
Artem Bityutskiy authored and Artem Bityutskiy committed Dec 3, 2008
1 parent 787845b commit 2ba5f7a
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 48 deletions.
28 changes: 18 additions & 10 deletions fs/ubifs/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ void dbg_dump_lprops(struct ubifs_info *c)
struct ubifs_lprops lp;
struct ubifs_lp_stats lst;

printk(KERN_DEBUG "(pid %d) Dumping LEB properties\n", current->pid);
printk(KERN_DEBUG "(pid %d) start dumping LEB properties\n",
current->pid);
ubifs_get_lp_stats(c, &lst);
dbg_dump_lstats(&lst);

Expand All @@ -657,13 +658,16 @@ void dbg_dump_lprops(struct ubifs_info *c)

dbg_dump_lprop(c, &lp);
}
printk(KERN_DEBUG "(pid %d) finish dumping LEB properties\n",
current->pid);
}

void dbg_dump_lpt_info(struct ubifs_info *c)
{
int i;

spin_lock(&dbg_lock);
printk(KERN_DEBUG "(pid %d) dumping LPT information\n", current->pid);
printk(KERN_DEBUG "\tlpt_sz: %lld\n", c->lpt_sz);
printk(KERN_DEBUG "\tpnode_sz: %d\n", c->pnode_sz);
printk(KERN_DEBUG "\tnnode_sz: %d\n", c->nnode_sz);
Expand Down Expand Up @@ -704,8 +708,8 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum)
if (dbg_failure_mode)
return;

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

printk(KERN_DEBUG "(pid %d) start dumping LEB %d\n",
current->pid, lnum);
sleb = ubifs_scan(c, lnum, 0, c->dbg->buf);
if (IS_ERR(sleb)) {
ubifs_err("scan error %d", (int)PTR_ERR(sleb));
Expand All @@ -722,6 +726,8 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum)
dbg_dump_node(c, snod->node);
}

printk(KERN_DEBUG "(pid %d) finish dumping LEB %d\n",
current->pid, lnum);
ubifs_scan_destroy(sleb);
return;
}
Expand Down Expand Up @@ -769,7 +775,7 @@ void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat)
{
int i;

printk(KERN_DEBUG "(pid %d) Dumping heap cat %d (%d elements)\n",
printk(KERN_DEBUG "(pid %d) start dumping heap cat %d (%d elements)\n",
current->pid, cat, heap->cnt);
for (i = 0; i < heap->cnt; i++) {
struct ubifs_lprops *lprops = heap->arr[i];
Expand All @@ -778,14 +784,15 @@ void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat)
"flags %d\n", i, lprops->lnum, lprops->hpos,
lprops->free, lprops->dirty, lprops->flags);
}
printk(KERN_DEBUG "(pid %d) finish dumping heap\n", current->pid);
}

void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
struct ubifs_nnode *parent, int iip)
{
int i;

printk(KERN_DEBUG "(pid %d) Dumping pnode:\n", current->pid);
printk(KERN_DEBUG "(pid %d) dumping pnode:\n", current->pid);
printk(KERN_DEBUG "\taddress %zx parent %zx cnext %zx\n",
(size_t)pnode, (size_t)parent, (size_t)pnode->cnext);
printk(KERN_DEBUG "\tflags %lu iip %d level %d num %d\n",
Expand All @@ -804,7 +811,7 @@ void dbg_dump_tnc(struct ubifs_info *c)
int level;

printk(KERN_DEBUG "\n");
printk(KERN_DEBUG "(pid %d) Dumping the TNC tree\n", current->pid);
printk(KERN_DEBUG "(pid %d) start dumping TNC tree\n", current->pid);
znode = ubifs_tnc_levelorder_next(c->zroot.znode, NULL);
level = znode->level;
printk(KERN_DEBUG "== Level %d ==\n", level);
Expand All @@ -816,8 +823,7 @@ void dbg_dump_tnc(struct ubifs_info *c)
dbg_dump_znode(c, znode);
znode = ubifs_tnc_levelorder_next(c->zroot.znode, znode);
}

printk(KERN_DEBUG "\n");
printk(KERN_DEBUG "(pid %d) finish dumping TNC tree\n", current->pid);
}

static int dump_znode(struct ubifs_info *c, struct ubifs_znode *znode,
Expand Down Expand Up @@ -992,7 +998,8 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
ubifs_err("1st entry at %d:%d has key %s", zbr1->lnum,
zbr1->offs, DBGKEY(&key));
ubifs_err("but it should have key %s according to tnc",
DBGKEY(&zbr1->key)); dbg_dump_node(c, dent1);
DBGKEY(&zbr1->key));
dbg_dump_node(c, dent1);
goto out_free;
}

Expand All @@ -1001,7 +1008,8 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
ubifs_err("2nd entry at %d:%d has key %s", zbr1->lnum,
zbr1->offs, DBGKEY(&key));
ubifs_err("but it should have key %s according to tnc",
DBGKEY(&zbr2->key)); dbg_dump_node(c, dent2);
DBGKEY(&zbr2->key));
dbg_dump_node(c, dent2);
goto out_free;
}

Expand Down
45 changes: 25 additions & 20 deletions fs/ubifs/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ const char *dbg_get_key_dump(const struct ubifs_info *c,
const union ubifs_key *key);
void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode);
void dbg_dump_node(const struct ubifs_info *c, const void *node);
void dbg_dump_lpt_node(const struct ubifs_info *c, void *node, int lnum,
int offs);
void dbg_dump_budget_req(const struct ubifs_budget_req *req);
void dbg_dump_lstats(const struct ubifs_lp_stats *lst);
void dbg_dump_budg(struct ubifs_info *c);
Expand All @@ -284,6 +286,7 @@ void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
struct ubifs_nnode *parent, int iip);
void dbg_dump_tnc(struct ubifs_info *c);
void dbg_dump_index(struct ubifs_info *c);
void dbg_dump_lpt_lebs(const struct ubifs_info *c);

/* Checking helper functions */
typedef int (*dbg_leaf_callback)(struct ubifs_info *c,
Expand Down Expand Up @@ -411,26 +414,28 @@ void dbg_debugfs_exit_fs(struct ubifs_info *c);
#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) ({})
#define dbg_dump_inode(c, inode) ({})
#define dbg_dump_node(c, node) ({})
#define dbg_dump_budget_req(req) ({})
#define dbg_dump_lstats(lst) ({})
#define dbg_dump_budg(c) ({})
#define dbg_dump_lprop(c, lp) ({})
#define dbg_dump_lprops(c) ({})
#define dbg_dump_lpt_info(c) ({})
#define dbg_dump_leb(c, lnum) ({})
#define dbg_dump_znode(c, znode) ({})
#define dbg_dump_heap(c, heap, cat) ({})
#define dbg_dump_pnode(c, pnode, parent, iip) ({})
#define dbg_dump_tnc(c) ({})
#define dbg_dump_index(c) ({})
#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) ({})
#define dbg_dump_inode(c, inode) ({})
#define dbg_dump_node(c, node) ({})
#define dbg_dump_lpt_node(c, node, lnum, offs) ({})
#define dbg_dump_budget_req(req) ({})
#define dbg_dump_lstats(lst) ({})
#define dbg_dump_budg(c) ({})
#define dbg_dump_lprop(c, lp) ({})
#define dbg_dump_lprops(c) ({})
#define dbg_dump_lpt_info(c) ({})
#define dbg_dump_leb(c, lnum) ({})
#define dbg_dump_znode(c, znode) ({})
#define dbg_dump_heap(c, heap, cat) ({})
#define dbg_dump_pnode(c, pnode, parent, iip) ({})
#define dbg_dump_tnc(c) ({})
#define dbg_dump_index(c) ({})
#define dbg_dump_lpt_lebs(c) ({})

#define dbg_walk_index(c, leaf_cb, znode_cb, priv) 0
#define dbg_old_index_check_init(c, zroot) 0
Expand Down
27 changes: 14 additions & 13 deletions fs/ubifs/lpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ static int calc_nnode_num(int row, int col)
* This function calculates and returns the nnode number based on the parent's
* nnode number and the index in parent.
*/
static int calc_nnode_num_from_parent(struct ubifs_info *c,
static int calc_nnode_num_from_parent(const struct ubifs_info *c,
struct ubifs_nnode *parent, int iip)
{
int num, shft;
Expand All @@ -582,7 +582,7 @@ static int calc_nnode_num_from_parent(struct ubifs_info *c,
* This function calculates and returns the pnode number based on the parent's
* nnode number and the index in parent.
*/
static int calc_pnode_num_from_parent(struct ubifs_info *c,
static int calc_pnode_num_from_parent(const struct ubifs_info *c,
struct ubifs_nnode *parent, int iip)
{
int i, n = c->lpt_hght - 1, pnum = parent->num, num = 0;
Expand Down Expand Up @@ -965,7 +965,7 @@ static int check_lpt_type(uint8_t **addr, int *pos, int type)
*
* This function returns %0 on success and a negative error code on failure.
*/
static int unpack_pnode(struct ubifs_info *c, void *buf,
static int unpack_pnode(const struct ubifs_info *c, void *buf,
struct ubifs_pnode *pnode)
{
uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
Expand Down Expand Up @@ -995,15 +995,15 @@ static int unpack_pnode(struct ubifs_info *c, void *buf,
}

/**
* unpack_nnode - unpack a nnode.
* ubifs_unpack_nnode - unpack a nnode.
* @c: UBIFS file-system description object
* @buf: buffer containing packed nnode to unpack
* @nnode: nnode structure to fill
*
* This function returns %0 on success and a negative error code on failure.
*/
static int unpack_nnode(struct ubifs_info *c, void *buf,
struct ubifs_nnode *nnode)
int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
struct ubifs_nnode *nnode)
{
uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
int i, pos = 0, err;
Expand Down Expand Up @@ -1035,7 +1035,7 @@ static int unpack_nnode(struct ubifs_info *c, void *buf,
*
* This function returns %0 on success and a negative error code on failure.
*/
static int unpack_ltab(struct ubifs_info *c, void *buf)
static int unpack_ltab(const struct ubifs_info *c, void *buf)
{
uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
int i, pos = 0, err;
Expand Down Expand Up @@ -1067,7 +1067,7 @@ static int unpack_ltab(struct ubifs_info *c, void *buf)
*
* This function returns %0 on success and a negative error code on failure.
*/
static int unpack_lsave(struct ubifs_info *c, void *buf)
static int unpack_lsave(const struct ubifs_info *c, void *buf)
{
uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
int i, pos = 0, err;
Expand Down Expand Up @@ -1095,7 +1095,7 @@ static int unpack_lsave(struct ubifs_info *c, void *buf)
*
* This function returns %0 on success and a negative error code on failure.
*/
static int validate_nnode(struct ubifs_info *c, struct ubifs_nnode *nnode,
static int validate_nnode(const struct ubifs_info *c, struct ubifs_nnode *nnode,
struct ubifs_nnode *parent, int iip)
{
int i, lvl, max_offs;
Expand Down Expand Up @@ -1139,7 +1139,7 @@ static int validate_nnode(struct ubifs_info *c, struct ubifs_nnode *nnode,
*
* This function returns %0 on success and a negative error code on failure.
*/
static int validate_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
static int validate_pnode(const struct ubifs_info *c, struct ubifs_pnode *pnode,
struct ubifs_nnode *parent, int iip)
{
int i;
Expand Down Expand Up @@ -1173,7 +1173,8 @@ static int validate_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
* This function calculates the LEB numbers for the LEB properties it contains
* based on the pnode number.
*/
static void set_pnode_lnum(struct ubifs_info *c, struct ubifs_pnode *pnode)
static void set_pnode_lnum(const struct ubifs_info *c,
struct ubifs_pnode *pnode)
{
int i, lnum;

Expand Down Expand Up @@ -1226,7 +1227,7 @@ int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip)
err = ubi_read(c->ubi, lnum, buf, offs, c->nnode_sz);
if (err)
goto out;
err = unpack_nnode(c, buf, nnode);
err = ubifs_unpack_nnode(c, buf, nnode);
if (err)
goto out;
}
Expand Down Expand Up @@ -1815,7 +1816,7 @@ static struct ubifs_nnode *scan_get_nnode(struct ubifs_info *c,
c->nnode_sz);
if (err)
return ERR_PTR(err);
err = unpack_nnode(c, buf, nnode);
err = ubifs_unpack_nnode(c, buf, nnode);
if (err)
return ERR_PTR(err);
}
Expand Down
Loading

0 comments on commit 2ba5f7a

Please sign in to comment.