2 #-----------------------------------------------------------------------
3 # Copyright (c) 2000-2006 Silicon Graphics, Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 # Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
20 # Mountain View, CA 94043, USA, or: http://www.sgi.com
21 #-----------------------------------------------------------------------
23 BC=$(which bc 2> /dev/null) || BC=
28 _notrun "this test requires 'bc' tool for doing math operations"
34 [ $# -le 0 ] && return
36 result=$(LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null)
38 _notrun "this test requires 'bc' tool for doing math operations"
45 if [ "$HOSTOS" == "Linux" ]
47 command dd --help | grep noxfer > /dev/null 2>&1
51 command dd status=noxfer $@
65 $BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
68 # Prints the md5 checksum of a given file
71 md5sum $1 | cut -d ' ' -f1
75 # ls -l w/ selinux sometimes puts a dot at the end:
76 # -rwxrw-r--. id1 id2 file1
80 ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /"
85 # SELinux adds extra xattrs which can mess up our expected output.
86 # So, mount with a context, and they won't be created
87 # nfs_t is a "liberal" context so we can use it.
88 if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
89 SELINUX_MOUNT_OPTIONS="-o context=system_u:object_r:nfs_t:s0"
90 export SELINUX_MOUNT_OPTIONS
95 export MOUNT_OPTIONS=$XFS_MOUNT_OPTIONS
98 export MOUNT_OPTIONS=$UDF_MOUNT_OPTIONS
101 export MOUNT_OPTIONS=$NFS_MOUNT_OPTIONS
103 ext2|ext3|ext4|ext4dev)
104 # acls & xattrs aren't turned on by default on ext$FOO
105 export MOUNT_OPTIONS="-o acl,user_xattr $EXT_MOUNT_OPTIONS"
108 # acls & xattrs aren't turned on by default on reiserfs
109 export MOUNT_OPTIONS="-o acl,user_xattr $REISERFS_MOUNT_OPTIONS"
112 # acls aren't turned on by default on gfs2
113 export MOUNT_OPTIONS="-o acl $GFS2_MOUNT_OPTIONS"
124 export MKFS_OPTIONS=$XFS_MKFS_OPTIONS
127 [ ! -z "$udf_fsize" ] && \
128 UDF_MKFS_OPTIONS="$UDF_MKFS_OPTIONS -s $udf_fsize"
129 export MKFS_OPTIONS=$UDF_MKFS_OPTIONS
132 export MKFS_OPTIONS=$NFS_MKFS_OPTIONS
135 export MKFS_OPTIONS="$REISERFS_MKFS_OPTIONS -q"
138 export MKFS_OPTIONS="$GFS2_MKFS_OPTIONS -O -p lock_nolock"
141 export MKFS_OPTIONS="$JFS_MKFS_OPTIONS -q"
151 ext2|ext3|ext4|ext4dev)
152 export FSCK_OPTIONS="-nf"
155 export FSCK_OPTIONS="--yes"
158 export FSCK_OPTIONS="-n"
163 [ -z "$FSTYP" ] && FSTYP=xfs
164 [ -z "$MOUNT_OPTIONS" ] && _mount_opts
165 [ -z "$MKFS_OPTIONS" ] && _mkfs_opts
166 [ -z "$FSCK_OPTIONS" ] && _fsck_opts
169 # we need common/config
170 if [ "$iam" != "check" ]
172 if ! . ./common/config
174 echo "$iam: failed to source common/config"
179 # check for correct setup
182 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
183 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
184 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
185 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
188 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
191 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
197 # make sure we have a standard umask
202 $MOUNT_PROG `_mount_ops_filter $*`
210 if [ "$FSTYP" != "xfs" ]; then
216 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
225 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
226 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
227 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
228 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
236 if [ "$FSTYP" != "xfs" ]; then
250 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
251 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
252 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
253 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
260 #get mount point to handle dmapi mtpt option correctly
262 [ $last_index -gt 0 ] && shift $last_index
265 # irix is fussy about how it is fed its mount options
266 # - multiple -o's are not allowed
267 # - no spaces between comma delimitered options
268 # the sed script replaces all -o's (except the first) with a comma
269 # not required for linux, but won't hurt
271 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
272 | sed -e 's/dmapi/dmi/' \
273 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
277 _scratch_mount_options()
279 _scratch_options mount
281 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
286 _mount -t $FSTYP `_scratch_mount_options $*`
291 $UMOUNT_PROG $SCRATCH_DEV
303 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
306 _scratch_mkfs_options()
308 _scratch_options mkfs
309 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
313 _setup_large_xfs_fs()
318 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
319 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
320 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
322 # calculate the size of the file we need to allocate.
323 # Default free space in the FS is 50GB, but you can specify more via
324 # SCRATCH_DEV_EMPTY_SPACE
325 file_size=$(($fs_size - 50*1024*1024*1024))
326 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
328 # mount the filesystem, create the file, unmount it
329 _scratch_mount 2>&1 >$tmp_dir/mnt.err
331 if [ $status -ne 0 ]; then
333 cat $tmp_dir/mnt.err >&2
334 rm -f $tmp_dir/mnt.err
337 rm -f $tmp_dir/mnt.err
340 -c "truncate $file_size" \
341 -c "falloc -k 0 $file_size" \
343 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
344 export NUM_SPACE_FILES=1
347 if [ $status -ne 0 ]; then
348 echo "large file prealloc failed"
349 cat $tmp_dir/mnt.err >&2
357 # extra mkfs options can be added by tests
358 local extra_mkfs_options=$*
362 _scratch_options mkfs
364 # save mkfs output in case conflict means we need to run again.
365 # only the output for the mkfs that applies should be shown
366 $MKFS_XFS_PROG $SCRATCH_OPTIONS $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
367 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
370 # a mkfs failure may be caused by conflicts between
371 # $MKFS_OPTIONS and $extra_mkfs_options
373 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
374 echo "** mkfs failed with extra mkfs options added to \"$MKFS_OPTIONS\" by test $seq **" \
376 echo "** attempting to mkfs using only test $seq options: $extra_mkfs_options **" \
378 # running mkfs again. overwrite previous mkfs output files
379 $MKFS_XFS_PROG $SCRATCH_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
380 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
384 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
385 # manually parse the mkfs output to get the fs size in bytes
387 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
388 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
390 print STDOUT "$size\n";
392 _setup_large_xfs_fs $fs_size
396 # output stored mkfs output
397 cat $tmp_dir.mkfserr >&2
399 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
404 # xfs_check script is planned to be deprecated. But, we want to
405 # be able to invoke "xfs_check" behavior in xfstests in order to
406 # maintain the current verification levels.
411 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
413 while getopts "b:fi:l:stvV" c
419 i) OPTS=$OPTS"-i "$OPTARG" ";;
420 b) OPTS=$OPTS"-b "$OPTARG" ";;
421 f) DBOPTS=$DBOPTS" -f";;
422 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
423 V) $XFS_DB_PROG -p xfs_check -V
431 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
441 _setup_large_ext4_fs()
446 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
447 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
448 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
450 # Default free space in the FS is 50GB, but you can specify more via
451 # SCRATCH_DEV_EMPTY_SPACE
452 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
454 # mount the filesystem and create 16TB - 4KB files until we consume
455 # all the necessary space.
456 _scratch_mount 2>&1 >$tmp_dir/mnt.err
458 if [ $status -ne 0 ]; then
460 cat $tmp_dir/mnt.err >&2
461 rm -f $tmp_dir/mnt.err
464 rm -f $tmp_dir/mnt.err
466 file_size=$((16*1024*1024*1024*1024 - 4096))
468 while [ $space_to_consume -gt $file_size ]; do
471 -c "truncate $file_size" \
472 -c "falloc -k 0 $file_size" \
473 $SCRATCH_MNT/.use_space.$nfiles 2>&1
475 if [ $status -ne 0 ]; then
479 space_to_consume=$(( $space_to_consume - $file_size ))
480 nfiles=$(($nfiles + 1))
483 # consume the remaining space.
484 if [ $space_to_consume -gt 0 ]; then
486 -c "truncate $space_to_consume" \
487 -c "falloc -k 0 $space_to_consume" \
488 $SCRATCH_MNT/.use_space.$nfiles 2>&1
491 export NUM_SPACE_FILES=$nfiles
494 if [ $status -ne 0 ]; then
495 echo "large file prealloc failed"
496 cat $tmp_dir/mnt.err >&2
505 /sbin/mkfs -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV \
506 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
509 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
510 # manually parse the mkfs output to get the fs size in bytes
511 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
512 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
513 / inodes, / { blks = $3 } \
514 /reserved for the super user/ { resv = $1 } \
515 END { fssize = bs * blks - resv; print fssize }'`
517 _setup_large_ext4_fs $fs_size
521 # output stored mkfs output
522 cat $tmp_dir.mkfserr >&2
524 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
539 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
542 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
545 _scratch_mkfs_ext4 $*
548 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
557 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
560 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
565 # Create fs of certain size on scratch device
566 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
567 _scratch_mkfs_sized()
571 [ -z "$blocksize" ] && blocksize=4096
574 if ! [[ $fssize =~ $re ]] ; then
575 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
577 if ! [[ $blocksize =~ $re ]] ; then
578 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
581 blocks=`expr $fssize / $blocksize`
583 if [ "$HOSTOS" == "Linux" ]; then
584 devsize=`blockdev --getsize64 $SCRATCH_DEV`
585 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
590 # don't override MKFS_OPTIONS that set a block size.
591 echo $MKFS_OPTIONS |egrep -q "b?size="
592 if [ $? -eq 0 ]; then
593 _scratch_mkfs_xfs -d size=$fssize
595 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
598 ext2|ext3|ext4|ext4dev)
599 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
602 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
605 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
610 # Emulate an N-data-disk stripe w/ various stripe units
611 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
617 [ -z "$blocksize" ] && blocksize=4096
619 let sunit_blocks=$sunit_bytes/$blocksize
620 let swidth_blocks=$sunit_blocks*$swidth_mult
624 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
627 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
630 _notrun "can't mkfs $FSTYP with geometry"
640 xfs_io -x -c "resblks $1" $SCRATCH_MNT
647 _scratch_xfs_db_options()
650 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
651 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
652 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
655 _scratch_xfs_logprint()
658 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
659 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
660 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
666 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
667 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
668 [ "$LARGE_SCRATCH_DEV" = yes ] && \
669 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
670 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
673 _scratch_xfs_repair()
676 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
677 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
678 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
679 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
680 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
681 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
688 echo "Usage: _get_pids_by_name process-name" 1>&2
692 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
693 # HH:MM:SS before the psargs field, use this as the search anchor.
695 # Matches with $1 (process-name) occur if the first psarg is $1
696 # or ends in /$1 ... the matching uses sed's regular expressions,
697 # so passing a regex into $1 will work.
705 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
706 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
709 # fix malloc libs output
713 # filter out the Electric Fence notice
716 if (defined $o && /^\s+Electric Fence/) {
722 print $o if (defined $o);
726 print $o if (defined $o);
730 # check if run as root
734 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
737 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
744 # _df_device : get an IRIX style df line for a given device
746 # - returns "" if not mounted
747 # - returns fs type in field two (ala IRIX)
748 # - joins line together if split by fancy df formatting
749 # - strips header etc
756 echo "Usage: _df_device device" 1>&2
760 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
761 match($1,what) && NF==1 {
775 # _df_dir : get an IRIX style df line for device where a directory resides
777 # - returns fs type in field two (ala IRIX)
778 # - joins line together if split by fancy df formatting
779 # - strips header etc
786 echo "Usage: _df_dir device" 1>&2
790 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
806 # return percentage used disk space for mounted device
812 echo "Usage: _used device" 1>&2
816 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
819 # return the FS type of a mounted device
825 echo "Usage: _fs_type device" 1>&2
830 # The Linux kernel shows NFSv4 filesystems in df output as
831 # filesystem type nfs4, although we mounted it as nfs earlier.
832 # Fix the filesystem type up here so that the callers don't
833 # have to bother with this quirk.
835 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
838 # return the FS mount options of a mounted device
840 # should write a version which just parses the output of mount for IRIX
841 # compatibility, but since this isn't used at all, at the moment I'll leave
848 echo "Usage: _fs_options device" 1>&2
852 $AWK_PROG -v dev=$1 '
853 match($1,dev) { print $4 }
857 # returns device number if a file is a block device
863 echo "Usage: _is_block_dev dev" 1>&2
868 if [ -L "${_dev}" ]; then
869 _dev=`readlink -f ${_dev}`
872 if [ -b "${_dev}" ]; then
873 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
877 # Do a command, log it to $seqres.full, optionally test return status
878 # and die if command fails. If called with one argument _do executes the
879 # command, logs it, and returns its exit status. With two arguments _do
880 # first prints the message passed in the first argument, and then "done"
881 # or "fail" depending on the return status of the command passed in the
882 # second argument. If the command fails and the variable _do_die_on_error
883 # is set to "always" or the two argument form is used and _do_die_on_error
884 # is set to "message_only" _do will print an error message to
885 # $seqres.out and exit.
889 if [ $# -eq 1 ]; then
891 elif [ $# -eq 2 ]; then
896 echo "Usage: _do [note] cmd" 1>&2
900 (eval "echo '---' \"$_cmd\"") >>$seqres.full
901 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
902 cat $tmp._out | _fix_malloc >>$seqres.full
903 if [ $# -eq 2 ]; then
904 if [ $ret -eq 0 ]; then
911 && [ "$_do_die_on_error" = "always" \
912 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
915 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
922 # bail out, setting up .notrun file
926 echo "$*" > $seqres.notrun
927 echo "$seq not run: $*"
932 # just plain bail out
936 echo "$*" | tee -a $seqres.full
937 echo "(see $seqres.full for details)"
942 # tests whether $FSTYP is one of the supported filesystems for a test
948 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
954 _notrun "not suitable for this filesystem type: $FSTYP"
957 # tests whether $FSTYP is one of the supported OSes for a test
963 if [ "$h" = "$HOSTOS" ]
969 _notrun "not suitable for this OS: $HOSTOS"
972 # this test needs a scratch partition - check we're ok & unmount it
978 _notrun "requires a scratch device"
981 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
983 _notrun "this test requires a valid \$SCRATCH_DEV"
985 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
987 _notrun "this test requires a valid \$SCRATCH_DEV"
989 if [ ! -d "$SCRATCH_MNT" ]
991 _notrun "this test requires a valid \$SCRATCH_MNT"
997 if _mount | grep -q $SCRATCH_DEV
999 # if it's mounted, make sure its on $SCRATCH_MNT
1000 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1002 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1005 # and then unmount it
1006 if ! $UMOUNT_PROG $SCRATCH_DEV
1008 echo "failed to unmount $SCRATCH_DEV"
1014 # this test needs a logdev
1018 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1019 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1020 [ "$USE_EXTERNAL" != yes ] && \
1021 _notrun "This test requires USE_EXTERNAL to be enabled"
1023 # ensure its not mounted
1024 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1027 # this test requires loopback device support
1031 if [ "$HOSTOS" != "Linux" ]
1033 _notrun "This test requires linux for loopback device support"
1036 modprobe loop >/dev/null 2>&1
1037 if grep loop /proc/devices >/dev/null 2>&1
1041 _notrun "This test requires loopback device support"
1045 # this test requires ext2 filesystem support
1049 if [ "$HOSTOS" != "Linux" ]
1051 _notrun "This test requires linux for ext2 filesystem support"
1054 modprobe ext2 >/dev/null 2>&1
1055 if grep ext2 /proc/filesystems >/dev/null 2>&1
1059 _notrun "This test requires ext2 filesystem support"
1063 # this test requires that (large) loopback device files are not in use
1065 _require_no_large_scratch_dev()
1067 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1068 _notrun "Large filesystem testing in progress, skipped this test"
1071 # this test requires that a realtime subvolume is in use, and
1072 # that the kernel supports realtime as well.
1076 [ "$USE_EXTERNAL" = yes ] || \
1077 _notrun "External volumes not in use, skipped this test"
1078 [ "$SCRATCH_RTDEV" = "" ] && \
1079 _notrun "Realtime device required, skipped this test"
1082 # this test requires that a specified command (executable) exists
1083 # $1 - command, $2 - name for error message
1087 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1088 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1091 # this test requires the device mapper flakey target
1093 _require_dm_flakey()
1095 _require_command $DMSETUP_PROG
1097 modprobe dm-flakey >/dev/null 2>&1
1098 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1103 _notrun "This test requires dm flakey support"
1107 # this test requires the projid32bit feature to be available in
1110 _require_projid32bit()
1112 _scratch_mkfs_xfs -f -i projid32bit=0 2>&1 >/dev/null \
1113 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1116 # this test requires that external log/realtime devices are not in use
1118 _require_nonexternal()
1120 [ "$USE_EXTERNAL" = yes ] && \
1121 _notrun "External device testing in progress, skipped this test"
1124 # this test requires that a (specified) aio-dio executable exists
1125 # $1 - command (optional)
1131 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1132 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1134 AIO_TEST=src/aio-dio-regress/$1
1135 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1139 # run an aio-dio program
1145 echo "usage: _run_aiodio command_name" 2>&1
1151 local testtemp=$TEST_DIR/aio-testfile
1153 $AIO_TEST $testtemp 2>&1
1160 # indicate whether YP/NIS is active or not
1165 dn=$(domainname 2>/dev/null)
1166 test -n "${dn}" -a "${dn}" != "(none)"
1170 # cat the password file
1174 [ $(_yp_active) -eq 0 ] && ypcat passwd
1178 # cat the group file
1182 [ $(_yp_active) -eq 0 ] && ypcat group
1186 # check for the fsgqa user on the machine
1191 _cat_passwd | grep -q $qa_user
1192 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1193 echo /bin/true | su $qa_user
1194 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1197 # check for the fsgqa group on the machine
1202 _cat_group | grep -q $qa_group
1203 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1209 s,.*Permission\sdenied.*,Permission denied,;
1210 s,.*no\saccess\sto\stty.*,,;
1211 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1218 if [ "$HOSTOS" == "IRIX" ]
1220 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1222 echo $1 | su $qa_user 2>&1 | _filter_user_do
1226 # check that xfs_io, kernel, and filesystem all support zero
1227 _require_xfs_io_zero()
1229 testio=`$XFS_IO_PROG -c "zero help" 2>&1`
1230 echo $testio | grep -q 'command "zero" not found' && \
1231 _notrun "zero command not supported"
1234 # check that xfs_io, glibc, kernel, and filesystem all (!) support
1237 _require_xfs_io_falloc()
1239 testfile=$TEST_DIR/$$.falloc
1240 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1241 rm -f $testfile 2>&1 > /dev/null
1242 echo $testio | grep -q "not found" && \
1243 _notrun "xfs_io fallocate support is missing"
1244 echo $testio | grep -q "Operation not supported" && \
1245 _notrun "xfs_io fallocate command failed (old kernel/wrong fs?)"
1248 # check that xfs_io, kernel and filesystem all support fallocate with hole
1250 _require_xfs_io_falloc_punch()
1252 testfile=$TEST_DIR/$$.falloc
1253 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1254 -c "fpunch 4k 8k" $testfile 2>&1`
1255 rm -f $testfile 2>&1 > /dev/null
1256 echo $testio | grep -q "not found" && \
1257 _notrun "xfs_io fallocate punch support is missing"
1258 echo $testio | grep -q "Operation not supported" && \
1259 _notrun "xfs_io fallocate punch command failed (no fs support?)"
1262 # check that xfs_io, kernel and filesystem support fiemap
1263 _require_xfs_io_fiemap()
1265 testfile=$TEST_DIR/$$.fiemap
1266 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1267 -c "fiemap -v" $testfile 2>&1`
1268 rm -f $testfile 2>&1 > /dev/null
1269 echo $testio | grep -q "not found" && \
1270 _notrun "xfs_io fiemap support is missing"
1271 echo $testio | grep -q "Operation not supported" && \
1272 _notrun "xfs_io fiemap command failed (no fs support?)"
1275 # Check that a fs has enough free space (in 1024b blocks)
1280 BLOCKS=$2 # in units of 1024
1281 let GB=$BLOCKS/1024/1024
1283 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1284 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1285 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1289 # Check if the filesystem supports sparse files.
1291 # Unfortunately there is no better way to do this than a manual black list.
1293 _require_sparse_files()
1297 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1306 #boot_params always present in debugfs
1307 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1310 _require_fail_make_request()
1312 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1313 || _notrun "$DEBUGFS_MNT/fail_make_request \
1314 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1318 # Check if the file system supports seek_data/hole
1320 _require_seek_data_hole()
1322 testfile=$TEST_DIR/$$.seek
1323 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1324 rm -f $testfile &>/dev/null
1325 echo $testseek | grep -q "Kernel does not support" && \
1326 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1329 # check that a FS on a device is mounted
1330 # if so, return mount point
1336 echo "Usage: _is_mounted device" 1>&2
1342 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1343 pattern { print $3 ; exit 0 }
1347 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1352 # remount a FS to a new mode (ro or rw)
1358 echo "Usage: _remount device ro/rw" 1>&2
1364 if ! mount -o remount,$mode $device
1366 echo "_remount: failed to remount filesystem on $device as $mode"
1371 # Run the appropriate repair/check on a filesystem
1373 # if the filesystem is mounted, it's either remounted ro before being
1374 # checked or it's unmounted and then remounted
1377 # If set, we remount ro instead of unmounting for fsck
1380 _umount_or_remount_ro()
1384 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1389 mountpoint=`_is_mounted $device`
1391 if [ $USE_REMOUNT -eq 0 ]; then
1392 $UMOUNT_PROG $device
1399 _mount_or_remount_rw()
1403 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1410 if [ $USE_REMOUNT -eq 0 ]
1412 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1414 echo "!!! failed to remount $device on $mountpoint"
1424 # Check a generic filesystem in no-op mode; this assumes that the
1425 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1426 # and that it will still return an errno for corruption in this mode.
1428 # Filesystems which don't support this will need to define their
1429 # own check routine.
1431 _check_generic_filesystem()
1435 # If type is set, we're mounted
1436 type=`_fs_type $device`
1439 if [ "$type" = "$FSTYP" ]
1442 mountpoint=`_umount_or_remount_ro $device`
1445 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1448 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1450 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1451 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1452 cat $tmp.fsck >>$seqres.full
1453 echo "*** end fsck.$FSTYP output" >>$seqres.full
1461 echo "*** mount output ***" >>$seqres.full
1462 _mount >>$seqres.full
1463 echo "*** end mount output" >>$seqres.full
1464 elif [ "$type" = "$FSTYP" ]
1467 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1471 if [ $ok -eq 0 ]; then
1479 # run xfs_check and friends on a FS.
1481 _check_xfs_filesystem()
1485 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1489 extra_mount_options=""
1491 if [ "$2" != "none" ]; then
1492 extra_log_options="-l$2"
1493 extra_mount_options="-ologdev=$2"
1496 if [ "$3" != "none" ]; then
1497 extra_rt_options="-r$3"
1498 extra_mount_options=$extra_mount_options" -ortdev=$3"
1500 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1502 [ "$FSTYP" != xfs ] && return 0
1504 type=`_fs_type $device`
1507 if [ "$type" = "xfs" ]
1510 mountpoint=`_umount_or_remount_ro $device`
1513 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1514 | tee $tmp.logprint | grep -q "<CLEAN>"
1515 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1517 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1519 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1520 echo "*** xfs_logprint -t output ***" >>$seqres.full
1521 cat $tmp.logprint >>$seqres.full
1522 echo "*** end xfs_logprint output" >>$seqres.full
1527 # xfs_check runs out of memory on large files, so even providing the test
1528 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1529 # large filesystems. Avoid it.
1530 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1531 _xfs_check $extra_log_options $device 2>&1 |\
1532 _fix_malloc >$tmp.fs_check
1534 if [ -s $tmp.fs_check ]
1536 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1538 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1539 echo "*** xfs_check output ***" >>$seqres.full
1540 cat $tmp.fs_check >>$seqres.full
1541 echo "*** end xfs_check output" >>$seqres.full
1546 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1549 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1551 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1552 echo "*** xfs_repair -n output ***" >>$seqres.full
1553 cat $tmp.repair | _fix_malloc >>$seqres.full
1554 echo "*** end xfs_repair output" >>$seqres.full
1558 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1562 echo "*** mount output ***" >>$seqres.full
1563 _mount >>$seqres.full
1564 echo "*** end mount output" >>$seqres.full
1565 elif [ "$type" = "xfs" ]
1567 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1570 if [ $ok -eq 0 ]; then
1578 # Filter the knowen errors the UDF Verifier reports.
1579 _udf_test_known_error_filter()
1581 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."
1585 _check_udf_filesystem()
1587 [ "$DISABLE_UDF_TEST" == "1" ] && return
1589 if [ $# -ne 1 -a $# -ne 2 ]
1591 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1595 if [ ! -x $here/src/udf_test ]
1597 echo "udf_test not installed, please download and build the Philips"
1598 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1599 echo "Then copy the udf_test binary to $here/src/."
1600 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1608 LAST_BLOCK=`expr \( $2 - 1 \)`
1609 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1612 rm -f $seqres.checkfs
1613 sleep 1 # Due to a problem with time stamps in udf_test
1614 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1615 _udf_test_known_error_filter | \
1616 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" | \
1617 sed "s/^.*$/Warning UDF Verifier reported errors see $seqres.checkfs./g"
1621 _check_xfs_test_fs()
1625 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1626 TEST_LOG="$TEST_LOGDEV"
1628 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1629 TEST_RT="$TEST_RTDEV"
1631 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1633 # check for ipath consistency
1634 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1635 # errors go to stderr
1636 xfs_check_ipaths $TEST_DIR >/dev/null
1637 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1641 _check_btrfs_filesystem()
1645 # If type is set, we're mounted
1646 type=`_fs_type $device`
1649 if [ "$type" = "$FSTYP" ]
1652 mountpoint=`_umount_or_remount_ro $device`
1655 btrfsck $device >$tmp.fsck 2>&1
1658 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1660 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1661 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1662 cat $tmp.fsck >>$seqres.full
1663 echo "*** end fsck.$FSTYP output" >>$seqres.full
1671 echo "*** mount output ***" >>$seqres.full
1672 _mount >>$seqres.full
1673 echo "*** end mount output" >>$seqres.full
1674 elif [ "$type" = "$FSTYP" ]
1677 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1681 if [ $ok -eq 0 ]; then
1696 # no way to check consistency for nfs
1699 # do nothing for now
1702 _check_btrfs_filesystem $TEST_DEV
1705 _check_generic_filesystem $TEST_DEV
1713 [ $# -eq 1 ] && device=$1
1719 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1720 SCRATCH_LOG="$SCRATCH_LOGDEV"
1722 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1723 SCRATCH_RT="$SCRATCH_RTDEV"
1725 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1728 _check_udf_filesystem $device $udf_fsize
1731 # Don't know how to check an NFS filesystem, yet.
1734 _check_btrfs_filesystem $device
1737 _check_generic_filesystem $device
1742 _full_fstyp_details()
1744 [ -z "$FSTYP" ] && FSTYP=xfs
1745 if [ $FSTYP = xfs ]; then
1746 if [ -d /proc/fs/xfs ]; then
1747 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1748 FSTYP="$FSTYP (non-debug)"
1749 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1750 FSTYP="$FSTYP (debug)"
1753 if uname -a | grep -qi 'debug'; then
1754 FSTYP="$FSTYP (debug)"
1756 FSTYP="$FSTYP (non-debug)"
1763 _full_platform_details()
1769 echo "$os/$platform $host $kernel"
1774 if [ -z "$1" -o -z "$2" ]; then
1775 echo Error must pass src and dst.
1779 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1781 elif [ "`uname`" == "Linux" ]; then
1784 echo Error test $seq does not run on the operating system: `uname`
1795 #takes files, randomdata
1803 if [ $size -gt 0 ]; then
1804 if [ "$2" == "false" ]; then
1805 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
1807 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
1814 # takes dirname, depth, randomdata
1817 dirname=$1; depth=$2; randomdata=$3
1818 mkdir $dirname || die "mkdir $dirname failed"
1821 _nfiles $files $randomdata # files for this dir and data type
1823 [ $depth -eq 0 ] && return
1824 let deep=$depth-1 # go 1 down
1826 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
1829 while [ $d -lt $dirs ]
1831 _descend d$d $deep &
1837 # Populate a filesystem with inodes for performance experiments
1839 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
1844 dirs=5 # ndirs in each subdir till leaves
1845 size=0 # sizeof files in K
1846 files=100 # num files in _each_ subdir
1847 depth=2 # depth of tree from root to leaves
1849 root=root # path of initial root of directory tree
1850 randomdata=false # -x data type urandom or zero
1853 while getopts "d:f:n:r:s:v:x" c
1862 x) randomdata=true;;
1866 _descend $root $depth $randomdata
1871 [ $verbose = true ] && echo done
1874 # query whether the given file has the given inode flag set
1881 if which $XFS_IO_PROG >/dev/null; then
1882 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
1889 # query the given files extsize allocator hint in bytes (if any)
1896 if which $XFS_IO_PROG >/dev/null; then
1897 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
1898 awk '/^xattr.extsize =/ { print $3 }'`
1900 [ -z "$blocks" ] && blocks="0"
1904 # scratch_dev_pool should contain the disks pool for the btrfs raid
1905 _require_scratch_dev_pool()
1908 if [ -z "$SCRATCH_DEV_POOL" ]; then
1909 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
1912 # btrfs test case needs 2 or more scratch_dev_pool; other FS not sure
1916 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt 2 ]; then
1917 _notrun "btrfs and this test needs 2 or more disks in SCRATCH_DEV_POOL"
1921 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
1925 for i in $SCRATCH_DEV_POOL; do
1926 if [ "`_is_block_dev $i`" = "" ]; then
1927 _notrun "this test requires valid block disk $i"
1929 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
1930 _notrun "$i is part of TEST_DEV, this test requires unique disks"
1932 if _mount | grep -q $i; then
1933 if ! $UMOUNT_PROG $i; then
1934 echo "failed to unmount $i - aborting"
1938 # to help better debug when something fails, we remove
1939 # traces of previous btrfs FS on the dev.
1940 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
1944 # We will check if the device is virtual (eg: loop device) since it does not
1945 # have the delete entry-point. Otherwise SCSI and USB devices are fine.
1946 _require_deletable_scratch_dev_pool()
1950 for i in $SCRATCH_DEV_POOL; do
1951 x=`echo $i | cut -d"/" -f 3`
1952 ls -l /sys/class/block/${x} | grep -q "virtual"
1953 if [ $? == "0" ]; then
1954 _notrun "$i is a virtual device which is not deletable"
1959 # We check for btrfs and (optionally) features of the btrfs command
1963 _require_command $BTRFS_UTIL_PROG btrfs
1964 if [ -z "$1" ]; then
1967 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
1968 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
1971 # Check that fio is present, and it is able to execute given jobfile
1976 _require_command $FIO_PROG
1977 if [ -z "$1" ]; then
1981 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
1982 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
1985 # Does freeze work on this fs?
1988 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
1990 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
1991 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
1994 # arg 1 is dev to remove and is output of the below eg.
1995 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2001 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2003 stat $disk > /dev/null 2>&1
2004 while [ $? -eq 0 ]; do
2006 stat $disk > /dev/null 2>&1
2010 # arg 1 is dev to add and is output of the below eg.
2011 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2016 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2017 h=`echo ${1} | cut -d":" -f 1`
2018 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2020 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2025 if [ -z "$FSTRIM_PROG" ]; then
2026 _notrun "This test requires fstrim utility."
2030 _test_batched_discard()
2032 if [ $# -ne 1 ]; then
2033 echo "Usage: _test_batched_discard mnt_point" 1>&2
2037 $FSTRIM_PROG ${1} &>/dev/null
2042 if [ -z "$DUMPE2FS_PROG" ]; then
2043 _notrun "This test requires dumpe2fs utility."
2049 if [ ! -e /proc/self/uid_map ]; then
2050 _notrun "This test requires procfs uid_map support."
2052 if [ ! -e /proc/self/gid_map ]; then
2053 _notrun "This test requires procfs gid_map support."
2057 _create_loop_device()
2060 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2064 _destroy_loop_device()
2067 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2070 _scale_fsstress_args()
2073 while [ $# -gt 0 ]; do
2075 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2076 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2077 *) args="$args $1" ;;
2085 # Return the logical block size if running on a block device,
2086 # else substitute the page size.
2088 _min_dio_alignment()
2092 if [ -b "$dev" ]; then
2093 blockdev --getss $dev
2095 $here/src/feature -s
2101 echo "# $@" >> $seqres.full 2>&1
2102 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2107 if [ "$iam" == new ]
2111 # make some further configuration checks here
2112 if [ "$TEST_DEV" = "" ]
2114 echo "common/rc: Error: \$TEST_DEV is not set"
2118 # if $TEST_DEV is not mounted, mount it now as XFS
2119 if [ -z "`_fs_type $TEST_DEV`" ]
2121 # $TEST_DEV is not mounted
2124 echo "common/rc: retrying test device mount with external set"
2125 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2128 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2134 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2136 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2140 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2141 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2142 export XFS_IO_PROG="$XFS_IO_PROG -F"
2147 ################################################################################
2148 # make sure this script returns success