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
554 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
555 _scratch_cleanup_files()
558 rm -rf $SCRATCH_MNT/*
569 # unable to re-create NFS, just remove all files in $SCRATCH_MNT to
570 # avoid EEXIST caused by the leftover files created in previous runs
571 _scratch_cleanup_files
574 # do nothing for cifs
577 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
580 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
583 _scratch_mkfs_ext4 $*
586 # do nothing for tmpfs
589 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
598 # if dup profile is in mkfs options call _scratch_mkfs instead
599 # because dup profile only works with single device
600 if [[ "$*" =~ dup ]]; then
603 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
607 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
612 # Create fs of certain size on scratch device
613 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
614 _scratch_mkfs_sized()
621 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
623 ext2|ext3|ext4|ext4dev|udf|btrfs)
624 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
628 [ -n "$def_blksz" ] && blocksize=$def_blksz
629 [ -z "$blocksize" ] && blocksize=4096
633 if ! [[ $fssize =~ $re ]] ; then
634 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
636 if ! [[ $blocksize =~ $re ]] ; then
637 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
640 blocks=`expr $fssize / $blocksize`
642 if [ "$HOSTOS" == "Linux" ]; then
643 devsize=`blockdev --getsize64 $SCRATCH_DEV`
644 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
649 # don't override MKFS_OPTIONS that set a block size.
650 echo $MKFS_OPTIONS |egrep -q "b?size="
651 if [ $? -eq 0 ]; then
652 _scratch_mkfs_xfs -d size=$fssize
654 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
657 ext2|ext3|ext4|ext4dev)
658 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
661 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
664 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
667 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
672 # Emulate an N-data-disk stripe w/ various stripe units
673 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
679 [ -z "$blocksize" ] && blocksize=4096
681 let sunit_blocks=$sunit_bytes/$blocksize
682 let swidth_blocks=$sunit_blocks*$swidth_mult
686 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
689 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
692 _notrun "can't mkfs $FSTYP with geometry"
702 xfs_io -x -c "resblks $1" $SCRATCH_MNT
709 _scratch_xfs_db_options()
712 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
713 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
714 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
717 _scratch_xfs_logprint()
720 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
721 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
722 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
728 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
729 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
730 [ "$LARGE_SCRATCH_DEV" = yes ] && \
731 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
732 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
735 _scratch_xfs_repair()
738 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
739 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
740 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
741 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
742 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
743 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
750 echo "Usage: _get_pids_by_name process-name" 1>&2
754 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
755 # HH:MM:SS before the psargs field, use this as the search anchor.
757 # Matches with $1 (process-name) occur if the first psarg is $1
758 # or ends in /$1 ... the matching uses sed's regular expressions,
759 # so passing a regex into $1 will work.
767 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
768 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
771 # fix malloc libs output
775 # filter out the Electric Fence notice
778 if (defined $o && /^\s+Electric Fence/) {
784 print $o if (defined $o);
788 print $o if (defined $o);
792 # check if run as root
796 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
799 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
806 # _df_device : get an IRIX style df line for a given device
808 # - returns "" if not mounted
809 # - returns fs type in field two (ala IRIX)
810 # - joins line together if split by fancy df formatting
811 # - strips header etc
818 echo "Usage: _df_device device" 1>&2
822 # Note that we use "==" here so awk doesn't try to interpret an NFS over
823 # IPv6 server as a regular expression.
824 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
825 ($1==what) && (NF==1) {
839 # _df_dir : get an IRIX style df line for device where a directory resides
841 # - returns fs type in field two (ala IRIX)
842 # - joins line together if split by fancy df formatting
843 # - strips header etc
850 echo "Usage: _df_dir device" 1>&2
854 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
870 # return percentage used disk space for mounted device
876 echo "Usage: _used device" 1>&2
880 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
883 # return the FS type of a mounted device
889 echo "Usage: _fs_type device" 1>&2
894 # The Linux kernel shows NFSv4 filesystems in df output as
895 # filesystem type nfs4, although we mounted it as nfs earlier.
896 # Fix the filesystem type up here so that the callers don't
897 # have to bother with this quirk.
899 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
902 # return the FS mount options of a mounted device
904 # should write a version which just parses the output of mount for IRIX
905 # compatibility, but since this isn't used at all, at the moment I'll leave
912 echo "Usage: _fs_options device" 1>&2
916 $AWK_PROG -v dev=$1 '
917 match($1,dev) { print $4 }
921 # returns device number if a file is a block device
927 echo "Usage: _is_block_dev dev" 1>&2
932 if [ -L "${_dev}" ]; then
933 _dev=`readlink -f ${_dev}`
936 if [ -b "${_dev}" ]; then
937 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
941 # Do a command, log it to $seqres.full, optionally test return status
942 # and die if command fails. If called with one argument _do executes the
943 # command, logs it, and returns its exit status. With two arguments _do
944 # first prints the message passed in the first argument, and then "done"
945 # or "fail" depending on the return status of the command passed in the
946 # second argument. If the command fails and the variable _do_die_on_error
947 # is set to "always" or the two argument form is used and _do_die_on_error
948 # is set to "message_only" _do will print an error message to
949 # $seqres.out and exit.
953 if [ $# -eq 1 ]; then
955 elif [ $# -eq 2 ]; then
960 echo "Usage: _do [note] cmd" 1>&2
964 (eval "echo '---' \"$_cmd\"") >>$seqres.full
965 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
966 cat $tmp._out | _fix_malloc >>$seqres.full
967 if [ $# -eq 2 ]; then
968 if [ $ret -eq 0 ]; then
975 && [ "$_do_die_on_error" = "always" \
976 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
979 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
986 # bail out, setting up .notrun file. Need to kill the filesystem check files
987 # here, otherwise they are set incorrectly for the next test.
991 echo "$*" > $seqres.notrun
992 echo "$seq not run: $*"
993 rm -f ${RESULT_DIR}/require_test
994 rm -f ${RESULT_DIR}/require_scratch
999 # just plain bail out
1003 echo "$*" | tee -a $seqres.full
1004 echo "(see $seqres.full for details)"
1009 # tests whether $FSTYP is one of the supported filesystems for a test
1015 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1021 _notrun "not suitable for this filesystem type: $FSTYP"
1025 # tests whether $FSTYP is one of the supported OSes for a test
1031 if [ "$h" = "$HOSTOS" ]
1037 _notrun "not suitable for this OS: $HOSTOS"
1040 # this test needs a scratch partition - check we're ok & unmount it
1041 # No post-test check of the device is required. e.g. the test intentionally
1042 # finishes the test with the filesystem in a corrupt state
1043 _require_scratch_nocheck()
1047 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1048 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1049 _notrun "this test requires a valid \$SCRATCH_DEV"
1051 if [ ! -d "$SCRATCH_MNT" ]; then
1052 _notrun "this test requires a valid \$SCRATCH_MNT"
1056 _notrun "requires a scratch device"
1059 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1061 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1065 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
1067 _notrun "this test requires a valid \$SCRATCH_DEV"
1069 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1071 _notrun "this test requires a valid \$SCRATCH_DEV"
1073 if [ ! -d "$SCRATCH_MNT" ]
1075 _notrun "this test requires a valid \$SCRATCH_MNT"
1081 if _mount | grep -q $SCRATCH_DEV
1083 # if it's mounted, make sure its on $SCRATCH_MNT
1084 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1086 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1089 # and then unmount it
1090 if ! $UMOUNT_PROG $SCRATCH_DEV
1092 echo "failed to unmount $SCRATCH_DEV"
1096 rm -f ${RESULT_DIR}/require_scratch
1099 # we need the scratch device and it should be checked post test.
1102 _require_scratch_nocheck
1103 touch ${RESULT_DIR}/require_scratch
1107 # this test needs a test partition - check we're ok & unmount it
1113 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1114 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1115 _notrun "this test requires a valid \$TEST_DIR"
1117 if [ ! -d "$TEST_DIR" ]; then
1118 _notrun "this test requires a valid \$TEST_DIR"
1122 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1123 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1124 _notrun "this test requires a valid \$TEST_DEV"
1126 if [ ! -d "$TEST_DIR" ]; then
1127 _notrun "this test requires a valid \$TEST_DIR"
1131 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1133 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1137 if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
1139 _notrun "this test requires a valid \$TEST_DEV"
1141 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1143 _notrun "this test requires a valid \$TEST_DEV"
1145 if [ ! -d "$TEST_DIR" ]
1147 _notrun "this test requires a valid \$TEST_DIR"
1153 # Note that we use -F here so grep doesn't try to interpret an NFS over
1154 # IPv6 server as a regular expression.
1155 if _mount | grep -F -q $TEST_DEV
1157 # if it's mounted, make sure its on $TEST_DIR
1158 if ! _mount | grep -F $TEST_DEV | grep -q $TEST_DIR
1160 echo "\$TEST_DEV is mounted but not on \$TEST_DIR - aborting"
1164 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1165 if [ $? -ne 1 ]; then
1170 touch ${RESULT_DIR}/require_test
1173 # this test needs a logdev
1177 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1178 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1179 [ "$USE_EXTERNAL" != yes ] && \
1180 _notrun "This test requires USE_EXTERNAL to be enabled"
1182 # ensure its not mounted
1183 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1186 # this test requires loopback device support
1190 if [ "$HOSTOS" != "Linux" ]
1192 _notrun "This test requires linux for loopback device support"
1195 modprobe loop >/dev/null 2>&1
1196 if grep loop /proc/devices >/dev/null 2>&1
1200 _notrun "This test requires loopback device support"
1204 # this test requires ext2 filesystem support
1208 if [ "$HOSTOS" != "Linux" ]
1210 _notrun "This test requires linux for ext2 filesystem support"
1213 modprobe ext2 >/dev/null 2>&1
1214 if grep ext2 /proc/filesystems >/dev/null 2>&1
1218 _notrun "This test requires ext2 filesystem support"
1222 # this test requires that (large) loopback device files are not in use
1224 _require_no_large_scratch_dev()
1226 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1227 _notrun "Large filesystem testing in progress, skipped this test"
1230 # this test requires that a realtime subvolume is in use, and
1231 # that the kernel supports realtime as well.
1235 [ "$USE_EXTERNAL" = yes ] || \
1236 _notrun "External volumes not in use, skipped this test"
1237 [ "$SCRATCH_RTDEV" = "" ] && \
1238 _notrun "Realtime device required, skipped this test"
1241 # this test requires that a specified command (executable) exists
1242 # $1 - command, $2 - name for error message
1246 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1247 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1250 # this test requires the device to be valid block device
1252 _require_block_device()
1254 if [ -z "$1" ]; then
1255 echo "Usage: _require_block_device <dev>" 1>&2
1258 if [ "`_is_block_dev $SCRATCH_DEV`" == "" ]; then
1259 _notrun "require $1 to be valid block disk"
1263 # this test requires the device mapper flakey target
1265 _require_dm_flakey()
1267 # require SCRATCH_DEV to be a valid block device
1268 _require_block_device $SCRATCH_DEV
1269 _require_command $DMSETUP_PROG
1271 modprobe dm-flakey >/dev/null 2>&1
1272 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1277 _notrun "This test requires dm flakey support"
1281 # this test requires the projid32bit feature to be available in mkfs.xfs.
1283 _require_projid32bit()
1285 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1286 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1289 _require_projid16bit()
1291 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1292 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1295 # this test requires the crc feature to be available in mkfs.xfs
1297 _require_xfs_mkfs_crc()
1299 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1300 || _notrun "mkfs.xfs doesn't have crc feature"
1303 # this test requires the xfs kernel support crc feature
1307 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1308 _scratch_mount >/dev/null 2>&1 \
1309 || _notrun "Kernel doesn't support crc feature"
1313 # this test requires the bigalloc feature to be available in mkfs.ext4
1315 _require_ext4_mkfs_bigalloc()
1317 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 200k >/dev/null 2>&1 \
1318 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1321 # this test requires the ext4 kernel support bigalloc feature
1323 _require_ext4_bigalloc()
1325 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 200k >/dev/null 2>&1
1326 _scratch_mount >/dev/null 2>&1 \
1327 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1331 # this test requires the finobt feature to be available in mkfs.xfs
1333 _require_xfs_mkfs_finobt()
1335 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1336 || _notrun "mkfs.xfs doesn't have finobt feature"
1339 # this test requires the xfs kernel support finobt feature
1341 _require_xfs_finobt()
1343 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1344 _scratch_mount >/dev/null 2>&1 \
1345 || _notrun "Kernel doesn't support finobt feature"
1349 # this test requires xfs sysfs attribute support
1351 _require_xfs_sysfs()
1354 sysfsdir=/sys/fs/xfs
1356 if [ ! -e $sysfsdir ]; then
1357 _notrun "no kernel support for XFS sysfs attributes"
1360 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1361 _notrun "sysfs attribute '$attr' is not supported"
1365 # this test requires that external log/realtime devices are not in use
1367 _require_nonexternal()
1369 [ "$USE_EXTERNAL" = yes ] && \
1370 _notrun "External device testing in progress, skipped this test"
1373 # this test requires that a (specified) aio-dio executable exists
1374 # $1 - command (optional)
1380 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1381 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1383 AIO_TEST=src/aio-dio-regress/$1
1384 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1388 # run an aio-dio program
1394 echo "usage: _run_aiodio command_name" 2>&1
1400 local testtemp=$TEST_DIR/aio-testfile
1402 $AIO_TEST $testtemp 2>&1
1409 # indicate whether YP/NIS is active or not
1414 dn=$(domainname 2>/dev/null)
1415 test -n "${dn}" -a "${dn}" != "(none)"
1419 # cat the password file
1423 [ $(_yp_active) -eq 0 ] && ypcat passwd
1427 # cat the group file
1431 [ $(_yp_active) -eq 0 ] && ypcat group
1435 # check for the fsgqa user on the machine
1440 _cat_passwd | grep -q $qa_user
1441 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1442 echo /bin/true | su $qa_user
1443 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1446 # check for the fsgqa group on the machine
1451 _cat_group | grep -q $qa_group
1452 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1458 s,.*Permission\sdenied.*,Permission denied,;
1459 s,.*no\saccess\sto\stty.*,,;
1460 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1467 if [ "$HOSTOS" == "IRIX" ]
1469 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1471 echo $1 | su $qa_user 2>&1 | _filter_user_do
1475 _require_xfs_io_command()
1479 echo "Usage: _require_xfs_io_command command" 1>&2
1484 testfile=$TEST_DIR/$$.xfs_io
1487 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1489 "fpunch" | "fcollapse" | "zero" | "fzero" )
1490 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1491 -c "$command 4k 8k" $testfile 2>&1`
1494 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1495 -c "fiemap -v" $testfile 2>&1`
1498 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1500 echo $testio | egrep -q "invalid option|Is a directory" && \
1501 _notrun "xfs_io $command support is missing"
1504 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1507 rm -f $testfile 2>&1 > /dev/null
1508 echo $testio | grep -q "not found" && \
1509 _notrun "xfs_io $command support is missing"
1510 echo $testio | grep -q "Operation not supported" && \
1511 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1514 # Check that a fs has enough free space (in 1024b blocks)
1519 BLOCKS=$2 # in units of 1024
1520 let GB=$BLOCKS/1024/1024
1522 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1523 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1524 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1528 # Check if the filesystem supports sparse files.
1530 # Unfortunately there is no better way to do this than a manual black list.
1532 _require_sparse_files()
1536 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1545 #boot_params always present in debugfs
1546 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1549 _require_fail_make_request()
1551 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1552 || _notrun "$DEBUGFS_MNT/fail_make_request \
1553 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1557 # Check if the file system supports seek_data/hole
1559 _require_seek_data_hole()
1561 testfile=$TEST_DIR/$$.seek
1562 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1563 rm -f $testfile &>/dev/null
1564 echo $testseek | grep -q "Kernel does not support" && \
1565 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1568 # check that a FS on a device is mounted
1569 # if so, return mount point
1575 echo "Usage: _is_mounted device" 1>&2
1581 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1582 pattern { print $3 ; exit 0 }
1586 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1591 # remount a FS to a new mode (ro or rw)
1597 echo "Usage: _remount device ro/rw" 1>&2
1603 if ! mount -o remount,$mode $device
1605 echo "_remount: failed to remount filesystem on $device as $mode"
1610 # Run the appropriate repair/check on a filesystem
1612 # if the filesystem is mounted, it's either remounted ro before being
1613 # checked or it's unmounted and then remounted
1616 # If set, we remount ro instead of unmounting for fsck
1619 _umount_or_remount_ro()
1623 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1628 mountpoint=`_is_mounted $device`
1630 if [ $USE_REMOUNT -eq 0 ]; then
1631 $UMOUNT_PROG $device
1638 _mount_or_remount_rw()
1642 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1649 if [ $USE_REMOUNT -eq 0 ]
1651 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1653 echo "!!! failed to remount $device on $mountpoint"
1663 # Check a generic filesystem in no-op mode; this assumes that the
1664 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1665 # and that it will still return an errno for corruption in this mode.
1667 # Filesystems which don't support this will need to define their
1668 # own check routine.
1670 _check_generic_filesystem()
1674 # If type is set, we're mounted
1675 type=`_fs_type $device`
1678 if [ "$type" = "$FSTYP" ]
1681 mountpoint=`_umount_or_remount_ro $device`
1684 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1687 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1689 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1690 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1691 cat $tmp.fsck >>$seqres.full
1692 echo "*** end fsck.$FSTYP output" >>$seqres.full
1700 echo "*** mount output ***" >>$seqres.full
1701 _mount >>$seqres.full
1702 echo "*** end mount output" >>$seqres.full
1703 elif [ "$type" = "$FSTYP" ]
1706 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1710 if [ $ok -eq 0 ]; then
1718 # run xfs_check and friends on a FS.
1720 _check_xfs_filesystem()
1724 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1728 extra_mount_options=""
1730 if [ "$2" != "none" ]; then
1731 extra_log_options="-l$2"
1732 extra_mount_options="-ologdev=$2"
1735 if [ "$3" != "none" ]; then
1736 extra_rt_options="-r$3"
1737 extra_mount_options=$extra_mount_options" -ortdev=$3"
1739 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1741 [ "$FSTYP" != xfs ] && return 0
1743 type=`_fs_type $device`
1746 if [ "$type" = "xfs" ]
1749 mountpoint=`_umount_or_remount_ro $device`
1752 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1753 | tee $tmp.logprint | grep -q "<CLEAN>"
1754 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1756 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1758 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1759 echo "*** xfs_logprint -t output ***" >>$seqres.full
1760 cat $tmp.logprint >>$seqres.full
1761 echo "*** end xfs_logprint output" >>$seqres.full
1766 # xfs_check runs out of memory on large files, so even providing the test
1767 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1768 # large filesystems. Avoid it.
1769 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1770 _xfs_check $extra_log_options $device 2>&1 |\
1771 _fix_malloc >$tmp.fs_check
1773 if [ -s $tmp.fs_check ]
1775 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1777 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1778 echo "*** xfs_check output ***" >>$seqres.full
1779 cat $tmp.fs_check >>$seqres.full
1780 echo "*** end xfs_check output" >>$seqres.full
1785 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1788 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1790 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1791 echo "*** xfs_repair -n output ***" >>$seqres.full
1792 cat $tmp.repair | _fix_malloc >>$seqres.full
1793 echo "*** end xfs_repair output" >>$seqres.full
1797 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1801 echo "*** mount output ***" >>$seqres.full
1802 _mount >>$seqres.full
1803 echo "*** end mount output" >>$seqres.full
1804 elif [ "$type" = "xfs" ]
1806 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1809 if [ $ok -eq 0 ]; then
1811 if [ "$iam" != "check" ]; then
1819 # Filter the knowen errors the UDF Verifier reports.
1820 _udf_test_known_error_filter()
1822 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."
1826 _check_udf_filesystem()
1828 [ "$DISABLE_UDF_TEST" == "1" ] && return
1830 if [ $# -ne 1 -a $# -ne 2 ]
1832 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1836 if [ ! -x $here/src/udf_test ]
1838 echo "udf_test not installed, please download and build the Philips"
1839 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1840 echo "Then copy the udf_test binary to $here/src/."
1841 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1849 LAST_BLOCK=`expr \( $2 - 1 \)`
1850 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1853 rm -f $seqres.checkfs
1854 sleep 1 # Due to a problem with time stamps in udf_test
1855 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1856 _udf_test_known_error_filter | \
1857 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1858 echo "Warning UDF Verifier reported errors see $seqres.checkfs."
1861 _check_xfs_test_fs()
1865 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1866 TEST_LOG="$TEST_LOGDEV"
1868 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1869 TEST_RT="$TEST_RTDEV"
1871 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1873 # check for ipath consistency
1874 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1875 # errors go to stderr
1876 xfs_check_ipaths $TEST_DIR >/dev/null
1877 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1881 _check_btrfs_filesystem()
1885 # If type is set, we're mounted
1886 type=`_fs_type $device`
1889 if [ "$type" = "$FSTYP" ]
1892 mountpoint=`_umount_or_remount_ro $device`
1895 btrfsck $device >$tmp.fsck 2>&1
1898 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1900 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1901 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1902 cat $tmp.fsck >>$seqres.full
1903 echo "*** end fsck.$FSTYP output" >>$seqres.full
1911 echo "*** mount output ***" >>$seqres.full
1912 _mount >>$seqres.full
1913 echo "*** end mount output" >>$seqres.full
1914 elif [ "$type" = "$FSTYP" ]
1917 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1921 if [ $ok -eq 0 ]; then
1936 # no way to check consistency for nfs
1939 # no way to check consistency for cifs
1942 # do nothing for now
1945 _check_btrfs_filesystem $TEST_DEV
1948 # no way to check consistency for tmpfs
1951 _check_generic_filesystem $TEST_DEV
1959 [ $# -eq 1 ] && device=$1
1965 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1966 SCRATCH_LOG="$SCRATCH_LOGDEV"
1968 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1969 SCRATCH_RT="$SCRATCH_RTDEV"
1971 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1974 _check_udf_filesystem $device $udf_fsize
1977 # Don't know how to check an NFS filesystem, yet.
1980 # Don't know how to check a CIFS filesystem, yet.
1983 _check_btrfs_filesystem $device
1986 # no way to check consistency for tmpfs
1989 _check_generic_filesystem $device
1994 _full_fstyp_details()
1996 [ -z "$FSTYP" ] && FSTYP=xfs
1997 if [ $FSTYP = xfs ]; then
1998 if [ -d /proc/fs/xfs ]; then
1999 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2000 FSTYP="$FSTYP (non-debug)"
2001 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2002 FSTYP="$FSTYP (debug)"
2005 if uname -a | grep -qi 'debug'; then
2006 FSTYP="$FSTYP (debug)"
2008 FSTYP="$FSTYP (non-debug)"
2015 _full_platform_details()
2021 echo "$os/$platform $host $kernel"
2026 if [ -z "$1" -o -z "$2" ]; then
2027 echo Error must pass src and dst.
2031 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2033 elif [ "`uname`" == "Linux" ]; then
2036 echo Error test $seq does not run on the operating system: `uname`
2047 #takes files, randomdata
2055 if [ $size -gt 0 ]; then
2056 if [ "$2" == "false" ]; then
2057 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2059 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2066 # takes dirname, depth, randomdata
2069 dirname=$1; depth=$2; randomdata=$3
2070 mkdir $dirname || die "mkdir $dirname failed"
2073 _nfiles $files $randomdata # files for this dir and data type
2075 [ $depth -eq 0 ] && return
2076 let deep=$depth-1 # go 1 down
2078 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2081 while [ $d -lt $dirs ]
2083 _descend d$d $deep &
2089 # Populate a filesystem with inodes for performance experiments
2091 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2096 dirs=5 # ndirs in each subdir till leaves
2097 size=0 # sizeof files in K
2098 files=100 # num files in _each_ subdir
2099 depth=2 # depth of tree from root to leaves
2101 root=root # path of initial root of directory tree
2102 randomdata=false # -x data type urandom or zero
2105 while getopts "d:f:n:r:s:v:x" c
2114 x) randomdata=true;;
2118 _descend $root $depth $randomdata
2123 [ $verbose = true ] && echo done
2126 # query whether the given file has the given inode flag set
2133 if which $XFS_IO_PROG >/dev/null; then
2134 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2141 # query the given files extsize allocator hint in bytes (if any)
2148 if which $XFS_IO_PROG >/dev/null; then
2149 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2150 awk '/^xattr.extsize =/ { print $3 }'`
2152 [ -z "$blocks" ] && blocks="0"
2156 # scratch_dev_pool should contain the disks pool for the btrfs raid
2157 _require_scratch_dev_pool()
2162 if [ -z "$SCRATCH_DEV_POOL" ]; then
2163 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2166 if [ -z "$1" ]; then
2172 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2176 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2177 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2181 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2185 for i in $SCRATCH_DEV_POOL; do
2186 if [ "`_is_block_dev $i`" = "" ]; then
2187 _notrun "this test requires valid block disk $i"
2189 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
2190 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2192 if _mount | grep -q $i; then
2193 if ! $UMOUNT_PROG $i; then
2194 echo "failed to unmount $i - aborting"
2198 # to help better debug when something fails, we remove
2199 # traces of previous btrfs FS on the dev.
2200 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2204 # ensure devices in SCRATCH_DEV_POOL are of the same size
2205 # must be called after _require_scratch_dev_pool
2206 _require_scratch_dev_pool_equal_size()
2212 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2213 _size=`_get_device_size $SCRATCH_DEV`
2214 for _dev in $SCRATCH_DEV_POOL; do
2215 _newsize=`_get_device_size $_dev`
2216 if [ $_size -ne $_newsize ]; then
2217 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2222 # We will check if the device is deletable
2223 _require_deletable_scratch_dev_pool()
2227 for i in $SCRATCH_DEV_POOL; do
2228 x=`echo $i | cut -d"/" -f 3`
2229 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2230 _notrun "$i is a device which is not deletable"
2235 # We check for btrfs and (optionally) features of the btrfs command
2239 _require_command $BTRFS_UTIL_PROG btrfs
2240 if [ -z "$1" ]; then
2243 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2244 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2247 # Check that fio is present, and it is able to execute given jobfile
2252 _require_command $FIO_PROG
2253 if [ -z "$1" ]; then
2257 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2258 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2261 # Does freeze work on this fs?
2264 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2266 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2267 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2270 # arg 1 is dev to remove and is output of the below eg.
2271 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2277 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2279 stat $disk > /dev/null 2>&1
2280 while [ $? -eq 0 ]; do
2282 stat $disk > /dev/null 2>&1
2286 # arg 1 is dev to add and is output of the below eg.
2287 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2292 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2293 h=`echo ${1} | cut -d":" -f 1`
2294 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2296 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2298 # ensure the device comes online
2300 for i in `seq 1 10`; do
2301 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2302 dev=`ls /sys/class/scsi_device/${1}/device/block`
2303 for j in `seq 1 10`;
2305 stat /dev/$dev > /dev/null 2>&1
2306 if [ $? -eq 0 ]; then
2317 if [ $dev_back_oneline -eq 0 ]; then
2318 echo "/dev/$dev online failed" >> $seqres.full
2320 echo "/dev/$dev is back online" >> $seqres.full
2326 if [ -z "$FSTRIM_PROG" ]; then
2327 _notrun "This test requires fstrim utility."
2331 _test_batched_discard()
2333 if [ $# -ne 1 ]; then
2334 echo "Usage: _test_batched_discard mnt_point" 1>&2
2338 $FSTRIM_PROG ${1} &>/dev/null
2343 if [ -z "$DUMPE2FS_PROG" ]; then
2344 _notrun "This test requires dumpe2fs utility."
2350 if [ ! -e /proc/self/uid_map ]; then
2351 _notrun "This test requires procfs uid_map support."
2353 if [ ! -e /proc/self/gid_map ]; then
2354 _notrun "This test requires procfs gid_map support."
2358 _require_cp_reflink()
2360 cp --help | grep -q reflink || \
2361 _notrun "This test requires a cp with --reflink support."
2366 FSSUM_PROG=$here/src/fssum
2367 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2370 _require_btrfs_cloner()
2372 CLONER_PROG=$here/src/cloner
2373 [ -x $CLONER_PROG ] || \
2374 _notrun "cloner binary not present at $CLONER_PROG"
2377 # Given 2 files, verify that they have the same mapping but different
2378 # inodes - i.e. an undisturbed reflink
2379 # Silent if so, make noise if not
2382 # not a hard link or symlink?
2383 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2384 && echo "$1 and $2 are not reflinks: same inode number"
2387 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2388 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2389 || echo "$1 and $2 are not reflinks: different extents"
2394 if [ "$FSTYP" == "nfs" ]; then
2395 _notrun "atime related mount options have no effect on NFS"
2401 _scratch_mkfs > /dev/null 2>&1
2402 _scratch_mount -o relatime || \
2403 _notrun "relatime not supported by the current kernel"
2409 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2410 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2413 _create_loop_device()
2416 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2420 _destroy_loop_device()
2423 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2426 _scale_fsstress_args()
2429 while [ $# -gt 0 ]; do
2431 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2432 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2433 *) args="$args $1" ;;
2441 # Return the logical block size if running on a block device,
2442 # else substitute the page size.
2444 _min_dio_alignment()
2448 if [ -b "$dev" ]; then
2449 blockdev --getss $dev
2451 $here/src/feature -s
2457 echo "# $@" >> $seqres.full 2>&1
2458 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2461 _run_btrfs_util_prog()
2463 run_check $BTRFS_UTIL_PROG $*
2466 _require_btrfs_send_stream_version()
2468 $BTRFS_UTIL_PROG send 2>&1 | \
2469 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2470 if [ $? -ne 0 ]; then
2471 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2474 # test if btrfs kernel supports send stream version 2
2475 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
2476 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
2480 _require_btrfs_mkfs_feature()
2483 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
2487 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
2488 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
2490 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
2493 _require_btrfs_fs_feature()
2496 echo "Missing feature name argument for _require_btrfs_fs_feature"
2500 modprobe btrfs > /dev/null 2>&1
2501 [ -e /sys/fs/btrfs/features/$feat ] || \
2502 _notrun "Feature $feat not supported by the available btrfs version"
2505 _require_test_symlinks()
2507 # IRIX UDF does not support symlinks
2508 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2509 _notrun "Require symlinks support"
2510 target=`mktemp -p $TEST_DIR`
2511 link=`mktemp -p $TEST_DIR -u`
2512 ln -s `basename $target` $link
2513 if [ "$?" -ne 0 ]; then
2515 _notrun "Require symlinks support"
2520 _require_test_fcntl_advisory_locks()
2522 [ "$FSTYP" != "cifs" ] && return 0
2523 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
2524 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
2525 _notrun "Require fcntl advisory locks support"
2530 if [ -z "$1" ]; then
2531 echo "Usage: _get_total_inode <mnt>"
2535 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
2541 if [ -z "$1" ]; then
2542 echo "Usage: _get_used_inode <mnt>"
2546 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
2552 if [ -z "$1" ]; then
2553 echo "Usage: _get_free_inode <mnt>"
2557 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
2561 # get btrfs profile configs being tested
2563 # A set of pre-set profile configs are exported via _btrfs_profile_configs
2564 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
2565 # var in the format "metadata_profile:data_profile", multiple configs can be
2566 # seperated by space, e.g.
2567 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
2568 _btrfs_get_profile_configs()
2570 if [ "$FSTYP" != "btrfs" ]; then
2574 # no user specified btrfs profile configs, export the default configs
2575 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
2577 _btrfs_profile_configs=(
2578 "-m single -d single"
2583 "-m raid10 -d raid10"
2588 # remove dup/raid5/raid6 profiles if we're doing device replace
2589 # dup profile indicates only one device being used (SCRATCH_DEV),
2590 # but we don't want to replace SCRATCH_DEV, which will be used in
2591 # _scratch_mount/_check_scratch_fs etc.
2592 # and raid5/raid6 doesn't support replace yet
2593 if [ "$1" == "replace" ]; then
2594 _btrfs_profile_configs=(
2595 "-m single -d single"
2599 "-m raid10 -d raid10"
2600 # add these back when raid5/6 is working with replace
2601 #"-m raid5 -d raid5"
2602 #"-m raid6 -d raid6"
2605 export _btrfs_profile_configs
2609 # parse user specified btrfs profile configs
2612 for cfg in $BTRFS_PROFILE_CONFIGS; do
2613 # turn "metadata:data" format to "-m metadata -d data"
2614 # and assign it to _btrfs_profile_configs array
2615 cfg=`echo "$cfg" | sed -e 's/^/-m /' -e 's/:/ -d /'`
2616 _btrfs_profile_configs[$i]="$cfg"
2620 if [ "$1" == "replace" ]; then
2621 if echo ${_btrfs_profile_configs[*]} | grep -q raid[56]; then
2622 _notrun "RAID5/6 doesn't support btrfs device replace yet"
2624 if echo ${_btrfs_profile_configs[*]} | grep -q dup; then
2625 _notrun "Do not set dup profile in btrfs device replace test"
2628 export _btrfs_profile_configs
2631 # stress btrfs by running balance operation in a loop
2632 _btrfs_stress_balance()
2636 $BTRFS_UTIL_PROG balance start $btrfs_mnt
2640 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
2641 _btrfs_stress_subvolume()
2645 local subvol_name=$3
2648 mkdir -p $subvol_mnt
2650 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
2651 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
2652 $UMOUNT_PROG $subvol_mnt
2653 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
2657 # stress btrfs by running scrub in a loop
2658 _btrfs_stress_scrub()
2662 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
2666 # stress btrfs by defragmenting every file/dir in a loop and compress file
2667 # contents while defragmenting if second argument is not "nocompress"
2668 _btrfs_stress_defrag()
2674 if [ "$compress" == "nocompress" ]; then
2675 find $btrfs_mnt \( -type f -o -type d \) -exec \
2676 $BTRFS_UTIL_PROG filesystem defrag {} \;
2678 find $btrfs_mnt \( -type f -o -type d \) -exec \
2679 $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
2680 find $btrfs_mnt \( -type f -o -type d \) -exec \
2681 $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
2686 # stress btrfs by remounting it with different compression algorithms in a loop
2687 # run this with fsstress running at background could exercise the compression
2688 # code path and ensure no race when switching compression algorithm with constant
2690 _btrfs_stress_remount_compress()
2694 for algo in no zlib lzo; do
2695 $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
2700 # stress btrfs by replacing devices in a loop
2701 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
2702 # device should be free(not used by btrfs)
2703 _btrfs_stress_replace()
2707 # The device number in SCRATCH_DEV_POOL should be at least 3,
2708 # one is SCRATCH_DEV, one is to be replaced, one is free device
2709 # we won't replace SCRATCH_DEV, see below for reason
2710 if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
2711 echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
2715 # take the last device as the first free_dev
2716 local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
2718 # free_dev should be really free
2719 if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
2720 echo "_btrfs_stress_replace: $free_dev is used by btrfs"
2724 # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
2725 # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
2726 # _scratch_mount and _check_scratch_fs etc.
2727 local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
2728 -e "s# *$free_dev *##"`
2730 # set the first device in dev_pool as the first src_dev to be replaced
2731 local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
2733 echo "dev_pool=$dev_pool"
2734 echo "free_dev=$free_dev, src_dev=$src_dev"
2736 echo "Replacing $src_dev with $free_dev"
2737 $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
2738 if [ $? -ne 0 ]; then
2739 # don't update src_dev and free_dev if replace failed
2742 dev_pool="$dev_pool $free_dev"
2743 dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
2745 src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
2749 # return device size in kb
2752 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
2757 if [ "$iam" == new ]
2761 # make some further configuration checks here
2762 if [ "$TEST_DEV" = "" ]
2764 echo "common/rc: Error: \$TEST_DEV is not set"
2768 # if $TEST_DEV is not mounted, mount it now as XFS
2769 if [ -z "`_fs_type $TEST_DEV`" ]
2771 # $TEST_DEV is not mounted
2774 echo "common/rc: retrying test device mount with external set"
2775 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2778 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2784 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2786 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2790 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2791 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2792 export XFS_IO_PROG="$XFS_IO_PROG -F"
2795 # get real device path name by following link
2799 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
2800 _dev=`readlink -f "$_dev"`
2805 # basename of a device
2808 echo `basename $(_real_dev $1)`
2813 if [ -z $1 ] || [ ! -d $1 ]; then
2814 echo "Missing mount point argument for get_block_size"
2817 echo `stat -f -c %S $1`
2822 ################################################################################
2823 # make sure this script returns success