Skip to contentSkip to conversation

f2fs: adding truncate page cache after being moved

PATCH New Zhang Qilong via Linux-f2fs-devel 1 participant 1 message Sep 20, 2022 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 f2fs: adding truncate page cache after being moved

If we do not truncate source page cache, user can still see the previous source data after being moved. We fix it by adding truncating after __exchange_data_block.

Fixes 4dd6f977fc778 ("f2fs: support an ioctl to move a range of data blocks")

---
v2
- let invalidate lock covers __exchange_data_block()

---
 fs/f2fs/file.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/file.c +3 -0
index f79f649543d0..742d318078b5 100644
@@ -2818,6 +2818,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,
@@ -2829,7 +2830,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]);
Signature · 8 lines
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel