2 #-----------------------------------------------------------------------
3 # Copyright (c) 2000-2006 Silicon Graphics, Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 # Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
20 # Mountain View, CA 94043, USA, or: http://www.sgi.com
21 #-----------------------------------------------------------------------
23 BC=$(which bc 2> /dev/null) || BC=
28 _notrun "this test requires 'bc' tool for doing math operations"
34 [ $# -le 0 ] && return
36 result=$(LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null)
38 _notrun "this test requires 'bc' tool for doing math operations"
45 if [ "$HOSTOS" == "Linux" ]
47 command dd --help | grep noxfer > /dev/null 2>&1
51 command dd status=noxfer $@
65 $BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
68 # Prints the md5 checksum of a given file
71 md5sum $1 | cut -d ' ' -f1
75 # ls -l w/ selinux sometimes puts a dot at the end:
76 # -rwxrw-r--. id1 id2 file1
77 # Also filter out lost+found directory on extN file system if present
81 ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /" | grep -v 'lost+found'
84 # we need common/config
85 if [ "$iam" != "check" ]
87 if ! . ./common/config
89 echo "$iam: failed to source common/config"
94 # check for correct setup
97 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
98 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
99 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
100 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
103 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
106 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
114 # make sure we have a standard umask
119 $MOUNT_PROG `_mount_ops_filter $*`
127 if [ "$FSTYP" != "xfs" ]; then
133 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
142 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
143 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
144 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
145 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
153 if [ "$FSTYP" != "xfs" ]; then
167 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
168 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
169 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
170 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
177 #get mount point to handle dmapi mtpt option correctly
179 [ $last_index -gt 0 ] && shift $last_index
182 # irix is fussy about how it is fed its mount options
183 # - multiple -o's are not allowed
184 # - no spaces between comma delimitered options
185 # the sed script replaces all -o's (except the first) with a comma
186 # not required for linux, but won't hurt
188 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
189 | sed -e 's/dmapi/dmi/' \
190 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
194 _scratch_mount_options()
196 _scratch_options mount
198 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
203 _mount -t $FSTYP `_scratch_mount_options $*`
208 $UMOUNT_PROG $SCRATCH_DEV
220 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
225 $UMOUNT_PROG $TEST_DEV
229 _scratch_mkfs_options()
231 _scratch_options mkfs
232 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
240 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
241 options="-l $SCRATCH_LOGDEV"
243 xfs_metadump $options $SCRATCH_DEV $dumpfile
246 _setup_large_xfs_fs()
251 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
252 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
253 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
255 # calculate the size of the file we need to allocate.
256 # Default free space in the FS is 50GB, but you can specify more via
257 # SCRATCH_DEV_EMPTY_SPACE
258 file_size=$(($fs_size - 50*1024*1024*1024))
259 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
261 # mount the filesystem, create the file, unmount it
262 _scratch_mount 2>&1 >$tmp_dir/mnt.err
264 if [ $status -ne 0 ]; then
266 cat $tmp_dir/mnt.err >&2
267 rm -f $tmp_dir/mnt.err
270 rm -f $tmp_dir/mnt.err
273 -c "truncate $file_size" \
274 -c "falloc -k 0 $file_size" \
276 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
277 export NUM_SPACE_FILES=1
280 if [ $status -ne 0 ]; then
281 echo "large file prealloc failed"
282 cat $tmp_dir/mnt.err >&2
288 _scratch_mkfs_xfs_opts()
292 _scratch_options mkfs
294 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
298 _scratch_mkfs_xfs_supported()
302 _scratch_options mkfs
304 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
309 # extra mkfs options can be added by tests
310 local extra_mkfs_options=$*
314 # save mkfs output in case conflict means we need to run again.
315 # only the output for the mkfs that applies should be shown
316 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
317 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
321 # a mkfs failure may be caused by conflicts between
322 # $MKFS_OPTIONS and $extra_mkfs_options
323 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
325 echo -n "** mkfs failed with extra mkfs options "
326 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
327 echo -n "** attempting to mkfs using only test $seq "
328 echo "options: $extra_mkfs_options **"
331 # running mkfs again. overwrite previous mkfs output files
332 _scratch_mkfs_xfs_opts $extra_mkfs_options \
333 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
337 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
338 # manually parse the mkfs output to get the fs size in bytes
340 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
341 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
343 print STDOUT "$size\n";
345 _setup_large_xfs_fs $fs_size
349 # output stored mkfs output
350 cat $tmp_dir.mkfserr >&2
352 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
357 # xfs_check script is planned to be deprecated. But, we want to
358 # be able to invoke "xfs_check" behavior in xfstests in order to
359 # maintain the current verification levels.
364 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
366 while getopts "b:fi:l:stvV" c
372 i) OPTS=$OPTS"-i "$OPTARG" ";;
373 b) OPTS=$OPTS"-b "$OPTARG" ";;
374 f) DBOPTS=$DBOPTS" -f";;
375 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
376 V) $XFS_DB_PROG -p xfs_check -V
384 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
394 _setup_large_ext4_fs()
399 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
400 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
401 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
403 # Default free space in the FS is 50GB, but you can specify more via
404 # SCRATCH_DEV_EMPTY_SPACE
405 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
407 # mount the filesystem and create 16TB - 4KB files until we consume
408 # all the necessary space.
409 _scratch_mount 2>&1 >$tmp_dir/mnt.err
411 if [ $status -ne 0 ]; then
413 cat $tmp_dir/mnt.err >&2
414 rm -f $tmp_dir/mnt.err
417 rm -f $tmp_dir/mnt.err
419 file_size=$((16*1024*1024*1024*1024 - 4096))
421 while [ $space_to_consume -gt $file_size ]; do
424 -c "truncate $file_size" \
425 -c "falloc -k 0 $file_size" \
426 $SCRATCH_MNT/.use_space.$nfiles 2>&1
428 if [ $status -ne 0 ]; then
432 space_to_consume=$(( $space_to_consume - $file_size ))
433 nfiles=$(($nfiles + 1))
436 # consume the remaining space.
437 if [ $space_to_consume -gt 0 ]; then
439 -c "truncate $space_to_consume" \
440 -c "falloc -k 0 $space_to_consume" \
441 $SCRATCH_MNT/.use_space.$nfiles 2>&1
444 export NUM_SPACE_FILES=$nfiles
447 if [ $status -ne 0 ]; then
448 echo "large file prealloc failed"
449 cat $tmp_dir/mnt.err >&2
457 # extra mkfs options can be added by tests
458 local extra_mkfs_options=$*
462 /sbin/mkfs -t ext4 -- -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
463 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
466 # a mkfs failure may be caused by conflicts between
467 # $MKFS_OPTIONS and $extra_mkfs_options
468 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
470 echo -n "** mkfs failed with extra mkfs options "
471 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
472 echo -n "** attempting to mkfs using only test $seq "
473 echo "options: $extra_mkfs_options **"
476 # running mkfs again. overwrite previous mkfs output files
477 /sbin/mkfs -t ext4 -- -F $extra_mkfs_options $SCRATCH_DEV \
478 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
482 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
483 # manually parse the mkfs output to get the fs size in bytes
484 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
485 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
486 / inodes, / { blks = $3 } \
487 /reserved for the super user/ { resv = $1 } \
488 END { fssize = bs * blks - resv; print fssize }'`
490 _setup_large_ext4_fs $fs_size
494 # output stored mkfs output
495 cat $tmp_dir.mkfserr >&2
497 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
509 # do nothing for cifs
512 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
515 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
518 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
530 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
533 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
536 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
537 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
541 if [ $? -ne 0 ]; then
542 # output stored mkfs output
543 cat $tmp_dir.mkfserr >&2
548 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
561 # do nothing for cifs
564 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
567 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
570 _scratch_mkfs_ext4 $*
573 # do nothing for tmpfs
576 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
585 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
588 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
593 # Create fs of certain size on scratch device
594 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
595 _scratch_mkfs_sized()
602 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
604 ext2|ext3|ext4|ext4dev|udf|btrfs)
605 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
609 [ -n "$def_blksz" ] && blocksize=$def_blksz
610 [ -z "$blocksize" ] && blocksize=4096
614 if ! [[ $fssize =~ $re ]] ; then
615 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
617 if ! [[ $blocksize =~ $re ]] ; then
618 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
621 blocks=`expr $fssize / $blocksize`
623 if [ "$HOSTOS" == "Linux" ]; then
624 devsize=`blockdev --getsize64 $SCRATCH_DEV`
625 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
630 # don't override MKFS_OPTIONS that set a block size.
631 echo $MKFS_OPTIONS |egrep -q "b?size="
632 if [ $? -eq 0 ]; then
633 _scratch_mkfs_xfs -d size=$fssize
635 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
638 ext2|ext3|ext4|ext4dev)
639 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
642 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
645 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
648 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
653 # Emulate an N-data-disk stripe w/ various stripe units
654 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
660 [ -z "$blocksize" ] && blocksize=4096
662 let sunit_blocks=$sunit_bytes/$blocksize
663 let swidth_blocks=$sunit_blocks*$swidth_mult
667 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
670 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
673 _notrun "can't mkfs $FSTYP with geometry"
683 xfs_io -x -c "resblks $1" $SCRATCH_MNT
690 _scratch_xfs_db_options()
693 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
694 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
695 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
698 _scratch_xfs_logprint()
701 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
702 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
703 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
709 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
710 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
711 [ "$LARGE_SCRATCH_DEV" = yes ] && \
712 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
713 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
716 _scratch_xfs_repair()
719 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
720 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
721 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
722 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
723 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
724 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
731 echo "Usage: _get_pids_by_name process-name" 1>&2
735 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
736 # HH:MM:SS before the psargs field, use this as the search anchor.
738 # Matches with $1 (process-name) occur if the first psarg is $1
739 # or ends in /$1 ... the matching uses sed's regular expressions,
740 # so passing a regex into $1 will work.
748 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
749 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
752 # fix malloc libs output
756 # filter out the Electric Fence notice
759 if (defined $o && /^\s+Electric Fence/) {
765 print $o if (defined $o);
769 print $o if (defined $o);
773 # check if run as root
777 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
780 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
787 # _df_device : get an IRIX style df line for a given device
789 # - returns "" if not mounted
790 # - returns fs type in field two (ala IRIX)
791 # - joins line together if split by fancy df formatting
792 # - strips header etc
799 echo "Usage: _df_device device" 1>&2
803 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
804 match($1,what) && NF==1 {
818 # _df_dir : get an IRIX style df line for device where a directory resides
820 # - returns fs type in field two (ala IRIX)
821 # - joins line together if split by fancy df formatting
822 # - strips header etc
829 echo "Usage: _df_dir device" 1>&2
833 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
849 # return percentage used disk space for mounted device
855 echo "Usage: _used device" 1>&2
859 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
862 # return the FS type of a mounted device
868 echo "Usage: _fs_type device" 1>&2
873 # The Linux kernel shows NFSv4 filesystems in df output as
874 # filesystem type nfs4, although we mounted it as nfs earlier.
875 # Fix the filesystem type up here so that the callers don't
876 # have to bother with this quirk.
878 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
881 # return the FS mount options of a mounted device
883 # should write a version which just parses the output of mount for IRIX
884 # compatibility, but since this isn't used at all, at the moment I'll leave
891 echo "Usage: _fs_options device" 1>&2
895 $AWK_PROG -v dev=$1 '
896 match($1,dev) { print $4 }
900 # returns device number if a file is a block device
906 echo "Usage: _is_block_dev dev" 1>&2
911 if [ -L "${_dev}" ]; then
912 _dev=`readlink -f ${_dev}`
915 if [ -b "${_dev}" ]; then
916 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
920 # Do a command, log it to $seqres.full, optionally test return status
921 # and die if command fails. If called with one argument _do executes the
922 # command, logs it, and returns its exit status. With two arguments _do
923 # first prints the message passed in the first argument, and then "done"
924 # or "fail" depending on the return status of the command passed in the
925 # second argument. If the command fails and the variable _do_die_on_error
926 # is set to "always" or the two argument form is used and _do_die_on_error
927 # is set to "message_only" _do will print an error message to
928 # $seqres.out and exit.
932 if [ $# -eq 1 ]; then
934 elif [ $# -eq 2 ]; then
939 echo "Usage: _do [note] cmd" 1>&2
943 (eval "echo '---' \"$_cmd\"") >>$seqres.full
944 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
945 cat $tmp._out | _fix_malloc >>$seqres.full
946 if [ $# -eq 2 ]; then
947 if [ $ret -eq 0 ]; then
954 && [ "$_do_die_on_error" = "always" \
955 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
958 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
965 # bail out, setting up .notrun file. Need to kill the filesystem check files
966 # here, otherwise they are set incorrectly for the next test.
970 echo "$*" > $seqres.notrun
971 echo "$seq not run: $*"
972 rm -f ${RESULT_DIR}/require_test
973 rm -f ${RESULT_DIR}/require_scratch
978 # just plain bail out
982 echo "$*" | tee -a $seqres.full
983 echo "(see $seqres.full for details)"
988 # tests whether $FSTYP is one of the supported filesystems for a test
994 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1000 _notrun "not suitable for this filesystem type: $FSTYP"
1004 # tests whether $FSTYP is one of the supported OSes for a test
1010 if [ "$h" = "$HOSTOS" ]
1016 _notrun "not suitable for this OS: $HOSTOS"
1019 # this test needs a scratch partition - check we're ok & unmount it
1020 # No post-test check of the device is required. e.g. the test intentionally
1021 # finishes the test with the filesystem in a corrupt state
1022 _require_scratch_nocheck()
1026 _notrun "requires a scratch device"
1029 _notrun "requires a scratch device"
1032 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1034 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1038 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
1040 _notrun "this test requires a valid \$SCRATCH_DEV"
1042 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1044 _notrun "this test requires a valid \$SCRATCH_DEV"
1046 if [ ! -d "$SCRATCH_MNT" ]
1048 _notrun "this test requires a valid \$SCRATCH_MNT"
1054 if _mount | grep -q $SCRATCH_DEV
1056 # if it's mounted, make sure its on $SCRATCH_MNT
1057 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1059 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1062 # and then unmount it
1063 if ! $UMOUNT_PROG $SCRATCH_DEV
1065 echo "failed to unmount $SCRATCH_DEV"
1069 rm -f ${RESULT_DIR}/require_scratch
1072 # we need the scratch device and it should be checked post test.
1075 _require_scratch_nocheck
1076 touch ${RESULT_DIR}/require_scratch
1080 # this test needs a test partition - check we're ok & unmount it
1086 _notrun "requires a test device"
1089 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1090 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1091 _notrun "this test requires a valid \$TEST_DEV"
1093 if [ ! -d "$TEST_DIR" ]; then
1094 _notrun "this test requires a valid \$TEST_DIR"
1098 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1100 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1104 if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
1106 _notrun "this test requires a valid \$TEST_DEV"
1108 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1110 _notrun "this test requires a valid \$TEST_DEV"
1112 if [ ! -d "$TEST_DIR" ]
1114 _notrun "this test requires a valid \$TEST_DIR"
1120 if _mount | grep -q $TEST_DEV
1122 # if it's mounted, make sure its on $TEST_DIR
1123 if ! _mount | grep $TEST_DEV | grep -q $TEST_DIR
1125 echo "\$TEST_DEV is mounted but not on \$TEST_DIR - aborting"
1129 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1130 if [ $? -ne 1 ]; then
1135 touch ${RESULT_DIR}/require_test
1138 # this test needs a logdev
1142 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1143 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1144 [ "$USE_EXTERNAL" != yes ] && \
1145 _notrun "This test requires USE_EXTERNAL to be enabled"
1147 # ensure its not mounted
1148 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1151 # this test requires loopback device support
1155 if [ "$HOSTOS" != "Linux" ]
1157 _notrun "This test requires linux for loopback device support"
1160 modprobe loop >/dev/null 2>&1
1161 if grep loop /proc/devices >/dev/null 2>&1
1165 _notrun "This test requires loopback device support"
1169 # this test requires ext2 filesystem support
1173 if [ "$HOSTOS" != "Linux" ]
1175 _notrun "This test requires linux for ext2 filesystem support"
1178 modprobe ext2 >/dev/null 2>&1
1179 if grep ext2 /proc/filesystems >/dev/null 2>&1
1183 _notrun "This test requires ext2 filesystem support"
1187 # this test requires that (large) loopback device files are not in use
1189 _require_no_large_scratch_dev()
1191 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1192 _notrun "Large filesystem testing in progress, skipped this test"
1195 # this test requires that a realtime subvolume is in use, and
1196 # that the kernel supports realtime as well.
1200 [ "$USE_EXTERNAL" = yes ] || \
1201 _notrun "External volumes not in use, skipped this test"
1202 [ "$SCRATCH_RTDEV" = "" ] && \
1203 _notrun "Realtime device required, skipped this test"
1206 # this test requires that a specified command (executable) exists
1207 # $1 - command, $2 - name for error message
1211 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1212 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1215 # this test requires the device mapper flakey target
1217 _require_dm_flakey()
1219 _require_command $DMSETUP_PROG
1221 modprobe dm-flakey >/dev/null 2>&1
1222 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1227 _notrun "This test requires dm flakey support"
1231 # this test requires the projid32bit feature to be available in mkfs.xfs.
1233 _require_projid32bit()
1235 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1236 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1239 _require_projid16bit()
1241 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1242 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1245 # this test requires the crc feature to be available in mkfs.xfs
1247 _require_xfs_mkfs_crc()
1249 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1250 || _notrun "mkfs.xfs doesn't have crc feature"
1253 # this test requires the xfs kernel support crc feature
1257 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1258 _scratch_mount >/dev/null 2>&1 \
1259 || _notrun "Kernel doesn't support crc feature"
1263 # this test requires the bigalloc feature to be available in mkfs.ext4
1265 _require_ext4_mkfs_bigalloc()
1267 _scratch_mkfs_ext4 -O bigalloc >/dev/null 2>&1 \
1268 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1271 # this test requires the ext4 kernel support bigalloc feature
1273 _require_ext4_bigalloc()
1275 _scratch_mkfs_ext4 -O bigalloc >/dev/null 2>&1
1276 _scratch_mount >/dev/null 2>&1 \
1277 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1281 # this test requires the finobt feature to be available in mkfs.xfs
1283 _require_xfs_mkfs_finobt()
1285 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1286 || _notrun "mkfs.xfs doesn't have finobt feature"
1289 # this test requires the xfs kernel support finobt feature
1291 _require_xfs_finobt()
1293 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1294 _scratch_mount >/dev/null 2>&1 \
1295 || _notrun "Kernel doesn't support finobt feature"
1299 # this test requires xfs sysfs attribute support
1301 _require_xfs_sysfs()
1304 sysfsdir=/sys/fs/xfs
1305 testdev=`_short_dev $TEST_DEV`
1307 if [ ! -e $sysfsdir ]; then
1308 _notrun "no kernel support for XFS sysfs attributes"
1311 if [ ! -z $1 ] && [ ! -e $sysfsdir/$testdev/$attr ]; then
1312 _notrun "sysfs attribute '$attr' is not supported"
1316 # this test requires that external log/realtime devices are not in use
1318 _require_nonexternal()
1320 [ "$USE_EXTERNAL" = yes ] && \
1321 _notrun "External device testing in progress, skipped this test"
1324 # this test requires that a (specified) aio-dio executable exists
1325 # $1 - command (optional)
1331 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1332 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1334 AIO_TEST=src/aio-dio-regress/$1
1335 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1339 # run an aio-dio program
1345 echo "usage: _run_aiodio command_name" 2>&1
1351 local testtemp=$TEST_DIR/aio-testfile
1353 $AIO_TEST $testtemp 2>&1
1360 # indicate whether YP/NIS is active or not
1365 dn=$(domainname 2>/dev/null)
1366 test -n "${dn}" -a "${dn}" != "(none)"
1370 # cat the password file
1374 [ $(_yp_active) -eq 0 ] && ypcat passwd
1378 # cat the group file
1382 [ $(_yp_active) -eq 0 ] && ypcat group
1386 # check for the fsgqa user on the machine
1391 _cat_passwd | grep -q $qa_user
1392 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1393 echo /bin/true | su $qa_user
1394 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1397 # check for the fsgqa group on the machine
1402 _cat_group | grep -q $qa_group
1403 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1409 s,.*Permission\sdenied.*,Permission denied,;
1410 s,.*no\saccess\sto\stty.*,,;
1411 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1418 if [ "$HOSTOS" == "IRIX" ]
1420 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1422 echo $1 | su $qa_user 2>&1 | _filter_user_do
1426 _require_xfs_io_command()
1430 echo "Usage: _require_xfs_io_command command" 1>&2
1435 testfile=$TEST_DIR/$$.xfs_io
1438 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1440 "fpunch" | "fcollapse" | "zero" | "fzero" )
1441 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1442 -c "$command 4k 8k" $testfile 2>&1`
1445 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1446 -c "fiemap -v" $testfile 2>&1`
1449 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1451 echo $testio | egrep -q "invalid option|Is a directory" && \
1452 _notrun "xfs_io $command support is missing"
1455 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1458 rm -f $testfile 2>&1 > /dev/null
1459 echo $testio | grep -q "not found" && \
1460 _notrun "xfs_io $command support is missing"
1461 echo $testio | grep -q "Operation not supported" && \
1462 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1465 # Check that a fs has enough free space (in 1024b blocks)
1470 BLOCKS=$2 # in units of 1024
1471 let GB=$BLOCKS/1024/1024
1473 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1474 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1475 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1479 # Check if the filesystem supports sparse files.
1481 # Unfortunately there is no better way to do this than a manual black list.
1483 _require_sparse_files()
1487 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1496 #boot_params always present in debugfs
1497 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1500 _require_fail_make_request()
1502 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1503 || _notrun "$DEBUGFS_MNT/fail_make_request \
1504 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1508 # Check if the file system supports seek_data/hole
1510 _require_seek_data_hole()
1512 testfile=$TEST_DIR/$$.seek
1513 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1514 rm -f $testfile &>/dev/null
1515 echo $testseek | grep -q "Kernel does not support" && \
1516 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1519 # check that a FS on a device is mounted
1520 # if so, return mount point
1526 echo "Usage: _is_mounted device" 1>&2
1532 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1533 pattern { print $3 ; exit 0 }
1537 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1542 # remount a FS to a new mode (ro or rw)
1548 echo "Usage: _remount device ro/rw" 1>&2
1554 if ! mount -o remount,$mode $device
1556 echo "_remount: failed to remount filesystem on $device as $mode"
1561 # Run the appropriate repair/check on a filesystem
1563 # if the filesystem is mounted, it's either remounted ro before being
1564 # checked or it's unmounted and then remounted
1567 # If set, we remount ro instead of unmounting for fsck
1570 _umount_or_remount_ro()
1574 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1579 mountpoint=`_is_mounted $device`
1581 if [ $USE_REMOUNT -eq 0 ]; then
1582 $UMOUNT_PROG $device
1589 _mount_or_remount_rw()
1593 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1600 if [ $USE_REMOUNT -eq 0 ]
1602 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1604 echo "!!! failed to remount $device on $mountpoint"
1614 # Check a generic filesystem in no-op mode; this assumes that the
1615 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1616 # and that it will still return an errno for corruption in this mode.
1618 # Filesystems which don't support this will need to define their
1619 # own check routine.
1621 _check_generic_filesystem()
1625 # If type is set, we're mounted
1626 type=`_fs_type $device`
1629 if [ "$type" = "$FSTYP" ]
1632 mountpoint=`_umount_or_remount_ro $device`
1635 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1638 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1640 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1641 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1642 cat $tmp.fsck >>$seqres.full
1643 echo "*** end fsck.$FSTYP output" >>$seqres.full
1651 echo "*** mount output ***" >>$seqres.full
1652 _mount >>$seqres.full
1653 echo "*** end mount output" >>$seqres.full
1654 elif [ "$type" = "$FSTYP" ]
1657 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1661 if [ $ok -eq 0 ]; then
1669 # run xfs_check and friends on a FS.
1671 _check_xfs_filesystem()
1675 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1679 extra_mount_options=""
1681 if [ "$2" != "none" ]; then
1682 extra_log_options="-l$2"
1683 extra_mount_options="-ologdev=$2"
1686 if [ "$3" != "none" ]; then
1687 extra_rt_options="-r$3"
1688 extra_mount_options=$extra_mount_options" -ortdev=$3"
1690 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1692 [ "$FSTYP" != xfs ] && return 0
1694 type=`_fs_type $device`
1697 if [ "$type" = "xfs" ]
1700 mountpoint=`_umount_or_remount_ro $device`
1703 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1704 | tee $tmp.logprint | grep -q "<CLEAN>"
1705 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1707 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1709 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1710 echo "*** xfs_logprint -t output ***" >>$seqres.full
1711 cat $tmp.logprint >>$seqres.full
1712 echo "*** end xfs_logprint output" >>$seqres.full
1717 # xfs_check runs out of memory on large files, so even providing the test
1718 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1719 # large filesystems. Avoid it.
1720 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1721 _xfs_check $extra_log_options $device 2>&1 |\
1722 _fix_malloc >$tmp.fs_check
1724 if [ -s $tmp.fs_check ]
1726 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1728 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1729 echo "*** xfs_check output ***" >>$seqres.full
1730 cat $tmp.fs_check >>$seqres.full
1731 echo "*** end xfs_check output" >>$seqres.full
1736 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1739 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1741 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1742 echo "*** xfs_repair -n output ***" >>$seqres.full
1743 cat $tmp.repair | _fix_malloc >>$seqres.full
1744 echo "*** end xfs_repair output" >>$seqres.full
1748 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1752 echo "*** mount output ***" >>$seqres.full
1753 _mount >>$seqres.full
1754 echo "*** end mount output" >>$seqres.full
1755 elif [ "$type" = "xfs" ]
1757 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1760 if [ $ok -eq 0 ]; then
1762 if [ "$iam" != "check" ]; then
1770 # Filter the knowen errors the UDF Verifier reports.
1771 _udf_test_known_error_filter()
1773 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."
1777 _check_udf_filesystem()
1779 [ "$DISABLE_UDF_TEST" == "1" ] && return
1781 if [ $# -ne 1 -a $# -ne 2 ]
1783 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1787 if [ ! -x $here/src/udf_test ]
1789 echo "udf_test not installed, please download and build the Philips"
1790 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1791 echo "Then copy the udf_test binary to $here/src/."
1792 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1800 LAST_BLOCK=`expr \( $2 - 1 \)`
1801 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1804 rm -f $seqres.checkfs
1805 sleep 1 # Due to a problem with time stamps in udf_test
1806 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1807 _udf_test_known_error_filter | \
1808 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1809 echo "Warning UDF Verifier reported errors see $seqres.checkfs."
1812 _check_xfs_test_fs()
1816 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1817 TEST_LOG="$TEST_LOGDEV"
1819 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1820 TEST_RT="$TEST_RTDEV"
1822 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1824 # check for ipath consistency
1825 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1826 # errors go to stderr
1827 xfs_check_ipaths $TEST_DIR >/dev/null
1828 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1832 _check_btrfs_filesystem()
1836 # If type is set, we're mounted
1837 type=`_fs_type $device`
1840 if [ "$type" = "$FSTYP" ]
1843 mountpoint=`_umount_or_remount_ro $device`
1846 btrfsck $device >$tmp.fsck 2>&1
1849 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1851 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1852 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1853 cat $tmp.fsck >>$seqres.full
1854 echo "*** end fsck.$FSTYP output" >>$seqres.full
1862 echo "*** mount output ***" >>$seqres.full
1863 _mount >>$seqres.full
1864 echo "*** end mount output" >>$seqres.full
1865 elif [ "$type" = "$FSTYP" ]
1868 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1872 if [ $ok -eq 0 ]; then
1887 # no way to check consistency for nfs
1890 # no way to check consistency for cifs
1893 # do nothing for now
1896 _check_btrfs_filesystem $TEST_DEV
1899 # no way to check consistency for tmpfs
1902 _check_generic_filesystem $TEST_DEV
1910 [ $# -eq 1 ] && device=$1
1916 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1917 SCRATCH_LOG="$SCRATCH_LOGDEV"
1919 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1920 SCRATCH_RT="$SCRATCH_RTDEV"
1922 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1925 _check_udf_filesystem $device $udf_fsize
1928 # Don't know how to check an NFS filesystem, yet.
1931 # Don't know how to check a CIFS filesystem, yet.
1934 _check_btrfs_filesystem $device
1937 # no way to check consistency for tmpfs
1940 _check_generic_filesystem $device
1945 _full_fstyp_details()
1947 [ -z "$FSTYP" ] && FSTYP=xfs
1948 if [ $FSTYP = xfs ]; then
1949 if [ -d /proc/fs/xfs ]; then
1950 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1951 FSTYP="$FSTYP (non-debug)"
1952 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1953 FSTYP="$FSTYP (debug)"
1956 if uname -a | grep -qi 'debug'; then
1957 FSTYP="$FSTYP (debug)"
1959 FSTYP="$FSTYP (non-debug)"
1966 _full_platform_details()
1972 echo "$os/$platform $host $kernel"
1977 if [ -z "$1" -o -z "$2" ]; then
1978 echo Error must pass src and dst.
1982 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1984 elif [ "`uname`" == "Linux" ]; then
1987 echo Error test $seq does not run on the operating system: `uname`
1998 #takes files, randomdata
2006 if [ $size -gt 0 ]; then
2007 if [ "$2" == "false" ]; then
2008 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2010 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2017 # takes dirname, depth, randomdata
2020 dirname=$1; depth=$2; randomdata=$3
2021 mkdir $dirname || die "mkdir $dirname failed"
2024 _nfiles $files $randomdata # files for this dir and data type
2026 [ $depth -eq 0 ] && return
2027 let deep=$depth-1 # go 1 down
2029 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2032 while [ $d -lt $dirs ]
2034 _descend d$d $deep &
2040 # Populate a filesystem with inodes for performance experiments
2042 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2047 dirs=5 # ndirs in each subdir till leaves
2048 size=0 # sizeof files in K
2049 files=100 # num files in _each_ subdir
2050 depth=2 # depth of tree from root to leaves
2052 root=root # path of initial root of directory tree
2053 randomdata=false # -x data type urandom or zero
2056 while getopts "d:f:n:r:s:v:x" c
2065 x) randomdata=true;;
2069 _descend $root $depth $randomdata
2074 [ $verbose = true ] && echo done
2077 # query whether the given file has the given inode flag set
2084 if which $XFS_IO_PROG >/dev/null; then
2085 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2092 # query the given files extsize allocator hint in bytes (if any)
2099 if which $XFS_IO_PROG >/dev/null; then
2100 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2101 awk '/^xattr.extsize =/ { print $3 }'`
2103 [ -z "$blocks" ] && blocks="0"
2107 # scratch_dev_pool should contain the disks pool for the btrfs raid
2108 _require_scratch_dev_pool()
2113 if [ -z "$SCRATCH_DEV_POOL" ]; then
2114 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2117 if [ -z "$1" ]; then
2123 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2127 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2128 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2132 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2136 for i in $SCRATCH_DEV_POOL; do
2137 if [ "`_is_block_dev $i`" = "" ]; then
2138 _notrun "this test requires valid block disk $i"
2140 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
2141 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2143 if _mount | grep -q $i; then
2144 if ! $UMOUNT_PROG $i; then
2145 echo "failed to unmount $i - aborting"
2149 # to help better debug when something fails, we remove
2150 # traces of previous btrfs FS on the dev.
2151 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2155 # We will check if the device is deletable
2156 _require_deletable_scratch_dev_pool()
2160 for i in $SCRATCH_DEV_POOL; do
2161 x=`echo $i | cut -d"/" -f 3`
2162 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2163 _notrun "$i is a device which is not deletable"
2168 # We check for btrfs and (optionally) features of the btrfs command
2172 _require_command $BTRFS_UTIL_PROG btrfs
2173 if [ -z "$1" ]; then
2176 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2177 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2180 # Check that fio is present, and it is able to execute given jobfile
2185 _require_command $FIO_PROG
2186 if [ -z "$1" ]; then
2190 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2191 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2194 # Does freeze work on this fs?
2197 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2199 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2200 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2203 # arg 1 is dev to remove and is output of the below eg.
2204 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2210 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2212 stat $disk > /dev/null 2>&1
2213 while [ $? -eq 0 ]; do
2215 stat $disk > /dev/null 2>&1
2219 # arg 1 is dev to add and is output of the below eg.
2220 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2225 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2226 h=`echo ${1} | cut -d":" -f 1`
2227 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2229 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2231 # ensure the device comes online
2233 for i in `seq 1 10`; do
2234 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2235 dev=`ls /sys/class/scsi_device/${1}/device/block`
2236 for j in `seq 1 10`;
2238 stat /dev/$dev > /dev/null 2>&1
2239 if [ $? -eq 0 ]; then
2250 if [ $dev_back_oneline -eq 0 ]; then
2251 echo "/dev/$dev online failed" >> $seqres.full
2253 echo "/dev/$dev is back online" >> $seqres.full
2259 if [ -z "$FSTRIM_PROG" ]; then
2260 _notrun "This test requires fstrim utility."
2264 _test_batched_discard()
2266 if [ $# -ne 1 ]; then
2267 echo "Usage: _test_batched_discard mnt_point" 1>&2
2271 $FSTRIM_PROG ${1} &>/dev/null
2276 if [ -z "$DUMPE2FS_PROG" ]; then
2277 _notrun "This test requires dumpe2fs utility."
2283 if [ ! -e /proc/self/uid_map ]; then
2284 _notrun "This test requires procfs uid_map support."
2286 if [ ! -e /proc/self/gid_map ]; then
2287 _notrun "This test requires procfs gid_map support."
2291 _require_cp_reflink()
2293 cp --help | grep -q reflink || \
2294 _notrun "This test requires a cp with --reflink support."
2299 FSSUM_PROG=$here/src/fssum
2300 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2303 _require_btrfs_cloner()
2305 CLONER_PROG=$here/src/cloner
2306 [ -x $CLONER_PROG ] || \
2307 _notrun "cloner binary not present at $CLONER_PROG"
2310 # Given 2 files, verify that they have the same mapping but different
2311 # inodes - i.e. an undisturbed reflink
2312 # Silent if so, make noise if not
2315 # not a hard link or symlink?
2316 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2317 && echo "$1 and $2 are not reflinks: same inode number"
2320 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2321 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2322 || echo "$1 and $2 are not reflinks: different extents"
2327 _scratch_mkfs > /dev/null 2>&1
2328 _mount -t $FSTYP -o relatime $SCRATCH_DEV $SCRATCH_MNT || \
2329 _notrun "relatime not supported by the current kernel"
2335 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2336 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2339 _create_loop_device()
2342 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2346 _destroy_loop_device()
2349 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2352 _scale_fsstress_args()
2355 while [ $# -gt 0 ]; do
2357 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2358 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2359 *) args="$args $1" ;;
2367 # Return the logical block size if running on a block device,
2368 # else substitute the page size.
2370 _min_dio_alignment()
2374 if [ -b "$dev" ]; then
2375 blockdev --getss $dev
2377 $here/src/feature -s
2383 echo "# $@" >> $seqres.full 2>&1
2384 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2387 _run_btrfs_util_prog()
2389 run_check $BTRFS_UTIL_PROG $*
2392 _require_btrfs_send_stream_version()
2394 $BTRFS_UTIL_PROG send 2>&1 | \
2395 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2396 if [ $? -ne 0 ]; then
2397 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2400 # test if btrfs kernel supports send stream version 2
2401 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
2402 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
2406 _require_btrfs_mkfs_feature()
2409 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
2413 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
2414 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
2416 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
2419 _require_btrfs_fs_feature()
2422 echo "Missing feature name argument for _require_btrfs_fs_feature"
2426 modprobe btrfs > /dev/null 2>&1
2427 [ -e /sys/fs/btrfs/features/$feat ] || \
2428 _notrun "Feature $feat not supported by the available btrfs version"
2431 _require_test_symlinks()
2433 # IRIX UDF does not support symlinks
2434 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2435 _notrun "Require symlinks support"
2436 target=`mktemp -p $TEST_DIR`
2437 link=`mktemp -p $TEST_DIR -u`
2438 ln -s `basename $target` $link
2439 if [ "$?" -ne 0 ]; then
2441 _notrun "Require symlinks support"
2446 _require_test_fcntl_advisory_locks()
2448 [ "$FSTYP" != "cifs" ] && return 0
2449 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
2450 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
2451 _notrun "Require fcntl advisory locks support"
2456 if [ -z "$1" ]; then
2457 echo "Usage: _get_total_inode <mnt>"
2461 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
2467 if [ -z "$1" ]; then
2468 echo "Usage: _get_used_inode <mnt>"
2472 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
2478 if [ -z "$1" ]; then
2479 echo "Usage: _get_free_inode <mnt>"
2483 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
2489 if [ "$iam" == new ]
2493 # make some further configuration checks here
2494 if [ "$TEST_DEV" = "" ]
2496 echo "common/rc: Error: \$TEST_DEV is not set"
2500 # if $TEST_DEV is not mounted, mount it now as XFS
2501 if [ -z "`_fs_type $TEST_DEV`" ]
2503 # $TEST_DEV is not mounted
2506 echo "common/rc: retrying test device mount with external set"
2507 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2510 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2516 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2518 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2522 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2523 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2524 export XFS_IO_PROG="$XFS_IO_PROG -F"
2527 # get real device path name by following link
2531 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
2532 _dev=`readlink -f "$_dev"`
2537 # basename of a device
2540 echo `basename $(_real_dev $1)`
2545 ################################################################################
2546 # make sure this script returns success