Whamcloud - gitweb
39af563943c6d510f3b450068c2980ea59bbd17e
[fs/lustre-release.git] /
1 Subject: [PATCH] ext4-corrupted-inode-block-bitmaps-handling-patches
2
3 Since we could skip corrupt block groups, this patch
4 use ext4_warning() intead of ext4_error() to make FS not
5 remount RO in default
6
7 ---
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,
13                                                     desc, bh) ||
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);
20                 return -EFSBADCRC;
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",
26 -                          block_group, blk);
27 +               ext4_warning(sb, "bg %u: block %llu: invalid block bitmap",
28 +                            block_group, blk);
29                 ext4_mark_group_bitmap_corrupted(sb, block_group,
30                                         EXT4_GROUP_INFO_BBITMAP_CORRUPT);
31                 return -EFSCORRUPTED;
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);
34                 unlock_buffer(bh);
35                 if (err) {
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);
40                         goto out;
41                 }
42                 goto verify;
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);
57                 return -EFSBADCRC;
58 @@ -353,7 +353,7 @@ out:
59                 if (!fatal)
60                         fatal = err;
61         } else {
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);
66         }
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;
73  
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);
87                 /*
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,
91         int block;
92         int pnum;
93         int poff;
94 -       struct page *page;
95 +       struct page *page = NULL;
96         int ret;
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,
100                  */
101                 ret = ext4_mb_init_group(sb, group, gfp);
102                 if (ret)
103 -                       return ret;
104 +                       goto err;
105         }
106  
107         /*
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);
113         return ret;
114  }
115  
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,
127 -                               free);
128                 ext4_grp_locked_error(sb, group, 0, 0, "free %u, pa_free %u",
129 -                                       free, pa->pa_free);
130 +                                     free, pa->pa_free);
131                 /*
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",
140 -                              err, group);
141                 goto out_dbg;
142         }
143  
144         err = ext4_mb_load_buddy(sb, group, &e4b);
145         if (err) {
146 -               ext4_warning(sb, "Error %d loading buddy information for %u",
147 -                            err, group);
148                 put_bh(bitmap_bh);
149                 goto out_dbg;
150         }
151 @@ -5286,17 +5278,12 @@ repeat:
152  
153                 err = ext4_mb_load_buddy_gfp(sb, group, &e4b,
154                                              GFP_NOFS|__GFP_NOFAIL);
155 -               if (err) {
156 -                       ext4_error_err(sb, -err, "Error %d loading buddy information for %u",
157 -                                      err, group);
158 +               if (err)
159                         return;
160 -               }
161  
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",
166 -                                      err, group);
167                         ext4_mb_unload_buddy(&e4b);
168                         continue;
169                 }
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);
174 -               if (err) {
175 -                       ext4_error_err(sb, -err, "Error %d loading buddy information for %u",
176 -                                      err, group);
177 +               if (err)
178                         continue;
179 -               }
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*/
186                         pa->pa_error++;
187 -                       ext4_error(sb,
188 +                       ext4_warning(sb,
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);
197                 }
198         }
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);
203         if (err)
204 -               goto error_return;
205 +               goto error_brelse;
206  
207         /*
208          * We need to make sure we don't reuse the freed block until after the
209 @@ -6373,8 +6358,9 @@ do_more:
210                 goto do_more;
211         }
212  error_return:
213 -       brelse(bitmap_bh);
214         ext4_std_error(sb, err);
215 +error_brelse:
216 +       brelse(bitmap_bh);
217         return;
218  }
219  
220 @@ -6573,7 +6559,7 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
221  
222         err = ext4_mb_load_buddy(sb, block_group, &e4b);
223         if (err)
224 -               goto error_return;
225 +               goto error_brelse;
226  
227         /*
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,
230                 err = ret;
231  
232  error_return:
233 -       brelse(bitmap_bh);
234         ext4_std_error(sb, err);
235 +error_brelse:
236 +       brelse(bitmap_bh);
237         return err;
238  }
239  
240 @@ -6733,8 +6720,6 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
241  
242         ret = ext4_mb_load_buddy(sb, group, &e4b);
243         if (ret) {
244 -               ext4_warning(sb, "Error %d loading buddy information for %u",
245 -                            ret, group);
246                 return ret;
247         }
248  
249 -- 
250 2.25.1
251