aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ubifs/debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ubifs/debug.c')
-rw-r--r--fs/ubifs/debug.c90
1 files changed, 46 insertions, 44 deletions
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index b09ba2dd8b6..f922cbacdb9 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -38,9 +38,6 @@
38 38
39DEFINE_SPINLOCK(dbg_lock); 39DEFINE_SPINLOCK(dbg_lock);
40 40
41static char dbg_key_buf0[128];
42static char dbg_key_buf1[128];
43
44static const char *get_key_fmt(int fmt) 41static const char *get_key_fmt(int fmt)
45{ 42{
46 switch (fmt) { 43 switch (fmt) {
@@ -103,8 +100,8 @@ static const char *get_dent_type(int type)
103 } 100 }
104} 101}
105 102
106static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key, 103const char *dbg_snprintf_key(const struct ubifs_info *c,
107 char *buffer) 104 const union ubifs_key *key, char *buffer, int len)
108{ 105{
109 char *p = buffer; 106 char *p = buffer;
110 int type = key_type(c, key); 107 int type = key_type(c, key);
@@ -112,45 +109,34 @@ static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key,
112 if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) { 109 if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) {
113 switch (type) { 110 switch (type) {
114 case UBIFS_INO_KEY: 111 case UBIFS_INO_KEY:
115 sprintf(p, "(%lu, %s)", (unsigned long)key_inum(c, key), 112 len -= snprintf(p, len, "(%lu, %s)",
116 get_key_type(type)); 113 (unsigned long)key_inum(c, key),
114 get_key_type(type));
117 break; 115 break;
118 case UBIFS_DENT_KEY: 116 case UBIFS_DENT_KEY:
119 case UBIFS_XENT_KEY: 117 case UBIFS_XENT_KEY:
120 sprintf(p, "(%lu, %s, %#08x)", 118 len -= snprintf(p, len, "(%lu, %s, %#08x)",
121 (unsigned long)key_inum(c, key), 119 (unsigned long)key_inum(c, key),
122 get_key_type(type), key_hash(c, key)); 120 get_key_type(type), key_hash(c, key));
123 break; 121 break;
124 case UBIFS_DATA_KEY: 122 case UBIFS_DATA_KEY:
125 sprintf(p, "(%lu, %s, %u)", 123 len -= snprintf(p, len, "(%lu, %s, %u)",
126 (unsigned long)key_inum(c, key), 124 (unsigned long)key_inum(c, key),
127 get_key_type(type), key_block(c, key)); 125 get_key_type(type), key_block(c, key));
128 break; 126 break;
129 case UBIFS_TRUN_KEY: 127 case UBIFS_TRUN_KEY:
130 sprintf(p, "(%lu, %s)", 128 len -= snprintf(p, len, "(%lu, %s)",
131 (unsigned long)key_inum(c, key), 129 (unsigned long)key_inum(c, key),
132 get_key_type(type)); 130 get_key_type(type));
133 break; 131 break;
134 default: 132 default:
135 sprintf(p, "(bad key type: %#08x, %#08x)", 133 len -= snprintf(p, len, "(bad key type: %#08x, %#08x)",
136 key->u32[0], key->u32[1]); 134 key->u32[0], key->u32[1]);
137 } 135 }
138 } else 136 } else
139 sprintf(p, "bad key format %d", c->key_fmt); 137 len -= snprintf(p, len, "bad key format %d", c->key_fmt);
140} 138 ubifs_assert(len > 0);
141 139 return p;
142const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key)
143{
144 /* dbg_lock must be held */
145 sprintf_key(c, key, dbg_key_buf0);
146 return dbg_key_buf0;
147}
148
149const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key)
150{
151 /* dbg_lock must be held */
152 sprintf_key(c, key, dbg_key_buf1);
153 return dbg_key_buf1;
154} 140}
155 141
156const char *dbg_ntype(int type) 142const char *dbg_ntype(int type)
@@ -319,6 +305,7 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node)
319 int i, n; 305 int i, n;
320 union ubifs_key key; 306 union ubifs_key key;
321 const struct ubifs_ch *ch = node; 307 const struct ubifs_ch *ch = node;
308 char key_buf[DBG_KEY_BUF_LEN];
322 309
323 if (dbg_is_tst_rcvry(c)) 310 if (dbg_is_tst_rcvry(c))
324 return; 311 return;
@@ -474,7 +461,8 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node)
474 const struct ubifs_ino_node *ino = node; 461 const struct ubifs_ino_node *ino = node;
475 462
476 key_read(c, &ino->key, &key); 463 key_read(c, &ino->key, &key);
477 printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); 464 printk(KERN_DEBUG "\tkey %s\n",
465 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN));
478 printk(KERN_DEBUG "\tcreat_sqnum %llu\n", 466 printk(KERN_DEBUG "\tcreat_sqnum %llu\n",
479 (unsigned long long)le64_to_cpu(ino->creat_sqnum)); 467 (unsigned long long)le64_to_cpu(ino->creat_sqnum));
480 printk(KERN_DEBUG "\tsize %llu\n", 468 printk(KERN_DEBUG "\tsize %llu\n",
@@ -517,7 +505,8 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node)
517 int nlen = le16_to_cpu(dent->nlen); 505 int nlen = le16_to_cpu(dent->nlen);
518 506
519 key_read(c, &dent->key, &key); 507 key_read(c, &dent->key, &key);
520 printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); 508 printk(KERN_DEBUG "\tkey %s\n",
509 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN));
521 printk(KERN_DEBUG "\tinum %llu\n", 510 printk(KERN_DEBUG "\tinum %llu\n",
522 (unsigned long long)le64_to_cpu(dent->inum)); 511 (unsigned long long)le64_to_cpu(dent->inum));
523 printk(KERN_DEBUG "\ttype %d\n", (int)dent->type); 512 printk(KERN_DEBUG "\ttype %d\n", (int)dent->type);
@@ -541,7 +530,8 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node)
541 int dlen = le32_to_cpu(ch->len) - UBIFS_DATA_NODE_SZ; 530 int dlen = le32_to_cpu(ch->len) - UBIFS_DATA_NODE_SZ;
542 531
543 key_read(c, &dn->key, &key); 532 key_read(c, &dn->key, &key);
544 printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); 533 printk(KERN_DEBUG "\tkey %s\n",
534 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN));
545 printk(KERN_DEBUG "\tsize %u\n", 535 printk(KERN_DEBUG "\tsize %u\n",
546 le32_to_cpu(dn->size)); 536 le32_to_cpu(dn->size));
547 printk(KERN_DEBUG "\tcompr_typ %d\n", 537 printk(KERN_DEBUG "\tcompr_typ %d\n",
@@ -582,7 +572,9 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node)
582 key_read(c, &br->key, &key); 572 key_read(c, &br->key, &key);
583 printk(KERN_DEBUG "\t%d: LEB %d:%d len %d key %s\n", 573 printk(KERN_DEBUG "\t%d: LEB %d:%d len %d key %s\n",
584 i, le32_to_cpu(br->lnum), le32_to_cpu(br->offs), 574 i, le32_to_cpu(br->lnum), le32_to_cpu(br->offs),
585 le32_to_cpu(br->len), DBGKEY(&key)); 575 le32_to_cpu(br->len),
576 dbg_snprintf_key(c, &key, key_buf,
577 DBG_KEY_BUF_LEN));
586 } 578 }
587 break; 579 break;
588 } 580 }
@@ -934,6 +926,7 @@ void dbg_dump_znode(const struct ubifs_info *c,
934{ 926{
935 int n; 927 int n;
936 const struct ubifs_zbranch *zbr; 928 const struct ubifs_zbranch *zbr;
929 char key_buf[DBG_KEY_BUF_LEN];
937 930
938 spin_lock(&dbg_lock); 931 spin_lock(&dbg_lock);
939 if (znode->parent) 932 if (znode->parent)
@@ -958,12 +951,16 @@ void dbg_dump_znode(const struct ubifs_info *c,
958 printk(KERN_DEBUG "\t%d: znode %p LEB %d:%d len %d key " 951 printk(KERN_DEBUG "\t%d: znode %p LEB %d:%d len %d key "
959 "%s\n", n, zbr->znode, zbr->lnum, 952 "%s\n", n, zbr->znode, zbr->lnum,
960 zbr->offs, zbr->len, 953 zbr->offs, zbr->len,
961 DBGKEY(&zbr->key)); 954 dbg_snprintf_key(c, &zbr->key,
955 key_buf,
956 DBG_KEY_BUF_LEN));
962 else 957 else
963 printk(KERN_DEBUG "\t%d: LNC %p LEB %d:%d len %d key " 958 printk(KERN_DEBUG "\t%d: LNC %p LEB %d:%d len %d key "
964 "%s\n", n, zbr->znode, zbr->lnum, 959 "%s\n", n, zbr->znode, zbr->lnum,
965 zbr->offs, zbr->len, 960 zbr->offs, zbr->len,
966 DBGKEY(&zbr->key)); 961 dbg_snprintf_key(c, &zbr->key,
962 key_buf,
963 DBG_KEY_BUF_LEN));
967 } 964 }
968 spin_unlock(&dbg_lock); 965 spin_unlock(&dbg_lock);
969} 966}
@@ -1260,6 +1257,7 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
1260 int err, nlen1, nlen2, cmp; 1257 int err, nlen1, nlen2, cmp;
1261 struct ubifs_dent_node *dent1, *dent2; 1258 struct ubifs_dent_node *dent1, *dent2;
1262 union ubifs_key key; 1259 union ubifs_key key;
1260 char key_buf[DBG_KEY_BUF_LEN];
1263 1261
1264 ubifs_assert(!keys_cmp(c, &zbr1->key, &zbr2->key)); 1262 ubifs_assert(!keys_cmp(c, &zbr1->key, &zbr2->key));
1265 dent1 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS); 1263 dent1 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS);
@@ -1290,9 +1288,11 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
1290 key_read(c, &dent1->key, &key); 1288 key_read(c, &dent1->key, &key);
1291 if (keys_cmp(c, &zbr1->key, &key)) { 1289 if (keys_cmp(c, &zbr1->key, &key)) {
1292 dbg_err("1st entry at %d:%d has key %s", zbr1->lnum, 1290 dbg_err("1st entry at %d:%d has key %s", zbr1->lnum,
1293 zbr1->offs, DBGKEY(&key)); 1291 zbr1->offs, dbg_snprintf_key(c, &key, key_buf,
1292 DBG_KEY_BUF_LEN));
1294 dbg_err("but it should have key %s according to tnc", 1293 dbg_err("but it should have key %s according to tnc",
1295 DBGKEY(&zbr1->key)); 1294 dbg_snprintf_key(c, &zbr1->key, key_buf,
1295 DBG_KEY_BUF_LEN));
1296 dbg_dump_node(c, dent1); 1296 dbg_dump_node(c, dent1);
1297 goto out_free; 1297 goto out_free;
1298 } 1298 }
@@ -1300,9 +1300,11 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
1300 key_read(c, &dent2->key, &key); 1300 key_read(c, &dent2->key, &key);
1301 if (keys_cmp(c, &zbr2->key, &key)) { 1301 if (keys_cmp(c, &zbr2->key, &key)) {
1302 dbg_err("2nd entry at %d:%d has key %s", zbr1->lnum, 1302 dbg_err("2nd entry at %d:%d has key %s", zbr1->lnum,
1303 zbr1->offs, DBGKEY(&key)); 1303 zbr1->offs, dbg_snprintf_key(c, &key, key_buf,
1304 DBG_KEY_BUF_LEN));
1304 dbg_err("but it should have key %s according to tnc", 1305 dbg_err("but it should have key %s according to tnc",
1305 DBGKEY(&zbr2->key)); 1306 dbg_snprintf_key(c, &zbr2->key, key_buf,
1307 DBG_KEY_BUF_LEN));
1306 dbg_dump_node(c, dent2); 1308 dbg_dump_node(c, dent2);
1307 goto out_free; 1309 goto out_free;
1308 } 1310 }
@@ -1319,7 +1321,7 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
1319 dbg_err("2 xent/dent nodes with the same name"); 1321 dbg_err("2 xent/dent nodes with the same name");
1320 else 1322 else
1321 dbg_err("bad order of colliding key %s", 1323 dbg_err("bad order of colliding key %s",
1322 DBGKEY(&key)); 1324 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN));
1323 1325
1324 ubifs_msg("first node at %d:%d\n", zbr1->lnum, zbr1->offs); 1326 ubifs_msg("first node at %d:%d\n", zbr1->lnum, zbr1->offs);
1325 dbg_dump_node(c, dent1); 1327 dbg_dump_node(c, dent1);