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 $@
60 # Prints the md5 checksum of a given file
63 md5sum $1 | cut -d ' ' -f1
67 # ls -l w/ selinux sometimes puts a dot at the end:
68 # -rwxrw-r--. id1 id2 file1
72 ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /"
77 # SELinux adds extra xattrs which can mess up our expected output.
78 # So, mount with a context, and they won't be created
79 # nfs_t is a "liberal" context so we can use it.
80 if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
81 SELINUX_MOUNT_OPTIONS="-o context=system_u:object_r:nfs_t:s0"
82 export SELINUX_MOUNT_OPTIONS
87 export MOUNT_OPTIONS=$XFS_MOUNT_OPTIONS
90 export MOUNT_OPTIONS=$UDF_MOUNT_OPTIONS
93 export MOUNT_OPTIONS=$NFS_MOUNT_OPTIONS
95 ext2|ext3|ext4|ext4dev)
96 # acls & xattrs aren't turned on by default on ext$FOO
97 export MOUNT_OPTIONS="-o acl,user_xattr $EXT_MOUNT_OPTIONS"
100 # acls & xattrs aren't turned on by default on reiserfs
101 export MOUNT_OPTIONS="-o acl,user_xattr $REISERFS_MOUNT_OPTIONS"
104 # acls aren't turned on by default on gfs2
105 export MOUNT_OPTIONS="-o acl $GFS2_MOUNT_OPTIONS"
116 export MKFS_OPTIONS=$XFS_MKFS_OPTIONS
119 [ ! -z "$udf_fsize" ] && \
120 UDF_MKFS_OPTIONS="$UDF_MKFS_OPTIONS -s $udf_fsize"
121 export MKFS_OPTIONS=$UDF_MKFS_OPTIONS
124 export MKFS_OPTIONS=$NFS_MKFS_OPTIONS
127 export MKFS_OPTIONS="$REISERFS_MKFS_OPTIONS -q"
130 export MKFS_OPTIONS="$GFS2_MKFS_OPTIONS -O -p lock_nolock"
133 export MKFS_OPTIONS="$JFS_MKFS_OPTIONS -q"
143 ext2|ext3|ext4|ext4dev)
144 export FSCK_OPTIONS="-nf"
147 export FSCK_OPTIONS="--yes"
150 export FSCK_OPTIONS="-n"
155 [ -z "$FSTYP" ] && FSTYP=xfs
156 [ -z "$MOUNT_OPTIONS" ] && _mount_opts
157 [ -z "$MKFS_OPTIONS" ] && _mkfs_opts
158 [ -z "$FSCK_OPTIONS" ] && _fsck_opts
161 # we need common/config
162 if [ "$iam" != "check" ]
164 if ! . ./common/config
166 echo "$iam: failed to source common/config"
171 # check for correct setup
174 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
175 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
176 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
177 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
180 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
183 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
189 # make sure we have a standard umask
194 $MOUNT_PROG `_mount_ops_filter $*`
202 if [ "$FSTYP" != "xfs" ]; then
208 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
217 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
218 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
219 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
220 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
228 if [ "$FSTYP" != "xfs" ]; then
242 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
243 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
244 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
245 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
252 #get mount point to handle dmapi mtpt option correctly
254 [ $last_index -gt 0 ] && shift $last_index
257 # irix is fussy about how it is fed its mount options
258 # - multiple -o's are not allowed
259 # - no spaces between comma delimitered options
260 # the sed script replaces all -o's (except the first) with a comma
261 # not required for linux, but won't hurt
263 echo $params | sed -e 's/[[:space:]]*-o[[:space:]]*/UnIqUe/1; s/[[:space:]]*-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
264 | sed -e 's/dmapi/dmi/' \
265 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
269 _scratch_mount_options()
271 _scratch_options mount
273 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
278 _mount -t $FSTYP `_scratch_mount_options $*`
283 $UMOUNT_PROG $SCRATCH_DEV
295 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
298 _scratch_mkfs_options()
300 _scratch_options mkfs
301 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
305 _setup_large_xfs_fs()
310 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
311 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
312 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
314 # calculate the size of the file we need to allocate.
315 # Default free space in the FS is 50GB, but you can specify more via
316 # SCRATCH_DEV_EMPTY_SPACE
317 file_size=$(($fs_size - 50*1024*1024*1024))
318 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
320 # mount the filesystem, create the file, unmount it
321 _scratch_mount 2>&1 >$tmp_dir/mnt.err
323 if [ $status -ne 0 ]; then
325 cat $tmp_dir/mnt.err >&2
326 rm -f $tmp_dir/mnt.err
329 rm -f $tmp_dir/mnt.err
332 -c "truncate $file_size" \
333 -c "falloc -k 0 $file_size" \
335 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
336 export NUM_SPACE_FILES=1
339 if [ $status -ne 0 ]; then
340 echo "large file prealloc failed"
341 cat $tmp_dir/mnt.err >&2
349 # extra mkfs options can be added by tests
350 local extra_mkfs_options=$*
354 _scratch_options mkfs
356 # save mkfs output in case conflict means we need to run again.
357 # only the output for the mkfs that applies should be shown
358 $MKFS_XFS_PROG $SCRATCH_OPTIONS $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
359 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
362 # a mkfs failure may be caused by conflicts between
363 # $MKFS_OPTIONS and $extra_mkfs_options
365 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
366 echo "** mkfs failed with extra mkfs options added to \"$MKFS_OPTIONS\" by test $seq **" \
368 echo "** attempting to mkfs using only test $seq options: $extra_mkfs_options **" \
370 # running mkfs again. overwrite previous mkfs output files
371 $MKFS_XFS_PROG $SCRATCH_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
372 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
376 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
377 # manually parse the mkfs output to get the fs size in bytes
379 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
380 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
382 print STDOUT "$size\n";
384 _setup_large_xfs_fs $fs_size
388 # output stored mkfs output
389 cat $tmp_dir.mkfserr >&2
391 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
396 # xfs_check script is planned to be deprecated. But, we want to
397 # be able to invoke "xfs_check" behavior in xfstests in order to
398 # maintain the current verification levels.
403 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
405 while getopts "b:fi:l:stvV" c
411 i) OPTS=$OPTS"-i "$OPTARG" ";;
412 b) OPTS=$OPTS"-b "$OPTARG" ";;
413 f) DBOPTS=$DBOPTS" -f";;
414 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
415 V) $XFS_DB_PROG -p xfs_check -V
423 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
433 _setup_large_ext4_fs()
438 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
439 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
440 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
442 # Default free space in the FS is 50GB, but you can specify more via
443 # SCRATCH_DEV_EMPTY_SPACE
444 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
446 # mount the filesystem and create 16TB - 4KB files until we consume
447 # all the necessary space.
448 _scratch_mount 2>&1 >$tmp_dir/mnt.err
450 if [ $status -ne 0 ]; then
452 cat $tmp_dir/mnt.err >&2
453 rm -f $tmp_dir/mnt.err
456 rm -f $tmp_dir/mnt.err
458 file_size=$((16*1024*1024*1024*1024 - 4096))
460 while [ $space_to_consume -gt $file_size ]; do
463 -c "truncate $file_size" \
464 -c "falloc -k 0 $file_size" \
465 $SCRATCH_MNT/.use_space.$nfiles 2>&1
467 if [ $status -ne 0 ]; then
471 space_to_consume=$(( $space_to_consume - $file_size ))
472 nfiles=$(($nfiles + 1))
475 # consume the remaining space.
476 if [ $space_to_consume -gt 0 ]; then
478 -c "truncate $space_to_consume" \
479 -c "falloc -k 0 $space_to_consume" \
480 $SCRATCH_MNT/.use_space.$nfiles 2>&1
483 export NUM_SPACE_FILES=$nfiles
486 if [ $status -ne 0 ]; then
487 echo "large file prealloc failed"
488 cat $tmp_dir/mnt.err >&2
497 /sbin/mkfs -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV \
498 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
501 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
502 # manually parse the mkfs output to get the fs size in bytes
503 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
504 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
505 / inodes, / { blks = $3 } \
506 /reserved for the super user/ { resv = $1 } \
507 END { fssize = bs * blks - resv; print fssize }'`
509 _setup_large_ext4_fs $fs_size
513 # output stored mkfs output
514 cat $tmp_dir.mkfserr >&2
516 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
531 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
534 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
537 _scratch_mkfs_ext4 $*
540 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
545 # Create fs of certain size on scratch device
546 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
547 _scratch_mkfs_sized()
551 [ -z "$blocksize" ] && blocksize=4096
552 blocks=`expr $fssize / $blocksize`
554 if [ "$HOSTOS" == "Linux" ]; then
555 devsize=`blockdev --getsize64 $SCRATCH_DEV`
556 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
561 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
563 ext2|ext3|ext4|ext4dev)
564 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
567 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
570 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
575 # Emulate an N-data-disk stripe w/ various stripe units
576 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
582 [ -z "$blocksize" ] && blocksize=4096
584 let sunit_blocks=$sunit_bytes/$blocksize
585 let swidth_blocks=$sunit_blocks*$swidth_mult
589 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
592 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
595 _notrun "can't mkfs $FSTYP with geometry"
605 xfs_io -x -c "resblks $1" $SCRATCH_MNT
612 _scratch_xfs_db_options()
615 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
616 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
617 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
620 _scratch_xfs_logprint()
623 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
624 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
625 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
631 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
632 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
633 [ "$LARGE_SCRATCH_DEV" = yes ] && \
634 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
635 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
638 _scratch_xfs_repair()
641 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
642 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
643 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
644 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
645 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
646 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
653 echo "Usage: _get_pids_by_name process-name" 1>&2
657 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
658 # HH:MM:SS before the psargs field, use this as the search anchor.
660 # Matches with $1 (process-name) occur if the first psarg is $1
661 # or ends in /$1 ... the matching uses sed's regular expressions,
662 # so passing a regex into $1 will work.
670 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
671 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
674 # fix malloc libs output
678 # filter out the Electric Fence notice
681 if (defined $o && /^\s+Electric Fence/) {
687 print $o if (defined $o);
691 print $o if (defined $o);
695 # check if run as root
699 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
702 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
709 # _df_device : get an IRIX style df line for a given device
711 # - returns "" if not mounted
712 # - returns fs type in field two (ala IRIX)
713 # - joins line together if split by fancy df formatting
714 # - strips header etc
721 echo "Usage: _df_device device" 1>&2
725 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
726 match($1,what) && NF==1 {
740 # _df_dir : get an IRIX style df line for device where a directory resides
742 # - returns fs type in field two (ala IRIX)
743 # - joins line together if split by fancy df formatting
744 # - strips header etc
751 echo "Usage: _df_dir device" 1>&2
755 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
771 # return percentage used disk space for mounted device
777 echo "Usage: _used device" 1>&2
781 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
784 # return the FS type of a mounted device
790 echo "Usage: _fs_type device" 1>&2
795 # The Linux kernel shows NFSv4 filesystems in df output as
796 # filesystem type nfs4, although we mounted it as nfs earlier.
797 # Fix the filesystem type up here so that the callers don't
798 # have to bother with this quirk.
800 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
803 # return the FS mount options of a mounted device
805 # should write a version which just parses the output of mount for IRIX
806 # compatibility, but since this isn't used at all, at the moment I'll leave
813 echo "Usage: _fs_options device" 1>&2
817 $AWK_PROG -v dev=$1 '
818 match($1,dev) { print $4 }
822 # returns device number if a file is a block device
828 echo "Usage: _is_block_dev dev" 1>&2
833 if [ -L "${_dev}" ]; then
834 _dev=`readlink -f ${_dev}`
837 if [ -b "${_dev}" ]; then
838 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
842 # Do a command, log it to $seqres.full, optionally test return status
843 # and die if command fails. If called with one argument _do executes the
844 # command, logs it, and returns its exit status. With two arguments _do
845 # first prints the message passed in the first argument, and then "done"
846 # or "fail" depending on the return status of the command passed in the
847 # second argument. If the command fails and the variable _do_die_on_error
848 # is set to "always" or the two argument form is used and _do_die_on_error
849 # is set to "message_only" _do will print an error message to
850 # $seqres.out and exit.
854 if [ $# -eq 1 ]; then
856 elif [ $# -eq 2 ]; then
861 echo "Usage: _do [note] cmd" 1>&2
865 (eval "echo '---' \"$_cmd\"") >>$seqres.full
866 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
867 cat $tmp._out | _fix_malloc >>$seqres.full
868 if [ $# -eq 2 ]; then
869 if [ $ret -eq 0 ]; then
876 && [ "$_do_die_on_error" = "always" \
877 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
880 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
887 # bail out, setting up .notrun file
891 echo "$*" > $seqres.notrun
892 echo "$seq not run: $*"
897 # just plain bail out
901 echo "$*" | tee -a $seqres.full
902 echo "(see $seqres.full for details)"
907 # tests whether $FSTYP is one of the supported filesystems for a test
913 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
919 _notrun "not suitable for this filesystem type: $FSTYP"
922 # tests whether $FSTYP is one of the supported OSes for a test
928 if [ "$h" = "$HOSTOS" ]
934 _notrun "not suitable for this OS: $HOSTOS"
937 # this test needs a scratch partition - check we're ok & unmount it
943 echo $SCRATCH_DEV | grep -q ":" > /dev/null 2>&1
944 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]
946 _notrun "this test requires a valid \$SCRATCH_DEV"
950 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
952 _notrun "this test requires a valid \$SCRATCH_DEV"
954 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
956 _notrun "this test requires a valid \$SCRATCH_DEV"
958 if [ ! -d "$SCRATCH_MNT" ]
960 _notrun "this test requires a valid \$SCRATCH_MNT"
966 if _mount | grep -q $SCRATCH_DEV
968 # if it's mounted, make sure its on $SCRATCH_MNT
969 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
971 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
974 # and then unmount it
975 if ! $UMOUNT_PROG $SCRATCH_DEV
977 echo "failed to unmount $SCRATCH_DEV"
983 # this test needs a logdev
987 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
988 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
989 [ "$USE_EXTERNAL" != yes ] && \
990 _notrun "This test requires USE_EXTERNAL to be enabled"
992 # ensure its not mounted
993 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
996 # this test requires loopback device support
1000 if [ "$HOSTOS" != "Linux" ]
1002 _notrun "This test requires linux for loopback device support"
1005 modprobe loop >/dev/null 2>&1
1006 if grep loop /proc/devices >/dev/null 2>&1
1010 _notrun "This test requires loopback device support"
1014 # this test requires ext2 filesystem support
1018 if [ "$HOSTOS" != "Linux" ]
1020 _notrun "This test requires linux for ext2 filesystem support"
1023 modprobe ext2 >/dev/null 2>&1
1024 if grep ext2 /proc/filesystems >/dev/null 2>&1
1028 _notrun "This test requires ext2 filesystem support"
1032 # this test requires that (large) loopback device files are not in use
1034 _require_no_large_scratch_dev()
1036 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1037 _notrun "Large filesystem testing in progress, skipped this test"
1040 # this test requires that a realtime subvolume is in use, and
1041 # that the kernel supports realtime as well.
1045 [ "$USE_EXTERNAL" = yes ] || \
1046 _notrun "External volumes not in use, skipped this test"
1047 [ "$SCRATCH_RTDEV" = "" ] && \
1048 _notrun "Realtime device required, skipped this test"
1051 # this test requires that a specified command (executable) exists
1052 # $1 - command, $2 - name for error message
1056 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1057 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1060 # this test requires the device mapper flakey target
1062 _require_dm_flakey()
1064 _require_command $DMSETUP_PROG
1066 modprobe dm-flakey >/dev/null 2>&1
1067 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1072 _notrun "This test requires dm flakey support"
1076 # this test requires the projid32bit feature to be available in
1079 _require_projid32bit()
1081 _scratch_mkfs_xfs -f -i projid32bit=0 2>&1 >/dev/null \
1082 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1085 # this test requires that external log/realtime devices are not in use
1087 _require_nonexternal()
1089 [ "$USE_EXTERNAL" = yes ] && \
1090 _notrun "External device testing in progress, skipped this test"
1093 # this test requires that a (specified) aio-dio executable exists
1094 # $1 - command (optional)
1100 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1101 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1103 AIO_TEST=src/aio-dio-regress/$1
1104 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1108 # run an aio-dio program
1114 echo "usage: _run_aiodio command_name" 2>&1
1120 local testtemp=$TEST_DIR/aio-testfile
1122 $AIO_TEST $testtemp 2>&1
1129 # indicate whether YP/NIS is active or not
1134 dn=$(domainname 2>/dev/null)
1135 test -n "${dn}" -a "${dn}" != "(none)"
1139 # cat the password file
1143 [ $(_yp_active) -eq 0 ] && ypcat passwd
1147 # cat the group file
1151 [ $(_yp_active) -eq 0 ] && ypcat group
1155 # check for the fsgqa user on the machine
1160 _cat_passwd | grep -q $qa_user
1161 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1162 echo /bin/true | su $qa_user
1163 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1166 # check for the fsgqa group on the machine
1171 _cat_group | grep -q $qa_group
1172 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1178 s,.*Permission\sdenied.*,Permission denied,;
1179 s,.*no\saccess\sto\stty.*,,;
1180 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1187 if [ "$HOSTOS" == "IRIX" ]
1189 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1191 echo $1 | su $qa_user 2>&1 | _filter_user_do
1195 # check that xfs_io, kernel, and filesystem all support zero
1196 _require_xfs_io_zero()
1198 testio=`$XFS_IO_PROG -c "zero help" 2>&1`
1199 echo $testio | grep -q 'command "zero" not found' && \
1200 _notrun "zero command not supported"
1203 # check that xfs_io, glibc, kernel, and filesystem all (!) support
1206 _require_xfs_io_falloc()
1208 testfile=$TEST_DIR/$$.falloc
1209 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1210 rm -f $testfile 2>&1 > /dev/null
1211 echo $testio | grep -q "not found" && \
1212 _notrun "xfs_io fallocate support is missing"
1213 echo $testio | grep -q "Operation not supported" && \
1214 _notrun "xfs_io fallocate command failed (old kernel/wrong fs?)"
1217 # check that xfs_io, kernel and filesystem all support fallocate with hole
1219 _require_xfs_io_falloc_punch()
1221 testfile=$TEST_DIR/$$.falloc
1222 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1223 -c "fpunch 4k 8k" $testfile 2>&1`
1224 rm -f $testfile 2>&1 > /dev/null
1225 echo $testio | grep -q "not found" && \
1226 _notrun "xfs_io fallocate punch support is missing"
1227 echo $testio | grep -q "Operation not supported" && \
1228 _notrun "xfs_io fallocate punch command failed (no fs support?)"
1231 # check that xfs_io, kernel and filesystem support fiemap
1232 _require_xfs_io_fiemap()
1234 testfile=$TEST_DIR/$$.fiemap
1235 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1236 -c "fiemap -v" $testfile 2>&1`
1237 rm -f $testfile 2>&1 > /dev/null
1238 echo $testio | grep -q "not found" && \
1239 _notrun "xfs_io fiemap support is missing"
1240 echo $testio | grep -q "Operation not supported" && \
1241 _notrun "xfs_io fiemap command failed (no fs support?)"
1244 # Check that a fs has enough free space (in 1024b blocks)
1249 BLOCKS=$2 # in units of 1024
1250 let GB=$BLOCKS/1024/1024
1252 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1253 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1254 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1258 # Check if the filesystem supports sparse files.
1260 # Unfortunately there is no better way to do this than a manual black list.
1262 _require_sparse_files()
1266 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1275 #boot_params always present in debugfs
1276 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1279 _require_fail_make_request()
1281 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1282 || _notrun "$DEBUGFS_MNT/fail_make_request \
1283 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1286 # check that a FS on a device is mounted
1287 # if so, return mount point
1293 echo "Usage: _is_mounted device" 1>&2
1299 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1300 pattern { print $3 ; exit 0 }
1304 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1309 # remount a FS to a new mode (ro or rw)
1315 echo "Usage: _remount device ro/rw" 1>&2
1321 if ! mount -o remount,$mode $device
1323 echo "_remount: failed to remount filesystem on $device as $mode"
1328 # Run the appropriate repair/check on a filesystem
1330 # if the filesystem is mounted, it's either remounted ro before being
1331 # checked or it's unmounted and then remounted
1334 # If set, we remount ro instead of unmounting for fsck
1337 _umount_or_remount_ro()
1341 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1346 mountpoint=`_is_mounted $device`
1348 if [ $USE_REMOUNT -eq 0 ]; then
1349 $UMOUNT_PROG $device
1356 _mount_or_remount_rw()
1360 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1367 if [ $USE_REMOUNT -eq 0 ]
1369 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1371 echo "!!! failed to remount $device on $mountpoint"
1381 # Check a generic filesystem in no-op mode; this assumes that the
1382 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1383 # and that it will still return an errno for corruption in this mode.
1385 # Filesystems which don't support this will need to define their
1386 # own check routine.
1388 _check_generic_filesystem()
1392 # If type is set, we're mounted
1393 type=`_fs_type $device`
1396 if [ "$type" = "$FSTYP" ]
1399 mountpoint=`_umount_or_remount_ro $device`
1402 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1405 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1407 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1408 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1409 cat $tmp.fsck >>$seqres.full
1410 echo "*** end fsck.$FSTYP output" >>$seqres.full
1418 echo "*** mount output ***" >>$seqres.full
1419 _mount >>$seqres.full
1420 echo "*** end mount output" >>$seqres.full
1421 elif [ "$type" = "$FSTYP" ]
1424 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1428 if [ $ok -eq 0 ]; then
1436 # run xfs_check and friends on a FS.
1438 _check_xfs_filesystem()
1442 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1446 extra_mount_options=""
1448 if [ "$2" != "none" ]; then
1449 extra_log_options="-l$2"
1450 extra_mount_options="-ologdev=$2"
1453 if [ "$3" != "none" ]; then
1454 extra_rt_options="-r$3"
1455 extra_mount_options=$extra_mount_options" -ortdev=$3"
1457 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1459 [ "$FSTYP" != xfs ] && return 0
1461 type=`_fs_type $device`
1464 if [ "$type" = "xfs" ]
1467 mountpoint=`_umount_or_remount_ro $device`
1470 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1471 | tee $tmp.logprint | grep -q "<CLEAN>"
1472 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1474 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1476 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1477 echo "*** xfs_logprint -t output ***" >>$seqres.full
1478 cat $tmp.logprint >>$seqres.full
1479 echo "*** end xfs_logprint output" >>$seqres.full
1484 # xfs_check runs out of memory on large files, so even providing the test
1485 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1486 # large filesystems. Avoid it.
1487 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1488 _xfs_check $extra_log_options $device 2>&1 |\
1489 _fix_malloc >$tmp.fs_check
1491 if [ -s $tmp.fs_check ]
1493 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1495 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1496 echo "*** xfs_check output ***" >>$seqres.full
1497 cat $tmp.fs_check >>$seqres.full
1498 echo "*** end xfs_check output" >>$seqres.full
1503 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1506 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1508 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1509 echo "*** xfs_repair -n output ***" >>$seqres.full
1510 cat $tmp.repair | _fix_malloc >>$seqres.full
1511 echo "*** end xfs_repair output" >>$seqres.full
1515 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1519 echo "*** mount output ***" >>$seqres.full
1520 _mount >>$seqres.full
1521 echo "*** end mount output" >>$seqres.full
1522 elif [ "$type" = "xfs" ]
1524 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1527 if [ $ok -eq 0 ]; then
1535 # Filter the knowen errors the UDF Verifier reports.
1536 _udf_test_known_error_filter()
1538 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."
1542 _check_udf_filesystem()
1544 [ "$DISABLE_UDF_TEST" == "1" ] && return
1546 if [ $# -ne 1 -a $# -ne 2 ]
1548 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1552 if [ ! -x $here/src/udf_test ]
1554 echo "udf_test not installed, please download and build the Philips"
1555 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1556 echo "Then copy the udf_test binary to $here/src/."
1557 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1565 LAST_BLOCK=`expr \( $2 - 1 \)`
1566 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1569 rm -f $seqres.checkfs
1570 sleep 1 # Due to a problem with time stamps in udf_test
1571 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1572 _udf_test_known_error_filter | \
1573 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" | \
1574 sed "s/^.*$/Warning UDF Verifier reported errors see $seqres.checkfs./g"
1578 _check_xfs_test_fs()
1582 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1583 TEST_LOG="$TEST_LOGDEV"
1585 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1586 TEST_RT="$TEST_RTDEV"
1588 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1590 # check for ipath consistency
1591 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1592 # errors go to stderr
1593 xfs_check_ipaths $TEST_DIR >/dev/null
1594 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1598 _check_btrfs_filesystem()
1602 # If type is set, we're mounted
1603 type=`_fs_type $device`
1606 if [ "$type" = "$FSTYP" ]
1609 mountpoint=`_umount_or_remount_ro $device`
1612 btrfsck $device >$tmp.fsck 2>&1
1615 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1617 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1618 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1619 cat $tmp.fsck >>$seqres.full
1620 echo "*** end fsck.$FSTYP output" >>$seqres.full
1628 echo "*** mount output ***" >>$seqres.full
1629 _mount >>$seqres.full
1630 echo "*** end mount output" >>$seqres.full
1631 elif [ "$type" = "$FSTYP" ]
1634 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1638 if [ $ok -eq 0 ]; then
1653 # no way to check consistency for nfs
1656 # do nothing for now
1659 _check_btrfs_filesystem $TEST_DEV
1662 _check_generic_filesystem $TEST_DEV
1673 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1674 SCRATCH_LOG="$SCRATCH_LOGDEV"
1676 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1677 SCRATCH_RT="$SCRATCH_RTDEV"
1679 _check_xfs_filesystem $SCRATCH_DEV $SCRATCH_LOG $SCRATCH_RT
1682 _check_udf_filesystem $SCRATCH_DEV $udf_fsize
1685 # Don't know how to check an NFS filesystem, yet.
1688 _check_btrfs_filesystem $SCRATCH_DEV
1691 _check_generic_filesystem $SCRATCH_DEV
1696 _full_fstyp_details()
1698 [ -z "$FSTYP" ] && FSTYP=xfs
1699 if [ $FSTYP = xfs ]; then
1700 if [ -d /proc/fs/xfs ]; then
1701 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1702 FSTYP="$FSTYP (non-debug)"
1703 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1704 FSTYP="$FSTYP (debug)"
1707 if uname -a | grep -qi 'debug'; then
1708 FSTYP="$FSTYP (debug)"
1710 FSTYP="$FSTYP (non-debug)"
1717 _full_platform_details()
1723 echo "$os/$platform $host $kernel"
1726 _setup_udf_scratchdir()
1728 [ "$FSTYP" != "udf" ] \
1729 && _fail "setup_udf_testdir: \$FSTYP is not udf"
1730 [ -z "$SCRATCH_DEV" -o ! -b "$SCRATCH_DEV" ] \
1731 && _notrun "this test requires a valid \$SCRATCH_DEV"
1732 [ -z "$SCRATCH_MNT" ] \
1733 && _notrun "this test requires a valid \$SCRATCH_MNT"
1736 if _mount | grep -q $SCRATCH_DEV
1738 # if it's mounted, make sure its on $TEST_RW_DIR
1739 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1741 _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1743 $UMOUNT_PROG $SCRATCH_DEV
1749 testdir=$SCRATCH_MNT
1752 _setup_nfs_scratchdir()
1754 [ "$FSTYP" != "nfs" ] \
1755 && _fail "setup_nfs_testdir: \$FSTYP is not nfs"
1756 [ -z "$SCRATCH_DEV" ] \
1757 && _notrun "this test requires a valid host fs for \$SCRATCH_DEV"
1758 [ -z "$SCRATCH_MNT" ] \
1759 && _notrun "this test requires a valid \$SCRATCH_MNT"
1762 if _mount | grep -q $SCRATCH_DEV
1764 # if it's mounted, make sure its on $SCRATCH_MNT
1765 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1767 _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1769 $UMOUNT_PROG $SCRATCH_DEV
1775 testdir=$SCRATCH_MNT
1779 # Warning for UDF and NFS:
1780 # this function calls _setup_udf_scratchdir and _setup_udf_scratchdir
1781 # which actually uses the scratch dir for the test dir.
1783 # This was done because testdir was intended to be a persistent
1784 # XFS only partition. This should eventually change, and treat
1785 # at least local filesystems all the same.
1791 _setup_udf_scratchdir
1794 _setup_nfs_scratchdir
1806 # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
1807 [ -n "$testdir" ] && $UMOUNT_PROG $testdir
1810 # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
1811 [ -n "$testdir" ] && $UMOUNT_PROG $testdir
1814 # do nothing, testdir is $TEST_DIR
1822 if [ -z "$1" -o -z "$2" ]; then
1823 echo Error must pass src and dst.
1827 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1829 elif [ "`uname`" == "Linux" ]; then
1832 echo Error test $seq does not run on the operating system: `uname`
1843 #takes files, randomdata
1851 if [ $size -gt 0 ]; then
1852 if [ "$2" == "false" ]; then
1853 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
1855 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
1862 # takes dirname, depth, randomdata
1865 dirname=$1; depth=$2; randomdata=$3
1866 mkdir $dirname || die "mkdir $dirname failed"
1869 _nfiles $files $randomdata # files for this dir and data type
1871 [ $depth -eq 0 ] && return
1872 let deep=$depth-1 # go 1 down
1874 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
1877 while [ $d -lt $dirs ]
1879 _descend d$d $deep &
1885 # Populate a filesystem with inodes for performance experiments
1887 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
1892 dirs=5 # ndirs in each subdir till leaves
1893 size=0 # sizeof files in K
1894 files=100 # num files in _each_ subdir
1895 depth=2 # depth of tree from root to leaves
1897 root=root # path of initial root of directory tree
1898 randomdata=false # -x data type urandom or zero
1901 while getopts "d:f:n:r:s:v:x" c
1910 x) randomdata=true;;
1914 _descend $root $depth $randomdata
1919 [ $verbose = true ] && echo done
1922 # query whether the given file has the given inode flag set
1929 if which $XFS_IO_PROG >/dev/null; then
1930 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
1937 # query the given files extsize allocator hint in bytes (if any)
1944 if which $XFS_IO_PROG >/dev/null; then
1945 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
1946 awk '/^xattr.extsize =/ { print $3 }'`
1948 [ -z "$blocks" ] && blocks="0"
1952 # scratch_dev_pool should contain the disks pool for the btrfs raid
1953 _require_scratch_dev_pool()
1956 if [ -z "$SCRATCH_DEV_POOL" ]; then
1957 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
1960 # btrfs test case needs 2 or more scratch_dev_pool; other FS not sure
1964 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt 2 ]; then
1965 _notrun "btrfs and this test needs 2 or more disks in SCRATCH_DEV_POOL"
1969 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
1973 for i in $SCRATCH_DEV_POOL; do
1974 if [ "`_is_block_dev $i`" = "" ]; then
1975 _notrun "this test requires valid block disk $i"
1977 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
1978 _notrun "$i is part of TEST_DEV, this test requires unique disks"
1980 if _mount | grep -q $i; then
1981 if ! $UMOUNT_PROG $i; then
1982 echo "failed to unmount $i - aborting"
1986 # to help better debug when something fails, we remove
1987 # traces of previous btrfs FS on the dev.
1988 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
1992 # We will check if the device is virtual (eg: loop device) since it does not
1993 # have the delete entry-point. Otherwise SCSI and USB devices are fine.
1994 _require_deletable_scratch_dev_pool()
1998 for i in $SCRATCH_DEV_POOL; do
1999 x=`echo $i | cut -d"/" -f 3`
2000 ls -l /sys/class/block/${x} | grep -q "virtual"
2001 if [ $? == "0" ]; then
2002 _notrun "$i is a virtual device which is not deletable"
2007 # We check for btrfs and (optionally) features of the btrfs command
2011 _require_command $BTRFS_UTIL_PROG btrfs
2012 if [ -z "$1" ]; then
2015 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2016 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2019 # Check that fio is present, and it is able to execute given jobfile
2024 _require_command $FIO_PROG
2025 if [ -z "$1" ]; then
2029 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2030 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2033 # Does freeze work on this fs?
2036 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2038 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2039 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2042 # arg 1 is dev to remove and is output of the below eg.
2043 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2046 echo 1 > /sys/class/scsi_device/${1}/device/delete || _fail "Remove disk failed"
2049 # arg 1 is dev to add and is output of the below eg.
2050 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2055 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2056 h=`echo ${1} | cut -d":" -f 1`
2057 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2059 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2064 if [ -z "$FSTRIM_PROG" ]; then
2065 _notrun "This test requires fstrim utility."
2069 _test_batched_discard()
2071 if [ $# -ne 1 ]; then
2072 echo "Usage: _test_batched_discard mnt_point" 1>&2
2076 $FSTRIM_PROG ${1} &>/dev/null
2081 if [ -z "$DUMPE2FS_PROG" ]; then
2082 _notrun "This test requires dumpe2fs utility."
2086 _create_loop_device()
2089 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2093 _destroy_loop_device()
2096 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2099 _scale_fsstress_args()
2102 while [ $# -gt 0 ]; do
2104 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2105 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2106 *) args="$args $1" ;;
2115 echo "# $@" >> $seqres.full 2>&1
2116 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2119 ################################################################################
2121 if [ "$iam" != new ]
2123 # make some further configuration checks here
2125 if [ "$TEST_DEV" = "" ]
2127 echo "common/rc: Error: \$TEST_DEV is not set"
2131 # if $TEST_DEV is not mounted, mount it now as XFS
2132 if [ -z "`_fs_type $TEST_DEV`" ]
2134 # $TEST_DEV is not mounted
2137 echo "common/rc: retrying test device mount with external set"
2138 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2141 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2147 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2149 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2154 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2155 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2156 export XFS_IO_PROG="$XFS_IO_PROG -F"
2160 # make sure this script returns success