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
77 # Also filter out lost+found directory on extN file system if present
81 ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /" | grep -v 'lost+found'
86 # SELinux adds extra xattrs which can mess up our expected output.
87 # So, mount with a context, and they won't be created
88 # nfs_t is a "liberal" context so we can use it.
89 if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
90 SELINUX_MOUNT_OPTIONS="-o context=system_u:object_r:nfs_t:s0"
91 export SELINUX_MOUNT_OPTIONS
96 export MOUNT_OPTIONS=$XFS_MOUNT_OPTIONS
99 export MOUNT_OPTIONS=$UDF_MOUNT_OPTIONS
102 export MOUNT_OPTIONS=$NFS_MOUNT_OPTIONS
104 ext2|ext3|ext4|ext4dev)
105 # acls & xattrs aren't turned on by default on ext$FOO
106 export MOUNT_OPTIONS="-o acl,user_xattr $EXT_MOUNT_OPTIONS"
109 # acls & xattrs aren't turned on by default on reiserfs
110 export MOUNT_OPTIONS="-o acl,user_xattr $REISERFS_MOUNT_OPTIONS"
113 # acls aren't turned on by default on gfs2
114 export MOUNT_OPTIONS="-o acl $GFS2_MOUNT_OPTIONS"
117 # We need to specify the size at mount, use 512 MB by default
118 export MOUNT_OPTIONS="-o size=512M $TMPFS_MOUNT_OPTIONS"
129 export MKFS_OPTIONS=$XFS_MKFS_OPTIONS
132 [ ! -z "$udf_fsize" ] && \
133 UDF_MKFS_OPTIONS="$UDF_MKFS_OPTIONS -s $udf_fsize"
134 export MKFS_OPTIONS=$UDF_MKFS_OPTIONS
137 export MKFS_OPTIONS=$NFS_MKFS_OPTIONS
140 export MKFS_OPTIONS="$REISERFS_MKFS_OPTIONS -q"
143 export MKFS_OPTIONS="$GFS2_MKFS_OPTIONS -O -p lock_nolock"
146 export MKFS_OPTIONS="$JFS_MKFS_OPTIONS -q"
149 export MKFS_OPTIONS="$TMPFS_MKFS_OPTIONS"
159 ext2|ext3|ext4|ext4dev)
160 export FSCK_OPTIONS="-nf"
163 export FSCK_OPTIONS="--yes"
166 export FSCK_OPTIONS="-n"
171 [ -z "$FSTYP" ] && FSTYP=xfs
172 [ -z "$MOUNT_OPTIONS" ] && _mount_opts
173 [ -z "$MKFS_OPTIONS" ] && _mkfs_opts
174 [ -z "$FSCK_OPTIONS" ] && _fsck_opts
177 # we need common/config
178 if [ "$iam" != "check" ]
180 if ! . ./common/config
182 echo "$iam: failed to source common/config"
187 # check for correct setup
190 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
191 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
192 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
193 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
196 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
199 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
205 # make sure we have a standard umask
210 $MOUNT_PROG `_mount_ops_filter $*`
218 if [ "$FSTYP" != "xfs" ]; then
224 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
233 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
234 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
235 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
236 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
244 if [ "$FSTYP" != "xfs" ]; then
258 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
259 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
260 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
261 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
268 #get mount point to handle dmapi mtpt option correctly
270 [ $last_index -gt 0 ] && shift $last_index
273 # irix is fussy about how it is fed its mount options
274 # - multiple -o's are not allowed
275 # - no spaces between comma delimitered options
276 # the sed script replaces all -o's (except the first) with a comma
277 # not required for linux, but won't hurt
279 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
280 | sed -e 's/dmapi/dmi/' \
281 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
285 _scratch_mount_options()
287 _scratch_options mount
289 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
294 _mount -t $FSTYP `_scratch_mount_options $*`
299 $UMOUNT_PROG $SCRATCH_DEV
311 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
314 _scratch_mkfs_options()
316 _scratch_options mkfs
317 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
321 _setup_large_xfs_fs()
326 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
327 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
328 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
330 # calculate the size of the file we need to allocate.
331 # Default free space in the FS is 50GB, but you can specify more via
332 # SCRATCH_DEV_EMPTY_SPACE
333 file_size=$(($fs_size - 50*1024*1024*1024))
334 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
336 # mount the filesystem, create the file, unmount it
337 _scratch_mount 2>&1 >$tmp_dir/mnt.err
339 if [ $status -ne 0 ]; then
341 cat $tmp_dir/mnt.err >&2
342 rm -f $tmp_dir/mnt.err
345 rm -f $tmp_dir/mnt.err
348 -c "truncate $file_size" \
349 -c "falloc -k 0 $file_size" \
351 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
352 export NUM_SPACE_FILES=1
355 if [ $status -ne 0 ]; then
356 echo "large file prealloc failed"
357 cat $tmp_dir/mnt.err >&2
365 # extra mkfs options can be added by tests
366 local extra_mkfs_options=$*
370 _scratch_options mkfs
372 # save mkfs output in case conflict means we need to run again.
373 # only the output for the mkfs that applies should be shown
374 $MKFS_XFS_PROG $SCRATCH_OPTIONS $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
375 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
378 # a mkfs failure may be caused by conflicts between
379 # $MKFS_OPTIONS and $extra_mkfs_options
381 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
382 echo "** mkfs failed with extra mkfs options added to \"$MKFS_OPTIONS\" by test $seq **" \
384 echo "** attempting to mkfs using only test $seq options: $extra_mkfs_options **" \
386 # running mkfs again. overwrite previous mkfs output files
387 $MKFS_XFS_PROG $SCRATCH_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
388 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
392 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
393 # manually parse the mkfs output to get the fs size in bytes
395 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
396 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
398 print STDOUT "$size\n";
400 _setup_large_xfs_fs $fs_size
404 # output stored mkfs output
405 cat $tmp_dir.mkfserr >&2
407 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
412 # xfs_check script is planned to be deprecated. But, we want to
413 # be able to invoke "xfs_check" behavior in xfstests in order to
414 # maintain the current verification levels.
419 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
421 while getopts "b:fi:l:stvV" c
427 i) OPTS=$OPTS"-i "$OPTARG" ";;
428 b) OPTS=$OPTS"-b "$OPTARG" ";;
429 f) DBOPTS=$DBOPTS" -f";;
430 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
431 V) $XFS_DB_PROG -p xfs_check -V
439 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
449 _setup_large_ext4_fs()
454 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
455 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
456 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
458 # Default free space in the FS is 50GB, but you can specify more via
459 # SCRATCH_DEV_EMPTY_SPACE
460 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
462 # mount the filesystem and create 16TB - 4KB files until we consume
463 # all the necessary space.
464 _scratch_mount 2>&1 >$tmp_dir/mnt.err
466 if [ $status -ne 0 ]; then
468 cat $tmp_dir/mnt.err >&2
469 rm -f $tmp_dir/mnt.err
472 rm -f $tmp_dir/mnt.err
474 file_size=$((16*1024*1024*1024*1024 - 4096))
476 while [ $space_to_consume -gt $file_size ]; do
479 -c "truncate $file_size" \
480 -c "falloc -k 0 $file_size" \
481 $SCRATCH_MNT/.use_space.$nfiles 2>&1
483 if [ $status -ne 0 ]; then
487 space_to_consume=$(( $space_to_consume - $file_size ))
488 nfiles=$(($nfiles + 1))
491 # consume the remaining space.
492 if [ $space_to_consume -gt 0 ]; then
494 -c "truncate $space_to_consume" \
495 -c "falloc -k 0 $space_to_consume" \
496 $SCRATCH_MNT/.use_space.$nfiles 2>&1
499 export NUM_SPACE_FILES=$nfiles
502 if [ $status -ne 0 ]; then
503 echo "large file prealloc failed"
504 cat $tmp_dir/mnt.err >&2
513 /sbin/mkfs -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV \
514 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
517 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
518 # manually parse the mkfs output to get the fs size in bytes
519 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
520 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
521 / inodes, / { blks = $3 } \
522 /reserved for the super user/ { resv = $1 } \
523 END { fssize = bs * blks - resv; print fssize }'`
525 _setup_large_ext4_fs $fs_size
529 # output stored mkfs output
530 cat $tmp_dir.mkfserr >&2
532 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
547 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
550 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
553 _scratch_mkfs_ext4 $*
556 # do nothing for tmpfs
559 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
568 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
571 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
576 # Create fs of certain size on scratch device
577 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
578 _scratch_mkfs_sized()
582 [ -z "$blocksize" ] && blocksize=4096
585 if ! [[ $fssize =~ $re ]] ; then
586 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
588 if ! [[ $blocksize =~ $re ]] ; then
589 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
592 blocks=`expr $fssize / $blocksize`
594 if [ "$HOSTOS" == "Linux" ]; then
595 devsize=`blockdev --getsize64 $SCRATCH_DEV`
596 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
601 # don't override MKFS_OPTIONS that set a block size.
602 echo $MKFS_OPTIONS |egrep -q "b?size="
603 if [ $? -eq 0 ]; then
604 _scratch_mkfs_xfs -d size=$fssize
606 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
609 ext2|ext3|ext4|ext4dev)
610 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
613 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
616 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
619 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
624 # Emulate an N-data-disk stripe w/ various stripe units
625 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
631 [ -z "$blocksize" ] && blocksize=4096
633 let sunit_blocks=$sunit_bytes/$blocksize
634 let swidth_blocks=$sunit_blocks*$swidth_mult
638 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
641 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
644 _notrun "can't mkfs $FSTYP with geometry"
654 xfs_io -x -c "resblks $1" $SCRATCH_MNT
661 _scratch_xfs_db_options()
664 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
665 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
666 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
669 _scratch_xfs_logprint()
672 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
673 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
674 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
680 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
681 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
682 [ "$LARGE_SCRATCH_DEV" = yes ] && \
683 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
684 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
687 _scratch_xfs_repair()
690 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
691 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
692 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
693 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
694 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
695 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
702 echo "Usage: _get_pids_by_name process-name" 1>&2
706 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
707 # HH:MM:SS before the psargs field, use this as the search anchor.
709 # Matches with $1 (process-name) occur if the first psarg is $1
710 # or ends in /$1 ... the matching uses sed's regular expressions,
711 # so passing a regex into $1 will work.
719 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
720 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
723 # fix malloc libs output
727 # filter out the Electric Fence notice
730 if (defined $o && /^\s+Electric Fence/) {
736 print $o if (defined $o);
740 print $o if (defined $o);
744 # check if run as root
748 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
751 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
758 # _df_device : get an IRIX style df line for a given device
760 # - returns "" if not mounted
761 # - returns fs type in field two (ala IRIX)
762 # - joins line together if split by fancy df formatting
763 # - strips header etc
770 echo "Usage: _df_device device" 1>&2
774 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
775 match($1,what) && NF==1 {
789 # _df_dir : get an IRIX style df line for device where a directory resides
791 # - returns fs type in field two (ala IRIX)
792 # - joins line together if split by fancy df formatting
793 # - strips header etc
800 echo "Usage: _df_dir device" 1>&2
804 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
820 # return percentage used disk space for mounted device
826 echo "Usage: _used device" 1>&2
830 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
833 # return the FS type of a mounted device
839 echo "Usage: _fs_type device" 1>&2
844 # The Linux kernel shows NFSv4 filesystems in df output as
845 # filesystem type nfs4, although we mounted it as nfs earlier.
846 # Fix the filesystem type up here so that the callers don't
847 # have to bother with this quirk.
849 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
852 # return the FS mount options of a mounted device
854 # should write a version which just parses the output of mount for IRIX
855 # compatibility, but since this isn't used at all, at the moment I'll leave
862 echo "Usage: _fs_options device" 1>&2
866 $AWK_PROG -v dev=$1 '
867 match($1,dev) { print $4 }
871 # returns device number if a file is a block device
877 echo "Usage: _is_block_dev dev" 1>&2
882 if [ -L "${_dev}" ]; then
883 _dev=`readlink -f ${_dev}`
886 if [ -b "${_dev}" ]; then
887 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
891 # Do a command, log it to $seqres.full, optionally test return status
892 # and die if command fails. If called with one argument _do executes the
893 # command, logs it, and returns its exit status. With two arguments _do
894 # first prints the message passed in the first argument, and then "done"
895 # or "fail" depending on the return status of the command passed in the
896 # second argument. If the command fails and the variable _do_die_on_error
897 # is set to "always" or the two argument form is used and _do_die_on_error
898 # is set to "message_only" _do will print an error message to
899 # $seqres.out and exit.
903 if [ $# -eq 1 ]; then
905 elif [ $# -eq 2 ]; then
910 echo "Usage: _do [note] cmd" 1>&2
914 (eval "echo '---' \"$_cmd\"") >>$seqres.full
915 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
916 cat $tmp._out | _fix_malloc >>$seqres.full
917 if [ $# -eq 2 ]; then
918 if [ $ret -eq 0 ]; then
925 && [ "$_do_die_on_error" = "always" \
926 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
929 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
936 # bail out, setting up .notrun file
940 echo "$*" > $seqres.notrun
941 echo "$seq not run: $*"
946 # just plain bail out
950 echo "$*" | tee -a $seqres.full
951 echo "(see $seqres.full for details)"
956 # tests whether $FSTYP is one of the supported filesystems for a test
962 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
968 _notrun "not suitable for this filesystem type: $FSTYP"
971 # tests whether $FSTYP is one of the supported OSes for a test
977 if [ "$h" = "$HOSTOS" ]
983 _notrun "not suitable for this OS: $HOSTOS"
986 # this test needs a scratch partition - check we're ok & unmount it
992 _notrun "requires a scratch device"
995 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
997 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1001 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
1003 _notrun "this test requires a valid \$SCRATCH_DEV"
1005 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1007 _notrun "this test requires a valid \$SCRATCH_DEV"
1009 if [ ! -d "$SCRATCH_MNT" ]
1011 _notrun "this test requires a valid \$SCRATCH_MNT"
1017 if _mount | grep -q $SCRATCH_DEV
1019 # if it's mounted, make sure its on $SCRATCH_MNT
1020 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1022 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1025 # and then unmount it
1026 if ! $UMOUNT_PROG $SCRATCH_DEV
1028 echo "failed to unmount $SCRATCH_DEV"
1034 # this test needs a logdev
1038 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1039 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1040 [ "$USE_EXTERNAL" != yes ] && \
1041 _notrun "This test requires USE_EXTERNAL to be enabled"
1043 # ensure its not mounted
1044 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1047 # this test requires loopback device support
1051 if [ "$HOSTOS" != "Linux" ]
1053 _notrun "This test requires linux for loopback device support"
1056 modprobe loop >/dev/null 2>&1
1057 if grep loop /proc/devices >/dev/null 2>&1
1061 _notrun "This test requires loopback device support"
1065 # this test requires ext2 filesystem support
1069 if [ "$HOSTOS" != "Linux" ]
1071 _notrun "This test requires linux for ext2 filesystem support"
1074 modprobe ext2 >/dev/null 2>&1
1075 if grep ext2 /proc/filesystems >/dev/null 2>&1
1079 _notrun "This test requires ext2 filesystem support"
1083 # this test requires that (large) loopback device files are not in use
1085 _require_no_large_scratch_dev()
1087 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1088 _notrun "Large filesystem testing in progress, skipped this test"
1091 # this test requires that a realtime subvolume is in use, and
1092 # that the kernel supports realtime as well.
1096 [ "$USE_EXTERNAL" = yes ] || \
1097 _notrun "External volumes not in use, skipped this test"
1098 [ "$SCRATCH_RTDEV" = "" ] && \
1099 _notrun "Realtime device required, skipped this test"
1102 # this test requires that a specified command (executable) exists
1103 # $1 - command, $2 - name for error message
1107 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1108 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1111 # this test requires the device mapper flakey target
1113 _require_dm_flakey()
1115 _require_command $DMSETUP_PROG
1117 modprobe dm-flakey >/dev/null 2>&1
1118 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1123 _notrun "This test requires dm flakey support"
1127 # this test requires the projid32bit feature to be available in
1130 _require_projid32bit()
1132 _scratch_mkfs_xfs -f -i projid32bit=0 2>&1 >/dev/null \
1133 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1136 # this test requires the crc feature to be available in mkfs.xfs
1138 _require_xfs_mkfs_crc()
1140 _scratch_mkfs_xfs -f -m crc=1 >/dev/null 2>&1 \
1141 || _notrun "mkfs.xfs doesn't have crc feature"
1144 # this test requires the xfs kernel support crc feature
1148 _scratch_mount >/dev/null 2>&1 \
1149 || _notrun "Kernel doesn't support crc feature"
1153 # this test requires that external log/realtime devices are not in use
1155 _require_nonexternal()
1157 [ "$USE_EXTERNAL" = yes ] && \
1158 _notrun "External device testing in progress, skipped this test"
1161 # this test requires that a (specified) aio-dio executable exists
1162 # $1 - command (optional)
1168 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1169 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1171 AIO_TEST=src/aio-dio-regress/$1
1172 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1176 # run an aio-dio program
1182 echo "usage: _run_aiodio command_name" 2>&1
1188 local testtemp=$TEST_DIR/aio-testfile
1190 $AIO_TEST $testtemp 2>&1
1197 # indicate whether YP/NIS is active or not
1202 dn=$(domainname 2>/dev/null)
1203 test -n "${dn}" -a "${dn}" != "(none)"
1207 # cat the password file
1211 [ $(_yp_active) -eq 0 ] && ypcat passwd
1215 # cat the group file
1219 [ $(_yp_active) -eq 0 ] && ypcat group
1223 # check for the fsgqa user on the machine
1228 _cat_passwd | grep -q $qa_user
1229 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1230 echo /bin/true | su $qa_user
1231 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1234 # check for the fsgqa group on the machine
1239 _cat_group | grep -q $qa_group
1240 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1246 s,.*Permission\sdenied.*,Permission denied,;
1247 s,.*no\saccess\sto\stty.*,,;
1248 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1255 if [ "$HOSTOS" == "IRIX" ]
1257 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1259 echo $1 | su $qa_user 2>&1 | _filter_user_do
1263 # check that xfs_io, kernel, and filesystem all support zero
1264 _require_xfs_io_zero()
1266 testio=`$XFS_IO_PROG -c "zero help" 2>&1`
1267 echo $testio | grep -q 'command "zero" not found' && \
1268 _notrun "zero command not supported"
1271 # check that xfs_io, glibc, kernel, and filesystem all (!) support
1274 _require_xfs_io_falloc()
1276 testfile=$TEST_DIR/$$.falloc
1277 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1278 rm -f $testfile 2>&1 > /dev/null
1279 echo $testio | grep -q "not found" && \
1280 _notrun "xfs_io fallocate support is missing"
1281 echo $testio | grep -q "Operation not supported" && \
1282 _notrun "xfs_io fallocate command failed (old kernel/wrong fs?)"
1285 # check that xfs_io, kernel and filesystem all support fallocate with hole
1287 _require_xfs_io_falloc_punch()
1289 testfile=$TEST_DIR/$$.falloc
1290 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1291 -c "fpunch 4k 8k" $testfile 2>&1`
1292 rm -f $testfile 2>&1 > /dev/null
1293 echo $testio | grep -q "not found" && \
1294 _notrun "xfs_io fallocate punch support is missing"
1295 echo $testio | grep -q "Operation not supported" && \
1296 _notrun "xfs_io fallocate punch command failed (no fs support?)"
1299 # check that xfs_io, kernel and filesystem support fiemap
1300 _require_xfs_io_fiemap()
1302 testfile=$TEST_DIR/$$.fiemap
1303 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1304 -c "fiemap -v" $testfile 2>&1`
1305 rm -f $testfile 2>&1 > /dev/null
1306 echo $testio | grep -q "not found" && \
1307 _notrun "xfs_io fiemap support is missing"
1308 echo $testio | grep -q "Operation not supported" && \
1309 _notrun "xfs_io fiemap command failed (no fs support?)"
1312 # Check that a fs has enough free space (in 1024b blocks)
1317 BLOCKS=$2 # in units of 1024
1318 let GB=$BLOCKS/1024/1024
1320 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1321 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1322 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1326 # Check if the filesystem supports sparse files.
1328 # Unfortunately there is no better way to do this than a manual black list.
1330 _require_sparse_files()
1334 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1343 #boot_params always present in debugfs
1344 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1347 _require_fail_make_request()
1349 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1350 || _notrun "$DEBUGFS_MNT/fail_make_request \
1351 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1355 # Check if the file system supports seek_data/hole
1357 _require_seek_data_hole()
1359 testfile=$TEST_DIR/$$.seek
1360 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1361 rm -f $testfile &>/dev/null
1362 echo $testseek | grep -q "Kernel does not support" && \
1363 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1366 # check that a FS on a device is mounted
1367 # if so, return mount point
1373 echo "Usage: _is_mounted device" 1>&2
1379 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1380 pattern { print $3 ; exit 0 }
1384 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1389 # remount a FS to a new mode (ro or rw)
1395 echo "Usage: _remount device ro/rw" 1>&2
1401 if ! mount -o remount,$mode $device
1403 echo "_remount: failed to remount filesystem on $device as $mode"
1408 # Run the appropriate repair/check on a filesystem
1410 # if the filesystem is mounted, it's either remounted ro before being
1411 # checked or it's unmounted and then remounted
1414 # If set, we remount ro instead of unmounting for fsck
1417 _umount_or_remount_ro()
1421 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1426 mountpoint=`_is_mounted $device`
1428 if [ $USE_REMOUNT -eq 0 ]; then
1429 $UMOUNT_PROG $device
1436 _mount_or_remount_rw()
1440 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1447 if [ $USE_REMOUNT -eq 0 ]
1449 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1451 echo "!!! failed to remount $device on $mountpoint"
1461 # Check a generic filesystem in no-op mode; this assumes that the
1462 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1463 # and that it will still return an errno for corruption in this mode.
1465 # Filesystems which don't support this will need to define their
1466 # own check routine.
1468 _check_generic_filesystem()
1472 # If type is set, we're mounted
1473 type=`_fs_type $device`
1476 if [ "$type" = "$FSTYP" ]
1479 mountpoint=`_umount_or_remount_ro $device`
1482 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1485 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1487 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1488 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1489 cat $tmp.fsck >>$seqres.full
1490 echo "*** end fsck.$FSTYP output" >>$seqres.full
1498 echo "*** mount output ***" >>$seqres.full
1499 _mount >>$seqres.full
1500 echo "*** end mount output" >>$seqres.full
1501 elif [ "$type" = "$FSTYP" ]
1504 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1508 if [ $ok -eq 0 ]; then
1516 # run xfs_check and friends on a FS.
1518 _check_xfs_filesystem()
1522 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1526 extra_mount_options=""
1528 if [ "$2" != "none" ]; then
1529 extra_log_options="-l$2"
1530 extra_mount_options="-ologdev=$2"
1533 if [ "$3" != "none" ]; then
1534 extra_rt_options="-r$3"
1535 extra_mount_options=$extra_mount_options" -ortdev=$3"
1537 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1539 [ "$FSTYP" != xfs ] && return 0
1541 type=`_fs_type $device`
1544 if [ "$type" = "xfs" ]
1547 mountpoint=`_umount_or_remount_ro $device`
1550 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1551 | tee $tmp.logprint | grep -q "<CLEAN>"
1552 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1554 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1556 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1557 echo "*** xfs_logprint -t output ***" >>$seqres.full
1558 cat $tmp.logprint >>$seqres.full
1559 echo "*** end xfs_logprint output" >>$seqres.full
1564 # xfs_check runs out of memory on large files, so even providing the test
1565 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1566 # large filesystems. Avoid it.
1567 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1568 _xfs_check $extra_log_options $device 2>&1 |\
1569 _fix_malloc >$tmp.fs_check
1571 if [ -s $tmp.fs_check ]
1573 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1575 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1576 echo "*** xfs_check output ***" >>$seqres.full
1577 cat $tmp.fs_check >>$seqres.full
1578 echo "*** end xfs_check output" >>$seqres.full
1583 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1586 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1588 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1589 echo "*** xfs_repair -n output ***" >>$seqres.full
1590 cat $tmp.repair | _fix_malloc >>$seqres.full
1591 echo "*** end xfs_repair output" >>$seqres.full
1595 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1599 echo "*** mount output ***" >>$seqres.full
1600 _mount >>$seqres.full
1601 echo "*** end mount output" >>$seqres.full
1602 elif [ "$type" = "xfs" ]
1604 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1607 if [ $ok -eq 0 ]; then
1615 # Filter the knowen errors the UDF Verifier reports.
1616 _udf_test_known_error_filter()
1618 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."
1622 _check_udf_filesystem()
1624 [ "$DISABLE_UDF_TEST" == "1" ] && return
1626 if [ $# -ne 1 -a $# -ne 2 ]
1628 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1632 if [ ! -x $here/src/udf_test ]
1634 echo "udf_test not installed, please download and build the Philips"
1635 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1636 echo "Then copy the udf_test binary to $here/src/."
1637 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1645 LAST_BLOCK=`expr \( $2 - 1 \)`
1646 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1649 rm -f $seqres.checkfs
1650 sleep 1 # Due to a problem with time stamps in udf_test
1651 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1652 _udf_test_known_error_filter | \
1653 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1654 echo "Warning UDF Verifier reported errors see $seqres.checkfs."
1657 _check_xfs_test_fs()
1661 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1662 TEST_LOG="$TEST_LOGDEV"
1664 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1665 TEST_RT="$TEST_RTDEV"
1667 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1669 # check for ipath consistency
1670 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1671 # errors go to stderr
1672 xfs_check_ipaths $TEST_DIR >/dev/null
1673 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1677 _check_btrfs_filesystem()
1681 # If type is set, we're mounted
1682 type=`_fs_type $device`
1685 if [ "$type" = "$FSTYP" ]
1688 mountpoint=`_umount_or_remount_ro $device`
1691 btrfsck $device >$tmp.fsck 2>&1
1694 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1696 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1697 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1698 cat $tmp.fsck >>$seqres.full
1699 echo "*** end fsck.$FSTYP output" >>$seqres.full
1707 echo "*** mount output ***" >>$seqres.full
1708 _mount >>$seqres.full
1709 echo "*** end mount output" >>$seqres.full
1710 elif [ "$type" = "$FSTYP" ]
1713 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1717 if [ $ok -eq 0 ]; then
1732 # no way to check consistency for nfs
1735 # do nothing for now
1738 _check_btrfs_filesystem $TEST_DEV
1741 # no way to check consistency for tmpfs
1744 _check_generic_filesystem $TEST_DEV
1752 [ $# -eq 1 ] && device=$1
1758 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1759 SCRATCH_LOG="$SCRATCH_LOGDEV"
1761 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1762 SCRATCH_RT="$SCRATCH_RTDEV"
1764 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1767 _check_udf_filesystem $device $udf_fsize
1770 # Don't know how to check an NFS filesystem, yet.
1773 _check_btrfs_filesystem $device
1776 # no way to check consistency for tmpfs
1779 _check_generic_filesystem $device
1784 _full_fstyp_details()
1786 [ -z "$FSTYP" ] && FSTYP=xfs
1787 if [ $FSTYP = xfs ]; then
1788 if [ -d /proc/fs/xfs ]; then
1789 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1790 FSTYP="$FSTYP (non-debug)"
1791 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1792 FSTYP="$FSTYP (debug)"
1795 if uname -a | grep -qi 'debug'; then
1796 FSTYP="$FSTYP (debug)"
1798 FSTYP="$FSTYP (non-debug)"
1805 _full_platform_details()
1811 echo "$os/$platform $host $kernel"
1816 if [ -z "$1" -o -z "$2" ]; then
1817 echo Error must pass src and dst.
1821 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1823 elif [ "`uname`" == "Linux" ]; then
1826 echo Error test $seq does not run on the operating system: `uname`
1837 #takes files, randomdata
1845 if [ $size -gt 0 ]; then
1846 if [ "$2" == "false" ]; then
1847 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
1849 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
1856 # takes dirname, depth, randomdata
1859 dirname=$1; depth=$2; randomdata=$3
1860 mkdir $dirname || die "mkdir $dirname failed"
1863 _nfiles $files $randomdata # files for this dir and data type
1865 [ $depth -eq 0 ] && return
1866 let deep=$depth-1 # go 1 down
1868 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
1871 while [ $d -lt $dirs ]
1873 _descend d$d $deep &
1879 # Populate a filesystem with inodes for performance experiments
1881 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
1886 dirs=5 # ndirs in each subdir till leaves
1887 size=0 # sizeof files in K
1888 files=100 # num files in _each_ subdir
1889 depth=2 # depth of tree from root to leaves
1891 root=root # path of initial root of directory tree
1892 randomdata=false # -x data type urandom or zero
1895 while getopts "d:f:n:r:s:v:x" c
1904 x) randomdata=true;;
1908 _descend $root $depth $randomdata
1913 [ $verbose = true ] && echo done
1916 # query whether the given file has the given inode flag set
1923 if which $XFS_IO_PROG >/dev/null; then
1924 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
1931 # query the given files extsize allocator hint in bytes (if any)
1938 if which $XFS_IO_PROG >/dev/null; then
1939 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
1940 awk '/^xattr.extsize =/ { print $3 }'`
1942 [ -z "$blocks" ] && blocks="0"
1946 # scratch_dev_pool should contain the disks pool for the btrfs raid
1947 _require_scratch_dev_pool()
1950 if [ -z "$SCRATCH_DEV_POOL" ]; then
1951 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
1954 # btrfs test case needs 2 or more scratch_dev_pool; other FS not sure
1958 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt 2 ]; then
1959 _notrun "btrfs and this test needs 2 or more disks in SCRATCH_DEV_POOL"
1963 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
1967 for i in $SCRATCH_DEV_POOL; do
1968 if [ "`_is_block_dev $i`" = "" ]; then
1969 _notrun "this test requires valid block disk $i"
1971 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
1972 _notrun "$i is part of TEST_DEV, this test requires unique disks"
1974 if _mount | grep -q $i; then
1975 if ! $UMOUNT_PROG $i; then
1976 echo "failed to unmount $i - aborting"
1980 # to help better debug when something fails, we remove
1981 # traces of previous btrfs FS on the dev.
1982 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
1986 # We will check if the device is virtual (eg: loop device) since it does not
1987 # have the delete entry-point. Otherwise SCSI and USB devices are fine.
1988 _require_deletable_scratch_dev_pool()
1992 for i in $SCRATCH_DEV_POOL; do
1993 x=`echo $i | cut -d"/" -f 3`
1994 ls -l /sys/class/block/${x} | grep -q "virtual"
1995 if [ $? == "0" ]; then
1996 _notrun "$i is a virtual device which is not deletable"
2001 # We check for btrfs and (optionally) features of the btrfs command
2005 _require_command $BTRFS_UTIL_PROG btrfs
2006 if [ -z "$1" ]; then
2009 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2010 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2013 # Check that fio is present, and it is able to execute given jobfile
2018 _require_command $FIO_PROG
2019 if [ -z "$1" ]; then
2023 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2024 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2027 # Does freeze work on this fs?
2030 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2032 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2033 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2036 # arg 1 is dev to remove and is output of the below eg.
2037 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2043 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2045 stat $disk > /dev/null 2>&1
2046 while [ $? -eq 0 ]; do
2048 stat $disk > /dev/null 2>&1
2052 # arg 1 is dev to add and is output of the below eg.
2053 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2058 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2059 h=`echo ${1} | cut -d":" -f 1`
2060 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2062 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2067 if [ -z "$FSTRIM_PROG" ]; then
2068 _notrun "This test requires fstrim utility."
2072 _test_batched_discard()
2074 if [ $# -ne 1 ]; then
2075 echo "Usage: _test_batched_discard mnt_point" 1>&2
2079 $FSTRIM_PROG ${1} &>/dev/null
2084 if [ -z "$DUMPE2FS_PROG" ]; then
2085 _notrun "This test requires dumpe2fs utility."
2091 if [ ! -e /proc/self/uid_map ]; then
2092 _notrun "This test requires procfs uid_map support."
2094 if [ ! -e /proc/self/gid_map ]; then
2095 _notrun "This test requires procfs gid_map support."
2099 _create_loop_device()
2102 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2106 _destroy_loop_device()
2109 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2112 _scale_fsstress_args()
2115 while [ $# -gt 0 ]; do
2117 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2118 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2119 *) args="$args $1" ;;
2127 # Return the logical block size if running on a block device,
2128 # else substitute the page size.
2130 _min_dio_alignment()
2134 if [ -b "$dev" ]; then
2135 blockdev --getss $dev
2137 $here/src/feature -s
2143 echo "# $@" >> $seqres.full 2>&1
2144 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2149 if [ "$iam" == new ]
2153 # make some further configuration checks here
2154 if [ "$TEST_DEV" = "" ]
2156 echo "common/rc: Error: \$TEST_DEV is not set"
2160 # if $TEST_DEV is not mounted, mount it now as XFS
2161 if [ -z "`_fs_type $TEST_DEV`" ]
2163 # $TEST_DEV is not mounted
2166 echo "common/rc: retrying test device mount with external set"
2167 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2170 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2176 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2178 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2182 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2183 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2184 export XFS_IO_PROG="$XFS_IO_PROG -F"
2189 ################################################################################
2190 # make sure this script returns success