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