diff mbox

f2fs: fix wrong bfree and bavail

Message ID 20170905210653.46186-1-jaegeuk@kernel.org (mailing list archive)
State New, archived
Headers show

Commit Message

Jaegeuk Kim Sept. 5, 2017, 9:06 p.m. UTC
This patch fixes bavail and bfree finally.

long    f_bfree;    /* free blocks in fs */
long    f_bavail;   /* free blocks avail to non-superuser */

So, bfree represents all the reserved blocks, while bavail does the space only
visible to normal user.

Fix: 3e6d0b4d9c1c ("f2fs: fix incorrect f_bfree calculation in ->statfs")
Cc: <stable@vger.kernel.org> # 4.8+
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fs/f2fs/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andreas Dilger Sept. 5, 2017, 9:20 p.m. UTC | #1
On Sep 5, 2017, at 3:06 PM, Jaegeuk Kim <jaegeuk@kernel.org> wrote:
> 
> This patch fixes bavail and bfree finally.
> 
> long    f_bfree;    /* free blocks in fs */
> long    f_bavail;   /* free blocks avail to non-superuser */
> 
> So, bfree represents all the reserved blocks, while bavail does the space only
> visible to normal user.
> 
> Fix: 3e6d0b4d9c1c ("f2fs: fix incorrect f_bfree calculation in ->statfs")
> Cc: <stable@vger.kernel.org> # 4.8+
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> ---
> fs/f2fs/super.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 7e29db227910..17cca4cb93af 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -955,8 +955,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
> 	buf->f_bsize = sbi->blocksize;
> 
> 	buf->f_blocks = total_count - start_count;
> -	buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count;
> -	buf->f_bavail = user_block_count - valid_user_blocks(sbi) -
> +	buf->f_bfree = user_block_count - valid_user_blocks(sbi);
> +	buf->f_bavail = user_block_count - valid_user_blocks(sbi) - ovp_count -
> 						sbi->reserved_blocks;

To keep the statfs data more consistent, you could use:

	buf->f_bavail = buf->f_bfree - ovp_count - sbi->reserved_blocks;

That avoids the extra subtraction, and avoids (minor) issues if these values
change while this syscall is running.

Cheers, Andreas
Jaegeuk Kim Sept. 5, 2017, 10:41 p.m. UTC | #2
On 09/05, Andreas Dilger wrote:
> On Sep 5, 2017, at 3:06 PM, Jaegeuk Kim <jaegeuk@kernel.org> wrote:
> > 
> > This patch fixes bavail and bfree finally.
> > 
> > long    f_bfree;    /* free blocks in fs */
> > long    f_bavail;   /* free blocks avail to non-superuser */
> > 
> > So, bfree represents all the reserved blocks, while bavail does the space only
> > visible to normal user.
> > 
> > Fix: 3e6d0b4d9c1c ("f2fs: fix incorrect f_bfree calculation in ->statfs")
> > Cc: <stable@vger.kernel.org> # 4.8+
> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> > ---
> > fs/f2fs/super.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> > index 7e29db227910..17cca4cb93af 100644
> > --- a/fs/f2fs/super.c
> > +++ b/fs/f2fs/super.c
> > @@ -955,8 +955,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
> > 	buf->f_bsize = sbi->blocksize;
> > 
> > 	buf->f_blocks = total_count - start_count;
> > -	buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count;
> > -	buf->f_bavail = user_block_count - valid_user_blocks(sbi) -
> > +	buf->f_bfree = user_block_count - valid_user_blocks(sbi);
> > +	buf->f_bavail = user_block_count - valid_user_blocks(sbi) - ovp_count -
> > 						sbi->reserved_blocks;
> 
> To keep the statfs data more consistent, you could use:
> 
> 	buf->f_bavail = buf->f_bfree - ovp_count - sbi->reserved_blocks;
> 
> That avoids the extra subtraction, and avoids (minor) issues if these values
> change while this syscall is running.

Much better. Thank you so much for correcting me.

> 
> Cheers, Andreas
> 
> 
> 
> 
>
Chao Yu Sept. 6, 2017, 3:07 a.m. UTC | #3
On 2017/9/6 5:06, Jaegeuk Kim wrote:
> This patch fixes bavail and bfree finally.
> 
> long    f_bfree;    /* free blocks in fs */
> long    f_bavail;   /* free blocks avail to non-superuser */
> 
> So, bfree represents all the reserved blocks, while bavail does the space only
> visible to normal user.
> 
> Fix: 3e6d0b4d9c1c ("f2fs: fix incorrect f_bfree calculation in ->statfs")
> Cc: <stable@vger.kernel.org> # 4.8+
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> ---
>  fs/f2fs/super.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 7e29db227910..17cca4cb93af 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -955,8 +955,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
>  	buf->f_bsize = sbi->blocksize;
>  
>  	buf->f_blocks = total_count - start_count;
> -	buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count;
> -	buf->f_bavail = user_block_count - valid_user_blocks(sbi) -
> +	buf->f_bfree = user_block_count - valid_user_blocks(sbi);
> +	buf->f_bavail = user_block_count - valid_user_blocks(sbi) - ovp_count -

	set_cp(user_block_count, ((get_cp(free_segment_count) + 6 -
			get_cp(overprov_segment_count)) * c.blks_per_seg));

As we calculated in mkfs, we have removed ovp_count in user_block_count, so
shouldn't we add ovp_count for f_bfree here?

Thanks,

>  						sbi->reserved_blocks;
>  
>  	avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
>
Jaegeuk Kim Sept. 6, 2017, 3:10 a.m. UTC | #4
On 09/06, Chao Yu wrote:
> On 2017/9/6 5:06, Jaegeuk Kim wrote:
> > This patch fixes bavail and bfree finally.
> > 
> > long    f_bfree;    /* free blocks in fs */
> > long    f_bavail;   /* free blocks avail to non-superuser */
> > 
> > So, bfree represents all the reserved blocks, while bavail does the space only
> > visible to normal user.
> > 
> > Fix: 3e6d0b4d9c1c ("f2fs: fix incorrect f_bfree calculation in ->statfs")
> > Cc: <stable@vger.kernel.org> # 4.8+
> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> > ---
> >  fs/f2fs/super.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> > index 7e29db227910..17cca4cb93af 100644
> > --- a/fs/f2fs/super.c
> > +++ b/fs/f2fs/super.c
> > @@ -955,8 +955,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
> >  	buf->f_bsize = sbi->blocksize;
> >  
> >  	buf->f_blocks = total_count - start_count;
> > -	buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count;
> > -	buf->f_bavail = user_block_count - valid_user_blocks(sbi) -
> > +	buf->f_bfree = user_block_count - valid_user_blocks(sbi);
> > +	buf->f_bavail = user_block_count - valid_user_blocks(sbi) - ovp_count -
> 
> 	set_cp(user_block_count, ((get_cp(free_segment_count) + 6 -
> 			get_cp(overprov_segment_count)) * c.blks_per_seg));
> 
> As we calculated in mkfs, we have removed ovp_count in user_block_count, so
> shouldn't we add ovp_count for f_bfree here?

Hehe, I already dropped this. :P
It seems like something wrong with df in android.

> 
> Thanks,
> 
> >  						sbi->reserved_blocks;
> >  
> >  	avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
> >
Chao Yu Sept. 6, 2017, 3:19 a.m. UTC | #5
On 2017/9/6 11:10, Jaegeuk Kim wrote:
> On 09/06, Chao Yu wrote:
>> On 2017/9/6 5:06, Jaegeuk Kim wrote:
>>> This patch fixes bavail and bfree finally.
>>>
>>> long    f_bfree;    /* free blocks in fs */
>>> long    f_bavail;   /* free blocks avail to non-superuser */
>>>
>>> So, bfree represents all the reserved blocks, while bavail does the space only
>>> visible to normal user.
>>>
>>> Fix: 3e6d0b4d9c1c ("f2fs: fix incorrect f_bfree calculation in ->statfs")
>>> Cc: <stable@vger.kernel.org> # 4.8+
>>> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
>>> ---
>>>  fs/f2fs/super.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
>>> index 7e29db227910..17cca4cb93af 100644
>>> --- a/fs/f2fs/super.c
>>> +++ b/fs/f2fs/super.c
>>> @@ -955,8 +955,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
>>>  	buf->f_bsize = sbi->blocksize;
>>>  
>>>  	buf->f_blocks = total_count - start_count;
>>> -	buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count;
>>> -	buf->f_bavail = user_block_count - valid_user_blocks(sbi) -
>>> +	buf->f_bfree = user_block_count - valid_user_blocks(sbi);
>>> +	buf->f_bavail = user_block_count - valid_user_blocks(sbi) - ovp_count -
>>
>> 	set_cp(user_block_count, ((get_cp(free_segment_count) + 6 -
>> 			get_cp(overprov_segment_count)) * c.blks_per_seg));
>>
>> As we calculated in mkfs, we have removed ovp_count in user_block_count, so
>> shouldn't we add ovp_count for f_bfree here?
> 
> Hehe, I already dropped this. :P

Alright. :)

> It seems like something wrong with df in android.

Maybe its version is too old?

Thanks,

> 
>>
>> Thanks,
>>
>>>  						sbi->reserved_blocks;
>>>  
>>>  	avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
>>>
> 
> .
>
diff mbox

Patch

diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 7e29db227910..17cca4cb93af 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -955,8 +955,8 @@  static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	buf->f_bsize = sbi->blocksize;
 
 	buf->f_blocks = total_count - start_count;
-	buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count;
-	buf->f_bavail = user_block_count - valid_user_blocks(sbi) -
+	buf->f_bfree = user_block_count - valid_user_blocks(sbi);
+	buf->f_bavail = user_block_count - valid_user_blocks(sbi) - ovp_count -
 						sbi->reserved_blocks;
 
 	avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;