xfs/419: remove irrelevant swapfile test
[xfstests-dev.git] / common / overlay
index b526f24d25eb181af60a3a03d35a175df7275a9f..1ca37e291183bbb467b261631863104d72a8faaf 100644 (file)
@@ -105,6 +105,11 @@ _overlay_base_scratch_mount()
 
 _overlay_scratch_mount()
 {
+       if echo "$*" | grep -q remount; then
+               $MOUNT_PROG $SCRATCH_MNT $*
+               return
+       fi
+
        _overlay_base_scratch_mount && \
                _overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
 }
@@ -132,9 +137,11 @@ _overlay_scratch_unmount()
 }
 
 # Check that a specific overlayfs feature is supported
-__check_scratch_overlay_feature()
+_check_overlay_feature()
 {
        local feature=$1
+       local dev=$2
+       local mnt=$3
 
        # overalyfs features (e.g. redirect_dir, index) are
        # configurable from Kconfig (the build default), by module
@@ -148,10 +155,10 @@ __check_scratch_overlay_feature()
        # index=off if underlying fs does not support file handles.
        # Overlayfs only displays mount option if it differs from the default.
        # Overlayfs may enable the feature, but fallback to read-only mount.
-       ((( [ "$default" = N ] && _fs_options $SCRATCH_DEV | grep -q "${feature}=on" ) || \
-         ( [ "$default" = Y ] && ! _fs_options $SCRATCH_DEV | grep -q "${feature}=off" )) && \
-           touch $SCRATCH_MNT/foo 2>/dev/null ) || \
-               _notrun "${FSTYP} feature '${feature}' cannot be enabled on ${SCRATCH_DEV}"
+       ((( [ "$default" = N ] && _fs_options $dev | grep -q "${feature}=on" ) || \
+         ( [ "$default" = Y ] && ! _fs_options $dev | grep -q "${feature}=off" )) && \
+           touch $mnt/foo 2>/dev/null ) || \
+               _notrun "${FSTYP} feature '${feature}' cannot be enabled on ${dev}"
 }
 
 # Require a set of overlayfs features
@@ -173,7 +180,7 @@ _require_scratch_overlay_features()
                _notrun "overlay features '${features[*]}' cannot be enabled on ${SCRATCH_DEV}"
 
        for feature in ${features[*]}; do
-               __check_scratch_overlay_feature ${feature}
+               _check_overlay_feature ${feature} $SCRATCH_DEV $SCRATCH_MNT
        done
 
        _scratch_unmount
@@ -193,6 +200,25 @@ _overlay_fsck_dirs()
                           -o workdir=$workdir $*
 }
 
+# Run fsck and check for expected return value
+_overlay_fsck_expect()
+{
+       # The first arguments is the expected fsck program exit code, the
+       # remaining arguments are the input parameters of the fsck program.
+       local expect_ret=$1
+       local lowerdir=$2
+       local upperdir=$3
+       local workdir=$4
+       shift 4
+
+       _overlay_fsck_dirs $lowerdir $upperdir $workdir $* >> \
+                       $seqres.full 2>&1
+       fsck_ret=$?
+
+       [[ "$fsck_ret" == "$expect_ret" ]] || \
+               echo "expect fsck.overlay to return $expect_ret, but got $fsck_ret"
+}
+
 _overlay_check_dirs()
 {
        local lowerdir=$1
@@ -320,3 +346,82 @@ _check_overlay_scratch_fs()
                "$OVL_BASE_SCRATCH_DEV" "$OVL_BASE_SCRATCH_MNT" \
                $OVL_BASE_MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS
 }
+
+_repair_overlay_scratch_fs()
+{
+       _overlay_fsck_dirs $OVL_BASE_SCRATCH_MNT/$OVL_LOWER \
+               $OVL_BASE_SCRATCH_MNT/$OVL_UPPER \
+               $OVL_BASE_SCRATCH_MNT/$OVL_WORK -y
+       local res=$?
+       case $res in
+       $FSCK_OK|$FSCK_NONDESTRUCT)
+               res=0
+               ;;
+       *)
+               _dump_err2 "fsck.overlay failed, err=$res"
+               ;;
+       esac
+       return $res
+}
+
+# This test requires that unionmount testsuite is installed at
+# $UNIONMOUNT_TESTSUITE and that it supports configuring layers and overlay
+# mount paths via UNIONMOUNT_* environment variables.
+_require_unionmount_testsuite()
+{
+       [ -x "$UNIONMOUNT_TESTSUITE/run" ] || \
+               _notrun "unionmount testsuite required."
+
+       # Verify that UNIONMOUNT_* vars are supported
+       local usage=`UNIONMOUNT_BASEDIR=_ "$UNIONMOUNT_TESTSUITE/run" 2>&1`
+       echo $usage | grep -wq "UNIONMOUNT_BASEDIR" || \
+               _notrun "newer version of unionmount testsuite required."
+
+       [ -n "$OVERLAY_MOUNT_OPTIONS" ] || return
+       # If custom overlay mount options are used
+       # verify that UNIONMOUNT_MNTOPTIONS var is supported
+       local usage=`UNIONMOUNT_MNTOPTIONS=_ "$UNIONMOUNT_TESTSUITE/run" 2>&1`
+       echo $usage | grep -wq "UNIONMOUNT_MNTOPTIONS" || \
+               _notrun "newer version of unionmount testsuite required to support OVERLAY_MOUNT_OPTIONS."
+}
+
+_unionmount_testsuite_run()
+{
+       [ "$FSTYP" = overlay ] || \
+               _notrun "Filesystem $FSTYP not supported with unionmount testsuite."
+
+       # Provide the mounted base fs for upper and lower dirs and the
+       # overlay mount point.
+       # unionmount testsuite will perform the overlay mount.
+       # test fs is used for lower layer in non-samefs runs.
+       # scratch fs is used for upper layer in non-samefs runs and
+       # for both layers in samefs runs.
+       if (echo $* | grep -qv samefs) ; then
+               _overlay_base_test_mount
+               export UNIONMOUNT_LOWERDIR=$OVL_BASE_TEST_DIR/union
+       fi
+       export UNIONMOUNT_BASEDIR=$OVL_BASE_SCRATCH_MNT/union
+       export UNIONMOUNT_MNTOPTIONS="$OVERLAY_MOUNT_OPTIONS"
+
+       _scratch_mkfs
+       rm -rf $UNIONMOUNT_BASEDIR $UNIONMOUNT_LOWERDIR
+       mkdir -p $UNIONMOUNT_BASEDIR $UNIONMOUNT_LOWERDIR
+
+       cd $UNIONMOUNT_TESTSUITE
+       echo "run $* ..." > $seqres.full
+       ./run $* >> $seqres.full || \
+               echo "unionmount testsuite failed! see $seqres.full for details."
+}
+
+_unionmount_testsuite_cleanup()
+{
+       cd /
+       rm -f $tmp.*
+
+       [ -n "$UNIONMOUNT_BASEDIR" ] || return 0
+
+       # Cleanup overlay mount after unionmount testsuite run
+       cd $UNIONMOUNT_TESTSUITE
+       echo "run --clean-up ..." >> $seqres.full
+       ./run --clean-up >> $seqres.full 2>&1
+}