1 From: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2 Date: Wed, 13 May 2009 22:36:58 +0000 (-0400)
3 Subject: ext4: Fix sub-block zeroing for writes into preallocated extents
5 Git-commit: 9c1ee184a30394e54165fa4c15923cabd952c106
8 ext4: Fix sub-block zeroing for writes into preallocated extents
10 We need to mark the buffer_head mapping preallocated space as new
11 during write_begin. Otherwise we don't zero out the page cache content
12 properly for a partial write. This will cause file corruption with
15 Now that we mark the buffer_head new we also need to have a valid
16 buffer_head blocknr so that unmap_underlying_metadata() unmaps the
19 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
20 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
21 Acked-by: Jeff Mahoney <jeffm@suse.com>
24 fs/ext4/extents.c | 2 ++
25 fs/ext4/inode.c | 7 +++++++
26 2 files changed, 9 insertions(+)
28 --- a/fs/ext4/extents.c
29 +++ b/fs/ext4/extents.c
30 @@ -2664,6 +2664,8 @@ int ext4_ext_get_blocks(handle_t *handle
31 if (allocated > max_blocks)
32 allocated = max_blocks;
33 set_buffer_unwritten(bh_result);
34 + bh_result->b_bdev = inode->i_sb->s_bdev;
35 + bh_result->b_blocknr = newblock;
41 @@ -2220,6 +2220,13 @@ static int ext4_da_get_block_prep(struct
42 set_buffer_delay(bh_result);
44 bh_result->b_size = (ret << inode->i_blkbits);
46 + * With sub-block writes into unwritten extents
47 + * we also need to mark the buffer as new so that
48 + * the unwritten parts of the buffer gets correctly zeroed.
50 + if (buffer_unwritten(bh_result))
51 + set_buffer_new(bh_result);