From patchwork Mon Feb 13 19:24:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: ext4: Issue cache flush on data partition when converting unwritten extents From: Jan Kara X-Patchwork-Id: 140961 Message-Id: <1329161053-31977-1-git-send-email-jack@suse.cz> To: Ted Tso Cc: linux-ext4@vger.kernel.org, jmoyer@redhat.com, Jan Kara Date: Mon, 13 Feb 2012 20:24:13 +0100 When we convert unwritten extents to normal extents (either after direct IO or buffered IO), we should make sure we don't expose uninitialized block contents after crash at least in data=ordered mode. Thus we have to make sure transaction commit issues a cache flush to filesystem partition before finishing transaction commit. Reported-by: Jeff Moyer Signed-off-by: Jan Kara --- fs/ext4/ext4_jbd2.h | 7 +++++++ fs/ext4/extents.c | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index 5802fa1..2901f7f 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h @@ -258,6 +258,13 @@ static inline void ext4_update_inode_fsync_trans(handle_t *handle, } } +static inline void ext4_mark_trans_data_flush(handle_t *handle) +{ + if (ext4_handle_valid(handle) && + !handle->h_transaction->t_need_data_flush) + handle->h_transaction->t_need_data_flush = 1; +} + /* super.c */ int ext4_force_commit(struct super_block *sb); diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 74f23c2..fb9535f 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3489,6 +3489,8 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, ext4_update_inode_fsync_trans(handle, inode, 1); err = check_eofblocks_fl(handle, inode, map->m_lblk, path, map->m_len); + if (!err && ext4_should_order_data(inode)) + ext4_mark_trans_data_flush(handle); } else err = ret; goto out2; @@ -3516,8 +3518,11 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, /* buffered write, writepage time, convert*/ ret = ext4_ext_convert_to_initialized(handle, inode, map, path); - if (ret >= 0) + if (ret >= 0) { ext4_update_inode_fsync_trans(handle, inode, 1); + if (ext4_should_order_data(inode)) + ext4_mark_trans_data_flush(handle); + } out: if (ret <= 0) { err = ret;