common/fuzzy: if the fuzz verb is random, keep fuzzing until we get a new value
[xfstests-dev.git] / common / rc
index b5053659c1c8cd26d17ee407d48b53c8b81b9155..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"
@@ -238,7 +239,7 @@ _scratch_options()
 
     case $type in
     mkfs)
-       [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
+       SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
        rt_opt="-r"
         log_opt="-l"
        ;;
@@ -287,14 +288,7 @@ _mount_ops_filter()
     [ $last_index -gt 0 ] && shift $last_index
     FS_ESCAPED=$1
     
-    # irix is fussy about how it is fed its mount options
-    # - multiple -o's are not allowed
-    # - no spaces between comma delimitered options
-    # the sed script replaces all -o's (except the first) with a comma
-    # not required for linux, but won't hurt
-    
-    echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
-        | sed -e 's/dmapi/dmi/' \
+    echo $params | sed -e 's/dmapi/dmi/' \
         | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
 
 }
@@ -307,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
 }
@@ -356,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
@@ -567,7 +430,7 @@ _scratch_do_mkfs()
        shift 2
        local extra_mkfs_options=$*
        local mkfs_status
-       local tmp=`mktemp`
+       local tmp=`mktemp -u`
 
        # save mkfs output in case conflict means we need to run again.
        # only the output for the mkfs that applies should be shown
@@ -595,7 +458,7 @@ _scratch_do_mkfs()
        cat $tmp.mkfsstd
        eval "cat $tmp.mkfserr | $mkfs_filter" >&2
 
-       rm -f $tmp*
+       rm -f $tmp.mkfserr $tmp.mkfsstd
        return $mkfs_status
 }
 
@@ -676,7 +539,7 @@ _scratch_mkfs_ext4()
 {
        local mkfs_cmd="$MKFS_EXT4_PROG -F"
        local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
-       local tmp=`mktemp`
+       local tmp=`mktemp -u`
        local mkfs_status
 
        [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
@@ -701,6 +564,7 @@ _scratch_mkfs_ext4()
        # output mkfs stdout and stderr
        cat $tmp.mkfsstd
        cat $tmp.mkfserr >&2
+       rm -f $tmp.mkfserr $tmp.mkfsstd
 
        return $mkfs_status
 }
@@ -743,6 +607,7 @@ _test_mkfs()
 
 _mkfs_dev()
 {
+    local tmp=`mktemp -u`
     case $FSTYP in
     nfs*)
        # do nothing for nfs
@@ -754,30 +619,33 @@ _mkfs_dev()
        # do nothing for pvfs2
        ;;
     udf)
-        $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
+        $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
        ;;
     btrfs)
-        $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
+        $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
        ;;
     ext2|ext3|ext4)
        $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
-               2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
+               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_dir.mkfserr 1>$tmp_dir.mkfsstd
+               2>$tmp.mkfserr 1>$tmp.mkfsstd
        ;;
     esac
 
     if [ $? -ne 0 ]; then
        # output stored mkfs output
-       cat $tmp_dir.mkfserr >&2
-       cat $tmp_dir.mkfsstd
+       cat $tmp.mkfserr >&2
+       cat $tmp.mkfsstd
        status=1
        exit 1
     fi
-    rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
+    rm -f $tmp.mkfserr $tmp.mkfsstd
 }
 
 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
@@ -1020,9 +888,12 @@ _scratch_mkfs_sized()
     xfs)
        def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
        ;;
-    ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4|ocfs2)
+    ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4|ocfs2|reiserfs)
        def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
        ;;
+    jfs)
+       def_blksz=4096
+       ;;
     esac
 
     [ -n "$def_blksz" ] && blocksize=$def_blksz
@@ -1057,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
        ;;
@@ -1068,6 +954,12 @@ _scratch_mkfs_sized()
        (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
        $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
        ;;
+    jfs)
+       ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS $SCRATCH_DEV $blocks
+       ;;
+    reiserfs)
+       ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
+       ;;
     reiser4)
        # mkfs.resier4 requires size in KB as input for creating filesystem
        $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
@@ -1135,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
        ;;
@@ -1429,6 +1324,7 @@ _do()
     (eval "echo '---' \"$_cmd\"") >>$seqres.full
     (eval "$_cmd") >$tmp._out 2>&1; ret=$?
     cat $tmp._out | _fix_malloc >>$seqres.full
+    rm -f $tmp._out
     if [ $# -eq 2 ]; then
        if [ $ret -eq 0 ]; then
            echo "done"
@@ -1738,6 +1634,15 @@ _require_test()
     touch ${RESULT_DIR}/require_test
 }
 
+_has_logdev()
+{
+       local ret=0
+       [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && ret=1
+       [ "$USE_EXTERNAL" != yes ] && ret=1
+
+       return $ret
+}
+
 # this test needs a logdev
 #
 _require_logdev()
@@ -2116,12 +2021,7 @@ s,^\s*$,,;
 
 _user_do()
 {
-    if [ "$HOSTOS" == "IRIX" ]
-       then
-       echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
-    else
        echo $1 | su -s /bin/bash $qa_user 2>&1 | _filter_user_do
-    fi
 }
 
 _require_xfs_io_command()
@@ -2168,7 +2068,7 @@ _require_xfs_io_command()
                ;;
        "fsmap" )
                testio=`$XFS_IO_PROG -f -c "fsmap" $testfile 2>&1`
-               echo $testio | egrep -q "Inappropriate ioctl" && \
+               echo $testio | grep -q "Inappropriate ioctl" && \
                        _notrun "xfs_io $command support is missing"
                ;;
        "open")
@@ -2176,12 +2076,12 @@ _require_xfs_io_command()
                # a new -C flag was introduced to execute one shot commands.
                # Check for -C flag support as an indication for the bug fix.
                testio=`$XFS_IO_PROG -F -f -C "open $testfile" $testfile 2>&1`
-               echo $testio | egrep -q "invalid option" && \
+               echo $testio | grep -q "invalid option" && \
                        _notrun "xfs_io $command support is missing"
                ;;
        "scrub"|"repair")
-               testio=`$XFS_IO_PROG -x -c "$command dummy 0" $TEST_DIR 2>&1`
-               echo $testio | egrep -q "Inappropriate ioctl" && \
+               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"
                ;;
        "utimes" )
@@ -2200,12 +2100,17 @@ _require_xfs_io_command()
                _notrun "xfs_io $command failed (old kernel/wrong fs/bad args?)"
        echo $testio | grep -q "foreign file active" && \
                _notrun "xfs_io $command not supported on $FSTYP"
-       echo $testio | egrep -q "Function not implemented" && \
+       echo $testio | grep -q "Function not implemented" && \
                _notrun "xfs_io $command support is missing (missing syscall?)"
 
-       if [ -n "$param" -a $param_checked -eq 0 ]; then
+       [ -n "$param" ] || return
+
+       if [ $param_checked -eq 0 ]; then
                $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
                        _notrun "xfs_io $command doesn't support $param"
+       else
+               echo $testio | grep -q "invalid option" && \
+                       _notrun "xfs_io $command doesn't support $param"
        fi
 }
 
@@ -2289,16 +2194,31 @@ _require_fail_make_request()
  not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
 }
 
-#
+# Disable extent zeroing for ext4 on the given device
+_ext4_disable_extent_zeroout()
+{
+       local dev=${1:-$TEST_DEV}
+       local sdev=`_short_dev $dev`
+
+       [ -f /sys/fs/ext4/$sdev/extent_max_zeroout_kb ] && \
+               echo 0 >/sys/fs/ext4/$sdev/extent_max_zeroout_kb
+}
+
 # Check if the file system supports seek_data/hole
-#
 _require_seek_data_hole()
 {
-    testfile=$TEST_DIR/$$.seek
-    testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
-    rm -f $testfile &>/dev/null
-    echo $testseek | grep -q "Kernel does not support" && \
-        _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
+       local dev=${1:-$TEST_DEV}
+       local testfile=$TEST_DIR/$$.seek
+       local testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
+
+       rm -f $testfile &>/dev/null
+       echo $testseek | grep -q "Kernel does not support" && \
+               _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
+       # Disable extent zeroing for ext4 as that change where holes are
+       # created
+       if [ "$FSTYP" = "ext4" ]; then
+               _ext4_disable_extent_zeroout $dev
+       fi
 }
 
 _require_runas()
@@ -2693,9 +2613,7 @@ _full_platform_details()
 
 _get_os_name()
 {
-       if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
-               echo 'irix'
-       elif [ "`uname`" == "Linux" ]; then
+       if [ "`uname`" == "Linux" ]; then
                echo 'linux'
        else
                echo Unknown operating system: `uname`
@@ -3259,9 +3177,6 @@ run_check()
 
 _require_test_symlinks()
 {
-       # IRIX UDF does not support symlinks
-       [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
-               _notrun "Require symlinks support"
        target=`mktemp -p $TEST_DIR`
        link=`mktemp -p $TEST_DIR -u`
        ln -s `basename $target` $link
@@ -3398,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)"
@@ -3549,8 +3465,10 @@ run_fsx()
        "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
        if [ ${PIPESTATUS[0]} -ne 0 ]; then
                cat $tmp.fsx
+               rm -f $tmp.fsx
                exit 1
        fi
+       rm -f $tmp.fsx
 }
 
 # Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
@@ -3626,6 +3544,21 @@ _get_fs_sysfs_attr()
        cat /sys/fs/${FSTYP}/${dname}/${attr}
 }
 
+# Generic test for specific filesystem feature.
+# Currently only implemented to test overlayfs features.
+_require_scratch_feature()
+{
+       local feature=$1
+
+       case "$FSTYP" in
+       overlay)
+               _require_scratch_overlay_feature ${feature}
+               ;;
+       *)
+               _fail "Test for feature '${feature}' of ${FSTYP} is not implemented"
+               ;;
+       esac
+}
 
 init_rc