add patch fix-mmap-data-corruption-in-nodelalloc-mode-when-blocksize-lt-pagesize
[ext4-patch-queue.git] / fix-mmap-data-corruption-in-nodelalloc-mode-when-blocksize-lt-pagesize
blob66cf3f2ce1574f843fc828d1f4239648cf1dbdec
1 ext4: fix mmap data corruption in nodelalloc mode when blocksize < pagesize
3 From: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
5 Since commit 90a8020 and d6320cb, Jan Kara has fixed this issue partially.
6 This mmap data corruption still exists in nodelalloc mode, fix this.
8 Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
9 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 Reviewed-by:   Jan Kara <jack@suse.cz>
11 ---
12  fs/ext4/inode.c | 7 +++++++
13  1 file changed, 7 insertions(+)
15 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
16 index 9193ea1..0390e41 100644
17 --- a/fs/ext4/inode.c
18 +++ b/fs/ext4/inode.c
19 @@ -1007,6 +1007,7 @@ static int ext4_write_end(struct file *file,
20  {
21         handle_t *handle = ext4_journal_current_handle();
22         struct inode *inode = mapping->host;
23 +       loff_t old_size = inode->i_size;
24         int ret = 0, ret2;
25         int i_size_changed = 0;
27 @@ -1037,6 +1038,8 @@ static int ext4_write_end(struct file *file,
28         unlock_page(page);
29         page_cache_release(page);
31 +       if (old_size < pos)
32 +               pagecache_isize_extended(inode, old_size, pos);
33         /*
34          * Don't mark the inode dirty under page lock. First, it unnecessarily
35          * makes the holding time of page lock longer. Second, it forces lock
36 @@ -1078,6 +1081,7 @@ static int ext4_journalled_write_end(struct file *file,
37  {
38         handle_t *handle = ext4_journal_current_handle();
39         struct inode *inode = mapping->host;
40 +       loff_t old_size = inode->i_size;
41         int ret = 0, ret2;
42         int partial = 0;
43         unsigned from, to;
44 @@ -1110,6 +1114,9 @@ static int ext4_journalled_write_end(struct file *file,
45         unlock_page(page);
46         page_cache_release(page);
48 +       if (old_size < pos)
49 +               pagecache_isize_extended(inode, old_size, pos);
51         if (size_changed) {
52                 ret2 = ext4_mark_inode_dirty(handle, inode);
53                 if (!ret)
54 -- 
55 1.8.3.1