fstests.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHSET 0/4] fstests: exercise code changes in 5.15
@ 2021-09-01  0:12 Darrick J. Wong
  2021-09-01  0:12 ` [PATCH 1/4] generic: regression test for a FALLOC_FL_UNSHARE bug in XFS Darrick J. Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Darrick J. Wong @ 2021-09-01  0:12 UTC (permalink / raw)
  To: djwong, guaneryu; +Cc: Zorro Lang, linux-xfs, fstests, guan

Hi all,

Add new tests to exercise bug fixes appearing in 5.15.

If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D

fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=new-tests-for-5.15
---
 tests/generic/729     |   77 ++++++++++++++++++
 tests/generic/729.out |    2 
 tests/xfs/108         |    1 
 tests/xfs/780         |  207 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/780.out     |   18 ++++
 tests/xfs/922         |  183 +++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/922.out     |    2 
 7 files changed, 490 insertions(+)
 create mode 100755 tests/generic/729
 create mode 100644 tests/generic/729.out
 create mode 100755 tests/xfs/780
 create mode 100644 tests/xfs/780.out
 create mode 100755 tests/xfs/922
 create mode 100644 tests/xfs/922.out


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] generic: regression test for a FALLOC_FL_UNSHARE bug in XFS
  2021-09-01  0:12 [PATCHSET 0/4] fstests: exercise code changes in 5.15 Darrick J. Wong
@ 2021-09-01  0:12 ` Darrick J. Wong
  2021-09-01  0:12 ` [PATCH 2/4] xfs: test DONTCACHE behavior with the inode cache Darrick J. Wong
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Darrick J. Wong @ 2021-09-01  0:12 UTC (permalink / raw)
  To: djwong, guaneryu; +Cc: Zorro Lang, linux-xfs, fstests, guan

From: Darrick J. Wong <djwong@kernel.org>

This is a regression test for "xfs: only set IOMAP_F_SHARED when
providing a srcmap to a write".

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
---
 tests/generic/729     |   77 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/729.out |    2 +
 2 files changed, 79 insertions(+)
 create mode 100755 tests/generic/729
 create mode 100644 tests/generic/729.out


diff --git a/tests/generic/729 b/tests/generic/729
new file mode 100755
index 00000000..90cecc03
--- /dev/null
+++ b/tests/generic/729
@@ -0,0 +1,77 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2021 Oracle.  All Rights Reserved.
+#
+# FS QA Test 729
+#
+# Regression test for commit:
+#
+# 72a048c1056a ("xfs: only set IOMAP_F_SHARED when providing a srcmap to a write")
+#
+# If a user creates a sparse shared region in a file, convinces XFS to create a
+# copy-on-write delayed allocation reservation spanning both the shared blocks
+# and the holes, and then calls the fallocate unshare command to unshare the
+# entire sparse region, XFS incorrectly tells iomap that the delalloc blocks
+# for the holes are shared, which causes it to error out while trying to
+# unshare a hole.
+#
+. ./common/preamble
+_begin_fstest auto clone unshare
+
+# Override the default cleanup function.
+_cleanup()
+{
+	cd /
+	rm -r -f $tmp.* $TEST_DIR/$seq
+}
+
+# Import common functions.
+. ./common/reflink
+. ./common/filter
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_require_cp_reflink
+_require_test_reflink
+_require_test_program "punch-alternating"
+_require_xfs_io_command "fpunch"	# make sure punch-alt can do its job
+_require_xfs_io_command "funshare"
+test "$FSTYP" = "xfs" && _require_xfs_io_command "cowextsize"
+
+mkdir $TEST_DIR/$seq
+file1=$TEST_DIR/$seq/a
+file2=$TEST_DIR/$seq/b
+
+$XFS_IO_PROG -f -c "pwrite -S 0x58 -b 10m 0 10m" $file1 >> $seqres.full
+
+f1sum0="$(md5sum $file1 | _filter_test_dir)"
+
+_cp_reflink $file1 $file2
+$here/src/punch-alternating -o 1 $file2
+
+f2sum0="$(md5sum $file2 | _filter_test_dir)"
+
+# set cowextsize to the defaults (128k) to force delalloc cow preallocations
+test "$FSTYP" = "xfs" && $XFS_IO_PROG -c 'cowextsize 0' $file2
+$XFS_IO_PROG -c "funshare 0 10m" $file2
+
+f1sum1="$(md5sum $file1 | _filter_test_dir)"
+f2sum1="$(md5sum $file2 | _filter_test_dir)"
+
+test "${f1sum0}" = "${f1sum1}" || echo "file1 should not have changed"
+test "${f2sum0}" = "${f2sum1}" || echo "file2 should not have changed"
+
+_test_cycle_mount
+
+f1sum2="$(md5sum $file1 | _filter_test_dir)"
+f2sum2="$(md5sum $file2 | _filter_test_dir)"
+
+test "${f1sum2}" = "${f1sum1}" || echo "file1 should not have changed ondisk"
+test "${f2sum2}" = "${f2sum1}" || echo "file2 should not have changed ondisk"
+
+# success, all done
+echo Silence is golden
+status=0
+exit
diff --git a/tests/generic/729.out b/tests/generic/729.out
new file mode 100644
index 00000000..0f175ae2
--- /dev/null
+++ b/tests/generic/729.out
@@ -0,0 +1,2 @@
+QA output created by 729
+Silence is golden


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/4] xfs: test DONTCACHE behavior with the inode cache
  2021-09-01  0:12 [PATCHSET 0/4] fstests: exercise code changes in 5.15 Darrick J. Wong
  2021-09-01  0:12 ` [PATCH 1/4] generic: regression test for a FALLOC_FL_UNSHARE bug in XFS Darrick J. Wong
@ 2021-09-01  0:12 ` Darrick J. Wong
  2021-09-01  0:12 ` [PATCH 3/4] xfs/108: sync filesystem before querying quota Darrick J. Wong
  2021-09-01  0:12 ` [PATCH 4/4] xfs: regresion test for fsmap problems with realtime Darrick J. Wong
  3 siblings, 0 replies; 7+ messages in thread
From: Darrick J. Wong @ 2021-09-01  0:12 UTC (permalink / raw)
  To: djwong, guaneryu; +Cc: linux-xfs, fstests, guan

From: Darrick J. Wong <djwong@kernel.org>

Basic testing that DONTCACHE affects the XFS inode cache in the manner
that we expect.  The only way we can do that (for XFS, anyway) is to
play around with the BULKSTAT ioctl.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 tests/xfs/780     |  207 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/780.out |   18 +++++
 2 files changed, 225 insertions(+)
 create mode 100755 tests/xfs/780
 create mode 100644 tests/xfs/780.out


diff --git a/tests/xfs/780 b/tests/xfs/780
new file mode 100755
index 00000000..464692ee
--- /dev/null
+++ b/tests/xfs/780
@@ -0,0 +1,207 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2021 Oracle.  All Rights Reserved.
+#
+# FS QA Test 780
+#
+# Functional test for commit:
+#
+# f38a032b165d ("xfs: fix I_DONTCACHE")
+#
+# Functional testing for the I_DONTCACHE inode flag, as set by the BULKSTAT
+# ioctl.  This flag neuters the inode cache's tendency to try to hang on to
+# incore inodes for a while after the last program closes the file, which
+# is helpful for filesystem scanners to avoid trashing the inode cache.
+#
+# However, the inode cache doesn't always honor the DONTCACHE behavior -- the
+# only time it really applies is to cache misses from a bulkstat scan.  If
+# any other threads accessed the inode before or immediately after the scan,
+# the DONTCACHE flag is ignored.  This includes other scans.
+#
+# Regrettably, there is no way to poke /only/ XFS inode reclamation directly,
+# so we're stuck with setting xfssyncd_centisecs to a low value and sleeping
+# while watching the internal inode cache counters.
+#
+. ./common/preamble
+_begin_fstest auto ioctl
+
+_cleanup()
+{
+	cd /
+	rm -r -f $tmp.*
+	test -n "$old_centisecs" && echo "$old_centisecs" > "$xfs_centisecs_file"
+}
+
+# Import common functions.
+. ./common/filter
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_require_xfs_io_command "bulkstat"
+_require_scratch
+
+# We require /sys/fs/xfs/$device/stats/stats to monitor per-filesystem inode
+# cache usage.
+_require_fs_sysfs stats/stats
+
+count_xfs_inode_objs() {
+	_get_fs_sysfs_attr $SCRATCH_DEV stats/stats | awk '/vnodes/ {print $2}'
+}
+
+dump_debug_info() {
+	echo "round $1 baseline: $baseline_count high: $high_count fresh: $fresh_count post: $post_count end: $end_count" >> $seqres.full
+}
+
+# Either of these need to be available to monitor slab usage
+xfs_ino_objcount_file=/sys/kernel/slab/xfs_inode/objects
+slabinfo_file=/proc/slabinfo
+if [ ! -r "$xfs_ino_objcount_file" ] && [ ! -r "$slabinfo_file" ]; then
+	_notrun "Cannot find xfs_inode slab count?"
+fi
+
+# Background reclamation of disused xfs inodes is scheduled for ($xfssyncd / 6)
+# centiseconds after the first inode is tagged for reclamation.  It's not great
+# to encode this implementation detail in a test like this, but there isn't
+# any means to trigger *only* inode cache reclaim -- actual memory pressure
+# can trigger the VFS to drop non-DONTCACHE inodes, which is not what we want.
+xfs_centisecs_file=/proc/sys/fs/xfs/xfssyncd_centisecs
+test -w "$xfs_centisecs_file" || _notrun "Cannot find xfssyncd_centisecs?"
+
+# Set the syncd knob to the minimum value 100cs (aka 1s) so that we don't have
+# to wait forever.
+old_centisecs="$(cat "$xfs_centisecs_file")"
+echo 100 > "$xfs_centisecs_file" || _notrun "Cannot adjust xfssyncd_centisecs?"
+delay_centisecs="$(cat "$xfs_centisecs_file")"
+
+# Sleep one second more than the xfssyncd delay to give background inode
+# reclaim enough time to run.
+sleep_seconds=$(( ( (99 + (delay_centisecs / 6) ) / 100) + 1))
+echo "Will sleep $sleep_seconds seconds to expire inodes" >> $seqres.full
+
+_scratch_mkfs >> $seqres.full
+_scratch_mount >> $seqres.full
+
+junkdir=$SCRATCH_MNT/$seq.junk
+
+# Sample the baseline count of cached inodes after a fresh remount.
+_scratch_cycle_mount
+baseline_count=$(count_xfs_inode_objs)
+
+# Create a junk directory with about a thousand files.
+nr_files=1024
+mkdir -p $junkdir
+for ((i = 0; i < nr_files; i++)); do
+	touch "$junkdir/$i"
+done
+new_files=$(find $junkdir | wc -l)
+echo "created $new_files files" >> $seqres.full
+_within_tolerance "new file count" $new_files $nr_files 5 -v
+
+# Sanity check: Make sure that all those new inodes are still in the cache.
+# We assume that memory limits are not so low that reclaim started for a bunch
+# of empty files.  We hope there will never be more than 100 metadata inodes
+# or automatic mount time scanners.
+high_count=$(count_xfs_inode_objs)
+echo "cached inodes: $high_count" >> $seqres.full
+_within_tolerance "inodes after creating files" $high_count $new_files 0 100 -v
+
+################
+# Round 1: Check DONTCACHE behavior when it is invoked once.  The inodes should
+# be reclaimed if we wait longer than the reclaim interval.
+echo "Round 1"
+
+_scratch_cycle_mount
+fresh_count=$(count_xfs_inode_objs)
+$XFS_IO_PROG -c 'bulkstat' $junkdir > /dev/null
+post_count=$(count_xfs_inode_objs)
+sleep $sleep_seconds
+end_count=$(count_xfs_inode_objs)
+dump_debug_info 1
+
+# Even with our greatly reduced reclaim timeout, the inodes should still be in
+# memory immediately after the bulkstat concludes.
+_within_tolerance "inodes after bulkstat" $post_count $high_count 5 -v
+
+# After we've given inode reclaim time to run, the inodes should no longer be
+# cached in memory, which means we should have the fresh count again.
+_within_tolerance "inodes after expire" $end_count $fresh_count 5 -v
+
+################
+# Round 2: Check DONTCACHE behavior when it is invoked multiple times in rapid
+# succession.  The inodes should remain in memory even after reclaim because
+# the cache notices repeat DONTCACHE hits and ignores them.
+echo "Round 2"
+
+_scratch_cycle_mount
+fresh_count=$(count_xfs_inode_objs)
+$XFS_IO_PROG -c 'bulkstat' $junkdir > /dev/null
+$XFS_IO_PROG -c 'bulkstat' $junkdir > /dev/null
+post_count=$(count_xfs_inode_objs)
+sleep $sleep_seconds
+end_count=$(count_xfs_inode_objs)
+dump_debug_info 2
+
+# Inodes should still be in memory immediately after the second bulkstat
+# concludes and after the reclaim interval.
+_within_tolerance "inodes after double bulkstat" $post_count $high_count 5 -v
+_within_tolerance "inodes after expire" $end_count $high_count 5 -v
+
+################
+# Round 3: Check DONTCACHE evictions when it is invoked repeatedly but with
+# enough time between scans for inode reclaim to remove the inodes.
+echo "Round 3"
+
+_scratch_cycle_mount
+fresh_count=$(count_xfs_inode_objs)
+$XFS_IO_PROG -c 'bulkstat' $junkdir > /dev/null
+sleep $sleep_seconds
+post_count=$(count_xfs_inode_objs)
+$XFS_IO_PROG -c 'bulkstat' $junkdir > /dev/null
+sleep $sleep_seconds
+end_count=$(count_xfs_inode_objs)
+dump_debug_info 3
+
+# Inodes should not still be cached after either scan and reclaim interval.
+_within_tolerance "inodes after slow bulkstat 1" $post_count $fresh_count 5 -v
+_within_tolerance "inodes after slow bulkstat 2" $end_count $fresh_count 5 -v
+
+################
+# Round 4: Check that DONTCACHE has no effect when all the files are read
+# immediately after a bulkstat.
+echo "Round 4"
+
+_scratch_cycle_mount
+fresh_count=$(count_xfs_inode_objs)
+$XFS_IO_PROG -c 'bulkstat' $junkdir > /dev/null
+find $junkdir -type f -print0 | xargs -0 cat > /dev/null
+post_count=$(count_xfs_inode_objs)
+sleep $sleep_seconds
+end_count=$(count_xfs_inode_objs)
+dump_debug_info 4
+
+# Inodes should still be cached after the scan/read and the reclaim interval.
+_within_tolerance "inodes after bulkstat/read" $post_count $high_count 5 -v
+_within_tolerance "inodes after reclaim" $end_count $high_count 5 -v
+
+################
+# Round 5: Check that DONTCACHE has no effect if the inodes were already in
+# cache due to reader programs.
+echo "Round 5"
+
+_scratch_cycle_mount
+fresh_count=$(count_xfs_inode_objs)
+find $junkdir -type f -print0 | xargs -0 cat > /dev/null
+$XFS_IO_PROG -c 'bulkstat' $junkdir > /dev/null
+post_count=$(count_xfs_inode_objs)
+sleep $sleep_seconds
+end_count=$(count_xfs_inode_objs)
+dump_debug_info 5
+
+# Inodes should still be cached after the read/scan and the reclaim interval.
+_within_tolerance "inodes after read/bulkstat" $post_count $high_count 5 -v
+_within_tolerance "inodes after reclaim" $end_count $high_count 5 -v
+
+status=0
+exit
diff --git a/tests/xfs/780.out b/tests/xfs/780.out
new file mode 100644
index 00000000..879c473e
--- /dev/null
+++ b/tests/xfs/780.out
@@ -0,0 +1,18 @@
+QA output created by 780
+new file count is in range
+inodes after creating files is in range
+Round 1
+inodes after bulkstat is in range
+inodes after expire is in range
+Round 2
+inodes after double bulkstat is in range
+inodes after expire is in range
+Round 3
+inodes after slow bulkstat 1 is in range
+inodes after slow bulkstat 2 is in range
+Round 4
+inodes after bulkstat/read is in range
+inodes after reclaim is in range
+Round 5
+inodes after read/bulkstat is in range
+inodes after reclaim is in range


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/4] xfs/108: sync filesystem before querying quota
  2021-09-01  0:12 [PATCHSET 0/4] fstests: exercise code changes in 5.15 Darrick J. Wong
  2021-09-01  0:12 ` [PATCH 1/4] generic: regression test for a FALLOC_FL_UNSHARE bug in XFS Darrick J. Wong
  2021-09-01  0:12 ` [PATCH 2/4] xfs: test DONTCACHE behavior with the inode cache Darrick J. Wong
@ 2021-09-01  0:12 ` Darrick J. Wong
  2021-09-01  0:12 ` [PATCH 4/4] xfs: regresion test for fsmap problems with realtime Darrick J. Wong
  3 siblings, 0 replies; 7+ messages in thread
From: Darrick J. Wong @ 2021-09-01  0:12 UTC (permalink / raw)
  To: djwong, guaneryu; +Cc: linux-xfs, fstests, guan

From: Darrick J. Wong <djwong@kernel.org>

The new deferred inactivation code is lazy about deallocating deleted
files, which means that we need to be more proactive about syncing the
filesystem after deleting things.  When reporting quotas, XFS only
flushes the deferred work if we query quota id 0, so we need the
explicit sync to ensure the quota numbers are not affected by laziness.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 tests/xfs/108 |    1 +
 1 file changed, 1 insertion(+)


diff --git a/tests/xfs/108 b/tests/xfs/108
index 8a102133..a3a4c8d4 100755
--- a/tests/xfs/108
+++ b/tests/xfs/108
@@ -47,6 +47,7 @@ test_accounting()
 	for file in $SCRATCH_MNT/{buffer,direct,mmap}; do
 		$here/src/lstat64 $file | head -3 | _filter_scratch
 	done
+	sync
 	$XFS_QUOTA_PROG -c "quota -hnb -$type $id" $QARGS | _filter_quota
 	$XFS_QUOTA_PROG -c "quota -hni -$type $id" $QARGS | _filter_quota
 	$XFS_QUOTA_PROG -c "quota -hnr -$type $id" $QARGS | _filter_quota


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/4] xfs: regresion test for fsmap problems with realtime
  2021-09-01  0:12 [PATCHSET 0/4] fstests: exercise code changes in 5.15 Darrick J. Wong
                   ` (2 preceding siblings ...)
  2021-09-01  0:12 ` [PATCH 3/4] xfs/108: sync filesystem before querying quota Darrick J. Wong
@ 2021-09-01  0:12 ` Darrick J. Wong
  2021-09-12 10:41   ` Eryu Guan
  3 siblings, 1 reply; 7+ messages in thread
From: Darrick J. Wong @ 2021-09-01  0:12 UTC (permalink / raw)
  To: djwong, guaneryu; +Cc: linux-xfs, fstests, guan

From: Darrick J. Wong <djwong@kernel.org>

This is a regression test for:

xfs: make xfs_rtalloc_query_range input parameters const
xfs: fix off-by-one error when the last rt extent is in use
xfs: make fsmap backend function key parameters const

In which we synthesize an XFS with a realtime volume and a special
realtime volume to trip the bugs fixed by all three patches that
resulted in incomplete fsmap output.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 tests/xfs/922     |  183 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/922.out |    2 +
 2 files changed, 185 insertions(+)
 create mode 100755 tests/xfs/922
 create mode 100644 tests/xfs/922.out


diff --git a/tests/xfs/922 b/tests/xfs/922
new file mode 100755
index 00000000..95304d57
--- /dev/null
+++ b/tests/xfs/922
@@ -0,0 +1,183 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2021 Oracle.  All Rights Reserved.
+#
+# FS QA Test 922
+#
+# Regression test for commits:
+#
+# c02f6529864a ("xfs: make xfs_rtalloc_query_range input parameters const")
+# 9ab72f222774 ("xfs: fix off-by-one error when the last rt extent is in use")
+# 7e1826e05ba6 ("xfs: make fsmap backend function key parameters const")
+#
+# These commits fix a bug in fsmap where the data device fsmap function would
+# corrupt the high key passed to the rt fsmap function if the data device
+# number is smaller than the rt device number and the data device itself is
+# smaller than the rt device.
+#
+. ./common/preamble
+_begin_fstest auto fsmap
+
+_cleanup()
+{
+	cd /
+	rm -r -f $tmp.*
+	_scratch_unmount
+	test -n "$ddloop" && _destroy_loop_device "$ddloop"
+	test -n "$rtloop" && _destroy_loop_device "$rtloop"
+	test -n "$ddfile" && rm -f "$ddfile"
+	test -n "$rtfile" && rm -f "$rtfile"
+	test -n "$old_use_external" && USE_EXTERNAL="$old_use_external"
+}
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_require_test
+
+# Synthesize data and rt volumes that as needed to trigger the bug
+ddfile=$TEST_DIR/data
+rtfile=$TEST_DIR/rt
+rm -f "$rtfile" "$ddfile"
+
+ddsize="$((100 * 1048576))"
+rtsize="$((200 * 1048576))"
+
+truncate -s $ddsize $ddfile
+truncate -s $rtsize $rtfile
+ddloop="$(_create_loop_device $ddfile)"
+rtloop="$(_create_loop_device $rtfile)"
+
+test -z "$ddloop" && _fail "Could not create data loop device"
+test -z "$rtloop" && _fail "Could not create rt loop device"
+
+# dataloop must have a smaller device number than rtloop because fsmap sorts
+# the output by device number
+ddmajor=$(stat -c '%t' "$ddloop")
+rtmajor=$(stat -c '%t' "$rtloop")
+test $ddmajor -le $rtmajor || \
+	_notrun "Data loopdev major $ddmajor larger than rt major $rtmajor"
+
+ddminor=$(stat -c '%T' "$ddloop")
+rtminor=$(stat -c '%T' "$rtloop")
+test $ddmajor -le $rtmajor || \
+	_notrun "Data loopdev minor $ddminor larger than rt minor $rtminor"
+
+# Inject our custom-built devices as an rt-capable scratch device.
+# We avoid touching "require_scratch" so that post-test fsck will not try to
+# run on our synthesized scratch device.
+old_use_external="$USE_EXTERNAL"
+USE_EXTERNAL=yes
+SCRATCH_RTDEV="$rtloop"
+SCRATCH_DEV="$ddloop"
+
+_scratch_mkfs >> $seqres.full
+_try_scratch_mount >> $seqres.full || \
+	_notrun "mount with injected rt device failed"
+
+# Create a file that we'll use to seed fsmap entries for the rt device,
+# and force the root directory to create only data device files
+rtfile="$SCRATCH_MNT/rtfile"
+$XFS_IO_PROG -R -f -c 'stat -v' $rtfile | grep -q 'fsxattr.*xflags.*realtime' || \
+	_notrun "could not create realtime file"
+$XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+rtextsize="$(stat -c '%o' $rtfile)"
+
+# Make sure the data device is smaller than the rt device by at least a few
+# realtime extents.
+ddbytes="$(stat -f -c '%S * %b' $SCRATCH_MNT | bc)"
+rtbytes="$(stat -f -c '%S * %b' $rtfile | bc)"
+
+test "$ddbytes" -lt "$((rtbytes + (10 * rtextsize) ))" || \
+	echo "data device ($ddbytes) has more bytes than rt ($rtbytes)"
+
+# Craft the layout of the sole realtime file in such a way that the only
+# allocated space on the realtime device is at a physical disk address that is
+# higher than the size of the data device.  For realtime files this is really
+# easy because fallocate for the first rt file always starts allocating at
+# physical offset zero.
+alloc_rtx="$((rtbytes / rtextsize))"
+$XFS_IO_PROG -c "falloc 0 $((alloc_rtx * rtextsize))" $rtfile
+
+expected_end="$(( (alloc_rtx * rtextsize - 1) / 512 ))"
+
+# Print extent mapping of rtfile in format:
+# file_offset file_end physical_offset physical_end
+rtfile_exts() {
+	$XFS_IO_PROG -c 'bmap -elp' $rtfile | \
+		egrep -v '(^/|EXT:|hole)' | \
+		tr ':.[]' '    ' | \
+		while read junk foff fend physoff physend junk; do
+			echo "$foff $fend $physoff $physend"
+		done
+}
+
+# Make sure that we actually got the entire device.
+rtfile_exts | awk -v end=$expected_end '
+{
+	if ($3 != 0)
+		printf("%s: unexpected physical offset %s, wanted 0\n", $0, $3);
+	if ($4 != end)
+		printf("%s: unexpected physical end %s, wanted %d\n", $0, $4, end);
+}'
+
+# Now punch out a range that is slightly larger than the size of the data
+# device.
+punch_bytes="$((ddsize + rtextsize))"
+punch_rtx="$((punch_bytes / rtextsize))"
+$XFS_IO_PROG -c "fpunch 0 $((punch_rtx * rtextsize))" $rtfile
+
+expected_offset="$((punch_rtx * rtextsize / 512))"
+
+echo "rtfile should have physical extent from $expected_offset to $expected_end sectors" >> $seqres.full
+
+# Make sure that the realtime file now has only one extent at the end of the
+# realtime device
+rtfile_exts | awk -v offset=$expected_offset -v end=$expected_end '
+{
+	if ($3 != offset)
+		printf("%s: unexpected physical offset %s, wanted %d\n", $0, $3, offset);
+	if ($4 != end)
+		printf("%s: unexpected physical end %s, wanted %d\n", $0, $4, end);
+}'
+
+$XFS_IO_PROG -c 'bmap -elpv' $rtfile >> $seqres.full
+$XFS_IO_PROG -c 'fsmap' $SCRATCH_MNT >> $seqres.full
+
+fsmap() {
+	$XFS_IO_PROG -c 'fsmap' $SCRATCH_MNT | \
+		grep -v 'EXT:' | \
+		tr ':.[]' '    ' | \
+		while read junk major minor physoff physend junk; do
+			echo "$major:$minor $physoff $physend"
+		done
+}
+
+# Check the fsmap output contains a record for the realtime device at a
+# physical offset higher than end of the data device and corresponding to the
+# beginning of the non-punched area.
+fsmap | awk -v dev="$rtmajor:$rtminor" -v offset=$expected_offset -v end=$expected_end '
+BEGIN {
+	found_start = 0;
+	found_end = 0;
+}
+{
+	if ($1 == dev && $2 >= offset) {
+		found_start = 1;
+		if ($3 == end) {
+			found_end = 1;
+		}
+	}
+}
+END {
+	if (found_start == 0)
+		printf("No fsmap record for rtdev %s above sector %d\n", dev, offset);
+	if (found_end == 0)
+		printf("No fsmap record for rtdev %s ending at sector %d\n", dev, end);
+}'
+
+echo Silence is golden
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/922.out b/tests/xfs/922.out
new file mode 100644
index 00000000..3f90539d
--- /dev/null
+++ b/tests/xfs/922.out
@@ -0,0 +1,2 @@
+QA output created by 922
+Silence is golden


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/4] xfs: regresion test for fsmap problems with realtime
  2021-09-01  0:12 ` [PATCH 4/4] xfs: regresion test for fsmap problems with realtime Darrick J. Wong
@ 2021-09-12 10:41   ` Eryu Guan
  2021-09-13 18:26     ` Darrick J. Wong
  0 siblings, 1 reply; 7+ messages in thread
From: Eryu Guan @ 2021-09-12 10:41 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: guaneryu, linux-xfs, fstests

On Tue, Aug 31, 2021 at 05:12:26PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> This is a regression test for:
> 
> xfs: make xfs_rtalloc_query_range input parameters const
> xfs: fix off-by-one error when the last rt extent is in use
> xfs: make fsmap backend function key parameters const
> 
> In which we synthesize an XFS with a realtime volume and a special
> realtime volume to trip the bugs fixed by all three patches that
> resulted in incomplete fsmap output.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>  tests/xfs/922     |  183 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/xfs/922.out |    2 +
>  2 files changed, 185 insertions(+)
>  create mode 100755 tests/xfs/922
>  create mode 100644 tests/xfs/922.out
> 
> 
> diff --git a/tests/xfs/922 b/tests/xfs/922
> new file mode 100755
> index 00000000..95304d57
> --- /dev/null
> +++ b/tests/xfs/922
> @@ -0,0 +1,183 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2021 Oracle.  All Rights Reserved.
> +#
> +# FS QA Test 922
> +#
> +# Regression test for commits:
> +#
> +# c02f6529864a ("xfs: make xfs_rtalloc_query_range input parameters const")
> +# 9ab72f222774 ("xfs: fix off-by-one error when the last rt extent is in use")
> +# 7e1826e05ba6 ("xfs: make fsmap backend function key parameters const")
> +#
> +# These commits fix a bug in fsmap where the data device fsmap function would
> +# corrupt the high key passed to the rt fsmap function if the data device
> +# number is smaller than the rt device number and the data device itself is
> +# smaller than the rt device.
> +#
> +. ./common/preamble
> +_begin_fstest auto fsmap
> +
> +_cleanup()
> +{
> +	cd /
> +	rm -r -f $tmp.*
> +	_scratch_unmount
> +	test -n "$ddloop" && _destroy_loop_device "$ddloop"
> +	test -n "$rtloop" && _destroy_loop_device "$rtloop"
> +	test -n "$ddfile" && rm -f "$ddfile"
> +	test -n "$rtfile" && rm -f "$rtfile"
> +	test -n "$old_use_external" && USE_EXTERNAL="$old_use_external"
> +}
> +
> +# real QA test starts here
> +
> +# Modify as appropriate.
> +_supported_fs generic

_supported_fs xfs

> +_require_test

Also need the following _require rules

_require_loop
_require_xfs_io_command "falloc"
_require_xfs_io_command "fpunch"
_require_xfs_io_command "fsmap"

I've fixed them all on commit.

Thanks,
Eryu

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/4] xfs: regresion test for fsmap problems with realtime
  2021-09-12 10:41   ` Eryu Guan
@ 2021-09-13 18:26     ` Darrick J. Wong
  0 siblings, 0 replies; 7+ messages in thread
From: Darrick J. Wong @ 2021-09-13 18:26 UTC (permalink / raw)
  To: Eryu Guan; +Cc: guaneryu, linux-xfs, fstests

On Sun, Sep 12, 2021 at 06:41:22PM +0800, Eryu Guan wrote:
> On Tue, Aug 31, 2021 at 05:12:26PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > This is a regression test for:
> > 
> > xfs: make xfs_rtalloc_query_range input parameters const
> > xfs: fix off-by-one error when the last rt extent is in use
> > xfs: make fsmap backend function key parameters const
> > 
> > In which we synthesize an XFS with a realtime volume and a special
> > realtime volume to trip the bugs fixed by all three patches that
> > resulted in incomplete fsmap output.
> > 
> > Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> > ---
> >  tests/xfs/922     |  183 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  tests/xfs/922.out |    2 +
> >  2 files changed, 185 insertions(+)
> >  create mode 100755 tests/xfs/922
> >  create mode 100644 tests/xfs/922.out
> > 
> > 
> > diff --git a/tests/xfs/922 b/tests/xfs/922
> > new file mode 100755
> > index 00000000..95304d57
> > --- /dev/null
> > +++ b/tests/xfs/922
> > @@ -0,0 +1,183 @@
> > +#! /bin/bash
> > +# SPDX-License-Identifier: GPL-2.0
> > +# Copyright (c) 2021 Oracle.  All Rights Reserved.
> > +#
> > +# FS QA Test 922
> > +#
> > +# Regression test for commits:
> > +#
> > +# c02f6529864a ("xfs: make xfs_rtalloc_query_range input parameters const")
> > +# 9ab72f222774 ("xfs: fix off-by-one error when the last rt extent is in use")
> > +# 7e1826e05ba6 ("xfs: make fsmap backend function key parameters const")
> > +#
> > +# These commits fix a bug in fsmap where the data device fsmap function would
> > +# corrupt the high key passed to the rt fsmap function if the data device
> > +# number is smaller than the rt device number and the data device itself is
> > +# smaller than the rt device.
> > +#
> > +. ./common/preamble
> > +_begin_fstest auto fsmap
> > +
> > +_cleanup()
> > +{
> > +	cd /
> > +	rm -r -f $tmp.*
> > +	_scratch_unmount
> > +	test -n "$ddloop" && _destroy_loop_device "$ddloop"
> > +	test -n "$rtloop" && _destroy_loop_device "$rtloop"
> > +	test -n "$ddfile" && rm -f "$ddfile"
> > +	test -n "$rtfile" && rm -f "$rtfile"
> > +	test -n "$old_use_external" && USE_EXTERNAL="$old_use_external"
> > +}
> > +
> > +# real QA test starts here
> > +
> > +# Modify as appropriate.
> > +_supported_fs generic
> 
> _supported_fs xfs
> 
> > +_require_test
> 
> Also need the following _require rules
> 
> _require_loop
> _require_xfs_io_command "falloc"
> _require_xfs_io_command "fpunch"
> _require_xfs_io_command "fsmap"
> 
> I've fixed them all on commit.

Thank you!

--D

> 
> Thanks,
> Eryu

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-13 18:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01  0:12 [PATCHSET 0/4] fstests: exercise code changes in 5.15 Darrick J. Wong
2021-09-01  0:12 ` [PATCH 1/4] generic: regression test for a FALLOC_FL_UNSHARE bug in XFS Darrick J. Wong
2021-09-01  0:12 ` [PATCH 2/4] xfs: test DONTCACHE behavior with the inode cache Darrick J. Wong
2021-09-01  0:12 ` [PATCH 3/4] xfs/108: sync filesystem before querying quota Darrick J. Wong
2021-09-01  0:12 ` [PATCH 4/4] xfs: regresion test for fsmap problems with realtime Darrick J. Wong
2021-09-12 10:41   ` Eryu Guan
2021-09-13 18:26     ` Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).