linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH -next] f2fs: adding truncate page cache after being moved
@ 2022-09-13  3:05 Zhang Qilong via Linux-f2fs-devel
  2022-09-13  3:19 ` Chao Yu
  0 siblings, 1 reply; 8+ messages in thread
From: Zhang Qilong via Linux-f2fs-devel @ 2022-09-13  3:05 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel

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")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 fs/f2fs/file.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 771f1f7f3690..e3ff648aa496 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -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:
-- 
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] 8+ messages in thread

* Re: [f2fs-dev] [PATCH -next] f2fs: adding truncate page cache after being moved
  2022-09-13  3:05 [f2fs-dev] [PATCH -next] f2fs: adding truncate page cache after being moved Zhang Qilong via Linux-f2fs-devel
@ 2022-09-13  3:19 ` Chao Yu
  2022-09-13  3:41   ` [f2fs-dev] 答复: " zhangqilong via Linux-f2fs-devel
  0 siblings, 1 reply; 8+ messages in thread
From: Chao Yu @ 2022-09-13  3:19 UTC (permalink / raw)
  To: Zhang Qilong, jaegeuk; +Cc: linux-f2fs-devel

On 2022/9/13 11:05, Zhang Qilong wrote:
> 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")
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---
>   fs/f2fs/file.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 771f1f7f3690..e3ff648aa496 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -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()?

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

truncate_pagecache_range() should be called before __exchange_data_block()?

Thanks,

> +	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
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* [f2fs-dev] 答复: [PATCH -next] f2fs: adding truncate page cache after being moved
  2022-09-13  3:19 ` Chao Yu
@ 2022-09-13  3:41   ` zhangqilong via Linux-f2fs-devel
  2022-09-13  3:50     ` Chao Yu
  0 siblings, 1 reply; 8+ messages in thread
From: zhangqilong via Linux-f2fs-devel @ 2022-09-13  3:41 UTC (permalink / raw)
  To: Chao Yu, jaegeuk; +Cc: linux-f2fs-devel

> On 2022/9/13 11:05, Zhang Qilong wrote:
> > 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")
> > Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> > ---
> >   fs/f2fs/file.c | 4 ++++
> >   1 file changed, 4 insertions(+)
> >
> > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index
> > 771f1f7f3690..e3ff648aa496 100644
> > --- a/fs/f2fs/file.c
> > +++ b/fs/f2fs/file.c
> > @@ -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()?
> 
> > +	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,

> 
> Thanks,
> 
> > +	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
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] 答复: [PATCH -next] f2fs: adding truncate page cache after being moved
  2022-09-13  3:41   ` [f2fs-dev] 答复: " zhangqilong via Linux-f2fs-devel
@ 2022-09-13  3:50     ` Chao Yu
  2022-09-13  4:37       ` [f2fs-dev] 答复: " zhangqilong via Linux-f2fs-devel
  0 siblings, 1 reply; 8+ messages in thread
From: Chao Yu @ 2022-09-13  3:50 UTC (permalink / raw)
  To: zhangqilong, jaegeuk; +Cc: linux-f2fs-devel

On 2022/9/13 11:41, zhangqilong wrote:
>> On 2022/9/13 11:05, Zhang Qilong wrote:
>>> 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")
>>> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
>>> ---
>>>    fs/f2fs/file.c | 4 ++++
>>>    1 file changed, 4 insertions(+)
>>>
>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index
>>> 771f1f7f3690..e3ff648aa496 100644
>>> --- a/fs/f2fs/file.c
>>> +++ b/fs/f2fs/file.c
>>> @@ -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()?
>>
>>> +	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,

> 
> Thanks,
> 
>>
>> Thanks,
>>
>>> +	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
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* [f2fs-dev] 答复: 答复: [PATCH -next] f2fs: adding truncate page cache after being moved
  2022-09-13  3:50     ` Chao Yu
@ 2022-09-13  4:37       ` zhangqilong via Linux-f2fs-devel
  2022-09-13  6:10         ` Chao Yu
  0 siblings, 1 reply; 8+ messages in thread
From: zhangqilong via Linux-f2fs-devel @ 2022-09-13  4:37 UTC (permalink / raw)
  To: Chao Yu, jaegeuk; +Cc: linux-f2fs-devel

> 
> On 2022/9/13 11:41, zhangqilong wrote:
> >> On 2022/9/13 11:05, Zhang Qilong wrote:
> >>> 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")
> >>> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> >>> ---
> >>>    fs/f2fs/file.c | 4 ++++
> >>>    1 file changed, 4 insertions(+)
> >>>
> >>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index
> >>> 771f1f7f3690..e3ff648aa496 100644
> >>> --- a/fs/f2fs/file.c
> >>> +++ b/fs/f2fs/file.c
> >>> @@ -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()?
> >>
> >>> +	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,
> 

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
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] 答复: 答复: [PATCH -next] f2fs: adding truncate page cache after being moved
  2022-09-13  4:37       ` [f2fs-dev] 答复: " zhangqilong via Linux-f2fs-devel
@ 2022-09-13  6:10         ` Chao Yu
  2022-09-13  6:14           ` Chao Yu
  0 siblings, 1 reply; 8+ messages in thread
From: Chao Yu @ 2022-09-13  6:10 UTC (permalink / raw)
  To: zhangqilong, jaegeuk; +Cc: linux-f2fs-devel

On 2022/9/13 12:37, zhangqilong wrote:
>>
>> On 2022/9/13 11:41, zhangqilong wrote:
>>>> On 2022/9/13 11:05, Zhang Qilong wrote:
>>>>> 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")
>>>>> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
>>>>> ---
>>>>>     fs/f2fs/file.c | 4 ++++
>>>>>     1 file changed, 4 insertions(+)
>>>>>
>>>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index
>>>>> 771f1f7f3690..e3ff648aa496 100644
>>>>> --- a/fs/f2fs/file.c
>>>>> +++ b/fs/f2fs/file.c
>>>>> @@ -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()?
>>>>
>>>>> +	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,
>>
> 
> 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,

> 
> -> 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
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] 答复: 答复: [PATCH -next] f2fs: adding truncate page cache after being moved
  2022-09-13  6:10         ` Chao Yu
@ 2022-09-13  6:14           ` Chao Yu
  2022-09-20 11:32             ` [f2fs-dev] 答复: " zhangqilong via Linux-f2fs-devel
  0 siblings, 1 reply; 8+ messages in thread
From: Chao Yu @ 2022-09-13  6:14 UTC (permalink / raw)
  To: zhangqilong, jaegeuk; +Cc: linux-f2fs-devel

On 2022/9/13 14:10, Chao Yu wrote:
> On 2022/9/13 12:37, zhangqilong wrote:
>>>
>>> On 2022/9/13 11:41, zhangqilong wrote:
>>>>> On 2022/9/13 11:05, Zhang Qilong wrote:
>>>>>> 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")
>>>>>> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
>>>>>> ---
>>>>>>     fs/f2fs/file.c | 4 ++++
>>>>>>     1 file changed, 4 insertions(+)
>>>>>>
>>>>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index
>>>>>> 771f1f7f3690..e3ff648aa496 100644
>>>>>> --- a/fs/f2fs/file.c
>>>>>> +++ b/fs/f2fs/file.c
>>>>>> @@ -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()?
>>>>>
>>>>>> +    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,
>>>
>>
>> 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,

> 
> Thanks,
> 
>>
>> -> 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
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


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

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

* [f2fs-dev] 答复:  答复: 答复: [PATCH -next] f2fs: adding truncate page cache after being moved
  2022-09-13  6:14           ` Chao Yu
@ 2022-09-20 11:32             ` zhangqilong via Linux-f2fs-devel
  0 siblings, 0 replies; 8+ messages in thread
From: zhangqilong via Linux-f2fs-devel @ 2022-09-20 11:32 UTC (permalink / raw)
  To: Chao Yu, jaegeuk; +Cc: linux-f2fs-devel

> 
> On 2022/9/13 14:10, Chao Yu wrote:
> > On 2022/9/13 12:37, zhangqilong wrote:
> >>>
> >>> On 2022/9/13 11:41, zhangqilong wrote:
> >>>>> On 2022/9/13 11:05, Zhang Qilong wrote:
> >>>>>> 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")
> >>>>>> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> >>>>>> ---
> >>>>>>     fs/f2fs/file.c | 4 ++++
> >>>>>>     1 file changed, 4 insertions(+)
> >>>>>>
> >>>>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index
> >>>>>> 771f1f7f3690..e3ff648aa496 100644
> >>>>>> --- a/fs/f2fs/file.c
> >>>>>> +++ b/fs/f2fs/file.c
> >>>>>> @@ -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()?
> >>>>>
> >>>>>> +    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?
> >>>
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
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

end of thread, other threads:[~2022-09-20 11:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-13  3:05 [f2fs-dev] [PATCH -next] f2fs: adding truncate page cache after being moved Zhang Qilong via Linux-f2fs-devel
2022-09-13  3:19 ` Chao Yu
2022-09-13  3:41   ` [f2fs-dev] 答复: " zhangqilong via Linux-f2fs-devel
2022-09-13  3:50     ` Chao Yu
2022-09-13  4:37       ` [f2fs-dev] 答复: " zhangqilong via Linux-f2fs-devel
2022-09-13  6:10         ` Chao Yu
2022-09-13  6:14           ` Chao Yu
2022-09-20 11:32             ` [f2fs-dev] 答复: " zhangqilong via Linux-f2fs-devel

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