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 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1096 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1097 _notrun "this test requires a valid \$TEST_DIR"
1099 if [ ! -d "$TEST_DIR" ]; then
1100 _notrun "this test requires a valid \$TEST_DIR"
1104 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1105 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1106 _notrun "this test requires a valid \$TEST_DEV"
1108 if [ ! -d "$TEST_DIR" ]; then
1109 _notrun "this test requires a valid \$TEST_DIR"
1113 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1115 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1119 if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
1121 _notrun "this test requires a valid \$TEST_DEV"
1123 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1125 _notrun "this test requires a valid \$TEST_DEV"
1127 if [ ! -d "$TEST_DIR" ]
1129 _notrun "this test requires a valid \$TEST_DIR"
1135 if _mount | grep -q $TEST_DEV
1137 # if it's mounted, make sure its on $TEST_DIR
1138 if ! _mount | grep $TEST_DEV | grep -q $TEST_DIR
1140 echo "\$TEST_DEV is mounted but not on \$TEST_DIR - aborting"
1144 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1145 if [ $? -ne 1 ]; then
1150 touch ${RESULT_DIR}/require_test
1153 # this test needs a logdev
1157 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1158 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1159 [ "$USE_EXTERNAL" != yes ] && \
1160 _notrun "This test requires USE_EXTERNAL to be enabled"
1162 # ensure its not mounted
1163 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1166 # this test requires loopback device support
1170 if [ "$HOSTOS" != "Linux" ]
1172 _notrun "This test requires linux for loopback device support"
1175 modprobe loop >/dev/null 2>&1
1176 if grep loop /proc/devices >/dev/null 2>&1
1180 _notrun "This test requires loopback device support"
1184 # this test requires ext2 filesystem support
1188 if [ "$HOSTOS" != "Linux" ]
1190 _notrun "This test requires linux for ext2 filesystem support"
1193 modprobe ext2 >/dev/null 2>&1
1194 if grep ext2 /proc/filesystems >/dev/null 2>&1
1198 _notrun "This test requires ext2 filesystem support"
1202 # this test requires that (large) loopback device files are not in use
1204 _require_no_large_scratch_dev()
1206 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1207 _notrun "Large filesystem testing in progress, skipped this test"
1210 # this test requires that a realtime subvolume is in use, and
1211 # that the kernel supports realtime as well.
1215 [ "$USE_EXTERNAL" = yes ] || \
1216 _notrun "External volumes not in use, skipped this test"
1217 [ "$SCRATCH_RTDEV" = "" ] && \
1218 _notrun "Realtime device required, skipped this test"
1221 # this test requires that a specified command (executable) exists
1222 # $1 - command, $2 - name for error message
1226 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1227 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1230 # this test requires the device mapper flakey target
1232 _require_dm_flakey()
1234 _require_command $DMSETUP_PROG
1236 modprobe dm-flakey >/dev/null 2>&1
1237 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1242 _notrun "This test requires dm flakey support"
1246 # this test requires the projid32bit feature to be available in mkfs.xfs.
1248 _require_projid32bit()
1250 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1251 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1254 _require_projid16bit()
1256 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1257 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1260 # this test requires the crc feature to be available in mkfs.xfs
1262 _require_xfs_mkfs_crc()
1264 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1265 || _notrun "mkfs.xfs doesn't have crc feature"
1268 # this test requires the xfs kernel support crc feature
1272 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1273 _scratch_mount >/dev/null 2>&1 \
1274 || _notrun "Kernel doesn't support crc feature"
1278 # this test requires the bigalloc feature to be available in mkfs.ext4
1280 _require_ext4_mkfs_bigalloc()
1282 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 200k >/dev/null 2>&1 \
1283 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1286 # this test requires the ext4 kernel support bigalloc feature
1288 _require_ext4_bigalloc()
1290 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 200k >/dev/null 2>&1
1291 _scratch_mount >/dev/null 2>&1 \
1292 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1296 # this test requires the finobt feature to be available in mkfs.xfs
1298 _require_xfs_mkfs_finobt()
1300 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1301 || _notrun "mkfs.xfs doesn't have finobt feature"
1304 # this test requires the xfs kernel support finobt feature
1306 _require_xfs_finobt()
1308 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1309 _scratch_mount >/dev/null 2>&1 \
1310 || _notrun "Kernel doesn't support finobt feature"
1314 # this test requires xfs sysfs attribute support
1316 _require_xfs_sysfs()
1319 sysfsdir=/sys/fs/xfs
1321 if [ ! -e $sysfsdir ]; then
1322 _notrun "no kernel support for XFS sysfs attributes"
1325 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1326 _notrun "sysfs attribute '$attr' is not supported"
1330 # this test requires that external log/realtime devices are not in use
1332 _require_nonexternal()
1334 [ "$USE_EXTERNAL" = yes ] && \
1335 _notrun "External device testing in progress, skipped this test"
1338 # this test requires that a (specified) aio-dio executable exists
1339 # $1 - command (optional)
1345 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1346 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1348 AIO_TEST=src/aio-dio-regress/$1
1349 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1353 # run an aio-dio program
1359 echo "usage: _run_aiodio command_name" 2>&1
1365 local testtemp=$TEST_DIR/aio-testfile
1367 $AIO_TEST $testtemp 2>&1
1374 # indicate whether YP/NIS is active or not
1379 dn=$(domainname 2>/dev/null)
1380 test -n "${dn}" -a "${dn}" != "(none)"
1384 # cat the password file
1388 [ $(_yp_active) -eq 0 ] && ypcat passwd
1392 # cat the group file
1396 [ $(_yp_active) -eq 0 ] && ypcat group
1400 # check for the fsgqa user on the machine
1405 _cat_passwd | grep -q $qa_user
1406 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1407 echo /bin/true | su $qa_user
1408 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1411 # check for the fsgqa group on the machine
1416 _cat_group | grep -q $qa_group
1417 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1423 s,.*Permission\sdenied.*,Permission denied,;
1424 s,.*no\saccess\sto\stty.*,,;
1425 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1432 if [ "$HOSTOS" == "IRIX" ]
1434 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1436 echo $1 | su $qa_user 2>&1 | _filter_user_do
1440 _require_xfs_io_command()
1444 echo "Usage: _require_xfs_io_command command" 1>&2
1449 testfile=$TEST_DIR/$$.xfs_io
1452 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1454 "fpunch" | "fcollapse" | "zero" | "fzero" )
1455 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1456 -c "$command 4k 8k" $testfile 2>&1`
1459 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1460 -c "fiemap -v" $testfile 2>&1`
1463 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1465 echo $testio | egrep -q "invalid option|Is a directory" && \
1466 _notrun "xfs_io $command support is missing"
1469 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1472 rm -f $testfile 2>&1 > /dev/null
1473 echo $testio | grep -q "not found" && \
1474 _notrun "xfs_io $command support is missing"
1475 echo $testio | grep -q "Operation not supported" && \
1476 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1479 # Check that a fs has enough free space (in 1024b blocks)
1484 BLOCKS=$2 # in units of 1024
1485 let GB=$BLOCKS/1024/1024
1487 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1488 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1489 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1493 # Check if the filesystem supports sparse files.
1495 # Unfortunately there is no better way to do this than a manual black list.
1497 _require_sparse_files()
1501 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1510 #boot_params always present in debugfs
1511 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1514 _require_fail_make_request()
1516 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1517 || _notrun "$DEBUGFS_MNT/fail_make_request \
1518 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1522 # Check if the file system supports seek_data/hole
1524 _require_seek_data_hole()
1526 testfile=$TEST_DIR/$$.seek
1527 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1528 rm -f $testfile &>/dev/null
1529 echo $testseek | grep -q "Kernel does not support" && \
1530 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1533 # check that a FS on a device is mounted
1534 # if so, return mount point
1540 echo "Usage: _is_mounted device" 1>&2
1546 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1547 pattern { print $3 ; exit 0 }
1551 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1556 # remount a FS to a new mode (ro or rw)
1562 echo "Usage: _remount device ro/rw" 1>&2
1568 if ! mount -o remount,$mode $device
1570 echo "_remount: failed to remount filesystem on $device as $mode"
1575 # Run the appropriate repair/check on a filesystem
1577 # if the filesystem is mounted, it's either remounted ro before being
1578 # checked or it's unmounted and then remounted
1581 # If set, we remount ro instead of unmounting for fsck
1584 _umount_or_remount_ro()
1588 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1593 mountpoint=`_is_mounted $device`
1595 if [ $USE_REMOUNT -eq 0 ]; then
1596 $UMOUNT_PROG $device
1603 _mount_or_remount_rw()
1607 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1614 if [ $USE_REMOUNT -eq 0 ]
1616 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1618 echo "!!! failed to remount $device on $mountpoint"
1628 # Check a generic filesystem in no-op mode; this assumes that the
1629 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1630 # and that it will still return an errno for corruption in this mode.
1632 # Filesystems which don't support this will need to define their
1633 # own check routine.
1635 _check_generic_filesystem()
1639 # If type is set, we're mounted
1640 type=`_fs_type $device`
1643 if [ "$type" = "$FSTYP" ]
1646 mountpoint=`_umount_or_remount_ro $device`
1649 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1652 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1654 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1655 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1656 cat $tmp.fsck >>$seqres.full
1657 echo "*** end fsck.$FSTYP output" >>$seqres.full
1665 echo "*** mount output ***" >>$seqres.full
1666 _mount >>$seqres.full
1667 echo "*** end mount output" >>$seqres.full
1668 elif [ "$type" = "$FSTYP" ]
1671 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1675 if [ $ok -eq 0 ]; then
1683 # run xfs_check and friends on a FS.
1685 _check_xfs_filesystem()
1689 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1693 extra_mount_options=""
1695 if [ "$2" != "none" ]; then
1696 extra_log_options="-l$2"
1697 extra_mount_options="-ologdev=$2"
1700 if [ "$3" != "none" ]; then
1701 extra_rt_options="-r$3"
1702 extra_mount_options=$extra_mount_options" -ortdev=$3"
1704 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1706 [ "$FSTYP" != xfs ] && return 0
1708 type=`_fs_type $device`
1711 if [ "$type" = "xfs" ]
1714 mountpoint=`_umount_or_remount_ro $device`
1717 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1718 | tee $tmp.logprint | grep -q "<CLEAN>"
1719 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1721 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1723 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1724 echo "*** xfs_logprint -t output ***" >>$seqres.full
1725 cat $tmp.logprint >>$seqres.full
1726 echo "*** end xfs_logprint output" >>$seqres.full
1731 # xfs_check runs out of memory on large files, so even providing the test
1732 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1733 # large filesystems. Avoid it.
1734 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1735 _xfs_check $extra_log_options $device 2>&1 |\
1736 _fix_malloc >$tmp.fs_check
1738 if [ -s $tmp.fs_check ]
1740 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1742 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1743 echo "*** xfs_check output ***" >>$seqres.full
1744 cat $tmp.fs_check >>$seqres.full
1745 echo "*** end xfs_check output" >>$seqres.full
1750 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1753 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1755 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1756 echo "*** xfs_repair -n output ***" >>$seqres.full
1757 cat $tmp.repair | _fix_malloc >>$seqres.full
1758 echo "*** end xfs_repair output" >>$seqres.full
1762 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1766 echo "*** mount output ***" >>$seqres.full
1767 _mount >>$seqres.full
1768 echo "*** end mount output" >>$seqres.full
1769 elif [ "$type" = "xfs" ]
1771 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1774 if [ $ok -eq 0 ]; then
1776 if [ "$iam" != "check" ]; then
1784 # Filter the knowen errors the UDF Verifier reports.
1785 _udf_test_known_error_filter()
1787 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."
1791 _check_udf_filesystem()
1793 [ "$DISABLE_UDF_TEST" == "1" ] && return
1795 if [ $# -ne 1 -a $# -ne 2 ]
1797 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1801 if [ ! -x $here/src/udf_test ]
1803 echo "udf_test not installed, please download and build the Philips"
1804 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1805 echo "Then copy the udf_test binary to $here/src/."
1806 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1814 LAST_BLOCK=`expr \( $2 - 1 \)`
1815 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1818 rm -f $seqres.checkfs
1819 sleep 1 # Due to a problem with time stamps in udf_test
1820 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1821 _udf_test_known_error_filter | \
1822 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1823 echo "Warning UDF Verifier reported errors see $seqres.checkfs."
1826 _check_xfs_test_fs()
1830 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1831 TEST_LOG="$TEST_LOGDEV"
1833 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1834 TEST_RT="$TEST_RTDEV"
1836 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1838 # check for ipath consistency
1839 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1840 # errors go to stderr
1841 xfs_check_ipaths $TEST_DIR >/dev/null
1842 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1846 _check_btrfs_filesystem()
1850 # If type is set, we're mounted
1851 type=`_fs_type $device`
1854 if [ "$type" = "$FSTYP" ]
1857 mountpoint=`_umount_or_remount_ro $device`
1860 btrfsck $device >$tmp.fsck 2>&1
1863 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1865 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1866 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1867 cat $tmp.fsck >>$seqres.full
1868 echo "*** end fsck.$FSTYP output" >>$seqres.full
1876 echo "*** mount output ***" >>$seqres.full
1877 _mount >>$seqres.full
1878 echo "*** end mount output" >>$seqres.full
1879 elif [ "$type" = "$FSTYP" ]
1882 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1886 if [ $ok -eq 0 ]; then
1901 # no way to check consistency for nfs
1904 # no way to check consistency for cifs
1907 # do nothing for now
1910 _check_btrfs_filesystem $TEST_DEV
1913 # no way to check consistency for tmpfs
1916 _check_generic_filesystem $TEST_DEV
1924 [ $# -eq 1 ] && device=$1
1930 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1931 SCRATCH_LOG="$SCRATCH_LOGDEV"
1933 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1934 SCRATCH_RT="$SCRATCH_RTDEV"
1936 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1939 _check_udf_filesystem $device $udf_fsize
1942 # Don't know how to check an NFS filesystem, yet.
1945 # Don't know how to check a CIFS filesystem, yet.
1948 _check_btrfs_filesystem $device
1951 # no way to check consistency for tmpfs
1954 _check_generic_filesystem $device
1959 _full_fstyp_details()
1961 [ -z "$FSTYP" ] && FSTYP=xfs
1962 if [ $FSTYP = xfs ]; then
1963 if [ -d /proc/fs/xfs ]; then
1964 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1965 FSTYP="$FSTYP (non-debug)"
1966 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1967 FSTYP="$FSTYP (debug)"
1970 if uname -a | grep -qi 'debug'; then
1971 FSTYP="$FSTYP (debug)"
1973 FSTYP="$FSTYP (non-debug)"
1980 _full_platform_details()
1986 echo "$os/$platform $host $kernel"
1991 if [ -z "$1" -o -z "$2" ]; then
1992 echo Error must pass src and dst.
1996 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1998 elif [ "`uname`" == "Linux" ]; then
2001 echo Error test $seq does not run on the operating system: `uname`
2012 #takes files, randomdata
2020 if [ $size -gt 0 ]; then
2021 if [ "$2" == "false" ]; then
2022 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2024 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2031 # takes dirname, depth, randomdata
2034 dirname=$1; depth=$2; randomdata=$3
2035 mkdir $dirname || die "mkdir $dirname failed"
2038 _nfiles $files $randomdata # files for this dir and data type
2040 [ $depth -eq 0 ] && return
2041 let deep=$depth-1 # go 1 down
2043 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2046 while [ $d -lt $dirs ]
2048 _descend d$d $deep &
2054 # Populate a filesystem with inodes for performance experiments
2056 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2061 dirs=5 # ndirs in each subdir till leaves
2062 size=0 # sizeof files in K
2063 files=100 # num files in _each_ subdir
2064 depth=2 # depth of tree from root to leaves
2066 root=root # path of initial root of directory tree
2067 randomdata=false # -x data type urandom or zero
2070 while getopts "d:f:n:r:s:v:x" c
2079 x) randomdata=true;;
2083 _descend $root $depth $randomdata
2088 [ $verbose = true ] && echo done
2091 # query whether the given file has the given inode flag set
2098 if which $XFS_IO_PROG >/dev/null; then
2099 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2106 # query the given files extsize allocator hint in bytes (if any)
2113 if which $XFS_IO_PROG >/dev/null; then
2114 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2115 awk '/^xattr.extsize =/ { print $3 }'`
2117 [ -z "$blocks" ] && blocks="0"
2121 # scratch_dev_pool should contain the disks pool for the btrfs raid
2122 _require_scratch_dev_pool()
2127 if [ -z "$SCRATCH_DEV_POOL" ]; then
2128 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2131 if [ -z "$1" ]; then
2137 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2141 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2142 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2146 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2150 for i in $SCRATCH_DEV_POOL; do
2151 if [ "`_is_block_dev $i`" = "" ]; then
2152 _notrun "this test requires valid block disk $i"
2154 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
2155 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2157 if _mount | grep -q $i; then
2158 if ! $UMOUNT_PROG $i; then
2159 echo "failed to unmount $i - aborting"
2163 # to help better debug when something fails, we remove
2164 # traces of previous btrfs FS on the dev.
2165 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2169 # ensure devices in SCRATCH_DEV_POOL are of the same size
2170 # must be called after _require_scratch_dev_pool
2171 _require_scratch_dev_pool_equal_size()
2177 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2178 _size=`_get_device_size $SCRATCH_DEV`
2179 for _dev in $SCRATCH_DEV_POOL; do
2180 _newsize=`_get_device_size $_dev`
2181 if [ $_size -ne $_newsize ]; then
2182 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2187 # We will check if the device is deletable
2188 _require_deletable_scratch_dev_pool()
2192 for i in $SCRATCH_DEV_POOL; do
2193 x=`echo $i | cut -d"/" -f 3`
2194 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2195 _notrun "$i is a device which is not deletable"
2200 # We check for btrfs and (optionally) features of the btrfs command
2204 _require_command $BTRFS_UTIL_PROG btrfs
2205 if [ -z "$1" ]; then
2208 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2209 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2212 # Check that fio is present, and it is able to execute given jobfile
2217 _require_command $FIO_PROG
2218 if [ -z "$1" ]; then
2222 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2223 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2226 # Does freeze work on this fs?
2229 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2231 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2232 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2235 # arg 1 is dev to remove and is output of the below eg.
2236 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2242 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2244 stat $disk > /dev/null 2>&1
2245 while [ $? -eq 0 ]; do
2247 stat $disk > /dev/null 2>&1
2251 # arg 1 is dev to add and is output of the below eg.
2252 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2257 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2258 h=`echo ${1} | cut -d":" -f 1`
2259 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2261 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2263 # ensure the device comes online
2265 for i in `seq 1 10`; do
2266 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2267 dev=`ls /sys/class/scsi_device/${1}/device/block`
2268 for j in `seq 1 10`;
2270 stat /dev/$dev > /dev/null 2>&1
2271 if [ $? -eq 0 ]; then
2282 if [ $dev_back_oneline -eq 0 ]; then
2283 echo "/dev/$dev online failed" >> $seqres.full
2285 echo "/dev/$dev is back online" >> $seqres.full
2291 if [ -z "$FSTRIM_PROG" ]; then
2292 _notrun "This test requires fstrim utility."
2296 _test_batched_discard()
2298 if [ $# -ne 1 ]; then
2299 echo "Usage: _test_batched_discard mnt_point" 1>&2
2303 $FSTRIM_PROG ${1} &>/dev/null
2308 if [ -z "$DUMPE2FS_PROG" ]; then
2309 _notrun "This test requires dumpe2fs utility."
2315 if [ ! -e /proc/self/uid_map ]; then
2316 _notrun "This test requires procfs uid_map support."
2318 if [ ! -e /proc/self/gid_map ]; then
2319 _notrun "This test requires procfs gid_map support."
2323 _require_cp_reflink()
2325 cp --help | grep -q reflink || \
2326 _notrun "This test requires a cp with --reflink support."
2331 FSSUM_PROG=$here/src/fssum
2332 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2335 _require_btrfs_cloner()
2337 CLONER_PROG=$here/src/cloner
2338 [ -x $CLONER_PROG ] || \
2339 _notrun "cloner binary not present at $CLONER_PROG"
2342 # Given 2 files, verify that they have the same mapping but different
2343 # inodes - i.e. an undisturbed reflink
2344 # Silent if so, make noise if not
2347 # not a hard link or symlink?
2348 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2349 && echo "$1 and $2 are not reflinks: same inode number"
2352 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2353 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2354 || echo "$1 and $2 are not reflinks: different extents"
2359 _scratch_mkfs > /dev/null 2>&1
2360 _mount -t $FSTYP -o relatime $SCRATCH_DEV $SCRATCH_MNT || \
2361 _notrun "relatime not supported by the current kernel"
2367 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2368 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2371 _create_loop_device()
2374 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2378 _destroy_loop_device()
2381 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2384 _scale_fsstress_args()
2387 while [ $# -gt 0 ]; do
2389 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2390 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2391 *) args="$args $1" ;;
2399 # Return the logical block size if running on a block device,
2400 # else substitute the page size.
2402 _min_dio_alignment()
2406 if [ -b "$dev" ]; then
2407 blockdev --getss $dev
2409 $here/src/feature -s
2415 echo "# $@" >> $seqres.full 2>&1
2416 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2419 _run_btrfs_util_prog()
2421 run_check $BTRFS_UTIL_PROG $*
2424 _require_btrfs_send_stream_version()
2426 $BTRFS_UTIL_PROG send 2>&1 | \
2427 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2428 if [ $? -ne 0 ]; then
2429 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2432 # test if btrfs kernel supports send stream version 2
2433 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
2434 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
2438 _require_btrfs_mkfs_feature()
2441 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
2445 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
2446 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
2448 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
2451 _require_btrfs_fs_feature()
2454 echo "Missing feature name argument for _require_btrfs_fs_feature"
2458 modprobe btrfs > /dev/null 2>&1
2459 [ -e /sys/fs/btrfs/features/$feat ] || \
2460 _notrun "Feature $feat not supported by the available btrfs version"
2463 _require_test_symlinks()
2465 # IRIX UDF does not support symlinks
2466 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2467 _notrun "Require symlinks support"
2468 target=`mktemp -p $TEST_DIR`
2469 link=`mktemp -p $TEST_DIR -u`
2470 ln -s `basename $target` $link
2471 if [ "$?" -ne 0 ]; then
2473 _notrun "Require symlinks support"
2478 _require_test_fcntl_advisory_locks()
2480 [ "$FSTYP" != "cifs" ] && return 0
2481 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
2482 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
2483 _notrun "Require fcntl advisory locks support"
2488 if [ -z "$1" ]; then
2489 echo "Usage: _get_total_inode <mnt>"
2493 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
2499 if [ -z "$1" ]; then
2500 echo "Usage: _get_used_inode <mnt>"
2504 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
2510 if [ -z "$1" ]; then
2511 echo "Usage: _get_free_inode <mnt>"
2515 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
2519 # get btrfs profile configs being tested
2521 # A set of pre-set profile configs are exported via _btrfs_profile_configs
2522 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
2523 # var in the format "metadata_profile:data_profile", multiple configs can be
2524 # seperated by space, e.g.
2525 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
2526 _btrfs_get_profile_configs()
2528 if [ "$FSTYP" != "btrfs" ]; then
2532 # no user specified btrfs profile configs, export the default configs
2533 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
2535 _btrfs_profile_configs=(
2536 "-m single -d single"
2541 "-m raid10 -d raid10"
2546 # remove dup/raid5/raid6 profiles if we're doing device replace
2547 # dup profile indicates only one device being used (SCRATCH_DEV),
2548 # but we don't want to replace SCRATCH_DEV, which will be used in
2549 # _scratch_mount/_check_scratch_fs etc.
2550 # and raid5/raid6 doesn't support replace yet
2551 if [ "$1" == "replace" ]; then
2552 _btrfs_profile_configs=(
2553 "-m single -d single"
2557 "-m raid10 -d raid10"
2558 # add these back when raid5/6 is working with replace
2559 #"-m raid5 -d raid5"
2560 #"-m raid6 -d raid6"
2563 export _btrfs_profile_configs
2567 # parse user specified btrfs profile configs
2570 for cfg in $BTRFS_PROFILE_CONFIGS; do
2571 # turn "metadata:data" format to "-m metadata -d data"
2572 # and assign it to _btrfs_profile_configs array
2573 cfg=`echo "$cfg" | sed -e 's/^/-m /' -e 's/:/ -d /'`
2574 _btrfs_profile_configs[$i]="$cfg"
2578 if [ "$1" == "replace" ]; then
2579 if echo ${_btrfs_profile_configs[*]} | grep -q raid[56]; then
2580 _notrun "RAID5/6 doesn't support btrfs device replace yet"
2582 if echo ${_btrfs_profile_configs[*]} | grep -q dup; then
2583 _notrun "Do not set dup profile in btrfs device replace test"
2586 export _btrfs_profile_configs
2589 # stress btrfs by running balance operation in a loop
2590 _btrfs_stress_balance()
2594 $BTRFS_UTIL_PROG balance start $btrfs_mnt
2598 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
2599 _btrfs_stress_subvolume()
2603 local subvol_name=$3
2606 mkdir -p $subvol_mnt
2608 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
2609 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
2610 $UMOUNT_PROG $subvol_mnt
2611 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
2615 # stress btrfs by running scrub in a loop
2616 _btrfs_stress_scrub()
2620 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
2624 # stress btrfs by defragmenting every file/dir in a loop and compress file
2625 # contents while defragmenting if second argument is not "nocompress"
2626 _btrfs_stress_defrag()
2632 if [ "$compress" == "nocompress" ]; then
2633 find $btrfs_mnt \( -type f -o -type d \) -exec \
2634 $BTRFS_UTIL_PROG filesystem defrag {} \;
2636 find $btrfs_mnt \( -type f -o -type d \) -exec \
2637 $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
2638 find $btrfs_mnt \( -type f -o -type d \) -exec \
2639 $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
2644 # stress btrfs by remounting it with different compression algorithms in a loop
2645 # run this with fsstress running at background could exercise the compression
2646 # code path and ensure no race when switching compression algorithm with constant
2648 _btrfs_stress_remount_compress()
2652 for algo in no zlib lzo; do
2653 $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
2658 # stress btrfs by replacing devices in a loop
2659 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
2660 # device should be free(not used by btrfs)
2661 _btrfs_stress_replace()
2665 # The device number in SCRATCH_DEV_POOL should be at least 3,
2666 # one is SCRATCH_DEV, one is to be replaced, one is free device
2667 # we won't replace SCRATCH_DEV, see below for reason
2668 if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
2669 echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
2673 # take the last device as the first free_dev
2674 local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
2676 # free_dev should be really free
2677 if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
2678 echo "_btrfs_stress_replace: $free_dev is used by btrfs"
2682 # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
2683 # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
2684 # _scratch_mount and _check_scratch_fs etc.
2685 local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
2686 -e "s# *$free_dev *##"`
2688 # set the first device in dev_pool as the first src_dev to be replaced
2689 local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
2691 echo "dev_pool=$dev_pool"
2692 echo "free_dev=$free_dev, src_dev=$src_dev"
2694 echo "Replacing $src_dev with $free_dev"
2695 $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
2696 if [ $? -ne 0 ]; then
2697 # don't update src_dev and free_dev if replace failed
2700 dev_pool="$dev_pool $free_dev"
2701 dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
2703 src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
2707 # return device size in kb
2710 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
2715 if [ "$iam" == new ]
2719 # make some further configuration checks here
2720 if [ "$TEST_DEV" = "" ]
2722 echo "common/rc: Error: \$TEST_DEV is not set"
2726 # if $TEST_DEV is not mounted, mount it now as XFS
2727 if [ -z "`_fs_type $TEST_DEV`" ]
2729 # $TEST_DEV is not mounted
2732 echo "common/rc: retrying test device mount with external set"
2733 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2736 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2742 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2744 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2748 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2749 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2750 export XFS_IO_PROG="$XFS_IO_PROG -F"
2753 # get real device path name by following link
2757 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
2758 _dev=`readlink -f "$_dev"`
2763 # basename of a device
2766 echo `basename $(_real_dev $1)`
2771 if [ -z $1 ] || [ ! -d $1 ]; then
2772 echo "Missing mount point argument for get_block_size"
2775 echo `stat -f -c %S $1`
2780 ################################################################################
2781 # make sure this script returns success