Linux-f2fs-devel Archive mirror
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Zhiguo Niu <zhiguo.niu@unisoc.com>, jaegeuk@kernel.org
Cc: hongyu.jin@unisoc.com, ke.wang@unisoc.com,
	linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to adjust appropirate defragment pg_end
Date: Sat, 23 Mar 2024 11:02:04 +0800	[thread overview]
Message-ID: <fa4686b5-5197-4130-bfa7-215f15bafe35@kernel.org> (raw)
In-Reply-To: <1711087390-23645-1-git-send-email-zhiguo.niu@unisoc.com>

On 2024/3/22 14:03, Zhiguo Niu wrote:
> A length that exceeds the real size of the inode may be
> specified from user, although these out-of-range areas
> are not mapped, but they still need to be check in
> while loop, which is unnecessary.
> 
> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
> ---
>   fs/f2fs/file.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 128e53d..0e7eac6 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -2609,7 +2609,9 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
>   	int err;
>   
>   	pg_start = range->start >> PAGE_SHIFT;
> -	pg_end = (range->start + range->len) >> PAGE_SHIFT;
> +	pg_end = min_t(pgoff_t,
> +			(range->start + range->len) >> PAGE_SHIFT,
> +			DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));

I guess we may check i_size w/ inode lock, it can avoid racing w/ append write
or truncate.

Thanks,

>   
>   	f2fs_balance_fs(sbi, true);
>   


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

      reply	other threads:[~2024-03-23  3:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22  6:03 [f2fs-dev] [PATCH] f2fs: fix to adjust appropirate defragment pg_end Zhiguo Niu
2024-03-23  3:02 ` Chao Yu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fa4686b5-5197-4130-bfa7-215f15bafe35@kernel.org \
    --to=chao@kernel.org \
    --cc=hongyu.jin@unisoc.com \
    --cc=jaegeuk@kernel.org \
    --cc=ke.wang@unisoc.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zhiguo.niu@unisoc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).