common/fuzzy: if the fuzz verb is random, keep fuzzing until we get a new value
[xfstests-dev.git] / common / rc
index 756c414684292272c754cf346c941d5d76dbb3cb..0cda9da71f87fc081314f47277f82069ecd59ef5 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -162,16 +162,25 @@ case "$FSTYP" in
         [ "$MKFS_F2FS_PROG" = "" ] && _fatal "mkfs.f2fs not found"
         ;;
     nfs)
+        . ./common/nfs
         ;;
     cifs)
         ;;
     ceph)
         ;;
+    glusterfs)
+        ;;
     overlay)
+        . ./common/overlay
         ;;
     reiser4)
         [ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
         ;;
+    pvfs2)
+       ;;
+    ubifs)
+       [ "$UBIUPDATEVOL_PROG" = "" ] && _fatal "ubiupdatevol not found"
+       ;;
 esac
 
 if [ ! -z "$REPORT_LIST" ]; then
@@ -230,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"
        ;;
@@ -279,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;"
 
 }
@@ -299,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
 }
@@ -348,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
@@ -559,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
@@ -587,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
 }
 
@@ -668,9 +539,12 @@ _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" ] && \
+           $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
+           mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
 
        _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
        mkfs_status=$?
@@ -690,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
 }
@@ -706,9 +581,15 @@ _test_mkfs()
     ceph)
        # do nothing for ceph
        ;;
+    glusterfs)
+       # do nothing for glusterfs
+       ;;
     overlay)
        # do nothing for overlay
        ;;
+    pvfs2)
+       # do nothing for pvfs2
+       ;;
     udf)
         $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
        ;;
@@ -726,6 +607,7 @@ _test_mkfs()
 
 _mkfs_dev()
 {
+    local tmp=`mktemp -u`
     case $FSTYP in
     nfs*)
        # do nothing for nfs
@@ -733,31 +615,37 @@ _mkfs_dev()
     overlay)
        # do nothing for overlay
        ;;
+    pvfs2)
+       # 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
@@ -788,7 +676,7 @@ _scratch_mkfs()
        local mkfs_status
 
        case $FSTYP in
-       nfs*|cifs|ceph|overlay)
+       nfs*|cifs|ceph|overlay|glusterfs|pvfs2)
                # unable to re-create this fstyp, just remove all files in
                # $SCRATCH_MNT to avoid EEXIST caused by the leftover files
                # created in previous runs
@@ -799,6 +687,11 @@ _scratch_mkfs()
                # do nothing for tmpfs
                return 0
                ;;
+       ubifs)
+               # erase the UBI volume; reformated automatically on next mount
+               $UBIUPDATEVOL_PROG ${SCRATCH_DEV} -t
+               return 0
+               ;;
        ext4)
                _scratch_mkfs_ext4 $*
                return $?
@@ -815,7 +708,16 @@ _scratch_mkfs()
                mkfs_cmd="$MKFS_BTRFS_PROG"
                mkfs_filter="cat"
                ;;
-       ext2|ext3)
+       ext3)
+               mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
+               mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
+
+               # put journal on separate device?
+               [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+               $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
+               mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
+               ;;
+       ext2)
                mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
                mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
                ;;
@@ -877,7 +779,7 @@ _spare_dev_get()
                _notrun "All devs used no spare"
        fi
        # Get a dev that is not used
-       local devs[]="( $SCRATCH_DEV_POOL_SAVED )"
+       local -a devs="( $SCRATCH_DEV_POOL_SAVED )"
        SPARE_DEV=${devs[@]:$ndevs:1}
        export SPARE_DEV
 }
@@ -919,7 +821,7 @@ _scratch_dev_pool_get()
 
        local test_ndevs=$1
        local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
-       local devs[]="( $SCRATCH_DEV_POOL )"
+       local -a devs="( $SCRATCH_DEV_POOL )"
 
        typeset -p config_ndevs >/dev/null 2>&1
        if [ $? -ne 0 ]; then
@@ -986,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
@@ -1023,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
        ;;
@@ -1034,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 \
@@ -1101,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
        ;;
@@ -1307,7 +1236,8 @@ _fs_type()
     # Fix the filesystem type up here so that the callers don't
     # have to bother with this quirk.
     #
-    _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
+    _df_device $1 | $AWK_PROG '{ print $2 }' | \
+        sed -e 's/nfs4/nfs/' -e 's/fuse.glusterfs/glusterfs/'
 }
 
 # return the FS mount options of a mounted device
@@ -1349,6 +1279,25 @@ _is_block_dev()
     fi
 }
 
+# returns device number if a file is a character device
+#
+_is_char_dev()
+{
+       if [ $# -ne 1 ]; then
+               echo "Usage: _is_char_dev dev" 1>&2
+               exit 1
+       fi
+
+       _dev=$1
+       if [ -L "${_dev}" ]; then
+               _dev=`readlink -f "${_dev}"`
+       fi
+
+       if [ -c "${_dev}" ]; then
+               src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
+       fi
+}
+
 # Do a command, log it to $seqres.full, optionally test return status
 # and die if command fails. If called with one argument _do executes the
 # command, logs it, and returns its exit status. With two arguments _do
@@ -1375,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"
@@ -1462,24 +1412,19 @@ _check_mounted_on()
        local mnt=$4
        local type=$5
 
-       # Note that we use -F here so grep doesn't try to interpret an NFS over
-       # IPv6 server as a regular expression.  Because of that, we cannot use
-       # ^$dev so we use "$dev on " to avoid matching $dev to mount point field
-       # for overlay case, where $dev is a directory.
-       local mount_rec=`_mount | grep -F "$dev on "`
+       # find $dev as the source, and print result in "$dev $mnt" format
+       local mount_rec=`findmnt -rncv -S $dev -o SOURCE,TARGET`
        [ -n "$mount_rec" ] || return 1 # 1 = not mounted
 
        # if it's mounted, make sure its on $mnt
-       if ! (echo $mount_rec | grep -q "$dev on $mnt")
-       then
+       if [ "$mount_rec" != "$dev $mnt" ]; then
                echo "$devname=$dev is mounted but not on $mntname=$mnt - aborting"
                echo "Already mounted result:"
                echo $mount_rec
                return 2 # 2 = mounted on wrong mnt
        fi
 
-       if [ -n "$type" -a "`_fs_type $dev`" != "$type" ]
-       then
+       if [ -n "$type" -a "`_fs_type $dev`" != "$type" ]; then
                echo "$devname=$dev is mounted but not a type $type filesystem"
                # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
                _df_device $dev
@@ -1494,6 +1439,15 @@ _check_mounted_on()
 _require_scratch_nocheck()
 {
     case "$FSTYP" in
+       glusterfs)
+               echo $SCRATCH_DEV | egrep -q ":/?" > /dev/null 2>&1
+               if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
+                       _notrun "this test requires a valid \$SCRATCH_DEV"
+               fi
+               if [ ! -d "$SCRATCH_MNT" ]; then
+                       _notrun "this test requires a valid \$SCRATCH_MNT"
+               fi
+               ;;
        nfs*|ceph)
                echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
                if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
@@ -1503,6 +1457,15 @@ _require_scratch_nocheck()
                        _notrun "this test requires a valid \$SCRATCH_MNT"
                fi
                ;;
+       pvfs2)
+               echo $SCRATCH_DEV | grep -q "://" > /dev/null 2>&1
+               if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
+                       _notrun "this test requires a valid \$SCRATCH_DEV"
+               fi
+               if [ ! -d "$SCRATCH_MNT" ]; then
+                       _notrun "this test requires a valid \$SCRATCH_MNT"
+               fi
+               ;;
        cifs)
                echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
                if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
@@ -1529,6 +1492,15 @@ _require_scratch_nocheck()
                    _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
                fi
                ;;
+       ubifs)
+               # ubifs needs an UBI volume. This will be a char device, not a block device.
+               if [ ! -c "$SCRATCH_DEV" ]; then
+                       _notrun "this test requires a valid UBI volume for \$SCRATCH_DEV"
+               fi
+               if [ ! -d "$SCRATCH_MNT" ]; then
+                       _notrun "this test requires a valid \$SCRATCH_MNT"
+               fi
+               ;;
        *)
                 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
                 then
@@ -1573,6 +1545,15 @@ _require_scratch()
 _require_test()
 {
     case "$FSTYP" in
+       glusterfs)
+               echo $TEST_DEV | egrep -q ":/?" > /dev/null 2>&1
+               if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
+                       _notrun "this test requires a valid \$TEST_DEV"
+               fi
+               if [ ! -d "$TEST_DIR" ]; then
+                       _notrun "this test requires a valid \$TEST_DIR"
+               fi
+               ;;
        nfs*|ceph)
                echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
                if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
@@ -1591,6 +1572,15 @@ _require_test()
                     _notrun "this test requires a valid \$TEST_DIR"
                fi
                ;;
+       pvfs2)
+               echo $TEST_DEV | grep -q "://" > /dev/null 2>&1
+               if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
+                       _notrun "this test requires a valid \$TEST_DIR"
+               fi
+               if [ ! -d "$TEST_DIR" ]; then
+                       _notrun "this test requires a valid \$TEST_DIR"
+               fi
+               ;;
        overlay)
                if [ -z "$OVL_BASE_TEST_DIR" -o ! -d "$OVL_BASE_TEST_DIR" ]; then
                        _notrun "this test requires a valid \$TEST_DIR as ovl base dir"
@@ -1605,6 +1595,15 @@ _require_test()
                    _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
                fi
                ;;
+       ubifs)
+               # ubifs needs an UBI volume. This will be a char device, not a block device.
+               if [ ! -c "$TEST_DEV" ]; then
+                       _notrun "this test requires a valid UBI volume for \$TEST_DEV"
+               fi
+               if [ ! -d "$TEST_DIR" ]; then
+                       _notrun "this test requires a valid \$TEST_DIR"
+               fi
+               ;;
        *)
                 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
                 then
@@ -1635,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()
@@ -1746,6 +1754,23 @@ _require_block_device()
        fi
 }
 
+# this test requires a path to refere to a local block or character device
+# $1 - device
+_require_local_device()
+{
+       if [ -z "$1" ]; then
+               echo "Usage: _require_local_device <dev>" 1>&2
+               exit 1
+       fi
+       if [ "`_is_block_dev "$1"`" != "" ]; then
+               return 0
+       fi
+       if [ "`_is_char_dev "$1"`" != "" ]; then
+               return 0
+       fi
+       _notrun "require $1 to be local device"
+}
+
 # brd based ram disks erase the device when they receive a flush command when no
 # active references are present. This causes problems for DM devices sitting on
 # top of brd devices as DM doesn't hold active references to the brd device.
@@ -1823,7 +1848,24 @@ _require_nonexternal()
        _notrun "External device testing in progress, skipped this test"
 }
 
+# this test requires that the kernel supports asynchronous I/O
+_require_aio()
+{
+       $here/src/feature -A
+       case $? in
+       0)
+               ;;
+       1)
+               _notrun "kernel does not support asynchronous I/O"
+               ;;
+       *)
+               _fail "unexpected error testing for asynchronous I/O support"
+               ;;
+       esac
+}
+
 # this test requires that a (specified) aio-dio executable exists
+# and that the kernel supports asynchronous I/O.
 # $1 - command (optional)
 #
 _require_aiodio()
@@ -1836,6 +1878,7 @@ _require_aiodio()
         AIO_TEST=src/aio-dio-regress/$1
         [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
     fi
+    _require_aio
     _require_odirect
 }
 
@@ -1963,7 +2006,7 @@ _require_group()
         qa_group=$1
     fi
     _cat_group | grep -q $qa_group
-    [ "$?" == "0" ] || _notrun "$qa_group user not defined."
+    [ "$?" == "0" ] || _notrun "$qa_group group not defined."
 }
 
 _filter_user_do()
@@ -1978,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()
@@ -1993,17 +2031,25 @@ _require_xfs_io_command()
                echo "Usage: _require_xfs_io_command command [switch]" 1>&2
                exit 1
        fi
-       command=$1
+       local command=$1
        shift
-       param="$*"
+       local param="$*"
+       local param_checked=0
 
        testfile=$TEST_DIR/$$.xfs_io
        case $command in
        "chproj")
                testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1`
                ;;
+       "copy_range")
+               testcopy=$TEST_DIR/$$.copy.xfs_io
+               $XFS_IO_PROG -F -f -c "pwrite 0 4k" $testfile > /dev/null 2>&1
+               testio=`$XFS_IO_PROG -F -f -c "copy_range $testfile" $testcopy 2>&1`
+               rm -f $testcopy > /dev/null 2>&1
+               ;;
        "falloc" )
-               testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
+               testio=`$XFS_IO_PROG -F -f -c "falloc $param 0 1m" $testfile 2>&1`
+               param_checked=1
                ;;
        "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" | "funshare")
                testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
@@ -2011,7 +2057,8 @@ _require_xfs_io_command()
                ;;
        "fiemap")
                testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
-                       -c "fiemap -v" $testfile 2>&1`
+                       -c "fiemap -v $param" $testfile 2>&1`
+               param_checked=1
                ;;
        "flink" )
                testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
@@ -2021,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")
@@ -2029,14 +2076,19 @@ _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 probe 0" $TEST_DIR 2>&1`
+               echo $testio | grep -q "Inappropriate ioctl" && \
                        _notrun "xfs_io $command support is missing"
                ;;
        "utimes" )
                testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
                ;;
        *)
-               testio=`$XFS_IO_PROG -c "$command help" 2>&1`
+               testio=`$XFS_IO_PROG -c "help $command" 2>&1`
        esac
 
        rm -f $testfile 2>&1 > /dev/null
@@ -2044,12 +2096,22 @@ _require_xfs_io_command()
                _notrun "xfs_io $command support is missing"
        echo $testio | grep -q "Operation not supported" && \
                _notrun "xfs_io $command failed (old kernel/wrong fs?)"
+       echo $testio | grep -q "Invalid" && \
+               _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 | grep -q "Function not implemented" && \
+               _notrun "xfs_io $command support is missing (missing syscall?)"
+
+       [ -n "$param" ] || return
 
-       test -z "$param" && return
-       $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
-               _notrun "xfs_io $command doesn't support $param"
+       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
 }
 
 # check that kernel and filesystem support direct I/O
@@ -2132,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()
@@ -2426,9 +2503,14 @@ _check_test_fs()
     ceph)
        # no way to check consistency for CephFS
        ;;
+    glusterfs)
+       # no way to check consistency for GlusterFS
+       ;;
     overlay)
        # no way to check consistency for overlay
        ;;
+    pvfs2)
+       ;;
     udf)
        # do nothing for now
        ;;
@@ -2438,6 +2520,9 @@ _check_test_fs()
     tmpfs)
        # no way to check consistency for tmpfs
        ;;
+    ubifs)
+       # there is no fsck program for ubifs yet
+       ;;
     *)
        _check_generic_filesystem $TEST_DEV
        ;;
@@ -2473,15 +2558,23 @@ _check_scratch_fs()
     ceph)
        # no way to check consistency for CephFS
        ;;
+    glusterfs)
+       # no way to check consistency for GlusterFS
+       ;;
     overlay)
        # no way to check consistency for overlay
        ;;
+    pvfs2)
+       ;;
     btrfs)
        _check_btrfs_filesystem $device
        ;;
     tmpfs)
        # no way to check consistency for tmpfs
        ;;
+    ubifs)
+       # there is no fsck program for ubifs yet
+       ;;
     *)
        _check_generic_filesystem $device
        ;;
@@ -2520,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`
@@ -2800,6 +2891,16 @@ _require_freeze()
        [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
 }
 
+# Does NFS export work on this fs?
+_require_exportfs()
+{
+       _require_test_program "open_by_handle"
+       mkdir -p "$TEST_DIR"/exportfs_test
+       $here/src/open_by_handle -c "$TEST_DIR"/exportfs_test 2>&1 \
+               || _notrun "$FSTYP does not support NFS export"
+}
+
+
 # Does shutdown work on this fs?
 _require_scratch_shutdown()
 {
@@ -2850,7 +2951,7 @@ _require_metadata_journaling()
        fi
 
        case "$FSTYP" in
-       ext2|vfat|msdos)
+       ext2|vfat|msdos|udf)
                _notrun "$FSTYP does not support metadata journaling"
                ;;
        ext4)
@@ -2867,12 +2968,6 @@ _require_metadata_journaling()
        esac
 }
 
-# Does fiemap support?
-_require_fiemap()
-{
-       _require_xfs_io_command "fiemap"
-}
-
 _count_extents()
 {
        $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
@@ -2883,6 +2978,11 @@ _count_holes()
        $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
 }
 
+_count_attr_extents()
+{
+       $XFS_IO_PROG -c "fiemap -a" $1 | tail -n +2 | grep -v hole | wc -l
+}
+
 # arg 1 is dev to remove and is output of the below eg.
 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
 _devmgt_remove()
@@ -3077,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
@@ -3109,18 +3206,21 @@ _require_test_lsattr()
 
 _require_chattr()
 {
-    attribute=$1
-
-    touch $TEST_DIR/syscalltest
-    chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
-    status=$?
-    chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
-    if [ "$status" -ne 0 ]; then
-      _notrun "file system doesn't support chattr +$attribute"
-    fi
-    cat $TEST_DIR/syscalltest.out >> $seqres.full
+       if [ -z "$1" ]; then
+               echo "Usage: _require_chattr <attr>"
+               exit 1
+       fi
+       local attribute=$1
 
-    rm -f $TEST_DIR/syscalltest.out
+       touch $TEST_DIR/syscalltest
+       chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
+       status=$?
+       chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
+       if [ "$status" -ne 0 ]; then
+               _notrun "file system doesn't support chattr +$attribute"
+       fi
+       cat $TEST_DIR/syscalltest.out >> $seqres.full
+       rm -f $TEST_DIR/syscalltest.out
 }
 
 _get_total_inode()
@@ -3204,15 +3304,16 @@ _check_dmesg()
        # use sed \cregexpc address type, since $seqnum contains "/"
        dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
                tac | $filter >$seqres.dmesg
-       grep -q -e "kernel BUG at" \
+       egrep -q -e "kernel BUG at" \
             -e "WARNING:" \
             -e "BUG:" \
             -e "Oops:" \
             -e "possible recursive locking detected" \
             -e "Internal error" \
-            -e "INFO: suspicious RCU usage" \
+            -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)"
@@ -3364,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
@@ -3389,6 +3492,12 @@ _require_fs_sysfs()
        fi
 }
 
+_require_statx()
+{
+       $here/src/stat_test --check-statx ||
+       _notrun "This test requires the statx system call"
+}
+
 # Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
 #
 # All arguments are necessary, and in this order:
@@ -3435,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