Re: [PATCH v3 3/4] f2fs: atomic: fix to truncate pagecache before on-disk metadata truncation

Jaegeuk Kim
2024-08-06T02:43:43Z

On 08/01, Chao Yu wrote:
> We should always truncate pagecache while truncating on-disk data.
>
> Fixes: a46bebd502fe ("f2fs: synchronize atomic write aborts")
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
> v3:
> - check dirty page before truncation
> - use invalidate_mapping_pages() instead of truncate_inode_pages()
> - set i_size to zero after truncation
> fs/f2fs/file.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index ac61c88f7688..a316c21539d1 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -2199,11 +2199,17 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)
> F2FS_I(fi->cow_inode)->atomic_inode = inode;
> } else {
> /* Reuse the already created COW inode */
> + f2fs_bug_on(sbi, get_dirty_pages(fi->cow_inode));
> +
> + invalidate_mapping_pages(fi->cow_inode->i_mapping, 0, -1);
> +
> ret = f2fs_do_truncate_blocks(fi->cow_inode, 0, true);
> if (ret) {
> f2fs_up_write(&fi->i_gc_rwsem[WRITE]);
> goto out;
> }
> +
> + i_size_write(fi->cow_inode, 0);

Do we really need this?

> }
>
> f2fs_write_inode(inode, NULL);
> --
> 2.40.1