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