mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Chao Yu <chao@kernel.org>
Cc: Chao Yu <yuchao0@huawei.com>,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, drosen@google.com
Subject: Re: [PATCH 1/2] f2fs: fix to avoid potential negative .f_bfree
Date: Mon, 29 Apr 2019 19:54:06 -0700	[thread overview]
Message-ID: <20190430025406.GA17299@jaegeuk-macbookpro.roam.corp.google.com> (raw)
In-Reply-To: <f8b890b8-22a3-bead-7df5-6ab87deb56e9@kernel.org>

On 04/29, Chao Yu wrote:
> On 2019-4-28 21:47, Jaegeuk Kim wrote:
> > On 04/26, Chao Yu wrote:
> >> When calculating .f_bfree value in f2fs_statfs(), sbi->unusable_block_count
> >> can be increased after the judgment condition, result in overflow of
> >> .f_bfree in later calculation. This patch fixes to use a temporary signed
> >> variable to save the calculation result of .f_bfree.
> >>
> >> 	if (unlikely(buf->f_bfree <= sbi->unusable_block_count))
> >>  		buf->f_bfree = 0;
> >>  	else
> >> 		buf->f_bfree -= sbi->unusable_block_count;
> > 
> > Do we just need stat_lock for this?
> 
> Like we access other stat value in statfs(), we just need the instantaneous
> value of .unusable_block_count, so we don't need additional stat_lock, right?

What I've concerend is whether or not this fixes all the inconsistent values.
The original intention was providing stats in best effort, so we wouldn't use
any lock.

> 
> Thanks,
> 
> > 
> >>
> >> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> >> ---
> >>  fs/f2fs/super.c | 7 +++++--
> >>  1 file changed, 5 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> >> index 2376bb01b5c4..fcc9793dbc2c 100644
> >> --- a/fs/f2fs/super.c
> >> +++ b/fs/f2fs/super.c
> >> @@ -1216,6 +1216,7 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
> >>  	u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
> >>  	block_t total_count, user_block_count, start_count;
> >>  	u64 avail_node_count;
> >> +	long long bfree;
> >>  
> >>  	total_count = le64_to_cpu(sbi->raw_super->block_count);
> >>  	user_block_count = sbi->user_block_count;
> >> @@ -1226,10 +1227,12 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
> >>  	buf->f_blocks = total_count - start_count;
> >>  	buf->f_bfree = user_block_count - valid_user_blocks(sbi) -
> >>  						sbi->current_reserved_blocks;
> >> -	if (unlikely(buf->f_bfree <= sbi->unusable_block_count))
> >> +
> >> +	bfree = buf->f_bfree - sbi->unusable_block_count;
> >> +	if (unlikely(bfree < 0))
> >>  		buf->f_bfree = 0;
> >>  	else
> >> -		buf->f_bfree -= sbi->unusable_block_count;
> >> +		buf->f_bfree = bfree;
> >>  
> >>  	if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks)
> >>  		buf->f_bavail = buf->f_bfree -
> >> -- 
> >> 2.18.0.rc1

  reply	other threads:[~2019-04-30  2:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-26  9:57 Chao Yu
2019-04-26  9:57 ` [PATCH 2/2] f2fs: fix to handle error in f2fs_disable_checkpoint() Chao Yu
2019-04-28 13:47 ` [PATCH 1/2] f2fs: fix to avoid potential negative .f_bfree Jaegeuk Kim
2019-04-29 14:13   ` Chao Yu
2019-04-30  2:54     ` Jaegeuk Kim [this message]
2019-04-30  3:14       ` Chao Yu

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=20190430025406.GA17299@jaegeuk-macbookpro.roam.corp.google.com \
    --to=jaegeuk@kernel.org \
    --cc=chao@kernel.org \
    --cc=drosen@google.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yuchao0@huawei.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

all inboxes | Powered by JetHome®