Skip to contentSkip to conversation

f2fs: adding truncate page cache after being moved

PATCH Superseded Zhang Qilong via Linux-f2fs-devel 2 participants 8 messages Sep 13, 2022 – Sep 20, 2022 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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")
---
 fs/f2fs/file.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/f2fs/file.c +4 -0
index 771f1f7f3690..e3ff648aa496 100644
@@ -2789,6 +2789,10 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
 	}
 	f2fs_unlock_op(sbi);
 
+	filemap_invalidate_lock(src->i_mapping);
+	truncate_pagecache_range(src, pos_in, pos_in + len - 1);
+	filemap_invalidate_unlock(src->i_mapping);
+
 	if (src != dst)
 		f2fs_up_write(&F2FS_I(dst)->i_gc_rwsem[WRITE]);
 out_src:
Signature · 8 lines
2.25.1



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

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")
---
  fs/f2fs/file.c | 4 ++++
  1 file changed, 4 insertions(+)
fs/f2fs/file.c +0 -0
index 771f1f7f3690..e3ff648aa496 100644

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

Quoted 4 lines
fs/f2fs/file.c +1 -0
@@ -2789,6 +2789,10 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
  	}
  	f2fs_unlock_op(sbi);
 
+	filemap_invalidate_lock(src->i_mapping);

invalidate lock should cover __exchange_data_block()?

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

Quoted 1 line
fs/f2fs/file.c +1 -0
+	truncate_pagecache_range(src, pos_in, pos_in + len - 1);

truncate_pagecache_range() should be called before __exchange_data_block()?

Thanks,

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

Quoted 5 lines
fs/f2fs/file.c +2 -0
+	filemap_invalidate_unlock(src->i_mapping);
+
  	if (src != dst)
  		f2fs_up_write(&F2FS_I(dst)->i_gc_rwsem[WRITE]);
  out_src:

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

#2 lore raw
Quoted 21 lines · Zhang Qilong

fs/f2fs/file.c static int f2fs_move_file_range(struct file

Quoted 16 lines

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")

---
  fs/f2fs/file.c | 4 ++++
  1 file changed, 4 insertions(+)
fs/f2fs/file.c index renamed from fs/f2fs/file.c +0 -0

771f1f7f3690..e3ff648aa496 100644

fs/f2fs/file.c +0 -0
@@ -2789,6 +2789,10 @@ static int f2fs_move_file_range(struct file

*file_in, loff_t pos_in,

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

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

Quoted 1 line
fs/f2fs/file.c +1 -0
+	filemap_invalidate_lock(src->i_mapping);

invalidate lock should cover __exchange_data_block()?

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

Quoted 1 line
fs/f2fs/file.c +1 -0
+	truncate_pagecache_range(src, pos_in, pos_in + len - 1);

truncate_pagecache_range() should be called before __exchange_data_block()?

I have tried it, but it do not work. So I move the truncate operation to the back of __exchange_data_block that it works well. I don't know much enough, what do you think of this issue.

Thanks,

Quoted 8 lines

Thanks,

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

Quoted 5 lines
fs/f2fs/file.c +2 -0
+	filemap_invalidate_unlock(src->i_mapping);
+
  	if (src != dst)
  		f2fs_up_write(&F2FS_I(dst)->i_gc_rwsem[WRITE]);
  out_src:

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

maintainer
#3 lore raw
Quoted 25 lines · zhangqilong
Quoted 25 lines · Zhang Qilong

fs/f2fs/file.c static int f2fs_move_file_range(struct file

Quoted 16 lines

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")

---
   fs/f2fs/file.c | 4 ++++
   1 file changed, 4 insertions(+)
fs/f2fs/file.c index renamed from fs/f2fs/file.c +0 -0

771f1f7f3690..e3ff648aa496 100644

fs/f2fs/file.c +0 -0
@@ -2789,6 +2789,10 @@ static int f2fs_move_file_range(struct file

*file_in, loff_t pos_in,

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

Quoted 4 lines
fs/f2fs/file.c +1 -0
   	}
   	f2fs_unlock_op(sbi);
 
+	filemap_invalidate_lock(src->i_mapping);

invalidate lock should cover __exchange_data_block()?

Quoted 8 lines
Quoted 4 lines

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

Quoted 1 line
fs/f2fs/file.c +1 -0
+	truncate_pagecache_range(src, pos_in, pos_in + len - 1);

truncate_pagecache_range() should be called before __exchange_data_block()?

I have tried it, but it do not work. So I move the truncate operation to the back of __exchange_data_block that it works well. I don't know much enough, what do you think of this issue.

Can you describe details about the testcase?

Thanks,

Quoted 11 lines

Thanks,

Quoted 8 lines

Thanks,

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

Quoted 5 lines
fs/f2fs/file.c +2 -0
+	filemap_invalidate_unlock(src->i_mapping);
+
   	if (src != dst)
   		f2fs_up_write(&F2FS_I(dst)->i_gc_rwsem[WRITE]);
   out_src:

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

#4 lore raw
Quoted 32 lines · zhangqilong
Quoted 30 lines
Quoted 29 lines · Zhang Qilong

fs/f2fs/file.c static int f2fs_move_file_range(struct file

Quoted 16 lines

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")

---
   fs/f2fs/file.c | 4 ++++
   1 file changed, 4 insertions(+)
fs/f2fs/file.c index renamed from fs/f2fs/file.c +0 -0

771f1f7f3690..e3ff648aa496 100644

fs/f2fs/file.c +0 -0
@@ -2789,6 +2789,10 @@ static int f2fs_move_file_range(struct file

*file_in, loff_t pos_in,

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

Quoted 4 lines
fs/f2fs/file.c +1 -0
   	}
   	f2fs_unlock_op(sbi);
 
+	filemap_invalidate_lock(src->i_mapping);

invalidate lock should cover __exchange_data_block()?

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

Quoted 1 line
fs/f2fs/file.c +1 -0
+	truncate_pagecache_range(src, pos_in, pos_in + len - 1);

truncate_pagecache_range() should be called before __exchange_data_block()?

Quoted 8 lines
Quoted 3 lines

I have tried it, but it do not work. So I move the truncate operation to the back of __exchange_data_block that it works well. I don't know much enough, what do you think of this issue.

Can you describe details about the testcase?

Thanks,

Process 1 process 2
-> open A
-> mmap

	Read the data and save
								-> ioctl with F2FS_IOC_MOVE_RANGE   A  ->  B

-> mmap
Read the data that offset is same with first time and save

Compare the consistency of the data that read twice.

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

maintainer
#5 lore raw
Quoted 38 lines · zhangqilong
Quoted 38 lines · zhangqilong
Quoted 25 lines
Quoted 25 lines · Zhang Qilong

fs/f2fs/file.c static int f2fs_move_file_range(struct file

Quoted 16 lines

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")

---
    fs/f2fs/file.c | 4 ++++
    1 file changed, 4 insertions(+)
fs/f2fs/file.c index renamed from fs/f2fs/file.c +0 -0

771f1f7f3690..e3ff648aa496 100644

fs/f2fs/file.c +0 -0
@@ -2789,6 +2789,10 @@ static int f2fs_move_file_range(struct file

*file_in, loff_t pos_in,

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

Quoted 4 lines
fs/f2fs/file.c +1 -0
    	}
    	f2fs_unlock_op(sbi);
 
+	filemap_invalidate_lock(src->i_mapping);

invalidate lock should cover __exchange_data_block()?

Quoted 8 lines
Quoted 4 lines

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

Quoted 1 line
fs/f2fs/file.c +1 -0
+	truncate_pagecache_range(src, pos_in, pos_in + len - 1);

truncate_pagecache_range() should be called before __exchange_data_block()?

I have tried it, but it do not work. So I move the truncate operation to the back of __exchange_data_block that it works well. I don't know much enough, what do you think of this issue.

Can you describe details about the testcase?

Quoted 8 lines
Quoted 2 lines

Thanks,

Process 1 process 2
-> open A
-> mmap

	Read the data and save
								-> ioctl with F2FS_IOC_MOVE_RANGE   A  ->  B

The ioctl only change the data on target file (B), so Process 1 needs to read and check data of source file (B)?

Thanks,

Quoted 6 lines

-> mmap
Read the data that offset is same with first time and save

Compare the consistency of the data that read twice.

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

maintainer
#6 lore raw
Quoted 42 lines · Chao Yu
Quoted 41 lines · zhangqilong
Quoted 40 lines · zhangqilong
Quoted 25 lines
Quoted 25 lines · Zhang Qilong

fs/f2fs/file.c static int f2fs_move_file_range(struct file

Quoted 16 lines

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")

---
    fs/f2fs/file.c | 4 ++++

    1 file changed, 4 insertions(+)
fs/f2fs/file.c index renamed from fs/f2fs/file.c +0 -0

771f1f7f3690..e3ff648aa496 100644

fs/f2fs/file.c +0 -0
@@ -2789,6 +2789,10 @@ static int f2fs_move_file_range(struct file

*file_in, loff_t pos_in,

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

Quoted 4 lines
fs/f2fs/file.c +1 -0
         }
         f2fs_unlock_op(sbi);
 
+    filemap_invalidate_lock(src->i_mapping);

invalidate lock should cover __exchange_data_block()?

Quoted 8 lines
Quoted 4 lines

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

Quoted 1 line
fs/f2fs/file.c +1 -0
+    truncate_pagecache_range(src, pos_in, pos_in + len - 1);

truncate_pagecache_range() should be called before __exchange_data_block()?

I have tried it, but it do not work. So I move the truncate operation to the back of __exchange_data_block that it works well. I don't know much enough, what do you think of this issue.

Can you describe details about the testcase?

Thanks,

Quoted 8 lines
Quoted 5 lines

Process 1                         process 2
-> open A
-> mmap
    Read the data and save
                                -> ioctl with F2FS_IOC_MOVE_RANGE   A  ->  B

The ioctl only change the data on target file (B), so Process 1 needs to read and check data of source file (B)?

Sorry, too rush to send this, let me check your testcase...

Thanks,

Quoted 7 lines

Thanks,

Quoted 4 lines

-> mmap
    Read the data that offset is same with first time and save

Quoted 8 lines
Quoted 2 lines

Compare the consistency of the data that read twice.

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

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

#7 lore raw
Quoted 37 lines · Chao Yu
Quoted 35 lines · zhangqilong
Quoted 34 lines
Quoted 34 lines · zhangqilong
Quoted 32 lines
Quoted 31 lines · Zhang Qilong
Quoted 17 lines

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")

---
    fs/f2fs/file.c | 4 ++++

    1 file changed, 4 insertions(+)
fs/f2fs/file.c index renamed from fs/f2fs/file.c +0 -0

771f1f7f3690..e3ff648aa496 100644

fs/f2fs/file.c +0 -0
@@ -2789,6 +2789,10 @@ static int f2fs_move_file_range(struct
Quoted 1 line

file

*file_in, loff_t pos_in,

Quoted 4 lines

        }
        f2fs_unlock_op(sbi);

+    filemap_invalidate_lock(src->i_mapping);

invalidate lock should cover __exchange_data_block()?

Quoted 1 line

+    truncate_pagecache_range(src, pos_in, pos_in + len - 1);

truncate_pagecache_range() should be called before __exchange_data_block()?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

I have tried it, but it do not work. So I move the truncate operation to the back of __exchange_data_block that it works well. I don't know much enough, what do you think of this issue.

Can you describe details about the testcase?

Hi,

I may found the reason that truncate_pagecache_range() being called before __exchange_data_block() that does not work. In the following path:
-> f2fs_move_file_range

    -> __exchange_data_block
      -> __clone_blkaddrs
       -> f2fs_get_lock_data_page

The source page(s) are read again. So we truncate source page(s) before __exchange_data_block is useless. We need to truncate source page(s) after __exchange_data_block(). How do you think?

Thanks,

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