aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-10-31 11:32:30 -0400
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-12-03 06:14:34 -0500
commit2ba5f7ae8165b3f575dd3a7d8bb18f421fab8273 (patch)
treec2916fd6398b0a380eed9ac3cd9e59c92ae8cbd5 /fs
parent787845bdeadd368eedeace92d5bf53f5aa1450ba (diff)
UBIFS: introduce LPT dump function
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/ubifs/debug.c28
-rw-r--r--fs/ubifs/debug.h45
-rw-r--r--fs/ubifs/lpt.c27
-rw-r--r--fs/ubifs/lpt_commit.c131
-rw-r--r--fs/ubifs/ubifs.h3
5 files changed, 186 insertions, 48 deletions
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index 56842772c804..934db1855f09 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -646,7 +646,8 @@ void dbg_dump_lprops(struct ubifs_info *c)
646 struct ubifs_lprops lp; 646 struct ubifs_lprops lp;
647 struct ubifs_lp_stats lst; 647 struct ubifs_lp_stats lst;
648 648
649 printk(KERN_DEBUG "(pid %d) Dumping LEB properties\n", current->pid); 649 printk(KERN_DEBUG "(pid %d) start dumping LEB properties\n",
650 current->pid);
650 ubifs_get_lp_stats(c, &lst); 651 ubifs_get_lp_stats(c, &lst);
651 dbg_dump_lstats(&lst); 652 dbg_dump_lstats(&lst);
652 653
@@ -657,6 +658,8 @@ void dbg_dump_lprops(struct ubifs_info *c)
657 658
658 dbg_dump_lprop(c, &lp); 659 dbg_dump_lprop(c, &lp);
659 } 660 }
661 printk(KERN_DEBUG "(pid %d) finish dumping LEB properties\n",
662 current->pid);
660} 663}
661 664
662void dbg_dump_lpt_info(struct ubifs_info *c) 665void dbg_dump_lpt_info(struct ubifs_info *c)
@@ -664,6 +667,7 @@ void dbg_dump_lpt_info(struct ubifs_info *c)
664 int i; 667 int i;
665 668
666 spin_lock(&dbg_lock); 669 spin_lock(&dbg_lock);
670 printk(KERN_DEBUG "(pid %d) dumping LPT information\n", current->pid);
667 printk(KERN_DEBUG "\tlpt_sz: %lld\n", c->lpt_sz); 671 printk(KERN_DEBUG "\tlpt_sz: %lld\n", c->lpt_sz);
668 printk(KERN_DEBUG "\tpnode_sz: %d\n", c->pnode_sz); 672 printk(KERN_DEBUG "\tpnode_sz: %d\n", c->pnode_sz);
669 printk(KERN_DEBUG "\tnnode_sz: %d\n", c->nnode_sz); 673 printk(KERN_DEBUG "\tnnode_sz: %d\n", c->nnode_sz);
@@ -704,8 +708,8 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum)
704 if (dbg_failure_mode) 708 if (dbg_failure_mode)
705 return; 709 return;
706 710
707 printk(KERN_DEBUG "(pid %d) Dumping LEB %d\n", current->pid, lnum); 711 printk(KERN_DEBUG "(pid %d) start dumping LEB %d\n",
708 712 current->pid, lnum);
709 sleb = ubifs_scan(c, lnum, 0, c->dbg->buf); 713 sleb = ubifs_scan(c, lnum, 0, c->dbg->buf);
710 if (IS_ERR(sleb)) { 714 if (IS_ERR(sleb)) {
711 ubifs_err("scan error %d", (int)PTR_ERR(sleb)); 715 ubifs_err("scan error %d", (int)PTR_ERR(sleb));
@@ -722,6 +726,8 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum)
722 dbg_dump_node(c, snod->node); 726 dbg_dump_node(c, snod->node);
723 } 727 }
724 728
729 printk(KERN_DEBUG "(pid %d) finish dumping LEB %d\n",
730 current->pid, lnum);
725 ubifs_scan_destroy(sleb); 731 ubifs_scan_destroy(sleb);
726 return; 732 return;
727} 733}
@@ -769,7 +775,7 @@ void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat)
769{ 775{
770 int i; 776 int i;
771 777
772 printk(KERN_DEBUG "(pid %d) Dumping heap cat %d (%d elements)\n", 778 printk(KERN_DEBUG "(pid %d) start dumping heap cat %d (%d elements)\n",
773 current->pid, cat, heap->cnt); 779 current->pid, cat, heap->cnt);
774 for (i = 0; i < heap->cnt; i++) { 780 for (i = 0; i < heap->cnt; i++) {
775 struct ubifs_lprops *lprops = heap->arr[i]; 781 struct ubifs_lprops *lprops = heap->arr[i];
@@ -778,6 +784,7 @@ void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat)
778 "flags %d\n", i, lprops->lnum, lprops->hpos, 784 "flags %d\n", i, lprops->lnum, lprops->hpos,
779 lprops->free, lprops->dirty, lprops->flags); 785 lprops->free, lprops->dirty, lprops->flags);
780 } 786 }
787 printk(KERN_DEBUG "(pid %d) finish dumping heap\n", current->pid);
781} 788}
782 789
783void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, 790void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
@@ -785,7 +792,7 @@ void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
785{ 792{
786 int i; 793 int i;
787 794
788 printk(KERN_DEBUG "(pid %d) Dumping pnode:\n", current->pid); 795 printk(KERN_DEBUG "(pid %d) dumping pnode:\n", current->pid);
789 printk(KERN_DEBUG "\taddress %zx parent %zx cnext %zx\n", 796 printk(KERN_DEBUG "\taddress %zx parent %zx cnext %zx\n",
790 (size_t)pnode, (size_t)parent, (size_t)pnode->cnext); 797 (size_t)pnode, (size_t)parent, (size_t)pnode->cnext);
791 printk(KERN_DEBUG "\tflags %lu iip %d level %d num %d\n", 798 printk(KERN_DEBUG "\tflags %lu iip %d level %d num %d\n",
@@ -804,7 +811,7 @@ void dbg_dump_tnc(struct ubifs_info *c)
804 int level; 811 int level;
805 812
806 printk(KERN_DEBUG "\n"); 813 printk(KERN_DEBUG "\n");
807 printk(KERN_DEBUG "(pid %d) Dumping the TNC tree\n", current->pid); 814 printk(KERN_DEBUG "(pid %d) start dumping TNC tree\n", current->pid);
808 znode = ubifs_tnc_levelorder_next(c->zroot.znode, NULL); 815 znode = ubifs_tnc_levelorder_next(c->zroot.znode, NULL);
809 level = znode->level; 816 level = znode->level;
810 printk(KERN_DEBUG "== Level %d ==\n", level); 817 printk(KERN_DEBUG "== Level %d ==\n", level);
@@ -816,8 +823,7 @@ void dbg_dump_tnc(struct ubifs_info *c)
816 dbg_dump_znode(c, znode); 823 dbg_dump_znode(c, znode);
817 znode = ubifs_tnc_levelorder_next(c->zroot.znode, znode); 824 znode = ubifs_tnc_levelorder_next(c->zroot.znode, znode);
818 } 825 }
819 826 printk(KERN_DEBUG "(pid %d) finish dumping TNC tree\n", current->pid);
820 printk(KERN_DEBUG "\n");
821} 827}
822 828
823static int dump_znode(struct ubifs_info *c, struct ubifs_znode *znode, 829static int dump_znode(struct ubifs_info *c, struct ubifs_znode *znode,
@@ -992,7 +998,8 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
992 ubifs_err("1st entry at %d:%d has key %s", zbr1->lnum, 998 ubifs_err("1st entry at %d:%d has key %s", zbr1->lnum,
993 zbr1->offs, DBGKEY(&key)); 999 zbr1->offs, DBGKEY(&key));
994 ubifs_err("but it should have key %s according to tnc", 1000 ubifs_err("but it should have key %s according to tnc",
995 DBGKEY(&zbr1->key)); dbg_dump_node(c, dent1); 1001 DBGKEY(&zbr1->key));
1002 dbg_dump_node(c, dent1);
996 goto out_free; 1003 goto out_free;
997 } 1004 }
998 1005
@@ -1001,7 +1008,8 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
1001 ubifs_err("2nd entry at %d:%d has key %s", zbr1->lnum, 1008 ubifs_err("2nd entry at %d:%d has key %s", zbr1->lnum,
1002 zbr1->offs, DBGKEY(&key)); 1009 zbr1->offs, DBGKEY(&key));
1003 ubifs_err("but it should have key %s according to tnc", 1010 ubifs_err("but it should have key %s according to tnc",
1004 DBGKEY(&zbr2->key)); dbg_dump_node(c, dent2); 1011 DBGKEY(&zbr2->key));
1012 dbg_dump_node(c, dent2);
1005 goto out_free; 1013 goto out_free;
1006 } 1014 }
1007 1015
diff --git a/fs/ubifs/debug.h b/fs/ubifs/debug.h
index a6b70f8aac9c..9820d6999f7e 100644
--- a/fs/ubifs/debug.h
+++ b/fs/ubifs/debug.h
@@ -270,6 +270,8 @@ const char *dbg_get_key_dump(const struct ubifs_info *c,
270 const union ubifs_key *key); 270 const union ubifs_key *key);
271void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode); 271void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode);
272void dbg_dump_node(const struct ubifs_info *c, const void *node); 272void dbg_dump_node(const struct ubifs_info *c, const void *node);
273void dbg_dump_lpt_node(const struct ubifs_info *c, void *node, int lnum,
274 int offs);
273void dbg_dump_budget_req(const struct ubifs_budget_req *req); 275void dbg_dump_budget_req(const struct ubifs_budget_req *req);
274void dbg_dump_lstats(const struct ubifs_lp_stats *lst); 276void dbg_dump_lstats(const struct ubifs_lp_stats *lst);
275void dbg_dump_budg(struct ubifs_info *c); 277void dbg_dump_budg(struct ubifs_info *c);
@@ -284,6 +286,7 @@ void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
284 struct ubifs_nnode *parent, int iip); 286 struct ubifs_nnode *parent, int iip);
285void dbg_dump_tnc(struct ubifs_info *c); 287void dbg_dump_tnc(struct ubifs_info *c);
286void dbg_dump_index(struct ubifs_info *c); 288void dbg_dump_index(struct ubifs_info *c);
289void dbg_dump_lpt_lebs(const struct ubifs_info *c);
287 290
288/* Checking helper functions */ 291/* Checking helper functions */
289typedef int (*dbg_leaf_callback)(struct ubifs_info *c, 292typedef int (*dbg_leaf_callback)(struct ubifs_info *c,
@@ -411,26 +414,28 @@ void dbg_debugfs_exit_fs(struct ubifs_info *c);
411#define DBGKEY(key) ((char *)(key)) 414#define DBGKEY(key) ((char *)(key))
412#define DBGKEY1(key) ((char *)(key)) 415#define DBGKEY1(key) ((char *)(key))
413 416
414#define ubifs_debugging_init(c) 0 417#define ubifs_debugging_init(c) 0
415#define ubifs_debugging_exit(c) ({}) 418#define ubifs_debugging_exit(c) ({})
416 419
417#define dbg_ntype(type) "" 420#define dbg_ntype(type) ""
418#define dbg_cstate(cmt_state) "" 421#define dbg_cstate(cmt_state) ""
419#define dbg_get_key_dump(c, key) ({}) 422#define dbg_get_key_dump(c, key) ({})
420#define dbg_dump_inode(c, inode) ({}) 423#define dbg_dump_inode(c, inode) ({})
421#define dbg_dump_node(c, node) ({}) 424#define dbg_dump_node(c, node) ({})
422#define dbg_dump_budget_req(req) ({}) 425#define dbg_dump_lpt_node(c, node, lnum, offs) ({})
423#define dbg_dump_lstats(lst) ({}) 426#define dbg_dump_budget_req(req) ({})
424#define dbg_dump_budg(c) ({}) 427#define dbg_dump_lstats(lst) ({})
425#define dbg_dump_lprop(c, lp) ({}) 428#define dbg_dump_budg(c) ({})
426#define dbg_dump_lprops(c) ({}) 429#define dbg_dump_lprop(c, lp) ({})
427#define dbg_dump_lpt_info(c) ({}) 430#define dbg_dump_lprops(c) ({})
428#define dbg_dump_leb(c, lnum) ({}) 431#define dbg_dump_lpt_info(c) ({})
429#define dbg_dump_znode(c, znode) ({}) 432#define dbg_dump_leb(c, lnum) ({})
430#define dbg_dump_heap(c, heap, cat) ({}) 433#define dbg_dump_znode(c, znode) ({})
431#define dbg_dump_pnode(c, pnode, parent, iip) ({}) 434#define dbg_dump_heap(c, heap, cat) ({})
432#define dbg_dump_tnc(c) ({}) 435#define dbg_dump_pnode(c, pnode, parent, iip) ({})
433#define dbg_dump_index(c) ({}) 436#define dbg_dump_tnc(c) ({})
437#define dbg_dump_index(c) ({})
438#define dbg_dump_lpt_lebs(c) ({})
434 439
435#define dbg_walk_index(c, leaf_cb, znode_cb, priv) 0 440#define dbg_walk_index(c, leaf_cb, znode_cb, priv) 0
436#define dbg_old_index_check_init(c, zroot) 0 441#define dbg_old_index_check_init(c, zroot) 0
diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c
index 93c181c742f2..6d914160ec55 100644
--- a/fs/ubifs/lpt.c
+++ b/fs/ubifs/lpt.c
@@ -557,7 +557,7 @@ static int calc_nnode_num(int row, int col)
557 * This function calculates and returns the nnode number based on the parent's 557 * This function calculates and returns the nnode number based on the parent's
558 * nnode number and the index in parent. 558 * nnode number and the index in parent.
559 */ 559 */
560static int calc_nnode_num_from_parent(struct ubifs_info *c, 560static int calc_nnode_num_from_parent(const struct ubifs_info *c,
561 struct ubifs_nnode *parent, int iip) 561 struct ubifs_nnode *parent, int iip)
562{ 562{
563 int num, shft; 563 int num, shft;
@@ -582,7 +582,7 @@ static int calc_nnode_num_from_parent(struct ubifs_info *c,
582 * This function calculates and returns the pnode number based on the parent's 582 * This function calculates and returns the pnode number based on the parent's
583 * nnode number and the index in parent. 583 * nnode number and the index in parent.
584 */ 584 */
585static int calc_pnode_num_from_parent(struct ubifs_info *c, 585static int calc_pnode_num_from_parent(const struct ubifs_info *c,
586 struct ubifs_nnode *parent, int iip) 586 struct ubifs_nnode *parent, int iip)
587{ 587{
588 int i, n = c->lpt_hght - 1, pnum = parent->num, num = 0; 588 int i, n = c->lpt_hght - 1, pnum = parent->num, num = 0;
@@ -965,7 +965,7 @@ static int check_lpt_type(uint8_t **addr, int *pos, int type)
965 * 965 *
966 * This function returns %0 on success and a negative error code on failure. 966 * This function returns %0 on success and a negative error code on failure.
967 */ 967 */
968static int unpack_pnode(struct ubifs_info *c, void *buf, 968static int unpack_pnode(const struct ubifs_info *c, void *buf,
969 struct ubifs_pnode *pnode) 969 struct ubifs_pnode *pnode)
970{ 970{
971 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 971 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
@@ -995,15 +995,15 @@ static int unpack_pnode(struct ubifs_info *c, void *buf,
995} 995}
996 996
997/** 997/**
998 * unpack_nnode - unpack a nnode. 998 * ubifs_unpack_nnode - unpack a nnode.
999 * @c: UBIFS file-system description object 999 * @c: UBIFS file-system description object
1000 * @buf: buffer containing packed nnode to unpack 1000 * @buf: buffer containing packed nnode to unpack
1001 * @nnode: nnode structure to fill 1001 * @nnode: nnode structure to fill
1002 * 1002 *
1003 * This function returns %0 on success and a negative error code on failure. 1003 * This function returns %0 on success and a negative error code on failure.
1004 */ 1004 */
1005static int unpack_nnode(struct ubifs_info *c, void *buf, 1005int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
1006 struct ubifs_nnode *nnode) 1006 struct ubifs_nnode *nnode)
1007{ 1007{
1008 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 1008 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
1009 int i, pos = 0, err; 1009 int i, pos = 0, err;
@@ -1035,7 +1035,7 @@ static int unpack_nnode(struct ubifs_info *c, void *buf,
1035 * 1035 *
1036 * This function returns %0 on success and a negative error code on failure. 1036 * This function returns %0 on success and a negative error code on failure.
1037 */ 1037 */
1038static int unpack_ltab(struct ubifs_info *c, void *buf) 1038static int unpack_ltab(const struct ubifs_info *c, void *buf)
1039{ 1039{
1040 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 1040 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
1041 int i, pos = 0, err; 1041 int i, pos = 0, err;
@@ -1067,7 +1067,7 @@ static int unpack_ltab(struct ubifs_info *c, void *buf)
1067 * 1067 *
1068 * This function returns %0 on success and a negative error code on failure. 1068 * This function returns %0 on success and a negative error code on failure.
1069 */ 1069 */
1070static int unpack_lsave(struct ubifs_info *c, void *buf) 1070static int unpack_lsave(const struct ubifs_info *c, void *buf)
1071{ 1071{
1072 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 1072 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
1073 int i, pos = 0, err; 1073 int i, pos = 0, err;
@@ -1095,7 +1095,7 @@ static int unpack_lsave(struct ubifs_info *c, void *buf)
1095 * 1095 *
1096 * This function returns %0 on success and a negative error code on failure. 1096 * This function returns %0 on success and a negative error code on failure.
1097 */ 1097 */
1098static int validate_nnode(struct ubifs_info *c, struct ubifs_nnode *nnode, 1098static int validate_nnode(const struct ubifs_info *c, struct ubifs_nnode *nnode,
1099 struct ubifs_nnode *parent, int iip) 1099 struct ubifs_nnode *parent, int iip)
1100{ 1100{
1101 int i, lvl, max_offs; 1101 int i, lvl, max_offs;
@@ -1139,7 +1139,7 @@ static int validate_nnode(struct ubifs_info *c, struct ubifs_nnode *nnode,
1139 * 1139 *
1140 * This function returns %0 on success and a negative error code on failure. 1140 * This function returns %0 on success and a negative error code on failure.
1141 */ 1141 */
1142static int validate_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, 1142static int validate_pnode(const struct ubifs_info *c, struct ubifs_pnode *pnode,
1143 struct ubifs_nnode *parent, int iip) 1143 struct ubifs_nnode *parent, int iip)
1144{ 1144{
1145 int i; 1145 int i;
@@ -1173,7 +1173,8 @@ static int validate_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
1173 * This function calculates the LEB numbers for the LEB properties it contains 1173 * This function calculates the LEB numbers for the LEB properties it contains
1174 * based on the pnode number. 1174 * based on the pnode number.
1175 */ 1175 */
1176static void set_pnode_lnum(struct ubifs_info *c, struct ubifs_pnode *pnode) 1176static void set_pnode_lnum(const struct ubifs_info *c,
1177 struct ubifs_pnode *pnode)
1177{ 1178{
1178 int i, lnum; 1179 int i, lnum;
1179 1180
@@ -1226,7 +1227,7 @@ int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip)
1226 err = ubi_read(c->ubi, lnum, buf, offs, c->nnode_sz); 1227 err = ubi_read(c->ubi, lnum, buf, offs, c->nnode_sz);
1227 if (err) 1228 if (err)
1228 goto out; 1229 goto out;
1229 err = unpack_nnode(c, buf, nnode); 1230 err = ubifs_unpack_nnode(c, buf, nnode);
1230 if (err) 1231 if (err)
1231 goto out; 1232 goto out;
1232 } 1233 }
@@ -1815,7 +1816,7 @@ static struct ubifs_nnode *scan_get_nnode(struct ubifs_info *c,
1815 c->nnode_sz); 1816 c->nnode_sz);
1816 if (err) 1817 if (err)
1817 return ERR_PTR(err); 1818 return ERR_PTR(err);
1818 err = unpack_nnode(c, buf, nnode); 1819 err = ubifs_unpack_nnode(c, buf, nnode);
1819 if (err) 1820 if (err)
1820 return ERR_PTR(err); 1821 return ERR_PTR(err);
1821 } 1822 }
diff --git a/fs/ubifs/lpt_commit.c b/fs/ubifs/lpt_commit.c
index c5c07f9cd22c..da60b5a0fab9 100644
--- a/fs/ubifs/lpt_commit.c
+++ b/fs/ubifs/lpt_commit.c
@@ -320,6 +320,7 @@ no_space:
320 dbg_err("LPT out of space at LEB %d:%d needing %d, done_ltab %d, " 320 dbg_err("LPT out of space at LEB %d:%d needing %d, done_ltab %d, "
321 "done_lsave %d", lnum, offs, len, done_ltab, done_lsave); 321 "done_lsave %d", lnum, offs, len, done_ltab, done_lsave);
322 dbg_dump_lpt_info(c); 322 dbg_dump_lpt_info(c);
323 dbg_dump_lpt_lebs(c);
323 dump_stack(); 324 dump_stack();
324 return err; 325 return err;
325} 326}
@@ -549,6 +550,7 @@ no_space:
549 dbg_err("LPT out of space mismatch at LEB %d:%d needing %d, done_ltab " 550 dbg_err("LPT out of space mismatch at LEB %d:%d needing %d, done_ltab "
550 "%d, done_lsave %d", lnum, offs, len, done_ltab, done_lsave); 551 "%d, done_lsave %d", lnum, offs, len, done_ltab, done_lsave);
551 dbg_dump_lpt_info(c); 552 dbg_dump_lpt_info(c);
553 dbg_dump_lpt_lebs(c);
552 dump_stack(); 554 dump_stack();
553 return err; 555 return err;
554} 556}
@@ -1027,7 +1029,7 @@ static int make_node_dirty(struct ubifs_info *c, int node_type, int node_num,
1027 * @c: UBIFS file-system description object 1029 * @c: UBIFS file-system description object
1028 * @node_type: LPT node type 1030 * @node_type: LPT node type
1029 */ 1031 */
1030static int get_lpt_node_len(struct ubifs_info *c, int node_type) 1032static int get_lpt_node_len(const struct ubifs_info *c, int node_type)
1031{ 1033{
1032 switch (node_type) { 1034 switch (node_type) {
1033 case UBIFS_LPT_NNODE: 1035 case UBIFS_LPT_NNODE:
@@ -1048,7 +1050,7 @@ static int get_lpt_node_len(struct ubifs_info *c, int node_type)
1048 * @buf: buffer 1050 * @buf: buffer
1049 * @len: length of buffer 1051 * @len: length of buffer
1050 */ 1052 */
1051static int get_pad_len(struct ubifs_info *c, uint8_t *buf, int len) 1053static int get_pad_len(const struct ubifs_info *c, uint8_t *buf, int len)
1052{ 1054{
1053 int offs, pad_len; 1055 int offs, pad_len;
1054 1056
@@ -1065,7 +1067,8 @@ static int get_pad_len(struct ubifs_info *c, uint8_t *buf, int len)
1065 * @buf: buffer 1067 * @buf: buffer
1066 * @node_num: node number is returned here 1068 * @node_num: node number is returned here
1067 */ 1069 */
1068static int get_lpt_node_type(struct ubifs_info *c, uint8_t *buf, int *node_num) 1070static int get_lpt_node_type(const struct ubifs_info *c, uint8_t *buf,
1071 int *node_num)
1069{ 1072{
1070 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 1073 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
1071 int pos = 0, node_type; 1074 int pos = 0, node_type;
@@ -1083,7 +1086,7 @@ static int get_lpt_node_type(struct ubifs_info *c, uint8_t *buf, int *node_num)
1083 * 1086 *
1084 * This function returns %1 if the buffer contains a node or %0 if it does not. 1087 * This function returns %1 if the buffer contains a node or %0 if it does not.
1085 */ 1088 */
1086static int is_a_node(struct ubifs_info *c, uint8_t *buf, int len) 1089static int is_a_node(const struct ubifs_info *c, uint8_t *buf, int len)
1087{ 1090{
1088 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 1091 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
1089 int pos = 0, node_type, node_len; 1092 int pos = 0, node_type, node_len;
@@ -1107,7 +1110,6 @@ static int is_a_node(struct ubifs_info *c, uint8_t *buf, int len)
1107 return 1; 1110 return 1;
1108} 1111}
1109 1112
1110
1111/** 1113/**
1112 * lpt_gc_lnum - garbage collect a LPT LEB. 1114 * lpt_gc_lnum - garbage collect a LPT LEB.
1113 * @c: UBIFS file-system description object 1115 * @c: UBIFS file-system description object
@@ -1724,6 +1726,7 @@ int dbg_chk_lpt_free_spc(struct ubifs_info *c)
1724 dbg_err("LPT space error: free %lld lpt_sz %lld", 1726 dbg_err("LPT space error: free %lld lpt_sz %lld",
1725 free, c->lpt_sz); 1727 free, c->lpt_sz);
1726 dbg_dump_lpt_info(c); 1728 dbg_dump_lpt_info(c);
1729 dbg_dump_lpt_lebs(c);
1727 dump_stack(); 1730 dump_stack();
1728 return -EINVAL; 1731 return -EINVAL;
1729 } 1732 }
@@ -1808,6 +1811,7 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len)
1808 } 1811 }
1809 if (err) { 1812 if (err) {
1810 dbg_dump_lpt_info(c); 1813 dbg_dump_lpt_info(c);
1814 dbg_dump_lpt_lebs(c);
1811 dump_stack(); 1815 dump_stack();
1812 } 1816 }
1813 d->chk_lpt_sz2 = d->chk_lpt_sz; 1817 d->chk_lpt_sz2 = d->chk_lpt_sz;
@@ -1825,4 +1829,121 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len)
1825 } 1829 }
1826} 1830}
1827 1831
1832/**
1833 * dbg_dump_lpt_leb - dump an LPT LEB.
1834 * @c: UBIFS file-system description object
1835 * @lnum: LEB number to dump
1836 *
1837 * This function dumps an LEB from LPT area. Nodes in this area are very
1838 * different to nodes in the main area (e.g., they do not have common headers,
1839 * they do not have 8-byte alignments, etc), so we have a separate function to
1840 * dump LPT area LEBs. Note, LPT has to be locked by the coller.
1841 */
1842static void dump_lpt_leb(const struct ubifs_info *c, int lnum)
1843{
1844 int err, len = c->leb_size, node_type, node_num, node_len, offs;
1845 void *buf = c->dbg->buf;
1846
1847 printk(KERN_DEBUG "(pid %d) start dumping LEB %d\n",
1848 current->pid, lnum);
1849 err = ubi_read(c->ubi, lnum, buf, 0, c->leb_size);
1850 if (err) {
1851 ubifs_err("cannot read LEB %d, error %d", lnum, err);
1852 return;
1853 }
1854 while (1) {
1855 offs = c->leb_size - len;
1856 if (!is_a_node(c, buf, len)) {
1857 int pad_len;
1858
1859 pad_len = get_pad_len(c, buf, len);
1860 if (pad_len) {
1861 printk(KERN_DEBUG "LEB %d:%d, pad %d bytes\n",
1862 lnum, offs, pad_len);
1863 buf += pad_len;
1864 len -= pad_len;
1865 continue;
1866 }
1867 if (len)
1868 printk(KERN_DEBUG "LEB %d:%d, free %d bytes\n",
1869 lnum, offs, len);
1870 break;
1871 }
1872
1873 node_type = get_lpt_node_type(c, buf, &node_num);
1874 switch (node_type) {
1875 case UBIFS_LPT_PNODE:
1876 {
1877 node_len = c->pnode_sz;
1878 if (c->big_lpt)
1879 printk(KERN_DEBUG "LEB %d:%d, pnode num %d\n",
1880 lnum, offs, node_num);
1881 else
1882 printk(KERN_DEBUG "LEB %d:%d, pnode\n",
1883 lnum, offs);
1884 break;
1885 }
1886 case UBIFS_LPT_NNODE:
1887 {
1888 int i;
1889 struct ubifs_nnode nnode;
1890
1891 node_len = c->nnode_sz;
1892 if (c->big_lpt)
1893 printk(KERN_DEBUG "LEB %d:%d, nnode num %d, ",
1894 lnum, offs, node_num);
1895 else
1896 printk(KERN_DEBUG "LEB %d:%d, nnode, ",
1897 lnum, offs);
1898 err = ubifs_unpack_nnode(c, buf, &nnode);
1899 for (i = 0; i < UBIFS_LPT_FANOUT; i++) {
1900 printk("%d:%d", nnode.nbranch[i].lnum,
1901 nnode.nbranch[i].offs);
1902 if (i != UBIFS_LPT_FANOUT - 1)
1903 printk(", ");
1904 }
1905 printk("\n");
1906 break;
1907 }
1908 case UBIFS_LPT_LTAB:
1909 node_len = c->ltab_sz;
1910 printk(KERN_DEBUG "LEB %d:%d, ltab\n",
1911 lnum, offs);
1912 break;
1913 case UBIFS_LPT_LSAVE:
1914 node_len = c->lsave_sz;
1915 printk(KERN_DEBUG "LEB %d:%d, lsave len\n", lnum, offs);
1916 break;
1917 default:
1918 ubifs_err("LPT node type %d not recognized", node_type);
1919 return;
1920 }
1921
1922 buf += node_len;
1923 len -= node_len;
1924 }
1925
1926 printk(KERN_DEBUG "(pid %d) finish dumping LEB %d\n",
1927 current->pid, lnum);
1928}
1929
1930/**
1931 * dbg_dump_lpt_lebs - dump LPT lebs.
1932 * @c: UBIFS file-system description object
1933 *
1934 * This function dumps all LPT LEBs. The caller has to make sure the LPT is
1935 * locked.
1936 */
1937void dbg_dump_lpt_lebs(const struct ubifs_info *c)
1938{
1939 int i;
1940
1941 printk(KERN_DEBUG "(pid %d) start dumping all LPT LEBs\n",
1942 current->pid);
1943 for (i = 0; i < c->lpt_lebs; i++)
1944 dump_lpt_leb(c, i + c->lpt_first);
1945 printk(KERN_DEBUG "(pid %d) finish dumping all LPT LEBs\n",
1946 current->pid);
1947}
1948
1828#endif /* CONFIG_UBIFS_FS_DEBUG */ 1949#endif /* CONFIG_UBIFS_FS_DEBUG */
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 4cf28e85de78..e658b06fd451 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -1622,6 +1622,9 @@ void ubifs_add_lpt_dirt(struct ubifs_info *c, int lnum, int dirty);
1622void ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode); 1622void ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode);
1623uint32_t ubifs_unpack_bits(uint8_t **addr, int *pos, int nrbits); 1623uint32_t ubifs_unpack_bits(uint8_t **addr, int *pos, int nrbits);
1624struct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght); 1624struct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght);
1625/* Needed only in debugging code in lpt_commit.c */
1626int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
1627 struct ubifs_nnode *nnode);
1625 1628
1626/* lpt_commit.c */ 1629/* lpt_commit.c */
1627int ubifs_lpt_start_commit(struct ubifs_info *c); 1630int ubifs_lpt_start_commit(struct ubifs_info *c);