diff mbox series

[1/5] generic/590: fix the xfs feature detection logic

Message ID 158768467794.3019327.1909486240720460347.stgit@magnolia (mailing list archive)
State Accepted
Headers show
Series fstests: random fixes | expand

Commit Message

Darrick J. Wong April 23, 2020, 11:31 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

The setup code in this regression test case tries to figure out if
certain features known to be incompatible with realtime are known to
mkfs, and if so, to forcibly disable them.

Unfortunately, the reflink feature detection logic here is broken,
because we have no way of distinguishing between the helper function
_scratch_mkfs_xfs_supported returning nonzero because reflink isn't
compatible with mkfs's defaults (e.g. your mkfs has rmapbt=1 by default)
vs. reflink isn't recognized at all vs. something else broke.

However, we can grep the mkfs output to look for reflink support, and if
we find it then we disable it.  That's fine for this test, since on XFS
it's trying to set up the exact conditions to test a known bug.

Second, rmapbt isn't currently compatible with realtime either, so we
need to detect and mask that off too.

Third, the test only needs to perform this feature detection if the test
runner didn't set SCRATCH_RTDEV, because we require that if the runner
configured SCRATCH_RTDEV, they also set MKFS_OPTIONS appropriately.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 tests/generic/590 |   31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/tests/generic/590 b/tests/generic/590
index 45f443c3..284bd49d 100755
--- a/tests/generic/590
+++ b/tests/generic/590
@@ -41,6 +41,21 @@  bs=4096
 rextsize=4
 filesz=$(((maxextlen + 1) * bs))
 
+must_disable_feature() {
+	local feat="$1"
+
+	# If mkfs doesn't know about the feature, we don't need to disable it
+	$MKFS_XFS_PROG --help 2>&1 | grep -q "${feat}=0" || return 1
+
+	# If turning the feature on works, we don't need to disable it
+	_scratch_mkfs_xfs_supported -m "${feat}=1" "${disabled_features[@]}" \
+		> /dev/null 2>&1 && return 1
+
+	# Otherwise mkfs knows of the feature and formatting with it failed,
+	# so we do need to mask it.
+	return 0
+}
+
 extra_options=""
 # If we're testing XFS, set up the realtime device to reproduce the bug.
 if [[ $FSTYP = xfs ]]; then
@@ -54,14 +69,20 @@  if [[ $FSTYP = xfs ]]; then
 		loop="$(_create_loop_device "$TEST_DIR/$seq")"
 		USE_EXTERNAL=yes
 		SCRATCH_RTDEV="$loop"
+		disabled_features=()
+
+		# disable reflink if not supported by realtime devices
+		must_disable_feature reflink &&
+			disabled_features=(-m reflink=0)
+
+		# disable rmap if not supported by realtime devices
+		must_disable_feature rmapbt &&
+			disabled_features+=(-m rmapbt=0)
 	fi
 	extra_options="$extra_options -r extsize=$((bs * rextsize))"
 	extra_options="$extra_options -d agsize=$(((maxextlen + 1) * bs / 2)),rtinherit=1"
-	# disable reflink as reflink not supported with realtime devices
-	if _scratch_mkfs_xfs_supported -m reflink=0 >/dev/null 2>&1; then
-		extra_options="$extra_options -m reflink=0"
-	fi
-	_scratch_mkfs $extra_options >>$seqres.full 2>&1
+
+	_scratch_mkfs $extra_options "${disabled_features[@]}" >>$seqres.full 2>&1
 	_try_scratch_mount >>$seqres.full 2>&1 || \
 		_notrun "mount failed, kernel doesn't support realtime?"
 	_scratch_unmount