1 commit 2963f3d09eb3a0817f87386c0bd7be7ce086809d
2 Author: Wang Shilong <wshilong@whamcloud.com>
3 AuthorDate: Tue Sep 8 21:54:29 2015 +0800
4 LU-7114 ldiskfs: corrupted bitmaps handling patches
6 This patch backported following patches from upstream:
8 163a203ddb36c36d4a1c942aececda0cc8d06aa7
9 ext4: mark block group as corrupt on block bitmap error
11 87a39389be3e3b007d341be510a7e4a0542bdf05
12 ext4: mark block group as corrupt on inode bitmap error
14 bdfb6ff4a255dcebeb09a901250e13a97eff75af
15 ext4: mark group corrupt on group descriptor checksum
17 Also use ext4_warning() instead of ext4_error() so that
18 filesystem don't become RO in default, and together
19 with these patches,FS wil still be usable even such
22 Signed-off-by: Wang Shilong <wshilong@ddn.com>
23 Change-Id: Ib4075aba7df6f7f59e89a90475405080acd43dd0
24 Reviewed-on: http://review.whamcloud.com/16312
25 Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
26 Reviewed-by: Yang Sheng <yang.sheng@intel.com>
28 NOTE: Ported to linux 5.8 keeps the ext4_warning() updates.
30 fs/ext4/balloc.c | 10 ++++----
31 fs/ext4/ialloc.c | 6 ++--
32 fs/ext4/mballoc.c | 66 +++++++++++++++++++++---------------------------------
33 3 files changed, 34 insertions(+), 48 deletions(-)
35 --- a/fs/ext4/balloc.c
36 +++ b/fs/ext4/balloc.c
37 @@ -382,7 +382,7 @@ static int ext4_validate_block_bitmap(st
39 ext4_simulate_fail(sb, EXT4_SIM_BBITMAP_CRC))) {
40 ext4_unlock_group(sb, block_group);
41 - ext4_error(sb, "bg %u: bad block bitmap checksum", block_group);
42 + ext4_warning(sb, "bg %u: bad block bitmap checksum", block_group);
43 ext4_mark_group_bitmap_corrupted(sb, block_group,
44 EXT4_GROUP_INFO_BBITMAP_CORRUPT);
46 @@ -390,8 +390,8 @@ static int ext4_validate_block_bitmap(st
47 blk = ext4_valid_block_bitmap(sb, desc, block_group, bh);
48 if (unlikely(blk != 0)) {
49 ext4_unlock_group(sb, block_group);
50 - ext4_error(sb, "bg %u: block %llu: invalid block bitmap",
52 + ext4_warning(sb, "bg %u: block %llu: invalid block bitmap",
54 ext4_mark_group_bitmap_corrupted(sb, block_group,
55 EXT4_GROUP_INFO_BBITMAP_CORRUPT);
57 @@ -467,8 +467,8 @@ ext4_read_block_bitmap_nowait(struct sup
58 ext4_unlock_group(sb, block_group);
61 - ext4_error(sb, "Failed to init block bitmap for group "
62 - "%u: %d", block_group, err);
63 + ext4_warning(sb, "Failed to init block bitmap for group "
64 + "%u: %d", block_group, err);
68 --- a/fs/ext4/ialloc.c
69 +++ b/fs/ext4/ialloc.c
70 @@ -97,8 +97,8 @@ static int ext4_validate_inode_bitmap(st
71 EXT4_INODES_PER_GROUP(sb) / 8) ||
72 ext4_simulate_fail(sb, EXT4_SIM_IBITMAP_CRC)) {
73 ext4_unlock_group(sb, block_group);
74 - ext4_error(sb, "Corrupt inode bitmap - block_group = %u, "
75 - "inode_bitmap = %llu", block_group, blk);
76 + ext4_warning(sb, "Corrupt inode bitmap - block_group = %u, "
77 + "inode_bitmap = %llu", block_group, blk);
78 ext4_mark_group_bitmap_corrupted(sb, block_group,
79 EXT4_GROUP_INFO_IBITMAP_CORRUPT);
81 @@ -345,7 +345,7 @@ out:
85 - ext4_error(sb, "bit already cleared for inode %lu", ino);
86 + ext4_warning(sb, "bit already cleared for inode %lu", ino);
87 ext4_mark_group_bitmap_corrupted(sb, block_group,
88 EXT4_GROUP_INFO_IBITMAP_CORRUPT);
90 --- a/fs/ext4/mballoc.c
91 +++ b/fs/ext4/mballoc.c
92 @@ -802,10 +802,14 @@ int ext4_mb_generate_buddy(struct super_
93 grp->bb_fragments = fragments;
95 if (free != grp->bb_free) {
96 - ext4_grp_locked_error(sb, group, 0, 0,
97 - "block bitmap and bg descriptor "
98 - "inconsistent: %u vs %u free clusters",
99 - free, grp->bb_free);
100 + struct ext4_group_desc *gdp;
101 + gdp = ext4_get_group_desc(sb, group, NULL);
102 + ext4_warning(sb, "group %lu: block bitmap and bg descriptor "
103 + "inconsistent: %u vs %u free clusters "
104 + "%u in gd, %lu pa's",
105 + (long unsigned int)group, free, grp->bb_free,
106 + ext4_free_group_clusters(sb, gdp),
107 + grp->bb_prealloc_nr);
109 * If we intend to continue, we consider group descriptor
110 * corrupt and update bb_free using bitmap value
111 @@ -1168,7 +1172,7 @@ ext4_mb_load_buddy_gfp(struct super_bloc
116 + struct page *page = NULL;
118 struct ext4_group_info *grp;
119 struct ext4_sb_info *sbi = EXT4_SB(sb);
120 @@ -1194,7 +1198,7 @@ ext4_mb_load_buddy_gfp(struct super_bloc
122 ret = ext4_mb_init_group(sb, group, gfp);
129 @@ -1297,6 +1301,7 @@ err:
130 put_page(e4b->bd_buddy_page);
131 e4b->bd_buddy = NULL;
132 e4b->bd_bitmap = NULL;
133 + ext4_warning(sb, "Error loading buddy information for %u", group);
137 @@ -3782,9 +3787,11 @@ int ext4_mb_check_ondisk_bitmap(struct s
140 if (free != free_in_gdp) {
141 - ext4_error(sb, "on-disk bitmap for group %d"
142 + ext4_warning(sb, "on-disk bitmap for group %d"
143 "corrupted: %u blocks free in bitmap, %u - in gd\n",
144 group, free, free_in_gdp);
145 + ext4_mark_group_bitmap_corrupted(sb, group,
146 + EXT4_GROUP_INFO_BBITMAP_CORRUPT);
150 @@ -4129,16 +4136,8 @@ ext4_mb_release_inode_pa(struct ext4_bud
151 /* "free < pa->pa_free" means we maybe double alloc the same blocks,
152 * otherwise maybe leave some free blocks unavailable, no need to BUG.*/
153 if ((free > pa->pa_free && !pa->pa_error) || (free < pa->pa_free)) {
154 - ext4_error(sb, "pa free mismatch: [pa %p] "
155 - "[phy %lu] [logic %lu] [len %u] [free %u] "
156 - "[error %u] [inode %d] [freed %u]", pa,
157 - (unsigned long)pa->pa_pstart,
158 - (unsigned long)pa->pa_lstart,
159 - pa->pa_len, (unsigned)pa->pa_free,
160 - (unsigned)pa->pa_error, pa->pa_inode->i_ino,
162 ext4_grp_locked_error(sb, group, 0, 0, "free %u, pa_free %u",
163 - free, pa->pa_free);
164 + free, pa->pa_free);
166 * pa is already deleted so we use the value obtained
167 * from the bitmap and continue.
168 @@ -4199,16 +4198,11 @@ ext4_mb_discard_group_preallocations(str
169 bitmap_bh = ext4_read_block_bitmap(sb, group);
170 if (IS_ERR(bitmap_bh)) {
171 err = PTR_ERR(bitmap_bh);
172 - ext4_error_err(sb, -err,
173 - "Error %d reading block bitmap for %u",
178 err = ext4_mb_load_buddy(sb, group, &e4b);
180 - ext4_warning(sb, "Error %d loading buddy information for %u",
185 @@ -4376,17 +4370,12 @@ repeat:
187 err = ext4_mb_load_buddy_gfp(sb, group, &e4b,
188 GFP_NOFS|__GFP_NOFAIL);
190 - ext4_error_err(sb, -err, "Error %d loading buddy information for %u",
196 bitmap_bh = ext4_read_block_bitmap(sb, group);
197 if (IS_ERR(bitmap_bh)) {
198 err = PTR_ERR(bitmap_bh);
199 - ext4_error_err(sb, -err, "Error %d reading block bitmap for %u",
201 ext4_mb_unload_buddy(&e4b);
204 @@ -4681,11 +4670,8 @@ ext4_mb_discard_lg_preallocations(struct
205 group = ext4_get_group_number(sb, pa->pa_pstart);
206 err = ext4_mb_load_buddy_gfp(sb, group, &e4b,
207 GFP_NOFS|__GFP_NOFAIL);
209 - ext4_error_err(sb, -err, "Error %d loading buddy information for %u",
214 ext4_lock_group(sb, group);
215 list_del(&pa->pa_group_list);
216 ext4_get_group_info(sb, group)->bb_prealloc_nr--;
217 @@ -4974,7 +4960,7 @@ errout:
218 * been updated or not when fail case. So can
219 * not revert pa_free back, just mark pa_error*/
223 "Updating bitmap error: [err %d] "
224 "[pa %p] [phy %lu] [logic %lu] "
225 "[len %u] [free %u] [error %u] "
226 @@ -4985,6 +4971,7 @@ errout:
227 (unsigned)pa->pa_free,
228 (unsigned)pa->pa_error,
229 pa->pa_inode ? pa->pa_inode->i_ino : 0);
230 + ext4_mark_group_bitmap_corrupted(sb, 0, 0);
233 ext4_mb_release_context(ac);
234 @@ -5271,7 +5258,7 @@ do_more:
235 err = ext4_mb_load_buddy_gfp(sb, block_group, &e4b,
236 GFP_NOFS|__GFP_NOFAIL);
242 * We need to make sure we don't reuse the freed block until after the
243 @@ -5362,8 +5349,9 @@ do_more:
248 ext4_std_error(sb, err);
254 @@ -5463,7 +5451,7 @@ int ext4_group_add_blocks(handle_t *hand
256 err = ext4_mb_load_buddy(sb, block_group, &e4b);
262 * need to update group_info->bb_free and bitmap
263 @@ -5502,8 +5490,9 @@ int ext4_group_add_blocks(handle_t *hand
268 ext4_std_error(sb, err);
274 @@ -5578,11 +5567,8 @@ ext4_trim_all_free(struct super_block *s
275 trace_ext4_trim_all_free(sb, group, start, max);
277 ret = ext4_mb_load_buddy(sb, group, &e4b);
279 - ext4_warning(sb, "Error %d loading buddy information for %u",
284 bitmap = e4b.bd_bitmap;
286 ext4_lock_group(sb, group);