]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common: provide a method to repair the scratch fs
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 9 Feb 2016 21:59:13 +0000 (13:59 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Fri, 12 Feb 2016 17:39:05 +0000 (09:39 -0800)
Create a wrapper function that repairs any damage to the scratch
filesystem and returns a standard result.  We will use this to clean
up after IO error testing and other weird corruption tests.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
common/rc

index 63eb90b5be2ff2a6dea1ab0b710cb8bb6ddecc08..e05df74ba4305abd3df9095c1687b5a374fa85cc 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -953,6 +953,49 @@ _scratch_xfs_repair()
     $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
 }
 
+# Repair scratch filesystem.  Returns 0 if the FS is good to go (either no
+# errors found or errors were fixed) and nonzero otherwise; also spits out
+# a complaint on stderr if fsck didn't tell us that the FS is good to go.
+_repair_scratch_fs()
+{
+    case $FSTYP in
+    xfs)
+        _scratch_xfs_repair "$@" 2>&1
+       res=$?
+       if [ "$res" -eq 2 ]; then
+               echo "xfs_repair returns $res; replay log?"
+               _scratch_mount
+               res=$?
+               if [ "$res" -gt 0 ]; then
+                       echo "mount returns $res; zap log?"
+                       _scratch_xfs_repair -L 2>&1
+                       echo "log zap returns $?"
+               else
+                       umount "$SCRATCH_MNT"
+               fi
+               _scratch_xfs_repair "$@" 2>&1
+               res=$?
+       fi
+       test $res -ne 0 && >&2 echo "xfs_repair failed, err=$res"
+       return $res
+        ;;
+    *)
+        # Let's hope fsck -y suffices...
+        fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
+       res=$?
+       case $res in
+       0|1|2)
+               res=0
+               ;;
+       *)
+               >&2 echo "fsck.$FSTYP failed, err=$res"
+               ;;
+       esac
+       return $res
+        ;;
+    esac
+}
+
 _get_pids_by_name()
 {
     if [ $# -ne 1 ]