Re: [PATCH] generic/587: fix rounding error in quota/stat block comparison

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



On Wed, Mar 18, 2020 at 08:01:42AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@xxxxxxxxxx>
> 
> It turns out that repquota (which reports in units of 1k blocks) reports
> rounded up numbers when the fs blocksize is 512 bytes.  However, xfs_io
> stat always reports block counts in units of 512 bytes.  If the number
> of (512b) file blocks is not an even number, the "$3 / 2" expression
> will round down, causing the test to fail.  Round up to the nearest 1k
> to match repquota's behavior.
> 
> Reported-by: zlang@xxxxxxxxxx
> Fixes: 6b04ed05456fc6c ("generic: test unwritten extent conversion extent mapping quota accounting")
> Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx>
> ---

I've tested this patch. It's good to me. If we can add a simple comment before
doing "($3 + 1)", to explain why we need a "blocks + 1" at here, that would be
better for others read this code.

Reviewed-by: Zorro Lang <zlang@xxxxxxxxxx>

>  tests/generic/587 |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/generic/587 b/tests/generic/587
> index 7b07d07d..2ffa367d 100755
> --- a/tests/generic/587
> +++ b/tests/generic/587
> @@ -57,7 +57,8 @@ check_quota_accounting()
>  {
>  	$XFS_IO_PROG -c stat $testfile > $tmp.out
>  	cat $tmp.out >> $seqres.full
> -	local stat_blocks=$(grep 'stat.blocks' $tmp.out | awk '{print $3 / 2}')
> +	local stat_blocks=$(grep 'stat.blocks' $tmp.out | \
> +		awk '{printf("%d\n", ($3 + 1) / 2);}')
>  
>  	_report_quota_blocks $SCRATCH_MNT > $tmp.out
>  	cat $tmp.out >> $seqres.full
> 




[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux