add patch remove-unnecessary-bio-get-put
[ext4-patch-queue.git] / clean-up-error-handling-for-orphan-list-problems
blobbc4265e88edc3418bb1dc81b6e1368b57db916b5
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
7 the file system.
9 Cc: stable@vger.kernel.org
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 ---
12  fs/ext4/ialloc.c | 49 ++++++++++++++++++++++---------------------------
13  1 file changed, 22 insertions(+), 27 deletions(-)
15 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
16 index c2caf2d..3da4cf8 100644
17 --- a/fs/ext4/ialloc.c
18 +++ b/fs/ext4/ialloc.c
19 @@ -1150,25 +1150,20 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
20         unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
21         ext4_group_t block_group;
22         int bit;
23 -       struct buffer_head *bitmap_bh;
24 +       struct buffer_head *bitmap_bh = NULL;
25         struct inode *inode = NULL;
26 -       long err = -EIO;
27 +       int err = -EFSCORRUPTED;
29 -       /* Error cases - e2fsck has already cleaned up for us */
30 -       if (ino > max_ino) {
31 -               ext4_warning(sb, "bad orphan ino %lu!  e2fsck was run?", ino);
32 -               err = -EFSCORRUPTED;
33 -               goto error;
34 -       }
35 +       if (ino < EXT4_FIRST_INO(sb) || ino > max_ino)
36 +               goto bad_orphan;
38         block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
39         bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
40         bitmap_bh = ext4_read_inode_bitmap(sb, block_group);
41         if (IS_ERR(bitmap_bh)) {
42 -               err = PTR_ERR(bitmap_bh);
43 -               ext4_warning(sb, "inode bitmap error %ld for orphan %lu",
44 -                            ino, err);
45 -               goto error;
46 +               ext4_error(sb, "inode bitmap error %ld for orphan %lu",
47 +                          ino, PTR_ERR(bitmap_bh));
48 +               return (struct inode *) bitmap_bh;
49         }
51         /* Having the inode bit set should be a 100% indicator that this
52 @@ -1179,8 +1174,12 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
53                 goto bad_orphan;
55         inode = ext4_iget(sb, ino);
56 -       if (IS_ERR(inode))
57 -               goto iget_failed;
58 +       if (IS_ERR(inode)) {
59 +               err = PTR_ERR(inode);
60 +               ext4_error(sb, "couldn't read orphan inode %lu (err %d)",
61 +                          ino, err);
62 +               return inode;
63 +       }
65         /*
66          * If the orphans has i_nlinks > 0 then it should be able to
67 @@ -1197,29 +1196,25 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
68         brelse(bitmap_bh);
69         return inode;
71 -iget_failed:
72 -       err = PTR_ERR(inode);
73 -       inode = NULL;
74  bad_orphan:
75 -       ext4_warning(sb, "bad orphan inode %lu!  e2fsck was run?", ino);
76 -       printk(KERN_WARNING "ext4_test_bit(bit=%d, block=%llu) = %d\n",
77 -              bit, (unsigned long long)bitmap_bh->b_blocknr,
78 -              ext4_test_bit(bit, bitmap_bh->b_data));
79 -       printk(KERN_WARNING "inode=%p\n", inode);
80 +       ext4_error(sb, "bad orphan inode %lu", ino);
81 +       if (bitmap_bh)
82 +               printk(KERN_ERR "ext4_test_bit(bit=%d, block=%llu) = %d\n",
83 +                      bit, (unsigned long long)bitmap_bh->b_blocknr,
84 +                      ext4_test_bit(bit, bitmap_bh->b_data));
85         if (inode) {
86 -               printk(KERN_WARNING "is_bad_inode(inode)=%d\n",
87 +               printk(KERN_ERR "is_bad_inode(inode)=%d\n",
88                        is_bad_inode(inode));
89 -               printk(KERN_WARNING "NEXT_ORPHAN(inode)=%u\n",
90 +               printk(KERN_ERR "NEXT_ORPHAN(inode)=%u\n",
91                        NEXT_ORPHAN(inode));
92 -               printk(KERN_WARNING "max_ino=%lu\n", max_ino);
93 -               printk(KERN_WARNING "i_nlink=%u\n", inode->i_nlink);
94 +               printk(KERN_ERR "max_ino=%lu\n", max_ino);
95 +               printk(KERN_ERR "i_nlink=%u\n", inode->i_nlink);
96                 /* Avoid freeing blocks if we got a bad deleted inode */
97                 if (inode->i_nlink == 0)
98                         inode->i_blocks = 0;
99                 iput(inode);
100         }
101         brelse(bitmap_bh);
102 -error:
103         return ERR_PTR(err);