Whamcloud - gitweb
LU-17504 build: fix gcc-13 [-Werror=stringop-overread] error
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / linux-5.8 / ext4-mballoc-pa-free-mismatch.patch
1 commit 2d3aaef4122c11dcb6d892da89522ffa37036136
2 Author:     Fan Yong <yong.fan@whamcloud.com>
3 AuthorDate: Thu Feb 25 00:32:12 2010 -0800
4 Subject: ext4: diagnostic patch to verify lustre read-only device mechanism
5
6 Diagnostic patch to check whether lustre read-only device mechanism works well or not.
7 Signed-off-by: Fan Yong <yong.fan@whamcloud.com>
8 Reviewed-by: Alex Zhuravlev <alex.zhuravlev@sun.com>
9 Reviewed-by: Rahul Deshmukh <rahul.deshmukh@sun.com>
10 ---
11  fs/ext4/mballoc.c |   43 +++++++++++++++++++++++++++++++++++++------
12  fs/ext4/mballoc.h |    2 ++
13  2 files changed, 39 insertions(+), 6 deletions(-)
14
15 --- a/fs/ext4/mballoc.c
16 +++ b/fs/ext4/mballoc.c
17 @@ -3992,6 +3992,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
18         INIT_LIST_HEAD(&pa->pa_group_list);
19         pa->pa_deleted = 0;
20         pa->pa_type = MB_INODE_PA;
21 +       pa->pa_error = 0;
22  
23         mb_debug(sb, "new inode pa %p: %llu/%d for %u\n", pa, pa->pa_pstart,
24                  pa->pa_len, pa->pa_lstart);
25 @@ -4046,6 +4047,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
26         INIT_LIST_HEAD(&pa->pa_group_list);
27         pa->pa_deleted = 0;
28         pa->pa_type = MB_GROUP_PA;
29 +       pa->pa_error = 0;
30  
31         mb_debug(sb, "new group pa %p: %llu/%d for %u\n", pa, pa->pa_pstart,
32                  pa->pa_len, pa->pa_lstart);
33 @@ -4098,7 +4100,9 @@ ext4_mb_release_inode_pa(struct ext4_bud
34         unsigned long long grp_blk_start;
35         int free = 0;
36  
37 +       assert_spin_locked(ext4_group_lock_ptr(sb, e4b->bd_group));
38         BUG_ON(pa->pa_deleted == 0);
39 +       BUG_ON(pa->pa_inode == NULL);
40         ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
41         grp_blk_start = pa->pa_pstart - EXT4_C2B(sbi, bit);
42         BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
43 @@ -4121,12 +4125,18 @@ ext4_mb_release_inode_pa(struct ext4_bud
44                 mb_free_blocks(pa->pa_inode, e4b, bit, next - bit);
45                 bit = next + 1;
46         }
47 -       if (free != pa->pa_free) {
48 -               ext4_msg(e4b->bd_sb, KERN_CRIT,
49 -                        "pa %p: logic %lu, phys. %lu, len %d",
50 -                        pa, (unsigned long) pa->pa_lstart,
51 -                        (unsigned long) pa->pa_pstart,
52 -                        pa->pa_len);
53 +
54 +       /* "free < pa->pa_free" means we maybe double alloc the same blocks,
55 +        * otherwise maybe leave some free blocks unavailable, no need to BUG.*/
56 +       if ((free > pa->pa_free && !pa->pa_error) || (free < pa->pa_free)) {
57 +               ext4_error(sb, "pa free mismatch: [pa %p] "
58 +                               "[phy %lu] [logic %lu] [len %u] [free %u] "
59 +                               "[error %u] [inode %d] [freed %u]", pa,
60 +                               (unsigned long)pa->pa_pstart,
61 +                               (unsigned long)pa->pa_lstart,
62 +                               pa->pa_len, (unsigned)pa->pa_free,
63 +                               (unsigned)pa->pa_error, pa->pa_inode->i_ino,
64 +                               free);
65                 ext4_grp_locked_error(sb, group, 0, 0, "free %u, pa_free %u",
66                                         free, pa->pa_free);
67                 /*
68 @@ -4134,6 +4144,8 @@ ext4_mb_release_inode_pa(struct ext4_bud
69                  * from the bitmap and continue.
70                  */
71         }
72 +       /* do not verify if the file system is being umounted */
73 +       BUG_ON(atomic_read(&sb->s_active) > 0 && pa->pa_free != free);
74         atomic_add(free, &sbi->s_mb_discarded);
75  
76         return 0;
77 @@ -4955,6 +4967,25 @@ errout:
78                 ac->ac_b_ex.fe_len = 0;
79                 ar->len = 0;
80                 ext4_mb_show_ac(ac);
81 +               if (ac->ac_pa) {
82 +                       struct ext4_prealloc_space *pa = ac->ac_pa;
83 +
84 +                       /* We can not make sure whether the bitmap has
85 +                        * been updated or not when fail case. So can
86 +                        * not revert pa_free back, just mark pa_error*/
87 +                       pa->pa_error++;
88 +                       ext4_error(sb,
89 +                               "Updating bitmap error: [err %d] "
90 +                               "[pa %p] [phy %lu] [logic %lu] "
91 +                               "[len %u] [free %u] [error %u] "
92 +                               "[inode %lu]", *errp, pa,
93 +                               (unsigned long)pa->pa_pstart,
94 +                               (unsigned long)pa->pa_lstart,
95 +                               (unsigned)pa->pa_len,
96 +                               (unsigned)pa->pa_free,
97 +                               (unsigned)pa->pa_error,
98 +                               pa->pa_inode ? pa->pa_inode->i_ino : 0);
99 +               }
100         }
101         ext4_mb_release_context(ac);
102  out:
103 --- a/fs/ext4/mballoc.h
104 +++ b/fs/ext4/mballoc.h
105 @@ -20,6 +20,7 @@
106  #include <linux/seq_file.h>
107  #include <linux/blkdev.h>
108  #include <linux/mutex.h>
109 +#include <linux/genhd.h>
110  #include "ext4_jbd2.h"
111  #include "ext4.h"
112  
113 @@ -107,6 +108,7 @@ struct ext4_prealloc_space {
114         ext4_grpblk_t           pa_len;         /* len of preallocated chunk */
115         ext4_grpblk_t           pa_free;        /* how many blocks are free */
116         unsigned short          pa_type;        /* pa type. inode or group */
117 +       unsigned short          pa_error;
118         spinlock_t              *pa_obj_lock;
119         struct inode            *pa_inode;      /* hack, for history only */
120  };