1 ext4: fix COLLAPSE_RANGE test failure in data journalling mode
3 From: Namjae Jeon <namjae.jeon@samsung.com>
5 When mounting ext4 with data=journal option, xfstest shared/002 and
6 shared/004 are currently failing as checksum computed for testfile
7 does not match with the checksum computed in other journal modes.
8 In case of data=journal mode, a call to filemap_write_and_wait_range
9 will not flush anything to disk as buffers are not marked dirty in
10 write_end. In collapse range this call is followed by a call to
11 truncate_pagecache_range. Due to this, when checksum is computed,
12 a portion of file is re-read from disk which replace valid data with
13 NULL bytes and hence the reason for the difference in checksum.
15 Calling ext4_force_commit before filemap_write_and_wait_range solves
16 the issue as it will mark the buffers dirty during commit transaction
17 which can be later synced by a call to filemap_write_and_wait_range.
19 Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
20 Signed-off-by: Ashish Sangwan <a.sangwan@samsung.com>
21 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
23 fs/ext4/extents.c | 7 +++++++
24 1 file changed, 7 insertions(+)
26 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
27 index 243a02e..dc9333f 100644
28 --- a/fs/ext4/extents.c
29 +++ b/fs/ext4/extents.c
30 @@ -5375,6 +5375,13 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
31 punch_start = offset >> EXT4_BLOCK_SIZE_BITS(sb);
32 punch_stop = (offset + len) >> EXT4_BLOCK_SIZE_BITS(sb);
34 + /* Call ext4_force_commit to flush all data in case of data=journal. */
35 + if (ext4_should_journal_data(inode)) {
36 + ret = ext4_force_commit(inode->i_sb);
41 /* Write out all dirty pages */
42 ret = filemap_write_and_wait_range(inode->i_mapping, offset, -1);