2010-01-20 10:27:08 +11:00
|
|
|
##/bin/bash
|
2018-06-09 11:34:49 +10:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
# Copyright (c) 2000-2006 Silicon Graphics, Inc. All Rights Reserved.
|
2004-06-15 07:32:36 +00:00
|
|
|
|
2018-05-29 18:51:19 +02:00
|
|
|
. common/config
|
2011-09-26 18:45:09 +00:00
|
|
|
|
2018-05-29 18:51:19 +02:00
|
|
|
BC=$(which bc 2> /dev/null) || BC=
|
2015-04-02 09:23:10 +11:00
|
|
|
|
2018-01-11 20:16:18 -08:00
|
|
|
# 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."
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-26 18:45:09 +00:00
|
|
|
_require_math()
|
|
|
|
|
{
|
|
|
|
|
if [ -z "$BC" ]; then
|
|
|
|
|
_notrun "this test requires 'bc' tool for doing math operations"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_math()
|
|
|
|
|
{
|
|
|
|
|
[ $# -le 0 ] && return
|
2018-04-06 19:35:29 -07:00
|
|
|
LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null
|
2011-09-26 18:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-15 06:10:31 +00:00
|
|
|
dd()
|
|
|
|
|
{
|
|
|
|
|
if [ "$HOSTOS" == "Linux" ]
|
|
|
|
|
then
|
2014-09-29 12:59:45 +10:00
|
|
|
command dd --help 2>&1 | grep noxfer >/dev/null
|
2006-05-15 06:10:31 +00:00
|
|
|
|
|
|
|
|
if [ "$?" -eq 0 ]
|
|
|
|
|
then
|
|
|
|
|
command dd status=noxfer $@
|
|
|
|
|
else
|
|
|
|
|
command dd $@
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
command dd $@
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-26 19:13:59 +00:00
|
|
|
# Prints the md5 checksum of a given file
|
|
|
|
|
_md5_checksum()
|
|
|
|
|
{
|
|
|
|
|
md5sum $1 | cut -d ' ' -f1
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-17 08:39:17 +11:00
|
|
|
# Write a byte into a range of a file
|
|
|
|
|
_pwrite_byte() {
|
2018-04-06 19:35:29 -07:00
|
|
|
local pattern="$1"
|
|
|
|
|
local offset="$2"
|
|
|
|
|
local len="$3"
|
|
|
|
|
local file="$4"
|
|
|
|
|
local xfs_io_args="$5"
|
2015-11-17 08:39:17 +11:00
|
|
|
|
2016-10-17 10:23:33 +03:00
|
|
|
$XFS_IO_PROG $xfs_io_args -f -c "pwrite -S $pattern $offset $len" "$file"
|
2015-11-17 08:39:17 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# mmap-write a byte into a range of a file
|
|
|
|
|
_mwrite_byte() {
|
2018-04-06 19:35:29 -07:00
|
|
|
local pattern="$1"
|
|
|
|
|
local offset="$2"
|
|
|
|
|
local len="$3"
|
|
|
|
|
local mmap_len="$4"
|
|
|
|
|
local file="$5"
|
2015-11-17 08:39:17 +11:00
|
|
|
|
2016-10-17 10:23:33 +03:00
|
|
|
$XFS_IO_PROG -f -c "mmap -rw 0 $mmap_len" -c "mwrite -S $pattern $offset $len" "$file"
|
2015-11-17 08:39:17 +11:00
|
|
|
}
|
2013-04-26 19:13:59 +00:00
|
|
|
|
2010-02-03 08:35:24 -06:00
|
|
|
# ls -l w/ selinux sometimes puts a dot at the end:
|
|
|
|
|
# -rwxrw-r--. id1 id2 file1
|
2014-01-20 12:46:51 +11:00
|
|
|
# Also filter out lost+found directory on extN file system if present
|
2010-02-03 08:35:24 -06:00
|
|
|
|
|
|
|
|
_ls_l()
|
|
|
|
|
{
|
2014-01-20 12:46:51 +11:00
|
|
|
ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /" | grep -v 'lost+found'
|
2010-02-03 08:35:24 -06:00
|
|
|
}
|
|
|
|
|
|
2017-03-03 12:26:15 +04:00
|
|
|
_dump_err()
|
|
|
|
|
{
|
2018-04-06 19:35:30 -07:00
|
|
|
_err_msg="$*"
|
|
|
|
|
echo "$_err_msg"
|
2017-03-03 12:26:15 +04:00
|
|
|
}
|
|
|
|
|
|
2018-05-29 09:07:37 +10:00
|
|
|
_dump_err_cont()
|
|
|
|
|
{
|
|
|
|
|
_err_msg="$*"
|
|
|
|
|
echo -n "$_err_msg"
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-03 12:26:15 +04:00
|
|
|
_dump_err2()
|
|
|
|
|
{
|
2018-04-06 19:35:30 -07:00
|
|
|
_err_msg="$*"
|
|
|
|
|
>2& echo "$_err_msg"
|
2017-03-03 12:26:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_log_err()
|
|
|
|
|
{
|
2018-04-06 19:35:30 -07:00
|
|
|
_err_msg="$*"
|
|
|
|
|
echo "$_err_msg" | tee -a $seqres.full
|
2017-03-03 12:26:15 +04:00
|
|
|
echo "(see $seqres.full for details)"
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-30 08:32:32 +11:00
|
|
|
# make sure we have a standard umask
|
|
|
|
|
umask 022
|
|
|
|
|
|
2016-11-30 08:32:33 +11:00
|
|
|
# check for correct setup and source the $FSTYP specific functions now
|
2013-03-15 12:27:50 +00:00
|
|
|
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"
|
2018-06-05 09:43:27 -07:00
|
|
|
[ "$XFS_INFO_PROG" = "" ] && _fatal "xfs_info not found"
|
2016-11-30 08:32:32 +11:00
|
|
|
|
|
|
|
|
. ./common/xfs
|
2013-03-15 12:27:50 +00:00
|
|
|
;;
|
|
|
|
|
udf)
|
|
|
|
|
[ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
|
|
|
|
|
;;
|
|
|
|
|
btrfs)
|
|
|
|
|
[ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
|
2016-11-30 08:32:33 +11:00
|
|
|
|
|
|
|
|
. ./common/btrfs
|
2013-03-15 12:27:50 +00:00
|
|
|
;;
|
2014-09-29 12:46:43 +10:00
|
|
|
ext4)
|
|
|
|
|
[ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found"
|
|
|
|
|
;;
|
2014-12-24 14:56:26 +11:00
|
|
|
f2fs)
|
|
|
|
|
[ "$MKFS_F2FS_PROG" = "" ] && _fatal "mkfs.f2fs not found"
|
|
|
|
|
;;
|
2013-03-15 12:27:50 +00:00
|
|
|
nfs)
|
2017-05-16 19:35:15 +08:00
|
|
|
. ./common/nfs
|
2013-03-15 12:27:50 +00:00
|
|
|
;;
|
2014-09-08 22:26:52 +10:00
|
|
|
cifs)
|
|
|
|
|
;;
|
2018-01-11 16:05:43 +02:00
|
|
|
9p)
|
|
|
|
|
;;
|
2016-11-04 11:04:39 +01:00
|
|
|
ceph)
|
|
|
|
|
;;
|
2017-03-16 13:28:19 +08:00
|
|
|
glusterfs)
|
|
|
|
|
;;
|
2015-12-21 18:07:47 +11:00
|
|
|
overlay)
|
2017-09-27 13:47:32 +03:00
|
|
|
. ./common/overlay
|
2015-12-21 18:07:47 +11:00
|
|
|
;;
|
2014-12-24 14:56:07 +11:00
|
|
|
reiser4)
|
|
|
|
|
[ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
|
|
|
|
|
;;
|
2017-04-07 16:09:43 -04:00
|
|
|
pvfs2)
|
|
|
|
|
;;
|
2017-06-07 10:20:45 +02:00
|
|
|
ubifs)
|
|
|
|
|
[ "$UBIUPDATEVOL_PROG" = "" ] && _fatal "ubiupdatevol not found"
|
|
|
|
|
;;
|
2013-03-15 12:27:50 +00:00
|
|
|
esac
|
|
|
|
|
|
2017-03-03 12:26:16 +04:00
|
|
|
if [ ! -z "$REPORT_LIST" ]; then
|
|
|
|
|
. ./common/report
|
|
|
|
|
_assert_report_list
|
|
|
|
|
fi
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
_mount()
|
2001-01-15 05:01:19 +00:00
|
|
|
{
|
2006-12-19 02:55:36 +00:00
|
|
|
$MOUNT_PROG `_mount_ops_filter $*`
|
2001-01-15 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-13 19:55:42 -05:00
|
|
|
# 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=${!#}
|
2018-01-11 20:16:17 -08:00
|
|
|
local mnt_dev=${@:(-2):1}
|
|
|
|
|
local scratch_opts=""
|
|
|
|
|
if [ "$mnt_dev" = "$SCRATCH_DEV" ]; then
|
|
|
|
|
_scratch_options mount
|
|
|
|
|
scratch_opts="$SCRATCH_OPTIONS"
|
|
|
|
|
fi
|
2017-02-13 19:55:42 -05:00
|
|
|
|
2018-01-11 20:16:17 -08:00
|
|
|
_mount $scratch_opts $*
|
2017-02-13 19:55:42 -05:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
|
MOUNTED_POINT_STACK="$mnt_point $MOUNTED_POINT_STACK"
|
|
|
|
|
else
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Unmount the last mounted mountpoint in MOUNTED_POINT_STACK
|
|
|
|
|
# and return it to caller
|
|
|
|
|
_put_mount()
|
|
|
|
|
{
|
|
|
|
|
local last_mnt=`echo $MOUNTED_POINT_STACK | awk '{print $1}'`
|
|
|
|
|
|
|
|
|
|
if [ -n "$last_mnt" ]; then
|
|
|
|
|
$UMOUNT_PROG $last_mnt
|
|
|
|
|
fi
|
|
|
|
|
MOUNTED_POINT_STACK=`echo $MOUNTED_POINT_STACK | cut -d\ -f2-`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Unmount all mountpoints in MOUNTED_POINT_STACK and clear the stack
|
|
|
|
|
_clear_mount_stack()
|
|
|
|
|
{
|
|
|
|
|
if [ -n "$MOUNTED_POINT_STACK" ]; then
|
|
|
|
|
$UMOUNT_PROG $MOUNTED_POINT_STACK
|
|
|
|
|
fi
|
|
|
|
|
MOUNTED_POINT_STACK=""
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
_scratch_options()
|
2002-01-20 00:47:43 +00:00
|
|
|
{
|
2018-01-11 20:16:17 -08:00
|
|
|
local type=$1
|
2018-04-06 19:35:29 -07:00
|
|
|
local rt_opt=""
|
|
|
|
|
local log_opt=""
|
2004-06-15 07:32:36 +00:00
|
|
|
SCRATCH_OPTIONS=""
|
|
|
|
|
|
2006-07-07 16:00:24 +00:00
|
|
|
if [ "$FSTYP" != "xfs" ]; then
|
2004-06-15 07:32:36 +00:00
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
case $type in
|
|
|
|
|
mkfs)
|
2017-07-20 21:22:05 -07:00
|
|
|
SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
|
2004-06-15 07:32:36 +00:00
|
|
|
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()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local type=$1
|
|
|
|
|
local rt_opt=""
|
|
|
|
|
local log_opt=""
|
2003-05-22 04:16:45 +00:00
|
|
|
TEST_OPTIONS=""
|
2004-06-15 07:32:36 +00:00
|
|
|
|
2006-07-07 16:00:24 +00:00
|
|
|
if [ "$FSTYP" != "xfs" ]; then
|
2004-06-15 07:32:36 +00:00
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
2004-06-16 06:08:04 +00:00
|
|
|
case $type in
|
2004-06-15 07:32:36 +00:00
|
|
|
mkfs)
|
|
|
|
|
rt_opt="-r"
|
|
|
|
|
log_opt="-l"
|
|
|
|
|
;;
|
|
|
|
|
mount)
|
|
|
|
|
rt_opt="-o"
|
|
|
|
|
log_opt="-o"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2003-06-01 21:40:24 +00:00
|
|
|
[ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
|
2004-06-15 07:32:36 +00:00
|
|
|
TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
|
2003-06-01 21:40:24 +00:00
|
|
|
[ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
|
2004-06-15 07:32:36 +00:00
|
|
|
TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
|
2003-05-22 04:16:45 +00:00
|
|
|
}
|
|
|
|
|
|
2006-12-19 02:55:36 +00:00
|
|
|
_mount_ops_filter()
|
2006-10-13 03:54:57 +00:00
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local params="$*"
|
|
|
|
|
local last_index=$(( $# - 1 ))
|
|
|
|
|
|
2007-01-11 02:56:11 +00:00
|
|
|
#get mount point to handle dmapi mtpt option correctly
|
2006-12-19 02:55:36 +00:00
|
|
|
[ $last_index -gt 0 ] && shift $last_index
|
2018-04-06 19:35:29 -07:00
|
|
|
local fs_escaped=$1
|
|
|
|
|
|
2017-07-20 21:22:05 -07:00
|
|
|
echo $params | sed -e 's/dmapi/dmi/' \
|
2018-04-06 19:35:29 -07:00
|
|
|
| $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$fs_escaped\1\2#; print;"
|
2007-01-11 02:56:11 +00:00
|
|
|
|
2006-10-13 03:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-21 13:06:18 +10:00
|
|
|
# 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 $*
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-22 04:16:45 +00:00
|
|
|
_scratch_mount_options()
|
|
|
|
|
{
|
2015-09-21 13:06:18 +10:00
|
|
|
_scratch_options mount
|
2006-12-19 02:55:36 +00:00
|
|
|
|
2015-09-21 13:06:18 +10:00
|
|
|
echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
|
|
|
|
|
$SCRATCH_DEV $SCRATCH_MNT
|
2003-05-22 04:16:45 +00:00
|
|
|
}
|
|
|
|
|
|
2016-12-20 15:17:33 +02:00
|
|
|
_supports_filetype()
|
|
|
|
|
{
|
|
|
|
|
local dir=$1
|
|
|
|
|
|
2017-01-16 16:07:20 +08:00
|
|
|
local fstyp=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $2}'`
|
2016-12-20 15:17:33 +02:00
|
|
|
case "$fstyp" in
|
|
|
|
|
xfs)
|
2018-06-05 09:43:27 -07:00
|
|
|
$XFS_INFO_PROG $dir | grep -q "ftype=1"
|
2016-12-20 15:17:33 +02:00
|
|
|
;;
|
|
|
|
|
ext2|ext3|ext4)
|
2017-01-16 16:07:20 +08:00
|
|
|
local dev=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $1}'`
|
|
|
|
|
tune2fs -l $dev | grep -q filetype
|
2016-12-20 15:17:33 +02:00
|
|
|
;;
|
2016-12-20 15:17:34 +02:00
|
|
|
*)
|
|
|
|
|
local testfile=$dir/$$.ftype
|
|
|
|
|
touch $testfile
|
|
|
|
|
# look for DT_UNKNOWN files
|
|
|
|
|
local unknowns=$(src/t_dir_type $dir u | wc -l)
|
|
|
|
|
rm $testfile
|
|
|
|
|
# 0 unknowns is success
|
|
|
|
|
return $unknowns
|
|
|
|
|
;;
|
2016-12-20 15:17:33 +02:00
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 17:31:36 +08:00
|
|
|
# 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
|
2003-05-22 04:16:45 +00:00
|
|
|
_scratch_mount()
|
|
|
|
|
{
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount $* || _fail "mount failed"
|
2004-06-15 07:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-10 13:10:26 -05:00
|
|
|
_scratch_unmount()
|
|
|
|
|
{
|
2016-02-08 09:27:14 +11:00
|
|
|
case "$FSTYP" in
|
|
|
|
|
overlay)
|
2015-12-21 18:07:47 +11:00
|
|
|
_overlay_scratch_unmount
|
2016-02-08 09:27:14 +11:00
|
|
|
;;
|
|
|
|
|
btrfs)
|
|
|
|
|
$UMOUNT_PROG $SCRATCH_MNT
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2015-12-21 18:07:47 +11:00
|
|
|
$UMOUNT_PROG $SCRATCH_DEV
|
2016-02-08 09:27:14 +11:00
|
|
|
;;
|
|
|
|
|
esac
|
2009-08-10 13:10:26 -05:00
|
|
|
}
|
|
|
|
|
|
2016-02-19 10:45:35 +11:00
|
|
|
_scratch_remount()
|
|
|
|
|
{
|
|
|
|
|
local opts="$1"
|
|
|
|
|
|
|
|
|
|
if test -n "$opts"; then
|
|
|
|
|
mount -o "remount,$opts" $SCRATCH_MNT
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-19 10:44:53 +11:00
|
|
|
_scratch_cycle_mount()
|
2009-08-10 13:10:26 -05:00
|
|
|
{
|
2016-02-19 10:45:35 +11:00
|
|
|
local opts="$1"
|
|
|
|
|
|
|
|
|
|
if [ "$FSTYP" = tmpfs ]; then
|
|
|
|
|
_scratch_remount "$opts"
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
if test -n "$opts"; then
|
|
|
|
|
opts="-o $opts"
|
|
|
|
|
fi
|
2009-08-10 13:10:26 -05:00
|
|
|
_scratch_unmount
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount "$opts" || _fail "cycle mount failed"
|
2009-08-10 13:10:26 -05:00
|
|
|
}
|
|
|
|
|
|
2017-12-15 15:47:33 +08:00
|
|
|
_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
|
|
|
|
|
src/godown $* $OVL_BASE_SCRATCH_MNT
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
src/godown $* $SCRATCH_MNT
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
_test_mount()
|
|
|
|
|
{
|
2015-12-21 18:07:47 +11:00
|
|
|
if [ "$FSTYP" == "overlay" ]; then
|
|
|
|
|
_overlay_test_mount $*
|
|
|
|
|
return $?
|
|
|
|
|
fi
|
2005-07-11 14:57:36 +00:00
|
|
|
_test_options mount
|
2010-02-19 09:33:45 -06:00
|
|
|
_mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
|
2003-05-22 04:16:45 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-21 18:07:43 +11:00
|
|
|
_test_unmount()
|
|
|
|
|
{
|
2015-12-21 18:07:47 +11:00
|
|
|
if [ "$FSTYP" == "overlay" ]; then
|
|
|
|
|
_overlay_test_unmount
|
|
|
|
|
else
|
|
|
|
|
$UMOUNT_PROG $TEST_DEV
|
|
|
|
|
fi
|
2015-12-21 18:07:43 +11:00
|
|
|
}
|
|
|
|
|
|
2016-02-19 10:45:04 +11:00
|
|
|
_test_cycle_mount()
|
2014-09-08 22:26:52 +10:00
|
|
|
{
|
2016-02-19 10:45:35 +11:00
|
|
|
if [ "$FSTYP" = tmpfs ]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
2015-12-21 18:07:43 +11:00
|
|
|
_test_unmount
|
2014-09-08 22:26:52 +10:00
|
|
|
_test_mount
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-22 04:16:45 +00:00
|
|
|
_scratch_mkfs_options()
|
|
|
|
|
{
|
2005-07-11 14:57:36 +00:00
|
|
|
_scratch_options mkfs
|
2003-05-22 04:16:45 +00:00
|
|
|
echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-05 00:15:08 +08:00
|
|
|
# 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
|
2017-01-11 17:38:45 +08:00
|
|
|
local tmp=`mktemp -u`
|
2016-12-05 00:15:08 +08:00
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
2017-01-11 17:38:45 +08:00
|
|
|
rm -f $tmp.mkfserr $tmp.mkfsstd
|
2016-12-05 00:15:08 +08:00
|
|
|
return $mkfs_status
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-20 06:22:35 +00:00
|
|
|
_scratch_metadump()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local dumpfile=$1
|
2017-01-21 00:10:58 -08:00
|
|
|
shift
|
2018-04-06 19:35:29 -07:00
|
|
|
local options=
|
2014-01-20 06:22:35 +00:00
|
|
|
|
|
|
|
|
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
|
|
|
|
|
options="-l $SCRATCH_LOGDEV"
|
|
|
|
|
|
2017-01-21 00:10:58 -08:00
|
|
|
xfs_metadump $options "$@" $SCRATCH_DEV $dumpfile
|
2014-01-20 06:22:35 +00:00
|
|
|
}
|
2013-03-15 11:53:23 +00:00
|
|
|
|
2013-03-15 11:53:27 +00:00
|
|
|
_setup_large_ext4_fs()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local fs_size=$1
|
2013-03-15 11:53:27 +00:00
|
|
|
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
|
2018-04-06 19:35:29 -07:00
|
|
|
local space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
|
2013-03-15 11:53:27 +00:00
|
|
|
|
|
|
|
|
# mount the filesystem and create 16TB - 4KB files until we consume
|
|
|
|
|
# all the necessary space.
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount 2>&1 >$tmp_dir/mnt.err
|
2013-03-15 11:53:27 +00:00
|
|
|
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
|
|
|
|
|
|
2018-04-06 19:35:29 -07:00
|
|
|
local file_size=$((16*1024*1024*1024*1024 - 4096))
|
|
|
|
|
local nfiles=0
|
2013-03-15 11:53:27 +00:00
|
|
|
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
|
2013-03-15 11:53:31 +00:00
|
|
|
export NUM_SPACE_FILES=$nfiles
|
2013-03-15 11:53:27 +00:00
|
|
|
|
2015-12-21 18:07:43 +11:00
|
|
|
_scratch_unmount
|
2013-03-15 11:53:27 +00:00
|
|
|
if [ $status -ne 0 ]; then
|
|
|
|
|
echo "large file prealloc failed"
|
|
|
|
|
cat $tmp_dir/mnt.err >&2
|
|
|
|
|
return $status
|
|
|
|
|
fi
|
|
|
|
|
return 0
|
|
|
|
|
}
|
2014-04-04 17:18:15 +11:00
|
|
|
|
2013-03-15 11:53:27 +00:00
|
|
|
_scratch_mkfs_ext4()
|
|
|
|
|
{
|
2016-12-05 00:15:08 +08:00
|
|
|
local mkfs_cmd="$MKFS_EXT4_PROG -F"
|
|
|
|
|
local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
|
2017-01-11 17:38:45 +08:00
|
|
|
local tmp=`mktemp -u`
|
2016-12-05 00:15:08 +08:00
|
|
|
local mkfs_status
|
2014-08-13 11:15:15 +10:00
|
|
|
|
2017-06-16 15:36:15 -04:00
|
|
|
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
|
|
|
|
|
$mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
|
|
|
|
|
mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
|
2013-03-15 11:53:27 +00:00
|
|
|
|
2016-12-05 00:15:08 +08:00
|
|
|
_scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
|
|
|
|
|
mkfs_status=$?
|
2014-08-13 11:15:15 +10:00
|
|
|
|
2013-03-15 11:53:27 +00:00
|
|
|
if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
|
|
|
|
|
# manually parse the mkfs output to get the fs size in bytes
|
2018-04-06 19:35:29 -07:00
|
|
|
local fs_size=`cat $tmp.mkfsstd | awk ' \
|
2013-03-15 11:53:27 +00:00
|
|
|
/^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
|
|
|
|
|
|
2016-12-05 00:15:08 +08:00
|
|
|
# output mkfs stdout and stderr
|
|
|
|
|
cat $tmp.mkfsstd
|
|
|
|
|
cat $tmp.mkfserr >&2
|
2017-01-11 17:38:45 +08:00
|
|
|
rm -f $tmp.mkfserr $tmp.mkfsstd
|
2013-03-15 11:53:27 +00:00
|
|
|
|
|
|
|
|
return $mkfs_status
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-04 17:18:15 +11:00
|
|
|
_test_mkfs()
|
|
|
|
|
{
|
|
|
|
|
case $FSTYP in
|
|
|
|
|
nfs*)
|
|
|
|
|
# do nothing for nfs
|
|
|
|
|
;;
|
2014-09-08 22:26:52 +10:00
|
|
|
cifs)
|
|
|
|
|
# do nothing for cifs
|
|
|
|
|
;;
|
2018-01-11 16:05:43 +02:00
|
|
|
9p)
|
|
|
|
|
# do nothing for 9p
|
|
|
|
|
;;
|
2016-11-04 11:04:39 +01:00
|
|
|
ceph)
|
|
|
|
|
# do nothing for ceph
|
|
|
|
|
;;
|
2017-03-16 13:28:19 +08:00
|
|
|
glusterfs)
|
|
|
|
|
# do nothing for glusterfs
|
|
|
|
|
;;
|
2015-12-21 18:07:47 +11:00
|
|
|
overlay)
|
|
|
|
|
# do nothing for overlay
|
|
|
|
|
;;
|
2017-04-07 16:09:43 -04:00
|
|
|
pvfs2)
|
|
|
|
|
# do nothing for pvfs2
|
|
|
|
|
;;
|
2014-04-04 17:18:15 +11:00
|
|
|
udf)
|
|
|
|
|
$MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
|
|
|
|
|
;;
|
|
|
|
|
btrfs)
|
|
|
|
|
$MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
|
|
|
|
|
;;
|
2014-12-16 10:50:21 +11:00
|
|
|
ext2|ext3|ext4)
|
|
|
|
|
$MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
|
|
|
|
|
;;
|
2014-04-04 17:18:15 +11:00
|
|
|
*)
|
|
|
|
|
yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-08 20:49:14 +10:00
|
|
|
_mkfs_dev()
|
|
|
|
|
{
|
2017-01-11 17:38:45 +08:00
|
|
|
local tmp=`mktemp -u`
|
2014-09-08 20:49:14 +10:00
|
|
|
case $FSTYP in
|
|
|
|
|
nfs*)
|
|
|
|
|
# do nothing for nfs
|
|
|
|
|
;;
|
2018-01-11 16:05:43 +02:00
|
|
|
9p)
|
|
|
|
|
# do nothing for 9p
|
|
|
|
|
;;
|
2015-12-21 18:07:47 +11:00
|
|
|
overlay)
|
|
|
|
|
# do nothing for overlay
|
|
|
|
|
;;
|
2017-04-07 16:09:43 -04:00
|
|
|
pvfs2)
|
|
|
|
|
# do nothing for pvfs2
|
|
|
|
|
;;
|
2014-09-08 20:49:14 +10:00
|
|
|
udf)
|
2017-01-11 17:38:45 +08:00
|
|
|
$MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
|
2014-09-08 20:49:14 +10:00
|
|
|
;;
|
|
|
|
|
btrfs)
|
2017-01-11 17:38:45 +08:00
|
|
|
$MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
|
2014-09-08 20:49:14 +10:00
|
|
|
;;
|
2014-12-16 10:50:21 +11:00
|
|
|
ext2|ext3|ext4)
|
|
|
|
|
$MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
|
2017-01-11 17:38:45 +08:00
|
|
|
2>$tmp.mkfserr 1>$tmp.mkfsstd
|
2014-12-16 10:50:21 +11:00
|
|
|
;;
|
2017-10-28 10:08:56 -07:00
|
|
|
xfs)
|
|
|
|
|
$MKFS_PROG -t $FSTYP -- -f $MKFS_OPTIONS $* \
|
|
|
|
|
2>$tmp.mkfserr 1>$tmp.mkfsstd
|
|
|
|
|
;;
|
2014-09-08 20:49:14 +10:00
|
|
|
*)
|
|
|
|
|
yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
|
2017-01-11 17:38:45 +08:00
|
|
|
2>$tmp.mkfserr 1>$tmp.mkfsstd
|
2014-09-08 20:49:14 +10:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
|
# output stored mkfs output
|
2017-01-11 17:38:45 +08:00
|
|
|
cat $tmp.mkfserr >&2
|
|
|
|
|
cat $tmp.mkfsstd
|
2014-09-08 20:49:14 +10:00
|
|
|
status=1
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2017-01-11 17:38:45 +08:00
|
|
|
rm -f $tmp.mkfserr $tmp.mkfsstd
|
2014-09-08 20:49:14 +10:00
|
|
|
}
|
|
|
|
|
|
2014-11-10 18:06:23 +11:00
|
|
|
# remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
|
|
|
|
|
_scratch_cleanup_files()
|
|
|
|
|
{
|
2016-02-08 09:27:14 +11:00
|
|
|
case $FSTYP in
|
|
|
|
|
overlay)
|
2017-02-28 14:18:35 +02:00
|
|
|
# Avoid rm -rf /* if we messed up
|
|
|
|
|
[ -n "$OVL_BASE_SCRATCH_MNT" ] || return 1
|
2017-02-28 14:18:36 +02:00
|
|
|
_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
|
2016-02-08 09:27:14 +11:00
|
|
|
;;
|
|
|
|
|
*)
|
2017-02-28 14:18:35 +02:00
|
|
|
[ -n "$SCRATCH_MNT" ] || return 1
|
2016-02-08 09:27:14 +11:00
|
|
|
_scratch_mount
|
|
|
|
|
rm -rf $SCRATCH_MNT/*
|
|
|
|
|
_scratch_unmount
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2014-11-10 18:06:23 +11:00
|
|
|
}
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
_scratch_mkfs()
|
|
|
|
|
{
|
2016-12-05 00:15:08 +08:00
|
|
|
local mkfs_cmd=""
|
|
|
|
|
local mkfs_filter=""
|
|
|
|
|
local mkfs_status
|
|
|
|
|
|
|
|
|
|
case $FSTYP in
|
2018-01-11 16:05:43 +02:00
|
|
|
nfs*|cifs|ceph|overlay|glusterfs|pvfs2|9p)
|
2016-12-05 00:15:08 +08:00
|
|
|
# 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
|
2017-02-28 14:18:36 +02:00
|
|
|
return $?
|
2016-12-05 00:15:08 +08:00
|
|
|
;;
|
|
|
|
|
tmpfs)
|
|
|
|
|
# do nothing for tmpfs
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
2017-06-07 10:20:45 +02:00
|
|
|
ubifs)
|
|
|
|
|
# erase the UBI volume; reformated automatically on next mount
|
|
|
|
|
$UBIUPDATEVOL_PROG ${SCRATCH_DEV} -t
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
2016-12-05 00:15:08 +08:00
|
|
|
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"
|
|
|
|
|
;;
|
2017-06-16 15:36:16 -04:00
|
|
|
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)
|
2016-12-05 00:15:08 +08:00
|
|
|
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 $?
|
2004-06-15 07:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-23 21:28:13 +08:00
|
|
|
# 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
|
2017-04-21 16:00:52 +01:00
|
|
|
local -a devs="( $SCRATCH_DEV_POOL_SAVED )"
|
2016-06-23 21:28:13 +08:00
|
|
|
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=""
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-23 21:25:39 +08:00
|
|
|
#
|
|
|
|
|
# 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`
|
2017-04-21 16:00:52 +01:00
|
|
|
local -a devs="( $SCRATCH_DEV_POOL )"
|
2016-06-23 21:25:39 +08:00
|
|
|
|
|
|
|
|
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=""
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-23 13:07:10 +00:00
|
|
|
_scratch_pool_mkfs()
|
|
|
|
|
{
|
|
|
|
|
case $FSTYP in
|
|
|
|
|
btrfs)
|
2014-10-14 22:59:37 +11:00
|
|
|
# if dup profile is in mkfs options call _scratch_mkfs instead
|
|
|
|
|
# because dup profile only works with single device
|
|
|
|
|
if [[ "$*" =~ dup ]]; then
|
|
|
|
|
_scratch_mkfs $*
|
|
|
|
|
else
|
|
|
|
|
$MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
|
|
|
|
|
fi
|
|
|
|
|
;;
|
2013-08-23 13:07:10 +00:00
|
|
|
*)
|
2014-10-14 22:59:37 +11:00
|
|
|
echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
|
|
|
|
|
;;
|
2013-08-23 13:07:10 +00:00
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-19 10:44:11 +11:00
|
|
|
# Return the amount of free memory available on the system
|
|
|
|
|
_free_memory_bytes()
|
|
|
|
|
{
|
|
|
|
|
free -b | grep ^Mem | awk '{print $4}'
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-05 11:03:01 -06:00
|
|
|
# Create fs of certain size on scratch device
|
|
|
|
|
# _scratch_mkfs_sized <size in bytes> [optional blocksize]
|
|
|
|
|
_scratch_mkfs_sized()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local fssize=$1
|
|
|
|
|
local blocksize=$2
|
|
|
|
|
local def_blksz
|
2014-09-08 20:49:26 +10:00
|
|
|
|
|
|
|
|
case $FSTYP in
|
|
|
|
|
xfs)
|
|
|
|
|
def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
|
|
|
|
|
;;
|
2017-07-24 01:02:35 -03:00
|
|
|
ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4|ocfs2|reiserfs)
|
2014-09-08 20:49:26 +10:00
|
|
|
def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
|
|
|
|
|
;;
|
2017-07-14 19:06:19 -03:00
|
|
|
jfs)
|
|
|
|
|
def_blksz=4096
|
|
|
|
|
;;
|
2014-09-08 20:49:26 +10:00
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
[ -n "$def_blksz" ] && blocksize=$def_blksz
|
2010-02-05 11:03:01 -06:00
|
|
|
[ -z "$blocksize" ] && blocksize=4096
|
2013-09-17 19:30:41 +00:00
|
|
|
|
2014-09-08 20:49:26 +10:00
|
|
|
|
2018-04-06 19:35:29 -07:00
|
|
|
local re='^[0-9]+$'
|
2013-09-17 19:30:41 +00:00
|
|
|
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
|
|
|
|
|
|
2018-04-06 19:35:29 -07:00
|
|
|
local blocks=`expr $fssize / $blocksize`
|
2010-02-05 11:03:01 -06:00
|
|
|
|
2016-02-19 10:44:11 +11:00
|
|
|
if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
|
2018-04-06 19:35:29 -07:00
|
|
|
local devsize=`blockdev --getsize64 $SCRATCH_DEV`
|
2012-11-29 12:47:22 -06:00
|
|
|
[ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
|
|
|
|
|
fi
|
|
|
|
|
|
2010-02-05 11:03:01 -06:00
|
|
|
case $FSTYP in
|
|
|
|
|
xfs)
|
2013-09-03 00:14:54 +00:00
|
|
|
# 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
|
|
|
|
|
else
|
|
|
|
|
_scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
|
|
|
|
|
fi
|
2010-02-05 11:03:01 -06:00
|
|
|
;;
|
2011-06-02 22:35:18 -05:00
|
|
|
ext2|ext3|ext4|ext4dev)
|
2014-12-16 10:50:21 +11:00
|
|
|
${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
|
2010-02-05 11:03:01 -06:00
|
|
|
;;
|
2017-09-16 15:20:54 +02:00
|
|
|
gfs2)
|
2017-10-04 20:20:09 +02:00
|
|
|
# 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.
|
2018-04-06 19:35:29 -07:00
|
|
|
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"
|
2017-10-04 20:20:09 +02:00
|
|
|
fi
|
|
|
|
|
${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV $blocks
|
2017-09-16 15:20:54 +02:00
|
|
|
;;
|
2016-11-09 15:00:17 -08:00
|
|
|
ocfs2)
|
|
|
|
|
yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
|
|
|
|
|
;;
|
2013-12-23 22:53:51 +00:00
|
|
|
udf)
|
|
|
|
|
$MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
|
|
|
|
|
;;
|
2011-06-02 22:35:18 -05:00
|
|
|
btrfs)
|
2015-12-21 17:10:32 +11:00
|
|
|
local mixed_opt=
|
2018-04-11 22:07:29 -07:00
|
|
|
(( fssize <= 1024 * 1024 * 1024 )) && mixed_opt='--mixed'
|
2015-12-21 17:10:32 +11:00
|
|
|
$MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
|
2010-11-30 23:22:36 +01:00
|
|
|
;;
|
2017-07-14 19:06:19 -03:00
|
|
|
jfs)
|
|
|
|
|
${MKFS_PROG}.$FSTYP $MKFS_OPTIONS $SCRATCH_DEV $blocks
|
|
|
|
|
;;
|
2017-07-24 01:02:35 -03:00
|
|
|
reiserfs)
|
|
|
|
|
${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
|
|
|
|
|
;;
|
2014-12-24 14:56:07 +11:00
|
|
|
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`
|
|
|
|
|
;;
|
2015-12-21 18:01:47 +11:00
|
|
|
f2fs)
|
|
|
|
|
# mkfs.f2fs requires # of sectors as an input for the size
|
2018-04-06 19:35:29 -07:00
|
|
|
local sector_size=`blockdev --getss $SCRATCH_DEV`
|
2015-12-21 18:01:47 +11:00
|
|
|
$MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
|
|
|
|
|
;;
|
2016-02-19 10:44:11 +11:00
|
|
|
tmpfs)
|
2018-04-06 19:35:29 -07:00
|
|
|
local free_mem=`_free_memory_bytes`
|
2016-02-19 10:44:11 +11:00
|
|
|
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"
|
|
|
|
|
;;
|
2010-02-05 11:03:01 -06:00
|
|
|
*)
|
|
|
|
|
_notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-03 10:43:53 -06:00
|
|
|
# Emulate an N-data-disk stripe w/ various stripe units
|
|
|
|
|
# _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
|
|
|
|
|
_scratch_mkfs_geom()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local sunit_bytes=$1
|
|
|
|
|
local swidth_mult=$2
|
|
|
|
|
local blocksize=$3
|
2010-02-03 10:43:53 -06:00
|
|
|
[ -z "$blocksize" ] && blocksize=4096
|
|
|
|
|
|
2018-04-06 19:35:29 -07:00
|
|
|
local sunit_blocks=$(( sunit_bytes / blocksize ))
|
|
|
|
|
local swidth_blocks=$(( sunit_blocks * swidth_mult ))
|
2010-02-03 10:43:53 -06:00
|
|
|
|
|
|
|
|
case $FSTYP in
|
|
|
|
|
xfs)
|
2010-11-17 20:44:57 -06:00
|
|
|
MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
|
2010-02-03 10:43:53 -06:00
|
|
|
;;
|
2011-06-02 22:35:18 -05:00
|
|
|
ext4|ext4dev)
|
2010-11-17 20:44:57 -06:00
|
|
|
MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
|
2010-02-03 10:43:53 -06:00
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
_notrun "can't mkfs $FSTYP with geometry"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
_scratch_mkfs
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-03 13:14:01 -08:00
|
|
|
# Create fs of certain blocksize on scratch device
|
|
|
|
|
# _scratch_mkfs_blocksized blocksize
|
|
|
|
|
_scratch_mkfs_blocksized()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local blocksize=$1
|
2016-02-03 13:14:01 -08:00
|
|
|
|
2018-04-06 19:35:29 -07:00
|
|
|
local re='^[0-9]+$'
|
2016-02-03 13:14:01 -08:00
|
|
|
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
|
|
|
|
|
;;
|
2016-11-09 15:00:17 -08:00
|
|
|
ext2|ext3|ext4)
|
2016-02-03 13:14:01 -08:00
|
|
|
${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
|
|
|
|
|
;;
|
2017-09-16 15:20:54 +02:00
|
|
|
gfs2)
|
2017-10-04 20:20:09 +02:00
|
|
|
${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV
|
2017-09-16 15:20:54 +02:00
|
|
|
;;
|
2016-11-09 15:00:17 -08:00
|
|
|
ocfs2)
|
2017-01-04 17:04:55 -08:00
|
|
|
yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize -C $blocksize $SCRATCH_DEV
|
2016-11-09 15:00:17 -08:00
|
|
|
;;
|
2016-02-03 13:14:01 -08:00
|
|
|
*)
|
|
|
|
|
_notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-06 11:25:10 +11:00
|
|
|
_scratch_resvblks()
|
|
|
|
|
{
|
|
|
|
|
case $FSTYP in
|
|
|
|
|
xfs)
|
|
|
|
|
xfs_io -x -c "resblks $1" $SCRATCH_MNT
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-20 00:47:43 +00:00
|
|
|
|
2016-02-09 13:59:13 -08:00
|
|
|
# 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
|
2018-04-06 19:35:29 -07:00
|
|
|
local res=$?
|
2016-09-14 10:52:36 +08:00
|
|
|
if [ "$res" -ne 0 ]; then
|
2016-02-09 13:59:13 -08:00
|
|
|
echo "xfs_repair returns $res; replay log?"
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount
|
2016-02-09 13:59:13 -08:00
|
|
|
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
|
2017-03-03 12:26:15 +04:00
|
|
|
if [ $res -ne 0 ]; then
|
|
|
|
|
_dump_err2 "xfs_repair failed, err=$res"
|
|
|
|
|
fi
|
2016-02-09 13:59:13 -08:00
|
|
|
return $res
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
# Let's hope fsck -y suffices...
|
|
|
|
|
fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
|
2018-04-06 19:35:29 -07:00
|
|
|
local res=$?
|
2016-02-09 13:59:13 -08:00
|
|
|
case $res in
|
|
|
|
|
0|1|2)
|
|
|
|
|
res=0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2017-03-03 12:26:15 +04:00
|
|
|
_dump_err2 "fsck.$FSTYP failed, err=$res"
|
2016-02-09 13:59:13 -08:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
return $res
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-15 05:01:19 +00:00
|
|
|
_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"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#
|
2005-07-11 14:57:36 +00:00
|
|
|
# _df_device : get an IRIX style df line for a given device
|
2001-01-15 05:01:19 +00:00
|
|
|
#
|
|
|
|
|
# - 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
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2014-11-10 18:06:23 +11:00
|
|
|
# Note that we use "==" here so awk doesn't try to interpret an NFS over
|
|
|
|
|
# IPv6 server as a regular expression.
|
2004-06-15 07:32:36 +00:00
|
|
|
$DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
|
2014-11-10 18:06:23 +11:00
|
|
|
($1==what) && (NF==1) {
|
2001-01-15 05:01:19 +00:00
|
|
|
v=$1
|
|
|
|
|
getline
|
|
|
|
|
print v, $0
|
|
|
|
|
exit
|
|
|
|
|
}
|
2014-11-10 18:06:23 +11:00
|
|
|
($1==what) {
|
2001-01-15 05:01:19 +00:00
|
|
|
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
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
$DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
|
2005-07-11 14:57:36 +00:00
|
|
|
NR == 2 && NF==1 {
|
2001-01-15 05:01:19 +00:00
|
|
|
v=$1
|
2005-07-11 14:57:36 +00:00
|
|
|
getline
|
2001-01-15 05:01:19 +00:00
|
|
|
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
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2001-01-15 05:01:19 +00:00
|
|
|
_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
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2011-08-02 12:20:43 +02:00
|
|
|
#
|
|
|
|
|
# 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.
|
|
|
|
|
#
|
2017-03-16 13:28:19 +08:00
|
|
|
_df_device $1 | $AWK_PROG '{ print $2 }' | \
|
|
|
|
|
sed -e 's/nfs4/nfs/' -e 's/fuse.glusterfs/glusterfs/'
|
2001-01-15 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# return the FS mount options of a mounted device
|
|
|
|
|
#
|
2004-06-15 07:32:36 +00:00
|
|
|
# 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
|
|
|
|
|
#
|
2001-01-15 05:01:19 +00:00
|
|
|
_fs_options()
|
|
|
|
|
{
|
|
|
|
|
if [ $# -ne 1 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Usage: _fs_options device" 1>&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2001-01-15 05:01:19 +00:00
|
|
|
$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
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2018-04-06 19:35:30 -07:00
|
|
|
local dev=$1
|
|
|
|
|
if [ -L "$dev" ]; then
|
|
|
|
|
dev=`readlink -f "$dev"`
|
2011-05-04 16:28:32 +02:00
|
|
|
fi
|
|
|
|
|
|
2018-04-06 19:35:30 -07:00
|
|
|
if [ -b "$dev" ]; then
|
|
|
|
|
src/lstat64 "$dev" | $AWK_PROG '/Device type:/ { print $9 }'
|
2011-05-04 16:28:32 +02:00
|
|
|
fi
|
2001-01-15 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
2017-06-07 10:20:44 +02:00
|
|
|
# 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
|
|
|
|
|
|
2018-04-06 19:35:30 -07:00
|
|
|
local dev=$1
|
|
|
|
|
if [ -L "$dev" ]; then
|
|
|
|
|
dev=`readlink -f "$dev"`
|
2017-06-07 10:20:44 +02:00
|
|
|
fi
|
|
|
|
|
|
2018-04-06 19:35:30 -07:00
|
|
|
if [ -c "$dev" ]; then
|
|
|
|
|
src/lstat64 "$dev" | $AWK_PROG '/Device type:/ { print $9 }'
|
2017-06-07 10:20:44 +02:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-15 12:28:06 +00:00
|
|
|
# Do a command, log it to $seqres.full, optionally test return status
|
2001-04-04 01:45:38 +00:00
|
|
|
# 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
|
2013-03-15 12:28:06 +00:00
|
|
|
# $seqres.out and exit.
|
2001-04-04 01:45:38 +00:00
|
|
|
|
2001-04-02 00:41:31 +00:00
|
|
|
_do()
|
|
|
|
|
{
|
2004-06-15 07:32:36 +00:00
|
|
|
if [ $# -eq 1 ]; then
|
2018-04-06 19:35:30 -07:00
|
|
|
local cmd=$1
|
2004-06-15 07:32:36 +00:00
|
|
|
elif [ $# -eq 2 ]; then
|
2018-04-06 19:35:30 -07:00
|
|
|
local note=$1
|
|
|
|
|
local cmd=$2
|
|
|
|
|
echo -n "$note... "
|
2001-04-04 01:45:38 +00:00
|
|
|
else
|
2004-06-15 07:32:36 +00:00
|
|
|
echo "Usage: _do [note] cmd" 1>&2
|
|
|
|
|
status=1; exit
|
2001-04-04 01:45:38 +00:00
|
|
|
fi
|
2001-04-02 00:41:31 +00:00
|
|
|
|
2018-04-06 19:35:30 -07:00
|
|
|
(eval "echo '---' \"$cmd\"") >>$seqres.full
|
|
|
|
|
(eval "$cmd") >$tmp._out 2>&1
|
2018-04-06 19:35:29 -07:00
|
|
|
local ret=$?
|
2018-05-07 08:45:31 +10:00
|
|
|
cat $tmp._out >>$seqres.full
|
2017-01-11 17:38:45 +08:00
|
|
|
rm -f $tmp._out
|
2004-06-15 07:32:36 +00:00
|
|
|
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
|
2018-04-06 19:35:30 -07:00
|
|
|
eval "echo \"$cmd\" failed \(returned $ret\): see $seqres.full"
|
2004-06-15 07:32:36 +00:00
|
|
|
status=1; exit
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return $ret
|
2001-04-02 00:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-08 20:48:45 +10:00
|
|
|
# bail out, setting up .notrun file. Need to kill the filesystem check files
|
|
|
|
|
# here, otherwise they are set incorrectly for the next test.
|
2005-07-11 14:57:36 +00:00
|
|
|
#
|
2001-01-15 05:01:19 +00:00
|
|
|
_notrun()
|
|
|
|
|
{
|
2013-03-15 12:28:06 +00:00
|
|
|
echo "$*" > $seqres.notrun
|
2001-01-31 07:08:16 +00:00
|
|
|
echo "$seq not run: $*"
|
2016-12-09 09:19:59 +08:00
|
|
|
rm -f ${RESULT_DIR}/require_test*
|
|
|
|
|
rm -f ${RESULT_DIR}/require_scratch*
|
|
|
|
|
|
2001-01-15 05:01:19 +00:00
|
|
|
status=0
|
|
|
|
|
exit
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# just plain bail out
|
2005-07-11 14:57:36 +00:00
|
|
|
#
|
2001-01-15 05:01:19 +00:00
|
|
|
_fail()
|
|
|
|
|
{
|
2013-03-15 12:28:06 +00:00
|
|
|
echo "$*" | tee -a $seqres.full
|
|
|
|
|
echo "(see $seqres.full for details)"
|
2001-01-15 05:01:19 +00:00
|
|
|
status=1
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
# tests whether $FSTYP is one of the supported filesystems for a test
|
|
|
|
|
#
|
|
|
|
|
_supported_fs()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local f
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
for f
|
|
|
|
|
do
|
2009-05-28 11:37:38 -05:00
|
|
|
if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
|
2004-06-15 07:32:36 +00:00
|
|
|
then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
_notrun "not suitable for this filesystem type: $FSTYP"
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-04 17:18:15 +11:00
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
# tests whether $FSTYP is one of the supported OSes for a test
|
|
|
|
|
#
|
|
|
|
|
_supported_os()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local h
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
for h
|
|
|
|
|
do
|
|
|
|
|
if [ "$h" = "$HOSTOS" ]
|
|
|
|
|
then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
_notrun "not suitable for this OS: $HOSTOS"
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 14:18:28 +02:00
|
|
|
# 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
|
|
|
|
|
|
2017-03-10 12:26:34 +08:00
|
|
|
# find $dev as the source, and print result in "$dev $mnt" format
|
2017-03-13 13:07:26 -05:00
|
|
|
local mount_rec=`findmnt -rncv -S $dev -o SOURCE,TARGET`
|
2017-02-28 14:18:28 +02:00
|
|
|
[ -n "$mount_rec" ] || return 1 # 1 = not mounted
|
|
|
|
|
|
|
|
|
|
# if it's mounted, make sure its on $mnt
|
2017-03-10 12:26:34 +08:00
|
|
|
if [ "$mount_rec" != "$dev $mnt" ]; then
|
2017-02-28 14:18:28 +02:00
|
|
|
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
|
|
|
|
|
|
2017-03-10 12:26:34 +08:00
|
|
|
if [ -n "$type" -a "`_fs_type $dev`" != "$type" ]; then
|
2017-02-28 14:18:28 +02:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-15 05:01:19 +00:00
|
|
|
# this test needs a scratch partition - check we're ok & unmount it
|
2014-09-08 20:48:45 +10:00
|
|
|
# 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()
|
2001-01-15 05:01:19 +00:00
|
|
|
{
|
2004-06-15 07:32:36 +00:00
|
|
|
case "$FSTYP" in
|
2017-03-16 13:28:19 +08:00
|
|
|
glusterfs)
|
2017-03-22 14:46:28 +08:00
|
|
|
echo $SCRATCH_DEV | egrep -q ":/?" > /dev/null 2>&1
|
2017-03-16 13:28:19 +08:00
|
|
|
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
|
|
|
|
|
;;
|
2018-01-11 16:05:43 +02:00
|
|
|
9p)
|
|
|
|
|
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
|
|
|
|
|
;;
|
2016-11-04 11:04:39 +01:00
|
|
|
nfs*|ceph)
|
2014-11-10 18:06:23 +11:00
|
|
|
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
|
|
|
|
|
;;
|
2017-04-07 16:09:43 -04:00
|
|
|
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
|
|
|
|
|
;;
|
2014-09-08 22:26:52 +10:00
|
|
|
cifs)
|
2014-12-12 10:53:55 +11:00
|
|
|
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
|
2014-09-08 22:26:52 +10:00
|
|
|
;;
|
2015-12-21 18:07:47 +11:00
|
|
|
overlay)
|
2017-02-28 14:18:35 +02:00
|
|
|
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"
|
2015-12-21 18:07:47 +11:00
|
|
|
fi
|
2017-02-28 14:18:35 +02:00
|
|
|
# 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
|
2015-12-21 18:07:47 +11:00
|
|
|
_notrun "this test requires a valid \$SCRATCH_MNT"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
2013-12-10 20:11:52 +00:00
|
|
|
tmpfs)
|
|
|
|
|
if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
|
|
|
|
|
then
|
|
|
|
|
_notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
2017-06-07 10:20:45 +02:00
|
|
|
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
|
|
|
|
|
;;
|
2009-06-20 19:05:45 +02:00
|
|
|
*)
|
2015-05-14 20:27:54 +10:00
|
|
|
if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
|
2004-06-15 07:32:36 +00:00
|
|
|
then
|
|
|
|
|
_notrun "this test requires a valid \$SCRATCH_DEV"
|
|
|
|
|
fi
|
2015-05-14 20:27:54 +10:00
|
|
|
if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
|
2004-06-15 07:32:36 +00:00
|
|
|
then
|
|
|
|
|
_notrun "this test requires a valid \$SCRATCH_DEV"
|
|
|
|
|
fi
|
2010-07-21 18:50:52 +02:00
|
|
|
if [ ! -d "$SCRATCH_MNT" ]
|
|
|
|
|
then
|
|
|
|
|
_notrun "this test requires a valid \$SCRATCH_MNT"
|
|
|
|
|
fi
|
2004-06-15 07:32:36 +00:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2017-02-28 14:18:28 +02:00
|
|
|
_check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
|
|
|
|
|
local err=$?
|
|
|
|
|
[ $err -le 1 ] || exit 1
|
|
|
|
|
if [ $err -eq 0 ]
|
2005-07-11 14:57:36 +00:00
|
|
|
then
|
2017-02-28 14:18:28 +02:00
|
|
|
# if it's mounted, unmount it
|
2015-12-21 18:07:43 +11:00
|
|
|
if ! _scratch_unmount
|
2001-01-15 05:01:19 +00:00
|
|
|
then
|
|
|
|
|
echo "failed to unmount $SCRATCH_DEV"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2014-09-08 20:48:45 +10:00
|
|
|
rm -f ${RESULT_DIR}/require_scratch
|
2001-01-15 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-08 20:48:45 +10:00
|
|
|
# we need the scratch device and it should be checked post test.
|
|
|
|
|
_require_scratch()
|
|
|
|
|
{
|
|
|
|
|
_require_scratch_nocheck
|
|
|
|
|
touch ${RESULT_DIR}/require_scratch
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 08:04:44 -04:00
|
|
|
# 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"
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-08 20:48:45 +10:00
|
|
|
|
2014-12-12 11:26:45 +11:00
|
|
|
# this test needs a test partition - check we're ok & mount it
|
2014-08-13 11:08:41 +10:00
|
|
|
#
|
|
|
|
|
_require_test()
|
|
|
|
|
{
|
|
|
|
|
case "$FSTYP" in
|
2017-03-16 13:28:19 +08:00
|
|
|
glusterfs)
|
2017-03-22 14:46:28 +08:00
|
|
|
echo $TEST_DEV | egrep -q ":/?" > /dev/null 2>&1
|
2017-03-16 13:28:19 +08:00
|
|
|
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
|
|
|
|
|
;;
|
2018-01-11 16:05:43 +02:00
|
|
|
9p)
|
|
|
|
|
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
|
|
|
|
|
;;
|
2016-11-04 11:04:39 +01:00
|
|
|
nfs*|ceph)
|
2014-10-14 22:59:38 +11:00
|
|
|
echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
|
|
|
|
|
if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
|
2016-11-04 11:04:39 +01:00
|
|
|
_notrun "this test requires a valid \$TEST_DEV"
|
2014-10-14 22:59:38 +11:00
|
|
|
fi
|
|
|
|
|
if [ ! -d "$TEST_DIR" ]; then
|
|
|
|
|
_notrun "this test requires a valid \$TEST_DIR"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
2014-09-08 22:26:52 +10:00
|
|
|
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
|
|
|
|
|
;;
|
2017-04-07 16:09:43 -04:00
|
|
|
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
|
|
|
|
|
;;
|
2015-12-21 18:07:47 +11:00
|
|
|
overlay)
|
2017-02-28 14:18:35 +02:00
|
|
|
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"
|
2015-12-21 18:07:47 +11:00
|
|
|
fi
|
|
|
|
|
if [ ! -d "$TEST_DIR" ]; then
|
|
|
|
|
_notrun "this test requires a valid \$TEST_DIR"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
2014-08-13 11:08:41 +10:00
|
|
|
tmpfs)
|
|
|
|
|
if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
|
|
|
|
|
then
|
|
|
|
|
_notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
2017-06-07 10:20:45 +02:00
|
|
|
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
|
|
|
|
|
;;
|
2014-08-13 11:08:41 +10:00
|
|
|
*)
|
2015-05-14 20:27:54 +10:00
|
|
|
if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
|
2014-08-13 11:08:41 +10:00
|
|
|
then
|
|
|
|
|
_notrun "this test requires a valid \$TEST_DEV"
|
|
|
|
|
fi
|
2015-05-14 20:27:54 +10:00
|
|
|
if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
|
2014-08-13 11:08:41 +10:00
|
|
|
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
|
|
|
|
|
|
2017-02-28 14:18:28 +02:00
|
|
|
_check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR
|
|
|
|
|
local err=$?
|
|
|
|
|
[ $err -le 1 ] || exit 1
|
|
|
|
|
if [ $err -ne 0 ]
|
2014-08-13 11:08:41 +10:00
|
|
|
then
|
2017-02-28 14:18:29 +02:00
|
|
|
if ! _test_mount
|
|
|
|
|
then
|
|
|
|
|
echo "!!! failed to mount $TEST_DEV on $TEST_DIR"
|
2014-08-13 11:08:41 +10:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
touch ${RESULT_DIR}/require_test
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-17 14:10:13 -04:00
|
|
|
_has_logdev()
|
|
|
|
|
{
|
|
|
|
|
local ret=0
|
|
|
|
|
[ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && ret=1
|
|
|
|
|
[ "$USE_EXTERNAL" != yes ] && ret=1
|
|
|
|
|
|
|
|
|
|
return $ret
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 14:57:36 +00:00
|
|
|
# this test needs a logdev
|
|
|
|
|
#
|
2001-01-15 05:01:19 +00:00
|
|
|
_require_logdev()
|
|
|
|
|
{
|
2003-05-22 04:16:45 +00:00
|
|
|
[ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
|
2005-07-11 14:57:36 +00:00
|
|
|
_notrun "This test requires a valid \$SCRATCH_LOGDEV"
|
2003-05-22 04:16:45 +00:00
|
|
|
[ "$USE_EXTERNAL" != yes ] && \
|
|
|
|
|
_notrun "This test requires USE_EXTERNAL to be enabled"
|
|
|
|
|
|
2002-05-06 07:44:22 +00:00
|
|
|
# ensure its not mounted
|
2004-06-15 07:32:36 +00:00
|
|
|
$UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
|
2001-01-15 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# this test requires loopback device support
|
2005-07-11 14:57:36 +00:00
|
|
|
#
|
2001-01-15 05:01:19 +00:00
|
|
|
_require_loop()
|
|
|
|
|
{
|
2004-06-15 07:32:36 +00:00
|
|
|
if [ "$HOSTOS" != "Linux" ]
|
|
|
|
|
then
|
|
|
|
|
_notrun "This test requires linux for loopback device support"
|
|
|
|
|
fi
|
|
|
|
|
|
2002-06-05 02:24:23 +00:00
|
|
|
modprobe loop >/dev/null 2>&1
|
2001-01-15 05:01:19 +00:00
|
|
|
if grep loop /proc/devices >/dev/null 2>&1
|
|
|
|
|
then
|
|
|
|
|
:
|
|
|
|
|
else
|
|
|
|
|
_notrun "This test requires loopback device support"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-10 16:03:41 -05:00
|
|
|
# this test requires ext2 filesystem support
|
|
|
|
|
#
|
|
|
|
|
_require_ext2()
|
|
|
|
|
{
|
|
|
|
|
if [ "$HOSTOS" != "Linux" ]
|
|
|
|
|
then
|
|
|
|
|
_notrun "This test requires linux for ext2 filesystem support"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-23 17:42:42 +08:00
|
|
|
# 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"
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-29 06:04:54 +00:00
|
|
|
# this test requires that (large) loopback device files are not in use
|
2005-07-11 14:57:36 +00:00
|
|
|
#
|
2013-03-15 11:53:21 +00:00
|
|
|
_require_no_large_scratch_dev()
|
2003-08-29 06:04:54 +00:00
|
|
|
{
|
2013-03-15 11:53:21 +00:00
|
|
|
[ "$LARGE_SCRATCH_DEV" = yes ] && \
|
2003-08-29 06:04:54 +00:00
|
|
|
_notrun "Large filesystem testing in progress, skipped this test"
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-09 04:16:16 +00:00
|
|
|
# this test requires that a realtime subvolume is in use, and
|
|
|
|
|
# that the kernel supports realtime as well.
|
2005-07-11 14:57:36 +00:00
|
|
|
#
|
2004-07-09 04:16:16 +00:00
|
|
|
_require_realtime()
|
|
|
|
|
{
|
|
|
|
|
[ "$USE_EXTERNAL" = yes ] || \
|
|
|
|
|
_notrun "External volumes not in use, skipped this test"
|
|
|
|
|
[ "$SCRATCH_RTDEV" = "" ] && \
|
|
|
|
|
_notrun "Realtime device required, skipped this test"
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 20:16:17 -08:00
|
|
|
# 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"
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-23 14:34:25 +00:00
|
|
|
# this test requires that a specified command (executable) exists
|
2010-09-09 19:02:17 +02:00
|
|
|
# $1 - command, $2 - name for error message
|
2005-07-11 14:57:36 +00:00
|
|
|
#
|
2015-05-04 16:48:05 +10:00
|
|
|
# Note: the command string might have parameters, so strip them before checking
|
|
|
|
|
# whether it is executable.
|
2004-09-23 14:34:25 +00:00
|
|
|
_require_command()
|
2004-08-20 06:44:08 +00:00
|
|
|
{
|
2015-05-04 16:48:05 +10:00
|
|
|
if [ $# -eq 2 ]; then
|
2018-04-06 19:35:30 -07:00
|
|
|
local name="$2"
|
2015-05-04 16:48:05 +10:00
|
|
|
elif [ $# -eq 1 ]; then
|
2018-04-06 19:35:30 -07:00
|
|
|
local name="$1"
|
2015-05-04 16:48:05 +10:00
|
|
|
else
|
|
|
|
|
_fail "usage: _require_command <command> [<name>]"
|
|
|
|
|
fi
|
|
|
|
|
|
2018-04-06 19:35:30 -07:00
|
|
|
local command=`echo "$1" | awk '{ print $1 }'`
|
|
|
|
|
if [ ! -x "$command" ]; then
|
|
|
|
|
_notrun "$name utility required, skipped this test"
|
2015-05-04 16:48:05 +10:00
|
|
|
fi
|
2004-08-20 06:44:08 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-10 18:06:23 +11:00
|
|
|
# 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
|
2015-03-18 14:55:58 +11:00
|
|
|
if [ "`_is_block_dev "$1"`" == "" ]; then
|
2014-11-10 18:06:23 +11:00
|
|
|
_notrun "require $1 to be valid block disk"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-07 10:20:44 +02:00
|
|
|
# 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"
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-04 16:47:52 +10:00
|
|
|
# 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
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 14:08:42 +11:00
|
|
|
# this test requires a specific device mapper target
|
|
|
|
|
_require_dm_target()
|
2013-04-26 19:13:59 +00:00
|
|
|
{
|
2018-04-06 19:35:30 -07:00
|
|
|
local target=$1
|
2015-10-14 14:08:42 +11:00
|
|
|
|
2015-05-04 16:47:52 +10:00
|
|
|
# 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
|
2013-04-26 19:13:59 +00:00
|
|
|
|
2018-04-06 19:35:30 -07:00
|
|
|
modprobe dm-$target >/dev/null 2>&1
|
2013-04-26 19:13:59 +00:00
|
|
|
|
2018-04-06 19:35:30 -07:00
|
|
|
$DMSETUP_PROG targets 2>&1 | grep -q ^$target
|
2015-04-02 09:41:15 +11:00
|
|
|
if [ $? -ne 0 ]; then
|
2018-04-06 19:35:30 -07:00
|
|
|
_notrun "This test requires dm $target support"
|
2015-04-02 09:41:15 +11:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 12:09:16 +10:00
|
|
|
# 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"
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount >/dev/null 2>&1 \
|
2015-09-21 12:09:16 +10:00
|
|
|
|| _notrun "Kernel doesn't support metadata_csum feature"
|
2015-12-21 18:07:43 +11:00
|
|
|
_scratch_unmount
|
2015-09-21 12:50:22 +10:00
|
|
|
}
|
|
|
|
|
|
2017-12-11 17:49:19 -05:00
|
|
|
# Check whether the specified feature whether it is supported by
|
|
|
|
|
# mkfs.ext4 and the kernel.
|
|
|
|
|
_require_scratch_ext4_feature()
|
2014-08-13 11:15:15 +10:00
|
|
|
{
|
2017-12-11 17:49:19 -05:00
|
|
|
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"
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount >/dev/null 2>&1 \
|
2017-12-11 17:49:19 -05:00
|
|
|
|| _notrun "Kernel doesn't support the ext4 feature(s): $1"
|
|
|
|
|
_scratch_unmount
|
2014-08-13 11:15:15 +10:00
|
|
|
}
|
|
|
|
|
|
2003-08-29 06:04:54 +00:00
|
|
|
# this test requires that external log/realtime devices are not in use
|
2005-07-11 14:57:36 +00:00
|
|
|
#
|
2003-08-29 06:04:54 +00:00
|
|
|
_require_nonexternal()
|
|
|
|
|
{
|
|
|
|
|
[ "$USE_EXTERNAL" = yes ] && \
|
|
|
|
|
_notrun "External device testing in progress, skipped this test"
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-18 15:49:10 -07:00
|
|
|
# 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
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-23 11:39:08 +09:00
|
|
|
# this test requires that a (specified) aio-dio executable exists
|
2017-05-18 15:49:10 -07:00
|
|
|
# and that the kernel supports asynchronous I/O.
|
2011-11-23 11:39:08 +09:00
|
|
|
# $1 - command (optional)
|
|
|
|
|
#
|
|
|
|
|
_require_aiodio()
|
|
|
|
|
{
|
|
|
|
|
if [ -z "$1" ]
|
|
|
|
|
then
|
|
|
|
|
AIO_TEST=src/aio-dio-regress/aiodio_sparse2
|
|
|
|
|
[ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
|
|
|
|
|
else
|
|
|
|
|
AIO_TEST=src/aio-dio-regress/$1
|
|
|
|
|
[ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
|
|
|
|
|
fi
|
2017-05-18 15:49:10 -07:00
|
|
|
_require_aio
|
2014-12-16 14:01:06 +11:00
|
|
|
_require_odirect
|
2011-11-23 11:39:08 +09:00
|
|
|
}
|
|
|
|
|
|
2016-02-09 00:22:21 -08:00
|
|
|
# this test requires that a test program exists under src/
|
|
|
|
|
# $1 - command (require)
|
|
|
|
|
#
|
|
|
|
|
_require_test_program()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local prog=src/$1
|
|
|
|
|
[ -x $prog ] || _notrun "$prog not built"
|
2016-02-09 00:22:21 -08:00
|
|
|
}
|
|
|
|
|
|
2011-11-23 11:39:08 +09:00
|
|
|
# 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
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-03 19:51:11 -08:00
|
|
|
# this test requires y2038 sysfs switch and filesystem
|
|
|
|
|
# timestamp ranges support.
|
|
|
|
|
_require_y2038()
|
|
|
|
|
{
|
|
|
|
|
local device=${1:-$TEST_DEV}
|
|
|
|
|
local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
|
|
|
|
|
|
|
|
|
|
if [ ! -e $sysfsdir ]; then
|
|
|
|
|
_notrun "no kernel support for y2038 sysfs switch"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local tsmin tsmax
|
|
|
|
|
read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
|
|
|
|
|
if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
|
|
|
|
|
_notrun "filesystem $FSTYP timestamp bounds are unknown"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_filesystem_timestamp_range()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local device=${1:-$TEST_DEV}
|
2017-01-03 19:51:11 -08:00
|
|
|
case $FSTYP in
|
|
|
|
|
ext4)
|
|
|
|
|
if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | cut -d: -f2) -gt 128 ]; then
|
|
|
|
|
echo "-2147483648 15032385535"
|
|
|
|
|
else
|
|
|
|
|
echo "-2147483648 2147483647"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
xfs)
|
|
|
|
|
echo "-2147483648 2147483647"
|
|
|
|
|
;;
|
|
|
|
|
jfs)
|
|
|
|
|
echo "0 4294967295"
|
|
|
|
|
;;
|
|
|
|
|
f2fs)
|
|
|
|
|
echo "-2147483648 2147483647"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "-1 -1"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-30 21:52:39 +00:00
|
|
|
# indicate whether YP/NIS is active or not
|
|
|
|
|
#
|
|
|
|
|
_yp_active()
|
|
|
|
|
{
|
|
|
|
|
local dn
|
|
|
|
|
dn=$(domainname 2>/dev/null)
|
2018-03-29 11:27:25 -04:00
|
|
|
local ypcat=$(type -P ypcat)
|
|
|
|
|
test -n "${dn}" -a "${dn}" != "(none)" -a "${dn}" != "localdomain" -a -n "${ypcat}"
|
2010-08-13 15:45:24 +10:00
|
|
|
echo $?
|
2010-07-30 21:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# cat the password file
|
|
|
|
|
#
|
|
|
|
|
_cat_passwd()
|
|
|
|
|
{
|
2010-08-13 15:45:24 +10:00
|
|
|
[ $(_yp_active) -eq 0 ] && ypcat passwd
|
2010-07-30 21:52:39 +00:00
|
|
|
cat /etc/passwd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# cat the group file
|
|
|
|
|
#
|
|
|
|
|
_cat_group()
|
|
|
|
|
{
|
2010-08-13 15:45:24 +10:00
|
|
|
[ $(_yp_active) -eq 0 ] && ypcat group
|
2010-07-30 21:52:39 +00:00
|
|
|
cat /etc/group
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-21 18:07:37 +11:00
|
|
|
# check for a user on the machine, fsgqa as default
|
2006-08-04 13:44:58 +00:00
|
|
|
#
|
|
|
|
|
_require_user()
|
|
|
|
|
{
|
|
|
|
|
qa_user=fsgqa
|
2015-12-21 18:07:37 +11:00
|
|
|
if [ -n "$1" ];then
|
|
|
|
|
qa_user=$1
|
|
|
|
|
fi
|
2010-07-30 21:52:39 +00:00
|
|
|
_cat_passwd | grep -q $qa_user
|
2006-08-04 13:44:58 +00:00
|
|
|
[ "$?" == "0" ] || _notrun "$qa_user user not defined."
|
2011-12-06 10:56:29 +01:00
|
|
|
echo /bin/true | su $qa_user
|
|
|
|
|
[ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
|
2006-08-04 13:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-21 18:07:37 +11:00
|
|
|
# check for a group on the machine, fsgqa as default
|
2012-12-18 11:35:50 +01:00
|
|
|
#
|
|
|
|
|
_require_group()
|
|
|
|
|
{
|
|
|
|
|
qa_group=fsgqa
|
2015-12-21 18:07:37 +11:00
|
|
|
if [ -n "$1" ];then
|
|
|
|
|
qa_group=$1
|
|
|
|
|
fi
|
2012-12-18 11:35:50 +01:00
|
|
|
_cat_group | grep -q $qa_group
|
2017-06-02 17:50:46 +03:00
|
|
|
[ "$?" == "0" ] || _notrun "$qa_group group not defined."
|
2012-12-18 11:35:50 +01:00
|
|
|
}
|
|
|
|
|
|
2011-06-28 14:45:00 +00:00
|
|
|
_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()
|
|
|
|
|
{
|
2017-01-13 17:38:16 +01:00
|
|
|
echo $1 | su -s /bin/bash $qa_user 2>&1 | _filter_user_do
|
2011-06-28 14:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-13 15:18:56 +11:00
|
|
|
_require_xfs_io_command()
|
|
|
|
|
{
|
2016-02-19 10:51:25 +11:00
|
|
|
if [ -z "$1" ]
|
2014-03-13 15:18:56 +11:00
|
|
|
then
|
2016-02-19 10:51:25 +11:00
|
|
|
echo "Usage: _require_xfs_io_command command [switch]" 1>&2
|
2014-03-13 15:18:56 +11:00
|
|
|
exit 1
|
|
|
|
|
fi
|
2017-05-17 09:42:33 +08:00
|
|
|
local command=$1
|
2016-05-19 12:30:59 +08:00
|
|
|
shift
|
2017-05-17 09:42:33 +08:00
|
|
|
local param="$*"
|
|
|
|
|
local param_checked=0
|
2017-12-07 10:00:42 -06:00
|
|
|
local opts=""
|
2014-03-13 15:18:56 +11:00
|
|
|
|
2018-04-06 19:35:29 -07:00
|
|
|
local testfile=$TEST_DIR/$$.xfs_io
|
|
|
|
|
local testio
|
2014-03-13 15:18:56 +11:00
|
|
|
case $command in
|
2016-09-22 17:51:03 -05:00
|
|
|
"chproj")
|
|
|
|
|
testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1`
|
|
|
|
|
;;
|
2017-05-10 13:46:24 -04:00
|
|
|
"copy_range")
|
2018-04-06 19:35:29 -07:00
|
|
|
local testcopy=$TEST_DIR/$$.copy.xfs_io
|
2017-05-10 13:46:24 -04:00
|
|
|
$XFS_IO_PROG -F -f -c "pwrite 0 4k" $testfile > /dev/null 2>&1
|
|
|
|
|
testio=`$XFS_IO_PROG -F -f -c "copy_range $testfile" $testcopy 2>&1`
|
|
|
|
|
rm -f $testcopy > /dev/null 2>&1
|
|
|
|
|
;;
|
2014-03-13 15:18:56 +11:00
|
|
|
"falloc" )
|
2017-04-04 07:34:29 +01:00
|
|
|
testio=`$XFS_IO_PROG -F -f -c "falloc $param 0 1m" $testfile 2>&1`
|
2017-05-17 09:42:33 +08:00
|
|
|
param_checked=1
|
2014-03-13 15:18:56 +11:00
|
|
|
;;
|
2016-10-17 15:09:28 -07:00
|
|
|
"fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" | "funshare")
|
2018-02-22 11:28:55 +05:30
|
|
|
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`
|
2014-03-13 15:18:56 +11:00
|
|
|
;;
|
|
|
|
|
"fiemap")
|
2017-11-30 18:05:27 +02:00
|
|
|
# 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
|
2014-03-13 15:18:56 +11:00
|
|
|
testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
|
2017-04-06 09:01:30 -07:00
|
|
|
-c "fiemap -v $param" $testfile 2>&1`
|
2017-05-17 09:42:33 +08:00
|
|
|
param_checked=1
|
2014-03-13 15:18:56 +11:00
|
|
|
;;
|
2018-05-06 09:36:07 +03:00
|
|
|
"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`
|
2014-05-13 15:30:03 +10:00
|
|
|
echo $testio | egrep -q "invalid option|Is a directory" && \
|
|
|
|
|
_notrun "xfs_io $command support is missing"
|
2018-05-06 09:36:07 +03:00
|
|
|
echo $testio | grep -q "Operation not supported" && \
|
|
|
|
|
_notrun "O_TMPFILE is not supported"
|
2014-04-04 17:15:51 +11:00
|
|
|
;;
|
2018-05-06 09:36:07 +03:00
|
|
|
"fsmap")
|
2016-09-20 13:23:12 +08:00
|
|
|
testio=`$XFS_IO_PROG -f -c "fsmap" $testfile 2>&1`
|
2017-08-23 18:49:10 +03:00
|
|
|
echo $testio | grep -q "Inappropriate ioctl" && \
|
2016-08-25 16:29:24 -07:00
|
|
|
_notrun "xfs_io $command support is missing"
|
|
|
|
|
;;
|
2018-05-17 10:28:26 -05:00
|
|
|
"label")
|
|
|
|
|
testio=`$XFS_IO_PROG -c "label" $TEST_DIR 2>&1`
|
|
|
|
|
;;
|
2016-12-08 12:52:20 +02:00
|
|
|
"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`
|
2017-08-23 18:49:10 +03:00
|
|
|
echo $testio | grep -q "invalid option" && \
|
2016-12-08 12:52:20 +02:00
|
|
|
_notrun "xfs_io $command support is missing"
|
|
|
|
|
;;
|
2017-12-07 10:00:42 -06:00
|
|
|
"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=1
|
|
|
|
|
;;
|
2017-06-29 21:12:39 -07:00
|
|
|
"scrub"|"repair")
|
2018-06-04 12:50:12 +08:00
|
|
|
testio=`$XFS_IO_PROG -x -c "$command probe" $TEST_DIR 2>&1`
|
2017-08-23 18:49:10 +03:00
|
|
|
echo $testio | grep -q "Inappropriate ioctl" && \
|
2017-06-29 21:12:39 -07:00
|
|
|
_notrun "xfs_io $command support is missing"
|
|
|
|
|
;;
|
2017-01-03 19:51:11 -08:00
|
|
|
"utimes" )
|
|
|
|
|
testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
|
|
|
|
|
;;
|
2017-12-15 15:47:34 +08:00
|
|
|
"syncfs")
|
|
|
|
|
touch $testfile
|
|
|
|
|
testio=`$XFS_IO_PROG -c "syncfs" $testfile 2>&1`
|
|
|
|
|
;;
|
2014-03-13 15:18:56 +11:00
|
|
|
*)
|
2017-05-17 09:42:33 +08:00
|
|
|
testio=`$XFS_IO_PROG -c "help $command" 2>&1`
|
2014-03-13 15:18:56 +11:00
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
rm -f $testfile 2>&1 > /dev/null
|
|
|
|
|
echo $testio | grep -q "not found" && \
|
|
|
|
|
_notrun "xfs_io $command support is missing"
|
2018-05-17 10:28:26 -05:00
|
|
|
echo $testio | grep -q "Operation not supported\|Inappropriate ioctl" && \
|
2014-03-13 15:18:56 +11:00
|
|
|
_notrun "xfs_io $command failed (old kernel/wrong fs?)"
|
2017-04-06 09:01:30 -07:00
|
|
|
echo $testio | grep -q "Invalid" && \
|
|
|
|
|
_notrun "xfs_io $command failed (old kernel/wrong fs/bad args?)"
|
2016-09-22 17:51:03 -05:00
|
|
|
echo $testio | grep -q "foreign file active" && \
|
|
|
|
|
_notrun "xfs_io $command not supported on $FSTYP"
|
2017-08-23 18:49:10 +03:00
|
|
|
echo $testio | grep -q "Function not implemented" && \
|
2017-06-28 12:20:51 +01:00
|
|
|
_notrun "xfs_io $command support is missing (missing syscall?)"
|
2016-02-19 10:51:25 +11:00
|
|
|
|
2017-08-23 18:49:11 +03:00
|
|
|
[ -n "$param" ] || return
|
|
|
|
|
|
|
|
|
|
if [ $param_checked -eq 0 ]; then
|
2017-05-17 09:42:33 +08:00
|
|
|
$XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
|
|
|
|
|
_notrun "xfs_io $command doesn't support $param"
|
2017-08-23 18:49:11 +03:00
|
|
|
else
|
2017-12-07 10:00:42 -06:00
|
|
|
# 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\)" && \
|
2017-08-23 18:49:11 +03:00
|
|
|
_notrun "xfs_io $command doesn't support $param"
|
2017-05-17 09:42:33 +08:00
|
|
|
fi
|
2014-03-13 15:18:56 +11:00
|
|
|
}
|
|
|
|
|
|
2014-12-16 14:01:06 +11:00
|
|
|
# check that kernel and filesystem support direct I/O
|
|
|
|
|
_require_odirect()
|
|
|
|
|
{
|
2016-06-28 21:32:55 -04:00
|
|
|
if [ $FSTYP = "ext4" ] ; then
|
|
|
|
|
if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
|
|
|
|
|
_notrun "ext4 encryption doesn't support O_DIRECT"
|
2018-01-10 16:19:05 -05:00
|
|
|
elif echo "$MOUNT_OPTIONS" | grep -q "data=journal"; then
|
|
|
|
|
_notrun "ext4 data journaling doesn't support O_DIRECT"
|
2016-06-28 21:32:55 -04:00
|
|
|
fi
|
|
|
|
|
fi
|
2018-04-06 19:35:29 -07:00
|
|
|
local testfile=$TEST_DIR/$$.direct
|
2016-06-28 21:32:55 -04:00
|
|
|
$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
|
2014-12-16 14:01:06 +11:00
|
|
|
}
|
|
|
|
|
|
2018-05-22 16:33:57 -07:00
|
|
|
_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 "$fname" >> $seqres.full
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-05 17:01:28 -08:00
|
|
|
# Check that the filesystem supports swapfiles
|
|
|
|
|
_require_scratch_swapfile()
|
|
|
|
|
{
|
|
|
|
|
_require_scratch
|
|
|
|
|
|
|
|
|
|
_scratch_mkfs >/dev/null
|
|
|
|
|
_scratch_mount
|
|
|
|
|
|
|
|
|
|
# Minimum size for mkswap is 10 pages
|
2018-05-22 16:33:57 -07:00
|
|
|
_format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
|
2016-12-05 17:01:28 -08:00
|
|
|
|
|
|
|
|
if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
|
|
|
|
|
_scratch_unmount
|
|
|
|
|
_notrun "swapfiles are not supported"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
|
|
|
|
|
_scratch_unmount
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-02 17:23:58 -06:00
|
|
|
# Check that a fs has enough free space (in 1024b blocks)
|
|
|
|
|
#
|
|
|
|
|
_require_fs_space()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local mnt=$1
|
|
|
|
|
local blocks=$2 # in units of 1024
|
|
|
|
|
local gb=$(( blocks / 1024 / 1024 ))
|
2010-02-02 17:23:58 -06:00
|
|
|
|
2018-04-06 19:35:29 -07:00
|
|
|
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"
|
2010-02-02 17:23:58 -06:00
|
|
|
}
|
|
|
|
|
|
2010-11-09 14:53:36 +01:00
|
|
|
#
|
|
|
|
|
# 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)
|
|
|
|
|
_notrun "Sparse files not supported by this filesystem type: $FSTYP"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 10:42:15 +00:00
|
|
|
_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_FAIL_MAKE_REQUEST kernel config option not enabled"
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-24 18:44:31 +08:00
|
|
|
# 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
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-14 13:25:44 -05:00
|
|
|
# Check if the file system supports seek_data/hole
|
|
|
|
|
_require_seek_data_hole()
|
|
|
|
|
{
|
2017-07-24 18:44:31 +08:00
|
|
|
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
|
2013-05-14 13:25:44 -05:00
|
|
|
}
|
|
|
|
|
|
2016-06-28 00:40:21 +02:00
|
|
|
_require_runas()
|
|
|
|
|
{
|
|
|
|
|
_require_test_program "runas"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_runas()
|
|
|
|
|
{
|
|
|
|
|
"$here/src/runas" "$@"
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 14:47:26 +02:00
|
|
|
_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
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount >/dev/null 2>&1 \
|
2016-06-28 14:47:26 +02:00
|
|
|
|| _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"
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount >/dev/null 2>&1 \
|
2016-06-28 14:47:26 +02:00
|
|
|
|| _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
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 20:13:43 +08:00
|
|
|
# check if the given device is mounted, if so, return mount point
|
|
|
|
|
_is_dev_mounted()
|
2001-01-15 05:01:19 +00:00
|
|
|
{
|
2018-03-01 20:13:43 +08:00
|
|
|
local dev=$1
|
|
|
|
|
local fstype=${2:-$FSTYP}
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2018-03-01 20:13:43 +08:00
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
|
echo "Usage: _is_dev_mounted <device> [fstype]" 1>&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2018-03-01 20:13:43 +08:00
|
|
|
findmnt -rncv -S $dev -t $fstype -o TARGET | head -1
|
2001-01-15 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
2018-03-01 20:13:44 +08:00
|
|
|
# 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
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-15 05:01:19 +00:00
|
|
|
# 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
|
2018-04-06 19:35:29 -07:00
|
|
|
local device=$1
|
|
|
|
|
local mode=$2
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2001-01-15 05:01:19 +00:00
|
|
|
if ! mount -o remount,$mode $device
|
|
|
|
|
then
|
|
|
|
|
echo "_remount: failed to remount filesystem on $device as $mode"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-02 22:42:21 +02:00
|
|
|
# Run the appropriate repair/check on a filesystem
|
2001-01-15 05:01:19 +00:00
|
|
|
#
|
|
|
|
|
# if the filesystem is mounted, it's either remounted ro before being
|
|
|
|
|
# checked or it's unmounted and then remounted
|
|
|
|
|
#
|
|
|
|
|
|
2009-06-02 22:42:21 +02:00
|
|
|
# If set, we remount ro instead of unmounting for fsck
|
2001-01-15 05:01:19 +00:00
|
|
|
USE_REMOUNT=0
|
|
|
|
|
|
2009-06-02 22:42:21 +02:00
|
|
|
_umount_or_remount_ro()
|
|
|
|
|
{
|
|
|
|
|
if [ $# -ne 1 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Usage: _umount_or_remount_ro <device>" 1>&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2018-04-06 19:35:29 -07:00
|
|
|
local device=$1
|
|
|
|
|
local mountpoint=`_is_dev_mounted $device`
|
2009-06-02 22:42:21 +02:00
|
|
|
|
|
|
|
|
if [ $USE_REMOUNT -eq 0 ]; then
|
|
|
|
|
$UMOUNT_PROG $device
|
|
|
|
|
else
|
|
|
|
|
_remount $device ro
|
|
|
|
|
fi
|
|
|
|
|
echo "$mountpoint"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_mount_or_remount_rw()
|
|
|
|
|
{
|
2015-12-21 18:07:47 +11:00
|
|
|
if [ $# -ne 3 ]; then
|
|
|
|
|
echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2018-04-06 19:35:29 -07:00
|
|
|
local mount_opts=$1
|
|
|
|
|
local device=$2
|
|
|
|
|
local mountpoint=$3
|
2009-06-02 22:42:21 +02:00
|
|
|
|
2015-12-21 18:07:47 +11:00
|
|
|
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
|
2017-03-03 12:26:15 +04:00
|
|
|
_dump_err "!!! failed to remount $device on $mountpoint"
|
2015-12-21 18:07:47 +11:00
|
|
|
return 0 # ok=0
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
_remount $device rw
|
|
|
|
|
fi
|
2009-06-02 22:42:21 +02:00
|
|
|
|
2015-12-21 18:07:47 +11:00
|
|
|
return 1 # ok=1
|
2009-06-02 22:42:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local device=$1
|
2009-06-02 22:42:21 +02:00
|
|
|
|
|
|
|
|
# If type is set, we're mounted
|
2018-04-06 19:35:29 -07:00
|
|
|
local type=`_fs_type $device`
|
|
|
|
|
local ok=1
|
2009-06-02 22:42:21 +02:00
|
|
|
|
|
|
|
|
if [ "$type" = "$FSTYP" ]
|
|
|
|
|
then
|
|
|
|
|
# mounted ...
|
2018-04-06 19:35:29 -07:00
|
|
|
local mountpoint=`_umount_or_remount_ro $device`
|
2009-06-02 22:42:21 +02:00
|
|
|
fi
|
|
|
|
|
|
2009-09-16 09:55:59 -03:00
|
|
|
fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
|
2009-06-02 22:42:21 +02:00
|
|
|
if [ $? -ne 0 ]
|
|
|
|
|
then
|
2017-03-03 12:26:15 +04:00
|
|
|
_log_err "_check_generic_filesystem: filesystem on $device is inconsistent"
|
2013-03-15 12:28:06 +00:00
|
|
|
echo "*** fsck.$FSTYP output ***" >>$seqres.full
|
|
|
|
|
cat $tmp.fsck >>$seqres.full
|
|
|
|
|
echo "*** end fsck.$FSTYP output" >>$seqres.full
|
2009-06-02 22:42:21 +02:00
|
|
|
|
|
|
|
|
ok=0
|
|
|
|
|
fi
|
|
|
|
|
rm -f $tmp.fsck
|
|
|
|
|
|
|
|
|
|
if [ $ok -eq 0 ]
|
|
|
|
|
then
|
2013-03-15 12:28:06 +00:00
|
|
|
echo "*** mount output ***" >>$seqres.full
|
|
|
|
|
_mount >>$seqres.full
|
|
|
|
|
echo "*** end mount output" >>$seqres.full
|
2009-06-02 22:42:21 +02:00
|
|
|
elif [ "$type" = "$FSTYP" ]
|
|
|
|
|
then
|
|
|
|
|
# was mounted ...
|
|
|
|
|
_mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
|
|
|
|
|
ok=$?
|
|
|
|
|
fi
|
|
|
|
|
|
2010-03-31 22:01:11 -05:00
|
|
|
if [ $ok -eq 0 ]; then
|
|
|
|
|
status=1
|
2014-12-24 14:51:04 +11:00
|
|
|
if [ "$iam" != "check" ]; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2014-12-24 14:51:25 +11:00
|
|
|
return 1
|
2010-03-31 22:01:11 -05:00
|
|
|
fi
|
|
|
|
|
|
2009-06-02 22:42:21 +02:00
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 14:57:36 +00:00
|
|
|
# Filter the knowen errors the UDF Verifier reports.
|
|
|
|
|
_udf_test_known_error_filter()
|
2004-09-15 05:57:50 +00:00
|
|
|
{
|
|
|
|
|
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."
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
_check_udf_filesystem()
|
|
|
|
|
{
|
2004-07-28 08:12:22 +00:00
|
|
|
[ "$DISABLE_UDF_TEST" == "1" ] && return
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
if [ $# -ne 1 -a $# -ne 2 ]
|
|
|
|
|
then
|
2004-09-15 05:57:50 +00:00
|
|
|
echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
|
2004-06-15 07:32:36 +00:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2004-07-28 08:12:22 +00:00
|
|
|
if [ ! -x $here/src/udf_test ]
|
|
|
|
|
then
|
2005-07-11 14:57:36 +00:00
|
|
|
echo "udf_test not installed, please download and build the Philips"
|
2004-07-28 08:12:22 +00:00
|
|
|
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
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2018-04-06 19:35:29 -07:00
|
|
|
local device=$1
|
|
|
|
|
local opt_arg=""
|
|
|
|
|
if [ $# -eq 2 ]; then
|
|
|
|
|
opt_arg="-lastvalidblock $(( $2 - 1 ))"
|
2004-06-15 07:32:36 +00:00
|
|
|
fi
|
|
|
|
|
|
2013-03-15 12:28:06 +00:00
|
|
|
rm -f $seqres.checkfs
|
2004-06-15 07:32:36 +00:00
|
|
|
sleep 1 # Due to a problem with time stamps in udf_test
|
2018-04-06 19:35:29 -07:00
|
|
|
$here/src/udf_test $opt_arg $device | tee $seqres.checkfs | egrep "Error|Warning" | \
|
2004-09-15 05:57:50 +00:00
|
|
|
_udf_test_known_error_filter | \
|
2013-12-23 22:53:50 +00:00
|
|
|
egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
|
2014-12-24 14:51:25 +11:00
|
|
|
echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
|
|
|
|
|
return 0
|
2004-06-15 07:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-02 22:42:21 +02:00
|
|
|
_check_test_fs()
|
|
|
|
|
{
|
|
|
|
|
case $FSTYP in
|
|
|
|
|
xfs)
|
|
|
|
|
_check_xfs_test_fs
|
|
|
|
|
;;
|
|
|
|
|
nfs)
|
|
|
|
|
# no way to check consistency for nfs
|
|
|
|
|
;;
|
2014-09-08 22:26:52 +10:00
|
|
|
cifs)
|
|
|
|
|
# no way to check consistency for cifs
|
|
|
|
|
;;
|
2018-01-11 16:05:43 +02:00
|
|
|
9p)
|
|
|
|
|
# no way to check consistency for 9p
|
|
|
|
|
;;
|
2016-11-04 11:04:39 +01:00
|
|
|
ceph)
|
|
|
|
|
# no way to check consistency for CephFS
|
|
|
|
|
;;
|
2017-03-16 13:28:19 +08:00
|
|
|
glusterfs)
|
|
|
|
|
# no way to check consistency for GlusterFS
|
|
|
|
|
;;
|
2015-12-21 18:07:47 +11:00
|
|
|
overlay)
|
2018-03-01 20:13:44 +08:00
|
|
|
_check_overlay_test_fs
|
2015-12-21 18:07:47 +11:00
|
|
|
;;
|
2017-04-07 16:09:43 -04:00
|
|
|
pvfs2)
|
|
|
|
|
;;
|
2009-06-02 22:42:21 +02:00
|
|
|
udf)
|
|
|
|
|
# do nothing for now
|
|
|
|
|
;;
|
2011-12-14 15:35:20 +08:00
|
|
|
btrfs)
|
|
|
|
|
_check_btrfs_filesystem $TEST_DEV
|
|
|
|
|
;;
|
2013-12-10 20:11:52 +00:00
|
|
|
tmpfs)
|
|
|
|
|
# no way to check consistency for tmpfs
|
|
|
|
|
;;
|
2017-06-07 10:20:45 +02:00
|
|
|
ubifs)
|
|
|
|
|
# there is no fsck program for ubifs yet
|
|
|
|
|
;;
|
2009-06-02 22:42:21 +02:00
|
|
|
*)
|
|
|
|
|
_check_generic_filesystem $TEST_DEV
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-22 04:16:45 +00:00
|
|
|
_check_scratch_fs()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local device=$SCRATCH_DEV
|
2013-05-16 08:48:03 -05:00
|
|
|
[ $# -eq 1 ] && device=$1
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
case $FSTYP in
|
|
|
|
|
xfs)
|
2018-04-06 19:35:29 -07:00
|
|
|
local scratch_log="none"
|
|
|
|
|
local scratch_rt="none"
|
2004-06-15 07:32:36 +00:00
|
|
|
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
|
2018-04-06 19:35:29 -07:00
|
|
|
scratch_log="$SCRATCH_LOGDEV"
|
2004-06-25 03:09:08 +00:00
|
|
|
|
2004-06-24 00:12:48 +00:00
|
|
|
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
|
2018-04-06 19:35:29 -07:00
|
|
|
scratch_rt="$SCRATCH_RTDEV"
|
2004-06-15 07:32:36 +00:00
|
|
|
|
2018-04-06 19:35:29 -07:00
|
|
|
_check_xfs_filesystem $device $scratch_log $scratch_rt
|
2004-06-15 07:32:36 +00:00
|
|
|
;;
|
|
|
|
|
udf)
|
2013-05-16 08:48:03 -05:00
|
|
|
_check_udf_filesystem $device $udf_fsize
|
2004-06-15 07:32:36 +00:00
|
|
|
;;
|
|
|
|
|
nfs*)
|
|
|
|
|
# Don't know how to check an NFS filesystem, yet.
|
|
|
|
|
;;
|
2014-09-08 22:26:52 +10:00
|
|
|
cifs)
|
|
|
|
|
# Don't know how to check a CIFS filesystem, yet.
|
|
|
|
|
;;
|
2018-01-11 16:05:43 +02:00
|
|
|
9p)
|
|
|
|
|
# no way to check consistency for 9p
|
|
|
|
|
;;
|
2016-11-04 11:04:39 +01:00
|
|
|
ceph)
|
|
|
|
|
# no way to check consistency for CephFS
|
|
|
|
|
;;
|
2017-03-16 13:28:19 +08:00
|
|
|
glusterfs)
|
|
|
|
|
# no way to check consistency for GlusterFS
|
|
|
|
|
;;
|
2015-12-21 18:07:47 +11:00
|
|
|
overlay)
|
2018-03-01 20:13:44 +08:00
|
|
|
_check_overlay_scratch_fs
|
2015-12-21 18:07:47 +11:00
|
|
|
;;
|
2017-04-07 16:09:43 -04:00
|
|
|
pvfs2)
|
|
|
|
|
;;
|
2011-12-14 15:35:20 +08:00
|
|
|
btrfs)
|
2013-05-16 08:48:03 -05:00
|
|
|
_check_btrfs_filesystem $device
|
2011-12-14 15:35:20 +08:00
|
|
|
;;
|
2013-12-10 20:11:52 +00:00
|
|
|
tmpfs)
|
|
|
|
|
# no way to check consistency for tmpfs
|
|
|
|
|
;;
|
2017-06-07 10:20:45 +02:00
|
|
|
ubifs)
|
|
|
|
|
# there is no fsck program for ubifs yet
|
|
|
|
|
;;
|
2004-06-15 07:32:36 +00:00
|
|
|
*)
|
2013-05-16 08:48:03 -05:00
|
|
|
_check_generic_filesystem $device
|
2004-06-15 07:32:36 +00:00
|
|
|
;;
|
|
|
|
|
esac
|
2003-05-22 04:16:45 +00:00
|
|
|
}
|
|
|
|
|
|
2004-02-02 01:13:25 +00:00
|
|
|
_full_fstyp_details()
|
|
|
|
|
{
|
2004-06-15 07:32:36 +00:00
|
|
|
[ -z "$FSTYP" ] && FSTYP=xfs
|
|
|
|
|
if [ $FSTYP = xfs ]; then
|
2004-08-10 05:43:44 +00:00
|
|
|
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
|
2004-06-15 07:32:36 +00:00
|
|
|
fi
|
|
|
|
|
echo $FSTYP
|
2004-02-02 01:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_full_platform_details()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local os=`uname -s`
|
|
|
|
|
local host=`hostname -s`
|
|
|
|
|
local kernel=`uname -r`
|
|
|
|
|
local platform=`uname -m`
|
2004-06-15 07:32:36 +00:00
|
|
|
echo "$os/$platform $host $kernel"
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-21 17:07:48 +11:00
|
|
|
_get_os_name()
|
|
|
|
|
{
|
2017-07-20 21:22:05 -07:00
|
|
|
if [ "`uname`" == "Linux" ]; then
|
2015-12-21 17:07:48 +11:00
|
|
|
echo 'linux'
|
|
|
|
|
else
|
|
|
|
|
echo Unknown operating system: `uname`
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-21 17:08:22 +11:00
|
|
|
_link_out_file_named()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local features=$2
|
|
|
|
|
local suffix=$(FEATURES="$features" perl -e '
|
2015-12-21 17:08:22 +11:00
|
|
|
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
|
2018-04-06 19:35:29 -07:00
|
|
|
ln -fs $(basename $1).$suffix $1
|
2015-12-21 17:08:22 +11:00
|
|
|
}
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
_link_out_file()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local features
|
|
|
|
|
|
2015-12-21 17:08:22 +11:00
|
|
|
if [ $# -eq 0 ]; then
|
2018-04-06 19:35:29 -07:00
|
|
|
features="$(_get_os_name)"
|
2015-12-21 17:08:22 +11:00
|
|
|
if [ -n "$MOUNT_OPTIONS" ]; then
|
2018-04-06 19:35:29 -07:00
|
|
|
features=$features,${MOUNT_OPTIONS##"-o "}
|
2015-12-21 17:08:22 +11:00
|
|
|
fi
|
|
|
|
|
else
|
2018-04-06 19:35:29 -07:00
|
|
|
features=$1
|
2013-03-15 12:28:03 +00:00
|
|
|
fi
|
2015-12-21 17:08:22 +11:00
|
|
|
|
2018-04-06 19:35:29 -07:00
|
|
|
_link_out_file_named $seqfull.out "$features"
|
2004-06-15 07:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-15 05:57:50 +00:00
|
|
|
_die()
|
|
|
|
|
{
|
|
|
|
|
echo $@
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 15:55:39 +08:00
|
|
|
# convert urandom incompressible data to compressible text data
|
|
|
|
|
_ddt()
|
|
|
|
|
{
|
2017-02-16 18:32:48 -08:00
|
|
|
od /dev/urandom | dd iflag=fullblock ${*}
|
2017-02-06 15:55:39 +08:00
|
|
|
}
|
|
|
|
|
|
2011-10-20 23:41:18 +08:00
|
|
|
#takes files, randomdata
|
2004-09-15 05:57:50 +00:00
|
|
|
_nfiles()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local f=0
|
2004-09-15 05:57:50 +00:00
|
|
|
while [ $f -lt $1 ]
|
|
|
|
|
do
|
2018-04-06 19:35:29 -07:00
|
|
|
local file=f$f
|
2009-03-25 20:53:36 +01:00
|
|
|
echo > $file
|
2004-09-15 05:57:50 +00:00
|
|
|
if [ $size -gt 0 ]; then
|
2011-10-20 23:41:19 +08:00
|
|
|
if [ "$2" == "false" ]; then
|
2011-10-20 23:41:18 +08:00
|
|
|
dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
|
2017-02-06 15:55:39 +08:00
|
|
|
elif [ "$2" == "comp" ]; then
|
|
|
|
|
_ddt of=$file bs=1024 count=$size 2>&1 | _filter_dd
|
2011-10-20 23:41:18 +08:00
|
|
|
else
|
|
|
|
|
dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
|
|
|
|
|
fi
|
2004-09-15 05:57:50 +00:00
|
|
|
fi
|
2009-03-25 20:53:36 +01:00
|
|
|
let f=$f+1
|
2004-09-15 05:57:50 +00:00
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-20 23:41:18 +08:00
|
|
|
# takes dirname, depth, randomdata
|
2004-09-15 05:57:50 +00:00
|
|
|
_descend()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local dirname=$1 depth=$2 randomdata=$3
|
2004-09-15 05:57:50 +00:00
|
|
|
mkdir $dirname || die "mkdir $dirname failed"
|
|
|
|
|
cd $dirname
|
|
|
|
|
|
2011-10-20 23:41:18 +08:00
|
|
|
_nfiles $files $randomdata # files for this dir and data type
|
2004-09-15 05:57:50 +00:00
|
|
|
|
|
|
|
|
[ $depth -eq 0 ] && return
|
2018-04-06 19:35:29 -07:00
|
|
|
local deep=$(( depth - 1 )) # go 1 down
|
2004-09-15 05:57:50 +00:00
|
|
|
|
|
|
|
|
[ $verbose = true ] && echo "descending, depth from leaves = $deep"
|
|
|
|
|
|
2018-04-06 19:35:29 -07:00
|
|
|
local d=0
|
2004-09-15 05:57:50 +00:00
|
|
|
while [ $d -lt $dirs ]
|
|
|
|
|
do
|
|
|
|
|
_descend d$d $deep &
|
2009-03-25 20:53:36 +01:00
|
|
|
let d=$d+1
|
2004-09-15 05:57:50 +00:00
|
|
|
wait
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 14:57:36 +00:00
|
|
|
# Populate a filesystem with inodes for performance experiments
|
|
|
|
|
#
|
2011-10-20 23:41:18 +08:00
|
|
|
# usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
|
2005-07-11 14:57:36 +00:00
|
|
|
#
|
2004-09-15 05:57:50 +00:00
|
|
|
_populate_fs()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
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
|
2004-09-15 05:57:50 +00:00
|
|
|
|
2011-10-20 23:41:22 +08:00
|
|
|
OPTIND=1
|
2017-02-06 15:55:39 +08:00
|
|
|
while getopts "d:f:n:r:s:v:x:c" c
|
2004-09-15 05:57:50 +00:00
|
|
|
do
|
|
|
|
|
case $c in
|
|
|
|
|
d) depth=$OPTARG;;
|
|
|
|
|
n) dirs=$OPTARG;;
|
|
|
|
|
f) files=$OPTARG;;
|
|
|
|
|
s) size=$OPTARG;;
|
|
|
|
|
v) verbose=true;;
|
|
|
|
|
r) root=$OPTARG;;
|
2011-10-20 23:41:18 +08:00
|
|
|
x) randomdata=true;;
|
2017-02-06 15:55:39 +08:00
|
|
|
c) randomdata=comp;;
|
2004-09-15 05:57:50 +00:00
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
2011-10-20 23:41:18 +08:00
|
|
|
_descend $root $depth $randomdata
|
2004-09-15 05:57:50 +00:00
|
|
|
wait
|
|
|
|
|
|
|
|
|
|
cd $here
|
|
|
|
|
|
|
|
|
|
[ $verbose = true ] && echo done
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 14:57:36 +00:00
|
|
|
# query whether the given file has the given inode flag set
|
|
|
|
|
#
|
|
|
|
|
_test_inode_flag()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local flag=$1
|
|
|
|
|
local file=$2
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2016-11-07 01:43:33 +08:00
|
|
|
if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
return 1
|
2005-07-11 14:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
2005-12-09 02:52:22 +00:00
|
|
|
# query the given files extsize allocator hint in bytes (if any)
|
|
|
|
|
#
|
|
|
|
|
_test_inode_extsz()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local file=$1
|
|
|
|
|
local blocks=""
|
2005-12-09 02:52:22 +00:00
|
|
|
|
|
|
|
|
blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
|
|
|
|
|
awk '/^xattr.extsize =/ { print $3 }'`
|
2016-11-07 01:43:33 +08:00
|
|
|
[ -z "$blocks" ] && blocks="0"
|
|
|
|
|
echo $blocks
|
2005-12-09 02:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-20 23:41:19 +08:00
|
|
|
# scratch_dev_pool should contain the disks pool for the btrfs raid
|
|
|
|
|
_require_scratch_dev_pool()
|
|
|
|
|
{
|
|
|
|
|
local i
|
2014-01-20 12:52:21 +11:00
|
|
|
local ndevs
|
|
|
|
|
|
2011-10-20 23:41:19 +08:00
|
|
|
if [ -z "$SCRATCH_DEV_POOL" ]; then
|
|
|
|
|
_notrun "this test requires a valid \$SCRATCH_DEV_POOL"
|
|
|
|
|
fi
|
|
|
|
|
|
2014-01-20 12:52:21 +11:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
|
ndevs=2
|
|
|
|
|
else
|
|
|
|
|
ndevs=$1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
|
2011-10-20 23:41:19 +08:00
|
|
|
# so fail it
|
|
|
|
|
case $FSTYP in
|
|
|
|
|
btrfs)
|
2014-01-20 12:52:21 +11:00
|
|
|
if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
|
|
|
|
|
_notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
|
2011-10-20 23:41:19 +08:00
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
_notrun "dev_pool is not supported by fstype \"$FSTYP\""
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
for i in $SCRATCH_DEV_POOL; do
|
2015-05-14 20:27:54 +10:00
|
|
|
if [ "`_is_block_dev "$i"`" = "" ]; then
|
2011-10-20 23:41:19 +08:00
|
|
|
_notrun "this test requires valid block disk $i"
|
|
|
|
|
fi
|
2015-05-14 20:27:54 +10:00
|
|
|
if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
|
2011-10-20 23:41:19 +08:00
|
|
|
_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
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-14 22:59:37 +11:00
|
|
|
# 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()
|
|
|
|
|
{
|
2018-04-06 19:35:30 -07:00
|
|
|
local size
|
|
|
|
|
local newsize
|
|
|
|
|
local dev
|
2014-10-14 22:59:37 +11:00
|
|
|
|
|
|
|
|
# SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
|
2018-04-06 19:35:30 -07:00
|
|
|
size=`_get_device_size $SCRATCH_DEV`
|
|
|
|
|
for dev in $SCRATCH_DEV_POOL; do
|
|
|
|
|
newsize=`_get_device_size $dev`
|
|
|
|
|
if [ $size -ne $newsize ]; then
|
2014-10-14 22:59:37 +11:00
|
|
|
_notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-20 12:52:21 +11:00
|
|
|
# We will check if the device is deletable
|
2011-10-20 23:41:19 +08:00
|
|
|
_require_deletable_scratch_dev_pool()
|
|
|
|
|
{
|
|
|
|
|
local i
|
|
|
|
|
local x
|
|
|
|
|
for i in $SCRATCH_DEV_POOL; do
|
|
|
|
|
x=`echo $i | cut -d"/" -f 3`
|
2014-01-20 12:52:21 +11:00
|
|
|
if [ ! -f /sys/class/block/${x}/device/delete ]; then
|
|
|
|
|
_notrun "$i is a device which is not deletable"
|
2011-10-20 23:41:19 +08:00
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 10:42:06 +00:00
|
|
|
# Check that fio is present, and it is able to execute given jobfile
|
|
|
|
|
_require_fio()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local job=$1
|
2013-02-20 10:42:06 +00:00
|
|
|
|
2015-03-18 15:00:23 +11:00
|
|
|
_require_command "$FIO_PROG" fio
|
2013-02-20 10:42:06 +00:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
|
return 1;
|
|
|
|
|
fi
|
|
|
|
|
|
2013-04-15 11:09:47 +00:00
|
|
|
$FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
|
|
|
|
|
[ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
|
2013-02-20 10:42:06 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-19 17:53:56 -05:00
|
|
|
# Does freeze work on this fs?
|
|
|
|
|
_require_freeze()
|
|
|
|
|
{
|
|
|
|
|
xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
|
2018-04-06 19:35:29 -07:00
|
|
|
local result=$?
|
2012-09-19 17:53:56 -05:00
|
|
|
xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
|
|
|
|
|
[ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 19:29:18 +03:00
|
|
|
# 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"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-02-12 14:14:52 +11:00
|
|
|
# Does shutdown work on this fs?
|
|
|
|
|
_require_scratch_shutdown()
|
|
|
|
|
{
|
|
|
|
|
[ -x src/godown ] || _notrun "src/godown executable not found"
|
|
|
|
|
|
2017-12-15 15:47:33 +08:00
|
|
|
_scratch_mkfs > /dev/null 2>&1 || _notrun "_scratch_mkfs failed on $SCRATCH_DEV"
|
2018-02-07 17:31:36 +08:00
|
|
|
_scratch_mount
|
2017-12-15 15:47:33 +08:00
|
|
|
|
|
|
|
|
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 "$SCRATCH_DEV is not a block device"
|
|
|
|
|
else
|
|
|
|
|
src/godown -f $OVL_BASE_SCRATCH_MNT 2>&1 \
|
|
|
|
|
|| _notrun "Underlying filesystem does not support shutdown"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
src/godown -f $SCRATCH_MNT 2>&1 \
|
|
|
|
|
|| _notrun "$FSTYP does not support shutdown"
|
|
|
|
|
fi
|
|
|
|
|
|
2015-02-12 14:14:52 +11:00
|
|
|
_scratch_unmount
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 12:11:17 +08:00
|
|
|
# Does dax mount option work on this dev/fs?
|
|
|
|
|
_require_scratch_dax()
|
|
|
|
|
{
|
|
|
|
|
_require_scratch
|
|
|
|
|
_scratch_mkfs > /dev/null 2>&1
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount -o dax || \
|
|
|
|
|
_notrun "mount $SCRATCH_DEV with dax failed"
|
2017-02-08 12:11:17 +08:00
|
|
|
# Check options to be sure. XFS ignores dax option
|
|
|
|
|
# and goes on if dev underneath does not support dax.
|
|
|
|
|
_fs_options $SCRATCH_DEV | grep -qw "dax" || \
|
|
|
|
|
_notrun "$SCRATCH_DEV $FSTYP does not support -o dax"
|
|
|
|
|
_scratch_unmount
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-12 14:19:37 +11:00
|
|
|
# Does norecovery support by this fs?
|
|
|
|
|
_require_norecovery()
|
|
|
|
|
{
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount -o ro,norecovery || \
|
2015-02-12 14:19:37 +11:00
|
|
|
_notrun "$FSTYP does not support norecovery"
|
|
|
|
|
_scratch_unmount
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-25 15:36:52 +11:00
|
|
|
# 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.
|
|
|
|
|
_require_metadata_journaling()
|
|
|
|
|
{
|
|
|
|
|
if [ -z $1 ]; then
|
2018-04-06 19:35:29 -07:00
|
|
|
local dev=$TEST_DEV
|
2015-02-25 15:36:52 +11:00
|
|
|
else
|
2018-04-06 19:35:29 -07:00
|
|
|
local dev=$1
|
2015-02-25 15:36:52 +11:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
case "$FSTYP" in
|
2017-06-14 09:19:21 +02:00
|
|
|
ext2|vfat|msdos|udf)
|
2015-02-25 15:36:52 +11:00
|
|
|
_notrun "$FSTYP does not support metadata journaling"
|
|
|
|
|
;;
|
|
|
|
|
ext4)
|
|
|
|
|
# ext4 could be mkfs'd without a journal...
|
|
|
|
|
_require_dumpe2fs
|
2018-04-06 19:35:29 -07:00
|
|
|
$DUMPE2FS_PROG -h $dev 2>&1 | grep -q has_journal || \
|
|
|
|
|
_notrun "$FSTYP on $dev not configured with metadata journaling"
|
2016-08-19 12:47:38 -04:00
|
|
|
# ext4 might not load a journal
|
|
|
|
|
_exclude_scratch_mount_option "noload"
|
2015-02-25 15:36:52 +11:00
|
|
|
;;
|
2018-01-06 16:23:58 +08:00
|
|
|
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
|
|
|
|
|
_overlay_config_restore
|
|
|
|
|
_require_metadata_journaling
|
|
|
|
|
_overlay_config_override
|
|
|
|
|
else
|
|
|
|
|
_notrun "No metadata journaling support for legacy overlay setup"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
2015-02-25 15:36:52 +11:00
|
|
|
*)
|
|
|
|
|
# by default we pass; if you need to, add your fs above!
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-12 14:18:23 +11:00
|
|
|
_count_extents()
|
|
|
|
|
{
|
2015-08-04 14:10:49 +10:00
|
|
|
$XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
|
2015-02-12 14:18:23 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_count_holes()
|
|
|
|
|
{
|
2015-08-04 14:10:49 +10:00
|
|
|
$XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
|
2015-02-12 14:18:23 +11:00
|
|
|
}
|
|
|
|
|
|
2017-04-06 09:01:30 -07:00
|
|
|
_count_attr_extents()
|
|
|
|
|
{
|
|
|
|
|
$XFS_IO_PROG -c "fiemap -a" $1 | tail -n +2 | grep -v hole | wc -l
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-20 23:41:19 +08:00
|
|
|
# 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()
|
|
|
|
|
{
|
2013-10-21 16:13:53 +00:00
|
|
|
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
|
2011-10-20 23:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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"
|
2014-08-13 11:15:43 +10:00
|
|
|
|
|
|
|
|
# ensure the device comes online
|
2018-04-06 19:35:29 -07:00
|
|
|
local dev_back_oneline=0
|
|
|
|
|
local i
|
2014-08-13 11:15:43 +10:00
|
|
|
for i in `seq 1 10`; do
|
|
|
|
|
if [ -d /sys/class/scsi_device/${1}/device/block ]; then
|
2018-04-06 19:35:29 -07:00
|
|
|
local dev=`ls /sys/class/scsi_device/${1}/device/block`
|
|
|
|
|
local j
|
2014-08-13 11:15:43 +10:00
|
|
|
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
|
2011-10-20 23:41:19 +08:00
|
|
|
}
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2012-10-09 13:24:10 +00:00
|
|
|
_require_fstrim()
|
|
|
|
|
{
|
|
|
|
|
if [ -z "$FSTRIM_PROG" ]; then
|
|
|
|
|
_notrun "This test requires fstrim utility."
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-16 10:53:57 +11:00
|
|
|
_require_batched_discard()
|
2012-10-09 13:24:10 +00:00
|
|
|
{
|
|
|
|
|
if [ $# -ne 1 ]; then
|
2014-12-16 10:53:57 +11:00
|
|
|
echo "Usage: _require_batched_discard mnt_point" 1>&2
|
2012-10-09 13:24:10 +00:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
_require_fstrim
|
2015-01-21 15:57:03 +11:00
|
|
|
$FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
|
2012-10-09 13:24:10 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 10:19:56 +00:00
|
|
|
_require_dumpe2fs()
|
|
|
|
|
{
|
|
|
|
|
if [ -z "$DUMPE2FS_PROG" ]; then
|
|
|
|
|
_notrun "This test requires dumpe2fs utility."
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 12:17:48 +00:00
|
|
|
_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
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-13 15:17:44 +11:00
|
|
|
_require_fssum()
|
|
|
|
|
{
|
|
|
|
|
FSSUM_PROG=$here/src/fssum
|
|
|
|
|
[ -x $FSSUM_PROG ] || _notrun "fssum not built"
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-12 11:23:06 +11:00
|
|
|
_require_cloner()
|
2014-05-27 12:07:36 +10:00
|
|
|
{
|
|
|
|
|
CLONER_PROG=$here/src/cloner
|
|
|
|
|
[ -x $CLONER_PROG ] || \
|
|
|
|
|
_notrun "cloner binary not present at $CLONER_PROG"
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-08 10:52:21 +08:00
|
|
|
# Normalize mount options from global $MOUNT_OPTIONS
|
|
|
|
|
# Convert options like "-o opt1,opt2 -oopt3" to
|
|
|
|
|
# "opt1 opt2 opt3"
|
|
|
|
|
_normalize_mount_options()
|
2016-06-23 14:09:46 +08:00
|
|
|
{
|
2016-09-08 10:52:21 +08:00
|
|
|
echo $MOUNT_OPTIONS | sed -n 's/-o\s*\(\S*\)/\1/gp'| sed 's/,/ /g'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# skip test if MOUNT_OPTIONS contains the given strings
|
|
|
|
|
_exclude_scratch_mount_option()
|
|
|
|
|
{
|
|
|
|
|
local mnt_opts=$(_normalize_mount_options)
|
|
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
|
if echo $mnt_opts | grep -qw "$1"; then
|
|
|
|
|
_notrun "mount option \"$1\" not allowed in this test"
|
|
|
|
|
fi
|
|
|
|
|
shift
|
|
|
|
|
done
|
2016-06-23 14:09:46 +08:00
|
|
|
}
|
|
|
|
|
|
2014-11-10 18:06:23 +11:00
|
|
|
_require_atime()
|
|
|
|
|
{
|
2016-06-23 14:09:46 +08:00
|
|
|
_exclude_scratch_mount_option "noatime"
|
2018-05-31 12:10:14 +08:00
|
|
|
case $FSTYP in
|
|
|
|
|
nfs|cifs)
|
|
|
|
|
_notrun "atime related mount options have no effect on $FSTYP"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2014-11-10 18:06:23 +11:00
|
|
|
}
|
|
|
|
|
|
2014-02-19 08:26:56 +11:00
|
|
|
_require_relatime()
|
|
|
|
|
{
|
|
|
|
|
_scratch_mkfs > /dev/null 2>&1
|
2018-02-07 17:31:36 +08:00
|
|
|
_try_scratch_mount -o relatime || \
|
2014-02-19 08:26:56 +11:00
|
|
|
_notrun "relatime not supported by the current kernel"
|
|
|
|
|
_scratch_unmount
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-18 09:34:39 +10:00
|
|
|
_require_userns()
|
|
|
|
|
{
|
|
|
|
|
[ -x src/nsexec ] || _notrun "src/nsexec executable not found"
|
|
|
|
|
src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-12 09:21:59 +00:00
|
|
|
_create_loop_device()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local file=$1 dev
|
2013-02-12 09:21:59 +00:00
|
|
|
dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
|
|
|
|
|
echo $dev
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_destroy_loop_device()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local dev=$1
|
2013-02-12 09:21:59 +00:00
|
|
|
losetup -d $dev || _fail "Cannot destroy loop device $dev"
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 10:42:10 +00:00
|
|
|
_scale_fsstress_args()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local args=""
|
2013-02-20 10:42:10 +00:00
|
|
|
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
|
|
|
|
|
echo $args
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 10:59:32 +00:00
|
|
|
#
|
|
|
|
|
# Return the logical block size if running on a block device,
|
|
|
|
|
# else substitute the page size.
|
|
|
|
|
#
|
|
|
|
|
_min_dio_alignment()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local dev=$1
|
2013-11-06 10:59:32 +00:00
|
|
|
|
|
|
|
|
if [ -b "$dev" ]; then
|
|
|
|
|
blockdev --getss $dev
|
|
|
|
|
else
|
|
|
|
|
$here/src/feature -s
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 10:42:11 +00:00
|
|
|
run_check()
|
|
|
|
|
{
|
2013-03-15 12:28:06 +00:00
|
|
|
echo "# $@" >> $seqres.full 2>&1
|
|
|
|
|
"$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
|
2013-02-20 10:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-08 22:26:52 +10:00
|
|
|
_require_test_symlinks()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local target=`mktemp -p $TEST_DIR`
|
|
|
|
|
local link=`mktemp -p $TEST_DIR -u`
|
2014-09-08 22:26:52 +10:00
|
|
|
ln -s `basename $target` $link
|
|
|
|
|
if [ "$?" -ne 0 ]; then
|
|
|
|
|
rm -f $target
|
|
|
|
|
_notrun "Require symlinks 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"
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-13 22:10:26 +08:00
|
|
|
_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
|
|
|
|
|
src/t_ofd_locks -t $TEST_DIR/ofd_testfile > /dev/null 2>&1
|
|
|
|
|
[ $? -eq 22 ] && _notrun "Require OFD locks support"
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-17 08:39:17 +11:00
|
|
|
_require_test_lsattr()
|
|
|
|
|
{
|
2018-04-06 19:35:29 -07:00
|
|
|
local testio=$(lsattr -d $TEST_DIR 2>&1)
|
2015-11-17 08:39:17 +11:00
|
|
|
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"
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-19 10:47:55 +11:00
|
|
|
_require_chattr()
|
|
|
|
|
{
|
2017-04-06 08:49:18 +03:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
|
echo "Usage: _require_chattr <attr>"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
local attribute=$1
|
2016-02-19 10:47:55 +11:00
|
|
|
|
2017-04-06 08:49:18 +03:00
|
|
|
touch $TEST_DIR/syscalltest
|
|
|
|
|
chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
|
2018-04-06 19:35:29 -07:00
|
|
|
local ret=$?
|
2017-04-06 08:49:18 +03:00
|
|
|
chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
|
2018-04-06 19:35:29 -07:00
|
|
|
if [ "$ret" -ne 0 ]; then
|
2017-04-06 08:49:18 +03:00
|
|
|
_notrun "file system doesn't support chattr +$attribute"
|
|
|
|
|
fi
|
|
|
|
|
cat $TEST_DIR/syscalltest.out >> $seqres.full
|
|
|
|
|
rm -f $TEST_DIR/syscalltest.out
|
2016-02-19 10:47:55 +11:00
|
|
|
}
|
|
|
|
|
|
2014-08-13 11:15:23 +10:00
|
|
|
_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
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-04 14:10:48 +10:00
|
|
|
_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
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-13 11:15:23 +10:00
|
|
|
_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
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-04 14:10:48 +10:00
|
|
|
# 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))
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-14 22:59:37 +11:00
|
|
|
# return device size in kb
|
|
|
|
|
_get_device_size()
|
|
|
|
|
{
|
|
|
|
|
grep `_short_dev $1` /proc/partitions | awk '{print $3}'
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-23 09:54:41 -07:00
|
|
|
# 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"
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-04 14:10:48 +10:00
|
|
|
# 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
|
|
|
|
|
|
2015-08-04 14:10:48 +10:00
|
|
|
# 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
|
2018-04-06 19:35:29 -07:00
|
|
|
local filter=${1:-cat}
|
2015-08-04 14:10:48 +10:00
|
|
|
|
2018-03-23 09:54:41 -07:00
|
|
|
_dmesg_since_test_start | $filter >$seqres.dmesg
|
2017-05-03 17:57:30 -07:00
|
|
|
egrep -q -e "kernel BUG at" \
|
2015-08-04 14:10:48 +10:00
|
|
|
-e "WARNING:" \
|
2018-06-12 14:09:06 +08:00
|
|
|
-e "\bBUG:" \
|
2015-08-04 14:10:48 +10:00
|
|
|
-e "Oops:" \
|
|
|
|
|
-e "possible recursive locking detected" \
|
2015-08-04 14:10:49 +10:00
|
|
|
-e "Internal error" \
|
2017-05-03 17:57:30 -07:00
|
|
|
-e "(INFO|ERR): suspicious RCU usage" \
|
2015-12-21 17:05:42 +11:00
|
|
|
-e "INFO: possible circular locking dependency detected" \
|
2016-03-23 17:39:11 +11:00
|
|
|
-e "general protection fault:" \
|
2017-11-09 16:44:40 -08:00
|
|
|
-e "BUG .* remaining" \
|
2017-11-15 17:22:44 -08:00
|
|
|
-e "UBSAN:" \
|
2015-08-04 14:10:48 +10:00
|
|
|
$seqres.dmesg
|
|
|
|
|
if [ $? -eq 0 ]; then
|
2017-03-03 12:26:15 +04:00
|
|
|
_dump_err "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
|
2015-08-04 14:10:48 +10:00
|
|
|
return 1
|
|
|
|
|
else
|
|
|
|
|
rm -f $seqres.dmesg
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-24 15:53:23 -08:00
|
|
|
# capture the kmemleak report
|
|
|
|
|
_capture_kmemleak()
|
|
|
|
|
{
|
2018-04-06 19:35:30 -07:00
|
|
|
local kern_knob="${DEBUGFS_MNT}/kmemleak"
|
|
|
|
|
local leak_file="$1"
|
2018-01-24 15:53:23 -08:00
|
|
|
|
|
|
|
|
# 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.
|
2018-04-06 19:35:30 -07:00
|
|
|
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
|
2018-01-24 15:53:23 -08:00
|
|
|
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
|
2018-04-06 19:35:30 -07:00
|
|
|
cat "$leak_file.tmp" >> "$leak_file"
|
2018-01-24 15:53:23 -08:00
|
|
|
fi
|
2018-04-23 14:23:14 +09:00
|
|
|
rm -rf "$leak_file.tmp"
|
2018-04-06 19:35:30 -07:00
|
|
|
echo "clear" > "$kern_knob"
|
2018-01-24 15:53:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# set up kmemleak
|
|
|
|
|
_init_kmemleak()
|
|
|
|
|
{
|
2018-04-06 19:35:30 -07:00
|
|
|
local kern_knob="${DEBUGFS_MNT}/kmemleak"
|
2018-01-24 15:53:23 -08:00
|
|
|
|
2018-04-06 19:35:30 -07:00
|
|
|
if [ ! -w "$kern_knob" ]; then
|
2018-01-24 15:53:23 -08:00
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Disable the automatic scan so that we can control it completely,
|
|
|
|
|
# then dump all the leaks recorded so far.
|
2018-04-06 19:35:30 -07:00
|
|
|
echo "scan=off" > "$kern_knob"
|
2018-01-24 15:53:23 -08:00
|
|
|
_capture_kmemleak /dev/null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# check kmemleak log
|
|
|
|
|
_check_kmemleak()
|
|
|
|
|
{
|
2018-04-06 19:35:30 -07:00
|
|
|
local kern_knob="${DEBUGFS_MNT}/kmemleak"
|
|
|
|
|
local leak_file="${seqres}.kmemleak"
|
2018-01-24 15:53:23 -08:00
|
|
|
|
2018-04-06 19:35:30 -07:00
|
|
|
if [ ! -w "$kern_knob" ]; then
|
2018-01-24 15:53:23 -08:00
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Capture and report any leaks
|
2018-04-06 19:35:30 -07:00
|
|
|
_capture_kmemleak "$leak_file"
|
|
|
|
|
if [ -s "$leak_file" ]; then
|
|
|
|
|
_dump_err "_check_kmemleak: something found in kmemleak (see $leak_file)"
|
2018-01-24 15:53:23 -08:00
|
|
|
return 1
|
|
|
|
|
else
|
2018-04-06 19:35:30 -07:00
|
|
|
rm -f "$leak_file"
|
2018-01-24 15:53:23 -08:00
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 16:19:33 +11:00
|
|
|
# don't check dmesg log after test
|
|
|
|
|
_disable_dmesg_check()
|
|
|
|
|
{
|
|
|
|
|
rm -f ${RESULT_DIR}/check_dmesg
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-11 10:37:59 +00:00
|
|
|
init_rc()
|
|
|
|
|
{
|
|
|
|
|
# make some further configuration checks here
|
|
|
|
|
if [ "$TEST_DEV" = "" ]
|
|
|
|
|
then
|
|
|
|
|
echo "common/rc: Error: \$TEST_DEV is not set"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2013-07-11 10:37:59 +00:00
|
|
|
# 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
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2017-02-28 14:18:28 +02:00
|
|
|
# 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
|
2013-07-11 10:37:59 +00:00
|
|
|
fi
|
2017-02-28 14:18:28 +02:00
|
|
|
|
2013-07-11 10:37:59 +00:00
|
|
|
# Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
|
2016-10-17 10:23:32 +03:00
|
|
|
$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"
|
2015-03-18 14:58:04 +11:00
|
|
|
|
2016-10-17 10:31:41 +03:00
|
|
|
# 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"
|
|
|
|
|
|
2016-11-08 13:33:50 +08:00
|
|
|
# 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
|
2015-03-18 14:58:04 +11:00
|
|
|
fi
|
2013-07-11 10:37:59 +00:00
|
|
|
}
|
2013-05-14 08:33:44 -05:00
|
|
|
|
2014-05-13 09:05:43 +10:00
|
|
|
# get real device path name by following link
|
|
|
|
|
_real_dev()
|
|
|
|
|
{
|
2018-04-06 19:35:30 -07:00
|
|
|
local dev=$1
|
|
|
|
|
if [ -b "$dev" ] && [ -L "$dev" ]; then
|
|
|
|
|
dev=`readlink -f "$dev"`
|
2014-05-13 09:05:43 +10:00
|
|
|
fi
|
2018-04-06 19:35:30 -07:00
|
|
|
echo $dev
|
2014-05-13 09:05:43 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# basename of a device
|
|
|
|
|
_short_dev()
|
|
|
|
|
{
|
|
|
|
|
echo `basename $(_real_dev $1)`
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 12:51:57 +10:00
|
|
|
_sysfs_dev()
|
|
|
|
|
{
|
2018-04-06 19:35:30 -07:00
|
|
|
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
|
2015-05-26 12:51:57 +10:00
|
|
|
}
|
|
|
|
|
|
2017-01-04 17:04:55 -08:00
|
|
|
# Get the minimum block size of a file. Usually this is the
|
|
|
|
|
# minimum fs block size, but some filesystems (ocfs2) do block
|
|
|
|
|
# mappings in larger units.
|
|
|
|
|
_get_file_block_size()
|
|
|
|
|
{
|
|
|
|
|
if [ -z $1 ] || [ ! -d $1 ]; then
|
|
|
|
|
echo "Missing mount point argument for _get_file_block_size"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
if [ "$FSTYP" = "ocfs2" ]; then
|
|
|
|
|
stat -c '%o' $1
|
|
|
|
|
else
|
|
|
|
|
_get_block_size $1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Get the minimum block size of an fs.
|
2017-01-04 17:04:48 -08:00
|
|
|
_get_block_size()
|
2014-10-14 17:07:52 +11:00
|
|
|
{
|
|
|
|
|
if [ -z $1 ] || [ ! -d $1 ]; then
|
2017-01-04 17:04:48 -08:00
|
|
|
echo "Missing mount point argument for _get_block_size"
|
2014-10-14 17:07:52 +11:00
|
|
|
exit 1
|
|
|
|
|
fi
|
2017-01-04 17:04:55 -08:00
|
|
|
stat -f -c %S $1
|
2014-10-14 17:07:52 +11:00
|
|
|
}
|
|
|
|
|
|
2015-12-21 18:01:46 +11:00
|
|
|
get_page_size()
|
|
|
|
|
{
|
|
|
|
|
echo $(getconf PAGE_SIZE)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-01-11 14:43:40 +11:00
|
|
|
run_fsx()
|
|
|
|
|
{
|
|
|
|
|
echo fsx $@
|
2018-04-06 19:35:29 -07:00
|
|
|
local args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
|
2016-01-11 14:43:40 +11:00
|
|
|
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
|
2017-01-11 17:38:45 +08:00
|
|
|
rm -f $tmp.fsx
|
2016-01-11 14:43:40 +11:00
|
|
|
exit 1
|
|
|
|
|
fi
|
2017-01-11 17:38:45 +08:00
|
|
|
rm -f $tmp.fsx
|
2016-01-11 14:43:40 +11:00
|
|
|
}
|
|
|
|
|
|
2016-07-05 17:30:24 +08:00
|
|
|
# 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
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 14:32:52 +01:00
|
|
|
_require_statx()
|
|
|
|
|
{
|
|
|
|
|
$here/src/stat_test --check-statx ||
|
|
|
|
|
_notrun "This test requires the statx system call"
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-05 17:30:24 +08:00
|
|
|
# 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}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-12 12:43:24 +03:00
|
|
|
# Generic test for specific filesystem feature.
|
|
|
|
|
# Currently only implemented to test overlayfs features.
|
|
|
|
|
_require_scratch_feature()
|
|
|
|
|
{
|
|
|
|
|
local feature=$1
|
|
|
|
|
|
|
|
|
|
case "$FSTYP" in
|
|
|
|
|
overlay)
|
2018-01-30 08:12:18 +02:00
|
|
|
_require_scratch_overlay_features ${feature}
|
2017-07-12 12:43:24 +03:00
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
_fail "Test for feature '${feature}' of ${FSTYP} is not implemented"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-17 10:28:26 -05:00
|
|
|
# The maximum filesystem label length, /not/ including terminating NULL
|
|
|
|
|
_label_get_max()
|
|
|
|
|
{
|
|
|
|
|
case $FSTYP in
|
|
|
|
|
xfs)
|
|
|
|
|
echo 12
|
|
|
|
|
;;
|
|
|
|
|
btrfs)
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 09:45:34 +08:00
|
|
|
_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
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-11 10:37:59 +00:00
|
|
|
init_rc
|
2005-07-11 14:57:36 +00:00
|
|
|
|
2013-07-11 10:37:59 +00:00
|
|
|
################################################################################
|
2001-01-15 05:01:19 +00:00
|
|
|
# make sure this script returns success
|
|
|
|
|
/bin/true
|