FSTests Archive on lore.kernel.org
 help / color / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Eryu Guan <guaneryu@gmail.com>
Cc: zlang@redhat.com, fstests <fstests@vger.kernel.org>,
	xfs <linux-xfs@vger.kernel.org>
Subject: [PATCH v2] generic/587: fix rounding error in quota/stat block comparison
Date: Wed, 18 Mar 2020 13:11:36 -0700
Message-ID: <20200318201136.GF256767@magnolia> (raw)
In-Reply-To: <20200318150142.GA256607@magnolia>

From: Darrick J. Wong <darrick.wong@oracle.com>

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 <darrick.wong@oracle.com>
---
v2: improve the comments to explain exactly what we're doing and why
---
 tests/generic/587 |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tests/generic/587 b/tests/generic/587
index 7b07d07d..3e58a302 100755
--- a/tests/generic/587
+++ b/tests/generic/587
@@ -51,13 +51,17 @@ 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

  parent reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-18 15:01 [PATCH] " Darrick J. Wong
2020-03-18 19:35 ` Zorro Lang
2020-03-18 20:11 ` Darrick J. Wong [this message]
2020-03-19  4:05   ` [PATCH v2] " Zorro Lang

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=20200318201136.GF256767@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=fstests@vger.kernel.org \
    --cc=guaneryu@gmail.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=zlang@redhat.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

FSTests Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/fstests/0 fstests/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 fstests fstests/ https://lore.kernel.org/fstests \
		fstests@vger.kernel.org
	public-inbox-index fstests

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.fstests


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git