]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
check: try to fix the test device if it gets corrupted
authorTheodore Ts'o <tytso@mit.edu>
Fri, 21 Apr 2023 17:51:31 +0000 (10:51 -0700)
committerZorro Lang <zlang@kernel.org>
Sun, 23 Apr 2023 18:48:02 +0000 (02:48 +0800)
If the test device gets corrupted all subsequent tests will fail.  To
prevent this from causing all subsequent tests to be useless, try
repair the file system on TEST_DEV if possible.  We don't need to do
this with the scratch device since that file system gets recreated
each time anyway.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Leah Rumancik <leah.rumancik@gmail.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Zorro Lang <zlang@kernel.org>
check
common/rc
common/xfs

diff --git a/check b/check
index 1a58a2b2690a1080e93a2e713793ddabebde7669..befbf465af1e14c0d28117a510848d487002447f 100755 (executable)
--- a/check
+++ b/check
@@ -536,7 +536,12 @@ _check_filesystems()
        local ret=0
 
        if [ -f ${RESULT_DIR}/require_test ]; then
-               _check_test_fs || ret=1
+               if ! _check_test_fs ; then
+                       ret=1
+                       echo "Trying to repair broken TEST_DEV file system"
+                       _repair_test_fs
+                       _test_mount
+               fi
                rm -f ${RESULT_DIR}/require_test*
        else
                _test_unmount 2> /dev/null
index e89b0a3794fc96a0fa9d84d5423924d7d069f4d7..8a67952e6c642d1cb6f8c9d454337a49acdb6a57 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -1199,6 +1199,47 @@ _repair_scratch_fs()
     esac
 }
 
+_repair_test_fs()
+{
+       case $FSTYP in
+       xfs)
+               _test_xfs_repair "$@" >$tmp.repair 2>&1
+               res=$?
+               if [ "$res" -ne 0 ]; then
+                       echo "xfs_repair returns $res; replay log?" >>$tmp.repair
+                       _test_mount
+                       res=$?
+                       if [ $res -gt 0 ]; then
+                               echo "mount returns $res; zap log?" >>$tmp.repair
+                               _xfs_repair_test_fs -L >>$tmp.repair 2>&1
+                               echo "log zap returns $?" >> $tmp.repair
+                       else
+                               umount "$TEST_DEV"
+                       fi
+                       _xfs_repair_test_fs "$@" >>$tmp.repair 2>&1
+                       res=$?
+               fi
+               ;;
+       *)
+               # Let's hope fsck -y suffices...
+               fsck -t $FSTYP -fy $TEST_DEV >$tmp.repair 2>&1
+               res=$?
+               if test "$res" -lt 4 ; then
+                       res=0
+               fi
+               ;;
+       esac
+       if [ $res -ne 0 ]; then
+               _log_err "_repair_test_fs: failed, err=$res"
+               echo "*** fsck.$FSTYP output ***"       >>$seqres.full
+               cat $tmp.repair                         >>$seqres.full
+               echo "*** end fsck.$FSTYP output"       >>$seqres.full
+
+       fi
+       rm -f $tmp.repair
+       return $res
+}
+
 _get_pids_by_name()
 {
     if [ $# -ne 1 ]
index c558e940cdf3e63a7e01d683d1bd76fe0ab820b7..137ac9dbbeb04a81ae928085bb6d9777a1e96f3a 100644 (file)
@@ -988,6 +988,18 @@ _check_xfs_test_fs()
        return $?
 }
 
+# modeled after _scratch_xfs_repair
+_test_xfs_repair()
+{
+       TEST_OPTIONS=""
+       [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
+               TEST_OPTIONS="-l$TEST_LOGDEV"
+       [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
+               TEST_OPTIONS=$TEST_OPTIONS" -r$TEST_RTDEV"
+       [ "$LARGE_TEST_DEV" = yes ] && TEST_OPTIONS=$TEST_OPTIONS" -t"
+       $XFS_REPAIR_PROG $TEST_OPTIONS $* $TEST_DEV
+}
+
 _require_xfs_test_rmapbt()
 {
        _require_test