fi
}
-_btrfs_get_subvolid()
-{
- mnt=$1
- name=$2
-
- $BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
-}
-
# Prints the md5 checksum of a given file
_md5_checksum()
{
file="$4"
xfs_io_args="$5"
- "$XFS_IO_PROG" $xfs_io_args -f -c "pwrite -S $pattern $offset $len" "$file"
+ $XFS_IO_PROG $xfs_io_args -f -c "pwrite -S $pattern $offset $len" "$file"
}
# mmap-write a byte into a range of a file
mmap_len="$4"
file="$5"
- "$XFS_IO_PROG" -f -c "mmap -rw 0 $mmap_len" -c "mwrite -S $pattern $offset $len" "$file"
+ $XFS_IO_PROG -f -c "mmap -rw 0 $mmap_len" -c "mwrite -S $pattern $offset $len" "$file"
}
# ls -l w/ selinux sometimes puts a dot at the end:
fi
fi
-# check for correct setup
+_dump_err()
+{
+ err_msg="$*"
+ echo "$err_msg"
+}
+
+_dump_err2()
+{
+ err_msg="$*"
+ >2& echo "$err_msg"
+}
+
+_log_err()
+{
+ err_msg="$*"
+ echo "$err_msg" | tee -a $seqres.full
+ echo "(see $seqres.full for details)"
+}
+
+# make sure we have a standard umask
+umask 022
+
+# check for correct setup and source the $FSTYP specific functions now
case "$FSTYP" in
xfs)
[ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
[ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
[ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
[ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
+
+ . ./common/xfs
;;
udf)
[ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
;;
btrfs)
[ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
+
+ . ./common/btrfs
;;
ext4)
[ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found"
;;
cifs)
;;
+ ceph)
+ ;;
+ overlay)
+ ;;
reiser4)
[ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
;;
esac
-# make sure we have a standard umask
-umask 022
+if [ ! -z "$REPORT_LIST" ]; then
+ . ./common/report
+ _assert_report_list
+fi
_mount()
{
$MOUNT_PROG `_mount_ops_filter $*`
}
+# Call _mount to do mount operation but also save mountpoint to
+# MOUNTED_POINT_STACK. Note that the mount point must be the last parameter
+_get_mount()
+{
+ local mnt_point=${!#}
+
+ _mount $*
+ if [ $? -eq 0 ]; then
+ MOUNTED_POINT_STACK="$mnt_point $MOUNTED_POINT_STACK"
+ else
+ return 1
+ fi
+}
+
+# Unmount the last mounted mountpoint in MOUNTED_POINT_STACK
+# and return it to caller
+_put_mount()
+{
+ local last_mnt=`echo $MOUNTED_POINT_STACK | awk '{print $1}'`
+
+ if [ -n "$last_mnt" ]; then
+ $UMOUNT_PROG $last_mnt
+ fi
+ MOUNTED_POINT_STACK=`echo $MOUNTED_POINT_STACK | cut -d\ -f2-`
+}
+
+# Unmount all mountpoints in MOUNTED_POINT_STACK and clear the stack
+_clear_mount_stack()
+{
+ if [ -n "$MOUNTED_POINT_STACK" ]; then
+ $UMOUNT_PROG $MOUNTED_POINT_STACK
+ fi
+ MOUNTED_POINT_STACK=""
+}
+
_scratch_options()
{
type=$1
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
}
-_scratch_mount()
+_supports_filetype()
{
- _mount -t $FSTYP `_scratch_mount_options $*`
+ local dir=$1
+
+ local fstyp=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $2}'`
+ case "$fstyp" in
+ xfs)
+ xfs_info $dir | grep -q "ftype=1"
+ ;;
+ ext2|ext3|ext4)
+ local dev=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $1}'`
+ tune2fs -l $dev | grep -q filetype
+ ;;
+ *)
+ local testfile=$dir/$$.ftype
+ touch $testfile
+ # look for DT_UNKNOWN files
+ local unknowns=$(src/t_dir_type $dir u | wc -l)
+ rm $testfile
+ # 0 unknowns is success
+ return $unknowns
+ ;;
+ esac
}
-_scratch_unmount()
+# helper function to do the actual overlayfs mount operation
+_overlay_mount_dirs()
{
- $UMOUNT_PROG $SCRATCH_DEV
+ local lowerdir=$1
+ local upperdir=$2
+ local workdir=$3
+ shift 3
+
+ $MOUNT_PROG -t overlay -o lowerdir=$lowerdir -o upperdir=$upperdir \
+ -o workdir=$workdir $*
}
-_scratch_remount()
+_overlay_mkdirs()
{
- _scratch_unmount
- _scratch_mount
+ local dir=$1
+
+ mkdir -p $dir/$OVL_UPPER
+ mkdir -p $dir/$OVL_LOWER
+ mkdir -p $dir/$OVL_WORK
+ mkdir -p $dir/$OVL_MNT
}
-_test_mount()
+# 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()
{
- _test_options mount
- _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
+ 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
}
-_test_remount()
+_overlay_base_test_mount()
{
- $UMOUNT_PROG $TEST_DEV
- _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
}
-_scratch_mkfs_options()
+_overlay_test_mount()
{
- _scratch_options mkfs
- echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
+ _overlay_base_test_mount && \
+ _overlay_mount $OVL_BASE_TEST_DIR $TEST_DIR $*
}
-_scratch_metadump()
+_overlay_base_scratch_mount()
{
- dumpfile=$1
- options=
+ 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
- [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
- options="-l $SCRATCH_LOGDEV"
+ _mount $OVL_BASE_MOUNT_OPTIONS \
+ $SELINUX_MOUNT_OPTIONS \
+ $OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_MNT
+}
- xfs_metadump $options $SCRATCH_DEV $dumpfile
+_overlay_base_scratch_unmount()
+{
+ [ -n "$OVL_BASE_SCRATCH_DEV" -a -n "$OVL_BASE_SCRATCH_MNT" ] || return 0
+
+ $UMOUNT_PROG $OVL_BASE_SCRATCH_MNT
}
-_setup_large_xfs_fs()
+_overlay_scratch_mount()
{
- fs_size=$1
- local tmp_dir=/tmp/
+ _overlay_base_scratch_mount && \
+ _overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
+}
- [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
- [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
- [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
+_overlay_base_test_unmount()
+{
+ [ -n "$OVL_BASE_TEST_DEV" -a -n "$OVL_BASE_TEST_DIR" ] || return 0
- # calculate the size of the file we need to allocate.
- # Default free space in the FS is 50GB, but you can specify more via
- # SCRATCH_DEV_EMPTY_SPACE
- file_size=$(($fs_size - 50*1024*1024*1024))
- file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
+ $UMOUNT_PROG $OVL_BASE_TEST_DIR
+}
- # mount the filesystem, create the file, unmount it
- _scratch_mount 2>&1 >$tmp_dir/mnt.err
- local status=$?
- if [ $status -ne 0 ]; then
- echo "mount failed"
- cat $tmp_dir/mnt.err >&2
- rm -f $tmp_dir/mnt.err
- return $status
- fi
- rm -f $tmp_dir/mnt.err
+_overlay_test_unmount()
+{
+ $UMOUNT_PROG $TEST_DIR
+ _overlay_base_test_unmount
+}
- xfs_io -F -f \
- -c "truncate $file_size" \
- -c "falloc -k 0 $file_size" \
- -c "chattr +d" \
- $SCRATCH_MNT/.use_space 2>&1 > /dev/null
- export NUM_SPACE_FILES=1
- status=$?
- umount $SCRATCH_MNT
- if [ $status -ne 0 ]; then
- echo "large file prealloc failed"
- cat $tmp_dir/mnt.err >&2
- return $status
- fi
- return 0
+_overlay_scratch_unmount()
+{
+ $UMOUNT_PROG $SCRATCH_MNT
+ _overlay_base_scratch_unmount
}
-_scratch_mkfs_xfs_opts()
+_scratch_mount()
{
- mkfs_opts=$*
+ if [ "$FSTYP" == "overlay" ]; then
+ _overlay_scratch_mount $*
+ return $?
+ fi
+ _mount -t $FSTYP `_scratch_mount_options $*`
+}
- # remove crc related mkfs options if mkfs.xfs doesn't support v5 xfs
- if [ -n "$XFS_MKFS_HAS_NO_META_SUPPORT" ]; then
- mkfs_opts=`echo $mkfs_opts | sed "s/-m\s\+crc=.//"`
- fi
+_scratch_unmount()
+{
+ case "$FSTYP" in
+ overlay)
+ _overlay_scratch_unmount
+ ;;
+ btrfs)
+ $UMOUNT_PROG $SCRATCH_MNT
+ ;;
+ *)
+ $UMOUNT_PROG $SCRATCH_DEV
+ ;;
+ esac
+}
- _scratch_options mkfs
+_scratch_remount()
+{
+ local opts="$1"
- $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
+ if test -n "$opts"; then
+ mount -o "remount,$opts" $SCRATCH_MNT
+ fi
}
+_scratch_cycle_mount()
+{
+ local opts="$1"
-_scratch_mkfs_xfs_supported()
+ if [ "$FSTYP" = tmpfs ]; then
+ _scratch_remount "$opts"
+ return
+ fi
+ if test -n "$opts"; then
+ opts="-o $opts"
+ fi
+ _scratch_unmount
+ _scratch_mount "$opts"
+}
+
+_test_mount()
+{
+ if [ "$FSTYP" == "overlay" ]; then
+ _overlay_test_mount $*
+ return $?
+ fi
+ _test_options mount
+ _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
+}
+
+_test_unmount()
{
- mkfs_opts=$*
+ if [ "$FSTYP" == "overlay" ]; then
+ _overlay_test_unmount
+ else
+ $UMOUNT_PROG $TEST_DEV
+ fi
+}
- _scratch_options mkfs
+_test_cycle_mount()
+{
+ if [ "$FSTYP" = tmpfs ]; then
+ return
+ fi
+ _test_unmount
+ _test_mount
+}
- $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
+_scratch_mkfs_options()
+{
+ _scratch_options mkfs
+ echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
}
-_scratch_mkfs_xfs()
+# Do the actual mkfs work on SCRATCH_DEV. Firstly mkfs with both MKFS_OPTIONS
+# and user specified mkfs options, if that fails (due to conflicts between mkfs
+# options), do a second mkfs with only user provided mkfs options.
+#
+# First param is the mkfs command without any mkfs options and device.
+# Second param is the filter to remove unnecessary messages from mkfs stderr.
+# Other extra mkfs options are followed.
+_scratch_do_mkfs()
{
- # extra mkfs options can be added by tests
+ local mkfs_cmd=$1
+ local mkfs_filter=$2
+ shift 2
local extra_mkfs_options=$*
-
- local tmp_dir=/tmp/
+ local mkfs_status
+ local tmp=`mktemp`
# save mkfs output in case conflict means we need to run again.
# only the output for the mkfs that applies should be shown
- _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
- 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
- local mkfs_status=$?
-
+ eval "$mkfs_cmd $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV" \
+ 2>$tmp.mkfserr 1>$tmp.mkfsstd
+ mkfs_status=$?
- # a mkfs failure may be caused by conflicts between
- # $MKFS_OPTIONS and $extra_mkfs_options
- if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
+ # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
+ # $extra_mkfs_options
+ if [ $mkfs_status -ne 0 -a -n "$extra_mkfs_options" ]; then
(
echo -n "** mkfs failed with extra mkfs options "
echo "added to \"$MKFS_OPTIONS\" by test $seq **"
) >> $seqres.full
# running mkfs again. overwrite previous mkfs output files
- _scratch_mkfs_xfs_opts $extra_mkfs_options \
- 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
- local mkfs_status=$?
- fi
-
- if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
- # manually parse the mkfs output to get the fs size in bytes
- local fs_size
- fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
- if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
- my $size = $1 * $2;
- print STDOUT "$size\n";
- }'`
- _setup_large_xfs_fs $fs_size
+ eval "$mkfs_cmd $extra_mkfs_options $SCRATCH_DEV" \
+ 2>$tmp.mkfserr 1>$tmp.mkfsstd
mkfs_status=$?
fi
- # output stored mkfs output, filtering unnecessary warnings from stderr
- cat $tmp_dir.mkfsstd
- cat $tmp_dir.mkfserr | sed \
- -e '/less than device physical sector/d' \
- -e '/switching to logical sector/d' \
- >&2
- rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
+ # output stored mkfs output, filtering unnecessary output from stderr
+ cat $tmp.mkfsstd
+ eval "cat $tmp.mkfserr | $mkfs_filter" >&2
+ rm -f $tmp*
return $mkfs_status
}
-# xfs_check script is planned to be deprecated. But, we want to
-# be able to invoke "xfs_check" behavior in xfstests in order to
-# maintain the current verification levels.
-_xfs_check()
+_scratch_metadump()
{
- OPTS=" "
- DBOPTS=" "
- USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
+ dumpfile=$1
+ shift
+ options=
- while getopts "b:fi:l:stvV" c
- do
- case $c in
- s) OPTS=$OPTS"-s ";;
- t) OPTS=$OPTS"-t ";;
- v) OPTS=$OPTS"-v ";;
- i) OPTS=$OPTS"-i "$OPTARG" ";;
- b) OPTS=$OPTS"-b "$OPTARG" ";;
- f) DBOPTS=$DBOPTS" -f";;
- l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
- V) $XFS_DB_PROG -p xfs_check -V
- return $?
- ;;
- esac
- done
- set -- extra $@
- shift $OPTIND
- case $# in
- 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
- status=$?
- ;;
- 2) echo $USAGE 1>&1
- status=2
- ;;
- esac
- return $status
+ [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+ options="-l $SCRATCH_LOGDEV"
+
+ xfs_metadump $options "$@" $SCRATCH_DEV $dumpfile
}
_setup_large_ext4_fs()
fi
export NUM_SPACE_FILES=$nfiles
- umount $SCRATCH_MNT
+ _scratch_unmount
if [ $status -ne 0 ]; then
echo "large file prealloc failed"
cat $tmp_dir/mnt.err >&2
_scratch_mkfs_ext4()
{
- # extra mkfs options can be added by tests
- local extra_mkfs_options=$*
-
- local tmp_dir=/tmp/
+ local mkfs_cmd="$MKFS_EXT4_PROG -F"
+ local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
+ local tmp=`mktemp`
+ local mkfs_status
- $MKFS_EXT4_PROG -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
- 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
- local mkfs_status=$?
- # a mkfs failure may be caused by conflicts between
- # $MKFS_OPTIONS and $extra_mkfs_options
- if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
- (
- echo -n "** mkfs failed with extra mkfs options "
- echo "added to \"$MKFS_OPTIONS\" by test $seq **"
- echo -n "** attempting to mkfs using only test $seq "
- echo "options: $extra_mkfs_options **"
- ) >> $seqres.full
-
- # running mkfs again. overwrite previous mkfs output files
- $MKFS_EXT4_PROG -F $extra_mkfs_options $SCRATCH_DEV \
- 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
- local mkfs_status=$?
- fi
+ _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
+ mkfs_status=$?
if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
# manually parse the mkfs output to get the fs size in bytes
- fs_size=`cat $tmp_dir.mkfsstd | awk ' \
+ fs_size=`cat $tmp.mkfsstd | awk ' \
/^Block size/ { split($2, a, "="); bs = a[2] ; } \
/ inodes, / { blks = $3 } \
/reserved for the super user/ { resv = $1 } \
mkfs_status=$?
fi
- # output stored mkfs output
- cat $tmp_dir.mkfserr >&2
- cat $tmp_dir.mkfsstd
- rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
+ # output mkfs stdout and stderr
+ cat $tmp.mkfsstd
+ cat $tmp.mkfserr >&2
return $mkfs_status
}
cifs)
# do nothing for cifs
;;
+ ceph)
+ # do nothing for ceph
+ ;;
+ overlay)
+ # do nothing for overlay
+ ;;
udf)
$MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
;;
nfs*)
# do nothing for nfs
;;
+ overlay)
+ # do nothing for overlay
+ ;;
udf)
$MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
;;
# remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
_scratch_cleanup_files()
{
- _scratch_mount
- rm -rf $SCRATCH_MNT/*
- _scratch_unmount
+ case $FSTYP in
+ overlay)
+ # Avoid rm -rf /* if we messed up
+ [ -n "$OVL_BASE_SCRATCH_MNT" ] || return 1
+ _overlay_base_scratch_mount || return 1
+ rm -rf $OVL_BASE_SCRATCH_MNT/* || return 1
+ _overlay_mkdirs $OVL_BASE_SCRATCH_MNT
+ # leave base fs mouted so tests can setup lower/upper dir files
+ ;;
+ *)
+ [ -n "$SCRATCH_MNT" ] || return 1
+ _scratch_mount
+ rm -rf $SCRATCH_MNT/*
+ _scratch_unmount
+ ;;
+ esac
}
_scratch_mkfs()
{
- case $FSTYP in
- xfs)
- _scratch_mkfs_xfs $*
- ;;
- nfs*)
- # unable to re-create NFS, just remove all files in $SCRATCH_MNT to
- # avoid EEXIST caused by the leftover files created in previous runs
- _scratch_cleanup_files
- ;;
- cifs)
- # unable to re-create CIFS, just remove all files in $SCRATCH_MNT to
- # avoid EEXIST caused by the leftover files created in previous runs
- _scratch_cleanup_files
- ;;
- udf)
- $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
- ;;
- btrfs)
- $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
- ;;
- ext2|ext3)
- $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV
- ;;
- ext4)
- _scratch_mkfs_ext4 $*
- ;;
- tmpfs)
- # do nothing for tmpfs
- ;;
- f2fs)
- $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
- ;;
- *)
- yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
- ;;
- esac
+ local mkfs_cmd=""
+ local mkfs_filter=""
+ local mkfs_status
+
+ case $FSTYP in
+ nfs*|cifs|ceph|overlay)
+ # 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
+ _scratch_cleanup_files
+ return $?
+ ;;
+ tmpfs)
+ # do nothing for tmpfs
+ return 0
+ ;;
+ ext4)
+ _scratch_mkfs_ext4 $*
+ return $?
+ ;;
+ xfs)
+ _scratch_mkfs_xfs $*
+ return $?
+ ;;
+ udf)
+ mkfs_cmd="$MKFS_UDF_PROG"
+ mkfs_filter="cat"
+ ;;
+ btrfs)
+ mkfs_cmd="$MKFS_BTRFS_PROG"
+ mkfs_filter="cat"
+ ;;
+ ext2|ext3)
+ mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
+ mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
+ ;;
+ f2fs)
+ mkfs_cmd="$MKFS_F2FS_PROG"
+ mkfs_filter="cat"
+ ;;
+ ocfs2)
+ mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
+ mkfs_filter="grep -v -e ^mkfs\.ocfs2"
+ ;;
+ *)
+ mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
+ mkfs_filter="cat"
+ ;;
+ esac
+
+ _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $*
+ return $?
+}
+
+# Helper function to get a spare or replace-target device from
+# configured SCRATCH_DEV_POLL, must call _scratch_dev_pool_get()
+# before _spare_dev_get(). Replace-target-device/Spare-device will
+# be assigned to SPARE_DEV.
+# As of now only one replace-target-device/spare-device can be
+# assigned.
+#
+# Usage:
+# _scratch_dev_pool_get() <ndevs>
+# _spare_dev_get()
+# :: do stuff
+# _spare_dev_put()
+# _scratch_dev_pool_put()
+#
+_spare_dev_get()
+{
+ typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ _fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
+ fi
+
+ if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
+ _fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
+ fi
+
+ # Check if the spare is already assigned
+ typeset -p SPARE_DEV >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ if [ ! -z "$SPARE_DEV" ]; then
+ _fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
+ fi
+ fi
+
+ local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
+ local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
+
+ if [ $ndevs -eq $config_ndevs ]; then
+ _notrun "All devs used no spare"
+ fi
+ # Get a dev that is not used
+ local devs[]="( $SCRATCH_DEV_POOL_SAVED )"
+ SPARE_DEV=${devs[@]:$ndevs:1}
+ export SPARE_DEV
+}
+
+_spare_dev_put()
+{
+ typeset -p SPARE_DEV >/dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ _fail "Bug: unset val, must call _spare_dev_get before its put"
+ fi
+
+ if [ -z "$SPARE_DEV" ]; then
+ _fail "Bug: str empty, must call _spare_dev_get before its put"
+ fi
+
+ export SPARE_DEV=""
+}
+
+#
+# Generally test cases will have..
+# _require_scratch_dev_pool X
+# to make sure it has the enough scratch devices including
+# replace-target and spare device. Now arg1 here is the
+# required number of scratch devices by a-test-case excluding
+# the replace-target and spare device. So this function will
+# set SCRATCH_DEV_POOL to the specified number of devices.
+#
+# Usage:
+# _scratch_dev_pool_get() <ndevs>
+# :: do stuff
+#
+# _scratch_dev_pool_put()
+#
+_scratch_dev_pool_get()
+{
+ if [ $# -ne 1 ]; then
+ _fail "Usage: _scratch_dev_pool_get ndevs"
+ fi
+
+ local test_ndevs=$1
+ local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
+ local devs[]="( $SCRATCH_DEV_POOL )"
+
+ typeset -p config_ndevs >/dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ _fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
+ fi
+
+ if [ $config_ndevs -lt $test_ndevs ]; then
+ _notrun "Need at least test requested number of ndevs $test_ndevs"
+ fi
+
+ SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
+ export SCRATCH_DEV_POOL_SAVED
+ SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
+ export SCRATCH_DEV_POOL
+}
+
+_scratch_dev_pool_put()
+{
+ typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ _fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
+ fi
+
+ if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
+ _fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
+ fi
+
+ export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
+ export SCRATCH_DEV_POOL_SAVED=""
}
_scratch_pool_mkfs()
esac
}
+# Return the amount of free memory available on the system
+_free_memory_bytes()
+{
+ free -b | grep ^Mem | awk '{print $4}'
+}
+
# Create fs of certain size on scratch device
# _scratch_mkfs_sized <size in bytes> [optional blocksize]
_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)
+ ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4|ocfs2)
def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
;;
esac
blocks=`expr $fssize / $blocksize`
- if [ "$HOSTOS" == "Linux" ]; then
+ if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
devsize=`blockdev --getsize64 $SCRATCH_DEV`
[ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
fi
ext2|ext3|ext4|ext4dev)
${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
;;
+ ocfs2)
+ yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
+ ;;
udf)
$MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
;;
btrfs)
- $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
+ local mixed_opt=
+ (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
+ $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
;;
reiser4)
# mkfs.resier4 requires size in KB as input for creating filesystem
$MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
`expr $fssize / 1024`
;;
+ f2fs)
+ # mkfs.f2fs requires # of sectors as an input for the size
+ sector_size=`blockdev --getss $SCRATCH_DEV`
+ $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
+ ;;
+ tmpfs)
+ free_mem=`_free_memory_bytes`
+ if [ "$free_mem" -lt "$fssize" ] ; then
+ _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
+ fi
+ export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
+ ;;
*)
_notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
;;
_scratch_mkfs
}
+# Create fs of certain blocksize on scratch device
+# _scratch_mkfs_blocksized blocksize
+_scratch_mkfs_blocksized()
+{
+ blocksize=$1
+
+ re='^[0-9]+$'
+ if ! [[ $blocksize =~ $re ]] ; then
+ _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
+ fi
+
+ case $FSTYP in
+ xfs)
+ _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
+ ;;
+ ext2|ext3|ext4)
+ ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
+ ;;
+ ocfs2)
+ yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize -C $blocksize $SCRATCH_DEV
+ ;;
+ *)
+ _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
+ ;;
+ esac
+}
+
_scratch_resvblks()
{
case $FSTYP in
esac
}
-_scratch_xfs_db_options()
-{
- SCRATCH_OPTIONS=""
- [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
- SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
- echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
-}
-_scratch_xfs_logprint()
+# 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()
{
- SCRATCH_OPTIONS=""
- [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
- SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
- $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
-}
-
-_scratch_xfs_check()
-{
- SCRATCH_OPTIONS=""
- [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
- SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
- [ "$LARGE_SCRATCH_DEV" = yes ] && \
- SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
- _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
-}
-
-_scratch_xfs_repair()
-{
- SCRATCH_OPTIONS=""
- [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
- SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
- [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
- SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
- [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
- $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
+ case $FSTYP in
+ xfs)
+ _scratch_xfs_repair "$@" 2>&1
+ res=$?
+ if [ "$res" -ne 0 ]; 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
+ if [ $res -ne 0 ]; then
+ _dump_err2 "xfs_repair failed, err=$res"
+ fi
+ 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
+ ;;
+ *)
+ _dump_err2 "fsck.$FSTYP failed, err=$res"
+ ;;
+ esac
+ return $res
+ ;;
+ esac
}
_get_pids_by_name()
'
}
-# check if run as root
-#
-_need_to_be_root()
-{
- id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
- if [ "$id" -ne 0 ]
- then
- echo "Arrgh ... you need to be root (not uid=$id) to run this test"
- exit 1
- fi
-}
-
-
#
# _df_device : get an IRIX style df line for a given device
#
{
echo "$*" > $seqres.notrun
echo "$seq not run: $*"
- rm -f ${RESULT_DIR}/require_test
- rm -f ${RESULT_DIR}/require_scratch
+ rm -f ${RESULT_DIR}/require_test*
+ rm -f ${RESULT_DIR}/require_scratch*
+
status=0
exit
}
_notrun "not suitable for this OS: $HOSTOS"
}
+# check if a FS on a device is mounted
+# if so, verify that it is mounted on mount point
+# if fstype is given as argument, verify that it is also
+# mounted with correct fs type
+#
+_check_mounted_on()
+{
+ local devname=$1
+ local dev=$2
+ local mntname=$3
+ 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 "`
+ [ -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
+ 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
+ echo "$devname=$dev is mounted but not a type $type filesystem"
+ # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
+ _df_device $dev
+ return 3 # 3 = mounted as wrong type
+ fi
+ return 0 # 0 = mounted as expected
+}
+
# this test needs a scratch partition - check we're ok & unmount it
# No post-test check of the device is required. e.g. the test intentionally
# finishes the test with the filesystem in a corrupt state
_require_scratch_nocheck()
{
case "$FSTYP" in
- nfs*)
+ nfs*|ceph)
echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
_notrun "this test requires a valid \$SCRATCH_DEV"
_notrun "this test requires a valid \$SCRATCH_MNT"
fi
;;
+ overlay)
+ if [ -z "$OVL_BASE_SCRATCH_MNT" -o ! -d "$OVL_BASE_SCRATCH_MNT" ]; then
+ _notrun "this test requires a valid \$OVL_BASE_SCRATCH_MNT as ovl base dir"
+ fi
+ # if $SCRATCH_MNT is derived from $OVL_BASE_SCRATCH_MNT then
+ # don't check $SCRATCH_MNT dir here because base fs may not be mounted
+ # and we will create the mount point anyway on _overlay_mount
+ if [ "$SCRATCH_MNT" != "$OVL_BASE_SCRATCH_MNT/$OVL_MNT" -a ! -d "$SCRATCH_MNT" ]; then
+ _notrun "this test requires a valid \$SCRATCH_MNT"
+ fi
+ ;;
tmpfs)
if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
then
;;
esac
- # mounted?
- # Note that we use -F here so grep doesn't try to interpret an NFS over
- # IPv6 server as a regular expression.
- if _mount | grep -F -q $SCRATCH_DEV
+ _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
+ local err=$?
+ [ $err -le 1 ] || exit 1
+ if [ $err -eq 0 ]
then
- # if it's mounted, make sure its on $SCRATCH_MNT
- if ! _mount | grep -F $SCRATCH_DEV | grep -q $SCRATCH_MNT
- then
- echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
- exit 1
- fi
- # and then unmount it
- if ! $UMOUNT_PROG $SCRATCH_DEV
+ # if it's mounted, unmount it
+ if ! _scratch_unmount
then
echo "failed to unmount $SCRATCH_DEV"
exit 1
_require_test()
{
case "$FSTYP" in
- nfs*)
+ nfs*|ceph)
echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
- _notrun "this test requires a valid \$TEST_DIR"
+ _notrun "this test requires a valid \$TEST_DEV"
fi
if [ ! -d "$TEST_DIR" ]; then
_notrun "this test requires a valid \$TEST_DIR"
_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"
+ fi
+ if [ ! -d "$TEST_DIR" ]; then
+ _notrun "this test requires a valid \$TEST_DIR"
+ fi
+ ;;
tmpfs)
if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
then
;;
esac
- # mounted?
- # Note that we use -F here so grep doesn't try to interpret an NFS over
- # IPv6 server as a regular expression.
- if _mount | grep -F -q $TEST_DEV
+ _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR
+ local err=$?
+ [ $err -le 1 ] || exit 1
+ if [ $err -ne 0 ]
then
- # if it's mounted, make sure its on $TEST_DIR
- if ! _mount | grep -F $TEST_DEV | grep -q $TEST_DIR
- then
- echo "\$TEST_DEV is mounted but not on \$TEST_DIR - aborting"
- exit 1
- fi
- else
- out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
- if [ $? -ne 1 ]; then
- echo $out
+ if ! _test_mount
+ then
+ echo "!!! failed to mount $TEST_DEV on $TEST_DIR"
exit 1
fi
fi
fi
}
+# this test requires tmpfs filesystem support
+#
+_require_tmpfs()
+{
+ modprobe tmpfs >/dev/null 2>&1
+ grep -q tmpfs /proc/filesystems ||
+ _notrun "this test requires tmpfs support"
+}
+
# this test requires that (large) loopback device files are not in use
#
_require_no_large_scratch_dev()
fi
}
-# this test requires the projid32bit feature to be available in mkfs.xfs.
-#
-_require_projid32bit()
-{
- _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
- || _notrun "mkfs.xfs doesn't have projid32bit feature"
-}
-
-_require_projid16bit()
-{
- _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
- || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
-}
-
-# this test requires the crc feature to be available in mkfs.xfs
-#
-_require_xfs_mkfs_crc()
-{
- _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
- || _notrun "mkfs.xfs doesn't have crc feature"
-}
-
-# this test requires the xfs kernel support crc feature
-#
-_require_xfs_crc()
-{
- _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
- _scratch_mount >/dev/null 2>&1 \
- || _notrun "Kernel doesn't support crc feature"
- umount $SCRATCH_MNT
-}
-
# this test requires the ext4 kernel support crc feature on scratch device
#
_require_scratch_ext4_crc()
dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
_scratch_mount >/dev/null 2>&1 \
|| _notrun "Kernel doesn't support metadata_csum feature"
- umount $SCRATCH_MNT
+ _scratch_unmount
}
-# this test requires the xfs kernel support crc feature on scratch device
-#
-_require_scratch_xfs_crc()
+# Check the specified feature whether it is available in mkfs.ext4 or not.
+_require_ext4_mkfs_feature()
{
- _scratch_mkfs_xfs >/dev/null 2>&1
- _scratch_mount >/dev/null 2>&1 \
- || _notrun "Kernel doesn't support crc feature"
- xfs_info $SCRATCH_MNT | grep -q 'crc=1' || _notrun "crc feature not supported by this filesystem"
- umount $SCRATCH_MNT
-}
+ local feature=$1
+ local testfile=/tmp/$$.ext4_mkfs
-# this test requires the bigalloc feature to be available in mkfs.ext4
-#
-_require_ext4_mkfs_bigalloc()
-{
- $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 512m >/dev/null 2>&1 \
- || _notrun "mkfs.ext4 doesn't have bigalloc feature"
+ if [ -z "$feature" ]; then
+ echo "Usage: _require_ext4_mkfs_feature feature"
+ exit 1
+ fi
+
+ touch $testfile
+ local result=$($MKFS_EXT4_PROG -F -O $feature -n $testfile 512m 2>&1)
+ rm -f $testfile
+ echo $result | grep -q "Invalid filesystem option" && \
+ _notrun "mkfs.ext4 doesn't support $feature feature"
}
# this test requires the ext4 kernel support bigalloc feature
$MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
_scratch_mount >/dev/null 2>&1 \
|| _notrun "Ext4 kernel doesn't support bigalloc feature"
- umount $SCRATCH_MNT
-}
-
-# this test requires the finobt feature to be available in mkfs.xfs
-#
-_require_xfs_mkfs_finobt()
-{
- _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
- || _notrun "mkfs.xfs doesn't have finobt feature"
-}
-
-# this test requires the xfs kernel support finobt feature
-#
-_require_xfs_finobt()
-{
- _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
- _scratch_mount >/dev/null 2>&1 \
- || _notrun "Kernel doesn't support finobt feature"
- umount $SCRATCH_MNT
-}
-
-# this test requires xfs sysfs attribute support
-#
-_require_xfs_sysfs()
-{
- attr=$1
- sysfsdir=/sys/fs/xfs
-
- if [ ! -e $sysfsdir ]; then
- _notrun "no kernel support for XFS sysfs attributes"
- fi
-
- if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
- _notrun "sysfs attribute '$attr' is not supported"
- fi
-}
-
-# this test requires the xfs sparse inode feature
-#
-_require_xfs_sparse_inodes()
-{
- _scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
- || _notrun "mkfs.xfs does not support sparse inodes"
- _scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
- _scratch_mount >/dev/null 2>&1 \
- || _notrun "kernel does not support sparse inodes"
- umount $SCRATCH_MNT
+ _scratch_unmount
}
# this test requires that external log/realtime devices are not in use
_require_odirect
}
+# this test requires that a test program exists under src/
+# $1 - command (require)
+#
+_require_test_program()
+{
+ SRC_TEST=src/$1
+ [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
+}
+
# run an aio-dio program
# $1 - command
_run_aiodio()
return $status
}
+# this test requires y2038 sysfs switch and filesystem
+# timestamp ranges support.
+_require_y2038()
+{
+ local device=${1:-$TEST_DEV}
+ local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
+
+ if [ ! -e $sysfsdir ]; then
+ _notrun "no kernel support for y2038 sysfs switch"
+ fi
+
+ local tsmin tsmax
+ read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
+ if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
+ _notrun "filesystem $FSTYP timestamp bounds are unknown"
+ fi
+}
+
+_filesystem_timestamp_range()
+{
+ device=${1:-$TEST_DEV}
+ case $FSTYP in
+ ext4)
+ if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | cut -d: -f2) -gt 128 ]; then
+ echo "-2147483648 15032385535"
+ else
+ echo "-2147483648 2147483647"
+ fi
+ ;;
+
+ xfs)
+ echo "-2147483648 2147483647"
+ ;;
+ jfs)
+ echo "0 4294967295"
+ ;;
+ f2fs)
+ echo "-2147483648 2147483647"
+ ;;
+ *)
+ echo "-1 -1"
+ ;;
+ esac
+}
+
# indicate whether YP/NIS is active or not
#
_yp_active()
{
local dn
dn=$(domainname 2>/dev/null)
- test -n "${dn}" -a "${dn}" != "(none)"
+ test -n "${dn}" -a "${dn}" != "(none)" -a "${dn}" != "localdomain"
echo $?
}
cat /etc/group
}
-# check for the fsgqa user on the machine
+# check for a user on the machine, fsgqa as default
#
_require_user()
{
qa_user=fsgqa
+ if [ -n "$1" ];then
+ qa_user=$1
+ fi
_cat_passwd | grep -q $qa_user
[ "$?" == "0" ] || _notrun "$qa_user user not defined."
echo /bin/true | su $qa_user
[ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
}
-# check for the fsgqa group on the machine
+# check for a group on the machine, fsgqa as default
#
_require_group()
{
qa_group=fsgqa
+ if [ -n "$1" ];then
+ qa_group=$1
+ fi
_cat_group | grep -q $qa_group
[ "$?" == "0" ] || _notrun "$qa_group user not defined."
}
then
echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
else
- echo $1 | su $qa_user 2>&1 | _filter_user_do
+ echo $1 | su -s /bin/bash $qa_user 2>&1 | _filter_user_do
fi
}
_require_xfs_io_command()
{
- if [ $# -ne 1 ]
+ if [ -z "$1" ]
then
- echo "Usage: _require_xfs_io_command command" 1>&2
+ echo "Usage: _require_xfs_io_command command [switch]" 1>&2
exit 1
fi
command=$1
+ shift
+ param="$*"
testfile=$TEST_DIR/$$.xfs_io
case $command in
+ "chproj")
+ testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1`
+ ;;
"falloc" )
testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
;;
- "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" )
+ "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" | "funshare")
testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
-c "$command 4k 8k" $testfile 2>&1`
;;
echo $testio | egrep -q "invalid option|Is a directory" && \
_notrun "xfs_io $command support is missing"
;;
+ "fsmap" )
+ testio=`$XFS_IO_PROG -f -c "fsmap" $testfile 2>&1`
+ echo $testio | egrep -q "Inappropriate ioctl" && \
+ _notrun "xfs_io $command support is missing"
+ ;;
+ "open")
+ # -c "open $f" is broken in xfs_io <= 4.8. Along with the fix,
+ # 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" && \
+ _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`
esac
_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 "foreign file active" && \
+ _notrun "xfs_io $command not supported on $FSTYP"
+
+ test -z "$param" && return
+ $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
+ _notrun "xfs_io $command doesn't support $param"
}
# check that kernel and filesystem support direct I/O
_require_odirect()
{
- testfile=$TEST_DIR/$$.direct
- $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
- if [ $? -ne 0 ]; then
- _notrun "O_DIRECT is not supported"
- fi
- rm -f $testfile 2>&1 > /dev/null
+ if [ $FSTYP = "ext4" ] ; then
+ if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
+ _notrun "ext4 encryption doesn't support O_DIRECT"
+ fi
+ fi
+ testfile=$TEST_DIR/$$.direct
+ $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ _notrun "O_DIRECT is not supported"
+ fi
+ rm -f $testfile 2>&1 > /dev/null
+}
+
+# Check that the filesystem supports swapfiles
+_require_scratch_swapfile()
+{
+ _require_scratch
+
+ _scratch_mkfs >/dev/null
+ _scratch_mount
+
+ # Minimum size for mkswap is 10 pages
+ local size=$(($(get_page_size) * 10))
+
+ _pwrite_byte 0x61 0 "$size" "$SCRATCH_MNT/swap" >/dev/null 2>&1
+ mkswap "$SCRATCH_MNT/swap" >/dev/null 2>&1
+ if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
+ _scratch_unmount
+ _notrun "swapfiles are not supported"
+ fi
+
+ swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
+ _scratch_unmount
}
# Check that a fs has enough free space (in 1024b blocks)
BLOCKS=$2 # in units of 1024
let GB=$BLOCKS/1024/1024
- FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
+ FREE_BLOCKS=`df -kP $MNT | grep -v Filesystem | awk '{print $4}'`
[ $FREE_BLOCKS -lt $BLOCKS ] && \
_notrun "This test requires at least ${GB}GB free on $MNT to run"
}
_notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
}
+_require_runas()
+{
+ _require_test_program "runas"
+}
+
+_runas()
+{
+ "$here/src/runas" "$@"
+}
+
+_require_richacl_prog()
+{
+ _require_command "$GETRICHACL_PROG" getrichacl
+ _require_command "$SETRICHACL_PROG" setrichacl
+}
+
+_require_scratch_richacl_xfs()
+{
+ _scratch_mkfs_xfs_supported -m richacl=1 >/dev/null 2>&1 \
+ || _notrun "mkfs.xfs doesn't have richacl feature"
+ _scratch_mkfs_xfs -m richacl=1 >/dev/null 2>&1
+ _scratch_mount >/dev/null 2>&1 \
+ || _notrun "kernel doesn't support richacl feature on $FSTYP"
+ _scratch_unmount
+}
+
+_require_scratch_richacl_ext4()
+{
+ _scratch_mkfs -O richacl >/dev/null 2>&1 \
+ || _notrun "can't mkfs $FSTYP with option -O richacl"
+ _scratch_mount >/dev/null 2>&1 \
+ || _notrun "kernel doesn't support richacl feature on $FSTYP"
+ _scratch_unmount
+}
+
+_require_scratch_richacl_support()
+{
+ _scratch_mount
+ $GETFATTR_PROG -n system.richacl >/dev/null 2>&1 \
+ || _notrun "this test requires richacl support on \$SCRATCH_DEV"
+ _scratch_unmount
+}
+
+_require_scratch_richacl()
+{
+ case "$FSTYP" in
+ xfs) _require_scratch_richacl_xfs
+ ;;
+ ext4) _require_scratch_richacl_ext4
+ ;;
+ nfs*|cifs|overlay)
+ _require_scratch_richacl_support
+ ;;
+ *) _notrun "this test requires richacl support on \$SCRATCH_DEV"
+ ;;
+ esac
+}
+
+_scratch_mkfs_richacl()
+{
+ case "$FSTYP" in
+ xfs) _scratch_mkfs_xfs -m richacl=1
+ ;;
+ ext4) _scratch_mkfs -O richacl
+ ;;
+ nfs*|cifs|overlay)
+ _scratch_mkfs
+ ;;
+ esac
+}
+
# check that a FS on a device is mounted
# if so, return mount point
#
_mount_or_remount_rw()
{
- if [ $# -ne 3 ]
- then
- echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
- exit 1
- fi
- mount_opts=$1
- device=$2
- mountpoint=$3
+ if [ $# -ne 3 ]; then
+ echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
+ exit 1
+ fi
+ mount_opts=$1
+ device=$2
+ mountpoint=$3
- if [ $USE_REMOUNT -eq 0 ]
- then
- if ! _mount -t $FSTYP $mount_opts $device $mountpoint
- then
- echo "!!! failed to remount $device on $mountpoint"
- return 0 # ok=0
- fi
- else
- _remount $device rw
- fi
+ if [ $USE_REMOUNT -eq 0 ]; then
+ if [ "$FSTYP" != "overlay" ]; then
+ _mount -t $FSTYP $mount_opts $device $mountpoint
+ else
+ _overlay_mount $device $mountpoint
+ fi
+ if [ $? -ne 0 ]; then
+ _dump_err "!!! failed to remount $device on $mountpoint"
+ return 0 # ok=0
+ fi
+ else
+ _remount $device rw
+ fi
- return 1 # ok=1
+ return 1 # ok=1
}
# Check a generic filesystem in no-op mode; this assumes that the
ok=1
if [ "$type" = "$FSTYP" ]
- then
- # mounted ...
- mountpoint=`_umount_or_remount_ro $device`
- fi
-
- fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
- if [ $? -ne 0 ]
- then
- echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
-
- echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
- echo "*** fsck.$FSTYP output ***" >>$seqres.full
- cat $tmp.fsck >>$seqres.full
- echo "*** end fsck.$FSTYP output" >>$seqres.full
-
- ok=0
- fi
- rm -f $tmp.fsck
-
- if [ $ok -eq 0 ]
- then
- echo "*** mount output ***" >>$seqres.full
- _mount >>$seqres.full
- echo "*** end mount output" >>$seqres.full
- elif [ "$type" = "$FSTYP" ]
- then
- # was mounted ...
- _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
- ok=$?
- fi
-
- if [ $ok -eq 0 ]; then
- status=1
- if [ "$iam" != "check" ]; then
- exit 1
- fi
- return 1
- fi
-
- return 0
-}
-
-# run xfs_check and friends on a FS.
-
-_check_xfs_filesystem()
-{
- if [ $# -ne 3 ]
- then
- echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
- exit 1
- fi
-
- extra_mount_options=""
- extra_options=""
- device=$1
- if [ -f $device ];then
- extra_options="-f"
- fi
-
- if [ "$2" != "none" ]; then
- extra_log_options="-l$2"
- extra_mount_options="-ologdev=$2"
- fi
-
- if [ "$3" != "none" ]; then
- extra_rt_options="-r$3"
- extra_mount_options=$extra_mount_options" -ortdev=$3"
- fi
- extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
-
- [ "$FSTYP" != xfs ] && return 0
-
- type=`_fs_type $device`
- ok=1
-
- if [ "$type" = "xfs" ]
- then
- # mounted ...
- mountpoint=`_umount_or_remount_ro $device`
- fi
-
- $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
- | tee $tmp.logprint | grep -q "<CLEAN>"
- if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
- then
- echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
-
- echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
- echo "*** xfs_logprint -t output ***" >>$seqres.full
- cat $tmp.logprint >>$seqres.full
- echo "*** end xfs_logprint output" >>$seqres.full
-
- ok=0
- fi
-
- # xfs_check runs out of memory on large files, so even providing the test
- # option (-t) to avoid indexing the free space trees doesn't make it pass on
- # large filesystems. Avoid it.
- if [ "$LARGE_SCRATCH_DEV" != yes ]; then
- _xfs_check $extra_log_options $device 2>&1 |\
- _fix_malloc >$tmp.fs_check
- fi
- if [ -s $tmp.fs_check ]
- then
- echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
-
- echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
- echo "*** xfs_check output ***" >>$seqres.full
- cat $tmp.fs_check >>$seqres.full
- echo "*** end xfs_check output" >>$seqres.full
-
- ok=0
+ then
+ # mounted ...
+ mountpoint=`_umount_or_remount_ro $device`
fi
- $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
+ fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
if [ $? -ne 0 ]
then
- echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
-
- echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
- echo "*** xfs_repair -n output ***" >>$seqres.full
- cat $tmp.repair | _fix_malloc >>$seqres.full
- echo "*** end xfs_repair output" >>$seqres.full
+ _log_err "_check_generic_filesystem: filesystem on $device is inconsistent"
+ echo "*** fsck.$FSTYP output ***" >>$seqres.full
+ cat $tmp.fsck >>$seqres.full
+ echo "*** end fsck.$FSTYP output" >>$seqres.full
ok=0
fi
- rm -f $tmp.fs_check $tmp.logprint $tmp.repair
+ rm -f $tmp.fsck
if [ $ok -eq 0 ]
then
echo "*** mount output ***" >>$seqres.full
_mount >>$seqres.full
echo "*** end mount output" >>$seqres.full
- elif [ "$type" = "xfs" ]
+ elif [ "$type" = "$FSTYP" ]
then
- _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
+ # was mounted ...
+ _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
+ ok=$?
fi
if [ $ok -eq 0 ]; then
return 0
}
-_check_xfs_test_fs()
-{
- TEST_LOG="none"
- TEST_RT="none"
- [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
- TEST_LOG="$TEST_LOGDEV"
-
- [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
- TEST_RT="$TEST_RTDEV"
-
- _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
-
- # check for ipath consistency
- if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
- # errors go to stderr
- xfs_check_ipaths $TEST_DIR >/dev/null
- xfs_repair_ipaths -n $TEST_DIR >/dev/null
- fi
-}
-
-_check_btrfs_filesystem()
-{
- device=$1
-
- # If type is set, we're mounted
- type=`_fs_type $device`
- ok=1
-
- if [ "$type" = "$FSTYP" ]
- then
- # mounted ...
- mountpoint=`_umount_or_remount_ro $device`
- fi
-
- btrfsck $device >$tmp.fsck 2>&1
- if [ $? -ne 0 ]
- then
- echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
-
- echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
- echo "*** fsck.$FSTYP output ***" >>$seqres.full
- cat $tmp.fsck >>$seqres.full
- echo "*** end fsck.$FSTYP output" >>$seqres.full
-
- ok=0
- fi
- rm -f $tmp.fsck
-
- if [ $ok -eq 0 ]
- then
- echo "*** mount output ***" >>$seqres.full
- _mount >>$seqres.full
- echo "*** end mount output" >>$seqres.full
- elif [ "$type" = "$FSTYP" ]
- then
- # was mounted ...
- _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
- ok=$?
- fi
-
- if [ $ok -eq 0 ]; then
- status=1
- if [ "$iam" != "check" ]; then
- exit 1
- fi
- return 1
- fi
-
- return 0
-}
-
_check_test_fs()
{
case $FSTYP in
cifs)
# no way to check consistency for cifs
;;
+ ceph)
+ # no way to check consistency for CephFS
+ ;;
+ overlay)
+ # no way to check consistency for overlay
+ ;;
udf)
# do nothing for now
;;
cifs)
# Don't know how to check a CIFS filesystem, yet.
;;
+ ceph)
+ # no way to check consistency for CephFS
+ ;;
+ overlay)
+ # no way to check consistency for overlay
+ ;;
btrfs)
_check_btrfs_filesystem $device
;;
fi
}
+_link_out_file_named()
+{
+ export FEATURES=$2
+ SUFFIX=$(perl -e '
+ my %feathash;
+ my $feature, $result, $suffix, $opts;
+
+ foreach $feature (split(/,/, $ENV{"FEATURES"})) {
+ $feathash{$feature} = 1;
+ }
+ $result = "default";
+ while (<>) {
+ my $found = 1;
+
+ chomp;
+ ($opts, $suffix) = split(/ *: */);
+ foreach my $opt (split(/,/, $opts)) {
+ if (!exists($feathash{$opt})) {
+ $found = 0;
+ last;
+ }
+ }
+ if ($found == 1) {
+ $result = $suffix;
+ last;
+ }
+ }
+ print $result
+ ' <$seqfull.cfg)
+ rm -f $1
+ SRC=$(basename $1)
+ ln -fs $SRC.$SUFFIX $1
+}
+
_link_out_file()
{
- if [ -z "$1" -o -z "$2" ]; then
- echo Error must pass src and dst.
- exit
+ if [ $# -eq 0 ]; then
+ FEATURES="$(_get_os_name)"
+ if [ -n "$MOUNT_OPTIONS" ]; then
+ FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
+ fi
+ else
+ FEATURES=$1
fi
- rm -f $2
- SUFFIX=$(_get_os_name())
- ln -s $1.$SUFFIX $2
+
+ _link_out_file_named $seqfull.out "$FEATURES"
}
_die()
exit 1
}
+# convert urandom incompressible data to compressible text data
+_ddt()
+{
+ od /dev/urandom | dd iflag=fullblock ${*}
+}
+
#takes files, randomdata
_nfiles()
{
if [ $size -gt 0 ]; then
if [ "$2" == "false" ]; then
dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
+ elif [ "$2" == "comp" ]; then
+ _ddt of=$file bs=1024 count=$size 2>&1 | _filter_dd
else
dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
fi
depth=2 # depth of tree from root to leaves
verbose=false
root=root # path of initial root of directory tree
- randomdata=false # -x data type urandom or zero
+ randomdata=false # -x data type urandom, zero or compressible
OPTIND=1
- while getopts "d:f:n:r:s:v:x" c
+ while getopts "d:f:n:r:s:v:x:c" c
do
case $c in
d) depth=$OPTARG;;
v) verbose=true;;
r) root=$OPTARG;;
x) randomdata=true;;
+ c) randomdata=comp;;
esac
done
#
_test_inode_flag()
{
- flag=$1
- file=$2
+ flag=$1
+ file=$2
- if which $XFS_IO_PROG >/dev/null; then
- if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
- return 0
- fi
- fi
- return 1
+ if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
+ return 0
+ fi
+ return 1
}
# query the given files extsize allocator hint in bytes (if any)
#
_test_inode_extsz()
{
- file=$1
- blocks=""
+ file=$1
+ blocks=""
- if which $XFS_IO_PROG >/dev/null; then
blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
awk '/^xattr.extsize =/ { print $3 }'`
- fi
- [ -z "$blocks" ] && blocks="0"
- echo $blocks
+ [ -z "$blocks" ] && blocks="0"
+ echo $blocks
}
# scratch_dev_pool should contain the disks pool for the btrfs raid
done
}
-# We check for btrfs and (optionally) features of the btrfs command
-_require_btrfs()
-{
- cmd=$1
- _require_command "$BTRFS_UTIL_PROG" btrfs
- if [ -z "$1" ]; then
- return 1;
- fi
- $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
- [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
-}
-
# Check that fio is present, and it is able to execute given jobfile
_require_fio()
{
_scratch_unmount
}
+# Does dax mount option work on this dev/fs?
+_require_scratch_dax()
+{
+ _require_scratch
+ _scratch_mkfs > /dev/null 2>&1
+ _scratch_mount -o dax
+ # Check options to be sure. XFS ignores dax option
+ # and goes on if dev underneath does not support dax.
+ _fs_options $SCRATCH_DEV | grep -qw "dax" || \
+ _notrun "$SCRATCH_DEV $FSTYP does not support -o dax"
+ _scratch_unmount
+}
+
# Does norecovery support by this fs?
_require_norecovery()
{
_require_dumpe2fs
$DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
_notrun "$FSTYP on $DEV not configured with metadata journaling"
+ # ext4 might not load a journal
+ _exclude_scratch_mount_option "noload"
;;
*)
# by default we pass; if you need to, add your fs above!
_notrun "cloner binary not present at $CLONER_PROG"
}
+# Normalize mount options from global $MOUNT_OPTIONS
+# Convert options like "-o opt1,opt2 -oopt3" to
+# "opt1 opt2 opt3"
+_normalize_mount_options()
+{
+ echo $MOUNT_OPTIONS | sed -n 's/-o\s*\(\S*\)/\1/gp'| sed 's/,/ /g'
+}
+
+# skip test if MOUNT_OPTIONS contains the given strings
+_exclude_scratch_mount_option()
+{
+ local mnt_opts=$(_normalize_mount_options)
+
+ while [ $# -gt 0 ]; do
+ if echo $mnt_opts | grep -qw "$1"; then
+ _notrun "mount option \"$1\" not allowed in this test"
+ fi
+ shift
+ done
+}
+
_require_atime()
{
+ _exclude_scratch_mount_option "noatime"
if [ "$FSTYP" == "nfs" ]; then
_notrun "atime related mount options have no effect on NFS"
fi
"$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
}
-_run_btrfs_util_prog()
-{
- run_check $BTRFS_UTIL_PROG $*
-}
-
-_require_btrfs_send_stream_version()
-{
- $BTRFS_UTIL_PROG send 2>&1 | \
- grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
- if [ $? -ne 0 ]; then
- _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
- fi
-
- # test if btrfs kernel supports send stream version 2
- if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
- _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
- fi
-}
-
-_require_btrfs_mkfs_feature()
-{
- if [ -z $1 ]; then
- echo "Missing feature name argument for _require_btrfs_mkfs_feature"
- exit 1
- fi
- feat=$1
- $MKFS_BTRFS_PROG -O list-all 2>&1 | \
- grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
- [ $? -eq 0 ] || \
- _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
-}
-
-_require_btrfs_fs_feature()
-{
- if [ -z $1 ]; then
- echo "Missing feature name argument for _require_btrfs_fs_feature"
- exit 1
- fi
- feat=$1
- modprobe btrfs > /dev/null 2>&1
- [ -e /sys/fs/btrfs/features/$feat ] || \
- _notrun "Feature $feat not supported by the available btrfs version"
-}
-
_require_test_symlinks()
{
# IRIX UDF does not support symlinks
_notrun "Require fcntl advisory locks support"
}
-# XFS ability to change UUIDs on V5/CRC filesystems
-#
-_require_meta_uuid()
-{
- # This will create a crc fs on $SCRATCH_DEV
- _require_xfs_crc
-
- $XFS_DB_PROG -x -c "uuid restore" $SCRATCH_DEV 2>&1 \
- | grep -q "invalid UUID\|supported on V5 fs" \
- && _notrun "Userspace doesn't support meta_uuid feature"
-
- $XFS_DB_PROG -x -c "uuid generate" $SCRATCH_DEV >/dev/null 2>&1
-
- _scratch_mount >/dev/null 2>&1 \
- || _notrun "Kernel doesn't support meta_uuid feature"
- umount $SCRATCH_MNT
-}
-
-_require_btrfs_dev_del_by_devid()
-{
- $BTRFS_UTIL_PROG device delete --help | egrep devid > /dev/null 2>&1
- [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old "\
- "(must support 'btrfs device delete <devid> /<mnt>')"
-}
-
_require_test_lsattr()
{
testio=$(lsattr -d $TEST_DIR 2>&1)
_notrun "lsattr not supported by test filesystem type: $FSTYP"
}
+_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
+
+ rm -f $TEST_DIR/syscalltest.out
+}
+
_get_total_inode()
{
if [ -z "$1" ]; then
echo $((avail_kb * 1024))
}
-# get btrfs profile configs being tested
-#
-# A set of pre-set profile configs are exported via _btrfs_profile_configs
-# array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
-# var in the format "metadata_profile:data_profile", multiple configs can be
-# seperated by space, e.g.
-# export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
-_btrfs_get_profile_configs()
-{
- if [ "$FSTYP" != "btrfs" ]; then
- return
- fi
-
- # no user specified btrfs profile configs, export the default configs
- if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
- # default configs
- _btrfs_profile_configs=(
- "-m single -d single"
- "-m dup -d single"
- "-m raid0 -d raid0"
- "-m raid1 -d raid0"
- "-m raid1 -d raid1"
- "-m raid10 -d raid10"
- "-m raid5 -d raid5"
- "-m raid6 -d raid6"
- )
-
- # remove dup/raid5/raid6 profiles if we're doing device replace
- # dup profile indicates only one device being used (SCRATCH_DEV),
- # but we don't want to replace SCRATCH_DEV, which will be used in
- # _scratch_mount/_check_scratch_fs etc.
- # and raid5/raid6 doesn't support replace yet
- if [ "$1" == "replace" ]; then
- _btrfs_profile_configs=(
- "-m single -d single"
- "-m raid0 -d raid0"
- "-m raid1 -d raid0"
- "-m raid1 -d raid1"
- "-m raid10 -d raid10"
- # add these back when raid5/6 is working with replace
- #"-m raid5 -d raid5"
- #"-m raid6 -d raid6"
- )
- fi
- export _btrfs_profile_configs
- return
- fi
-
- # parse user specified btrfs profile configs
- local i=0
- local cfg=""
- for cfg in $BTRFS_PROFILE_CONFIGS; do
- # turn "metadata:data" format to "-m metadata -d data"
- # and assign it to _btrfs_profile_configs array
- cfg=`echo "$cfg" | sed -e 's/^/-m /' -e 's/:/ -d /'`
- _btrfs_profile_configs[$i]="$cfg"
- let i=i+1
- done
-
- if [ "$1" == "replace" ]; then
- if echo ${_btrfs_profile_configs[*]} | grep -q raid[56]; then
- _notrun "RAID5/6 doesn't support btrfs device replace yet"
- fi
- if echo ${_btrfs_profile_configs[*]} | grep -q dup; then
- _notrun "Do not set dup profile in btrfs device replace test"
- fi
- fi
- export _btrfs_profile_configs
-}
-
-# stress btrfs by running balance operation in a loop
-_btrfs_stress_balance()
-{
- local btrfs_mnt=$1
- while true; do
- $BTRFS_UTIL_PROG balance start $btrfs_mnt
- done
-}
-
-# stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
-_btrfs_stress_subvolume()
-{
- local btrfs_dev=$1
- local btrfs_mnt=$2
- local subvol_name=$3
- local subvol_mnt=$4
-
- mkdir -p $subvol_mnt
- while true; do
- $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
- $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
- $UMOUNT_PROG $subvol_mnt
- $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
- done
-}
-
-# stress btrfs by running scrub in a loop
-_btrfs_stress_scrub()
-{
- local btrfs_mnt=$1
- while true; do
- $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
- done
-}
-
-# stress btrfs by defragmenting every file/dir in a loop and compress file
-# contents while defragmenting if second argument is not "nocompress"
-_btrfs_stress_defrag()
-{
- local btrfs_mnt=$1
- local compress=$2
-
- while true; do
- if [ "$compress" == "nocompress" ]; then
- find $btrfs_mnt \( -type f -o -type d \) -exec \
- $BTRFS_UTIL_PROG filesystem defrag {} \;
- else
- find $btrfs_mnt \( -type f -o -type d \) -exec \
- $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
- find $btrfs_mnt \( -type f -o -type d \) -exec \
- $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
- fi
- done
-}
-
-# stress btrfs by remounting it with different compression algorithms in a loop
-# run this with fsstress running at background could exercise the compression
-# code path and ensure no race when switching compression algorithm with constant
-# I/O activity.
-_btrfs_stress_remount_compress()
-{
- local btrfs_mnt=$1
- while true; do
- for algo in no zlib lzo; do
- $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
- done
- done
-}
-
-# stress btrfs by replacing devices in a loop
-# Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
-# device should be free(not used by btrfs)
-_btrfs_stress_replace()
-{
- local btrfs_mnt=$1
-
- # The device number in SCRATCH_DEV_POOL should be at least 3,
- # one is SCRATCH_DEV, one is to be replaced, one is free device
- # we won't replace SCRATCH_DEV, see below for reason
- if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
- echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
- return
- fi
-
- # take the last device as the first free_dev
- local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
-
- # free_dev should be really free
- if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
- echo "_btrfs_stress_replace: $free_dev is used by btrfs"
- return
- fi
-
- # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
- # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
- # _scratch_mount and _check_scratch_fs etc.
- local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
- -e "s# *$free_dev *##"`
-
- # set the first device in dev_pool as the first src_dev to be replaced
- local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
-
- echo "dev_pool=$dev_pool"
- echo "free_dev=$free_dev, src_dev=$src_dev"
- while true; do
- echo "Replacing $src_dev with $free_dev"
- $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
- if [ $? -ne 0 ]; then
- # don't update src_dev and free_dev if replace failed
- continue
- fi
- dev_pool="$dev_pool $free_dev"
- dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
- free_dev=$src_dev
- src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
- done
-}
-
-# find the right option to force output in bytes, older versions of btrfs-progs
-# print that by default, newer print human readable numbers with unit suffix
-_btrfs_qgroup_units()
-{
- $BTRFS_UTIL_PROG qgroup show --help 2>&1 | grep -q -- --raw && echo "--raw"
-}
-
# return device size in kb
_get_device_size()
{
-e "Internal error" \
-e "INFO: suspicious RCU usage" \
-e "INFO: possible circular locking dependency detected" \
+ -e "general protection fault:" \
$seqres.dmesg
if [ $? -eq 0 ]; then
- echo "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
+ _dump_err "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
return 1
else
rm -f $seqres.dmesg
fi
fi
- if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
- then
- echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
- $DF_PROG $TEST_DEV
- exit 1
+ # Sanity check that TEST partition is not mounted at another mount point
+ # or as another fs type
+ _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR $FSTYP || exit 1
+ if [ -n "$SCRATCH_DEV" ]; then
+ # Sanity check that SCRATCH partition is not mounted at another
+ # mount point, because it is about to be unmounted and formatted.
+ # Another fs type for scratch is fine (bye bye old fs type).
+ _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
+ [ $? -le 1 ] || exit 1
fi
- # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
- xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
- export XFS_IO_PROG="$XFS_IO_PROG -F"
- # xfs_copy doesn't work on v5 xfs yet without -d option
- if [ "$FSTYP" == "xfs" ] && [[ $MKFS_OPTIONS =~ crc=1 ]]; then
- export XFS_COPY_PROG="$XFS_COPY_PROG -d"
+ # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
+ $XFS_IO_PROG -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
+ export XFS_IO_PROG="$XFS_IO_PROG -F"
+
+ # xfs_io -i option starts an idle thread for xfs_io.
+ # With single threaded process, the file table is not shared
+ # and file structs are not reference counted.
+ # Spawning an idle thread can help detecting file struct
+ # reference leaks, so we want to enable the option whenever
+ # it is supported.
+ $XFS_IO_PROG -i -c quit 2>/dev/null && \
+ export XFS_IO_PROG="$XFS_IO_PROG -i"
+
+ # xfs_copy on v5 filesystems do not require the "-d" option if xfs_db
+ # can change the UUID on v5 filesystems
+ if [ "$FSTYP" == "xfs" ]; then
+ touch /tmp/$$.img
+ $MKFS_XFS_PROG -d file,name=/tmp/$$.img,size=512m >/dev/null 2>&1
+ # xfs_db will return 0 even if it can't generate a new uuid, so
+ # check the output to make sure if it can change UUID of V5 xfs
+ $XFS_DB_PROG -x -c "uuid generate" /tmp/$$.img \
+ | grep -q "invalid UUID\|supported on V5 fs" \
+ && export XFS_COPY_PROG="$XFS_COPY_PROG -d"
+ rm -f /tmp/$$.img
fi
}
_sysfs_dev()
{
- local _dev=$1
+ local _dev=`_real_dev $1`
local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
_maj=$(echo "ibase=16; $_maj" | bc)
echo /sys/dev/block/$_maj:$_min
}
-get_block_size()
+# Get the minimum block size of a file. Usually this is the
+# minimum fs block size, but some filesystems (ocfs2) do block
+# mappings in larger units.
+_get_file_block_size()
+{
+ if [ -z $1 ] || [ ! -d $1 ]; then
+ echo "Missing mount point argument for _get_file_block_size"
+ exit 1
+ fi
+ if [ "$FSTYP" = "ocfs2" ]; then
+ stat -c '%o' $1
+ else
+ _get_block_size $1
+ fi
+}
+
+# Get the minimum block size of an fs.
+_get_block_size()
{
if [ -z $1 ] || [ ! -d $1 ]; then
- echo "Missing mount point argument for get_block_size"
+ echo "Missing mount point argument for _get_block_size"
+ exit 1
+ fi
+ stat -f -c %S $1
+}
+
+get_page_size()
+{
+ echo $(getconf PAGE_SIZE)
+}
+
+
+run_fsx()
+{
+ echo fsx $@
+ args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
+ set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
+ echo "$@" >>$seqres.full
+ rm -f $TEST_DIR/junk
+ "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
+ if [ ${PIPESTATUS[0]} -ne 0 ]; then
+ cat $tmp.fsx
exit 1
fi
- echo `stat -f -c %S $1`
}
+# Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
+#
+# Only one argument is needed:
+# - attr: path name under /sys/fs/$FSTYP/DEV
+#
+# Usage example:
+# _require_fs_sysfs error/fail_at_unmount
+_require_fs_sysfs()
+{
+ local attr=$1
+ local dname=$(_short_dev $TEST_DEV)
+
+ if [ -z "$attr" -o -z "$dname" ];then
+ _fail "Usage: _require_fs_sysfs <sysfs_attr_path>"
+ fi
+
+ if [ ! -e /sys/fs/${FSTYP}/${dname}/${attr} ];then
+ _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
+ fi
+}
+
+# Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
+#
+# All arguments are necessary, and in this order:
+# - dev: device name, e.g. $SCRATCH_DEV
+# - attr: path name under /sys/fs/$FSTYP/$dev
+# - content: the content of $attr
+#
+# Usage example:
+# _set_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount 0
+_set_fs_sysfs_attr()
+{
+ local dev=$1
+ shift
+ local attr=$1
+ shift
+ local content="$*"
+
+ if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
+ _fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
+ fi
+
+ local dname=$(_short_dev $dev)
+ echo "$content" > /sys/fs/${FSTYP}/${dname}/${attr}
+}
+
+# Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
+#
+# All arguments are necessary, and in this order:
+# - dev: device name, e.g. $SCRATCH_DEV
+# - attr: path name under /sys/fs/$FSTYP/$dev
+#
+# Usage example:
+# _get_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount
+_get_fs_sysfs_attr()
+{
+ local dev=$1
+ local attr=$2
+
+ if [ ! -b "$dev" -o -z "$attr" ];then
+ _fail "Usage: _get_fs_sysfs_attr <mounted_device> <attr>"
+ fi
+
+ local dname=$(_short_dev $dev)
+ cat /sys/fs/${FSTYP}/${dname}/${attr}
+}
+
+
init_rc
################################################################################