From a095b17675c1dcb102bf4aa8a877231ab539c79c Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 29 May 2017 14:32:47 -0400 Subject: [PATCH] add patch fix-fdatasync-after-extent-manipulation-operations --- fix-fdatasync-after-extent-manipulation-operations | 66 ++++++++++++++++++++++ series | 1 + timestamps | 7 ++- 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 fix-fdatasync-after-extent-manipulation-operations diff --git a/fix-fdatasync-after-extent-manipulation-operations b/fix-fdatasync-after-extent-manipulation-operations new file mode 100644 index 00000000..2130df1a --- /dev/null +++ b/fix-fdatasync-after-extent-manipulation-operations @@ -0,0 +1,66 @@ +ext4: fix fdatasync(2) after extent manipulation operations + +From: Jan Kara + +Currently, extent manipulation operations such as hole punch, range +zeroing, or extent shifting do not record the fact that file data has +changed and thus fdatasync(2) has a work to do. As a result if we crash +e.g. after a punch hole and fdatasync, user can still possibly see the +punched out data after journal replay. Test generic/392 fails due to +these problems. + +Fix the problem by properly marking that file data has changed in these +operations. + +CC: stable@vger.kernel.org +Fixes: a4bb6b64e39abc0e41ca077725f2a72c868e7622 +Signed-off-by: Jan Kara +Signed-off-by: Theodore Ts'o +--- + fs/ext4/extents.c | 5 +++++ + fs/ext4/inode.c | 2 ++ + 2 files changed, 7 insertions(+) + +diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c +index 83a513efc824..3e36508610b7 100644 +--- a/fs/ext4/extents.c ++++ b/fs/ext4/extents.c +@@ -4877,6 +4877,8 @@ static long ext4_zero_range(struct file *file, loff_t offset, + + /* Zero out partial block at the edges of the range */ + ret = ext4_zero_partial_blocks(handle, inode, offset, len); ++ if (ret >= 0) ++ ext4_update_inode_fsync_trans(handle, inode, 1); + + if (file->f_flags & O_SYNC) + ext4_handle_sync(handle); +@@ -5563,6 +5565,7 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len) + ext4_handle_sync(handle); + inode->i_mtime = inode->i_ctime = current_time(inode); + ext4_mark_inode_dirty(handle, inode); ++ ext4_update_inode_fsync_trans(handle, inode, 1); + + out_stop: + ext4_journal_stop(handle); +@@ -5736,6 +5739,8 @@ int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len) + up_write(&EXT4_I(inode)->i_data_sem); + if (IS_SYNC(inode)) + ext4_handle_sync(handle); ++ if (ret >= 0) ++ ext4_update_inode_fsync_trans(handle, inode, 1); + + out_stop: + ext4_journal_stop(handle); +diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c +index 14539ce38034..9475cb3cc5fc 100644 +--- a/fs/ext4/inode.c ++++ b/fs/ext4/inode.c +@@ -4221,6 +4221,8 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length) + + inode->i_mtime = inode->i_ctime = current_time(inode); + ext4_mark_inode_dirty(handle, inode); ++ if (ret >= 0) ++ ext4_update_inode_fsync_trans(handle, inode, 1); + out_stop: + ext4_journal_stop(handle); + out_dio: diff --git a/series b/series index fbca3663..4ee320f2 100644 --- a/series +++ b/series @@ -16,6 +16,7 @@ fix-quota-charging-for-shared-xattr-blocks fix-data-corruption-with-EXT4_GET_BLOCKS_ZERO fix-data-corruption-for-mmap-writes +fix-fdatasync-after-extent-manipulation-operations # Dropped due to regressions # add-largedir-feature diff --git a/timestamps b/timestamps index e1b30016..d967b514 100755 --- a/timestamps +++ b/timestamps @@ -44,7 +44,8 @@ touch -d @1495663909 stable-boundary touch -d @1495664431 remove-redundant-check-for-encrypted-file-on-dio-write-path touch -d @1495664647 fix-quota-charging-for-shared-xattr-blocks touch -d @1495834852 fix-data-corruption-with-EXT4_GET_BLOCKS_ZERO -touch -d @1495834934 status touch -d @1495835145 fix-data-corruption-for-mmap-writes -touch -d @1495835189 series -touch -d @1495835193 timestamps +touch -d @1496078695 fix-fdatasync-after-extent-manipulation-operations +touch -d @1496081597 status +touch -d @1496082752 series +touch -d @1496082758 timestamps -- 2.11.4.GIT