Skip to contentSkip to conversation

f2fs: fix to call invalidate_mapping_pages in f2fs_move_file_range

PATCH In review Yangtao Li 2 participants 2 messages May 4, 2023 – May 5, 2023 F2FS file system

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH 1/1 f2fs: fix to call invalidate_mapping_pages in f2fs_move_file_range

In the following scenario, after executing the move_range ioctl syscall, the block size of the source file is 0, but data can still be read.

  # stat test
  File: test
  Size: 6               Blocks: 8          IO Block: 4096   regular file
  # ./new_f2fs_io move_range test test_move_range 0 0 0
  move range ret=0
  # stat test
  File: test
  Size: 6               Blocks: 0          IO Block: 4096   regular file
  # cat test
  nihao

Let's fix to call invalidate_mapping_pages() after __exchange_data_block() success.

Fixes 4dd6f977fc77 ("f2fs: support an ioctl to move a range of data blocks")
---
 fs/f2fs/file.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/file.c +3 -0
index 78aa8cff4b41..ae7752c5cd0a 100644
@@ -2870,6 +2870,9 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
 			f2fs_i_size_write(dst, dst_max_i_size);
 		else if (dst_osize != dst->i_size)
 			f2fs_i_size_write(dst, dst_osize);
+
+		invalidate_mapping_pages(src->i_mapping,
+				pos_out, pos_in + len);
 	}
 	f2fs_unlock_op(sbi);
 
Signature · 8 lines
2.39.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
maintainer
#1 lore raw
Quoted 28 lines · Yangtao Li

In the following scenario, after executing the move_range ioctl syscall, the block size of the source file is 0, but data can still be read.

   # stat test
   File: test
   Size: 6               Blocks: 8          IO Block: 4096   regular file
   # ./new_f2fs_io move_range test test_move_range 0 0 0
   move range ret=0
   # stat test
   File: test
   Size: 6               Blocks: 0          IO Block: 4096   regular file
   # cat test
   nihao

Let's fix to call invalidate_mapping_pages() after __exchange_data_block() success.

Fixes 4dd6f977fc77 ("f2fs: support an ioctl to move a range of data blocks")
---
  fs/f2fs/file.c | 3 +++
  1 file changed, 3 insertions(+)
fs/f2fs/file.c +0 -0
index 78aa8cff4b41..ae7752c5cd0a 100644

fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, · line 2875

Quoted 6 lines
fs/f2fs/file.c +3 -0
@@ -2870,6 +2870,9 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
  			f2fs_i_size_write(dst, dst_max_i_size);
  		else if (dst_osize != dst->i_size)
  			f2fs_i_size_write(dst, dst_osize);
+
+		invalidate_mapping_pages(src->i_mapping,
+				pos_out, pos_in + len);

It needs to consider error cases?

Should we call this to drop page cache of src_inode after __clone_blkaddrs() for each round exchange in __exchange_data_block()? and also drop page cache of dst_indoe in roll_back case?

Thanks,

Quoted 3 lines
fs/f2fs/file.c +0 -0
  	}
  	f2fs_unlock_op(sbi);