1 Index: linux-stage/fs/ext4/mballoc.c
2 ===================================================================
3 --- linux-stage.orig/fs/ext4/mballoc.c 2011-03-14 16:34:39.790758415 +0800
4 +++ linux-stage/fs/ext4/mballoc.c 2011-03-14 16:38:36.211681104 +0800
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);
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);
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 @@ -3752,19 +3756,27 @@
32 mb_free_blocks(pa->pa_inode, e4b, bit, next - bit);
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);
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,
52 ext4_grp_locked_error(sb, group,
53 - __func__, "free %u, pa_free %u",
55 + __func__, "free %u, pa_free %u",
58 * pa is already deleted so we use the value obtained
59 * from the bitmap and continue.
62 + BUG_ON(pa->pa_free != free);
63 atomic_add(free, &sbi->s_mb_discarded);
66 @@ -4450,6 +4462,24 @@
68 trace_ext4_request_blocks(ar);
71 + if (dev_check_rdonly(sb->s_bdev)) {
72 + struct block_device *bdev = sb->s_bdev;
74 + printk(KERN_WARNING "Alloc from readonly device %s (%#x): "
75 + "[inode %lu] [logic %llu] [goal %llu] [ll %llu] "
76 + "[pl %llu] [lr %llu] [pr %llu] [len %u] [flags %u]\n",
77 + bdev->bd_disk ? bdev->bd_disk->disk_name : "",
78 + bdev->bd_dev, ar->inode->i_ino,
79 + (unsigned long long)ar->logical,
80 + (unsigned long long)ar->goal,
81 + (unsigned long long)ar->lleft,
82 + (unsigned long long)ar->pleft,
83 + (unsigned long long)ar->lright,
84 + (unsigned long long)ar->pright,
85 + ar->len, ar->flags);
89 * For delayed allocation, we could skip the ENOSPC and
90 * EDQUOT check, as blocks and quotas have been already
91 @@ -4529,6 +4559,25 @@
92 ac->ac_b_ex.fe_len = 0;
96 + struct ext4_prealloc_space *pa = ac->ac_pa;
98 + /* We can not make sure whether the bitmap has
99 + * been updated or not when fail case. So can
100 + * not revert pa_free back, just mark pa_error*/
103 + "Updating bitmap error: [err %d] "
104 + "[pa %p] [phy %lu] [logic %lu] "
105 + "[len %u] [free %u] [error %u] "
106 + "[inode %lu]", *errp, pa,
107 + (unsigned long)pa->pa_pstart,
108 + (unsigned long)pa->pa_lstart,
109 + (unsigned)pa->pa_len,
110 + (unsigned)pa->pa_free,
111 + (unsigned)pa->pa_error,
112 + pa->pa_inode ? pa->pa_inode->i_ino : 0);
115 block = ext4_grp_offs_to_block(sb, &ac->ac_b_ex);
116 ar->len = ac->ac_b_ex.fe_len;
117 @@ -4691,6 +4740,15 @@
121 + if (dev_check_rdonly(sb->s_bdev)) {
122 + struct block_device *bdev = sb->s_bdev;
124 + printk(KERN_WARNING "Release to readonly device %s (%#x): "
125 + "[inode %lu] [block %llu] [count %lu] [is_meta %d]\n",
126 + bdev->bd_disk ? bdev->bd_disk->disk_name : "",
127 + bdev->bd_dev, inode->i_ino, block, count, metadata);
130 ext4_debug("freeing block %llu\n", block);
131 trace_ext4_free_blocks(inode, block, count, metadata);
133 Index: linux-stage/fs/ext4/mballoc.h
134 ===================================================================
135 --- linux-stage.orig/fs/ext4/mballoc.h 2011-03-14 16:32:50.859552482 +0800
136 +++ linux-stage/fs/ext4/mballoc.h 2011-03-14 16:39:20.928429776 +0800
138 #include <linux/version.h>
139 #include <linux/blkdev.h>
140 #include <linux/mutex.h>
141 +#include <linux/genhd.h>
142 #include "ext4_jbd2.h"
146 ext4_grpblk_t pa_free; /* how many blocks are free */
147 unsigned short pa_type; /* pa type. inode or group */
148 spinlock_t *pa_obj_lock;
149 + unsigned short pa_error;
150 struct inode *pa_inode; /* hack, for history only */