diff mbox series

common: switch _get_available_space accounting to units of 512 bytes

Message ID 20230328150104.129486-1-ailiop@suse.com (mailing list archive)
State New, archived
Headers show
Series common: switch _get_available_space accounting to units of 512 bytes | expand

Commit Message

Anthony Iliopoulos March 28, 2023, 3:01 p.m. UTC
xfs/220 relies on detecting free space changes after truncation of
single filesystem blocks, and this fails when the fs block size is 512b.

By default df is counting 1024b block units and as such is not reporting
any change in the number of available blocks after freeing just a 512b
block.

Switch the df reporting block size from units of 1024b blocks to 512b
blocks to accommodate accounting for smaller granularity fs block sizes.

Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
---
 common/rc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Darrick J. Wong March 28, 2023, 4:02 p.m. UTC | #1
On Tue, Mar 28, 2023 at 05:01:04PM +0200, Anthony Iliopoulos wrote:
> xfs/220 relies on detecting free space changes after truncation of
> single filesystem blocks, and this fails when the fs block size is 512b.
> 
> By default df is counting 1024b block units and as such is not reporting
> any change in the number of available blocks after freeing just a 512b
> block.
> 
> Switch the df reporting block size from units of 1024b blocks to 512b
> blocks to accommodate accounting for smaller granularity fs block sizes.
> 
> Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
> ---
>  common/rc | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/common/rc b/common/rc
> index 90749343f3c4..a32bbe3c0b5f 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -4209,8 +4209,8 @@ _get_available_space()
>  		exit 1
>  	fi
>  	local avail_kb;
> -	avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
> -	echo $((avail_kb * 1024))
> +	avail_kb=`$DF_PROG --block-size=512 $1 | tail -n1 | awk '{ print $5 }'`
> +	echo $((avail_kb * 512))

Why not have df report the free space in bytes?

$DF_PROG -B 1 $1 | tail -n 1 | awk '{print $5}'

--D

>  }
>  
>  # get the total space in bytes
> -- 
> 2.35.3
>
Zorro Lang March 28, 2023, 6:03 p.m. UTC | #2
On Tue, Mar 28, 2023 at 09:02:25AM -0700, Darrick J. Wong wrote:
> On Tue, Mar 28, 2023 at 05:01:04PM +0200, Anthony Iliopoulos wrote:
> > xfs/220 relies on detecting free space changes after truncation of
> > single filesystem blocks, and this fails when the fs block size is 512b.
> > 
> > By default df is counting 1024b block units and as such is not reporting
> > any change in the number of available blocks after freeing just a 512b
> > block.
> > 
> > Switch the df reporting block size from units of 1024b blocks to 512b
> > blocks to accommodate accounting for smaller granularity fs block sizes.
> > 
> > Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
> > ---
> >  common/rc | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/common/rc b/common/rc
> > index 90749343f3c4..a32bbe3c0b5f 100644
> > --- a/common/rc
> > +++ b/common/rc
> > @@ -4209,8 +4209,8 @@ _get_available_space()
> >  		exit 1
> >  	fi
> >  	local avail_kb;
> > -	avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
> > -	echo $((avail_kb * 1024))
> > +	avail_kb=`$DF_PROG --block-size=512 $1 | tail -n1 | awk '{ print $5 }'`
> > +	echo $((avail_kb * 512))
> 
> Why not have df report the free space in bytes?
> 
> $DF_PROG -B 1 $1 | tail -n 1 | awk '{print $5}'

Agree, if we finally hope to get "bytes", and we can get it at beginning, why
take a long way?

If you'd like to send a V2 to do that, you can do the same change on
_get_total_space() too.

Thanks,
Zorro

> 
> --D
> 
> >  }
> >  
> >  # get the total space in bytes
> > -- 
> > 2.35.3
> > 
>
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 90749343f3c4..a32bbe3c0b5f 100644
--- a/common/rc
+++ b/common/rc
@@ -4209,8 +4209,8 @@  _get_available_space()
 		exit 1
 	fi
 	local avail_kb;
-	avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
-	echo $((avail_kb * 1024))
+	avail_kb=`$DF_PROG --block-size=512 $1 | tail -n1 | awk '{ print $5 }'`
+	echo $((avail_kb * 512))
 }
 
 # get the total space in bytes