xfs: basic testing of new xfs_spaceman health command
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 20 May 2019 22:31:41 +0000 (15:31 -0700)
committerEryu Guan <guaneryu@gmail.com>
Sun, 26 May 2019 14:48:00 +0000 (22:48 +0800)
Basic tests to make sure xfs_spaceman health command works properly.

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>
common/xfs
tests/xfs/505 [new file with mode: 0755]
tests/xfs/505.out [new file with mode: 0644]
tests/xfs/506 [new file with mode: 0755]
tests/xfs/506.out [new file with mode: 0644]
tests/xfs/group

index 42f02ff73b36bd11754d68593153ce44fb1409a9..f8dafc6c724f92a6acce3361c14b8ab803dc4d2e 100644 (file)
@@ -773,7 +773,12 @@ _require_xfs_spaceman_command()
        _require_command "$XFS_SPACEMAN_PROG" "xfs_spaceman"
 
        testfile=$TEST_DIR/$$.xfs_spaceman
+       touch $testfile
        case $command in
+       "health")
+               testio=`$XFS_SPACEMAN_PROG -c "health $param" $TEST_DIR 2>&1`
+               param_checked=1
+               ;;
        *)
                testio=`$XFS_SPACEMAN_PROG -c "help $command" $TEST_DIR 2>&1`
        esac
@@ -787,6 +792,8 @@ _require_xfs_spaceman_command()
                _notrun "xfs_spaceman $command failed (old kernel/wrong fs/bad args?)"
        echo $testio | grep -q "foreign file active" && \
                _notrun "xfs_spaceman $command not supported on $FSTYP"
+       echo $testio | grep -q "Inappropriate ioctl for device" && \
+               _notrun "xfs_spaceman $command support is missing (missing ioctl?)"
        echo $testio | grep -q "Function not implemented" && \
                _notrun "xfs_spaceman $command support is missing (missing syscall?)"
 
diff --git a/tests/xfs/505 b/tests/xfs/505
new file mode 100755 (executable)
index 0000000..7df0425
--- /dev/null
@@ -0,0 +1,52 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2019, Oracle and/or its affiliates.  All Rights Reserved.
+#
+# FS QA Test No. 505
+#
+# Ensure all xfs_spaceman commands are documented.
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1    # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+
+# real QA test starts here
+_supported_fs xfs
+_supported_os Linux
+_require_command "$XFS_SPACEMAN_PROG" "xfs_spaceman"
+_require_command "$MAN_PROG" man
+
+echo "Silence is golden"
+
+MANPAGE=$($MAN_PROG --path xfs_spaceman)
+
+case "$MANPAGE" in
+*.gz|*.z\|*.Z) CAT=zcat;;
+*.bz2)         CAT=bzcat;;
+*.xz)          CAT=xzcat;;
+*)             CAT=cat;;
+esac
+_require_command `which $CAT` $CAT
+
+for COMMAND in `$XFS_SPACEMAN_PROG -c help $TEST_DIR | awk '{print $1}' | grep -v "^Use"`; do
+  $CAT "$MANPAGE" | egrep -q "^\.B.*$COMMAND" || \
+       echo "$COMMAND not documented in the xfs_spaceman manpage"
+done
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/505.out b/tests/xfs/505.out
new file mode 100644 (file)
index 0000000..80e3bd1
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 505
+Silence is golden
diff --git a/tests/xfs/506 b/tests/xfs/506
new file mode 100755 (executable)
index 0000000..153ba60
--- /dev/null
@@ -0,0 +1,82 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2019, Oracle and/or its affiliates.  All Rights Reserved.
+#
+# FS QA Test No. 506
+#
+# Basic tests of the xfs_spaceman health command.
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1    # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/fuzzy
+. ./common/filter
+
+# real QA test starts here
+_supported_fs xfs
+_supported_os Linux
+_require_scratch_nocheck
+_require_scrub
+_require_xfs_spaceman_command "health"
+
+rm -f $seqres.full
+
+_scratch_mkfs > $seqres.full 2>&1
+_scratch_mount
+
+# Haven't checked anything, it should tell us to run scrub
+$XFS_SPACEMAN_PROG -c "health" $SCRATCH_MNT
+
+# Run scrub to collect health info.
+_scratch_scrub -n >> $seqres.full
+
+query() {
+       $XFS_SPACEMAN_PROG -c "$@" $SCRATCH_MNT | tee -a $seqres.full
+}
+
+query_health() {
+       query "$@" | grep -q ": ok$"
+}
+
+query_sick() {
+       query "$@" | grep -q ": unhealthy$"
+}
+
+# Let's see if we get at least one healthy rating for each health reporting
+# group.
+query_health "health -f" || \
+       echo "Didn't see a single healthy fs metadata?"
+
+query_health "health -a 0" || \
+       echo "Didn't see a single healthy ag metadata?"
+
+query_health "health $SCRATCH_MNT" || \
+       echo "Didn't see a single healthy file metadata?"
+
+# Unmount, corrupt filesystem
+_scratch_unmount
+_scratch_xfs_db -x -c 'sb 1' -c 'fuzz -d magicnum random' >> $seqres.full
+
+# Now let's see what the AG report says
+_scratch_mount
+_scratch_scrub -n >> $seqres.full 2>&1
+query_sick "health -a 1" || \
+       echo "Didn't see the expected unhealthy metadata?"
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/506.out b/tests/xfs/506.out
new file mode 100644 (file)
index 0000000..1cde383
--- /dev/null
@@ -0,0 +1,3 @@
+QA output created by 506
+Health status has not been collected for this filesystem.
+Please run xfs_scrub(8) to remedy this situation.
index 144b2fc5ed5d9218920df83f763746bbd051711c..ffe4ae120b3c6e37103321c4b95c61aa1b3b62d2 100644 (file)
 502 auto quick unlink
 503 auto copy metadump
 504 auto quick mkfs label
+505 auto quick spaceman
+506 auto quick health