generic/590: fix the xfs feature detection logic
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 23 Apr 2020 23:31:18 +0000 (16:31 -0700)
committerEryu Guan <guaneryu@gmail.com>
Sun, 10 May 2020 15:04:37 +0000 (23:04 +0800)
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>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/generic/590

index 45f443c3ff3fb7b0c1abe5eaacf7ec5a8e290727..284bd49d4107038f13b77f41c1c3881127ab519b 100755 (executable)
@@ -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