xfs: test that the needsrepair feature works as advertised
[xfstests-dev.git] / common / xfs
index 6e1e661aef150f80e591390be431855e6826be25..cf4afb5341339ed295d1f27086c835dbef3c1a68 100644 (file)
@@ -277,7 +277,13 @@ _scratch_xfs_admin()
                        _notrun 'xfs_admin does not support rt devices'
                rt_opts+=(-r "$SCRATCH_RTDEV")
        fi
-       $XFS_ADMIN_PROG "${rt_opts[@]}" "$@" "${options[@]}"
+
+       # xfs_admin in xfsprogs 5.11 has a bug where an external log device
+       # forces xfs_db to be invoked, potentially with zero command arguments.
+       # When this happens, xfs_db will wait for input on stdin, which causes
+       # fstests to hang.  Since xfs_admin is not an interactive tool, we
+       # can redirect stdin from /dev/null to prevent this issue.
+       $XFS_ADMIN_PROG "${rt_opts[@]}" "$@" "${options[@]}" < /dev/null
 }
 
 _scratch_xfs_logprint()
@@ -306,6 +312,14 @@ _scratch_xfs_check()
        _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
 }
 
+# Check for secret debugging hooks in xfs_repair
+_require_libxfs_debug_flag() {
+       local hook="$1"
+
+       grep -q "$hook" "$(type -P xfs_repair)" || \
+               _notrun "libxfs debug hook $hook not detected?"
+}
+
 _scratch_xfs_repair()
 {
        SCRATCH_OPTIONS=""
@@ -1108,3 +1122,24 @@ _xfs_get_cowgc_interval() {
                _fail "Can't find cowgc interval procfs knob?"
        fi
 }
+
+# Print the status of the given features on the scratch filesystem.
+# Returns 0 if all features are found, 1 otherwise.
+_check_scratch_xfs_features()
+{
+       local features="$(_scratch_xfs_db -c 'version')"
+       local output=("FEATURES:")
+       local found=0
+
+       for feature in "$@"; do
+               local status="NO"
+               if echo "${features}" | grep -q -w "${feature}"; then
+                       status="YES"
+                       found=$((found + 1))
+               fi
+               output+=("${feature}:${status}")
+       done
+
+       echo "${output[@]}"
+       test "${found}" -eq "$#"
+}