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 2>&1 | grep noxfer >/dev/null
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 # if dup profile is in mkfs options call _scratch_mkfs instead
589 # because dup profile only works with single device
590 if [[ "$*" =~ dup ]]; then
593 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
597 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
602 # Create fs of certain size on scratch device
603 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
604 _scratch_mkfs_sized()
611 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
613 ext2|ext3|ext4|ext4dev|udf|btrfs)
614 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
618 [ -n "$def_blksz" ] && blocksize=$def_blksz
619 [ -z "$blocksize" ] && blocksize=4096
623 if ! [[ $fssize =~ $re ]] ; then
624 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
626 if ! [[ $blocksize =~ $re ]] ; then
627 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
630 blocks=`expr $fssize / $blocksize`
632 if [ "$HOSTOS" == "Linux" ]; then
633 devsize=`blockdev --getsize64 $SCRATCH_DEV`
634 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
639 # don't override MKFS_OPTIONS that set a block size.
640 echo $MKFS_OPTIONS |egrep -q "b?size="
641 if [ $? -eq 0 ]; then
642 _scratch_mkfs_xfs -d size=$fssize
644 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
647 ext2|ext3|ext4|ext4dev)
648 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
651 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
654 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
657 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
662 # Emulate an N-data-disk stripe w/ various stripe units
663 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
669 [ -z "$blocksize" ] && blocksize=4096
671 let sunit_blocks=$sunit_bytes/$blocksize
672 let swidth_blocks=$sunit_blocks*$swidth_mult
676 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
679 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
682 _notrun "can't mkfs $FSTYP with geometry"
692 xfs_io -x -c "resblks $1" $SCRATCH_MNT
699 _scratch_xfs_db_options()
702 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
703 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
704 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
707 _scratch_xfs_logprint()
710 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
711 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
712 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
718 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
719 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
720 [ "$LARGE_SCRATCH_DEV" = yes ] && \
721 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
722 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
725 _scratch_xfs_repair()
728 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
729 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
730 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
731 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
732 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
733 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
740 echo "Usage: _get_pids_by_name process-name" 1>&2
744 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
745 # HH:MM:SS before the psargs field, use this as the search anchor.
747 # Matches with $1 (process-name) occur if the first psarg is $1
748 # or ends in /$1 ... the matching uses sed's regular expressions,
749 # so passing a regex into $1 will work.
757 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
758 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
761 # fix malloc libs output
765 # filter out the Electric Fence notice
768 if (defined $o && /^\s+Electric Fence/) {
774 print $o if (defined $o);
778 print $o if (defined $o);
782 # check if run as root
786 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
789 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
796 # _df_device : get an IRIX style df line for a given device
798 # - returns "" if not mounted
799 # - returns fs type in field two (ala IRIX)
800 # - joins line together if split by fancy df formatting
801 # - strips header etc
808 echo "Usage: _df_device device" 1>&2
812 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
813 match($1,what) && NF==1 {
827 # _df_dir : get an IRIX style df line for device where a directory resides
829 # - returns fs type in field two (ala IRIX)
830 # - joins line together if split by fancy df formatting
831 # - strips header etc
838 echo "Usage: _df_dir device" 1>&2
842 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
858 # return percentage used disk space for mounted device
864 echo "Usage: _used device" 1>&2
868 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
871 # return the FS type of a mounted device
877 echo "Usage: _fs_type device" 1>&2
882 # The Linux kernel shows NFSv4 filesystems in df output as
883 # filesystem type nfs4, although we mounted it as nfs earlier.
884 # Fix the filesystem type up here so that the callers don't
885 # have to bother with this quirk.
887 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
890 # return the FS mount options of a mounted device
892 # should write a version which just parses the output of mount for IRIX
893 # compatibility, but since this isn't used at all, at the moment I'll leave
900 echo "Usage: _fs_options device" 1>&2
904 $AWK_PROG -v dev=$1 '
905 match($1,dev) { print $4 }
909 # returns device number if a file is a block device
915 echo "Usage: _is_block_dev dev" 1>&2
920 if [ -L "${_dev}" ]; then
921 _dev=`readlink -f ${_dev}`
924 if [ -b "${_dev}" ]; then
925 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
929 # Do a command, log it to $seqres.full, optionally test return status
930 # and die if command fails. If called with one argument _do executes the
931 # command, logs it, and returns its exit status. With two arguments _do
932 # first prints the message passed in the first argument, and then "done"
933 # or "fail" depending on the return status of the command passed in the
934 # second argument. If the command fails and the variable _do_die_on_error
935 # is set to "always" or the two argument form is used and _do_die_on_error
936 # is set to "message_only" _do will print an error message to
937 # $seqres.out and exit.
941 if [ $# -eq 1 ]; then
943 elif [ $# -eq 2 ]; then
948 echo "Usage: _do [note] cmd" 1>&2
952 (eval "echo '---' \"$_cmd\"") >>$seqres.full
953 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
954 cat $tmp._out | _fix_malloc >>$seqres.full
955 if [ $# -eq 2 ]; then
956 if [ $ret -eq 0 ]; then
963 && [ "$_do_die_on_error" = "always" \
964 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
967 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
974 # bail out, setting up .notrun file. Need to kill the filesystem check files
975 # here, otherwise they are set incorrectly for the next test.
979 echo "$*" > $seqres.notrun
980 echo "$seq not run: $*"
981 rm -f ${RESULT_DIR}/require_test
982 rm -f ${RESULT_DIR}/require_scratch
987 # just plain bail out
991 echo "$*" | tee -a $seqres.full
992 echo "(see $seqres.full for details)"
997 # tests whether $FSTYP is one of the supported filesystems for a test
1003 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1009 _notrun "not suitable for this filesystem type: $FSTYP"
1013 # tests whether $FSTYP is one of the supported OSes for a test
1019 if [ "$h" = "$HOSTOS" ]
1025 _notrun "not suitable for this OS: $HOSTOS"
1028 # this test needs a scratch partition - check we're ok & unmount it
1029 # No post-test check of the device is required. e.g. the test intentionally
1030 # finishes the test with the filesystem in a corrupt state
1031 _require_scratch_nocheck()
1035 _notrun "requires a scratch device"
1038 _notrun "requires a scratch device"
1041 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1043 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1047 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
1049 _notrun "this test requires a valid \$SCRATCH_DEV"
1051 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1053 _notrun "this test requires a valid \$SCRATCH_DEV"
1055 if [ ! -d "$SCRATCH_MNT" ]
1057 _notrun "this test requires a valid \$SCRATCH_MNT"
1063 if _mount | grep -q $SCRATCH_DEV
1065 # if it's mounted, make sure its on $SCRATCH_MNT
1066 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1068 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1071 # and then unmount it
1072 if ! $UMOUNT_PROG $SCRATCH_DEV
1074 echo "failed to unmount $SCRATCH_DEV"
1078 rm -f ${RESULT_DIR}/require_scratch
1081 # we need the scratch device and it should be checked post test.
1084 _require_scratch_nocheck
1085 touch ${RESULT_DIR}/require_scratch
1089 # this test needs a test partition - check we're ok & unmount it
1095 _notrun "requires a test device"
1098 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1099 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1100 _notrun "this test requires a valid \$TEST_DEV"
1102 if [ ! -d "$TEST_DIR" ]; then
1103 _notrun "this test requires a valid \$TEST_DIR"
1107 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1109 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1113 if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
1115 _notrun "this test requires a valid \$TEST_DEV"
1117 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1119 _notrun "this test requires a valid \$TEST_DEV"
1121 if [ ! -d "$TEST_DIR" ]
1123 _notrun "this test requires a valid \$TEST_DIR"
1129 if _mount | grep -q $TEST_DEV
1131 # if it's mounted, make sure its on $TEST_DIR
1132 if ! _mount | grep $TEST_DEV | grep -q $TEST_DIR
1134 echo "\$TEST_DEV is mounted but not on \$TEST_DIR - aborting"
1138 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1139 if [ $? -ne 1 ]; then
1144 touch ${RESULT_DIR}/require_test
1147 # this test needs a logdev
1151 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1152 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1153 [ "$USE_EXTERNAL" != yes ] && \
1154 _notrun "This test requires USE_EXTERNAL to be enabled"
1156 # ensure its not mounted
1157 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1160 # this test requires loopback device support
1164 if [ "$HOSTOS" != "Linux" ]
1166 _notrun "This test requires linux for loopback device support"
1169 modprobe loop >/dev/null 2>&1
1170 if grep loop /proc/devices >/dev/null 2>&1
1174 _notrun "This test requires loopback device support"
1178 # this test requires ext2 filesystem support
1182 if [ "$HOSTOS" != "Linux" ]
1184 _notrun "This test requires linux for ext2 filesystem support"
1187 modprobe ext2 >/dev/null 2>&1
1188 if grep ext2 /proc/filesystems >/dev/null 2>&1
1192 _notrun "This test requires ext2 filesystem support"
1196 # this test requires that (large) loopback device files are not in use
1198 _require_no_large_scratch_dev()
1200 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1201 _notrun "Large filesystem testing in progress, skipped this test"
1204 # this test requires that a realtime subvolume is in use, and
1205 # that the kernel supports realtime as well.
1209 [ "$USE_EXTERNAL" = yes ] || \
1210 _notrun "External volumes not in use, skipped this test"
1211 [ "$SCRATCH_RTDEV" = "" ] && \
1212 _notrun "Realtime device required, skipped this test"
1215 # this test requires that a specified command (executable) exists
1216 # $1 - command, $2 - name for error message
1220 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1221 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1224 # this test requires the device mapper flakey target
1226 _require_dm_flakey()
1228 _require_command $DMSETUP_PROG
1230 modprobe dm-flakey >/dev/null 2>&1
1231 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1236 _notrun "This test requires dm flakey support"
1240 # this test requires the projid32bit feature to be available in mkfs.xfs.
1242 _require_projid32bit()
1244 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1245 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1248 _require_projid16bit()
1250 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1251 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1254 # this test requires the crc feature to be available in mkfs.xfs
1256 _require_xfs_mkfs_crc()
1258 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1259 || _notrun "mkfs.xfs doesn't have crc feature"
1262 # this test requires the xfs kernel support crc feature
1266 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1267 _scratch_mount >/dev/null 2>&1 \
1268 || _notrun "Kernel doesn't support crc feature"
1272 # this test requires the bigalloc feature to be available in mkfs.ext4
1274 _require_ext4_mkfs_bigalloc()
1276 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 200k >/dev/null 2>&1 \
1277 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1280 # this test requires the ext4 kernel support bigalloc feature
1282 _require_ext4_bigalloc()
1284 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 200k >/dev/null 2>&1
1285 _scratch_mount >/dev/null 2>&1 \
1286 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1290 # this test requires the finobt feature to be available in mkfs.xfs
1292 _require_xfs_mkfs_finobt()
1294 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1295 || _notrun "mkfs.xfs doesn't have finobt feature"
1298 # this test requires the xfs kernel support finobt feature
1300 _require_xfs_finobt()
1302 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1303 _scratch_mount >/dev/null 2>&1 \
1304 || _notrun "Kernel doesn't support finobt feature"
1308 # this test requires xfs sysfs attribute support
1310 _require_xfs_sysfs()
1313 sysfsdir=/sys/fs/xfs
1315 if [ ! -e $sysfsdir ]; then
1316 _notrun "no kernel support for XFS sysfs attributes"
1319 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1320 _notrun "sysfs attribute '$attr' is not supported"
1324 # this test requires that external log/realtime devices are not in use
1326 _require_nonexternal()
1328 [ "$USE_EXTERNAL" = yes ] && \
1329 _notrun "External device testing in progress, skipped this test"
1332 # this test requires that a (specified) aio-dio executable exists
1333 # $1 - command (optional)
1339 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1340 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1342 AIO_TEST=src/aio-dio-regress/$1
1343 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1347 # run an aio-dio program
1353 echo "usage: _run_aiodio command_name" 2>&1
1359 local testtemp=$TEST_DIR/aio-testfile
1361 $AIO_TEST $testtemp 2>&1
1368 # indicate whether YP/NIS is active or not
1373 dn=$(domainname 2>/dev/null)
1374 test -n "${dn}" -a "${dn}" != "(none)"
1378 # cat the password file
1382 [ $(_yp_active) -eq 0 ] && ypcat passwd
1386 # cat the group file
1390 [ $(_yp_active) -eq 0 ] && ypcat group
1394 # check for the fsgqa user on the machine
1399 _cat_passwd | grep -q $qa_user
1400 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1401 echo /bin/true | su $qa_user
1402 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1405 # check for the fsgqa group on the machine
1410 _cat_group | grep -q $qa_group
1411 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1417 s,.*Permission\sdenied.*,Permission denied,;
1418 s,.*no\saccess\sto\stty.*,,;
1419 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1426 if [ "$HOSTOS" == "IRIX" ]
1428 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1430 echo $1 | su $qa_user 2>&1 | _filter_user_do
1434 _require_xfs_io_command()
1438 echo "Usage: _require_xfs_io_command command" 1>&2
1443 testfile=$TEST_DIR/$$.xfs_io
1446 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1448 "fpunch" | "fcollapse" | "zero" | "fzero" )
1449 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1450 -c "$command 4k 8k" $testfile 2>&1`
1453 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1454 -c "fiemap -v" $testfile 2>&1`
1457 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1459 echo $testio | egrep -q "invalid option|Is a directory" && \
1460 _notrun "xfs_io $command support is missing"
1463 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1466 rm -f $testfile 2>&1 > /dev/null
1467 echo $testio | grep -q "not found" && \
1468 _notrun "xfs_io $command support is missing"
1469 echo $testio | grep -q "Operation not supported" && \
1470 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1473 # Check that a fs has enough free space (in 1024b blocks)
1478 BLOCKS=$2 # in units of 1024
1479 let GB=$BLOCKS/1024/1024
1481 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1482 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1483 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1487 # Check if the filesystem supports sparse files.
1489 # Unfortunately there is no better way to do this than a manual black list.
1491 _require_sparse_files()
1495 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1504 #boot_params always present in debugfs
1505 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1508 _require_fail_make_request()
1510 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1511 || _notrun "$DEBUGFS_MNT/fail_make_request \
1512 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1516 # Check if the file system supports seek_data/hole
1518 _require_seek_data_hole()
1520 testfile=$TEST_DIR/$$.seek
1521 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1522 rm -f $testfile &>/dev/null
1523 echo $testseek | grep -q "Kernel does not support" && \
1524 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1527 # check that a FS on a device is mounted
1528 # if so, return mount point
1534 echo "Usage: _is_mounted device" 1>&2
1540 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1541 pattern { print $3 ; exit 0 }
1545 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1550 # remount a FS to a new mode (ro or rw)
1556 echo "Usage: _remount device ro/rw" 1>&2
1562 if ! mount -o remount,$mode $device
1564 echo "_remount: failed to remount filesystem on $device as $mode"
1569 # Run the appropriate repair/check on a filesystem
1571 # if the filesystem is mounted, it's either remounted ro before being
1572 # checked or it's unmounted and then remounted
1575 # If set, we remount ro instead of unmounting for fsck
1578 _umount_or_remount_ro()
1582 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1587 mountpoint=`_is_mounted $device`
1589 if [ $USE_REMOUNT -eq 0 ]; then
1590 $UMOUNT_PROG $device
1597 _mount_or_remount_rw()
1601 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1608 if [ $USE_REMOUNT -eq 0 ]
1610 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1612 echo "!!! failed to remount $device on $mountpoint"
1622 # Check a generic filesystem in no-op mode; this assumes that the
1623 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1624 # and that it will still return an errno for corruption in this mode.
1626 # Filesystems which don't support this will need to define their
1627 # own check routine.
1629 _check_generic_filesystem()
1633 # If type is set, we're mounted
1634 type=`_fs_type $device`
1637 if [ "$type" = "$FSTYP" ]
1640 mountpoint=`_umount_or_remount_ro $device`
1643 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1646 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1648 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1649 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1650 cat $tmp.fsck >>$seqres.full
1651 echo "*** end fsck.$FSTYP output" >>$seqres.full
1659 echo "*** mount output ***" >>$seqres.full
1660 _mount >>$seqres.full
1661 echo "*** end mount output" >>$seqres.full
1662 elif [ "$type" = "$FSTYP" ]
1665 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1669 if [ $ok -eq 0 ]; then
1677 # run xfs_check and friends on a FS.
1679 _check_xfs_filesystem()
1683 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1687 extra_mount_options=""
1689 if [ "$2" != "none" ]; then
1690 extra_log_options="-l$2"
1691 extra_mount_options="-ologdev=$2"
1694 if [ "$3" != "none" ]; then
1695 extra_rt_options="-r$3"
1696 extra_mount_options=$extra_mount_options" -ortdev=$3"
1698 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1700 [ "$FSTYP" != xfs ] && return 0
1702 type=`_fs_type $device`
1705 if [ "$type" = "xfs" ]
1708 mountpoint=`_umount_or_remount_ro $device`
1711 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1712 | tee $tmp.logprint | grep -q "<CLEAN>"
1713 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1715 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1717 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1718 echo "*** xfs_logprint -t output ***" >>$seqres.full
1719 cat $tmp.logprint >>$seqres.full
1720 echo "*** end xfs_logprint output" >>$seqres.full
1725 # xfs_check runs out of memory on large files, so even providing the test
1726 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1727 # large filesystems. Avoid it.
1728 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1729 _xfs_check $extra_log_options $device 2>&1 |\
1730 _fix_malloc >$tmp.fs_check
1732 if [ -s $tmp.fs_check ]
1734 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1736 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1737 echo "*** xfs_check output ***" >>$seqres.full
1738 cat $tmp.fs_check >>$seqres.full
1739 echo "*** end xfs_check output" >>$seqres.full
1744 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1747 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1749 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1750 echo "*** xfs_repair -n output ***" >>$seqres.full
1751 cat $tmp.repair | _fix_malloc >>$seqres.full
1752 echo "*** end xfs_repair output" >>$seqres.full
1756 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1760 echo "*** mount output ***" >>$seqres.full
1761 _mount >>$seqres.full
1762 echo "*** end mount output" >>$seqres.full
1763 elif [ "$type" = "xfs" ]
1765 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1768 if [ $ok -eq 0 ]; then
1770 if [ "$iam" != "check" ]; then
1778 # Filter the knowen errors the UDF Verifier reports.
1779 _udf_test_known_error_filter()
1781 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."
1785 _check_udf_filesystem()
1787 [ "$DISABLE_UDF_TEST" == "1" ] && return
1789 if [ $# -ne 1 -a $# -ne 2 ]
1791 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1795 if [ ! -x $here/src/udf_test ]
1797 echo "udf_test not installed, please download and build the Philips"
1798 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1799 echo "Then copy the udf_test binary to $here/src/."
1800 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1808 LAST_BLOCK=`expr \( $2 - 1 \)`
1809 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1812 rm -f $seqres.checkfs
1813 sleep 1 # Due to a problem with time stamps in udf_test
1814 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1815 _udf_test_known_error_filter | \
1816 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1817 echo "Warning UDF Verifier reported errors see $seqres.checkfs."
1820 _check_xfs_test_fs()
1824 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1825 TEST_LOG="$TEST_LOGDEV"
1827 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1828 TEST_RT="$TEST_RTDEV"
1830 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1832 # check for ipath consistency
1833 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1834 # errors go to stderr
1835 xfs_check_ipaths $TEST_DIR >/dev/null
1836 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1840 _check_btrfs_filesystem()
1844 # If type is set, we're mounted
1845 type=`_fs_type $device`
1848 if [ "$type" = "$FSTYP" ]
1851 mountpoint=`_umount_or_remount_ro $device`
1854 btrfsck $device >$tmp.fsck 2>&1
1857 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1859 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1860 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1861 cat $tmp.fsck >>$seqres.full
1862 echo "*** end fsck.$FSTYP output" >>$seqres.full
1870 echo "*** mount output ***" >>$seqres.full
1871 _mount >>$seqres.full
1872 echo "*** end mount output" >>$seqres.full
1873 elif [ "$type" = "$FSTYP" ]
1876 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1880 if [ $ok -eq 0 ]; then
1895 # no way to check consistency for nfs
1898 # no way to check consistency for cifs
1901 # do nothing for now
1904 _check_btrfs_filesystem $TEST_DEV
1907 # no way to check consistency for tmpfs
1910 _check_generic_filesystem $TEST_DEV
1918 [ $# -eq 1 ] && device=$1
1924 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1925 SCRATCH_LOG="$SCRATCH_LOGDEV"
1927 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1928 SCRATCH_RT="$SCRATCH_RTDEV"
1930 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1933 _check_udf_filesystem $device $udf_fsize
1936 # Don't know how to check an NFS filesystem, yet.
1939 # Don't know how to check a CIFS filesystem, yet.
1942 _check_btrfs_filesystem $device
1945 # no way to check consistency for tmpfs
1948 _check_generic_filesystem $device
1953 _full_fstyp_details()
1955 [ -z "$FSTYP" ] && FSTYP=xfs
1956 if [ $FSTYP = xfs ]; then
1957 if [ -d /proc/fs/xfs ]; then
1958 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1959 FSTYP="$FSTYP (non-debug)"
1960 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1961 FSTYP="$FSTYP (debug)"
1964 if uname -a | grep -qi 'debug'; then
1965 FSTYP="$FSTYP (debug)"
1967 FSTYP="$FSTYP (non-debug)"
1974 _full_platform_details()
1980 echo "$os/$platform $host $kernel"
1985 if [ -z "$1" -o -z "$2" ]; then
1986 echo Error must pass src and dst.
1990 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1992 elif [ "`uname`" == "Linux" ]; then
1995 echo Error test $seq does not run on the operating system: `uname`
2006 #takes files, randomdata
2014 if [ $size -gt 0 ]; then
2015 if [ "$2" == "false" ]; then
2016 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2018 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2025 # takes dirname, depth, randomdata
2028 dirname=$1; depth=$2; randomdata=$3
2029 mkdir $dirname || die "mkdir $dirname failed"
2032 _nfiles $files $randomdata # files for this dir and data type
2034 [ $depth -eq 0 ] && return
2035 let deep=$depth-1 # go 1 down
2037 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2040 while [ $d -lt $dirs ]
2042 _descend d$d $deep &
2048 # Populate a filesystem with inodes for performance experiments
2050 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2055 dirs=5 # ndirs in each subdir till leaves
2056 size=0 # sizeof files in K
2057 files=100 # num files in _each_ subdir
2058 depth=2 # depth of tree from root to leaves
2060 root=root # path of initial root of directory tree
2061 randomdata=false # -x data type urandom or zero
2064 while getopts "d:f:n:r:s:v:x" c
2073 x) randomdata=true;;
2077 _descend $root $depth $randomdata
2082 [ $verbose = true ] && echo done
2085 # query whether the given file has the given inode flag set
2092 if which $XFS_IO_PROG >/dev/null; then
2093 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2100 # query the given files extsize allocator hint in bytes (if any)
2107 if which $XFS_IO_PROG >/dev/null; then
2108 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2109 awk '/^xattr.extsize =/ { print $3 }'`
2111 [ -z "$blocks" ] && blocks="0"
2115 # scratch_dev_pool should contain the disks pool for the btrfs raid
2116 _require_scratch_dev_pool()
2121 if [ -z "$SCRATCH_DEV_POOL" ]; then
2122 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2125 if [ -z "$1" ]; then
2131 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2135 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2136 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2140 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2144 for i in $SCRATCH_DEV_POOL; do
2145 if [ "`_is_block_dev $i`" = "" ]; then
2146 _notrun "this test requires valid block disk $i"
2148 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
2149 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2151 if _mount | grep -q $i; then
2152 if ! $UMOUNT_PROG $i; then
2153 echo "failed to unmount $i - aborting"
2157 # to help better debug when something fails, we remove
2158 # traces of previous btrfs FS on the dev.
2159 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2163 # We will check if the device is deletable
2164 _require_deletable_scratch_dev_pool()
2168 for i in $SCRATCH_DEV_POOL; do
2169 x=`echo $i | cut -d"/" -f 3`
2170 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2171 _notrun "$i is a device which is not deletable"
2176 # We check for btrfs and (optionally) features of the btrfs command
2180 _require_command $BTRFS_UTIL_PROG btrfs
2181 if [ -z "$1" ]; then
2184 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2185 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2188 # Check that fio is present, and it is able to execute given jobfile
2193 _require_command $FIO_PROG
2194 if [ -z "$1" ]; then
2198 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2199 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2202 # Does freeze work on this fs?
2205 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2207 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2208 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2211 # arg 1 is dev to remove and is output of the below eg.
2212 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2218 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2220 stat $disk > /dev/null 2>&1
2221 while [ $? -eq 0 ]; do
2223 stat $disk > /dev/null 2>&1
2227 # arg 1 is dev to add and is output of the below eg.
2228 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2233 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2234 h=`echo ${1} | cut -d":" -f 1`
2235 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2237 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2239 # ensure the device comes online
2241 for i in `seq 1 10`; do
2242 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2243 dev=`ls /sys/class/scsi_device/${1}/device/block`
2244 for j in `seq 1 10`;
2246 stat /dev/$dev > /dev/null 2>&1
2247 if [ $? -eq 0 ]; then
2258 if [ $dev_back_oneline -eq 0 ]; then
2259 echo "/dev/$dev online failed" >> $seqres.full
2261 echo "/dev/$dev is back online" >> $seqres.full
2267 if [ -z "$FSTRIM_PROG" ]; then
2268 _notrun "This test requires fstrim utility."
2272 _test_batched_discard()
2274 if [ $# -ne 1 ]; then
2275 echo "Usage: _test_batched_discard mnt_point" 1>&2
2279 $FSTRIM_PROG ${1} &>/dev/null
2284 if [ -z "$DUMPE2FS_PROG" ]; then
2285 _notrun "This test requires dumpe2fs utility."
2291 if [ ! -e /proc/self/uid_map ]; then
2292 _notrun "This test requires procfs uid_map support."
2294 if [ ! -e /proc/self/gid_map ]; then
2295 _notrun "This test requires procfs gid_map support."
2299 _require_cp_reflink()
2301 cp --help | grep -q reflink || \
2302 _notrun "This test requires a cp with --reflink support."
2307 FSSUM_PROG=$here/src/fssum
2308 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2311 _require_btrfs_cloner()
2313 CLONER_PROG=$here/src/cloner
2314 [ -x $CLONER_PROG ] || \
2315 _notrun "cloner binary not present at $CLONER_PROG"
2318 # Given 2 files, verify that they have the same mapping but different
2319 # inodes - i.e. an undisturbed reflink
2320 # Silent if so, make noise if not
2323 # not a hard link or symlink?
2324 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2325 && echo "$1 and $2 are not reflinks: same inode number"
2328 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2329 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2330 || echo "$1 and $2 are not reflinks: different extents"
2335 _scratch_mkfs > /dev/null 2>&1
2336 _mount -t $FSTYP -o relatime $SCRATCH_DEV $SCRATCH_MNT || \
2337 _notrun "relatime not supported by the current kernel"
2343 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2344 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2347 _create_loop_device()
2350 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2354 _destroy_loop_device()
2357 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2360 _scale_fsstress_args()
2363 while [ $# -gt 0 ]; do
2365 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2366 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2367 *) args="$args $1" ;;
2375 # Return the logical block size if running on a block device,
2376 # else substitute the page size.
2378 _min_dio_alignment()
2382 if [ -b "$dev" ]; then
2383 blockdev --getss $dev
2385 $here/src/feature -s
2391 echo "# $@" >> $seqres.full 2>&1
2392 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2395 _run_btrfs_util_prog()
2397 run_check $BTRFS_UTIL_PROG $*
2400 _require_btrfs_send_stream_version()
2402 $BTRFS_UTIL_PROG send 2>&1 | \
2403 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2404 if [ $? -ne 0 ]; then
2405 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2408 # test if btrfs kernel supports send stream version 2
2409 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
2410 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
2414 _require_btrfs_mkfs_feature()
2417 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
2421 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
2422 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
2424 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
2427 _require_btrfs_fs_feature()
2430 echo "Missing feature name argument for _require_btrfs_fs_feature"
2434 modprobe btrfs > /dev/null 2>&1
2435 [ -e /sys/fs/btrfs/features/$feat ] || \
2436 _notrun "Feature $feat not supported by the available btrfs version"
2439 _require_test_symlinks()
2441 # IRIX UDF does not support symlinks
2442 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2443 _notrun "Require symlinks support"
2444 target=`mktemp -p $TEST_DIR`
2445 link=`mktemp -p $TEST_DIR -u`
2446 ln -s `basename $target` $link
2447 if [ "$?" -ne 0 ]; then
2449 _notrun "Require symlinks support"
2454 _require_test_fcntl_advisory_locks()
2456 [ "$FSTYP" != "cifs" ] && return 0
2457 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
2458 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
2459 _notrun "Require fcntl advisory locks support"
2464 if [ -z "$1" ]; then
2465 echo "Usage: _get_total_inode <mnt>"
2469 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
2475 if [ -z "$1" ]; then
2476 echo "Usage: _get_used_inode <mnt>"
2480 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
2486 if [ -z "$1" ]; then
2487 echo "Usage: _get_free_inode <mnt>"
2491 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
2495 # get btrfs profile configs being tested
2497 # A set of pre-set profile configs are exported via _btrfs_profile_configs
2498 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
2499 # var in the format "metadata_profile:data_profile", multiple configs can be
2500 # seperated by space, e.g.
2501 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
2502 _btrfs_get_profile_configs()
2504 if [ "$FSTYP" != "btrfs" ]; then
2508 # no user specified btrfs profile configs, export the default configs
2509 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
2511 _btrfs_profile_configs=(
2512 "-m single -d single"
2517 "-m raid10 -d raid10"
2522 # remove dup/raid5/raid6 profiles if we're doing device replace
2523 # dup profile indicates only one device being used (SCRATCH_DEV),
2524 # but we don't want to replace SCRATCH_DEV, which will be used in
2525 # _scratch_mount/_check_scratch_fs etc.
2526 # and raid5/raid6 doesn't support replace yet
2527 if [ "$1" == "replace" ]; then
2528 _btrfs_profile_configs=(
2529 "-m single -d single"
2533 "-m raid10 -d raid10"
2534 # add these back when raid5/6 is working with replace
2535 #"-m raid5 -d raid5"
2536 #"-m raid6 -d raid6"
2539 export _btrfs_profile_configs
2543 # parse user specified btrfs profile configs
2546 for cfg in $BTRFS_PROFILE_CONFIGS; do
2547 # turn "metadata:data" format to "-m metadata -d data"
2548 # and assign it to _btrfs_profile_configs array
2549 cfg=`echo "$cfg" | sed -e 's/^/-m /' -e 's/:/ -d /'`
2550 _btrfs_profile_configs[$i]="$cfg"
2554 if [ "$1" == "replace" ]; then
2555 if echo ${_btrfs_profile_configs[*]} | grep -q raid[56]; then
2556 _notrun "RAID5/6 doesn't support btrfs device replace yet"
2558 if echo ${_btrfs_profile_configs[*]} | grep -q dup; then
2559 _notrun "Do not set dup profile in btrfs device replace test"
2562 export _btrfs_profile_configs
2565 # stress btrfs by running balance operation in a loop
2566 _btrfs_stress_balance()
2570 $BTRFS_UTIL_PROG balance start $btrfs_mnt
2574 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
2575 _btrfs_stress_subvolume()
2579 local subvol_name=$3
2582 mkdir -p $subvol_mnt
2584 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
2585 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
2586 $UMOUNT_PROG $subvol_mnt
2587 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
2591 # stress btrfs by running scrub in a loop
2592 _btrfs_stress_scrub()
2596 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
2602 if [ "$iam" == new ]
2606 # make some further configuration checks here
2607 if [ "$TEST_DEV" = "" ]
2609 echo "common/rc: Error: \$TEST_DEV is not set"
2613 # if $TEST_DEV is not mounted, mount it now as XFS
2614 if [ -z "`_fs_type $TEST_DEV`" ]
2616 # $TEST_DEV is not mounted
2619 echo "common/rc: retrying test device mount with external set"
2620 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2623 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2629 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2631 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2635 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2636 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2637 export XFS_IO_PROG="$XFS_IO_PROG -F"
2640 # get real device path name by following link
2644 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
2645 _dev=`readlink -f "$_dev"`
2650 # basename of a device
2653 echo `basename $(_real_dev $1)`
2658 if [ -z $1 ] || [ ! -d $1 ]; then
2659 echo "Missing mount point argument for get_block_size"
2662 echo `stat -f -c %S $1`
2667 ################################################################################
2668 # make sure this script returns success