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'
84 # we need common/config
85 if [ "$iam" != "check" ]
87 if ! . ./common/config
89 echo "$iam: failed to source common/config"
94 # check for correct setup
97 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
98 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
99 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
100 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
103 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
106 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
109 [ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found"
117 # make sure we have a standard umask
122 $MOUNT_PROG `_mount_ops_filter $*`
130 if [ "$FSTYP" != "xfs" ]; then
136 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
145 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
146 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
147 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
148 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
156 if [ "$FSTYP" != "xfs" ]; then
170 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
171 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
172 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
173 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
180 #get mount point to handle dmapi mtpt option correctly
182 [ $last_index -gt 0 ] && shift $last_index
185 # irix is fussy about how it is fed its mount options
186 # - multiple -o's are not allowed
187 # - no spaces between comma delimitered options
188 # the sed script replaces all -o's (except the first) with a comma
189 # not required for linux, but won't hurt
191 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
192 | sed -e 's/dmapi/dmi/' \
193 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
197 _scratch_mount_options()
199 _scratch_options mount
201 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
206 _mount -t $FSTYP `_scratch_mount_options $*`
211 $UMOUNT_PROG $SCRATCH_DEV
223 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
228 $UMOUNT_PROG $TEST_DEV
232 _scratch_mkfs_options()
234 _scratch_options mkfs
235 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
243 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
244 options="-l $SCRATCH_LOGDEV"
246 xfs_metadump $options $SCRATCH_DEV $dumpfile
249 _setup_large_xfs_fs()
254 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
255 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
256 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
258 # calculate the size of the file we need to allocate.
259 # Default free space in the FS is 50GB, but you can specify more via
260 # SCRATCH_DEV_EMPTY_SPACE
261 file_size=$(($fs_size - 50*1024*1024*1024))
262 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
264 # mount the filesystem, create the file, unmount it
265 _scratch_mount 2>&1 >$tmp_dir/mnt.err
267 if [ $status -ne 0 ]; then
269 cat $tmp_dir/mnt.err >&2
270 rm -f $tmp_dir/mnt.err
273 rm -f $tmp_dir/mnt.err
276 -c "truncate $file_size" \
277 -c "falloc -k 0 $file_size" \
279 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
280 export NUM_SPACE_FILES=1
283 if [ $status -ne 0 ]; then
284 echo "large file prealloc failed"
285 cat $tmp_dir/mnt.err >&2
291 _scratch_mkfs_xfs_opts()
295 _scratch_options mkfs
297 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
301 _scratch_mkfs_xfs_supported()
305 _scratch_options mkfs
307 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
312 # extra mkfs options can be added by tests
313 local extra_mkfs_options=$*
317 # save mkfs output in case conflict means we need to run again.
318 # only the output for the mkfs that applies should be shown
319 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
320 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
324 # a mkfs failure may be caused by conflicts between
325 # $MKFS_OPTIONS and $extra_mkfs_options
326 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
328 echo -n "** mkfs failed with extra mkfs options "
329 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
330 echo -n "** attempting to mkfs using only test $seq "
331 echo "options: $extra_mkfs_options **"
334 # running mkfs again. overwrite previous mkfs output files
335 _scratch_mkfs_xfs_opts $extra_mkfs_options \
336 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
340 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
341 # manually parse the mkfs output to get the fs size in bytes
343 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
344 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
346 print STDOUT "$size\n";
348 _setup_large_xfs_fs $fs_size
352 # output stored mkfs output
353 cat $tmp_dir.mkfserr >&2
355 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
360 # xfs_check script is planned to be deprecated. But, we want to
361 # be able to invoke "xfs_check" behavior in xfstests in order to
362 # maintain the current verification levels.
367 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
369 while getopts "b:fi:l:stvV" c
375 i) OPTS=$OPTS"-i "$OPTARG" ";;
376 b) OPTS=$OPTS"-b "$OPTARG" ";;
377 f) DBOPTS=$DBOPTS" -f";;
378 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
379 V) $XFS_DB_PROG -p xfs_check -V
387 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
397 _setup_large_ext4_fs()
402 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
403 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
404 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
406 # Default free space in the FS is 50GB, but you can specify more via
407 # SCRATCH_DEV_EMPTY_SPACE
408 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
410 # mount the filesystem and create 16TB - 4KB files until we consume
411 # all the necessary space.
412 _scratch_mount 2>&1 >$tmp_dir/mnt.err
414 if [ $status -ne 0 ]; then
416 cat $tmp_dir/mnt.err >&2
417 rm -f $tmp_dir/mnt.err
420 rm -f $tmp_dir/mnt.err
422 file_size=$((16*1024*1024*1024*1024 - 4096))
424 while [ $space_to_consume -gt $file_size ]; do
427 -c "truncate $file_size" \
428 -c "falloc -k 0 $file_size" \
429 $SCRATCH_MNT/.use_space.$nfiles 2>&1
431 if [ $status -ne 0 ]; then
435 space_to_consume=$(( $space_to_consume - $file_size ))
436 nfiles=$(($nfiles + 1))
439 # consume the remaining space.
440 if [ $space_to_consume -gt 0 ]; then
442 -c "truncate $space_to_consume" \
443 -c "falloc -k 0 $space_to_consume" \
444 $SCRATCH_MNT/.use_space.$nfiles 2>&1
447 export NUM_SPACE_FILES=$nfiles
450 if [ $status -ne 0 ]; then
451 echo "large file prealloc failed"
452 cat $tmp_dir/mnt.err >&2
460 # extra mkfs options can be added by tests
461 local extra_mkfs_options=$*
465 $MKFS_EXT4_PROG -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
466 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
469 # a mkfs failure may be caused by conflicts between
470 # $MKFS_OPTIONS and $extra_mkfs_options
471 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
473 echo -n "** mkfs failed with extra mkfs options "
474 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
475 echo -n "** attempting to mkfs using only test $seq "
476 echo "options: $extra_mkfs_options **"
479 # running mkfs again. overwrite previous mkfs output files
480 $MKFS_EXT4_PROG -F $extra_mkfs_options $SCRATCH_DEV \
481 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
485 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
486 # manually parse the mkfs output to get the fs size in bytes
487 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
488 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
489 / inodes, / { blks = $3 } \
490 /reserved for the super user/ { resv = $1 } \
491 END { fssize = bs * blks - resv; print fssize }'`
493 _setup_large_ext4_fs $fs_size
497 # output stored mkfs output
498 cat $tmp_dir.mkfserr >&2
500 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
512 # do nothing for cifs
515 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
518 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
521 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
533 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
536 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
539 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
540 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
544 if [ $? -ne 0 ]; then
545 # output stored mkfs output
546 cat $tmp_dir.mkfserr >&2
551 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
564 # do nothing for cifs
567 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
570 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
573 _scratch_mkfs_ext4 $*
576 # do nothing for tmpfs
579 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
588 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
591 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
596 # Create fs of certain size on scratch device
597 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
598 _scratch_mkfs_sized()
605 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
607 ext2|ext3|ext4|ext4dev|udf|btrfs)
608 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
612 [ -n "$def_blksz" ] && blocksize=$def_blksz
613 [ -z "$blocksize" ] && blocksize=4096
617 if ! [[ $fssize =~ $re ]] ; then
618 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
620 if ! [[ $blocksize =~ $re ]] ; then
621 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
624 blocks=`expr $fssize / $blocksize`
626 if [ "$HOSTOS" == "Linux" ]; then
627 devsize=`blockdev --getsize64 $SCRATCH_DEV`
628 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
633 # don't override MKFS_OPTIONS that set a block size.
634 echo $MKFS_OPTIONS |egrep -q "b?size="
635 if [ $? -eq 0 ]; then
636 _scratch_mkfs_xfs -d size=$fssize
638 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
641 ext2|ext3|ext4|ext4dev)
642 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
645 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
648 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
651 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
656 # Emulate an N-data-disk stripe w/ various stripe units
657 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
663 [ -z "$blocksize" ] && blocksize=4096
665 let sunit_blocks=$sunit_bytes/$blocksize
666 let swidth_blocks=$sunit_blocks*$swidth_mult
670 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
673 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
676 _notrun "can't mkfs $FSTYP with geometry"
686 xfs_io -x -c "resblks $1" $SCRATCH_MNT
693 _scratch_xfs_db_options()
696 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
697 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
698 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
701 _scratch_xfs_logprint()
704 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
705 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
706 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
712 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
713 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
714 [ "$LARGE_SCRATCH_DEV" = yes ] && \
715 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
716 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
719 _scratch_xfs_repair()
722 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
723 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
724 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
725 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
726 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
727 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
734 echo "Usage: _get_pids_by_name process-name" 1>&2
738 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
739 # HH:MM:SS before the psargs field, use this as the search anchor.
741 # Matches with $1 (process-name) occur if the first psarg is $1
742 # or ends in /$1 ... the matching uses sed's regular expressions,
743 # so passing a regex into $1 will work.
751 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
752 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
755 # fix malloc libs output
759 # filter out the Electric Fence notice
762 if (defined $o && /^\s+Electric Fence/) {
768 print $o if (defined $o);
772 print $o if (defined $o);
776 # check if run as root
780 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
783 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
790 # _df_device : get an IRIX style df line for a given device
792 # - returns "" if not mounted
793 # - returns fs type in field two (ala IRIX)
794 # - joins line together if split by fancy df formatting
795 # - strips header etc
802 echo "Usage: _df_device device" 1>&2
806 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
807 match($1,what) && NF==1 {
821 # _df_dir : get an IRIX style df line for device where a directory resides
823 # - returns fs type in field two (ala IRIX)
824 # - joins line together if split by fancy df formatting
825 # - strips header etc
832 echo "Usage: _df_dir device" 1>&2
836 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
852 # return percentage used disk space for mounted device
858 echo "Usage: _used device" 1>&2
862 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
865 # return the FS type of a mounted device
871 echo "Usage: _fs_type device" 1>&2
876 # The Linux kernel shows NFSv4 filesystems in df output as
877 # filesystem type nfs4, although we mounted it as nfs earlier.
878 # Fix the filesystem type up here so that the callers don't
879 # have to bother with this quirk.
881 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
884 # return the FS mount options of a mounted device
886 # should write a version which just parses the output of mount for IRIX
887 # compatibility, but since this isn't used at all, at the moment I'll leave
894 echo "Usage: _fs_options device" 1>&2
898 $AWK_PROG -v dev=$1 '
899 match($1,dev) { print $4 }
903 # returns device number if a file is a block device
909 echo "Usage: _is_block_dev dev" 1>&2
914 if [ -L "${_dev}" ]; then
915 _dev=`readlink -f ${_dev}`
918 if [ -b "${_dev}" ]; then
919 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
923 # Do a command, log it to $seqres.full, optionally test return status
924 # and die if command fails. If called with one argument _do executes the
925 # command, logs it, and returns its exit status. With two arguments _do
926 # first prints the message passed in the first argument, and then "done"
927 # or "fail" depending on the return status of the command passed in the
928 # second argument. If the command fails and the variable _do_die_on_error
929 # is set to "always" or the two argument form is used and _do_die_on_error
930 # is set to "message_only" _do will print an error message to
931 # $seqres.out and exit.
935 if [ $# -eq 1 ]; then
937 elif [ $# -eq 2 ]; then
942 echo "Usage: _do [note] cmd" 1>&2
946 (eval "echo '---' \"$_cmd\"") >>$seqres.full
947 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
948 cat $tmp._out | _fix_malloc >>$seqres.full
949 if [ $# -eq 2 ]; then
950 if [ $ret -eq 0 ]; then
957 && [ "$_do_die_on_error" = "always" \
958 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
961 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
968 # bail out, setting up .notrun file. Need to kill the filesystem check files
969 # here, otherwise they are set incorrectly for the next test.
973 echo "$*" > $seqres.notrun
974 echo "$seq not run: $*"
975 rm -f ${RESULT_DIR}/require_test
976 rm -f ${RESULT_DIR}/require_scratch
981 # just plain bail out
985 echo "$*" | tee -a $seqres.full
986 echo "(see $seqres.full for details)"
991 # tests whether $FSTYP is one of the supported filesystems for a test
997 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1003 _notrun "not suitable for this filesystem type: $FSTYP"
1007 # tests whether $FSTYP is one of the supported OSes for a test
1013 if [ "$h" = "$HOSTOS" ]
1019 _notrun "not suitable for this OS: $HOSTOS"
1022 # this test needs a scratch partition - check we're ok & unmount it
1023 # No post-test check of the device is required. e.g. the test intentionally
1024 # finishes the test with the filesystem in a corrupt state
1025 _require_scratch_nocheck()
1029 _notrun "requires a scratch device"
1032 _notrun "requires a scratch device"
1035 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1037 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1041 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
1043 _notrun "this test requires a valid \$SCRATCH_DEV"
1045 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1047 _notrun "this test requires a valid \$SCRATCH_DEV"
1049 if [ ! -d "$SCRATCH_MNT" ]
1051 _notrun "this test requires a valid \$SCRATCH_MNT"
1057 if _mount | grep -q $SCRATCH_DEV
1059 # if it's mounted, make sure its on $SCRATCH_MNT
1060 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1062 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1065 # and then unmount it
1066 if ! $UMOUNT_PROG $SCRATCH_DEV
1068 echo "failed to unmount $SCRATCH_DEV"
1072 rm -f ${RESULT_DIR}/require_scratch
1075 # we need the scratch device and it should be checked post test.
1078 _require_scratch_nocheck
1079 touch ${RESULT_DIR}/require_scratch
1083 # this test needs a test partition - check we're ok & unmount it
1089 _notrun "requires a test device"
1092 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1093 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1094 _notrun "this test requires a valid \$TEST_DEV"
1096 if [ ! -d "$TEST_DIR" ]; then
1097 _notrun "this test requires a valid \$TEST_DIR"
1101 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1103 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1107 if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
1109 _notrun "this test requires a valid \$TEST_DEV"
1111 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1113 _notrun "this test requires a valid \$TEST_DEV"
1115 if [ ! -d "$TEST_DIR" ]
1117 _notrun "this test requires a valid \$TEST_DIR"
1123 if _mount | grep -q $TEST_DEV
1125 # if it's mounted, make sure its on $TEST_DIR
1126 if ! _mount | grep $TEST_DEV | grep -q $TEST_DIR
1128 echo "\$TEST_DEV is mounted but not on \$TEST_DIR - aborting"
1132 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1133 if [ $? -ne 1 ]; then
1138 touch ${RESULT_DIR}/require_test
1141 # this test needs a logdev
1145 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1146 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1147 [ "$USE_EXTERNAL" != yes ] && \
1148 _notrun "This test requires USE_EXTERNAL to be enabled"
1150 # ensure its not mounted
1151 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1154 # this test requires loopback device support
1158 if [ "$HOSTOS" != "Linux" ]
1160 _notrun "This test requires linux for loopback device support"
1163 modprobe loop >/dev/null 2>&1
1164 if grep loop /proc/devices >/dev/null 2>&1
1168 _notrun "This test requires loopback device support"
1172 # this test requires ext2 filesystem support
1176 if [ "$HOSTOS" != "Linux" ]
1178 _notrun "This test requires linux for ext2 filesystem support"
1181 modprobe ext2 >/dev/null 2>&1
1182 if grep ext2 /proc/filesystems >/dev/null 2>&1
1186 _notrun "This test requires ext2 filesystem support"
1190 # this test requires that (large) loopback device files are not in use
1192 _require_no_large_scratch_dev()
1194 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1195 _notrun "Large filesystem testing in progress, skipped this test"
1198 # this test requires that a realtime subvolume is in use, and
1199 # that the kernel supports realtime as well.
1203 [ "$USE_EXTERNAL" = yes ] || \
1204 _notrun "External volumes not in use, skipped this test"
1205 [ "$SCRATCH_RTDEV" = "" ] && \
1206 _notrun "Realtime device required, skipped this test"
1209 # this test requires that a specified command (executable) exists
1210 # $1 - command, $2 - name for error message
1214 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1215 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1218 # this test requires the device mapper flakey target
1220 _require_dm_flakey()
1222 _require_command $DMSETUP_PROG
1224 modprobe dm-flakey >/dev/null 2>&1
1225 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1230 _notrun "This test requires dm flakey support"
1234 # this test requires the projid32bit feature to be available in mkfs.xfs.
1236 _require_projid32bit()
1238 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1239 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1242 _require_projid16bit()
1244 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1245 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1248 # this test requires the crc feature to be available in mkfs.xfs
1250 _require_xfs_mkfs_crc()
1252 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1253 || _notrun "mkfs.xfs doesn't have crc feature"
1256 # this test requires the xfs kernel support crc feature
1260 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1261 _scratch_mount >/dev/null 2>&1 \
1262 || _notrun "Kernel doesn't support crc feature"
1266 # this test requires the bigalloc feature to be available in mkfs.ext4
1268 _require_ext4_mkfs_bigalloc()
1270 _scratch_mkfs_ext4 -O bigalloc >/dev/null 2>&1 \
1271 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1274 # this test requires the ext4 kernel support bigalloc feature
1276 _require_ext4_bigalloc()
1278 _scratch_mkfs_ext4 -O bigalloc >/dev/null 2>&1
1279 _scratch_mount >/dev/null 2>&1 \
1280 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1284 # this test requires the finobt feature to be available in mkfs.xfs
1286 _require_xfs_mkfs_finobt()
1288 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1289 || _notrun "mkfs.xfs doesn't have finobt feature"
1292 # this test requires the xfs kernel support finobt feature
1294 _require_xfs_finobt()
1296 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1297 _scratch_mount >/dev/null 2>&1 \
1298 || _notrun "Kernel doesn't support finobt feature"
1302 # this test requires xfs sysfs attribute support
1304 _require_xfs_sysfs()
1307 sysfsdir=/sys/fs/xfs
1309 if [ ! -e $sysfsdir ]; then
1310 _notrun "no kernel support for XFS sysfs attributes"
1313 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1314 _notrun "sysfs attribute '$attr' is not supported"
1318 # this test requires that external log/realtime devices are not in use
1320 _require_nonexternal()
1322 [ "$USE_EXTERNAL" = yes ] && \
1323 _notrun "External device testing in progress, skipped this test"
1326 # this test requires that a (specified) aio-dio executable exists
1327 # $1 - command (optional)
1333 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1334 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1336 AIO_TEST=src/aio-dio-regress/$1
1337 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1341 # run an aio-dio program
1347 echo "usage: _run_aiodio command_name" 2>&1
1353 local testtemp=$TEST_DIR/aio-testfile
1355 $AIO_TEST $testtemp 2>&1
1362 # indicate whether YP/NIS is active or not
1367 dn=$(domainname 2>/dev/null)
1368 test -n "${dn}" -a "${dn}" != "(none)"
1372 # cat the password file
1376 [ $(_yp_active) -eq 0 ] && ypcat passwd
1380 # cat the group file
1384 [ $(_yp_active) -eq 0 ] && ypcat group
1388 # check for the fsgqa user on the machine
1393 _cat_passwd | grep -q $qa_user
1394 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1395 echo /bin/true | su $qa_user
1396 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1399 # check for the fsgqa group on the machine
1404 _cat_group | grep -q $qa_group
1405 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1411 s,.*Permission\sdenied.*,Permission denied,;
1412 s,.*no\saccess\sto\stty.*,,;
1413 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1420 if [ "$HOSTOS" == "IRIX" ]
1422 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1424 echo $1 | su $qa_user 2>&1 | _filter_user_do
1428 _require_xfs_io_command()
1432 echo "Usage: _require_xfs_io_command command" 1>&2
1437 testfile=$TEST_DIR/$$.xfs_io
1440 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1442 "fpunch" | "fcollapse" | "zero" | "fzero" )
1443 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1444 -c "$command 4k 8k" $testfile 2>&1`
1447 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1448 -c "fiemap -v" $testfile 2>&1`
1451 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1453 echo $testio | egrep -q "invalid option|Is a directory" && \
1454 _notrun "xfs_io $command support is missing"
1457 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1460 rm -f $testfile 2>&1 > /dev/null
1461 echo $testio | grep -q "not found" && \
1462 _notrun "xfs_io $command support is missing"
1463 echo $testio | grep -q "Operation not supported" && \
1464 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1467 # Check that a fs has enough free space (in 1024b blocks)
1472 BLOCKS=$2 # in units of 1024
1473 let GB=$BLOCKS/1024/1024
1475 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1476 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1477 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1481 # Check if the filesystem supports sparse files.
1483 # Unfortunately there is no better way to do this than a manual black list.
1485 _require_sparse_files()
1489 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1498 #boot_params always present in debugfs
1499 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1502 _require_fail_make_request()
1504 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1505 || _notrun "$DEBUGFS_MNT/fail_make_request \
1506 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1510 # Check if the file system supports seek_data/hole
1512 _require_seek_data_hole()
1514 testfile=$TEST_DIR/$$.seek
1515 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1516 rm -f $testfile &>/dev/null
1517 echo $testseek | grep -q "Kernel does not support" && \
1518 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1521 # check that a FS on a device is mounted
1522 # if so, return mount point
1528 echo "Usage: _is_mounted device" 1>&2
1534 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1535 pattern { print $3 ; exit 0 }
1539 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1544 # remount a FS to a new mode (ro or rw)
1550 echo "Usage: _remount device ro/rw" 1>&2
1556 if ! mount -o remount,$mode $device
1558 echo "_remount: failed to remount filesystem on $device as $mode"
1563 # Run the appropriate repair/check on a filesystem
1565 # if the filesystem is mounted, it's either remounted ro before being
1566 # checked or it's unmounted and then remounted
1569 # If set, we remount ro instead of unmounting for fsck
1572 _umount_or_remount_ro()
1576 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1581 mountpoint=`_is_mounted $device`
1583 if [ $USE_REMOUNT -eq 0 ]; then
1584 $UMOUNT_PROG $device
1591 _mount_or_remount_rw()
1595 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1602 if [ $USE_REMOUNT -eq 0 ]
1604 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1606 echo "!!! failed to remount $device on $mountpoint"
1616 # Check a generic filesystem in no-op mode; this assumes that the
1617 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1618 # and that it will still return an errno for corruption in this mode.
1620 # Filesystems which don't support this will need to define their
1621 # own check routine.
1623 _check_generic_filesystem()
1627 # If type is set, we're mounted
1628 type=`_fs_type $device`
1631 if [ "$type" = "$FSTYP" ]
1634 mountpoint=`_umount_or_remount_ro $device`
1637 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1640 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1642 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1643 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1644 cat $tmp.fsck >>$seqres.full
1645 echo "*** end fsck.$FSTYP output" >>$seqres.full
1653 echo "*** mount output ***" >>$seqres.full
1654 _mount >>$seqres.full
1655 echo "*** end mount output" >>$seqres.full
1656 elif [ "$type" = "$FSTYP" ]
1659 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1663 if [ $ok -eq 0 ]; then
1671 # run xfs_check and friends on a FS.
1673 _check_xfs_filesystem()
1677 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1681 extra_mount_options=""
1683 if [ "$2" != "none" ]; then
1684 extra_log_options="-l$2"
1685 extra_mount_options="-ologdev=$2"
1688 if [ "$3" != "none" ]; then
1689 extra_rt_options="-r$3"
1690 extra_mount_options=$extra_mount_options" -ortdev=$3"
1692 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1694 [ "$FSTYP" != xfs ] && return 0
1696 type=`_fs_type $device`
1699 if [ "$type" = "xfs" ]
1702 mountpoint=`_umount_or_remount_ro $device`
1705 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1706 | tee $tmp.logprint | grep -q "<CLEAN>"
1707 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1709 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1711 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1712 echo "*** xfs_logprint -t output ***" >>$seqres.full
1713 cat $tmp.logprint >>$seqres.full
1714 echo "*** end xfs_logprint output" >>$seqres.full
1719 # xfs_check runs out of memory on large files, so even providing the test
1720 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1721 # large filesystems. Avoid it.
1722 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1723 _xfs_check $extra_log_options $device 2>&1 |\
1724 _fix_malloc >$tmp.fs_check
1726 if [ -s $tmp.fs_check ]
1728 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1730 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1731 echo "*** xfs_check output ***" >>$seqres.full
1732 cat $tmp.fs_check >>$seqres.full
1733 echo "*** end xfs_check output" >>$seqres.full
1738 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1741 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1743 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1744 echo "*** xfs_repair -n output ***" >>$seqres.full
1745 cat $tmp.repair | _fix_malloc >>$seqres.full
1746 echo "*** end xfs_repair output" >>$seqres.full
1750 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1754 echo "*** mount output ***" >>$seqres.full
1755 _mount >>$seqres.full
1756 echo "*** end mount output" >>$seqres.full
1757 elif [ "$type" = "xfs" ]
1759 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1762 if [ $ok -eq 0 ]; then
1764 if [ "$iam" != "check" ]; then
1772 # Filter the knowen errors the UDF Verifier reports.
1773 _udf_test_known_error_filter()
1775 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."
1779 _check_udf_filesystem()
1781 [ "$DISABLE_UDF_TEST" == "1" ] && return
1783 if [ $# -ne 1 -a $# -ne 2 ]
1785 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1789 if [ ! -x $here/src/udf_test ]
1791 echo "udf_test not installed, please download and build the Philips"
1792 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1793 echo "Then copy the udf_test binary to $here/src/."
1794 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1802 LAST_BLOCK=`expr \( $2 - 1 \)`
1803 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1806 rm -f $seqres.checkfs
1807 sleep 1 # Due to a problem with time stamps in udf_test
1808 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1809 _udf_test_known_error_filter | \
1810 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1811 echo "Warning UDF Verifier reported errors see $seqres.checkfs."
1814 _check_xfs_test_fs()
1818 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1819 TEST_LOG="$TEST_LOGDEV"
1821 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1822 TEST_RT="$TEST_RTDEV"
1824 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1826 # check for ipath consistency
1827 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1828 # errors go to stderr
1829 xfs_check_ipaths $TEST_DIR >/dev/null
1830 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1834 _check_btrfs_filesystem()
1838 # If type is set, we're mounted
1839 type=`_fs_type $device`
1842 if [ "$type" = "$FSTYP" ]
1845 mountpoint=`_umount_or_remount_ro $device`
1848 btrfsck $device >$tmp.fsck 2>&1
1851 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1853 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1854 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1855 cat $tmp.fsck >>$seqres.full
1856 echo "*** end fsck.$FSTYP output" >>$seqres.full
1864 echo "*** mount output ***" >>$seqres.full
1865 _mount >>$seqres.full
1866 echo "*** end mount output" >>$seqres.full
1867 elif [ "$type" = "$FSTYP" ]
1870 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1874 if [ $ok -eq 0 ]; then
1889 # no way to check consistency for nfs
1892 # no way to check consistency for cifs
1895 # do nothing for now
1898 _check_btrfs_filesystem $TEST_DEV
1901 # no way to check consistency for tmpfs
1904 _check_generic_filesystem $TEST_DEV
1912 [ $# -eq 1 ] && device=$1
1918 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1919 SCRATCH_LOG="$SCRATCH_LOGDEV"
1921 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1922 SCRATCH_RT="$SCRATCH_RTDEV"
1924 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1927 _check_udf_filesystem $device $udf_fsize
1930 # Don't know how to check an NFS filesystem, yet.
1933 # Don't know how to check a CIFS filesystem, yet.
1936 _check_btrfs_filesystem $device
1939 # no way to check consistency for tmpfs
1942 _check_generic_filesystem $device
1947 _full_fstyp_details()
1949 [ -z "$FSTYP" ] && FSTYP=xfs
1950 if [ $FSTYP = xfs ]; then
1951 if [ -d /proc/fs/xfs ]; then
1952 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1953 FSTYP="$FSTYP (non-debug)"
1954 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1955 FSTYP="$FSTYP (debug)"
1958 if uname -a | grep -qi 'debug'; then
1959 FSTYP="$FSTYP (debug)"
1961 FSTYP="$FSTYP (non-debug)"
1968 _full_platform_details()
1974 echo "$os/$platform $host $kernel"
1979 if [ -z "$1" -o -z "$2" ]; then
1980 echo Error must pass src and dst.
1984 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1986 elif [ "`uname`" == "Linux" ]; then
1989 echo Error test $seq does not run on the operating system: `uname`
2000 #takes files, randomdata
2008 if [ $size -gt 0 ]; then
2009 if [ "$2" == "false" ]; then
2010 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2012 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2019 # takes dirname, depth, randomdata
2022 dirname=$1; depth=$2; randomdata=$3
2023 mkdir $dirname || die "mkdir $dirname failed"
2026 _nfiles $files $randomdata # files for this dir and data type
2028 [ $depth -eq 0 ] && return
2029 let deep=$depth-1 # go 1 down
2031 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2034 while [ $d -lt $dirs ]
2036 _descend d$d $deep &
2042 # Populate a filesystem with inodes for performance experiments
2044 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2049 dirs=5 # ndirs in each subdir till leaves
2050 size=0 # sizeof files in K
2051 files=100 # num files in _each_ subdir
2052 depth=2 # depth of tree from root to leaves
2054 root=root # path of initial root of directory tree
2055 randomdata=false # -x data type urandom or zero
2058 while getopts "d:f:n:r:s:v:x" c
2067 x) randomdata=true;;
2071 _descend $root $depth $randomdata
2076 [ $verbose = true ] && echo done
2079 # query whether the given file has the given inode flag set
2086 if which $XFS_IO_PROG >/dev/null; then
2087 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2094 # query the given files extsize allocator hint in bytes (if any)
2101 if which $XFS_IO_PROG >/dev/null; then
2102 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2103 awk '/^xattr.extsize =/ { print $3 }'`
2105 [ -z "$blocks" ] && blocks="0"
2109 # scratch_dev_pool should contain the disks pool for the btrfs raid
2110 _require_scratch_dev_pool()
2115 if [ -z "$SCRATCH_DEV_POOL" ]; then
2116 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2119 if [ -z "$1" ]; then
2125 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2129 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2130 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2134 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2138 for i in $SCRATCH_DEV_POOL; do
2139 if [ "`_is_block_dev $i`" = "" ]; then
2140 _notrun "this test requires valid block disk $i"
2142 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
2143 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2145 if _mount | grep -q $i; then
2146 if ! $UMOUNT_PROG $i; then
2147 echo "failed to unmount $i - aborting"
2151 # to help better debug when something fails, we remove
2152 # traces of previous btrfs FS on the dev.
2153 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2157 # We will check if the device is deletable
2158 _require_deletable_scratch_dev_pool()
2162 for i in $SCRATCH_DEV_POOL; do
2163 x=`echo $i | cut -d"/" -f 3`
2164 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2165 _notrun "$i is a device which is not deletable"
2170 # We check for btrfs and (optionally) features of the btrfs command
2174 _require_command $BTRFS_UTIL_PROG btrfs
2175 if [ -z "$1" ]; then
2178 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2179 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2182 # Check that fio is present, and it is able to execute given jobfile
2187 _require_command $FIO_PROG
2188 if [ -z "$1" ]; then
2192 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2193 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2196 # Does freeze work on this fs?
2199 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2201 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2202 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2205 # arg 1 is dev to remove and is output of the below eg.
2206 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2212 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2214 stat $disk > /dev/null 2>&1
2215 while [ $? -eq 0 ]; do
2217 stat $disk > /dev/null 2>&1
2221 # arg 1 is dev to add and is output of the below eg.
2222 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2227 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2228 h=`echo ${1} | cut -d":" -f 1`
2229 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2231 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2233 # ensure the device comes online
2235 for i in `seq 1 10`; do
2236 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2237 dev=`ls /sys/class/scsi_device/${1}/device/block`
2238 for j in `seq 1 10`;
2240 stat /dev/$dev > /dev/null 2>&1
2241 if [ $? -eq 0 ]; then
2252 if [ $dev_back_oneline -eq 0 ]; then
2253 echo "/dev/$dev online failed" >> $seqres.full
2255 echo "/dev/$dev is back online" >> $seqres.full
2261 if [ -z "$FSTRIM_PROG" ]; then
2262 _notrun "This test requires fstrim utility."
2266 _test_batched_discard()
2268 if [ $# -ne 1 ]; then
2269 echo "Usage: _test_batched_discard mnt_point" 1>&2
2273 $FSTRIM_PROG ${1} &>/dev/null
2278 if [ -z "$DUMPE2FS_PROG" ]; then
2279 _notrun "This test requires dumpe2fs utility."
2285 if [ ! -e /proc/self/uid_map ]; then
2286 _notrun "This test requires procfs uid_map support."
2288 if [ ! -e /proc/self/gid_map ]; then
2289 _notrun "This test requires procfs gid_map support."
2293 _require_cp_reflink()
2295 cp --help | grep -q reflink || \
2296 _notrun "This test requires a cp with --reflink support."
2301 FSSUM_PROG=$here/src/fssum
2302 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2305 _require_btrfs_cloner()
2307 CLONER_PROG=$here/src/cloner
2308 [ -x $CLONER_PROG ] || \
2309 _notrun "cloner binary not present at $CLONER_PROG"
2312 # Given 2 files, verify that they have the same mapping but different
2313 # inodes - i.e. an undisturbed reflink
2314 # Silent if so, make noise if not
2317 # not a hard link or symlink?
2318 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2319 && echo "$1 and $2 are not reflinks: same inode number"
2322 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2323 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2324 || echo "$1 and $2 are not reflinks: different extents"
2329 _scratch_mkfs > /dev/null 2>&1
2330 _mount -t $FSTYP -o relatime $SCRATCH_DEV $SCRATCH_MNT || \
2331 _notrun "relatime not supported by the current kernel"
2337 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2338 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2341 _create_loop_device()
2344 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2348 _destroy_loop_device()
2351 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2354 _scale_fsstress_args()
2357 while [ $# -gt 0 ]; do
2359 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2360 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2361 *) args="$args $1" ;;
2369 # Return the logical block size if running on a block device,
2370 # else substitute the page size.
2372 _min_dio_alignment()
2376 if [ -b "$dev" ]; then
2377 blockdev --getss $dev
2379 $here/src/feature -s
2385 echo "# $@" >> $seqres.full 2>&1
2386 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2389 _run_btrfs_util_prog()
2391 run_check $BTRFS_UTIL_PROG $*
2394 _require_btrfs_send_stream_version()
2396 $BTRFS_UTIL_PROG send 2>&1 | \
2397 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2398 if [ $? -ne 0 ]; then
2399 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2402 # test if btrfs kernel supports send stream version 2
2403 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
2404 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
2408 _require_btrfs_mkfs_feature()
2411 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
2415 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
2416 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
2418 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
2421 _require_btrfs_fs_feature()
2424 echo "Missing feature name argument for _require_btrfs_fs_feature"
2428 modprobe btrfs > /dev/null 2>&1
2429 [ -e /sys/fs/btrfs/features/$feat ] || \
2430 _notrun "Feature $feat not supported by the available btrfs version"
2433 _require_test_symlinks()
2435 # IRIX UDF does not support symlinks
2436 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2437 _notrun "Require symlinks support"
2438 target=`mktemp -p $TEST_DIR`
2439 link=`mktemp -p $TEST_DIR -u`
2440 ln -s `basename $target` $link
2441 if [ "$?" -ne 0 ]; then
2443 _notrun "Require symlinks support"
2448 _require_test_fcntl_advisory_locks()
2450 [ "$FSTYP" != "cifs" ] && return 0
2451 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
2452 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
2453 _notrun "Require fcntl advisory locks support"
2458 if [ -z "$1" ]; then
2459 echo "Usage: _get_total_inode <mnt>"
2463 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
2469 if [ -z "$1" ]; then
2470 echo "Usage: _get_used_inode <mnt>"
2474 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
2480 if [ -z "$1" ]; then
2481 echo "Usage: _get_free_inode <mnt>"
2485 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
2491 if [ "$iam" == new ]
2495 # make some further configuration checks here
2496 if [ "$TEST_DEV" = "" ]
2498 echo "common/rc: Error: \$TEST_DEV is not set"
2502 # if $TEST_DEV is not mounted, mount it now as XFS
2503 if [ -z "`_fs_type $TEST_DEV`" ]
2505 # $TEST_DEV is not mounted
2508 echo "common/rc: retrying test device mount with external set"
2509 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2512 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2518 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2520 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2524 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2525 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2526 export XFS_IO_PROG="$XFS_IO_PROG -F"
2529 # get real device path name by following link
2533 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
2534 _dev=`readlink -f "$_dev"`
2539 # basename of a device
2542 echo `basename $(_real_dev $1)`
2547 ################################################################################
2548 # make sure this script returns success