fstests.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] xfstests: random fixes
@ 2020-11-11  0:42 Darrick J. Wong
  2020-11-11  0:42 ` [PATCH 1/6] common: extract rt extent size for _get_file_block_size Darrick J. Wong
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Darrick J. Wong @ 2020-11-11  0:42 UTC (permalink / raw)
  To: darrick.wong, guaneryu; +Cc: linux-xfs, fstests

Hi all,

This series contains random fixes to fstests.

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

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=random-fixes

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=random-fixes

fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=random-fixes
---
 check             |   26 +++++++++++++++++++++++++-
 common/populate   |   11 +++++++++++
 common/rc         |   29 ++++++++++++++++++-----------
 common/xfs        |   20 ++++++++++++++++++++
 tests/ext4/032    |    2 +-
 tests/generic/157 |    2 +-
 tests/generic/175 |    2 +-
 tests/shared/032  |    2 +-
 tests/xfs/033     |    2 +-
 tests/xfs/129     |    2 +-
 tests/xfs/169     |    2 +-
 tests/xfs/208     |    2 +-
 tests/xfs/336     |    2 +-
 tests/xfs/344     |    2 +-
 tests/xfs/345     |    2 +-
 15 files changed, 85 insertions(+), 23 deletions(-)


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

* [PATCH 1/6] common: extract rt extent size for _get_file_block_size
  2020-11-11  0:42 [PATCH 0/6] xfstests: random fixes Darrick J. Wong
@ 2020-11-11  0:42 ` Darrick J. Wong
  2020-11-11  4:23   ` Chandan Babu R
  2020-11-11  0:43 ` [PATCH 2/6] check: run tests in a systemd scope for mandatory test cleanup Darrick J. Wong
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Darrick J. Wong @ 2020-11-11  0:42 UTC (permalink / raw)
  To: darrick.wong, guaneryu; +Cc: linux-xfs, fstests

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

_get_file_block_size is intended to return the size (in bytes) of the
fundamental allocation unit for a file.  This is required for remapping
operations like fallocate and reflink, which can only operate on
allocation units.  Since the XFS realtime volume can be configure for
allocation units larger than 1 fs block, we need to factor that in here.

Note that ext* with bigalloc does not allocations to be aligned to the
cluster size, so no update is needed there.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 common/rc  |   13 ++++++++++---
 common/xfs |   20 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 3 deletions(-)


diff --git a/common/rc b/common/rc
index 65ebfe20..019b9b2b 100644
--- a/common/rc
+++ b/common/rc
@@ -3975,11 +3975,18 @@ _get_file_block_size()
 		echo "Missing mount point argument for _get_file_block_size"
 		exit 1
 	fi
-	if [ "$FSTYP" = "ocfs2" ]; then
+
+	case "$FSTYP" in
+	"ocfs2")
 		stat -c '%o' $1
-	else
+		;;
+	"xfs")
+		_xfs_get_file_block_size $1
+		;;
+	*)
 		_get_block_size $1
-	fi
+		;;
+	esac
 }
 
 # Get the minimum block size of an fs.
diff --git a/common/xfs b/common/xfs
index 79dab058..3f5c14ba 100644
--- a/common/xfs
+++ b/common/xfs
@@ -174,6 +174,26 @@ _scratch_mkfs_xfs()
 	return $mkfs_status
 }
 
+# Get the size of an allocation unit of a file.  Normally this is just the
+# block size of the file, but for realtime files, this is the realtime extent
+# size.
+_xfs_get_file_block_size()
+{
+	local path="$1"
+
+	if ! ($XFS_IO_PROG -c "stat -v" "$path" 2>&1 | egrep -q '(rt-inherit|realtime)'); then
+		_get_block_size "$path"
+		return
+	fi
+
+	# Otherwise, call xfs_info until we find a mount point or the root.
+	path="$(readlink -m "$path")"
+	while ! $XFS_INFO_PROG "$path" &>/dev/null && [ "$path" != "/" ]; do
+		path="$(dirname "$path")"
+	done
+	$XFS_INFO_PROG "$path" | grep realtime | sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g'
+}
+
 # xfs_check script is planned to be deprecated. But, we want to
 # be able to invoke "xfs_check" behavior in xfstests in order to
 # maintain the current verification levels.


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

* [PATCH 2/6] check: run tests in a systemd scope for mandatory test cleanup
  2020-11-11  0:42 [PATCH 0/6] xfstests: random fixes Darrick J. Wong
  2020-11-11  0:42 ` [PATCH 1/6] common: extract rt extent size for _get_file_block_size Darrick J. Wong
@ 2020-11-11  0:43 ` Darrick J. Wong
  2020-11-22 14:35   ` Eryu Guan
  2020-11-11  0:43 ` [PATCH 3/6] common/populate: make sure _scratch_xfs_populate puts its files on the data device Darrick J. Wong
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Darrick J. Wong @ 2020-11-11  0:43 UTC (permalink / raw)
  To: darrick.wong, guaneryu; +Cc: linux-xfs, fstests

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

TLDR: If systemd is available, run each test in its own temporary
systemd scope.  This enables the test harness to forcibly clean up all
of the test's child processes (if it does not do so itself) so that we
can move into the post-test unmount and check cleanly.

I frequently run fstests in "low" memory situations (2GB!) to force the
kernel to do interesting things.  There are a few tests like generic/224
and generic/561 that put processes in the background and occasionally
trigger the OOM killer.  Most of the time the OOM killer correctly
shoots down fsstress or duperemove, but once in a while it's stupid
enough to shoot down the test control process (i.e. tests/generic/224)
instead.  fsstress is still running in the background, and the one
process that knew about that is dead.

When the control process dies, ./check moves on to the post-test fsck,
which fails because fsstress is still running and we can't unmount.
After fsck fails, ./check moves on to the next test, which fails because
fsstress is /still/ writing to the filesystem and we can't unmount or
format.

The end result is that that one OOM kill causes cascading test failures,
and I have to re-start fstests to see if I get a clean(er) run.

So, the solution I present in this patch is to teach ./check to try to
run the test script in a systemd scope.  If that succeeds, ./check will
tell systemd to kill the scope when the test script exits and returns
control to ./check.  Concretely, this means that systemd creates a new
cgroup, stuffs the processes in that cgroup, and when we kill the scope,
systemd kills all the processes in that cgroup and deletes the cgroup.

The end result is that fstests now has an easy way to ensure that /all/
child processes of a test are dead before we try to unmount the test and
scratch devices.  I've designed this to be optional, because not
everyone does or wants or likes to run systemd, but it makes QA easier.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 check |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)


diff --git a/check b/check
index 5072dd82..83f6fc8b 100755
--- a/check
+++ b/check
@@ -521,6 +521,12 @@ _expunge_test()
 	return 0
 }
 
+# Can we run systemd scopes?
+HAVE_SYSTEMD_SCOPES=
+systemctl reset-failed "fstests-check" &>/dev/null
+systemd-run --quiet --unit "fstests-check" --scope bash -c "exit 77" &> /dev/null
+test $? -eq 77 && HAVE_SYSTEMD_SCOPES=yes
+
 # Make the check script unattractive to the OOM killer...
 OOM_SCORE_ADJ="/proc/self/oom_score_adj"
 test -w ${OOM_SCORE_ADJ} && echo -1000 > ${OOM_SCORE_ADJ}
@@ -528,8 +534,26 @@ test -w ${OOM_SCORE_ADJ} && echo -1000 > ${OOM_SCORE_ADJ}
 # ...and make the tests themselves somewhat more attractive to it, so that if
 # the system runs out of memory it'll be the test that gets killed and not the
 # test framework.
+#
+# If systemd is available, run the entire test script in a scope so that we can
+# kill all subprocesses of the test if it fails to clean up after itself.  This
+# is essential for ensuring that the post-test unmount succeeds.  Note that
+# systemd doesn't automatically remove transient scopes that fail to terminate
+# when systemd tells them to terminate (e.g. programs stuck in D state when
+# systemd sends SIGKILL), so we use reset-failed to tear down the scope.
 _run_seq() {
-	bash -c "test -w ${OOM_SCORE_ADJ} && echo 250 > ${OOM_SCORE_ADJ}; exec ./$seq"
+	local cmd=(bash -c "test -w ${OOM_SCORE_ADJ} && echo 250 > ${OOM_SCORE_ADJ}; exec ./$seq")
+
+	if [ -n "${HAVE_SYSTEMD_SCOPES}" ]; then
+		local unit="$(systemd-escape "fs$seq").scope"
+		systemctl reset-failed "${unit}" &> /dev/null
+		systemd-run --quiet --unit "${unit}" --scope "${cmd[@]}"
+		res=$?
+		systemctl stop "${unit}" &> /dev/null
+		return "${res}"
+	else
+		"${cmd[@]}"
+	fi
 }
 
 _detect_kmemleak


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

* [PATCH 3/6] common/populate: make sure _scratch_xfs_populate puts its files on the data device
  2020-11-11  0:42 [PATCH 0/6] xfstests: random fixes Darrick J. Wong
  2020-11-11  0:42 ` [PATCH 1/6] common: extract rt extent size for _get_file_block_size Darrick J. Wong
  2020-11-11  0:43 ` [PATCH 2/6] check: run tests in a systemd scope for mandatory test cleanup Darrick J. Wong
@ 2020-11-11  0:43 ` Darrick J. Wong
  2020-11-11  0:43 ` [PATCH 4/6] misc: fix $MKFS_PROG.$FSTYP usage treewide Darrick J. Wong
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Darrick J. Wong @ 2020-11-11  0:43 UTC (permalink / raw)
  To: darrick.wong, guaneryu; +Cc: linux-xfs, fstests

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

Make sure that _scratch_xfs_populate always installs its files on the
data device even if the test config selects rt by default.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 common/populate |   11 +++++++++++
 1 file changed, 11 insertions(+)


diff --git a/common/populate b/common/populate
index 0b036051..f4ad8669 100644
--- a/common/populate
+++ b/common/populate
@@ -154,6 +154,16 @@ _scratch_xfs_populate() {
 
 	_populate_xfs_qmount_option
 	_scratch_mount
+
+	# We cannot directly force the filesystem to create the metadata
+	# structures we want; we can only achieve this indirectly by carefully
+	# crafting files and a directory tree.  Therefore, we must have exact
+	# control over the layout and device selection of all files created.
+	# Clear the rtinherit flag on the root directory so that files are
+	# always created on the data volume regardless of MKFS_OPTIONS.  We can
+	# set the realtime flag when needed.
+	$XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+
 	blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
 	dblksz="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep naming.*bsize | sed -e 's/^.*bsize=//g' -e 's/\([0-9]*\).*$/\1/g')"
 	crc="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep crc= | sed -e 's/^.*crc=//g' -e 's/\([0-9]*\).*$/\1/g')"
@@ -306,6 +316,7 @@ _scratch_xfs_populate() {
 	if [ $is_rmapbt -gt 0 ] && [ $is_rt -gt 0 ]; then
 		echo "+ rtrmapbt btree"
 		nr="$((blksz * 2 / 32))"
+		$XFS_IO_PROG -R -f -c 'truncate 0' "${SCRATCH_MNT}/RTRMAPBT"
 		__populate_create_file $((blksz * nr)) "${SCRATCH_MNT}/RTRMAPBT"
 	fi
 


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

* [PATCH 4/6] misc: fix $MKFS_PROG.$FSTYP usage treewide
  2020-11-11  0:42 [PATCH 0/6] xfstests: random fixes Darrick J. Wong
                   ` (2 preceding siblings ...)
  2020-11-11  0:43 ` [PATCH 3/6] common/populate: make sure _scratch_xfs_populate puts its files on the data device Darrick J. Wong
@ 2020-11-11  0:43 ` Darrick J. Wong
  2020-11-11  0:43 ` [PATCH 5/6] misc: fix _get_file_block_size usage Darrick J. Wong
  2020-11-11  0:43 ` [PATCH 6/6] xfs/033: use _scratch_xfs_db wrapper Darrick J. Wong
  5 siblings, 0 replies; 9+ messages in thread
From: Darrick J. Wong @ 2020-11-11  0:43 UTC (permalink / raw)
  To: darrick.wong, guaneryu; +Cc: linux-xfs, fstests

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

Replace all the $MKFS_PROG.$FSTYP invocations with $MKFS_PROG -t $FSTYP.
The mkfs wrapper binary knows how to search the user's $PATH to find the
appropriate mkfs delegate, which the author uses to switch between
development and distro versions of various tools.

Unfortunately, using "$MKFS_PROG.$FSTYP" means that the shell only looks
in the same directory as the mkfs wrapper, which means that we can end
up mixing different tool versions when this is the case.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 common/rc        |   16 ++++++++--------
 tests/ext4/032   |    2 +-
 tests/shared/032 |    2 +-
 3 files changed, 10 insertions(+), 10 deletions(-)


diff --git a/common/rc b/common/rc
index 019b9b2b..9b10d455 100644
--- a/common/rc
+++ b/common/rc
@@ -987,7 +987,7 @@ _scratch_mkfs_sized()
 		fi
 		;;
 	ext2|ext3|ext4|ext4dev)
-		${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
+		${MKFS_PROG} -t $FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
 		;;
 	gfs2)
 		# mkfs.gfs2 doesn't automatically shrink journal files on small
@@ -1002,10 +1002,10 @@ _scratch_mkfs_sized()
 			(( journal_size >= min_journal_size )) || journal_size=$min_journal_size
 			MKFS_OPTIONS="-J $journal_size $MKFS_OPTIONS"
 		fi
-		${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV $blocks
+		${MKFS_PROG} -t $FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV $blocks
 		;;
 	ocfs2)
-		yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
+		yes | ${MKFS_PROG} -t $FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
 		;;
 	udf)
 		$MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
@@ -1019,10 +1019,10 @@ _scratch_mkfs_sized()
 		$MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
 		;;
 	jfs)
-		${MKFS_PROG}.$FSTYP $MKFS_OPTIONS $SCRATCH_DEV $blocks
+		${MKFS_PROG} -t $FSTYP $MKFS_OPTIONS $SCRATCH_DEV $blocks
 		;;
 	reiserfs)
-		${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
+		${MKFS_PROG} -t $FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
 		;;
 	reiser4)
 		# mkfs.resier4 requires size in KB as input for creating filesystem
@@ -1101,13 +1101,13 @@ _scratch_mkfs_blocksized()
 	_scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
 	;;
     ext2|ext3|ext4)
-	${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
+	${MKFS_PROG} -t $FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
 	;;
     gfs2)
-	${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV
+	${MKFS_PROG} -t $FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV
 	;;
     ocfs2)
-	yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize -C $blocksize $SCRATCH_DEV
+	yes | ${MKFS_PROG} -t $FSTYP -F $MKFS_OPTIONS -b $blocksize -C $blocksize $SCRATCH_DEV
 	;;
     *)
 	_notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
diff --git a/tests/ext4/032 b/tests/ext4/032
index c63e7034..4e8dac42 100755
--- a/tests/ext4/032
+++ b/tests/ext4/032
@@ -46,7 +46,7 @@ ext4_online_resize()
 	echo "+++ create fs on image file $original_size" | \
 		tee -a $seqres.full
 
-	${MKFS_PROG}.${FSTYP} -F -O bigalloc,resize_inode -C $CLUSTER_SIZ \
+	${MKFS_PROG} -t ${FSTYP} -F -O bigalloc,resize_inode -C $CLUSTER_SIZ \
 		-b $BLK_SIZ ${LOOP_DEVICE} $original_size >> \
 		$seqres.full 2>&1 || _fail "mkfs failed"
 
diff --git a/tests/shared/032 b/tests/shared/032
index 40d27898..00ae6860 100755
--- a/tests/shared/032
+++ b/tests/shared/032
@@ -67,7 +67,7 @@ do
 	if [ $? -eq 0 ] ; then
 		# next, ensure we don't overwrite it
 		echo "=== Attempting $FSTYP overwrite of $fs..." >>$seqres.full
-		${MKFS_PROG}.$FSTYP $SCRATCH_DEV >>$seqres.full 2>&1
+		${MKFS_PROG} -t $FSTYP $SCRATCH_DEV >>$seqres.full 2>&1
 
 		[ $? -eq 0 ] && echo "Failed - overwrote fs type ${fs}!"
 	else


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

* [PATCH 5/6] misc: fix _get_file_block_size usage
  2020-11-11  0:42 [PATCH 0/6] xfstests: random fixes Darrick J. Wong
                   ` (3 preceding siblings ...)
  2020-11-11  0:43 ` [PATCH 4/6] misc: fix $MKFS_PROG.$FSTYP usage treewide Darrick J. Wong
@ 2020-11-11  0:43 ` Darrick J. Wong
  2020-11-11  0:43 ` [PATCH 6/6] xfs/033: use _scratch_xfs_db wrapper Darrick J. Wong
  5 siblings, 0 replies; 9+ messages in thread
From: Darrick J. Wong @ 2020-11-11  0:43 UTC (permalink / raw)
  To: darrick.wong, guaneryu; +Cc: linux-xfs, fstests

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

Fix these tests that rely on the allocation unit size of a file, which
might not necessarily be the fs block size.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 tests/generic/157 |    2 +-
 tests/generic/175 |    2 +-
 tests/xfs/129     |    2 +-
 tests/xfs/169     |    2 +-
 tests/xfs/208     |    2 +-
 tests/xfs/336     |    2 +-
 tests/xfs/344     |    2 +-
 tests/xfs/345     |    2 +-
 8 files changed, 8 insertions(+), 8 deletions(-)


diff --git a/tests/generic/157 b/tests/generic/157
index 5ec8999e..379c38b9 100755
--- a/tests/generic/157
+++ b/tests/generic/157
@@ -46,7 +46,7 @@ testdir2=$SCRATCH_MNT/test-$seq
 mkdir $testdir2
 
 echo "Create the original files"
-blksz="$(_get_block_size $testdir1)"
+blksz="$(_get_file_block_size $testdir1)"
 blks=1000
 margin='7%'
 sz=$((blksz * blks))
diff --git a/tests/generic/175 b/tests/generic/175
index f1b73522..436d2cca 100755
--- a/tests/generic/175
+++ b/tests/generic/175
@@ -41,7 +41,7 @@ testdir="$SCRATCH_MNT/test-$seq"
 mkdir "$testdir"
 
 echo "Create a one block file"
-blksz="$(_get_block_size $testdir)"
+blksz="$(_get_file_block_size $testdir)"
 _pwrite_byte 0x61 0 $blksz "$testdir/file1" >> "$seqres.full"
 
 fnr=19
diff --git a/tests/xfs/129 b/tests/xfs/129
index 5e348805..78baf5c4 100755
--- a/tests/xfs/129
+++ b/tests/xfs/129
@@ -44,7 +44,7 @@ mkdir $testdir
 metadump_file=$TEST_DIR/${seq}_metadump
 
 echo "Create the original file blocks"
-blksz="$(_get_block_size $testdir)"
+blksz="$(_get_file_block_size $testdir)"
 nr_blks=$((4 * blksz / 12))
 _pwrite_byte 0x61 0 $((blksz * nr_blks)) $testdir/file1 >> $seqres.full
 
diff --git a/tests/xfs/169 b/tests/xfs/169
index 44577fbf..2051091f 100755
--- a/tests/xfs/169
+++ b/tests/xfs/169
@@ -42,7 +42,7 @@ testdir=$SCRATCH_MNT/test-$seq
 mkdir $testdir
 
 echo "Create the original file blocks"
-blksz="$(_get_block_size $testdir)"
+blksz="$(_get_file_block_size $testdir)"
 nr_blks=$((8 * blksz / 12))
 
 for i in 1 2 x; do
diff --git a/tests/xfs/208 b/tests/xfs/208
index 104763d5..2a899fc0 100755
--- a/tests/xfs/208
+++ b/tests/xfs/208
@@ -56,7 +56,7 @@ bufnr=16
 bufsize=$((blksz * bufnr))
 
 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
-real_blksz=$(_get_block_size $testdir)
+real_blksz=$(_get_file_block_size $testdir)
 internal_blks=$((filesize / real_blksz))
 
 echo "Create the original files"
diff --git a/tests/xfs/336 b/tests/xfs/336
index 5f32f060..a006938d 100755
--- a/tests/xfs/336
+++ b/tests/xfs/336
@@ -39,7 +39,7 @@ _scratch_mkfs | _filter_mkfs 2>$tmp.mkfs >/dev/null
 . $tmp.mkfs
 cat $tmp.mkfs > "$seqres.full" 2>&1
 _scratch_mount
-blksz="$(_get_block_size $SCRATCH_MNT)"
+blksz="$(_get_file_block_size $SCRATCH_MNT)"
 
 metadump_file=$TEST_DIR/${seq}_metadump
 rm -rf $metadump_file
diff --git a/tests/xfs/344 b/tests/xfs/344
index b00541f6..46868fa5 100755
--- a/tests/xfs/344
+++ b/tests/xfs/344
@@ -55,7 +55,7 @@ bufnr=16
 bufsize=$((blksz * bufnr))
 
 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
-real_blksz=$(_get_block_size $testdir)
+real_blksz=$(_get_file_block_size $testdir)
 internal_blks=$((filesize / real_blksz))
 
 echo "Create the original files"
diff --git a/tests/xfs/345 b/tests/xfs/345
index ceb1dce9..4204cc22 100755
--- a/tests/xfs/345
+++ b/tests/xfs/345
@@ -53,7 +53,7 @@ bufnr=16
 bufsize=$((blksz * bufnr))
 
 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
-real_blksz=$(_get_block_size $testdir)
+real_blksz=$(_get_file_block_size $testdir)
 internal_blks=$((filesize / real_blksz))
 
 echo "Create the original files"


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

* [PATCH 6/6] xfs/033: use _scratch_xfs_db wrapper
  2020-11-11  0:42 [PATCH 0/6] xfstests: random fixes Darrick J. Wong
                   ` (4 preceding siblings ...)
  2020-11-11  0:43 ` [PATCH 5/6] misc: fix _get_file_block_size usage Darrick J. Wong
@ 2020-11-11  0:43 ` Darrick J. Wong
  5 siblings, 0 replies; 9+ messages in thread
From: Darrick J. Wong @ 2020-11-11  0:43 UTC (permalink / raw)
  To: darrick.wong, guaneryu; +Cc: linux-xfs, fstests

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

Use the wrapper instead of open-coding the call.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 tests/xfs/033 |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


diff --git a/tests/xfs/033 b/tests/xfs/033
index 372426b7..a1311dbe 100755
--- a/tests/xfs/033
+++ b/tests/xfs/033
@@ -76,7 +76,7 @@ if [ $_fs_has_crcs -eq 1 ]; then
 fi
 _link_out_file_named $seqfull.out "$FEATURES"
 
-`xfs_db -r -c sb -c p $SCRATCH_DEV | grep 'ino = ' | \
+`_scratch_xfs_db -r -c sb -c p | grep 'ino = ' | \
 	sed -e 's/ //g' -e 's/^/export /'`
 
 # check we won't get any quota inodes setup on mount


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

* Re: [PATCH 1/6] common: extract rt extent size for _get_file_block_size
  2020-11-11  0:42 ` [PATCH 1/6] common: extract rt extent size for _get_file_block_size Darrick J. Wong
@ 2020-11-11  4:23   ` Chandan Babu R
  0 siblings, 0 replies; 9+ messages in thread
From: Chandan Babu R @ 2020-11-11  4:23 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: guaneryu, linux-xfs, fstests

On Wednesday 11 November 2020 6:12:59 AM IST Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> _get_file_block_size is intended to return the size (in bytes) of the
> fundamental allocation unit for a file.  This is required for remapping
> operations like fallocate and reflink, which can only operate on
> allocation units.  Since the XFS realtime volume can be configure for
> allocation units larger than 1 fs block, we need to factor that in here.
> 
> Note that ext* with bigalloc does not allocations to be aligned to the
> cluster size, so no update is needed there.
>

Looks good to me.

Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>

> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  common/rc  |   13 ++++++++++---
>  common/xfs |   20 ++++++++++++++++++++
>  2 files changed, 30 insertions(+), 3 deletions(-)
> 
> 
> diff --git a/common/rc b/common/rc
> index 65ebfe20..019b9b2b 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -3975,11 +3975,18 @@ _get_file_block_size()
>  		echo "Missing mount point argument for _get_file_block_size"
>  		exit 1
>  	fi
> -	if [ "$FSTYP" = "ocfs2" ]; then
> +
> +	case "$FSTYP" in
> +	"ocfs2")
>  		stat -c '%o' $1
> -	else
> +		;;
> +	"xfs")
> +		_xfs_get_file_block_size $1
> +		;;
> +	*)
>  		_get_block_size $1
> -	fi
> +		;;
> +	esac
>  }
>  
>  # Get the minimum block size of an fs.
> diff --git a/common/xfs b/common/xfs
> index 79dab058..3f5c14ba 100644
> --- a/common/xfs
> +++ b/common/xfs
> @@ -174,6 +174,26 @@ _scratch_mkfs_xfs()
>  	return $mkfs_status
>  }
>  
> +# Get the size of an allocation unit of a file.  Normally this is just the
> +# block size of the file, but for realtime files, this is the realtime extent
> +# size.
> +_xfs_get_file_block_size()
> +{
> +	local path="$1"
> +
> +	if ! ($XFS_IO_PROG -c "stat -v" "$path" 2>&1 | egrep -q '(rt-inherit|realtime)'); then
> +		_get_block_size "$path"
> +		return
> +	fi
> +
> +	# Otherwise, call xfs_info until we find a mount point or the root.
> +	path="$(readlink -m "$path")"
> +	while ! $XFS_INFO_PROG "$path" &>/dev/null && [ "$path" != "/" ]; do
> +		path="$(dirname "$path")"
> +	done
> +	$XFS_INFO_PROG "$path" | grep realtime | sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g'
> +}
> +
>  # xfs_check script is planned to be deprecated. But, we want to
>  # be able to invoke "xfs_check" behavior in xfstests in order to
>  # maintain the current verification levels.
> 
> 


-- 
chandan




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

* Re: [PATCH 2/6] check: run tests in a systemd scope for mandatory test cleanup
  2020-11-11  0:43 ` [PATCH 2/6] check: run tests in a systemd scope for mandatory test cleanup Darrick J. Wong
@ 2020-11-22 14:35   ` Eryu Guan
  0 siblings, 0 replies; 9+ messages in thread
From: Eryu Guan @ 2020-11-22 14:35 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: guaneryu, linux-xfs, fstests

On Tue, Nov 10, 2020 at 04:43:16PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> TLDR: If systemd is available, run each test in its own temporary
> systemd scope.  This enables the test harness to forcibly clean up all
> of the test's child processes (if it does not do so itself) so that we
> can move into the post-test unmount and check cleanly.
> 
> I frequently run fstests in "low" memory situations (2GB!) to force the
> kernel to do interesting things.  There are a few tests like generic/224
> and generic/561 that put processes in the background and occasionally
> trigger the OOM killer.  Most of the time the OOM killer correctly
> shoots down fsstress or duperemove, but once in a while it's stupid
> enough to shoot down the test control process (i.e. tests/generic/224)
> instead.  fsstress is still running in the background, and the one
> process that knew about that is dead.
> 
> When the control process dies, ./check moves on to the post-test fsck,
> which fails because fsstress is still running and we can't unmount.
> After fsck fails, ./check moves on to the next test, which fails because
> fsstress is /still/ writing to the filesystem and we can't unmount or
> format.
> 
> The end result is that that one OOM kill causes cascading test failures,
> and I have to re-start fstests to see if I get a clean(er) run.
> 
> So, the solution I present in this patch is to teach ./check to try to
> run the test script in a systemd scope.  If that succeeds, ./check will
> tell systemd to kill the scope when the test script exits and returns
> control to ./check.  Concretely, this means that systemd creates a new
> cgroup, stuffs the processes in that cgroup, and when we kill the scope,
> systemd kills all the processes in that cgroup and deletes the cgroup.
> 
> The end result is that fstests now has an easy way to ensure that /all/
> child processes of a test are dead before we try to unmount the test and
> scratch devices.  I've designed this to be optional, because not
> everyone does or wants or likes to run systemd, but it makes QA easier.

Currently it uses systemd if the host has systemd enabled. Perhaps we
could add an env to control the systemd usage in the future so we have a
knob to turn it off even on hosts with systemd enabled. e.g.

USE_SYSTEMD_SCOPES=yes

But I'd take it as is for now.

Thanks,
Eryu

> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  check |   26 +++++++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
> 
> 
> diff --git a/check b/check
> index 5072dd82..83f6fc8b 100755
> --- a/check
> +++ b/check
> @@ -521,6 +521,12 @@ _expunge_test()
>  	return 0
>  }
>  
> +# Can we run systemd scopes?
> +HAVE_SYSTEMD_SCOPES=
> +systemctl reset-failed "fstests-check" &>/dev/null
> +systemd-run --quiet --unit "fstests-check" --scope bash -c "exit 77" &> /dev/null
> +test $? -eq 77 && HAVE_SYSTEMD_SCOPES=yes
> +
>  # Make the check script unattractive to the OOM killer...
>  OOM_SCORE_ADJ="/proc/self/oom_score_adj"
>  test -w ${OOM_SCORE_ADJ} && echo -1000 > ${OOM_SCORE_ADJ}
> @@ -528,8 +534,26 @@ test -w ${OOM_SCORE_ADJ} && echo -1000 > ${OOM_SCORE_ADJ}
>  # ...and make the tests themselves somewhat more attractive to it, so that if
>  # the system runs out of memory it'll be the test that gets killed and not the
>  # test framework.
> +#
> +# If systemd is available, run the entire test script in a scope so that we can
> +# kill all subprocesses of the test if it fails to clean up after itself.  This
> +# is essential for ensuring that the post-test unmount succeeds.  Note that
> +# systemd doesn't automatically remove transient scopes that fail to terminate
> +# when systemd tells them to terminate (e.g. programs stuck in D state when
> +# systemd sends SIGKILL), so we use reset-failed to tear down the scope.
>  _run_seq() {
> -	bash -c "test -w ${OOM_SCORE_ADJ} && echo 250 > ${OOM_SCORE_ADJ}; exec ./$seq"
> +	local cmd=(bash -c "test -w ${OOM_SCORE_ADJ} && echo 250 > ${OOM_SCORE_ADJ}; exec ./$seq")
> +
> +	if [ -n "${HAVE_SYSTEMD_SCOPES}" ]; then
> +		local unit="$(systemd-escape "fs$seq").scope"
> +		systemctl reset-failed "${unit}" &> /dev/null
> +		systemd-run --quiet --unit "${unit}" --scope "${cmd[@]}"
> +		res=$?
> +		systemctl stop "${unit}" &> /dev/null
> +		return "${res}"
> +	else
> +		"${cmd[@]}"
> +	fi
>  }
>  
>  _detect_kmemleak

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

end of thread, other threads:[~2020-11-22 14:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-11  0:42 [PATCH 0/6] xfstests: random fixes Darrick J. Wong
2020-11-11  0:42 ` [PATCH 1/6] common: extract rt extent size for _get_file_block_size Darrick J. Wong
2020-11-11  4:23   ` Chandan Babu R
2020-11-11  0:43 ` [PATCH 2/6] check: run tests in a systemd scope for mandatory test cleanup Darrick J. Wong
2020-11-22 14:35   ` Eryu Guan
2020-11-11  0:43 ` [PATCH 3/6] common/populate: make sure _scratch_xfs_populate puts its files on the data device Darrick J. Wong
2020-11-11  0:43 ` [PATCH 4/6] misc: fix $MKFS_PROG.$FSTYP usage treewide Darrick J. Wong
2020-11-11  0:43 ` [PATCH 5/6] misc: fix _get_file_block_size usage Darrick J. Wong
2020-11-11  0:43 ` [PATCH 6/6] xfs/033: use _scratch_xfs_db wrapper 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).