1 Subject: [PATCH] ext4-corrupted-inode-block-bitmaps-handling-patches
3 Since we could skip corrupt block groups, this patch
4 use ext4_warning() intead of ext4_error() to make FS not
8 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
9 index fadcb94e..f151ba9c 100644
10 --- a/fs/ext4/balloc.c
11 +++ b/fs/ext4/balloc.c
12 @@ -419,7 +419,7 @@ static int ext4_validate_block_bitmap(struct super_block *sb,
14 ext4_simulate_fail(sb, EXT4_SIM_BBITMAP_CRC))) {
15 ext4_unlock_group(sb, block_group);
16 - ext4_error(sb, "bg %u: bad block bitmap checksum", block_group);
17 + ext4_warning(sb, "bg %u: bad block bitmap checksum", block_group);
18 ext4_mark_group_bitmap_corrupted(sb, block_group,
19 EXT4_GROUP_INFO_BBITMAP_CORRUPT);
21 @@ -427,8 +427,8 @@ static int ext4_validate_block_bitmap(struct super_block *sb,
22 blk = ext4_valid_block_bitmap(sb, desc, block_group, bh);
23 if (unlikely(blk != 0)) {
24 ext4_unlock_group(sb, block_group);
25 - ext4_error(sb, "bg %u: block %llu: invalid block bitmap",
27 + ext4_warning(sb, "bg %u: block %llu: invalid block bitmap",
29 ext4_mark_group_bitmap_corrupted(sb, block_group,
30 EXT4_GROUP_INFO_BBITMAP_CORRUPT);
32 @@ -520,8 +520,8 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group,
33 ext4_unlock_group(sb, block_group);
36 - ext4_error(sb, "Failed to init block bitmap for group "
37 - "%u: %d", block_group, err);
38 + ext4_warning(sb, "Failed to init block bitmap for group "
39 + "%u: %d", block_group, err);
43 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
44 index d66fab40..fe275613 100644
45 --- a/fs/ext4/ialloc.c
46 +++ b/fs/ext4/ialloc.c
47 @@ -102,8 +102,8 @@ static int ext4_validate_inode_bitmap(struct super_block *sb,
48 EXT4_INODES_PER_GROUP(sb) / 8) ||
49 ext4_simulate_fail(sb, EXT4_SIM_IBITMAP_CRC)) {
50 ext4_unlock_group(sb, block_group);
51 - ext4_error(sb, "Corrupt inode bitmap - block_group = %u, "
52 - "inode_bitmap = %llu", block_group, blk);
53 + ext4_warning(sb, "Corrupt inode bitmap - block_group = %u, "
54 + "inode_bitmap = %llu", block_group, blk);
55 ext4_mark_group_bitmap_corrupted(sb, block_group,
56 EXT4_GROUP_INFO_IBITMAP_CORRUPT);
58 @@ -353,7 +353,7 @@ out:
62 - ext4_error(sb, "bit already cleared for inode %lu", ino);
63 + ext4_warning(sb, "bit already cleared for inode %lu", ino);
64 ext4_mark_group_bitmap_corrupted(sb, block_group,
65 EXT4_GROUP_INFO_IBITMAP_CORRUPT);
67 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
68 index 8fdcfc78..6b4b5fb8 100644
69 --- a/fs/ext4/mballoc.c
70 +++ b/fs/ext4/mballoc.c
71 @@ -1144,10 +1144,14 @@ int ext4_mb_generate_buddy(struct super_block *sb,
72 grp->bb_fragments = fragments;
74 if (free != grp->bb_free) {
75 - ext4_grp_locked_error(sb, group, 0, 0,
76 - "block bitmap and bg descriptor "
77 - "inconsistent: %u vs %u free clusters",
78 - free, grp->bb_free);
79 + struct ext4_group_desc *gdp;
80 + gdp = ext4_get_group_desc(sb, group, NULL);
81 + ext4_warning(sb, "group %lu: block bitmap and bg descriptor "
82 + "inconsistent: %u vs %u free clusters "
83 + "%u in gd, %lu pa's",
84 + (long unsigned int)group, free, grp->bb_free,
85 + ext4_free_group_clusters(sb, gdp),
86 + grp->bb_prealloc_nr);
88 * If we intend to continue, we consider group descriptor
89 * corrupt and update bb_free using bitmap value
90 @@ -1500,7 +1504,7 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_group_t group,
95 + struct page *page = NULL;
97 struct ext4_group_info *grp;
98 struct ext4_sb_info *sbi = EXT4_SB(sb);
99 @@ -1528,7 +1532,7 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_group_t group,
101 ret = ext4_mb_init_group(sb, group, gfp);
108 @@ -1628,6 +1632,7 @@ err:
109 put_page(e4b->bd_buddy_page);
110 e4b->bd_buddy = NULL;
111 e4b->bd_bitmap = NULL;
112 + ext4_warning(sb, "Error loading buddy information for %u", group);
116 @@ -5045,16 +5050,8 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
117 /* "free < pa->pa_free" means we maybe double alloc the same blocks,
118 * otherwise maybe leave some free blocks unavailable, no need to BUG.*/
119 if ((free > pa->pa_free && !pa->pa_error) || (free < pa->pa_free)) {
120 - ext4_error(sb, "pa free mismatch: [pa %p] "
121 - "[phy %lu] [logic %lu] [len %u] [free %u] "
122 - "[error %u] [inode %d] [freed %u]", pa,
123 - (unsigned long)pa->pa_pstart,
124 - (unsigned long)pa->pa_lstart,
125 - pa->pa_len, (unsigned)pa->pa_free,
126 - (unsigned)pa->pa_error, pa->pa_inode->i_ino,
128 ext4_grp_locked_error(sb, group, 0, 0, "free %u, pa_free %u",
129 - free, pa->pa_free);
130 + free, pa->pa_free);
132 * pa is already deleted so we use the value obtained
133 * from the bitmap and continue.
134 @@ -5120,16 +5117,11 @@ ext4_mb_discard_group_preallocations(struct super_block *sb,
135 bitmap_bh = ext4_read_block_bitmap(sb, group);
136 if (IS_ERR(bitmap_bh)) {
137 err = PTR_ERR(bitmap_bh);
138 - ext4_error_err(sb, -err,
139 - "Error %d reading block bitmap for %u",
144 err = ext4_mb_load_buddy(sb, group, &e4b);
146 - ext4_warning(sb, "Error %d loading buddy information for %u",
151 @@ -5286,17 +5278,12 @@ repeat:
153 err = ext4_mb_load_buddy_gfp(sb, group, &e4b,
154 GFP_NOFS|__GFP_NOFAIL);
156 - ext4_error_err(sb, -err, "Error %d loading buddy information for %u",
162 bitmap_bh = ext4_read_block_bitmap(sb, group);
163 if (IS_ERR(bitmap_bh)) {
164 err = PTR_ERR(bitmap_bh);
165 - ext4_error_err(sb, -err, "Error %d reading block bitmap for %u",
167 ext4_mb_unload_buddy(&e4b);
170 @@ -5596,11 +5583,8 @@ ext4_mb_discard_lg_preallocations(struct super_block *sb,
171 group = ext4_get_group_number(sb, pa->pa_pstart);
172 err = ext4_mb_load_buddy_gfp(sb, group, &e4b,
173 GFP_NOFS|__GFP_NOFAIL);
175 - ext4_error_err(sb, -err, "Error %d loading buddy information for %u",
180 ext4_lock_group(sb, group);
181 list_del(&pa->pa_group_list);
182 ext4_get_group_info(sb, group)->bb_prealloc_nr--;
183 @@ -5937,7 +5921,7 @@ errout:
184 * been updated or not when fail case. So can
185 * not revert pa_free back, just mark pa_error*/
189 "Updating bitmap error: [err %d] "
190 "[pa %p] [phy %lu] [logic %lu] "
191 "[len %u] [free %u] [error %u] "
192 @@ -5948,6 +5932,7 @@ errout:
193 (unsigned)pa->pa_free,
194 (unsigned)pa->pa_error,
195 pa->pa_inode ? pa->pa_inode->i_ino : 0);
196 + ext4_mark_group_bitmap_corrupted(sb, 0, 0);
199 ext4_mb_release_context(ac);
200 @@ -6280,7 +6265,7 @@ do_more:
201 err = ext4_mb_load_buddy_gfp(sb, block_group, &e4b,
202 GFP_NOFS|__GFP_NOFAIL);
208 * We need to make sure we don't reuse the freed block until after the
209 @@ -6373,8 +6358,9 @@ do_more:
214 ext4_std_error(sb, err);
220 @@ -6573,7 +6559,7 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
222 err = ext4_mb_load_buddy(sb, block_group, &e4b);
228 * need to update group_info->bb_free and bitmap
229 @@ -6612,8 +6598,9 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
234 ext4_std_error(sb, err);
240 @@ -6733,8 +6720,6 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
242 ret = ext4_mb_load_buddy(sb, group, &e4b);
244 - ext4_warning(sb, "Error %d loading buddy information for %u",