]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/patches/suse-2.6.27.31/patches.fixes/ext4-fix-sub-block-zeroing-for-preallocated-writes
Merge branch 'master' of git://git.ipfire.org/ipfire-2.x
[people/teissler/ipfire-2.x.git] / src / patches / suse-2.6.27.31 / patches.fixes / ext4-fix-sub-block-zeroing-for-preallocated-writes
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
4 Patch-mainline: 2.6.30
5 Git-commit: 9c1ee184a30394e54165fa4c15923cabd952c106
6 References: bnc#503161
7
8 ext4: Fix sub-block zeroing for writes into preallocated extents
9
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
13 preallocation.
14
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
17 correct block.
18
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>
22 ---
23
24 fs/ext4/extents.c | 2 ++
25 fs/ext4/inode.c | 7 +++++++
26 2 files changed, 9 insertions(+)
27
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;
36 goto out2;
37 }
38
39 --- a/fs/ext4/inode.c
40 +++ b/fs/ext4/inode.c
41 @@ -2220,6 +2220,13 @@ static int ext4_da_get_block_prep(struct
42 set_buffer_delay(bh_result);
43 } else if (ret > 0) {
44 bh_result->b_size = (ret << inode->i_blkbits);
45 + /*
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.
49 + */
50 + if (buffer_unwritten(bh_result))
51 + set_buffer_new(bh_result);
52 ret = 0;
53 }
54