2 #-----------------------------------------------------------------------
3 # Copyright (c) 2000-2006 Silicon Graphics, Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 # Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
20 # Mountain View, CA 94043, USA, or: http://www.sgi.com
21 #-----------------------------------------------------------------------
23 BC=$(which bc 2> /dev/null) || BC=
28 _notrun "this test requires 'bc' tool for doing math operations"
34 [ $# -le 0 ] && return
36 result=$(LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null)
38 _notrun "this test requires 'bc' tool for doing math operations"
45 if [ "$HOSTOS" == "Linux" ]
47 command dd --help 2>&1 | grep noxfer >/dev/null
51 command dd status=noxfer $@
65 $BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
68 # Prints the md5 checksum of a given file
71 md5sum $1 | cut -d ' ' -f1
75 # ls -l w/ selinux sometimes puts a dot at the end:
76 # -rwxrw-r--. id1 id2 file1
77 # Also filter out lost+found directory on extN file system if present
81 ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /" | grep -v 'lost+found'
84 # we need common/config
85 if [ "$iam" != "check" ]
87 if ! . ./common/config
89 echo "$iam: failed to source common/config"
94 # check for correct setup
97 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
98 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
99 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
100 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
103 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
106 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
109 [ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found"
117 # make sure we have a standard umask
122 $MOUNT_PROG `_mount_ops_filter $*`
130 if [ "$FSTYP" != "xfs" ]; then
136 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
145 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
146 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
147 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
148 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
156 if [ "$FSTYP" != "xfs" ]; then
170 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
171 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
172 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
173 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
180 #get mount point to handle dmapi mtpt option correctly
182 [ $last_index -gt 0 ] && shift $last_index
185 # irix is fussy about how it is fed its mount options
186 # - multiple -o's are not allowed
187 # - no spaces between comma delimitered options
188 # the sed script replaces all -o's (except the first) with a comma
189 # not required for linux, but won't hurt
191 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
192 | sed -e 's/dmapi/dmi/' \
193 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
197 _scratch_mount_options()
199 _scratch_options mount
201 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
206 _mount -t $FSTYP `_scratch_mount_options $*`
211 $UMOUNT_PROG $SCRATCH_DEV
223 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
228 $UMOUNT_PROG $TEST_DEV
232 _scratch_mkfs_options()
234 _scratch_options mkfs
235 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
243 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
244 options="-l $SCRATCH_LOGDEV"
246 xfs_metadump $options $SCRATCH_DEV $dumpfile
249 _setup_large_xfs_fs()
254 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
255 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
256 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
258 # calculate the size of the file we need to allocate.
259 # Default free space in the FS is 50GB, but you can specify more via
260 # SCRATCH_DEV_EMPTY_SPACE
261 file_size=$(($fs_size - 50*1024*1024*1024))
262 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
264 # mount the filesystem, create the file, unmount it
265 _scratch_mount 2>&1 >$tmp_dir/mnt.err
267 if [ $status -ne 0 ]; then
269 cat $tmp_dir/mnt.err >&2
270 rm -f $tmp_dir/mnt.err
273 rm -f $tmp_dir/mnt.err
276 -c "truncate $file_size" \
277 -c "falloc -k 0 $file_size" \
279 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
280 export NUM_SPACE_FILES=1
283 if [ $status -ne 0 ]; then
284 echo "large file prealloc failed"
285 cat $tmp_dir/mnt.err >&2
291 _scratch_mkfs_xfs_opts()
295 _scratch_options mkfs
297 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
301 _scratch_mkfs_xfs_supported()
305 _scratch_options mkfs
307 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
312 # extra mkfs options can be added by tests
313 local extra_mkfs_options=$*
317 # save mkfs output in case conflict means we need to run again.
318 # only the output for the mkfs that applies should be shown
319 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
320 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
324 # a mkfs failure may be caused by conflicts between
325 # $MKFS_OPTIONS and $extra_mkfs_options
326 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
328 echo -n "** mkfs failed with extra mkfs options "
329 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
330 echo -n "** attempting to mkfs using only test $seq "
331 echo "options: $extra_mkfs_options **"
334 # running mkfs again. overwrite previous mkfs output files
335 _scratch_mkfs_xfs_opts $extra_mkfs_options \
336 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
340 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
341 # manually parse the mkfs output to get the fs size in bytes
343 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
344 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
346 print STDOUT "$size\n";
348 _setup_large_xfs_fs $fs_size
352 # output stored mkfs output
353 cat $tmp_dir.mkfserr >&2
355 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
360 # xfs_check script is planned to be deprecated. But, we want to
361 # be able to invoke "xfs_check" behavior in xfstests in order to
362 # maintain the current verification levels.
367 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
369 while getopts "b:fi:l:stvV" c
375 i) OPTS=$OPTS"-i "$OPTARG" ";;
376 b) OPTS=$OPTS"-b "$OPTARG" ";;
377 f) DBOPTS=$DBOPTS" -f";;
378 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
379 V) $XFS_DB_PROG -p xfs_check -V
387 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
397 _setup_large_ext4_fs()
402 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
403 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
404 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
406 # Default free space in the FS is 50GB, but you can specify more via
407 # SCRATCH_DEV_EMPTY_SPACE
408 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
410 # mount the filesystem and create 16TB - 4KB files until we consume
411 # all the necessary space.
412 _scratch_mount 2>&1 >$tmp_dir/mnt.err
414 if [ $status -ne 0 ]; then
416 cat $tmp_dir/mnt.err >&2
417 rm -f $tmp_dir/mnt.err
420 rm -f $tmp_dir/mnt.err
422 file_size=$((16*1024*1024*1024*1024 - 4096))
424 while [ $space_to_consume -gt $file_size ]; do
427 -c "truncate $file_size" \
428 -c "falloc -k 0 $file_size" \
429 $SCRATCH_MNT/.use_space.$nfiles 2>&1
431 if [ $status -ne 0 ]; then
435 space_to_consume=$(( $space_to_consume - $file_size ))
436 nfiles=$(($nfiles + 1))
439 # consume the remaining space.
440 if [ $space_to_consume -gt 0 ]; then
442 -c "truncate $space_to_consume" \
443 -c "falloc -k 0 $space_to_consume" \
444 $SCRATCH_MNT/.use_space.$nfiles 2>&1
447 export NUM_SPACE_FILES=$nfiles
450 if [ $status -ne 0 ]; then
451 echo "large file prealloc failed"
452 cat $tmp_dir/mnt.err >&2
460 # extra mkfs options can be added by tests
461 local extra_mkfs_options=$*
465 $MKFS_EXT4_PROG -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
466 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
469 # a mkfs failure may be caused by conflicts between
470 # $MKFS_OPTIONS and $extra_mkfs_options
471 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
473 echo -n "** mkfs failed with extra mkfs options "
474 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
475 echo -n "** attempting to mkfs using only test $seq "
476 echo "options: $extra_mkfs_options **"
479 # running mkfs again. overwrite previous mkfs output files
480 $MKFS_EXT4_PROG -F $extra_mkfs_options $SCRATCH_DEV \
481 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
485 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
486 # manually parse the mkfs output to get the fs size in bytes
487 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
488 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
489 / inodes, / { blks = $3 } \
490 /reserved for the super user/ { resv = $1 } \
491 END { fssize = bs * blks - resv; print fssize }'`
493 _setup_large_ext4_fs $fs_size
497 # output stored mkfs output
498 cat $tmp_dir.mkfserr >&2
500 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
512 # do nothing for cifs
515 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
518 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
521 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
533 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
536 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
539 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
540 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
544 if [ $? -ne 0 ]; then
545 # output stored mkfs output
546 cat $tmp_dir.mkfserr >&2
551 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
554 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
555 _scratch_cleanup_files()
558 rm -rf $SCRATCH_MNT/*
569 # unable to re-create NFS, just remove all files in $SCRATCH_MNT to
570 # avoid EEXIST caused by the leftover files created in previous runs
571 _scratch_cleanup_files
574 # unable to re-create CIFS, just remove all files in $SCRATCH_MNT to
575 # avoid EEXIST caused by the leftover files created in previous runs
576 _scratch_cleanup_files
579 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
582 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
585 _scratch_mkfs_ext4 $*
588 # do nothing for tmpfs
591 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
600 # if dup profile is in mkfs options call _scratch_mkfs instead
601 # because dup profile only works with single device
602 if [[ "$*" =~ dup ]]; then
605 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
609 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
614 # Create fs of certain size on scratch device
615 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
616 _scratch_mkfs_sized()
623 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
625 ext2|ext3|ext4|ext4dev|udf|btrfs)
626 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
630 [ -n "$def_blksz" ] && blocksize=$def_blksz
631 [ -z "$blocksize" ] && blocksize=4096
635 if ! [[ $fssize =~ $re ]] ; then
636 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
638 if ! [[ $blocksize =~ $re ]] ; then
639 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
642 blocks=`expr $fssize / $blocksize`
644 if [ "$HOSTOS" == "Linux" ]; then
645 devsize=`blockdev --getsize64 $SCRATCH_DEV`
646 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
651 # don't override MKFS_OPTIONS that set a block size.
652 echo $MKFS_OPTIONS |egrep -q "b?size="
653 if [ $? -eq 0 ]; then
654 _scratch_mkfs_xfs -d size=$fssize
656 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
659 ext2|ext3|ext4|ext4dev)
660 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
663 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
666 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
669 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
674 # Emulate an N-data-disk stripe w/ various stripe units
675 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
681 [ -z "$blocksize" ] && blocksize=4096
683 let sunit_blocks=$sunit_bytes/$blocksize
684 let swidth_blocks=$sunit_blocks*$swidth_mult
688 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
691 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
694 _notrun "can't mkfs $FSTYP with geometry"
704 xfs_io -x -c "resblks $1" $SCRATCH_MNT
711 _scratch_xfs_db_options()
714 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
715 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
716 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
719 _scratch_xfs_logprint()
722 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
723 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
724 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
730 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
731 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
732 [ "$LARGE_SCRATCH_DEV" = yes ] && \
733 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
734 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
737 _scratch_xfs_repair()
740 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
741 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
742 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
743 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
744 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
745 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
752 echo "Usage: _get_pids_by_name process-name" 1>&2
756 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
757 # HH:MM:SS before the psargs field, use this as the search anchor.
759 # Matches with $1 (process-name) occur if the first psarg is $1
760 # or ends in /$1 ... the matching uses sed's regular expressions,
761 # so passing a regex into $1 will work.
769 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
770 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
773 # fix malloc libs output
777 # filter out the Electric Fence notice
780 if (defined $o && /^\s+Electric Fence/) {
786 print $o if (defined $o);
790 print $o if (defined $o);
794 # check if run as root
798 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
801 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
808 # _df_device : get an IRIX style df line for a given device
810 # - returns "" if not mounted
811 # - returns fs type in field two (ala IRIX)
812 # - joins line together if split by fancy df formatting
813 # - strips header etc
820 echo "Usage: _df_device device" 1>&2
824 # Note that we use "==" here so awk doesn't try to interpret an NFS over
825 # IPv6 server as a regular expression.
826 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
827 ($1==what) && (NF==1) {
841 # _df_dir : get an IRIX style df line for device where a directory resides
843 # - returns fs type in field two (ala IRIX)
844 # - joins line together if split by fancy df formatting
845 # - strips header etc
852 echo "Usage: _df_dir device" 1>&2
856 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
872 # return percentage used disk space for mounted device
878 echo "Usage: _used device" 1>&2
882 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
885 # return the FS type of a mounted device
891 echo "Usage: _fs_type device" 1>&2
896 # The Linux kernel shows NFSv4 filesystems in df output as
897 # filesystem type nfs4, although we mounted it as nfs earlier.
898 # Fix the filesystem type up here so that the callers don't
899 # have to bother with this quirk.
901 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
904 # return the FS mount options of a mounted device
906 # should write a version which just parses the output of mount for IRIX
907 # compatibility, but since this isn't used at all, at the moment I'll leave
914 echo "Usage: _fs_options device" 1>&2
918 $AWK_PROG -v dev=$1 '
919 match($1,dev) { print $4 }
923 # returns device number if a file is a block device
929 echo "Usage: _is_block_dev dev" 1>&2
934 if [ -L "${_dev}" ]; then
935 _dev=`readlink -f ${_dev}`
938 if [ -b "${_dev}" ]; then
939 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
943 # Do a command, log it to $seqres.full, optionally test return status
944 # and die if command fails. If called with one argument _do executes the
945 # command, logs it, and returns its exit status. With two arguments _do
946 # first prints the message passed in the first argument, and then "done"
947 # or "fail" depending on the return status of the command passed in the
948 # second argument. If the command fails and the variable _do_die_on_error
949 # is set to "always" or the two argument form is used and _do_die_on_error
950 # is set to "message_only" _do will print an error message to
951 # $seqres.out and exit.
955 if [ $# -eq 1 ]; then
957 elif [ $# -eq 2 ]; then
962 echo "Usage: _do [note] cmd" 1>&2
966 (eval "echo '---' \"$_cmd\"") >>$seqres.full
967 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
968 cat $tmp._out | _fix_malloc >>$seqres.full
969 if [ $# -eq 2 ]; then
970 if [ $ret -eq 0 ]; then
977 && [ "$_do_die_on_error" = "always" \
978 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
981 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
988 # bail out, setting up .notrun file. Need to kill the filesystem check files
989 # here, otherwise they are set incorrectly for the next test.
993 echo "$*" > $seqres.notrun
994 echo "$seq not run: $*"
995 rm -f ${RESULT_DIR}/require_test
996 rm -f ${RESULT_DIR}/require_scratch
1001 # just plain bail out
1005 echo "$*" | tee -a $seqres.full
1006 echo "(see $seqres.full for details)"
1011 # tests whether $FSTYP is one of the supported filesystems for a test
1017 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1023 _notrun "not suitable for this filesystem type: $FSTYP"
1027 # tests whether $FSTYP is one of the supported OSes for a test
1033 if [ "$h" = "$HOSTOS" ]
1039 _notrun "not suitable for this OS: $HOSTOS"
1042 # this test needs a scratch partition - check we're ok & unmount it
1043 # No post-test check of the device is required. e.g. the test intentionally
1044 # finishes the test with the filesystem in a corrupt state
1045 _require_scratch_nocheck()
1049 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1050 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1051 _notrun "this test requires a valid \$SCRATCH_DEV"
1053 if [ ! -d "$SCRATCH_MNT" ]; then
1054 _notrun "this test requires a valid \$SCRATCH_MNT"
1058 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1059 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1060 _notrun "this test requires a valid \$SCRATCH_DEV"
1062 if [ ! -d "$SCRATCH_MNT" ]; then
1063 _notrun "this test requires a valid \$SCRATCH_MNT"
1067 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1069 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1073 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
1075 _notrun "this test requires a valid \$SCRATCH_DEV"
1077 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1079 _notrun "this test requires a valid \$SCRATCH_DEV"
1081 if [ ! -d "$SCRATCH_MNT" ]
1083 _notrun "this test requires a valid \$SCRATCH_MNT"
1089 if _mount | grep -q $SCRATCH_DEV
1091 # if it's mounted, make sure its on $SCRATCH_MNT
1092 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1094 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1097 # and then unmount it
1098 if ! $UMOUNT_PROG $SCRATCH_DEV
1100 echo "failed to unmount $SCRATCH_DEV"
1104 rm -f ${RESULT_DIR}/require_scratch
1107 # we need the scratch device and it should be checked post test.
1110 _require_scratch_nocheck
1111 touch ${RESULT_DIR}/require_scratch
1115 # this test needs a test partition - check we're ok & unmount it
1121 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1122 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1123 _notrun "this test requires a valid \$TEST_DIR"
1125 if [ ! -d "$TEST_DIR" ]; then
1126 _notrun "this test requires a valid \$TEST_DIR"
1130 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1131 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1132 _notrun "this test requires a valid \$TEST_DEV"
1134 if [ ! -d "$TEST_DIR" ]; then
1135 _notrun "this test requires a valid \$TEST_DIR"
1139 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1141 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1145 if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
1147 _notrun "this test requires a valid \$TEST_DEV"
1149 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1151 _notrun "this test requires a valid \$TEST_DEV"
1153 if [ ! -d "$TEST_DIR" ]
1155 _notrun "this test requires a valid \$TEST_DIR"
1161 # Note that we use -F here so grep doesn't try to interpret an NFS over
1162 # IPv6 server as a regular expression.
1163 if _mount | grep -F -q $TEST_DEV
1165 # if it's mounted, make sure its on $TEST_DIR
1166 if ! _mount | grep -F $TEST_DEV | grep -q $TEST_DIR
1168 echo "\$TEST_DEV is mounted but not on \$TEST_DIR - aborting"
1172 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1173 if [ $? -ne 1 ]; then
1178 touch ${RESULT_DIR}/require_test
1181 # this test needs a logdev
1185 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1186 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1187 [ "$USE_EXTERNAL" != yes ] && \
1188 _notrun "This test requires USE_EXTERNAL to be enabled"
1190 # ensure its not mounted
1191 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1194 # this test requires loopback device support
1198 if [ "$HOSTOS" != "Linux" ]
1200 _notrun "This test requires linux for loopback device support"
1203 modprobe loop >/dev/null 2>&1
1204 if grep loop /proc/devices >/dev/null 2>&1
1208 _notrun "This test requires loopback device support"
1212 # this test requires ext2 filesystem support
1216 if [ "$HOSTOS" != "Linux" ]
1218 _notrun "This test requires linux for ext2 filesystem support"
1221 modprobe ext2 >/dev/null 2>&1
1222 if grep ext2 /proc/filesystems >/dev/null 2>&1
1226 _notrun "This test requires ext2 filesystem support"
1230 # this test requires that (large) loopback device files are not in use
1232 _require_no_large_scratch_dev()
1234 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1235 _notrun "Large filesystem testing in progress, skipped this test"
1238 # this test requires that a realtime subvolume is in use, and
1239 # that the kernel supports realtime as well.
1243 [ "$USE_EXTERNAL" = yes ] || \
1244 _notrun "External volumes not in use, skipped this test"
1245 [ "$SCRATCH_RTDEV" = "" ] && \
1246 _notrun "Realtime device required, skipped this test"
1249 # this test requires that a specified command (executable) exists
1250 # $1 - command, $2 - name for error message
1254 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1255 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1258 # this test requires the device to be valid block device
1260 _require_block_device()
1262 if [ -z "$1" ]; then
1263 echo "Usage: _require_block_device <dev>" 1>&2
1266 if [ "`_is_block_dev $SCRATCH_DEV`" == "" ]; then
1267 _notrun "require $1 to be valid block disk"
1271 # this test requires the device mapper flakey target
1273 _require_dm_flakey()
1275 # require SCRATCH_DEV to be a valid block device
1276 _require_block_device $SCRATCH_DEV
1277 _require_command $DMSETUP_PROG
1279 modprobe dm-flakey >/dev/null 2>&1
1280 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1285 _notrun "This test requires dm flakey support"
1289 # this test requires the projid32bit feature to be available in mkfs.xfs.
1291 _require_projid32bit()
1293 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1294 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1297 _require_projid16bit()
1299 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1300 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1303 # this test requires the crc feature to be available in mkfs.xfs
1305 _require_xfs_mkfs_crc()
1307 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1308 || _notrun "mkfs.xfs doesn't have crc feature"
1311 # this test requires the xfs kernel support crc feature
1315 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1316 _scratch_mount >/dev/null 2>&1 \
1317 || _notrun "Kernel doesn't support crc feature"
1321 # this test requires the bigalloc feature to be available in mkfs.ext4
1323 _require_ext4_mkfs_bigalloc()
1325 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 200k >/dev/null 2>&1 \
1326 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1329 # this test requires the ext4 kernel support bigalloc feature
1331 _require_ext4_bigalloc()
1333 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 200k >/dev/null 2>&1
1334 _scratch_mount >/dev/null 2>&1 \
1335 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1339 # this test requires the finobt feature to be available in mkfs.xfs
1341 _require_xfs_mkfs_finobt()
1343 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1344 || _notrun "mkfs.xfs doesn't have finobt feature"
1347 # this test requires the xfs kernel support finobt feature
1349 _require_xfs_finobt()
1351 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1352 _scratch_mount >/dev/null 2>&1 \
1353 || _notrun "Kernel doesn't support finobt feature"
1357 # this test requires xfs sysfs attribute support
1359 _require_xfs_sysfs()
1362 sysfsdir=/sys/fs/xfs
1364 if [ ! -e $sysfsdir ]; then
1365 _notrun "no kernel support for XFS sysfs attributes"
1368 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1369 _notrun "sysfs attribute '$attr' is not supported"
1373 # this test requires that external log/realtime devices are not in use
1375 _require_nonexternal()
1377 [ "$USE_EXTERNAL" = yes ] && \
1378 _notrun "External device testing in progress, skipped this test"
1381 # this test requires that a (specified) aio-dio executable exists
1382 # $1 - command (optional)
1388 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1389 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1391 AIO_TEST=src/aio-dio-regress/$1
1392 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1396 # run an aio-dio program
1402 echo "usage: _run_aiodio command_name" 2>&1
1408 local testtemp=$TEST_DIR/aio-testfile
1410 $AIO_TEST $testtemp 2>&1
1417 # indicate whether YP/NIS is active or not
1422 dn=$(domainname 2>/dev/null)
1423 test -n "${dn}" -a "${dn}" != "(none)"
1427 # cat the password file
1431 [ $(_yp_active) -eq 0 ] && ypcat passwd
1435 # cat the group file
1439 [ $(_yp_active) -eq 0 ] && ypcat group
1443 # check for the fsgqa user on the machine
1448 _cat_passwd | grep -q $qa_user
1449 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1450 echo /bin/true | su $qa_user
1451 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1454 # check for the fsgqa group on the machine
1459 _cat_group | grep -q $qa_group
1460 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1466 s,.*Permission\sdenied.*,Permission denied,;
1467 s,.*no\saccess\sto\stty.*,,;
1468 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1475 if [ "$HOSTOS" == "IRIX" ]
1477 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1479 echo $1 | su $qa_user 2>&1 | _filter_user_do
1483 _require_xfs_io_command()
1487 echo "Usage: _require_xfs_io_command command" 1>&2
1492 testfile=$TEST_DIR/$$.xfs_io
1495 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1497 "fpunch" | "fcollapse" | "zero" | "fzero" )
1498 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1499 -c "$command 4k 8k" $testfile 2>&1`
1502 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1503 -c "fiemap -v" $testfile 2>&1`
1506 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1508 echo $testio | egrep -q "invalid option|Is a directory" && \
1509 _notrun "xfs_io $command support is missing"
1512 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1515 rm -f $testfile 2>&1 > /dev/null
1516 echo $testio | grep -q "not found" && \
1517 _notrun "xfs_io $command support is missing"
1518 echo $testio | grep -q "Operation not supported" && \
1519 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1522 # Check that a fs has enough free space (in 1024b blocks)
1527 BLOCKS=$2 # in units of 1024
1528 let GB=$BLOCKS/1024/1024
1530 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1531 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1532 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1536 # Check if the filesystem supports sparse files.
1538 # Unfortunately there is no better way to do this than a manual black list.
1540 _require_sparse_files()
1544 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1553 #boot_params always present in debugfs
1554 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1557 _require_fail_make_request()
1559 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1560 || _notrun "$DEBUGFS_MNT/fail_make_request \
1561 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1565 # Check if the file system supports seek_data/hole
1567 _require_seek_data_hole()
1569 testfile=$TEST_DIR/$$.seek
1570 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1571 rm -f $testfile &>/dev/null
1572 echo $testseek | grep -q "Kernel does not support" && \
1573 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1576 # check that a FS on a device is mounted
1577 # if so, return mount point
1583 echo "Usage: _is_mounted device" 1>&2
1589 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1590 pattern { print $3 ; exit 0 }
1594 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1599 # remount a FS to a new mode (ro or rw)
1605 echo "Usage: _remount device ro/rw" 1>&2
1611 if ! mount -o remount,$mode $device
1613 echo "_remount: failed to remount filesystem on $device as $mode"
1618 # Run the appropriate repair/check on a filesystem
1620 # if the filesystem is mounted, it's either remounted ro before being
1621 # checked or it's unmounted and then remounted
1624 # If set, we remount ro instead of unmounting for fsck
1627 _umount_or_remount_ro()
1631 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1636 mountpoint=`_is_mounted $device`
1638 if [ $USE_REMOUNT -eq 0 ]; then
1639 $UMOUNT_PROG $device
1646 _mount_or_remount_rw()
1650 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1657 if [ $USE_REMOUNT -eq 0 ]
1659 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1661 echo "!!! failed to remount $device on $mountpoint"
1671 # Check a generic filesystem in no-op mode; this assumes that the
1672 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1673 # and that it will still return an errno for corruption in this mode.
1675 # Filesystems which don't support this will need to define their
1676 # own check routine.
1678 _check_generic_filesystem()
1682 # If type is set, we're mounted
1683 type=`_fs_type $device`
1686 if [ "$type" = "$FSTYP" ]
1689 mountpoint=`_umount_or_remount_ro $device`
1692 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1695 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1697 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1698 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1699 cat $tmp.fsck >>$seqres.full
1700 echo "*** end fsck.$FSTYP output" >>$seqres.full
1708 echo "*** mount output ***" >>$seqres.full
1709 _mount >>$seqres.full
1710 echo "*** end mount output" >>$seqres.full
1711 elif [ "$type" = "$FSTYP" ]
1714 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1718 if [ $ok -eq 0 ]; then
1726 # run xfs_check and friends on a FS.
1728 _check_xfs_filesystem()
1732 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1736 extra_mount_options=""
1738 if [ "$2" != "none" ]; then
1739 extra_log_options="-l$2"
1740 extra_mount_options="-ologdev=$2"
1743 if [ "$3" != "none" ]; then
1744 extra_rt_options="-r$3"
1745 extra_mount_options=$extra_mount_options" -ortdev=$3"
1747 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1749 [ "$FSTYP" != xfs ] && return 0
1751 type=`_fs_type $device`
1754 if [ "$type" = "xfs" ]
1757 mountpoint=`_umount_or_remount_ro $device`
1760 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1761 | tee $tmp.logprint | grep -q "<CLEAN>"
1762 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1764 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1766 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1767 echo "*** xfs_logprint -t output ***" >>$seqres.full
1768 cat $tmp.logprint >>$seqres.full
1769 echo "*** end xfs_logprint output" >>$seqres.full
1774 # xfs_check runs out of memory on large files, so even providing the test
1775 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1776 # large filesystems. Avoid it.
1777 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1778 _xfs_check $extra_log_options $device 2>&1 |\
1779 _fix_malloc >$tmp.fs_check
1781 if [ -s $tmp.fs_check ]
1783 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1785 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1786 echo "*** xfs_check output ***" >>$seqres.full
1787 cat $tmp.fs_check >>$seqres.full
1788 echo "*** end xfs_check output" >>$seqres.full
1793 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1796 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1798 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1799 echo "*** xfs_repair -n output ***" >>$seqres.full
1800 cat $tmp.repair | _fix_malloc >>$seqres.full
1801 echo "*** end xfs_repair output" >>$seqres.full
1805 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1809 echo "*** mount output ***" >>$seqres.full
1810 _mount >>$seqres.full
1811 echo "*** end mount output" >>$seqres.full
1812 elif [ "$type" = "xfs" ]
1814 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1817 if [ $ok -eq 0 ]; then
1819 if [ "$iam" != "check" ]; then
1827 # Filter the knowen errors the UDF Verifier reports.
1828 _udf_test_known_error_filter()
1830 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."
1834 _check_udf_filesystem()
1836 [ "$DISABLE_UDF_TEST" == "1" ] && return
1838 if [ $# -ne 1 -a $# -ne 2 ]
1840 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1844 if [ ! -x $here/src/udf_test ]
1846 echo "udf_test not installed, please download and build the Philips"
1847 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1848 echo "Then copy the udf_test binary to $here/src/."
1849 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1857 LAST_BLOCK=`expr \( $2 - 1 \)`
1858 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1861 rm -f $seqres.checkfs
1862 sleep 1 # Due to a problem with time stamps in udf_test
1863 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1864 _udf_test_known_error_filter | \
1865 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1866 echo "Warning UDF Verifier reported errors see $seqres.checkfs."
1869 _check_xfs_test_fs()
1873 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1874 TEST_LOG="$TEST_LOGDEV"
1876 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1877 TEST_RT="$TEST_RTDEV"
1879 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1881 # check for ipath consistency
1882 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1883 # errors go to stderr
1884 xfs_check_ipaths $TEST_DIR >/dev/null
1885 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1889 _check_btrfs_filesystem()
1893 # If type is set, we're mounted
1894 type=`_fs_type $device`
1897 if [ "$type" = "$FSTYP" ]
1900 mountpoint=`_umount_or_remount_ro $device`
1903 btrfsck $device >$tmp.fsck 2>&1
1906 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1908 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1909 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1910 cat $tmp.fsck >>$seqres.full
1911 echo "*** end fsck.$FSTYP output" >>$seqres.full
1919 echo "*** mount output ***" >>$seqres.full
1920 _mount >>$seqres.full
1921 echo "*** end mount output" >>$seqres.full
1922 elif [ "$type" = "$FSTYP" ]
1925 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1929 if [ $ok -eq 0 ]; then
1944 # no way to check consistency for nfs
1947 # no way to check consistency for cifs
1950 # do nothing for now
1953 _check_btrfs_filesystem $TEST_DEV
1956 # no way to check consistency for tmpfs
1959 _check_generic_filesystem $TEST_DEV
1967 [ $# -eq 1 ] && device=$1
1973 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1974 SCRATCH_LOG="$SCRATCH_LOGDEV"
1976 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1977 SCRATCH_RT="$SCRATCH_RTDEV"
1979 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1982 _check_udf_filesystem $device $udf_fsize
1985 # Don't know how to check an NFS filesystem, yet.
1988 # Don't know how to check a CIFS filesystem, yet.
1991 _check_btrfs_filesystem $device
1994 # no way to check consistency for tmpfs
1997 _check_generic_filesystem $device
2002 _full_fstyp_details()
2004 [ -z "$FSTYP" ] && FSTYP=xfs
2005 if [ $FSTYP = xfs ]; then
2006 if [ -d /proc/fs/xfs ]; then
2007 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2008 FSTYP="$FSTYP (non-debug)"
2009 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2010 FSTYP="$FSTYP (debug)"
2013 if uname -a | grep -qi 'debug'; then
2014 FSTYP="$FSTYP (debug)"
2016 FSTYP="$FSTYP (non-debug)"
2023 _full_platform_details()
2029 echo "$os/$platform $host $kernel"
2034 if [ -z "$1" -o -z "$2" ]; then
2035 echo Error must pass src and dst.
2039 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2041 elif [ "`uname`" == "Linux" ]; then
2044 echo Error test $seq does not run on the operating system: `uname`
2055 #takes files, randomdata
2063 if [ $size -gt 0 ]; then
2064 if [ "$2" == "false" ]; then
2065 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2067 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2074 # takes dirname, depth, randomdata
2077 dirname=$1; depth=$2; randomdata=$3
2078 mkdir $dirname || die "mkdir $dirname failed"
2081 _nfiles $files $randomdata # files for this dir and data type
2083 [ $depth -eq 0 ] && return
2084 let deep=$depth-1 # go 1 down
2086 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2089 while [ $d -lt $dirs ]
2091 _descend d$d $deep &
2097 # Populate a filesystem with inodes for performance experiments
2099 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2104 dirs=5 # ndirs in each subdir till leaves
2105 size=0 # sizeof files in K
2106 files=100 # num files in _each_ subdir
2107 depth=2 # depth of tree from root to leaves
2109 root=root # path of initial root of directory tree
2110 randomdata=false # -x data type urandom or zero
2113 while getopts "d:f:n:r:s:v:x" c
2122 x) randomdata=true;;
2126 _descend $root $depth $randomdata
2131 [ $verbose = true ] && echo done
2134 # query whether the given file has the given inode flag set
2141 if which $XFS_IO_PROG >/dev/null; then
2142 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2149 # query the given files extsize allocator hint in bytes (if any)
2156 if which $XFS_IO_PROG >/dev/null; then
2157 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2158 awk '/^xattr.extsize =/ { print $3 }'`
2160 [ -z "$blocks" ] && blocks="0"
2164 # scratch_dev_pool should contain the disks pool for the btrfs raid
2165 _require_scratch_dev_pool()
2170 if [ -z "$SCRATCH_DEV_POOL" ]; then
2171 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2174 if [ -z "$1" ]; then
2180 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2184 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2185 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2189 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2193 for i in $SCRATCH_DEV_POOL; do
2194 if [ "`_is_block_dev $i`" = "" ]; then
2195 _notrun "this test requires valid block disk $i"
2197 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
2198 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2200 if _mount | grep -q $i; then
2201 if ! $UMOUNT_PROG $i; then
2202 echo "failed to unmount $i - aborting"
2206 # to help better debug when something fails, we remove
2207 # traces of previous btrfs FS on the dev.
2208 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2212 # ensure devices in SCRATCH_DEV_POOL are of the same size
2213 # must be called after _require_scratch_dev_pool
2214 _require_scratch_dev_pool_equal_size()
2220 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2221 _size=`_get_device_size $SCRATCH_DEV`
2222 for _dev in $SCRATCH_DEV_POOL; do
2223 _newsize=`_get_device_size $_dev`
2224 if [ $_size -ne $_newsize ]; then
2225 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2230 # We will check if the device is deletable
2231 _require_deletable_scratch_dev_pool()
2235 for i in $SCRATCH_DEV_POOL; do
2236 x=`echo $i | cut -d"/" -f 3`
2237 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2238 _notrun "$i is a device which is not deletable"
2243 # We check for btrfs and (optionally) features of the btrfs command
2247 _require_command $BTRFS_UTIL_PROG btrfs
2248 if [ -z "$1" ]; then
2251 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2252 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2255 # Check that fio is present, and it is able to execute given jobfile
2260 _require_command $FIO_PROG
2261 if [ -z "$1" ]; then
2265 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2266 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2269 # Does freeze work on this fs?
2272 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2274 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2275 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2278 # arg 1 is dev to remove and is output of the below eg.
2279 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2285 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2287 stat $disk > /dev/null 2>&1
2288 while [ $? -eq 0 ]; do
2290 stat $disk > /dev/null 2>&1
2294 # arg 1 is dev to add and is output of the below eg.
2295 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2300 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2301 h=`echo ${1} | cut -d":" -f 1`
2302 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2304 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2306 # ensure the device comes online
2308 for i in `seq 1 10`; do
2309 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2310 dev=`ls /sys/class/scsi_device/${1}/device/block`
2311 for j in `seq 1 10`;
2313 stat /dev/$dev > /dev/null 2>&1
2314 if [ $? -eq 0 ]; then
2325 if [ $dev_back_oneline -eq 0 ]; then
2326 echo "/dev/$dev online failed" >> $seqres.full
2328 echo "/dev/$dev is back online" >> $seqres.full
2334 if [ -z "$FSTRIM_PROG" ]; then
2335 _notrun "This test requires fstrim utility."
2339 _test_batched_discard()
2341 if [ $# -ne 1 ]; then
2342 echo "Usage: _test_batched_discard mnt_point" 1>&2
2346 $FSTRIM_PROG ${1} &>/dev/null
2351 if [ -z "$DUMPE2FS_PROG" ]; then
2352 _notrun "This test requires dumpe2fs utility."
2358 if [ ! -e /proc/self/uid_map ]; then
2359 _notrun "This test requires procfs uid_map support."
2361 if [ ! -e /proc/self/gid_map ]; then
2362 _notrun "This test requires procfs gid_map support."
2366 _require_cp_reflink()
2368 cp --help | grep -q reflink || \
2369 _notrun "This test requires a cp with --reflink support."
2374 FSSUM_PROG=$here/src/fssum
2375 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2380 CLONER_PROG=$here/src/cloner
2381 [ -x $CLONER_PROG ] || \
2382 _notrun "cloner binary not present at $CLONER_PROG"
2385 # Given 2 files, verify that they have the same mapping but different
2386 # inodes - i.e. an undisturbed reflink
2387 # Silent if so, make noise if not
2390 # not a hard link or symlink?
2391 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2392 && echo "$1 and $2 are not reflinks: same inode number"
2395 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2396 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2397 || echo "$1 and $2 are not reflinks: different extents"
2402 if [ "$FSTYP" == "nfs" ]; then
2403 _notrun "atime related mount options have no effect on NFS"
2409 _scratch_mkfs > /dev/null 2>&1
2410 _scratch_mount -o relatime || \
2411 _notrun "relatime not supported by the current kernel"
2417 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2418 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2421 _create_loop_device()
2424 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2428 _destroy_loop_device()
2431 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2434 _scale_fsstress_args()
2437 while [ $# -gt 0 ]; do
2439 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2440 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2441 *) args="$args $1" ;;
2449 # Return the logical block size if running on a block device,
2450 # else substitute the page size.
2452 _min_dio_alignment()
2456 if [ -b "$dev" ]; then
2457 blockdev --getss $dev
2459 $here/src/feature -s
2465 echo "# $@" >> $seqres.full 2>&1
2466 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2469 _run_btrfs_util_prog()
2471 run_check $BTRFS_UTIL_PROG $*
2474 _require_btrfs_send_stream_version()
2476 $BTRFS_UTIL_PROG send 2>&1 | \
2477 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2478 if [ $? -ne 0 ]; then
2479 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2482 # test if btrfs kernel supports send stream version 2
2483 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
2484 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
2488 _require_btrfs_mkfs_feature()
2491 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
2495 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
2496 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
2498 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
2501 _require_btrfs_fs_feature()
2504 echo "Missing feature name argument for _require_btrfs_fs_feature"
2508 modprobe btrfs > /dev/null 2>&1
2509 [ -e /sys/fs/btrfs/features/$feat ] || \
2510 _notrun "Feature $feat not supported by the available btrfs version"
2513 _require_test_symlinks()
2515 # IRIX UDF does not support symlinks
2516 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2517 _notrun "Require symlinks support"
2518 target=`mktemp -p $TEST_DIR`
2519 link=`mktemp -p $TEST_DIR -u`
2520 ln -s `basename $target` $link
2521 if [ "$?" -ne 0 ]; then
2523 _notrun "Require symlinks support"
2528 _require_test_fcntl_advisory_locks()
2530 [ "$FSTYP" != "cifs" ] && return 0
2531 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
2532 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
2533 _notrun "Require fcntl advisory locks support"
2538 if [ -z "$1" ]; then
2539 echo "Usage: _get_total_inode <mnt>"
2543 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
2549 if [ -z "$1" ]; then
2550 echo "Usage: _get_used_inode <mnt>"
2554 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
2560 if [ -z "$1" ]; then
2561 echo "Usage: _get_free_inode <mnt>"
2565 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
2569 # get btrfs profile configs being tested
2571 # A set of pre-set profile configs are exported via _btrfs_profile_configs
2572 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
2573 # var in the format "metadata_profile:data_profile", multiple configs can be
2574 # seperated by space, e.g.
2575 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
2576 _btrfs_get_profile_configs()
2578 if [ "$FSTYP" != "btrfs" ]; then
2582 # no user specified btrfs profile configs, export the default configs
2583 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
2585 _btrfs_profile_configs=(
2586 "-m single -d single"
2591 "-m raid10 -d raid10"
2596 # remove dup/raid5/raid6 profiles if we're doing device replace
2597 # dup profile indicates only one device being used (SCRATCH_DEV),
2598 # but we don't want to replace SCRATCH_DEV, which will be used in
2599 # _scratch_mount/_check_scratch_fs etc.
2600 # and raid5/raid6 doesn't support replace yet
2601 if [ "$1" == "replace" ]; then
2602 _btrfs_profile_configs=(
2603 "-m single -d single"
2607 "-m raid10 -d raid10"
2608 # add these back when raid5/6 is working with replace
2609 #"-m raid5 -d raid5"
2610 #"-m raid6 -d raid6"
2613 export _btrfs_profile_configs
2617 # parse user specified btrfs profile configs
2620 for cfg in $BTRFS_PROFILE_CONFIGS; do
2621 # turn "metadata:data" format to "-m metadata -d data"
2622 # and assign it to _btrfs_profile_configs array
2623 cfg=`echo "$cfg" | sed -e 's/^/-m /' -e 's/:/ -d /'`
2624 _btrfs_profile_configs[$i]="$cfg"
2628 if [ "$1" == "replace" ]; then
2629 if echo ${_btrfs_profile_configs[*]} | grep -q raid[56]; then
2630 _notrun "RAID5/6 doesn't support btrfs device replace yet"
2632 if echo ${_btrfs_profile_configs[*]} | grep -q dup; then
2633 _notrun "Do not set dup profile in btrfs device replace test"
2636 export _btrfs_profile_configs
2639 # stress btrfs by running balance operation in a loop
2640 _btrfs_stress_balance()
2644 $BTRFS_UTIL_PROG balance start $btrfs_mnt
2648 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
2649 _btrfs_stress_subvolume()
2653 local subvol_name=$3
2656 mkdir -p $subvol_mnt
2658 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
2659 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
2660 $UMOUNT_PROG $subvol_mnt
2661 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
2665 # stress btrfs by running scrub in a loop
2666 _btrfs_stress_scrub()
2670 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
2674 # stress btrfs by defragmenting every file/dir in a loop and compress file
2675 # contents while defragmenting if second argument is not "nocompress"
2676 _btrfs_stress_defrag()
2682 if [ "$compress" == "nocompress" ]; then
2683 find $btrfs_mnt \( -type f -o -type d \) -exec \
2684 $BTRFS_UTIL_PROG filesystem defrag {} \;
2686 find $btrfs_mnt \( -type f -o -type d \) -exec \
2687 $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
2688 find $btrfs_mnt \( -type f -o -type d \) -exec \
2689 $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
2694 # stress btrfs by remounting it with different compression algorithms in a loop
2695 # run this with fsstress running at background could exercise the compression
2696 # code path and ensure no race when switching compression algorithm with constant
2698 _btrfs_stress_remount_compress()
2702 for algo in no zlib lzo; do
2703 $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
2708 # stress btrfs by replacing devices in a loop
2709 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
2710 # device should be free(not used by btrfs)
2711 _btrfs_stress_replace()
2715 # The device number in SCRATCH_DEV_POOL should be at least 3,
2716 # one is SCRATCH_DEV, one is to be replaced, one is free device
2717 # we won't replace SCRATCH_DEV, see below for reason
2718 if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
2719 echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
2723 # take the last device as the first free_dev
2724 local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
2726 # free_dev should be really free
2727 if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
2728 echo "_btrfs_stress_replace: $free_dev is used by btrfs"
2732 # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
2733 # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
2734 # _scratch_mount and _check_scratch_fs etc.
2735 local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
2736 -e "s# *$free_dev *##"`
2738 # set the first device in dev_pool as the first src_dev to be replaced
2739 local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
2741 echo "dev_pool=$dev_pool"
2742 echo "free_dev=$free_dev, src_dev=$src_dev"
2744 echo "Replacing $src_dev with $free_dev"
2745 $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
2746 if [ $? -ne 0 ]; then
2747 # don't update src_dev and free_dev if replace failed
2750 dev_pool="$dev_pool $free_dev"
2751 dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
2753 src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
2757 # return device size in kb
2760 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
2765 if [ "$iam" == new ]
2769 # make some further configuration checks here
2770 if [ "$TEST_DEV" = "" ]
2772 echo "common/rc: Error: \$TEST_DEV is not set"
2776 # if $TEST_DEV is not mounted, mount it now as XFS
2777 if [ -z "`_fs_type $TEST_DEV`" ]
2779 # $TEST_DEV is not mounted
2782 echo "common/rc: retrying test device mount with external set"
2783 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2786 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2792 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2794 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2798 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2799 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2800 export XFS_IO_PROG="$XFS_IO_PROG -F"
2803 # get real device path name by following link
2807 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
2808 _dev=`readlink -f "$_dev"`
2813 # basename of a device
2816 echo `basename $(_real_dev $1)`
2821 if [ -z $1 ] || [ ! -d $1 ]; then
2822 echo "Missing mount point argument for get_block_size"
2825 echo `stat -f -c %S $1`
2830 ################################################################################
2831 # make sure this script returns success