Whamcloud - gitweb
LU-2748 fsfilt: ext4_map_inode_page in osd and ldisk out of sync
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / sles11sp2 / ext4-mballoc-pa_free-mismatch.patch
1 diff -r -u linux-stage.orig/fs/ext4/mballoc.c linux-stage/fs/ext4/mballoc.c
2 --- linux-stage.orig/fs/ext4/mballoc.c  2012-12-31 15:18:15.000000000 -0500
3 +++ linux-stage/fs/ext4/mballoc.c       2012-12-31 15:23:38.000000000 -0500
4 @@ -3643,6 +3643,7 @@
5         INIT_LIST_HEAD(&pa->pa_group_list);
6         pa->pa_deleted = 0;
7         pa->pa_type = MB_INODE_PA;
8 +       pa->pa_error = 0;
9
10         mb_debug(1, "new inode pa %p: %llu/%u for %u\n", pa,
11                         pa->pa_pstart, pa->pa_len, pa->pa_lstart);
12 @@ -3704,6 +3705,7 @@
13         INIT_LIST_HEAD(&pa->pa_group_list);
14         pa->pa_deleted = 0;
15         pa->pa_type = MB_GROUP_PA;
16 +       pa->pa_error = 0;
17
18         mb_debug(1, "new group pa %p: %llu/%u for %u\n", pa,
19                         pa->pa_pstart, pa->pa_len, pa->pa_lstart);
20 @@ -3764,7 +3766,9 @@
21         int err = 0;
22         int free = 0;
23
24 +       assert_spin_locked(ext4_group_lock_ptr(sb, e4b->bd_group));
25         BUG_ON(pa->pa_deleted == 0);
26 +       BUG_ON(pa->pa_inode == NULL);
27         ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
28         grp_blk_start = pa->pa_pstart - bit;
29         BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
30 @@ -3786,19 +3790,27 @@
31                 mb_free_blocks(pa->pa_inode, e4b, bit, next - bit);
32                 bit = next + 1;
33         }
34 -       if (free != pa->pa_free) {
35 -               ext4_msg(e4b->bd_sb, KERN_CRIT,
36 -                        "pa %p: logic %lu, phys. %lu, len %lu",
37 -                        pa, (unsigned long) pa->pa_lstart,
38 -                        (unsigned long) pa->pa_pstart,
39 -                        (unsigned long) pa->pa_len);
40 -               ext4_grp_locked_error(sb, group, 0, 0, "free %u, pa_free %u",
41 +
42 +       /* "free < pa->pa_free" means we maybe double alloc the same blocks,
43 +        * otherwise maybe leave some free blocks unavailable, no need to BUG.*/
44 +       if ((free > pa->pa_free && !pa->pa_error) || (free < pa->pa_free)) {
45 +               ext4_error(sb, "pa free mismatch: [pa %p] "
46 +                               "[phy %lu] [logic %lu] [len %u] [free %u] "
47 +                               "[error %u] [inode %lu] [freed %u]", pa,
48 +                               (unsigned long)pa->pa_pstart,
49 +                               (unsigned long)pa->pa_lstart,
50 +                               (unsigned)pa->pa_len, (unsigned)pa->pa_free,
51 +                               (unsigned)pa->pa_error, pa->pa_inode->i_ino,
52 +                               free);
53 +               ext4_grp_locked_error(sb, group, 0, 0,
54 +                                       "free %u, pa_free %u",
55                                         free, pa->pa_free);
56                 /*
57                  * pa is already deleted so we use the value obtained
58                  * from the bitmap and continue.
59                  */
60         }
61 +       BUG_ON(pa->pa_free != free);
62         atomic_add(free, &sbi->s_mb_discarded);
63
64         return err;
65 @@ -4542,6 +4555,25 @@
66                 ac->ac_b_ex.fe_len = 0;
67                 ar->len = 0;
68                 ext4_mb_show_ac(ac);
69 +               if (ac->ac_pa) {
70 +                       struct ext4_prealloc_space *pa = ac->ac_pa;
71 +
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 diff -r -u linux-stage.orig/fs/ext4/mballoc.h linux-stage/fs/ext4/mballoc.h
92 --- linux-stage.orig/fs/ext4/mballoc.h  2012-12-31 15:18:15.000000000 -0500
93 +++ linux-stage/fs/ext4/mballoc.h       2012-12-31 15:19:22.000000000 -0500
94 @@ -19,6 +19,7 @@
95  #include <linux/seq_file.h>
96  #include <linux/blkdev.h>
97  #include <linux/mutex.h>
98 +#include <linux/genhd.h>
99  #include "ext4_jbd2.h"
100  #include "ext4.h"
101
102 @@ -129,6 +130,7 @@
103         ext4_grpblk_t           pa_free;        /* how many blocks are free */
104         unsigned short          pa_type;        /* pa type. inode or group */
105         spinlock_t              *pa_obj_lock;
106 +       unsigned short          pa_error;
107         struct inode            *pa_inode;      /* hack, for history only */
108  };
109