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
5 INIT_LIST_HEAD(&pa->pa_group_list);
7 pa->pa_type = MB_INODE_PA;
10 mb_debug(1, "new inode pa %p: %llu/%u for %u\n", pa,
11 pa->pa_pstart, pa->pa_len, pa->pa_lstart);
13 INIT_LIST_HEAD(&pa->pa_group_list);
15 pa->pa_type = MB_GROUP_PA;
18 mb_debug(1, "new group pa %p: %llu/%u for %u\n", pa,
19 pa->pa_pstart, pa->pa_len, pa->pa_lstart);
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);
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",
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,
53 + ext4_grp_locked_error(sb, group, 0, 0,
54 + "free %u, pa_free %u",
57 * pa is already deleted so we use the value obtained
58 * from the bitmap and continue.
61 + BUG_ON(pa->pa_free != free);
62 atomic_add(free, &sbi->s_mb_discarded);
65 @@ -4542,6 +4555,25 @@
66 ac->ac_b_ex.fe_len = 0;
70 + 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*/
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);
89 ext4_mb_release_context(ac);
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
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"
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 */