[PATCH] ext4: Issue cache flush on data partition when converting unwritten extents

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <jmoyer@xxxxxxxxxx>
Signed-off-by: Jan Kara <jack@xxxxxxx>
---
 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;
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux