1 From 436e2704a8b589fb1217add4f9e5be480773ca6c Mon Sep 17 00:00:00 2001
2 From: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
3 Date: Sun, 30 May 2010 22:49:20 -0400
4 Subject: ext4: Ensure zeroout blocks have no dirty metadata
6 commit 515f41c33a9d44a964264c9511ad2c869af1fac3 upstream (as of v2.6.33-rc3)
8 This fixes a bug (found by Curt Wohlgemuth) in which new blocks
9 returned from an extent created with ext4_ext_zeroout() can have dirty
10 metadata still associated with them.
12 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
13 Signed-off-by: Curt Wohlgemuth <curtw@google.com>
14 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
15 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
17 fs/ext4/extents.c | 20 ++++++++++++++++++++
18 1 file changed, 20 insertions(+)
20 --- a/fs/ext4/extents.c
21 +++ b/fs/ext4/extents.c
22 @@ -3029,6 +3029,14 @@ out:
26 +static void unmap_underlying_metadata_blocks(struct block_device *bdev,
27 + sector_t block, int count)
30 + for (i = 0; i < count; i++)
31 + unmap_underlying_metadata(bdev, block + i);
35 ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode,
36 ext4_lblk_t iblock, unsigned int max_blocks,
37 @@ -3104,6 +3112,18 @@ out:
40 set_buffer_new(bh_result);
42 + * if we allocated more blocks than requested
43 + * we need to make sure we unmap the extra block
44 + * allocated. The actual needed block will get
45 + * unmapped later when we find the buffer_head marked
48 + if (allocated > max_blocks) {
49 + unmap_underlying_metadata_blocks(inode->i_sb->s_bdev,
50 + newblock + max_blocks,
51 + allocated - max_blocks);
54 set_buffer_mapped(bh_result);