Skip to content

Commit 4315fb4

Browse files
Artem Bityutskiydedekind
authored andcommitted
UBIFS: improve inode dumping function
Teach 'dbg_dump_inode()' dump directory entries for directory inodes. This requires few additional changes: 1. The 'c' argument of 'dbg_dump_inode()' cannot be const any more. 2. Users of 'dbg_dump_inode()' should not have 'tnc_mutex' locked. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
1 parent bfcf677 commit 4315fb4

3 files changed

Lines changed: 60 additions & 5 deletions

File tree

‎fs/ubifs/debug.c‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,28 @@ static const char *get_key_type(int type)
9191
}
9292
}
9393

94+
static const char *get_dent_type(int type)
95+
{
96+
switch (type) {
97+
case UBIFS_ITYPE_REG:
98+
return "file";
99+
case UBIFS_ITYPE_DIR:
100+
return "dir";
101+
case UBIFS_ITYPE_LNK:
102+
return "symlink";
103+
case UBIFS_ITYPE_BLK:
104+
return "blkdev";
105+
case UBIFS_ITYPE_CHR:
106+
return "char dev";
107+
case UBIFS_ITYPE_FIFO:
108+
return "fifo";
109+
case UBIFS_ITYPE_SOCK:
110+
return "socket";
111+
default:
112+
return "unknown/invalid type";
113+
}
114+
}
115+
94116
static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key,
95117
char *buffer)
96118
{
@@ -234,9 +256,13 @@ static void dump_ch(const struct ubifs_ch *ch)
234256
printk(KERN_DEBUG "\tlen %u\n", le32_to_cpu(ch->len));
235257
}
236258

237-
void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode)
259+
void dbg_dump_inode(struct ubifs_info *c, const struct inode *inode)
238260
{
239261
const struct ubifs_inode *ui = ubifs_inode(inode);
262+
struct qstr nm = { .name = NULL };
263+
union ubifs_key key;
264+
struct ubifs_dent_node *dent, *pdent = NULL;
265+
int count = 2;
240266

241267
printk(KERN_DEBUG "Dump in-memory inode:");
242268
printk(KERN_DEBUG "\tinode %lu\n", inode->i_ino);
@@ -270,6 +296,32 @@ void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode)
270296
printk(KERN_DEBUG "\tlast_page_read %lu\n", ui->last_page_read);
271297
printk(KERN_DEBUG "\tread_in_a_row %lu\n", ui->read_in_a_row);
272298
printk(KERN_DEBUG "\tdata_len %d\n", ui->data_len);
299+
300+
if (!S_ISDIR(inode->i_mode))
301+
return;
302+
303+
printk(KERN_DEBUG "List of directory entries:\n");
304+
ubifs_assert(!mutex_is_locked(&c->tnc_mutex));
305+
306+
lowest_dent_key(c, &key, inode->i_ino);
307+
while (1) {
308+
dent = ubifs_tnc_next_ent(c, &key, &nm);
309+
if (IS_ERR(dent)) {
310+
if (PTR_ERR(dent) != -ENOENT)
311+
printk(KERN_DEBUG "error %ld\n", PTR_ERR(dent));
312+
break;
313+
}
314+
315+
printk(KERN_DEBUG "\t%d: %s (%s)\n",
316+
count++, dent->name, get_dent_type(dent->type));
317+
318+
nm.name = dent->name;
319+
nm.len = le16_to_cpu(dent->nlen);
320+
kfree(pdent);
321+
pdent = dent;
322+
key_read(c, &dent->key, &key);
323+
}
324+
kfree(pdent);
273325
}
274326

275327
void dbg_dump_node(const struct ubifs_info *c, const void *node)
@@ -1167,12 +1219,14 @@ int dbg_check_dir_size(struct ubifs_info *c, const struct inode *dir)
11671219
"but calculated size is %llu", dir->i_ino,
11681220
(unsigned long long)i_size_read(dir),
11691221
(unsigned long long)size);
1222+
dbg_dump_inode(c, dir);
11701223
dump_stack();
11711224
return -EINVAL;
11721225
}
11731226
if (dir->i_nlink != nlink) {
11741227
ubifs_err("directory inode %lu has nlink %u, but calculated "
11751228
"nlink is %u", dir->i_ino, dir->i_nlink, nlink);
1229+
dbg_dump_inode(c, dir);
11761230
dump_stack();
11771231
return -EINVAL;
11781232
}

‎fs/ubifs/debug.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ const char *dbg_cstate(int cmt_state);
214214
const char *dbg_jhead(int jhead);
215215
const char *dbg_get_key_dump(const struct ubifs_info *c,
216216
const union ubifs_key *key);
217-
void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode);
217+
void dbg_dump_inode(struct ubifs_info *c, const struct inode *inode);
218218
void dbg_dump_node(const struct ubifs_info *c, const void *node);
219219
void dbg_dump_lpt_node(const struct ubifs_info *c, void *node, int lnum,
220220
int offs);
@@ -364,7 +364,7 @@ static inline const char *dbg_jhead(int jhead) { return ""; }
364364
static inline const char *
365365
dbg_get_key_dump(const struct ubifs_info *c,
366366
const union ubifs_key *key) { return ""; }
367-
static inline void dbg_dump_inode(const struct ubifs_info *c,
367+
static inline void dbg_dump_inode(struct ubifs_info *c,
368368
const struct inode *inode) { return; }
369369
static inline void dbg_dump_node(const struct ubifs_info *c,
370370
const void *node) { return; }
@@ -418,7 +418,7 @@ static inline int dbg_chk_lpt_sz(struct ubifs_info *c,
418418
int action, int len) { return 0; }
419419
static inline int dbg_check_synced_i_size(struct inode *inode) { return 0; }
420420
static inline int dbg_check_dir_size(struct ubifs_info *c,
421-
const struct inode *dir) { return 0; }
421+
const struct inode *dir) { return 0; }
422422
static inline int dbg_check_tnc(struct ubifs_info *c, int extra) { return 0; }
423423
static inline int dbg_check_idx_size(struct ubifs_info *c,
424424
long long idx_size) { return 0; }

‎fs/ubifs/tnc.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3337,9 +3337,10 @@ int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode,
33373337
ubifs_err("inode %lu has size %lld, but there are data at offset %lld "
33383338
"(data key %s)", (unsigned long)inode->i_ino, size,
33393339
((loff_t)block) << UBIFS_BLOCK_SHIFT, DBGKEY(key));
3340+
mutex_unlock(&c->tnc_mutex);
33403341
dbg_dump_inode(c, inode);
33413342
dbg_dump_stack();
3342-
err = -EINVAL;
3343+
return -EINVAL;
33433344

33443345
out_unlock:
33453346
mutex_unlock(&c->tnc_mutex);

0 commit comments

Comments
 (0)