1 Index: linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/mballoc.c
2 ===================================================================
3 --- linux-3.10.0-123.13.2.el7.x86_64.orig/fs/ext4/mballoc.c
4 +++ linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/mballoc.c
5 @@ -3747,6 +3747,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
6 INIT_LIST_HEAD(&pa->pa_group_list);
8 pa->pa_type = MB_INODE_PA;
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 @@ -3808,6 +3809,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
14 INIT_LIST_HEAD(&pa->pa_group_list);
16 pa->pa_type = MB_GROUP_PA;
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 @@ -3868,7 +3870,9 @@ ext4_mb_release_inode_pa(struct ext4_bud
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 - EXT4_C2B(sbi, bit);
30 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
31 @@ -3891,12 +3895,19 @@ ext4_mb_release_inode_pa(struct ext4_bud
32 mb_free_blocks(pa->pa_inode, e4b, bit, next - bit);
35 - if (free != pa->pa_free) {
36 - ext4_msg(e4b->bd_sb, KERN_CRIT,
37 - "pa %p: logic %lu, phys. %lu, len %lu",
38 - pa, (unsigned long) pa->pa_lstart,
39 - (unsigned long) pa->pa_pstart,
40 - (unsigned long) pa->pa_len);
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 + atomic_read(&sb->s_active) > 0) {
46 + ext4_error(sb, "pa free mismatch: [pa %p] "
47 + "[phy %lu] [logic %lu] [len %u] [free %u] "
48 + "[error %u] [inode %lu] [freed %u]", pa,
49 + (unsigned long)pa->pa_pstart,
50 + (unsigned long)pa->pa_lstart,
51 + (unsigned)pa->pa_len, (unsigned)pa->pa_free,
52 + (unsigned)pa->pa_error, pa->pa_inode->i_ino,
54 ext4_grp_locked_error(sb, group, 0, 0, "free %u, pa_free %u",
57 @@ -3904,6 +3914,8 @@ ext4_mb_release_inode_pa(struct ext4_bud
58 * from the bitmap and continue.
61 + /* do not verify if the file system is being umounted */
62 + BUG_ON(pa->pa_free != free && atomic_read(&sb->s_active) > 0);
63 atomic_add(free, &sbi->s_mb_discarded);
66 @@ -4661,6 +4673,25 @@ errout:
67 ac->ac_b_ex.fe_len = 0;
71 + struct ext4_prealloc_space *pa = ac->ac_pa;
73 + /* We can not make sure whether the bitmap has
74 + * been updated or not when fail case. So can
75 + * not revert pa_free back, just mark pa_error*/
78 + "Updating bitmap error: [err %d] "
79 + "[pa %p] [phy %lu] [logic %lu] "
80 + "[len %u] [free %u] [error %u] "
81 + "[inode %lu]", *errp, pa,
82 + (unsigned long)pa->pa_pstart,
83 + (unsigned long)pa->pa_lstart,
84 + (unsigned)pa->pa_len,
85 + (unsigned)pa->pa_free,
86 + (unsigned)pa->pa_error,
87 + pa->pa_inode ? pa->pa_inode->i_ino : 0);
90 ext4_mb_release_context(ac);
92 Index: linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/mballoc.h
93 ===================================================================
94 --- linux-3.10.0-123.13.2.el7.x86_64.orig/fs/ext4/mballoc.h
95 +++ linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/mballoc.h
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"
104 @@ -125,6 +126,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 */