From b2faf2047019c6290a4373ae214738f4fbfbf2f1 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Wed, 18 Mar 2020 13:11:36 -0700 Subject: [PATCH] generic/587: fix rounding error in quota/stat block comparison 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@redhat.com Fixes: 6b04ed05456fc6c ("generic: test unwritten extent conversion extent mapping quota accounting") Signed-off-by: Darrick J. Wong Reviewed-by: Zorro Lang Signed-off-by: Eryu Guan --- tests/generic/587 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/generic/587 b/tests/generic/587 index 7b07d07d..c218c09b 100755 --- a/tests/generic/587 +++ b/tests/generic/587 @@ -51,17 +51,21 @@ ENDL # Make sure that the quota blocks accounting for qa_user on the scratch fs # matches the stat blocks counter for the only file on the scratch fs that -# is owned by qa_user. Note that stat reports in units of 512b blocks whereas -# repquota reports in units of 1k blocks. +# is owned by qa_user. check_quota_accounting() { + # repquota rounds the raw numbers up to the nearest 1k when reporting + # space usage. xfs_io stat always reports space usage in 512b units, + # so use an awk script to round this number up to the nearest 1k, just + # like repquota does. $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 - awk -v qa_user=$qa_user -v blocks=$stat_blocks -f $tmp.awk $tmp.out + $AWK_PROG -v qa_user=$qa_user -v blocks=$stat_blocks -f $tmp.awk $tmp.out } _scratch_mkfs > $seqres.full -- 2.30.2