1 ext4: clean up error handling when orphan list is corrupted
3 Instead of just printing warning messages, if the orphan list is
4 corrupted, declare the file system is corrupted. If there are any
5 reserved inodes in the orphaned inode list, declare the file system
6 corrupted and stop right away to avoid doing more potential damage to
9 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 fs/ext4/ialloc.c | 49 ++++++++++++++++++++++---------------------------
12 1 file changed, 22 insertions(+), 27 deletions(-)
14 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
15 index c2caf2d..3da4cf8 100644
16 --- a/fs/ext4/ialloc.c
17 +++ b/fs/ext4/ialloc.c
18 @@ -1150,25 +1150,20 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
19 unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
20 ext4_group_t block_group;
22 - struct buffer_head *bitmap_bh;
23 + struct buffer_head *bitmap_bh = NULL;
24 struct inode *inode = NULL;
26 + int err = -EFSCORRUPTED;
28 - /* Error cases - e2fsck has already cleaned up for us */
29 - if (ino > max_ino) {
30 - ext4_warning(sb, "bad orphan ino %lu! e2fsck was run?", ino);
31 - err = -EFSCORRUPTED;
34 + if (ino < EXT4_FIRST_INO(sb) || ino > max_ino)
37 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
38 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
39 bitmap_bh = ext4_read_inode_bitmap(sb, block_group);
40 if (IS_ERR(bitmap_bh)) {
41 - err = PTR_ERR(bitmap_bh);
42 - ext4_warning(sb, "inode bitmap error %ld for orphan %lu",
45 + ext4_error(sb, "inode bitmap error %ld for orphan %lu",
46 + ino, PTR_ERR(bitmap_bh));
47 + return (struct inode *) bitmap_bh;
50 /* Having the inode bit set should be a 100% indicator that this
51 @@ -1179,8 +1174,12 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
54 inode = ext4_iget(sb, ino);
57 + if (IS_ERR(inode)) {
58 + err = PTR_ERR(inode);
59 + ext4_error(sb, "couldn't read orphan inode %lu (err %d)",
65 * If the orphans has i_nlinks > 0 then it should be able to
66 @@ -1197,29 +1196,25 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
71 - err = PTR_ERR(inode);
74 - ext4_warning(sb, "bad orphan inode %lu! e2fsck was run?", ino);
75 - printk(KERN_WARNING "ext4_test_bit(bit=%d, block=%llu) = %d\n",
76 - bit, (unsigned long long)bitmap_bh->b_blocknr,
77 - ext4_test_bit(bit, bitmap_bh->b_data));
78 - printk(KERN_WARNING "inode=%p\n", inode);
79 + ext4_error(sb, "bad orphan inode %lu", ino);
81 + printk(KERN_ERR "ext4_test_bit(bit=%d, block=%llu) = %d\n",
82 + bit, (unsigned long long)bitmap_bh->b_blocknr,
83 + ext4_test_bit(bit, bitmap_bh->b_data));
85 - printk(KERN_WARNING "is_bad_inode(inode)=%d\n",
86 + printk(KERN_ERR "is_bad_inode(inode)=%d\n",
88 - printk(KERN_WARNING "NEXT_ORPHAN(inode)=%u\n",
89 + printk(KERN_ERR "NEXT_ORPHAN(inode)=%u\n",
91 - printk(KERN_WARNING "max_ino=%lu\n", max_ino);
92 - printk(KERN_WARNING "i_nlink=%u\n", inode->i_nlink);
93 + printk(KERN_ERR "max_ino=%lu\n", max_ino);
94 + printk(KERN_ERR "i_nlink=%u\n", inode->i_nlink);
95 /* Avoid freeing blocks if we got a bad deleted inode */
96 if (inode->i_nlink == 0)