common/fuzzy: if the fuzz verb is random, keep fuzzing until we get a new value
[xfstests-dev.git] / common / rc
index cd53a3734c057dcbf0c774a522d14c94492d50f7..0cda9da71f87fc081314f47277f82069ecd59ef5 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -171,6 +171,7 @@ case "$FSTYP" in
     glusterfs)
         ;;
     overlay)
+        . ./common/overlay
         ;;
     reiser4)
         [ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
@@ -300,26 +301,10 @@ _common_dev_mount_options()
        echo $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $*
 }
 
-_overlay_basic_mount_options()
-{
-       echo "-o lowerdir=$1/$OVL_LOWER,upperdir=$1/$OVL_UPPER,workdir=$1/$OVL_WORK"
-}
-
-_overlay_mount_options()
-{
-       echo `_common_dev_mount_options` \
-            `_overlay_basic_mount_options $1` \
-            $OVERLAY_MOUNT_OPTIONS
-}
-
 _scratch_mount_options()
 {
        _scratch_options mount
 
-       if [ "$FSTYP" == "overlay" ]; then
-               echo `_overlay_mount_options $OVL_BASE_SCRATCH_MNT`
-               return 0
-       fi
        echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
                                        $SCRATCH_DEV $SCRATCH_MNT
 }
@@ -349,121 +334,6 @@ _supports_filetype()
        esac
 }
 
-# helper function to do the actual overlayfs mount operation
-_overlay_mount_dirs()
-{
-       local lowerdir=$1
-       local upperdir=$2
-       local workdir=$3
-       shift 3
-
-       $MOUNT_PROG -t overlay -o lowerdir=$lowerdir -o upperdir=$upperdir \
-                   -o workdir=$workdir $*
-}
-
-_overlay_mkdirs()
-{
-       local dir=$1
-
-       mkdir -p $dir/$OVL_UPPER
-       mkdir -p $dir/$OVL_LOWER
-       mkdir -p $dir/$OVL_WORK
-       mkdir -p $dir/$OVL_MNT
-}
-
-# Given a base fs dir, set up overlay directories and mount on the given mnt.
-# The dir is used as the mount device so it can be seen from df or mount
-_overlay_mount()
-{
-       local dir=$1
-       local mnt=$2
-       shift 2
-
-       _supports_filetype $dir || _notrun "upper fs needs to support d_type"
-
-       _overlay_mkdirs $dir
-
-       _overlay_mount_dirs $dir/$OVL_LOWER $dir/$OVL_UPPER \
-                           $dir/$OVL_WORK $OVERLAY_MOUNT_OPTIONS \
-                           $SELINUX_MOUNT_OPTIONS $* $dir $mnt
-}
-
-_overlay_base_test_mount()
-{
-       if [ -z "$OVL_BASE_TEST_DEV" -o -z "$OVL_BASE_TEST_DIR" ] || \
-               _check_mounted_on OVL_BASE_TEST_DEV $OVL_BASE_TEST_DEV \
-                               OVL_BASE_TEST_DIR $OVL_BASE_TEST_DIR
-       then
-               # no base fs or already mounted
-               return 0
-       elif [ $? -ne 1 ]
-       then
-               # base fs mounted but not on mount point
-               return 1
-       fi
-
-       _mount $TEST_FS_MOUNT_OPTS \
-               $SELINUX_MOUNT_OPTIONS \
-               $OVL_BASE_TEST_DEV $OVL_BASE_TEST_DIR
-}
-
-_overlay_test_mount()
-{
-       _overlay_base_test_mount && \
-               _overlay_mount $OVL_BASE_TEST_DIR $TEST_DIR $*
-}
-
-_overlay_base_scratch_mount()
-{
-       if [ -z "$OVL_BASE_SCRATCH_DEV" -o -z "$OVL_BASE_SCRATCH_MNT" ] || \
-               _check_mounted_on OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_DEV \
-                               OVL_BASE_SCRATCH_MNT $OVL_BASE_SCRATCH_MNT
-       then
-               # no base fs or already mounted
-               return 0
-       elif [ $? -ne 1 ]
-       then
-               # base fs mounted but not on mount point
-               return 1
-       fi
-
-       _mount $OVL_BASE_MOUNT_OPTIONS \
-               $SELINUX_MOUNT_OPTIONS \
-               $OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_MNT
-}
-
-_overlay_base_scratch_unmount()
-{
-       [ -n "$OVL_BASE_SCRATCH_DEV" -a -n "$OVL_BASE_SCRATCH_MNT" ] || return 0
-
-       $UMOUNT_PROG $OVL_BASE_SCRATCH_MNT
-}
-
-_overlay_scratch_mount()
-{
-       _overlay_base_scratch_mount && \
-               _overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
-}
-
-_overlay_base_test_unmount()
-{
-       [ -n "$OVL_BASE_TEST_DEV" -a -n "$OVL_BASE_TEST_DIR" ] || return 0
-
-       $UMOUNT_PROG $OVL_BASE_TEST_DIR
-}
-
-_overlay_test_unmount()
-{
-       $UMOUNT_PROG $TEST_DIR
-       _overlay_base_test_unmount
-}
-
-_overlay_scratch_unmount()
-{
-       $UMOUNT_PROG $SCRATCH_MNT
-       _overlay_base_scratch_unmount
-}
-
 _scratch_mount()
 {
     if [ "$FSTYP" == "overlay" ]; then
@@ -758,7 +628,10 @@ _mkfs_dev()
        $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
                2>$tmp.mkfserr 1>$tmp.mkfsstd
        ;;
-
+    xfs)
+       $MKFS_PROG -t $FSTYP -- -f $MKFS_OPTIONS $* \
+               2>$tmp.mkfserr 1>$tmp.mkfsstd
+       ;;
     *)
        yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
                2>$tmp.mkfserr 1>$tmp.mkfsstd
@@ -1055,6 +928,21 @@ _scratch_mkfs_sized()
     ext2|ext3|ext4|ext4dev)
        ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
        ;;
+    gfs2)
+       # mkfs.gfs2 doesn't automatically shrink journal files on small
+       # filesystems, so the journal files may end up being bigger than the
+       # filesystem, which will cause mkfs.gfs2 to fail.  Until that's fixed,
+       # shrink the journal size to at most one eigth of the filesystem and at
+       # least 8 MiB, the minimum size allowed.
+       MIN_JOURNAL_SIZE=8
+       DEFAULT_JOURNAL_SIZE=128
+       if (( fssize/8 / (1024*1024) < DEFAULT_JOURNAL_SIZE )); then
+           (( JOURNAL_SIZE = fssize/8 / (1024*1024) ))
+           (( JOURNAL_SIZE >= MIN_JOURNAL_SIZE )) || JOURNAL_SIZE=$MIN_JOURNAL_SIZE
+           MKFS_OPTIONS="-J $JOURNAL_SIZE $MKFS_OPTIONS"
+       fi
+       ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV $blocks
+       ;;
     ocfs2)
        yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
        ;;
@@ -1139,6 +1027,9 @@ _scratch_mkfs_blocksized()
     ext2|ext3|ext4)
        ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
        ;;
+    gfs2)
+       ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV
+       ;;
     ocfs2)
        yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize -C $blocksize $SCRATCH_DEV
        ;;
@@ -2189,7 +2080,7 @@ _require_xfs_io_command()
                        _notrun "xfs_io $command support is missing"
                ;;
        "scrub"|"repair")
-               testio=`$XFS_IO_PROG -x -c "$command test 0" $TEST_DIR 2>&1`
+               testio=`$XFS_IO_PROG -x -c "$command probe 0" $TEST_DIR 2>&1`
                echo $testio | grep -q "Inappropriate ioctl" && \
                        _notrun "xfs_io $command support is missing"
                ;;
@@ -3422,6 +3313,7 @@ _check_dmesg()
             -e "(INFO|ERR): suspicious RCU usage" \
             -e "INFO: possible circular locking dependency detected" \
             -e "general protection fault:" \
+            -e "BUG .* remaining" \
             $seqres.dmesg
        if [ $? -eq 0 ]; then
                _dump_err "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
@@ -3652,16 +3544,6 @@ _get_fs_sysfs_attr()
        cat /sys/fs/${FSTYP}/${dname}/${attr}
 }
 
-# Print the value of a filesystem module parameter
-# at /sys/module/$FSTYP/parameters/$PARAM
-#
-# Usage example (FSTYP=overlay):
-#   _get_fs_module_param index
-_get_fs_module_param()
-{
-       cat /sys/module/${FSTYP}/parameters/${1} 2>/dev/null
-}
-
 # Generic test for specific filesystem feature.
 # Currently only implemented to test overlayfs features.
 _require_scratch_feature()
@@ -3670,29 +3552,7 @@ _require_scratch_feature()
 
        case "$FSTYP" in
        overlay)
-               # overalyfs features (e.g. redirect_dir, index) are
-               # configurable from Kconfig (the build default), by module
-               # parameter (the system default) and per mount by mount
-               # option ${feature}=[on|off].
-               #
-               # If the module parameter does not exist then there is no
-               # point in checking the mount option.
-               local default=`_get_fs_module_param ${feature}`
-               [ "$default" = Y ] || [ "$default" = N ] || \
-                       _notrun "feature '${feature}' not supported by ${FSTYP}"
-
-               _scratch_mkfs > /dev/null 2>&1
-               _scratch_mount -o ${feature}=on || \
-                       _notrun "${FSTYP} feature '${feature}' cannot be enabled on ${SCRATCH_DEV}"
-               # Check options to be sure. For example, Overlayfs will fallback to
-               # 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}"
-               _scratch_unmount
+               _require_scratch_overlay_feature ${feature}
                ;;
        *)
                _fail "Test for feature '${feature}' of ${FSTYP} is not implemented"
@@ -3700,7 +3560,6 @@ _require_scratch_feature()
        esac
 }
 
-
 init_rc
 
 ################################################################################