Whamcloud - gitweb
LU-13839 kernel: RHEL 8.3 server support
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / rhel8.3 / ext4-corrupted-inode-block-bitmaps-handling-patches.patch
1 Since we could skip corrupt block groups, this patch
2 use ext4_warning() intead of ext4_error() to make FS not
3 emount RO in default
4
5 Index: linux-4.18.0-80.1.2.el8_0/fs/ext4/balloc.c
6 ===================================================================
7 --- linux-4.18.0-80.1.2.el8_0.orig/fs/ext4/balloc.c
8 +++ linux-4.18.0-80.1.2.el8_0/fs/ext4/balloc.c
9 @@ -373,7 +373,7 @@ static int ext4_validate_block_bitmap(st
10         if (unlikely(!ext4_block_bitmap_csum_verify(sb, block_group,
11                         desc, bh))) {
12                 ext4_unlock_group(sb, block_group);
13 -               ext4_error(sb, "bg %u: bad block bitmap checksum", block_group);
14 +               ext4_warning(sb, "bg %u: bad block bitmap checksum", block_group);
15                 ext4_mark_group_bitmap_corrupted(sb, block_group,
16                                         EXT4_GROUP_INFO_BBITMAP_CORRUPT);
17                 return -EFSBADCRC;
18 @@ -381,8 +381,8 @@ static int ext4_validate_block_bitmap(st
19         blk = ext4_valid_block_bitmap(sb, desc, block_group, bh);
20         if (unlikely(blk != 0)) {
21                 ext4_unlock_group(sb, block_group);
22 -               ext4_error(sb, "bg %u: block %llu: invalid block bitmap",
23 -                          block_group, blk);
24 +               ext4_warning(sb, "bg %u: block %llu: invalid block bitmap",
25 +                            block_group, blk);
26                 ext4_mark_group_bitmap_corrupted(sb, block_group,
27                                         EXT4_GROUP_INFO_BBITMAP_CORRUPT);
28                 return -EFSCORRUPTED;
29 @@ -458,8 +458,8 @@ ext4_read_block_bitmap_nowait(struct sup
30                 ext4_unlock_group(sb, block_group);
31                 unlock_buffer(bh);
32                 if (err) {
33 -                       ext4_error(sb, "Failed to init block bitmap for group "
34 -                                  "%u: %d", block_group, err);
35 +                       ext4_warning(sb, "Failed to init block bitmap for group "
36 +                                    "%u: %d", block_group, err);
37                         goto out;
38                 }
39                 goto verify;
40 Index: linux-4.18.0-80.1.2.el8_0/fs/ext4/ialloc.c
41 ===================================================================
42 --- linux-4.18.0-80.1.2.el8_0.orig/fs/ext4/ialloc.c
43 +++ linux-4.18.0-80.1.2.el8_0/fs/ext4/ialloc.c
44 @@ -96,8 +96,8 @@ static int ext4_validate_inode_bitmap(st
45         if (!ext4_inode_bitmap_csum_verify(sb, block_group, desc, bh,
46                                            EXT4_INODES_PER_GROUP(sb) / 8)) {
47                 ext4_unlock_group(sb, block_group);
48 -               ext4_error(sb, "Corrupt inode bitmap - block_group = %u, "
49 -                          "inode_bitmap = %llu", block_group, blk);
50 +               ext4_warning(sb, "Corrupt inode bitmap - block_group = %u, "
51 +                            "inode_bitmap = %llu", block_group, blk);
52                 ext4_mark_group_bitmap_corrupted(sb, block_group,
53                                         EXT4_GROUP_INFO_IBITMAP_CORRUPT);
54                 return -EFSBADCRC;
55 @@ -346,7 +346,7 @@ out:
56                 if (!fatal)
57                         fatal = err;
58         } else {
59 -               ext4_error(sb, "bit already cleared for inode %lu", ino);
60 +               ext4_warning(sb, "bit already cleared for inode %lu", ino);
61                 ext4_mark_group_bitmap_corrupted(sb, block_group,
62                                         EXT4_GROUP_INFO_IBITMAP_CORRUPT);
63         }
64 Index: linux-4.18.0-240.1.1.el8/fs/ext4/mballoc.c
65 ===================================================================
66 --- linux-4.18.0-240.1.1.el8.orig/fs/ext4/mballoc.c
67 +++ linux-4.18.0-240.1.1.el8/fs/ext4/mballoc.c
68 @@ -741,10 +741,14 @@ int ext4_mb_generate_buddy(struct super_
69         grp->bb_fragments = fragments;
70  
71         if (free != grp->bb_free) {
72 -               ext4_grp_locked_error(sb, group, 0, 0,
73 -                                     "block bitmap and bg descriptor "
74 -                                     "inconsistent: %u vs %u free clusters",
75 -                                     free, grp->bb_free);
76 +               struct ext4_group_desc *gdp;
77 +               gdp = ext4_get_group_desc(sb, group, NULL);
78 +               ext4_warning(sb, "group %lu: block bitmap and bg descriptor "
79 +                            "inconsistent: %u vs %u free clusters "
80 +                            "%u in gd, %lu pa's",
81 +                            (long unsigned int)group, free, grp->bb_free,
82 +                            ext4_free_group_clusters(sb, gdp),
83 +                            grp->bb_prealloc_nr);
84                 /*
85                  * If we intend to continue, we consider group descriptor
86                  * corrupt and update bb_free using bitmap value
87 @@ -1107,7 +1111,7 @@ ext4_mb_load_buddy_gfp(struct super_bloc
88         int block;
89         int pnum;
90         int poff;
91 -       struct page *page;
92 +       struct page *page = NULL;
93         int ret;
94         struct ext4_group_info *grp;
95         struct ext4_sb_info *sbi = EXT4_SB(sb);
96 @@ -1133,7 +1137,7 @@ ext4_mb_load_buddy_gfp(struct super_bloc
97                  */
98                 ret = ext4_mb_init_group(sb, group, gfp);
99                 if (ret)
100 -                       return ret;
101 +                       goto err;
102         }
103  
104         /*
105 @@ -1236,6 +1240,7 @@ err:
106                 put_page(e4b->bd_buddy_page);
107         e4b->bd_buddy = NULL;
108         e4b->bd_bitmap = NULL;
109 +       ext4_warning(sb, "Error loading buddy information for %u", group);
110         return ret;
111  }
112  
113 @@ -3675,9 +3680,11 @@ int ext4_mb_check_ondisk_bitmap(struct s
114         }
115  
116         if (free != free_in_gdp) {
117 -               ext4_error(sb, "on-disk bitmap for group %d"
118 +               ext4_warning(sb, "on-disk bitmap for group %d"
119                         "corrupted: %u blocks free in bitmap, %u - in gd\n",
120                         group, free, free_in_gdp);
121 +               ext4_mark_group_bitmap_corrupted(sb, group,
122 +                                       EXT4_GROUP_INFO_BBITMAP_CORRUPT);
123                 return -EIO;
124         }
125         return 0;
126 @@ -4037,16 +4044,8 @@ ext4_mb_release_inode_pa(struct ext4_bud
127         /* "free < pa->pa_free" means we maybe double alloc the same blocks,
128          * otherwise maybe leave some free blocks unavailable, no need to BUG.*/
129         if ((free > pa->pa_free && !pa->pa_error) || (free < pa->pa_free)) {
130 -               ext4_error(sb, "pa free mismatch: [pa %p] "
131 -                               "[phy %lu] [logic %lu] [len %u] [free %u] "
132 -                               "[error %u] [inode %lu] [freed %u]", pa,
133 -                               (unsigned long)pa->pa_pstart,
134 -                               (unsigned long)pa->pa_lstart,
135 -                               (unsigned)pa->pa_len, (unsigned)pa->pa_free,
136 -                               (unsigned)pa->pa_error, pa->pa_inode->i_ino,
137 -                               free);
138                 ext4_grp_locked_error(sb, group, 0, 0, "free %u, pa_free %u",
139 -                                       free, pa->pa_free);
140 +                                     free, pa->pa_free);
141                 /*
142                  * pa is already deleted so we use the value obtained
143                  * from the bitmap and continue.
144 @@ -4108,16 +4107,11 @@ ext4_mb_discard_group_preallocations(str
145         bitmap_bh = ext4_read_block_bitmap(sb, group);
146         if (IS_ERR(bitmap_bh)) {
147                 err = PTR_ERR(bitmap_bh);
148 -               ext4_error_err(sb, -err,
149 -                              "Error %d reading block bitmap for %u",
150 -                              err, group);
151                 return 0;
152         }
153  
154         err = ext4_mb_load_buddy(sb, group, &e4b);
155         if (err) {
156 -               ext4_warning(sb, "Error %d loading buddy information for %u",
157 -                            err, group);
158                 put_bh(bitmap_bh);
159                 return 0;
160         }
161 @@ -4278,17 +4272,12 @@ repeat:
162  
163                 err = ext4_mb_load_buddy_gfp(sb, group, &e4b,
164                                              GFP_NOFS|__GFP_NOFAIL);
165 -               if (err) {
166 -                       ext4_error_err(sb, -err, "Error %d loading buddy information for %u",
167 -                                      err, group);
168 +               if (err)
169                         return;
170 -               }
171  
172                 bitmap_bh = ext4_read_block_bitmap(sb, group);
173                 if (IS_ERR(bitmap_bh)) {
174                         err = PTR_ERR(bitmap_bh);
175 -                       ext4_error_err(sb, -err, "Error %d reading block bitmap for %u",
176 -                                      err, group);
177                         ext4_mb_unload_buddy(&e4b);
178                         continue;
179                 }
180 @@ -4550,11 +4539,8 @@ ext4_mb_discard_lg_preallocations(struct
181                 group = ext4_get_group_number(sb, pa->pa_pstart);
182                 err = ext4_mb_load_buddy_gfp(sb, group, &e4b,
183                                              GFP_NOFS|__GFP_NOFAIL);
184 -               if (err) {
185 -                       ext4_error_err(sb, -err, "Error %d loading buddy information for %u",
186 -                                      err, group);
187 +               if (err)
188                         continue;
189 -               }
190                 ext4_lock_group(sb, group);
191                 list_del(&pa->pa_group_list);
192                 ext4_get_group_info(sb, group)->bb_prealloc_nr--;
193 @@ -4807,7 +4793,7 @@ errout:
194                          * been updated or not when fail case. So can
195                          * not revert pa_free back, just mark pa_error*/
196                         pa->pa_error++;
197 -                       ext4_error(sb,
198 +                       ext4_warning(sb,
199                                 "Updating bitmap error: [err %d] "
200                                 "[pa %p] [phy %lu] [logic %lu] "
201                                 "[len %u] [free %u] [error %u] "
202 @@ -4818,6 +4804,7 @@ errout:
203                                 (unsigned)pa->pa_free,
204                                 (unsigned)pa->pa_error,
205                                 pa->pa_inode ? pa->pa_inode->i_ino : 0);
206 +                       ext4_mark_group_bitmap_corrupted(sb, 0, 0);
207                 }
208         }
209         ext4_mb_release_context(ac);
210 @@ -5103,7 +5090,7 @@ do_more:
211         err = ext4_mb_load_buddy_gfp(sb, block_group, &e4b,
212                                      GFP_NOFS|__GFP_NOFAIL);
213         if (err)
214 -               goto error_return;
215 +               goto error_brelse;
216  
217         /*
218          * We need to make sure we don't reuse the freed block until after the
219 @@ -5194,8 +5181,9 @@ do_more:
220                 goto do_more;
221         }
222  error_return:
223 -       brelse(bitmap_bh);
224         ext4_std_error(sb, err);
225 +error_brelse:
226 +       brelse(bitmap_bh);
227         return;
228  }
229  
230 @@ -5295,7 +5283,7 @@ int ext4_group_add_blocks(handle_t *hand
231  
232         err = ext4_mb_load_buddy(sb, block_group, &e4b);
233         if (err)
234 -               goto error_return;
235 +               goto error_brelse;
236  
237         /*
238          * need to update group_info->bb_free and bitmap
239 @@ -5334,8 +5322,9 @@ int ext4_group_add_blocks(handle_t *hand
240                 err = ret;
241  
242  error_return:
243 -       brelse(bitmap_bh);
244         ext4_std_error(sb, err);
245 +error_brelse:
246 +       brelse(bitmap_bh);
247         return err;
248  }
249  
250 @@ -5410,11 +5399,8 @@ ext4_trim_all_free(struct super_block *s
251         trace_ext4_trim_all_free(sb, group, start, max);
252  
253         ret = ext4_mb_load_buddy(sb, group, &e4b);
254 -       if (ret) {
255 -               ext4_warning(sb, "Error %d loading buddy information for %u",
256 -                            ret, group);
257 +       if (ret)
258                 return ret;
259 -       }
260         bitmap = e4b.bd_bitmap;
261  
262         ext4_lock_group(sb, group);