Whamcloud - gitweb
LU-9510 ldiskfs: to not verify preallocation in umount path
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / rhel8 / 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-80.1.2.el8_0/fs/ext4/mballoc.c
65 ===================================================================
66 --- linux-4.18.0-80.1.2.el8_0.orig/fs/ext4/mballoc.c
67 +++ linux-4.18.0-80.1.2.el8_0/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 @@ -3654,9 +3659,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 @@ -4016,16 +4023,8 @@ ext4_mb_release_inode_pa(struct ext4_bud
127          * otherwise maybe leave some free blocks unavailable, no need to BUG.*/
128         if (((free > pa->pa_free && !pa->pa_error) || (free < pa->pa_free)) &&
129             atomic_read(&sb->s_active) > 0) {
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 @@ -4087,15 +4086,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(sb, "Error %d reading block bitmap for %u",
149 -                          err, group);
150                 return 0;
151         }
152  
153         err = ext4_mb_load_buddy(sb, group, &e4b);
154         if (err) {
155 -               ext4_warning(sb, "Error %d loading buddy information for %u",
156 -                            err, group);
157                 put_bh(bitmap_bh);
158                 return 0;
159         }
160 @@ -4256,17 +4251,12 @@ repeat:
161  
162                 err = ext4_mb_load_buddy_gfp(sb, group, &e4b,
163                                              GFP_NOFS|__GFP_NOFAIL);
164 -               if (err) {
165 -                       ext4_error(sb, "Error %d loading buddy information for %u",
166 -                                  err, group);
167 +               if (err)
168                         return;
169 -               }
170  
171                 bitmap_bh = ext4_read_block_bitmap(sb, group);
172                 if (IS_ERR(bitmap_bh)) {
173                         err = PTR_ERR(bitmap_bh);
174 -                       ext4_error(sb, "Error %d reading block bitmap for %u",
175 -                                       err, group);
176                         ext4_mb_unload_buddy(&e4b);
177                         continue;
178                 }
179 @@ -4529,11 +4519,8 @@ ext4_mb_discard_lg_preallocations(struct
180                 group = ext4_get_group_number(sb, pa->pa_pstart);
181                 err = ext4_mb_load_buddy_gfp(sb, group, &e4b,
182                                              GFP_NOFS|__GFP_NOFAIL);
183 -               if (err) {
184 -                       ext4_error(sb, "Error %d loading buddy information for %u",
185 -                                  err, group);
186 +               if (err)
187                         continue;
188 -               }
189                 ext4_lock_group(sb, group);
190                 list_del(&pa->pa_group_list);
191                 ext4_get_group_info(sb, group)->bb_prealloc_nr--;
192 @@ -4786,7 +4773,7 @@ errout:
193                          * been updated or not when fail case. So can
194                          * not revert pa_free back, just mark pa_error*/
195                         pa->pa_error++;
196 -                       ext4_error(sb,
197 +                       ext4_warning(sb,
198                                 "Updating bitmap error: [err %d] "
199                                 "[pa %p] [phy %lu] [logic %lu] "
200                                 "[len %u] [free %u] [error %u] "
201 @@ -4797,6 +4784,7 @@ errout:
202                                 (unsigned)pa->pa_free,
203                                 (unsigned)pa->pa_error,
204                                 pa->pa_inode ? pa->pa_inode->i_ino : 0);
205 +                       ext4_mark_group_bitmap_corrupted(sb, 0, 0);
206                 }
207         }
208         ext4_mb_release_context(ac);
209 @@ -5082,7 +5070,7 @@ do_more:
210         err = ext4_mb_load_buddy_gfp(sb, block_group, &e4b,
211                                      GFP_NOFS|__GFP_NOFAIL);
212         if (err)
213 -               goto error_return;
214 +               goto error_brelse;
215  
216         /*
217          * We need to make sure we don't reuse the freed block until after the
218 @@ -5164,8 +5152,9 @@ do_more:
219                 goto do_more;
220         }
221  error_return:
222 -       brelse(bitmap_bh);
223         ext4_std_error(sb, err);
224 +error_brelse:
225 +       brelse(bitmap_bh);
226         return;
227  }
228  
229 @@ -5265,7 +5254,7 @@ int ext4_group_add_blocks(handle_t *hand
230  
231         err = ext4_mb_load_buddy(sb, block_group, &e4b);
232         if (err)
233 -               goto error_return;
234 +               goto error_brelse;
235  
236         /*
237          * need to update group_info->bb_free and bitmap
238 @@ -5303,8 +5292,9 @@ int ext4_group_add_blocks(handle_t *hand
239                 err = ret;
240  
241  error_return:
242 -       brelse(bitmap_bh);
243         ext4_std_error(sb, err);
244 +error_brelse:
245 +       brelse(bitmap_bh);
246         return err;
247  }
248  
249 @@ -5379,11 +5369,8 @@ ext4_trim_all_free(struct super_block *s
250         trace_ext4_trim_all_free(sb, group, start, max);
251  
252         ret = ext4_mb_load_buddy(sb, group, &e4b);
253 -       if (ret) {
254 -               ext4_warning(sb, "Error %d loading buddy information for %u",
255 -                            ret, group);
256 +       if (ret)
257                 return ret;
258 -       }
259         bitmap = e4b.bd_bitmap;
260  
261         ext4_lock_group(sb, group);