Files
apfstests/common/rc
T
Chandan Babu R b13284d992 _scratch_mkfs_geom(): Filter out 'k' suffix from fs block size
If the original value of $MKFS_OPTIONS contained a block size value
having 'k' as a suffix (e.g. -b size=4k), then the newly constructed
value of $MKFS_OPTIONS will have 'k' suffixed to the value of
$blocksize.  $blocksize itself is specified in units of bytes. Hence
having 'k' suffixed to this value will result in an incorrect block
size.

This commit fixes the bug by conditionally filtering out the 'k'
suffix from block size option present in the original value of
$MKFS_OPTIONS.

Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
2021-02-28 21:02:22 +08:00

4413 lines
104 KiB
Plaintext

##/bin/bash
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2000-2006 Silicon Graphics, Inc. All Rights Reserved.
. common/config
BC=$(which bc 2> /dev/null) || BC=
# Some tests are not relevant or functional when testing XFS realtime
# subvolumes along with the rtinherit=1 mkfs option. In these cases,
# this test will opt-out of the test.
_require_no_rtinherit()
{
[ "$FSTYP" = "xfs" ] && echo "$MKFS_OPTIONS" |
egrep -q "rtinherit([^=]|=1|$)" && \
_notrun "rtinherit mkfs option is not supported by this test."
}
_require_math()
{
if [ -z "$BC" ]; then
_notrun "this test requires 'bc' tool for doing math operations"
fi
}
_math()
{
[ $# -le 0 ] && return
LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null
}
dd()
{
command dd --help 2>&1 | grep noxfer >/dev/null
if [ "$?" -eq 0 ]
then
command dd status=noxfer $@
else
command dd $@
fi
}
# Prints the md5 checksum of a given file
_md5_checksum()
{
md5sum $1 | cut -d ' ' -f1
}
# Write a byte into a range of a file
_pwrite_byte() {
local pattern="$1"
local offset="$2"
local len="$3"
local file="$4"
local xfs_io_args="$5"
$XFS_IO_PROG $xfs_io_args -f -c "pwrite -S $pattern $offset $len" "$file"
}
# mmap-write a byte into a range of a file
_mwrite_byte() {
local pattern="$1"
local offset="$2"
local len="$3"
local mmap_len="$4"
local file="$5"
$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:
# -rwxrw-r--. id1 id2 file1
# Also filter out lost+found directory on extN file system if present
_ls_l()
{
ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /" | grep -v 'lost+found'
}
_dump_err()
{
_err_msg="$*"
echo "$_err_msg"
}
_dump_err_cont()
{
_err_msg="$*"
echo -n "$_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"
[ "$XFS_INFO_PROG" = "" ] && _fatal "xfs_info 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"
;;
f2fs)
[ "$MKFS_F2FS_PROG" = "" ] && _fatal "mkfs.f2fs not found"
;;
nfs)
. ./common/nfs
;;
cifs)
;;
9p)
;;
ceph)
. ./common/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
. ./common/report
_assert_report_list
fi
_get_filesize()
{
stat -c %s "$1"
}
# Get hugepagesize in bytes
_get_hugepagesize()
{
local hugepgsz=$(awk '/Hugepagesize/ {print $2}' /proc/meminfo)
# Call _notrun if $hugepgsz is not a number
echo "$hugepgsz" | egrep -q ^[0-9]+$ || \
_notrun "Cannot get the value of Hugepagesize"
echo $((hugepgsz * 1024))
}
_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=${!#}
local mnt_dev=${@:(-2):1}
local scratch_opts=""
if [ "$mnt_dev" = "$SCRATCH_DEV" ]; then
_scratch_options mount
scratch_opts="$SCRATCH_OPTIONS"
fi
_mount $scratch_opts $*
if [ $? -eq 0 ]; then
# mount --move operation updates the mountpoint, so remove
# the old one and insert the new one
if [[ "$*" =~ --move|-M ]]; then
MOUNTED_POINT_STACK=`echo $MOUNTED_POINT_STACK | \
cut -d\ -f2-`
fi
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()
{
local type=$1
local rt_opt=""
local log_opt=""
SCRATCH_OPTIONS=""
if [ "$FSTYP" != "xfs" ]; then
return
fi
case $type in
mkfs)
SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
rt_opt="-r"
log_opt="-l"
;;
mount)
rt_opt="-o"
log_opt="-o"
;;
esac
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
}
_test_options()
{
local type=$1
local rt_opt=""
local log_opt=""
TEST_OPTIONS=""
if [ "$FSTYP" != "xfs" ]; then
return
fi
case $type in
mkfs)
rt_opt="-r"
log_opt="-l"
;;
mount)
rt_opt="-o"
log_opt="-o"
;;
esac
[ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
[ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
}
_mount_ops_filter()
{
local params="$*"
local last_index=$(( $# - 1 ))
#get mount point to handle dmapi mtpt option correctly
[ $last_index -gt 0 ] && shift $last_index
local fs_escaped=$1
echo $params | sed -e 's/dmapi/dmi/' \
| $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$fs_escaped\1\2#; print;"
}
# Used for mounting non-scratch devices (e.g. loop, dm constructs)
# with the safe set of scratch mount options (e.g. loop image may be
# hosted on $SCRATCH_DEV, so can't use external scratch devices).
_common_dev_mount_options()
{
echo $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $*
}
_scratch_mount_options()
{
_scratch_options mount
echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
$SCRATCH_DEV $SCRATCH_MNT
}
_supports_filetype()
{
local dir=$1
local fstyp=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $2}'`
case "$fstyp" in
xfs)
$XFS_INFO_PROG $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=$($here/src/t_dir_type $dir u | wc -l)
rm $testfile
# 0 unknowns is success
return $unknowns
;;
esac
}
# mount scratch device with given options but don't check mount status
_try_scratch_mount()
{
if [ "$FSTYP" == "overlay" ]; then
_overlay_scratch_mount $*
return $?
fi
_mount -t $FSTYP `_scratch_mount_options $*`
}
# mount scratch device with given options and _fail if mount fails
_scratch_mount()
{
_try_scratch_mount $* || _fail "mount failed"
}
_scratch_unmount()
{
case "$FSTYP" in
overlay)
_overlay_scratch_unmount
;;
btrfs)
$UMOUNT_PROG $SCRATCH_MNT
;;
*)
$UMOUNT_PROG $SCRATCH_DEV
;;
esac
}
_scratch_remount()
{
local opts="$1"
if test -n "$opts"; then
_try_scratch_mount "-o remount,$opts"
fi
}
_scratch_cycle_mount()
{
local opts="$1"
if [ "$FSTYP" = tmpfs ]; then
_scratch_remount "$opts"
return
fi
if test -n "$opts"; then
opts="-o $opts"
fi
_scratch_unmount
_try_scratch_mount "$opts" || _fail "cycle mount failed"
}
_scratch_shutdown()
{
if [ $FSTYP = "overlay" ]; then
# In lagacy overlay usage, it may specify directory as
# SCRATCH_DEV, in this case OVL_BASE_SCRATCH_DEV
# will be null, so check OVL_BASE_SCRATCH_DEV before
# running shutdown to avoid shutting down base fs accidently.
if [ -z $OVL_BASE_SCRATCH_DEV ]; then
_fail "_scratch_shutdown: call _require_scratch_shutdown first in test"
else
$here/src/godown $* $OVL_BASE_SCRATCH_MNT
fi
else
$here/src/godown $* $SCRATCH_MNT
fi
}
# Return a file path that can be used to shut down the scratch filesystem.
# Caller should _require_scratch_shutdown before using this.
_scratch_shutdown_handle()
{
if [ $FSTYP = "overlay" ]; then
echo $OVL_BASE_SCRATCH_MNT
else
echo $SCRATCH_MNT
fi
}
_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()
{
if [ "$FSTYP" == "overlay" ]; then
_overlay_test_unmount
else
$UMOUNT_PROG $TEST_DEV
fi
}
_test_cycle_mount()
{
if [ "$FSTYP" = tmpfs ]; then
return
fi
_test_unmount
_test_mount
}
_scratch_mkfs_options()
{
_scratch_options mkfs
echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
}
# 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()
{
local mkfs_cmd=$1
local mkfs_filter=$2
shift 2
local extra_mkfs_options=$*
local mkfs_status
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
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 -n "$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
eval "$mkfs_cmd $extra_mkfs_options $SCRATCH_DEV" \
2>$tmp.mkfserr 1>$tmp.mkfsstd
mkfs_status=$?
fi
# output stored mkfs output, filtering unnecessary output from stderr
cat $tmp.mkfsstd
eval "cat $tmp.mkfserr | $mkfs_filter" >&2
rm -f $tmp.mkfserr $tmp.mkfsstd
return $mkfs_status
}
_scratch_metadump()
{
local dumpfile=$1
shift
local options=
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
options="-l $SCRATCH_LOGDEV"
xfs_metadump $options "$@" $SCRATCH_DEV $dumpfile
}
_setup_large_ext4_fs()
{
local fs_size=$1
local tmp_dir=/tmp/
[ "$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
# Default free space in the FS is 50GB, but you can specify more via
# SCRATCH_DEV_EMPTY_SPACE
local space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
# mount the filesystem and create 16TB - 4KB files until we consume
# all the necessary space.
_try_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
local file_size=$((16*1024*1024*1024*1024 - 4096))
local nfiles=0
while [ $space_to_consume -gt $file_size ]; do
xfs_io -F -f \
-c "truncate $file_size" \
-c "falloc -k 0 $file_size" \
$SCRATCH_MNT/.use_space.$nfiles 2>&1
status=$?
if [ $status -ne 0 ]; then
break;
fi
space_to_consume=$(( $space_to_consume - $file_size ))
nfiles=$(($nfiles + 1))
done
# consume the remaining space.
if [ $space_to_consume -gt 0 ]; then
xfs_io -F -f \
-c "truncate $space_to_consume" \
-c "falloc -k 0 $space_to_consume" \
$SCRATCH_MNT/.use_space.$nfiles 2>&1
status=$?
fi
export NUM_SPACE_FILES=$nfiles
_scratch_unmount
if [ $status -ne 0 ]; then
echo "large file prealloc failed"
cat $tmp_dir/mnt.err >&2
return $status
fi
return 0
}
_scratch_mkfs_ext4()
{
local mkfs_cmd="$MKFS_EXT4_PROG -F"
local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \" | grep -v \"^$\""
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=$?
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=`cat $tmp.mkfsstd | awk ' \
/^Block size/ { split($2, a, "="); bs = a[2] ; } \
/ inodes, / { blks = $3 } \
/reserved for the super user/ { resv = $1 } \
END { fssize = bs * blks - resv; print fssize }'`
_setup_large_ext4_fs $fs_size
mkfs_status=$?
fi
# output mkfs stdout and stderr
cat $tmp.mkfsstd
cat $tmp.mkfserr >&2
rm -f $tmp.mkfserr $tmp.mkfsstd
return $mkfs_status
}
_test_mkfs()
{
case $FSTYP in
nfs*)
# do nothing for nfs
;;
cifs)
# do nothing for cifs
;;
9p)
# do nothing for 9p
;;
virtiofs)
# do nothing for virtiofs
;;
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
;;
btrfs)
$MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
;;
ext2|ext3|ext4)
$MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
;;
*)
yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
;;
esac
}
_mkfs_dev()
{
local tmp=`mktemp -u`
case $FSTYP in
nfs*)
# do nothing for nfs
;;
9p)
# do nothing for 9p
;;
virtiofs)
# do nothing for virtiofs
;;
overlay)
# do nothing for overlay
;;
pvfs2)
# do nothing for pvfs2
;;
udf)
$MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
;;
btrfs)
$MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
;;
ext2|ext3|ext4)
$MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
2>$tmp.mkfserr 1>$tmp.mkfsstd
;;
xfs)
$MKFS_PROG -t $FSTYP -- -f $MKFS_OPTIONS $* \
2>$tmp.mkfserr 1>$tmp.mkfsstd
;;
*)
yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
2>$tmp.mkfserr 1>$tmp.mkfsstd
;;
esac
if [ $? -ne 0 ]; then
# output stored mkfs output
cat $tmp.mkfserr >&2
cat $tmp.mkfsstd
status=1
exit 1
fi
rm -f $tmp.mkfserr $tmp.mkfsstd
}
# remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
_scratch_cleanup_files()
{
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()
{
local mkfs_cmd=""
local mkfs_filter=""
local mkfs_status
case $FSTYP in
nfs*|cifs|ceph|overlay|glusterfs|pvfs2|9p|virtiofs)
# 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
;;
ubifs)
# erase the UBI volume; reformated automatically on next mount
$UBIUPDATEVOL_PROG ${SCRATCH_DEV} -t
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"
;;
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 \""
;;
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 -a 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 -a 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()
{
case $FSTYP in
btrfs)
$MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
;;
*)
echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
;;
esac
}
# Return the amount of free memory available on the system
_free_memory_bytes()
{
free -b | grep ^Mem | awk '{print $4}'
}
_available_memory_bytes()
{
nf=`free -b | grep ^Mem | awk '{print NF}'`
if [[ nf -lt 7 ]]; then
# Doesn't have available field. Fallback.
_free_memory_bytes
else
free -b | grep ^Mem | awk '{print $7}'
fi
}
# Create fs of certain size on scratch device
# _scratch_mkfs_sized <size in bytes> [optional blocksize]
_scratch_mkfs_sized()
{
local fssize=$1
local blocksize=$2
local def_blksz
case $FSTYP in
xfs)
def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
;;
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
[ -z "$blocksize" ] && blocksize=4096
local re='^[0-9]+$'
if ! [[ $fssize =~ $re ]] ; then
_notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
fi
if ! [[ $blocksize =~ $re ]] ; then
_notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
fi
local blocks=`expr $fssize / $blocksize`
if [ -b "$SCRATCH_DEV" ]; then
local devsize=`blockdev --getsize64 $SCRATCH_DEV`
[ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
fi
if [ "$FSTYP" = "xfs" ] && [ -b "$SCRATCH_RTDEV" ]; then
local rtdevsize=`blockdev --getsize64 $SCRATCH_RTDEV`
[ "$fssize" -gt "$rtdevsize" ] && _notrun "Scratch rt device too small"
rt_ops="-r size=$fssize"
fi
case $FSTYP in
xfs)
# don't override MKFS_OPTIONS that set a block size.
echo $MKFS_OPTIONS |egrep -q "b?size="
if [ $? -eq 0 ]; then
_scratch_mkfs_xfs -d size=$fssize $rt_ops
else
_scratch_mkfs_xfs -d size=$fssize $rt_ops -b size=$blocksize
fi
;;
ext2|ext3|ext4|ext4dev)
${MKFS_PROG} -t $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.
local min_journal_size=8
local default_journal_size=128
if (( fssize/8 / (1024*1024) < default_journal_size )); then
local 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} -t $FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV $blocks
;;
ocfs2)
yes | ${MKFS_PROG} -t $FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
;;
udf)
$MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
;;
btrfs)
local mixed_opt=
# minimum size that's needed without the mixed option.
# Ref: btrfs-prog: btrfs_min_dev_size()
# Non mixed mode is also the default option.
(( fssize < $((256 * 1024 *1024)) )) && mixed_opt='--mixed'
$MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
;;
jfs)
${MKFS_PROG} -t $FSTYP $MKFS_OPTIONS $SCRATCH_DEV $blocks
;;
reiserfs)
${MKFS_PROG} -t $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 \
`expr $fssize / 1024`
;;
f2fs)
# mkfs.f2fs requires # of sectors as an input for the size
local sector_size=`blockdev --getss $SCRATCH_DEV`
$MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
;;
tmpfs)
local 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"
;;
esac
}
# Emulate an N-data-disk stripe w/ various stripe units
# _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
_scratch_mkfs_geom()
{
local sunit_bytes=$1
local swidth_mult=$2
local blocksize=$3
[ -z "$blocksize" ] && blocksize=4096
local sunit_blocks=$(( sunit_bytes / blocksize ))
local swidth_blocks=$(( sunit_blocks * swidth_mult ))
case $FSTYP in
xfs)
if echo "$MKFS_OPTIONS" | egrep -q "b?size="; then
MKFS_OPTIONS=$(echo "$MKFS_OPTIONS" | sed -r "s/(b?size=)[0-9]+k?/\1$blocksize/")
else
MKFS_OPTIONS+=" -b size=$blocksize"
fi
if echo "$MKFS_OPTIONS" | egrep -q "(su|sunit|sw|swidth)="; then
MKFS_OPTIONS=$(echo "$MKFS_OPTIONS" | sed -r \
-e "s/(su|sunit)=[0-9kmg]+/su=$sunit_bytes/" \
-e "s/(sw|swidth)=[0-9kmg]+/sw=$swidth_mult/")
else
MKFS_OPTIONS+=" -d su=$sunit_bytes,sw=$swidth_mult"
fi
;;
ext4|ext4dev)
MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
;;
*)
_notrun "can't mkfs $FSTYP with geometry"
;;
esac
_scratch_mkfs
}
# Create fs of certain blocksize on scratch device
# _scratch_mkfs_blocksized blocksize
_scratch_mkfs_blocksized()
{
local blocksize=$1
local 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} -t $FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
;;
gfs2)
${MKFS_PROG} -t $FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV
;;
ocfs2)
yes | ${MKFS_PROG} -t $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
xfs)
xfs_io -x -c "resblks $1" $SCRATCH_MNT
;;
*)
;;
esac
}
# 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()
{
case $FSTYP in
xfs)
_scratch_xfs_repair "$@" 2>&1
local res=$?
if [ "$res" -ne 0 ]; then
echo "xfs_repair returns $res; replay log?"
_try_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
;;
*)
local dev=$SCRATCH_DEV
local fstyp=$FSTYP
if [ $FSTYP = "overlay" -a -n "$OVL_BASE_SCRATCH_DEV" ]; then
_repair_overlay_scratch_fs
# Fall through to repair base fs
dev=$OVL_BASE_SCRATCH_DEV
fstyp=$OVL_BASE_FSTYP
$UMOUNT_PROG $OVL_BASE_SCRATCH_MNT
fi
# Let's hope fsck -y suffices...
fsck -t $fstyp -y $dev 2>&1
local res=$?
case $res in
$FSCK_OK|$FSCK_NONDESTRUCT|$FSCK_REBOOT)
res=0
;;
*)
_dump_err2 "fsck.$FSTYP failed, err=$res"
;;
esac
return $res
;;
esac
}
_get_pids_by_name()
{
if [ $# -ne 1 ]
then
echo "Usage: _get_pids_by_name process-name" 1>&2
exit 1
fi
# Algorithm ... all ps(1) variants have a time of the form MM:SS or
# HH:MM:SS before the psargs field, use this as the search anchor.
#
# Matches with $1 (process-name) occur if the first psarg is $1
# or ends in /$1 ... the matching uses sed's regular expressions,
# so passing a regex into $1 will work.
ps $PS_ALL_FLAGS \
| sed -n \
-e 's/$/ /' \
-e 's/[ ][ ]*/ /g' \
-e 's/^ //' \
-e 's/^[^ ]* //' \
-e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
-e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
}
#
# _df_device : get an IRIX style df line for a given device
#
# - returns "" if not mounted
# - returns fs type in field two (ala IRIX)
# - joins line together if split by fancy df formatting
# - strips header etc
#
_df_device()
{
if [ $# -ne 1 ]
then
echo "Usage: _df_device device" 1>&2
exit 1
fi
# Note that we use "==" here so awk doesn't try to interpret an NFS over
# IPv6 server as a regular expression.
$DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
($1==what) && (NF==1) {
v=$1
getline
print v, $0
exit
}
($1==what) {
print
exit
}
'
}
#
# _df_dir : get an IRIX style df line for device where a directory resides
#
# - returns fs type in field two (ala IRIX)
# - joins line together if split by fancy df formatting
# - strips header etc
#
_df_dir()
{
if [ $# -ne 1 ]
then
echo "Usage: _df_dir device" 1>&2
exit 1
fi
$DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
NR == 2 && NF==1 {
v=$1
getline
print v, $0;
exit 0
}
NR == 2 {
print;
exit 0
}
{}
'
# otherwise, nada
}
# return percentage used disk space for mounted device
_used()
{
if [ $# -ne 1 ]
then
echo "Usage: _used device" 1>&2
exit 1
fi
_df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
}
# return the FS type of a mounted device
#
_fs_type()
{
if [ $# -ne 1 ]
then
echo "Usage: _fs_type device" 1>&2
exit 1
fi
#
# The Linux kernel shows NFSv4 filesystems in df output as
# filesystem type nfs4, although we mounted it as nfs earlier.
# 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/' -e 's/fuse.glusterfs/glusterfs/'
}
# return the FS mount options of a mounted device
#
# should write a version which just parses the output of mount for IRIX
# compatibility, but since this isn't used at all, at the moment I'll leave
# this for now
#
_fs_options()
{
if [ $# -ne 1 ]
then
echo "Usage: _fs_options device" 1>&2
exit 1
fi
$AWK_PROG -v dev=$1 '
match($1,dev) { print $4 }
' </proc/mounts
}
# returns device number if a file is a block device
#
_is_block_dev()
{
if [ $# -ne 1 ]
then
echo "Usage: _is_block_dev dev" 1>&2
exit 1
fi
local dev=$1
if [ -L "$dev" ]; then
dev=`readlink -f "$dev"`
fi
if [ -b "$dev" ]; then
$here/src/lstat64 "$dev" | $AWK_PROG '/Device type:/ { print $9 }'
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
local dev=$1
if [ -L "$dev" ]; then
dev=`readlink -f "$dev"`
fi
if [ -c "$dev" ]; then
$here/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
# first prints the message passed in the first argument, and then "done"
# or "fail" depending on the return status of the command passed in the
# second argument. If the command fails and the variable _do_die_on_error
# is set to "always" or the two argument form is used and _do_die_on_error
# is set to "message_only" _do will print an error message to
# $seqres.out and exit.
_do()
{
if [ $# -eq 1 ]; then
local cmd=$1
elif [ $# -eq 2 ]; then
local note=$1
local cmd=$2
echo -n "$note... "
else
echo "Usage: _do [note] cmd" 1>&2
status=1; exit
fi
(eval "echo '---' \"$cmd\"") >>$seqres.full
(eval "$cmd") >$tmp._out 2>&1
local ret=$?
cat $tmp._out >>$seqres.full
rm -f $tmp._out
if [ $# -eq 2 ]; then
if [ $ret -eq 0 ]; then
echo "done"
else
echo "fail"
fi
fi
if [ $ret -ne 0 ] \
&& [ "$_do_die_on_error" = "always" \
-o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
then
[ $# -ne 2 ] && echo
eval "echo \"$cmd\" failed \(returned $ret\): see $seqres.full"
status=1; exit
fi
return $ret
}
# bail out, setting up .notrun file. Need to kill the filesystem check files
# here, otherwise they are set incorrectly for the next test.
#
_notrun()
{
echo "$*" > $seqres.notrun
echo "$seq not run: $*"
rm -f ${RESULT_DIR}/require_test*
rm -f ${RESULT_DIR}/require_scratch*
status=0
exit
}
# just plain bail out
#
_fail()
{
echo "$*" | tee -a $seqres.full
echo "(see $seqres.full for details)"
status=1
exit 1
}
# tests whether $FSTYP is one of the supported filesystems for a test
#
_supported_fs()
{
local f
for f
do
if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
then
return
fi
done
_notrun "not suitable for this filesystem type: $FSTYP"
}
# 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
# 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 [ "$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
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
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
;;
9p|virtiofs)
if [ -z "$SCRATCH_DEV" ]; 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
_notrun "this test requires a valid \$SCRATCH_DEV"
fi
if [ ! -d "$SCRATCH_MNT" ]; then
_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
_notrun "this test requires a valid \$SCRATCH_DEV"
fi
if [ ! -d "$SCRATCH_MNT" ]; then
_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
_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
_notrun "this test requires a valid \$SCRATCH_DEV"
fi
if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
then
_notrun "this test requires a valid \$SCRATCH_DEV"
fi
if [ ! -d "$SCRATCH_MNT" ]
then
_notrun "this test requires a valid \$SCRATCH_MNT"
fi
;;
esac
_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, unmount it
if ! _scratch_unmount
then
echo "failed to unmount $SCRATCH_DEV"
exit 1
fi
fi
rm -f ${RESULT_DIR}/require_scratch
}
# we need the scratch device and it should be checked post test.
_require_scratch()
{
_require_scratch_nocheck
touch ${RESULT_DIR}/require_scratch
}
# require a scratch dev of a minimum size (in kb)
_require_scratch_size()
{
[ $# -eq 1 ] || _fail "_require_scratch_size: expected size param"
_require_scratch
local devsize=`_get_device_size $SCRATCH_DEV`
[ $devsize -lt $1 ] && _notrun "scratch dev too small"
}
# require a scratch dev of a minimum size (in kb) and should not be checked
# post test
_require_scratch_size_nocheck()
{
[ $# -eq 1 ] || _fail "_require_scratch_size: expected size param"
_require_scratch_nocheck
local devsize=`_get_device_size $SCRATCH_DEV`
[ $devsize -lt $1 ] && _notrun "scratch dev too small"
}
# require scratch fs which supports >16T of filesystem size.
_require_scratch_16T_support()
{
case $FSTYP in
ext2|ext3|f2fs)
_notrun "$FSTYP doesn't support >16T filesystem"
;;
ext4)
_scratch_mkfs >> $seqres.full 2>&1
_scratch_mount
local blocksize=$(_get_block_size $SCRATCH_MNT)
if [ $blocksize -lt 4096 ]; then
_notrun "This test requires >16T fs support"
fi
_scratch_unmount
;;
*)
;;
esac
}
# this test needs a test partition - check we're ok & mount it
#
_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
;;
9p|virtiofs)
if [ -z "$TEST_DEV" ]; 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
_notrun "this test requires a valid \$TEST_DEV"
fi
if [ ! -d "$TEST_DIR" ]; then
_notrun "this test requires a valid \$TEST_DIR"
fi
;;
cifs)
echo $TEST_DEV | grep -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
;;
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"
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
_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
_notrun "this test requires a valid \$TEST_DEV"
fi
if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
then
_notrun "this test requires a valid \$TEST_DEV"
fi
if [ ! -d "$TEST_DIR" ]
then
_notrun "this test requires a valid \$TEST_DIR"
fi
;;
esac
_check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR
local err=$?
[ $err -le 1 ] || exit 1
if [ $err -ne 0 ]
then
if ! _test_mount
then
echo "!!! failed to mount $TEST_DEV on $TEST_DIR"
exit 1
fi
fi
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()
{
[ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
_notrun "This test requires a valid \$SCRATCH_LOGDEV"
[ "$USE_EXTERNAL" != yes ] && \
_notrun "This test requires USE_EXTERNAL to be enabled"
# ensure its not mounted
$UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
}
# this test requires loopback device support
#
_require_loop()
{
modprobe loop >/dev/null 2>&1
if grep loop /proc/devices >/dev/null 2>&1
then
:
else
_notrun "This test requires loopback device support"
fi
}
# this test requires ext2 filesystem support
#
_require_ext2()
{
modprobe ext2 >/dev/null 2>&1
if grep ext2 /proc/filesystems >/dev/null 2>&1
then
:
else
_notrun "This test requires ext2 filesystem support"
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()
{
[ "$LARGE_SCRATCH_DEV" = yes ] && \
_notrun "Large filesystem testing in progress, skipped this test"
}
# this test requires that a realtime subvolume is in use, and
# that the kernel supports realtime as well.
#
_require_realtime()
{
[ "$USE_EXTERNAL" = yes ] || \
_notrun "External volumes not in use, skipped this test"
[ "$SCRATCH_RTDEV" = "" ] && \
_notrun "Realtime device required, skipped this test"
}
# This test requires that a realtime subvolume is not in use
#
_require_no_realtime()
{
[ "$USE_EXTERNAL" = "yes" ] && [ -n "$SCRATCH_RTDEV" ] && \
_notrun "Test not compatible with realtime subvolumes, skipped this test"
}
# this test requires that a specified command (executable) exists
# $1 - command, $2 - name for error message
#
# Note: the command string might have parameters, so strip them before checking
# whether it is executable.
_require_command()
{
if [ $# -eq 2 ]; then
local name="$2"
elif [ $# -eq 1 ]; then
local name="$1"
else
_fail "usage: _require_command <command> [<name>]"
fi
local command=`echo "$1" | awk '{ print $1 }'`
if [ ! -x "$command" ]; then
_notrun "$name utility required, skipped this test"
fi
}
# this test requires the device to be valid block device
# $1 - device
_require_block_device()
{
if [ -z "$1" ]; then
echo "Usage: _require_block_device <dev>" 1>&2
exit 1
fi
if [ "`_is_block_dev "$1"`" == "" ]; then
_notrun "require $1 to be valid block disk"
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.
_require_sane_bdev_flush()
{
echo $1 | grep -q "^/dev/ram[0-9]\+$"
if [ $? -eq 0 ]; then
_notrun "This test requires a sane block device flush"
fi
}
# this test requires a specific device mapper target
_require_dm_target()
{
local target=$1
# require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
# behaviour
_require_block_device $SCRATCH_DEV
_require_sane_bdev_flush $SCRATCH_DEV
_require_command "$DMSETUP_PROG" dmsetup
_normalize_mount_options | egrep -q "dax(=always| |$)"
if [ $? -eq 0 ]; then
case $target in
stripe|linear|log-writes)
;;
*)
_notrun "Cannot run tests with DAX on $target devices."
;;
esac
fi
modprobe dm-$target >/dev/null 2>&1
$DMSETUP_PROG targets 2>&1 | grep -q ^$target
if [ $? -ne 0 ]; then
_notrun "This test requires dm $target support"
fi
}
# this test requires the ext4 kernel support crc feature on scratch device
#
_require_scratch_ext4_crc()
{
_scratch_mkfs_ext4 >/dev/null 2>&1
dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
_try_scratch_mount >/dev/null 2>&1 \
|| _notrun "Kernel doesn't support metadata_csum feature"
_scratch_unmount
}
# Check whether the specified feature whether it is supported by
# mkfs.ext4 and the kernel.
_require_scratch_ext4_feature()
{
if [ -z "$1" ]; then
echo "Usage: _require_scratch_ext4_feature feature"
exit 1
fi
$MKFS_EXT4_PROG -F $MKFS_OPTIONS -O "$1" \
$SCRATCH_DEV 512m >/dev/null 2>&1 \
|| _notrun "mkfs.ext4 doesn't support $1 feature"
_try_scratch_mount >/dev/null 2>&1 \
|| _notrun "Kernel doesn't support the ext4 feature(s): $1"
_scratch_unmount
}
# this test requires that external log/realtime devices are not in use
#
_require_nonexternal()
{
[ "$USE_EXTERNAL" = yes ] && \
_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()
{
if [ -z "$1" ]
then
AIO_TEST=$here/src/aio-dio-regress/aiodio_sparse2
[ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
else
AIO_TEST=$here/src/aio-dio-regress/$1
[ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
fi
_require_aio
_require_odirect
}
# this test requires that the kernel supports IO_URING
_require_io_uring()
{
$here/src/feature -R
case $? in
0)
;;
1)
_notrun "kernel does not support IO_URING"
;;
*)
_fail "unexpected error testing for IO_URING support"
;;
esac
}
# this test requires that a test program exists under src/
# $1 - command (require)
#
_require_test_program()
{
local prog=$here/src/$1
[ -x $prog ] || _notrun "$prog not built"
}
# run an aio-dio program
# $1 - command
_run_aiodio()
{
if [ -z "$1" ]
then
echo "usage: _run_aiodio command_name" 2>&1
status=1; exit 1
fi
_require_aiodio $1
local testtemp=$TEST_DIR/aio-testfile
rm -f $testtemp
$AIO_TEST $testtemp 2>&1
status=$?
rm -f $testtemp
return $status
}
_require_timestamp_range()
{
local device=${1:-$TEST_DEV}
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
# expect console warning from rw scratch mount if fs limit is near
if [ $tsmax -le $((1<<31)) ] && \
! _check_dmesg_for "filesystem being mounted at .* supports timestamps until"
then
_notrun "Kernel does not support timestamp limits"
fi
}
_filesystem_timestamp_range()
{
local device=${1:-$TEST_DEV}
local fstyp=${2:-$FSTYP}
u32max=$(((1<<32)-1))
s32min=-$((1<<31))
s32max=$(((1<<31)-1))
s64max=$(((1<<63)-1))
s64min=$((1<<63))
case $fstyp in
ext2)
echo "$s32min $s32max"
;;
ext3|ext4)
if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | cut -d: -f2) -gt 128 ]; then
printf "%d %d\n" $s32min 0x37fffffff
else
echo "$s32min $s32max"
fi
;;
jfs)
echo "0 $u32max"
;;
xfs)
echo "$s32min $s32max"
;;
btrfs)
echo "$s64min $s64max"
;;
overlay)
if [ ! -z $OVL_BASE_FSTYP -a $OVL_BASE_FSTYP != "overlay" ]; then
_filesystem_timestamp_range $OVL_BASE_TEST_DEV $OVL_BASE_FSTYP
else
echo "-1 -1"
fi
;;
*)
echo "-1 -1"
;;
esac
}
# indicate whether YP/NIS is active or not
#
_yp_active()
{
local dn
dn=$(domainname 2>/dev/null)
local ypcat=$(type -P ypcat)
local rpcinfo=$(type -P rpcinfo)
test -n "${dn}" -a "${dn}" != "(none)" -a "${dn}" != "localdomain" -a -n "${ypcat}" -a -n "${rpcinfo}" && \
"${rpcinfo}" -p localhost 2>/dev/null | grep -q ypbind
echo $?
}
# cat the password file
#
_cat_passwd()
{
[ $(_yp_active) -eq 0 ] && ypcat passwd
cat /etc/passwd
}
# cat the group file
#
_cat_group()
{
[ $(_yp_active) -eq 0 ] && ypcat group
cat /etc/group
}
# 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 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 group not defined."
}
_filter_user_do()
{
perl -ne "
s,.*Permission\sdenied.*,Permission denied,;
s,.*no\saccess\sto\stty.*,,;
s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
s,^\s*$,,;
print;"
}
_user_do()
{
echo $1 | su -s /bin/bash $qa_user 2>&1 | _filter_user_do
}
_require_xfs_io_command()
{
if [ -z "$1" ]
then
echo "Usage: _require_xfs_io_command command [switch]" 1>&2
exit 1
fi
local command=$1
shift
local param="$*"
local param_checked=""
local opts=""
local attr_info=""
local testfile=$TEST_DIR/$$.xfs_io
local testio
case $command in
"lsattr")
# Test xfs_io lsattr support and filesystem FS_IOC_FSSETXATTR
# support.
testio=`$XFS_IO_PROG -F -f -c "lsattr $param" $testfile 2>&1`
param_checked="$param"
;;
"chattr")
local testdir=$TEST_DIR/$$.attr_dir
mkdir $TEST_DIR/$$.attr_dir
if [ -z "$param" ]; then
param=s
fi
# Test xfs_io chattr support AND
# filesystem FS_IOC_FSSETXATTR support
# 'tPnE' flags are only valid for a directory so check them on a directory.
if echo "$param" | egrep -q 't|P|n|E'; then
testio=`$XFS_IO_PROG -F -c "chattr +$param" $testdir 2>&1`
attr_info=`$XFS_IO_PROG -F -r -c "lsattr" $testdir | awk '{print $1}'`
$XFS_IO_PROG -F -r -c "chattr -$param" $testdir 2>&1
else
testio=`$XFS_IO_PROG -F -f -c "chattr +$param" $testfile 2>&1`
attr_info=`$XFS_IO_PROG -F -r -c "lsattr" $testfile | awk '{print $1}'`
$XFS_IO_PROG -F -r -c "chattr -$param" $testfile 2>&1
fi
param_checked="+$param"
rm -rf $testdir 2>&1 > /dev/null
;;
"chproj")
testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1`
;;
"copy_range")
local testcopy=$TEST_DIR/$$.copy.xfs_io
local copy_opts=$testfile
if [ "$param" == "-f" ]; then
# source file is the open destination file
testcopy=$testfile
copy_opts="0 -d 4k -l 4k"
fi
$XFS_IO_PROG -F -f -c "pwrite 0 4k" $testfile > /dev/null 2>&1
testio=`$XFS_IO_PROG -F -f -c "copy_range $param $copy_opts" $testcopy 2>&1`
rm -f $testcopy > /dev/null 2>&1
param_checked="$param"
;;
"falloc" )
testio=`$XFS_IO_PROG -F -f -c "falloc $param 0 1m" $testfile 2>&1`
param_checked="$param"
;;
"fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" | "funshare")
local blocksize=$(_get_block_size $TEST_DIR)
testio=`$XFS_IO_PROG -F -f -c "pwrite 0 $((5 * $blocksize))" \
-c "fsync" -c "$command $blocksize $((2 * $blocksize))" \
$testfile 2>&1`
;;
"fiemap")
# If 'ranged' is passed as argument then we check to see if fiemap supports
# ranged query params
if echo "$param" | grep -q "ranged"; then
param=$(echo "$param" | sed "s/ranged//")
$XFS_IO_PROG -c "help fiemap" | grep -q "\[offset \[len\]\]"
[ $? -eq 0 ] || _notrun "xfs_io $command ranged support is missing"
fi
testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
-c "fiemap -v $param" $testfile 2>&1`
param_checked="$param"
;;
"flink")
local testlink=$TEST_DIR/$$.link.xfs_io
testio=`$XFS_IO_PROG -F -f -c "flink $testlink" $testfile 2>&1`
rm -f $testlink > /dev/null 2>&1
;;
"-T")
# Check O_TMPFILE support in xfs_io, kernel and fs
testio=`$XFS_IO_PROG -T -c quit $TEST_DIR 2>&1`
echo $testio | egrep -q "invalid option|Is a directory" && \
_notrun "xfs_io $command support is missing"
echo $testio | grep -q "Operation not supported" && \
_notrun "O_TMPFILE is not supported"
;;
"fsmap")
testio=`$XFS_IO_PROG -f -c "fsmap" $testfile 2>&1`
echo $testio | grep -q "Inappropriate ioctl" && \
_notrun "xfs_io $command support is missing"
;;
"label")
testio=`$XFS_IO_PROG -c "label" $TEST_DIR 2>&1`
;;
"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 | grep -q "invalid option" && \
_notrun "xfs_io $command support is missing"
;;
"pwrite")
# -N (RWF_NOWAIT) only works with direct vectored I/O writes
local pwrite_opts=" "
if [ "$param" == "-N" ]; then
opts+=" -d"
pwrite_opts+="-V 1 -b 4k"
fi
testio=`$XFS_IO_PROG -f $opts -c \
"pwrite $pwrite_opts $param 0 4k" $testfile 2>&1`
param_checked="$pwrite_opts $param"
;;
"scrub"|"repair")
testio=`$XFS_IO_PROG -x -c "$command probe" $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`
;;
"syncfs")
touch $testfile
testio=`$XFS_IO_PROG -c "syncfs" $testfile 2>&1`
;;
*)
testio=`$XFS_IO_PROG -c "help $command" 2>&1`
esac
rm -f $testfile 2>&1 > /dev/null
echo $testio | grep -q "not found" && \
_notrun "xfs_io $command $param_checked support is missing"
echo $testio | grep -q "Operation not supported\|Inappropriate ioctl" && \
_notrun "xfs_io $command $param_checked failed (old kernel/wrong fs?)"
echo $testio | grep -q "Invalid" && \
_notrun "xfs_io $command $param_checked failed (old kernel/wrong fs/bad args?)"
echo $testio | grep -q "foreign file active" && \
_notrun "xfs_io $command $param_checked not supported on $FSTYP"
echo $testio | grep -q "Function not implemented" && \
_notrun "xfs_io $command $param_checked support is missing (missing syscall?)"
echo $testio | grep -q "unknown flag" && \
_notrun "xfs_io $command $param_checked support is missing (unknown flag)"
[ -n "$param" ] || return
if [ -z "$param_checked" ]; then
$XFS_IO_PROG -c "help $command" | grep -E -q "^ $param ([a-zA-Z_]+ )?--" || \
_notrun "xfs_io $command doesn't support $param"
else
# xfs_io could result in "command %c not supported" if it was
# built on kernels not supporting pwritev2() calls
echo $testio | grep -q "\(invalid option\|not supported\)" && \
_notrun "xfs_io $command doesn't support $param"
fi
# On XFS, ioctl(FSSETXATTR)(called by xfs_io -c "chattr") maskes off unsupported
# or invalid flags silently so need to check these flags by extra ioctl(FSGETXATTR)
# (called by xfs_io -c "lsattr").
# The following URL explains why we don't change the behavior of XFS.
# https://www.spinics.net/lists/linux-xfs/msg44725.html
if [ -n "$attr_info" -a "$FSTYP" = "xfs" ]; then
local num=${#param}
for i in $(seq 0 $((num-1))); do
echo $attr_info | grep -q "${param:$i:1}" || \
_notrun "xfs_io $command +${param:$i:1} support is missing (unknown flag in kernel)"
done
fi
}
# check that kernel and filesystem support direct I/O
_require_odirect()
{
if [ $FSTYP = "ext4" ] || [ $FSTYP = "f2fs" ] ; then
if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
_notrun "$FSTYP encryption doesn't support O_DIRECT"
fi
fi
if [ $FSTYP = "ext4" ] ; then
if echo "$MOUNT_OPTIONS" | grep -q "data=journal"; then
_notrun "ext4 data journaling doesn't support O_DIRECT"
fi
fi
local 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
}
_format_swapfile() {
local fname="$1"
local sz="$2"
rm -f "$fname"
touch "$fname"
chmod 0600 "$fname"
# Swap files must be nocow on Btrfs.
$CHATTR_PROG +C "$fname" > /dev/null 2>&1
_pwrite_byte 0x61 0 "$sz" "$fname" >> $seqres.full
$MKSWAP_PROG "$fname" >> $seqres.full
}
# Check that the filesystem supports swapfiles
_require_scratch_swapfile()
{
_require_scratch
_require_command "$MKSWAP_PROG" "mkswap"
_scratch_mkfs >/dev/null 2>&1
# With mounting SELinux context(e.g. system_u:object_r:root_t:s0),
# standard mkswap tried to reset the type of default context to
# swapfile_t if it's not swapfile_t, and then it failed and returned
# ENOTSUP expectedly as we don't want to create any SELinux attr on
# purpose. standard mkswap ignored this relabel error by commit
# d97dc0e of util-linux, but it still reported the error before
# commit d97dc0e. We mount swapfile context directly to skip the
# reset step.
[ -n "$SELINUX_MOUNT_OPTIONS" ] && export \
SELINUX_MOUNT_OPTIONS="-o context=system_u:object_r:swapfile_t:s0"
_scratch_mount
# Minimum size for mkswap is 10 pages
_format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
# ext* and xfs have supported all variants of swap files since their
# introduction, so swapon should not fail.
case "$FSTYP" in
ext2|ext3|ext4|xfs)
if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
_scratch_unmount
_fail "swapon failed for $FSTYP"
fi
;;
*)
if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
_scratch_unmount
_notrun "swapfiles are not supported"
fi
;;
esac
swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
_scratch_unmount
}
# Check that a fs has enough free space (in 1024b blocks)
#
_require_fs_space()
{
local mnt=$1
local blocks=$2 # in units of 1024
local gb=$(( blocks / 1024 / 1024 ))
local 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"
}
#
# Check if the filesystem supports sparse files.
#
# Unfortunately there is no better way to do this than a manual black list.
#
_require_sparse_files()
{
case $FSTYP in
hfsplus|exfat)
_notrun "Sparse files not supported by this filesystem type: $FSTYP"
;;
*)
;;
esac
}
_require_debugfs()
{
#boot_params always present in debugfs
[ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
}
_require_fail_make_request()
{
[ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
|| _notrun "$DEBUGFS_MNT/fail_make_request \
not found. Seems that CONFIG_FAULT_INJECTION_DEBUG_FS 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
}
# The default behavior of SEEK_HOLE is to always return EOF.
# Filesystems that implement non-default behavior return the offset
# of holes with SEEK_HOLE. There is no way to query the filesystem
# of which behavior it is implementing.
# We use this whitelist FSTYP, to set expectation and avoid silent
# regression of filesystem seek hole behavior.
#
# Return 0 for true
_fstyp_has_non_default_seek_data_hole()
{
if [ -z $1 ]; then
local fstyp=$FSTYP
else
local fstyp=$1
fi
case "$fstyp" in
btrfs|ext4|xfs|cifs|f2fs|gfs2|ocfs2|tmpfs)
return 0
;;
nfs*)
# NFSv2 and NFSv3 only support default behavior of SEEK_HOLE,
# while NFSv4 supports non-default behavior
local nfsvers=`_df_device $TEST_DEV | $AWK_PROG '{ print $2 }'`
[ "$nfsvers" = "nfs4" ]
return $?
;;
overlay)
if [ ! -z $OVL_BASE_FSTYP -a $OVL_BASE_FSTYP != "overlay" ]; then
_fstyp_has_non_default_seek_data_hole $OVL_BASE_FSTYP
return $?
else
# Assume that base fs has default behavior
return 1
fi
;;
*)
# by default fstyp has default SEEK_HOLE behavior;
# if your fs has non-default behavior, add it to whitelist above!
return 1
;;
esac
}
# Run seek sanity test with predefined expectation for SEEK_DATA/HOLE behavior
_run_seek_sanity_test()
{
local testseekargs
if _fstyp_has_non_default_seek_data_hole; then
testseekargs+="-f"
fi
$here/src/seek_sanity_test $testseekargs $*
}
# Check if the file system supports seek_data/hole
_require_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()
{
_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
_try_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"
_try_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 if the given device is mounted, if so, return mount point
_is_dev_mounted()
{
local dev=$1
local fstype=${2:-$FSTYP}
if [ $# -lt 1 ]; then
echo "Usage: _is_dev_mounted <device> [fstype]" 1>&2
exit 1
fi
findmnt -rncv -S $dev -t $fstype -o TARGET | head -1
}
# check if the given dir is a mount point, if so, return mount point
_is_dir_mountpoint()
{
local dir=$1
local fstype=${2:-$FSTYP}
if [ $# -lt 1 ]; then
echo "Uasge: _is_dir_mountpoint <dir> [fstype]" 1>&2
exit 1
fi
findmnt -rncv -t $fstype -o TARGET $dir | head -1
}
# remount a FS to a new mode (ro or rw)
#
_remount()
{
if [ $# -ne 2 ]
then
echo "Usage: _remount device ro/rw" 1>&2
exit 1
fi
local device=$1
local mode=$2
if ! mount -o remount,$mode $device
then
echo "_remount: failed to remount filesystem on $device as $mode"
exit 1
fi
}
# Run the appropriate repair/check on a filesystem
#
# if the filesystem is mounted, it's either remounted ro before being
# checked or it's unmounted and then remounted
#
# If set, we remount ro instead of unmounting for fsck
USE_REMOUNT=0
_umount_or_remount_ro()
{
if [ $# -ne 1 ]
then
echo "Usage: _umount_or_remount_ro <device>" 1>&2
exit 1
fi
local device=$1
local mountpoint=`_is_dev_mounted $device`
if [ $USE_REMOUNT -eq 0 ]; then
$UMOUNT_PROG $device
else
_remount $device ro
fi
echo "$mountpoint"
}
_mount_or_remount_rw()
{
if [ $# -ne 3 ]; then
echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
exit 1
fi
local mount_opts=$1
local device=$2
local mountpoint=$3
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
}
# Check a generic filesystem in no-op mode; this assumes that the
# underlying fsck program accepts "-n" for a no-op (check-only) run,
# and that it will still return an errno for corruption in this mode.
#
# Filesystems which don't support this will need to define their
# own check routine.
#
_check_generic_filesystem()
{
local device=$1
# If type is set, we're mounted
local type=`_fs_type $device`
local ok=1
if [ "$type" = "$FSTYP" ]
then
# mounted ...
local mountpoint=`_umount_or_remount_ro $device`
fi
fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
if [ $? -ne 0 ]
then
_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.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
}
# Filter the knowen errors the UDF Verifier reports.
_udf_test_known_error_filter()
{
egrep -v "PVD 60 Error: Interchange Level: 1, Maximum Interchange Level: 0|FSD 28 Error: Interchange Level: 1, Maximum Interchange Level: 1,|PVD 72 Warning: Volume Set Identifier: \"\*IRIX UDF\",|Warning: [0-9]+ unused blocks NOT marked as unallocated."
}
_check_udf_filesystem()
{
[ "$DISABLE_UDF_TEST" == "1" ] && return
if [ $# -ne 1 -a $# -ne 2 ]
then
echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
exit 1
fi
if [ ! -x $here/src/udf_test ]
then
echo "udf_test not installed, please download and build the Philips"
echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
echo "Then copy the udf_test binary to $here/src/."
echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
echo "to 1."
return
fi
local device=$1
local opt_arg=""
if [ $# -eq 2 ]; then
opt_arg="-lastvalidblock $(( $2 - 1 ))"
fi
rm -f $seqres.checkfs
sleep 1 # Due to a problem with time stamps in udf_test
$here/src/udf_test $opt_arg $device | tee $seqres.checkfs | egrep "Error|Warning" | \
_udf_test_known_error_filter | \
egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
return 0
}
_check_test_fs()
{
case $FSTYP in
xfs)
_check_xfs_test_fs
;;
nfs)
# no way to check consistency for nfs
;;
cifs)
# no way to check consistency for cifs
;;
9p)
# no way to check consistency for 9p
;;
virtiofs)
# no way to check consistency for virtiofs
;;
ceph)
# no way to check consistency for CephFS
;;
glusterfs)
# no way to check consistency for GlusterFS
;;
overlay)
_check_overlay_test_fs
;;
pvfs2)
;;
udf)
# do nothing for now
;;
btrfs)
_check_btrfs_filesystem $TEST_DEV
;;
tmpfs)
# no way to check consistency for tmpfs
;;
ubifs)
# there is no fsck program for ubifs yet
;;
*)
_check_generic_filesystem $TEST_DEV
;;
esac
}
_check_scratch_fs()
{
local device=$SCRATCH_DEV
[ $# -eq 1 ] && device=$1
case $FSTYP in
xfs)
local scratch_log="none"
local scratch_rt="none"
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
scratch_log="$SCRATCH_LOGDEV"
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
scratch_rt="$SCRATCH_RTDEV"
_check_xfs_filesystem $device $scratch_log $scratch_rt
;;
udf)
_check_udf_filesystem $device $udf_fsize
;;
nfs*)
# Don't know how to check an NFS filesystem, yet.
;;
cifs)
# Don't know how to check a CIFS filesystem, yet.
;;
9p)
# no way to check consistency for 9p
;;
virtiofs)
# no way to check consistency for virtiofs
;;
ceph)
# no way to check consistency for CephFS
;;
glusterfs)
# no way to check consistency for GlusterFS
;;
overlay)
_check_overlay_scratch_fs
;;
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
;;
esac
}
_full_fstyp_details()
{
[ -z "$FSTYP" ] && FSTYP=xfs
if [ $FSTYP = xfs ]; then
if [ -d /proc/fs/xfs ]; then
if grep -q 'debug 0' /proc/fs/xfs/stat; then
FSTYP="$FSTYP (non-debug)"
elif grep -q 'debug 1' /proc/fs/xfs/stat; then
FSTYP="$FSTYP (debug)"
fi
else
if uname -a | grep -qi 'debug'; then
FSTYP="$FSTYP (debug)"
else
FSTYP="$FSTYP (non-debug)"
fi
fi
fi
echo $FSTYP
}
_full_platform_details()
{
local os=`uname -s`
local host=`hostname -s`
local kernel=`uname -rv`
local platform=`uname -m`
echo "$os/$platform $host $kernel"
}
_get_os_name()
{
if [ "`uname`" == "Linux" ]; then
echo 'linux'
else
echo Unknown operating system: `uname`
exit
fi
}
_link_out_file_named()
{
local features=$2
local suffix=$(FEATURES="$features" 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
ln -fs $(basename $1).$suffix $1
}
_link_out_file()
{
local features
if [ $# -eq 0 ]; then
features="$(_get_os_name),$FSTYP"
if [ -n "$MOUNT_OPTIONS" ]; then
features=$features,${MOUNT_OPTIONS##"-o "}
fi
else
features=$1
fi
_link_out_file_named $seqfull.out "$features"
}
_die()
{
echo $@
exit 1
}
# convert urandom incompressible data to compressible text data
_ddt()
{
od /dev/urandom | dd iflag=fullblock ${*}
}
#takes files, randomdata
_nfiles()
{
local f=0
while [ $f -lt $1 ]
do
local file=f$f
echo > $file
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
fi
let f=$f+1
done
}
# takes dirname, depth, randomdata
_descend()
{
local dirname=$1 depth=$2 randomdata=$3
mkdir $dirname || die "mkdir $dirname failed"
cd $dirname
_nfiles $files $randomdata # files for this dir and data type
[ $depth -eq 0 ] && return
local deep=$(( depth - 1 )) # go 1 down
[ $verbose = true ] && echo "descending, depth from leaves = $deep"
local d=0
while [ $d -lt $dirs ]
do
_descend d$d $deep &
let d=$d+1
wait
done
}
# Populate a filesystem with inodes for performance experiments
#
# usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
#
_populate_fs()
{
local here=`pwd`
local dirs=5 # ndirs in each subdir till leaves
local size=0 # sizeof files in K
local files=100 # num files in _each_ subdir
local depth=2 # depth of tree from root to leaves
local verbose=false
local root=root # path of initial root of directory tree
local randomdata=false # -x data type urandom, zero or compressible
local c
OPTIND=1
while getopts "d:f:n:r:s:v:x:c" c
do
case $c in
d) depth=$OPTARG;;
n) dirs=$OPTARG;;
f) files=$OPTARG;;
s) size=$OPTARG;;
v) verbose=true;;
r) root=$OPTARG;;
x) randomdata=true;;
c) randomdata=comp;;
esac
done
_descend $root $depth $randomdata
wait
cd $here
[ $verbose = true ] && echo done
}
# query whether the given file has the given inode flag set
#
_test_inode_flag()
{
local flag=$1
local file=$2
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()
{
local file=$1
local blocks=""
blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
awk '/^xattr.extsize =/ { print $3 }'`
[ -z "$blocks" ] && blocks="0"
echo $blocks
}
# scratch_dev_pool should contain the disks pool for the btrfs raid
_require_scratch_dev_pool()
{
local i
local ndevs
if [ -z "$SCRATCH_DEV_POOL" ]; then
_notrun "this test requires a valid \$SCRATCH_DEV_POOL"
fi
if [ -z "$1" ]; then
ndevs=2
else
ndevs=$1
fi
# btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
# so fail it
case $FSTYP in
btrfs)
if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
_notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
fi
;;
*)
_notrun "dev_pool is not supported by fstype \"$FSTYP\""
;;
esac
for i in $SCRATCH_DEV_POOL; do
if [ "`_is_block_dev "$i"`" = "" ]; then
_notrun "this test requires valid block disk $i"
fi
if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
_notrun "$i is part of TEST_DEV, this test requires unique disks"
fi
if _mount | grep -q $i; then
if ! $UMOUNT_PROG $i; then
echo "failed to unmount $i - aborting"
exit 1
fi
fi
# to help better debug when something fails, we remove
# traces of previous btrfs FS on the dev.
dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
done
}
# ensure devices in SCRATCH_DEV_POOL are of the same size
# must be called after _require_scratch_dev_pool
_require_scratch_dev_pool_equal_size()
{
local size
local newsize
local dev
# SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
size=`_get_device_size $SCRATCH_DEV`
for dev in $SCRATCH_DEV_POOL; do
newsize=`_get_device_size $dev`
if [ $size -ne $newsize ]; then
_notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
fi
done
}
# Check that fio is present, and it is able to execute given jobfile
_require_fio()
{
local job=$1
_require_command "$FIO_PROG" fio
if [ -z "$1" ]; then
return 1;
fi
$FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
[ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
}
# Does freeze work on this fs?
_require_freeze()
{
xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
local result=$?
xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
[ $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()
{
[ -x $here/src/godown ] || _notrun "src/godown executable not found"
_scratch_mkfs > /dev/null 2>&1 || _notrun "_scratch_mkfs failed on $SCRATCH_DEV"
_scratch_mount
if [ $FSTYP = "overlay" ]; then
if [ -z $OVL_BASE_SCRATCH_DEV ]; then
# In lagacy overlay usage, it may specify directory as
# SCRATCH_DEV, in this case OVL_BASE_SCRATCH_DEV
# will be null, so check OVL_BASE_SCRATCH_DEV before
# running shutdown to avoid shutting down base fs accidently.
_notrun "This test requires a valid $OVL_BASE_SCRATCH_DEV as ovl base fs"
else
$here/src/godown -f $OVL_BASE_SCRATCH_MNT 2>&1 \
|| _notrun "Underlying filesystem does not support shutdown"
fi
else
$here/src/godown -f $SCRATCH_MNT 2>&1 \
|| _notrun "$FSTYP does not support shutdown"
fi
_scratch_unmount
}
_check_s_dax()
{
local target=$1
local exp_s_dax=$2
local attributes=$($XFS_IO_PROG -c 'statx -r' $target | awk '/stat.attributes / { print $3 }')
# The original attribute bit value, STATX_ATTR_DAX (0x2000), conflicted
# with STATX_ATTR_MOUNT_ROOT. Therefore, STATX_ATTR_DAX was changed to
# 0x00200000.
#
# Because DAX tests do not run on root mounts, STATX_ATTR_MOUNT_ROOT
# should always be 0. Check for the old flag and fail the test if that
# occurs.
if [ $(( attributes & 0x2000 )) -ne 0 ]; then
echo "$target has an unexpected STATX_ATTR_MOUNT_ROOT flag set"
echo "which used to be STATX_ATTR_DAX"
echo " This test should not be running on the root inode..."
echo " Does the kernel have the following patch?"
echo " 72d1249e2ffd uapi: fix statx attribute value overlap for DAX & MOUNT_ROOT"
fi
if [ $exp_s_dax -eq 0 ]; then
(( attributes & 0x00200000 )) && echo "$target has unexpected S_DAX flag"
else
(( attributes & 0x00200000 )) || echo "$target doesn't have expected S_DAX flag"
fi
}
_check_xflag()
{
local target=$1
local exp_xflag=$2
if [ $exp_xflag -eq 0 ]; then
_test_inode_flag dax $target && echo "$target has unexpected FS_XFLAG_DAX flag"
else
_test_inode_flag dax $target || echo "$target doesn't have expected FS_XFLAG_DAX flag"
fi
}
# Check if dax mount options are supported
#
# $1 can be either 'dax=always' or 'dax'
#
# dax=always
# Check for the new dax options (dax=inode, dax=always or dax=never)
# by passing "dax=always".
# dax
# Check for the old dax or new dax=always by passing "dax".
#
# This only accepts 'dax=always' because dax=always, dax=inode and
# dax=never are always supported together. So if the other options are
# required checking for 'dax=always' indicates support for the other 2.
#
# Return 0 if filesystem/device supports the specified dax option.
# Return 1 if mount fails with the specified dax option.
# Return 2 if /proc/mounts shows wrong dax option.
_check_scratch_dax_mountopt()
{
local option=$1
_require_scratch
_scratch_mkfs > /dev/null 2>&1
_try_scratch_mount "-o $option" > /dev/null 2>&1 || return 1
if _fs_options $SCRATCH_DEV | egrep -q "dax(=always|,|$)"; then
_scratch_unmount
return 0
else
_scratch_unmount
return 2
fi
}
# Throw notrun if _check_scratch_dax_mountopt() returns a non-zero value.
_require_scratch_dax_mountopt()
{
local mountopt=$1
_check_scratch_dax_mountopt "$mountopt"
local res=$?
[ $res -eq 1 ] && _notrun "mount $SCRATCH_DEV with $mountopt failed"
[ $res -eq 2 ] && _notrun "$SCRATCH_DEV $FSTYP does not support -o $mountopt"
}
_require_dax_iflag()
{
_require_xfs_io_command "chattr" "x"
}
# Does norecovery support by this fs?
_require_norecovery()
{
_try_scratch_mount -o ro,norecovery || \
_notrun "$FSTYP does not support norecovery"
_scratch_unmount
}
# Does this filesystem support metadata journaling?
# We exclude ones here that don't; otherwise we assume that it does, so the
# test will run, fail, and motivate someone to update this test for a new
# filesystem.
#
# It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
# odd, but possible) so check $TEST_DEV by default, but we can optionall pass
# any dev we want.
_has_metadata_journaling()
{
if [ -z $1 ]; then
local dev=$TEST_DEV
else
local dev=$1
fi
case "$FSTYP" in
ext2|vfat|msdos|udf|exfat)
echo "$FSTYP does not support metadata journaling"
return 1
;;
ext4)
# ext4 could be mkfs'd without a journal...
_require_dumpe2fs
$DUMPE2FS_PROG -h $dev 2>&1 | grep -q has_journal || {
echo "$FSTYP on $dev not configured with metadata journaling"
return 1
}
# ext4 might not load a journal
if _normalize_mount_options | grep -qw "noload"; then
echo "mount option \"noload\" not allowed in this test"
return 1
fi
;;
overlay)
# metadata journaling check is based on base filesystem configurations
# and because -overlay option saves those configurations to OVL_BASE_*,
# adding restore/override the configurations before/after the check.
if [ ! -z $OVL_BASE_FSTYP -a $OVL_BASE_FSTYP != "overlay" ]; then
local ret
_overlay_config_restore
_has_metadata_journaling
ret=$?
_overlay_config_override
return $ret
else
echo "No metadata journaling support for legacy overlay setup"
return 1
fi
;;
*)
# by default we pass; if you need to, add your fs above!
;;
esac
return 0
}
_require_metadata_journaling()
{
local msg=$(_has_metadata_journaling $@)
if [ -n "$msg" ]; then
_notrun "$msg"
fi
}
_count_extents()
{
$XFS_IO_PROG -r -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
}
# Similar to _count_extents() but if any extent is shared multiples times in
# the file (reflinked to different file offsets), it is accounted as 1 extent
# instead of N extents.
_count_exclusive_extents()
{
$XFS_IO_PROG -r -c "fiemap" $1 | tail -n +2 | grep -v hole | \
cut -d ' ' -f 3 | sort | uniq | wc -l
}
_count_holes()
{
$XFS_IO_PROG -r -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()
{
local lun=$1
local disk=$2
echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
stat $disk > /dev/null 2>&1
while [ $? -eq 0 ]; do
sleep 1
stat $disk > /dev/null 2>&1
done
}
# arg 1 is dev to add and is output of the below eg.
# ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
_devmgt_add()
{
local h
local tdl
# arg 1 will be in h:t:d:l format now in the h and "t d l" format
h=`echo ${1} | cut -d":" -f 1`
tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
# ensure the device comes online
local dev_back_oneline=0
local i
for i in `seq 1 10`; do
if [ -d /sys/class/scsi_device/${1}/device/block ]; then
local dev=`ls /sys/class/scsi_device/${1}/device/block`
local j
for j in `seq 1 10`;
do
stat /dev/$dev > /dev/null 2>&1
if [ $? -eq 0 ]; then
dev_back_oneline=1
break
fi
sleep 1
done
break
else
sleep 1
fi
done
if [ $dev_back_oneline -eq 0 ]; then
echo "/dev/$dev online failed" >> $seqres.full
else
echo "/dev/$dev is back online" >> $seqres.full
fi
}
_require_fstrim()
{
if [ -z "$FSTRIM_PROG" ]; then
_notrun "This test requires fstrim utility."
fi
}
_require_batched_discard()
{
if [ $# -ne 1 ]; then
echo "Usage: _require_batched_discard mnt_point" 1>&2
exit 1
fi
_require_fstrim
$FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
}
_require_dumpe2fs()
{
if [ -z "$DUMPE2FS_PROG" ]; then
_notrun "This test requires dumpe2fs utility."
fi
}
_require_ugid_map()
{
if [ ! -e /proc/self/uid_map ]; then
_notrun "This test requires procfs uid_map support."
fi
if [ ! -e /proc/self/gid_map ]; then
_notrun "This test requires procfs gid_map support."
fi
}
_require_fssum()
{
FSSUM_PROG=$here/src/fssum
[ -x $FSSUM_PROG ] || _notrun "fssum not built"
}
_require_cloner()
{
CLONER_PROG=$here/src/cloner
[ -x $CLONER_PROG ] || \
_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
# Both dax and dax=always are excluded if dax or dax=always is passed
_exclude_scratch_mount_option()
{
local mnt_opts=$(_normalize_mount_options)
while [ $# -gt 0 ]; do
local pattern=$1
echo "$pattern" | egrep -q "dax(=always|$)" && \
pattern="dax(=always| |$)"
if echo $mnt_opts | egrep -q "$pattern"; then
_notrun "mount option \"$1\" not allowed in this test"
fi
shift
done
}
_require_atime()
{
_exclude_scratch_mount_option "noatime"
case $FSTYP in
nfs|cifs)
_notrun "atime related mount options have no effect on $FSTYP"
;;
esac
}
_require_relatime()
{
_scratch_mkfs > /dev/null 2>&1
_try_scratch_mount -o relatime || \
_notrun "relatime not supported by the current kernel"
_scratch_unmount
}
_require_userns()
{
[ -x $here/src/nsexec ] || _notrun "src/nsexec executable not found"
$here/src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
}
_create_loop_device()
{
local file=$1 dev
dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
echo $dev
}
_destroy_loop_device()
{
local dev=$1
losetup -d $dev || _fail "Cannot destroy loop device $dev"
}
_scale_fsstress_args()
{
local args=""
while [ $# -gt 0 ]; do
case "$1" in
-n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
-p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
*) args="$args $1" ;;
esac
shift
done
printf '%s\n' "$args"
}
#
# Return the logical block size if running on a block device,
# else substitute the page size.
#
_min_dio_alignment()
{
local dev=$1
if [ -b "$dev" ]; then
blockdev --getss $dev
else
$here/src/feature -s
fi
}
run_check()
{
echo "# $@" >> $seqres.full 2>&1
"$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
}
_require_symlinks()
{
local target=`mktemp -p $TEST_DIR`
local link=`mktemp -p $TEST_DIR -u`
ln -s `basename $target` $link
if [ "$?" -ne 0 ]; then
rm -f $target
_notrun "Require symlinks support"
fi
rm -f $target $link
}
_require_hardlinks()
{
local target=`mktemp -p $TEST_DIR`
local link=`mktemp -p $TEST_DIR -u`
ln $target $link
if [ "$?" -ne 0 ]; then
rm -f $target
_notrun "No hardlink support"
fi
rm -f $target $link
}
_require_test_fcntl_advisory_locks()
{
[ "$FSTYP" != "cifs" ] && return 0
cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
_notrun "Require fcntl advisory locks support"
}
_require_test_fcntl_setlease()
{
_require_test_program "locktest"
touch $TEST_DIR/setlease_testfile
$here/src/locktest -t $TEST_DIR/setlease_testfile >/dev/null 2>&1
[ $? -eq 22 ] && _notrun "Require fcntl setlease support"
}
_require_ofd_locks()
{
# Give a test run by getlk wrlck on testfile.
# If the running kernel does not support OFD locks,
# EINVAL will be returned.
_require_test_program "t_ofd_locks"
touch $TEST_DIR/ofd_testfile
$here/src/t_ofd_locks -t $TEST_DIR/ofd_testfile > /dev/null 2>&1
[ $? -eq 22 ] && _notrun "Require OFD locks support"
}
_require_test_lsattr()
{
local testio=$(lsattr -d $TEST_DIR 2>&1)
echo $testio | grep -q "Operation not supported" && \
_notrun "lsattr not supported by test filesystem type: $FSTYP"
echo $testio | grep -q "Inappropriate ioctl for device" && \
_notrun "lsattr not supported by test filesystem type: $FSTYP"
}
_require_chattr()
{
if [ -z "$1" ]; then
echo "Usage: _require_chattr <attr>"
exit 1
fi
local attribute=$1
touch $TEST_DIR/syscalltest
chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
local ret=$?
chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
if [ "$ret" -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 "Usage: _get_total_inode <mnt>"
exit 1
fi
local nr_inode;
nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
echo $nr_inode
}
_get_used_inode()
{
if [ -z "$1" ]; then
echo "Usage: _get_used_inode <mnt>"
exit 1
fi
local nr_inode;
nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
echo $nr_inode
}
_get_used_inode_percent()
{
if [ -z "$1" ]; then
echo "Usage: _get_used_inode_percent <mnt>"
exit 1
fi
local pct_inode;
pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
sed -e 's/%//'`
echo $pct_inode
}
_get_free_inode()
{
if [ -z "$1" ]; then
echo "Usage: _get_free_inode <mnt>"
exit 1
fi
local nr_inode;
nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
echo $nr_inode
}
# get the available space in bytes
#
_get_available_space()
{
if [ -z "$1" ]; then
echo "Usage: _get_available_space <mnt>"
exit 1
fi
local avail_kb;
avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
echo $((avail_kb * 1024))
}
# return device size in kb
_get_device_size()
{
grep -w `_short_dev $1` /proc/partitions | awk '{print $3}'
}
# Make sure we actually have dmesg checking set up.
_require_check_dmesg()
{
test -w /dev/kmsg || \
_notrun "Test requires writable /dev/kmsg."
}
# Return the dmesg log since the start of this test. Caller must ensure that
# /dev/kmsg was writable when the test was started so that we can find the
# beginning of this test's log messages; _require_check_dmesg does this.
_dmesg_since_test_start()
{
# search the dmesg log of last run of $seqnum for possible failures
# use sed \cregexpc address type, since $seqnum contains "/"
dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
tac
}
# check dmesg log for a specific string, subject to the same requirements as
# _dmesg_since_test_start.
_check_dmesg_for()
{
_dmesg_since_test_start | egrep -q "$1"
}
# Default filter for dmesg scanning.
# Ignore lockdep complaining about its own bugginess when scanning dmesg
# output, because we shouldn't be failing filesystem tests on account of
# lockdep.
_check_dmesg_filter()
{
egrep -v -e "BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low" \
-e "BUG: MAX_STACK_TRACE_ENTRIES too low"
}
# check dmesg log for WARNING/Oops/etc.
_check_dmesg()
{
if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
return 0
fi
rm -f ${RESULT_DIR}/check_dmesg
# default filter is a simple cat command, caller could provide a
# customized filter and pass the name through the first argument, to
# filter out intentional WARNINGs or Oopses
local filter=${1:-_check_dmesg_filter}
_dmesg_since_test_start | $filter >$seqres.dmesg
egrep -q -e "kernel BUG at" \
-e "WARNING:" \
-e "\bBUG:" \
-e "Oops:" \
-e "possible recursive locking detected" \
-e "Internal error" \
-e "(INFO|ERR): suspicious RCU usage" \
-e "INFO: possible circular locking dependency detected" \
-e "general protection fault:" \
-e "BUG .* remaining" \
-e "UBSAN:" \
$seqres.dmesg
if [ $? -eq 0 ]; then
_dump_err "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
return 1
else
if [ "$KEEP_DMESG" != "yes" ]; then
rm -f $seqres.dmesg
fi
return 0
fi
}
# capture the kmemleak report
_capture_kmemleak()
{
local kern_knob="$DEBUGFS_MNT/kmemleak"
local leak_file="$1"
# Tell the kernel to scan for memory leaks. Apparently the write
# returns before the scan is complete, so do it twice in the hopes
# that twice is enough to capture all the leaks.
echo "scan" > "$kern_knob"
cat "$kern_knob" > /dev/null
echo "scan" > "$kern_knob"
cat "$kern_knob" > "$leak_file.tmp"
if [ -s "$leak_file.tmp" ]; then
cat > "$leak_file" << ENDL
EXPERIMENTAL kmemleak reported some memory leaks! Due to the way kmemleak
works, the leak might be from an earlier test, or something totally unrelated.
ENDL
cat "$leak_file.tmp" >> "$leak_file"
fi
rm -rf "$leak_file.tmp"
echo "clear" > "$kern_knob"
}
# Figure out if the running kernel supports kmemleak; if it does, clear out
# anything that leaked before we even started testing. The leak checker only
# needs to be primed like this once per ./check invocation.
_detect_kmemleak()
{
local kern_knob="$DEBUGFS_MNT/kmemleak"
KMEMLEAK_CHECK_FILE="/tmp/check_kmemleak"
# Since kernel v4.19-rc3, the kmemleak knob exists even if kmemleak is
# disabled, but returns EBUSY on write. So instead of relying on
# existance of writable knob file, we use a test file to indicate that
# _check_kmemleak() is enabled only if we actually managed to write to
# the knob file.
rm -f "$KMEMLEAK_CHECK_FILE"
if [ ! -w "$kern_knob" ]; then
return 0
fi
# Disable the automatic scan so that we can control it completely,
# then dump all the leaks recorded so far.
if echo "scan=off" > "$kern_knob" 2>/dev/null; then
_capture_kmemleak /dev/null
touch "$KMEMLEAK_CHECK_FILE"
fi
}
# Kick the kmemleak checker to scan for leaks. Background leak scan mode is
# not enabled, so we must call the kernel to ask for a scan and deal with the
# results appropriately. This we do after every test completes, whether or not
# it was successful.
_check_kmemleak()
{
local kern_knob="$DEBUGFS_MNT/kmemleak"
local leak_file="$seqres.kmemleak"
if [ ! -f "$KMEMLEAK_CHECK_FILE" ]; then
return 0
fi
# Not enabled, so discard any report of leaks found.
if [ "$USE_KMEMLEAK" != "yes" ]; then
_capture_kmemleak /dev/null
return 0
fi
# Capture and report any leaks
_capture_kmemleak "$leak_file"
if [ -s "$leak_file" ]; then
_dump_err "_check_kmemleak: something found in kmemleak (see $leak_file)"
return 1
else
rm -f "$leak_file"
return 0
fi
}
# don't check dmesg log after test
_disable_dmesg_check()
{
rm -f ${RESULT_DIR}/check_dmesg
}
init_rc()
{
# make some further configuration checks here
if [ "$TEST_DEV" = "" ]
then
echo "common/rc: Error: \$TEST_DEV is not set"
exit 1
fi
# if $TEST_DEV is not mounted, mount it now as XFS
if [ -z "`_fs_type $TEST_DEV`" ]
then
# $TEST_DEV is not mounted
if ! _test_mount
then
echo "common/rc: retrying test device mount with external set"
[ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
if ! _test_mount
then
echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
exit 1
fi
fi
fi
# 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_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
}
# get real device path name by following link
_real_dev()
{
local dev=$1
if [ -b "$dev" ] && [ -L "$dev" ]; then
dev=`readlink -f "$dev"`
fi
echo $dev
}
# basename of a device
_short_dev()
{
echo `basename $(_real_dev $1)`
}
_sysfs_dev()
{
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)
min=$(echo "ibase=16; $min" | bc)
echo /sys/dev/block/$maj:$min
}
# 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
case "$FSTYP" in
"ocfs2")
stat -c '%o' $1
;;
"xfs")
_xfs_get_file_block_size $1
;;
*)
_get_block_size $1
;;
esac
}
# 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"
exit 1
fi
stat -f -c %S $1
}
get_page_size()
{
echo $(getconf PAGE_SIZE)
}
run_fsx()
{
echo fsx $@
local 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
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
#
# 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
}
_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:
# - 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}
}
# 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_features ${feature}
;;
*)
_fail "Test for feature '${feature}' of ${FSTYP} is not implemented"
;;
esac
}
# Get the maximum size of a file in $TEST_DIR (s_maxbytes). On ext4 this will
# be UINT32_MAX * block_size, but other filesystems may allow up to LLONG_MAX.
_get_max_file_size()
{
local testfile=$TEST_DIR/maxfilesize.$seq
local l=0
local r=9223372036854775807 # LLONG_MAX
rm -f $testfile
while (( l < r )); do
# Use _math() to avoid signed integer overflow.
local m=$(_math "($l + $r + 1) / 2")
if $XFS_IO_PROG -f -c "truncate $m" $testfile \
|& grep -q 'File too large'
then
r=$(( m - 1 ))
else
l=$m
fi
done
echo $l
}
# get MAX_LFS_FILESIZE
_get_max_lfs_filesize()
{
case "$(getconf LONG_BIT)" in
"32")
local ulong_max=$(getconf ULONG_MAX)
local page_size=$(getconf PAGE_SIZE)
echo $(( ulong_max * page_size ))
;;
"64")
echo 9223372036854775807
;;
*)
_fail "sizeof(long) == $(getconf LONG_BIT)?"
;;
esac
}
# The maximum filesystem label length, /not/ including terminating NULL
_label_get_max()
{
case $FSTYP in
xfs)
echo 12
;;
btrfs)
echo 255
;;
f2fs)
echo 255
;;
*)
_notrun "$FSTYP does not define maximum label length"
;;
esac
}
# Helper to check above early in a script
_require_label_get_max()
{
# Just call _label_get_max which will notrun if appropriate
dummy=$(_label_get_max)
}
_dmsetup_remove()
{
$UDEV_SETTLE_PROG >/dev/null 2>&1
$DMSETUP_PROG remove "$@" >>$seqres.full 2>&1
$DMSETUP_PROG mknodes >/dev/null 2>&1
}
_dmsetup_create()
{
$DMSETUP_PROG create "$@" >>$seqres.full 2>&1 || return 1
$DMSETUP_PROG mknodes >/dev/null 2>&1
$UDEV_SETTLE_PROG >/dev/null 2>&1
}
_require_btime()
{
# Note: filesystems are not required to report btime (creation time)
# if the caller doesn't ask for it, so we define STATX_BTIME here and
# pass it in to the statx command.
export STATX_BTIME=0x800
$XFS_IO_PROG -f $TEST_DIR/test_creation_time -c "statx -m $STATX_BTIME -v" \
| grep btime >>$seqres.full 2>&1 || \
_notrun "inode creation time not supported by this filesystem"
rm -f $TEST_DIR/test_creation_time
}
_require_scratch_btime()
{
_require_scratch
_scratch_mkfs > /dev/null 2>&1
_scratch_mount
# Note: filesystems are not required to report btime (creation time)
# if the caller doesn't ask for it, so we define STATX_BTIME here and
# pass it in to the statx command.
export STATX_BTIME=0x800
$XFS_IO_PROG -f $SCRATCH_MNT/test_creation_time -c "statx -m $STATX_BTIME -v" \
| grep btime >>$seqres.full 2>&1 || \
_notrun "inode creation time not supported by this filesystem"
_scratch_unmount
}
_require_inode_limits()
{
if [ $(_get_free_inode $TEST_DIR) -eq 0 ]; then
_notrun "$FSTYP does not have a fixed number of inodes available"
fi
}
_require_filefrag_options()
{
_require_command "$FILEFRAG_PROG" filefrag
local options=$1
local file="$TEST_DIR/options_testfile"
echo "XX" > $file
${FILEFRAG_PROG} -$options $file 2>&1 | grep -q "invalid option" && \
_notrun "filefrag doesn't support $options option"
rm -f $file
}
_require_fibmap()
{
_require_filefrag_options "B"
local file="$TEST_DIR/fibmap_testfile"
echo "XX" > $file
${FILEFRAG_PROG} -B $file 2>&1 | grep -q "FIBMAP[[:space:]]*unsupported"
if [ $? -eq 0 ]; then
_notrun "FIBMAP not supported by this filesystem"
fi
rm -f $file
}
_try_wipe_scratch_devs()
{
test -x "$WIPEFS_PROG" || return 0
# Do specified filesystem wipe at first
case "$FSTYP" in
"xfs")
_try_wipe_scratch_xfs
;;
esac
# Then do wipefs on all scratch devices
for dev in $SCRATCH_DEV_POOL $SCRATCH_DEV $SCRATCH_LOGDEV $SCRATCH_RTDEV; do
test -b $dev && $WIPEFS_PROG -a $dev
done
}
# Only run this on xfs if xfs_scrub is available and has the unicode checker
_check_xfs_scrub_does_unicode() {
[ "${FSTYP}" == "xfs" ] || return 1
local mount="$1"
local dev="$2"
_supports_xfs_scrub "${mount}" "${dev}" || return 1
# We only care if xfs_scrub has unicode string support...
if ! type ldd > /dev/null 2>&1 || \
! ldd "${XFS_SCRUB_PROG}" | grep -q libicui18n; then
return 1
fi
return 0
}
# exfat timestamps start at 1980 and cannot be prior to epoch
_require_negative_timestamps() {
case "$FSTYP" in
ceph|exfat)
_notrun "$FSTYP does not support negative timestamps"
;;
esac
}
# Require the 'accton' userspace tool and CONFIG_BSD_PROCESS_ACCT=y.
_require_bsd_process_accounting()
{
_require_command "$ACCTON_PROG" accton
$ACCTON_PROG on &> $tmp.test_accton
cat $tmp.test_accton >> $seqres.full
if grep 'Function not implemented' $tmp.test_accton; then
_notrun "BSD process accounting support unavailable"
fi
$ACCTON_PROG off >> $seqres.full
}
_require_sysctl_variable()
{
local name=$1
sysctl $name &>/dev/null || _notrun "$name sysctl unavailable"
}
_require_mknod()
{
mknod $TEST_DIR/$seq.null c 1 3 \
|| _notrun "$FSTYP does not support mknod/mkfifo"
rm -f $TEST_DIR/$seq.null
}
_getcap()
{
$GETCAP_PROG "$@" | _filter_getcap
return ${PIPESTATUS[0]}
}
init_rc
################################################################################
# make sure this script returns success
/bin/true