add patch update-mtime-in-ext4_punch_hole-even-if-no-blocks-removed
[ext4-patch-queue.git] / mark-inode-bitmap-corrupted-when-found
blob21908cbd748647417f539cc2805debeaa542bade
1 ext4: mark inode bitmap corrupted when found
3 From: Wang Shilong <wshilong@ddn.com>
5 There are still some cases that we missed to set
6 block bitmaps corrupted bit properly:
8 1)inode bitmap number is wrong.
9 2)failed to read block bitmap due to disk errors.
10 3)double allocations from bitmap
12 Also remove a duplicated call ext4_error() afer
13 ext4_read_inode_bitmap(), as ext4_error() have been
14 called inside ext4_read_inode_bitmap() properly.
16 Signed-off-by: Wang Shilong <wshilong@ddn.com>
17 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
18 Reviewed-by: Andreas Dilger <adilger@dilger.ca>
19 ---
20  fs/ext4/ialloc.c | 13 +++++++++----
21  1 file changed, 9 insertions(+), 4 deletions(-)
23 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
24 index 95611cf9f552..4d6e007f3569 100644
25 --- a/fs/ext4/ialloc.c
26 +++ b/fs/ext4/ialloc.c
27 @@ -129,6 +129,8 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
28             (bitmap_blk >= ext4_blocks_count(sbi->s_es))) {
29                 ext4_error(sb, "Invalid inode bitmap blk %llu in "
30                            "block_group %u", bitmap_blk, block_group);
31 +               ext4_mark_group_bitmap_corrupted(sb, block_group,
32 +                                       EXT4_GROUP_INFO_IBITMAP_CORRUPT);
33                 return ERR_PTR(-EFSCORRUPTED);
34         }
35         bh = sb_getblk(sb, bitmap_blk);
36 @@ -183,6 +185,8 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
37                 ext4_error(sb, "Cannot read inode bitmap - "
38                            "block_group = %u, inode_bitmap = %llu",
39                            block_group, bitmap_blk);
40 +               ext4_mark_group_bitmap_corrupted(sb, block_group,
41 +                               EXT4_GROUP_INFO_IBITMAP_CORRUPT);
42                 return ERR_PTR(-EIO);
43         }
45 @@ -902,6 +906,8 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
46                 if (group == 0 && (ino + 1) < EXT4_FIRST_INO(sb)) {
47                         ext4_error(sb, "reserved inode found cleared - "
48                                    "inode=%lu", ino + 1);
49 +                       ext4_mark_group_bitmap_corrupted(sb, group,
50 +                                       EXT4_GROUP_INFO_IBITMAP_CORRUPT);
51                         goto next_group;
52                 }
54 @@ -1093,6 +1099,8 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
55                 err = -EIO;
56                 ext4_error(sb, "failed to insert inode %lu: doubly allocated?",
57                            inode->i_ino);
58 +               ext4_mark_group_bitmap_corrupted(sb, group,
59 +                                       EXT4_GROUP_INFO_IBITMAP_CORRUPT);
60                 goto out;
61         }
62         inode->i_generation = prandom_u32();
63 @@ -1194,11 +1202,8 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
64         block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
65         bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
66         bitmap_bh = ext4_read_inode_bitmap(sb, block_group);
67 -       if (IS_ERR(bitmap_bh)) {
68 -               ext4_error(sb, "inode bitmap error %ld for orphan %lu",
69 -                          ino, PTR_ERR(bitmap_bh));
70 +       if (IS_ERR(bitmap_bh))
71                 return (struct inode *) bitmap_bh;
72 -       }
74         /* Having the inode bit set should be a 100% indicator that this
75          * is a valid orphan (no e2fsck run on fs).  Orphans also include
76 -- 
77 2.14.3