linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs: Fix data consistency in f2fs_move_file_range()
@ 2022-10-18  2:45 Zhang Qilong via Linux-f2fs-devel
  2022-10-18  2:45 ` [f2fs-dev] [PATCH] f2fs: Fix the race condition of resize flag between resizefs Zhang Qilong via Linux-f2fs-devel
  2022-10-20  1:29 ` [f2fs-dev] [PATCH] f2fs: Fix data consistency in f2fs_move_file_range() Chao Yu
  0 siblings, 2 replies; 12+ messages in thread
From: Zhang Qilong via Linux-f2fs-devel @ 2022-10-18  2:45 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel

In the following case:
process 1			process 2
 ->open A
  ->mmap
   ->read # the first time
   				 ->ioctl w/h F2FS_IOC_MOVE_RANGE
				        	# (range A->B)
   ->read # the second time

We will read old data at the second time. The root cause is that
user still can see the previous source data after being moved. We
fix it by adding truncating after __exchange_data_block.

Fixes: 4dd6f977fc77 ("f2fs: support an ioctl to move a range of data blocks")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
v2:
- moving truncating to the range of f2fs_lock_op()

v3:
- modify the title and commit message
---
 fs/f2fs/file.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 82cda1258227..e9dfa41baf9e 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2824,6 +2824,7 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
 			goto out_src;
 	}
 
+	filemap_invalidate_lock(src->i_mapping);
 	f2fs_lock_op(sbi);
 	ret = __exchange_data_block(src, dst, pos_in >> F2FS_BLKSIZE_BITS,
 				pos_out >> F2FS_BLKSIZE_BITS,
@@ -2835,7 +2836,9 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
 		else if (dst_osize != dst->i_size)
 			f2fs_i_size_write(dst, dst_osize);
 	}
+	truncate_pagecache_range(src, pos_in, pos_in + len - 1);
 	f2fs_unlock_op(sbi);
+	filemap_invalidate_unlock(src->i_mapping);
 
 	if (src != dst)
 		f2fs_up_write(&F2FS_I(dst)->i_gc_rwsem[WRITE]);
-- 
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-10-25  7:54 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-18  2:45 [f2fs-dev] [PATCH] f2fs: Fix data consistency in f2fs_move_file_range() Zhang Qilong via Linux-f2fs-devel
2022-10-18  2:45 ` [f2fs-dev] [PATCH] f2fs: Fix the race condition of resize flag between resizefs Zhang Qilong via Linux-f2fs-devel
2022-10-20  1:19   ` Chao Yu
2022-10-20  1:29 ` [f2fs-dev] [PATCH] f2fs: Fix data consistency in f2fs_move_file_range() Chao Yu
2022-10-20  7:27   ` [f2fs-dev] 答复: " zhangqilong via Linux-f2fs-devel
2022-10-25  1:17     ` Chao Yu
2022-10-25  6:27       ` [f2fs-dev] 答复: " zhangqilong via Linux-f2fs-devel
2022-10-25  6:41         ` Chao Yu
2022-10-25  7:01           ` [f2fs-dev] 答复: " zhangqilong via Linux-f2fs-devel
2022-10-25  7:20             ` Chao Yu
2022-10-25  7:36               ` [f2fs-dev] 答复: " zhangqilong via Linux-f2fs-devel
2022-10-25  7:54                 ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).