1 ext4: fix fdatasync(2) after extent manipulation operations
3 From: Jan Kara <jack@suse.cz>
5 Currently, extent manipulation operations such as hole punch, range
6 zeroing, or extent shifting do not record the fact that file data has
7 changed and thus fdatasync(2) has a work to do. As a result if we crash
8 e.g. after a punch hole and fdatasync, user can still possibly see the
9 punched out data after journal replay. Test generic/392 fails due to
12 Fix the problem by properly marking that file data has changed in these
15 CC: stable@vger.kernel.org
16 Fixes: a4bb6b64e39abc0e41ca077725f2a72c868e7622
17 Signed-off-by: Jan Kara <jack@suse.cz>
18 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 fs/ext4/extents.c | 5 +++++
21 fs/ext4/inode.c | 2 ++
22 2 files changed, 7 insertions(+)
24 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
25 index 83a513efc824..3e36508610b7 100644
26 --- a/fs/ext4/extents.c
27 +++ b/fs/ext4/extents.c
28 @@ -4877,6 +4877,8 @@ static long ext4_zero_range(struct file *file, loff_t offset,
30 /* Zero out partial block at the edges of the range */
31 ret = ext4_zero_partial_blocks(handle, inode, offset, len);
33 + ext4_update_inode_fsync_trans(handle, inode, 1);
35 if (file->f_flags & O_SYNC)
36 ext4_handle_sync(handle);
37 @@ -5563,6 +5565,7 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
38 ext4_handle_sync(handle);
39 inode->i_mtime = inode->i_ctime = current_time(inode);
40 ext4_mark_inode_dirty(handle, inode);
41 + ext4_update_inode_fsync_trans(handle, inode, 1);
44 ext4_journal_stop(handle);
45 @@ -5736,6 +5739,8 @@ int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len)
46 up_write(&EXT4_I(inode)->i_data_sem);
48 ext4_handle_sync(handle);
50 + ext4_update_inode_fsync_trans(handle, inode, 1);
53 ext4_journal_stop(handle);
54 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
55 index 14539ce38034..9475cb3cc5fc 100644
58 @@ -4221,6 +4221,8 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
60 inode->i_mtime = inode->i_ctime = current_time(inode);
61 ext4_mark_inode_dirty(handle, inode);
63 + ext4_update_inode_fsync_trans(handle, inode, 1);
65 ext4_journal_stop(handle);