generic: check for reasonable inode creation time
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 12 Feb 2019 02:17:39 +0000 (18:17 -0800)
committerEryu Guan <guaneryu@gmail.com>
Sat, 16 Feb 2019 11:45:49 +0000 (19:45 +0800)
If statx returns inode creation time (aka btime), check it to make
sure that the filesystem is setting a creation time that's
reasonably close to when it creates a file.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/generic/528 [new file with mode: 0755]
tests/generic/528.out [new file with mode: 0644]
tests/generic/group

diff --git a/tests/generic/528 b/tests/generic/528
new file mode 100755 (executable)
index 0000000..1ceffe3
--- /dev/null
@@ -0,0 +1,53 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2019 Oracle, Inc.  All Rights Reserved.
+#
+# FS QA Test No. 528
+#
+# Check that statx btime (aka creation time) is plausibly close to when
+# we created a file.  A bug caught during code review of xfs patches revealed
+# that there weren't any sanity checks of the btime values.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+tmp=/tmp/$$
+status=1       # failure is the default!
+testfile=$TEST_DIR/$seq.txt
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.* $testfile
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/attr
+. ./common/filter
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_test
+_require_xfs_io_command "statx" "-r"
+_require_btime
+
+rm -f $seqres.full
+rm -f $testfile
+
+# Create a file and the time we created it
+now=$(date +%s)
+touch $testfile
+
+# Make sure the reported btime is within 5 seconds of the time we recorded
+# just prior to creating the file.
+btime=$(date +%s -d "$($XFS_IO_PROG -c "statx -v -m $STATX_BTIME" $testfile | \
+       grep 'stat.btime =' | cut -d '=' -f 2)")
+test -n "$btime" || echo "error: did not see btime in output??"
+
+_within_tolerance "btime" "$btime" "$now" 0 5 -v
+
+status=0
+exit
diff --git a/tests/generic/528.out b/tests/generic/528.out
new file mode 100644 (file)
index 0000000..97705b8
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 528
+btime is in range
index a38c578a2e6e7b0195592ed058bce2143d757178..8ad0557d7d3d8c3bda72c73873d2582ce4843245 100644 (file)
 525 auto quick rw
 526 auto quick log
 527 auto quick log
+528 auto quick