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"
112 # make sure we have a standard umask
117 $MOUNT_PROG `_mount_ops_filter $*`
125 if [ "$FSTYP" != "xfs" ]; then
131 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
140 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
141 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
142 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
143 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
151 if [ "$FSTYP" != "xfs" ]; then
165 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
166 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
167 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
168 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
175 #get mount point to handle dmapi mtpt option correctly
177 [ $last_index -gt 0 ] && shift $last_index
180 # irix is fussy about how it is fed its mount options
181 # - multiple -o's are not allowed
182 # - no spaces between comma delimitered options
183 # the sed script replaces all -o's (except the first) with a comma
184 # not required for linux, but won't hurt
186 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
187 | sed -e 's/dmapi/dmi/' \
188 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
192 _scratch_mount_options()
194 _scratch_options mount
196 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
201 _mount -t $FSTYP `_scratch_mount_options $*`
206 $UMOUNT_PROG $SCRATCH_DEV
218 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
221 _scratch_mkfs_options()
223 _scratch_options mkfs
224 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
232 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
233 options="-l $SCRATCH_LOGDEV"
235 xfs_metadump $options $SCRATCH_DEV $dumpfile
238 _setup_large_xfs_fs()
243 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
244 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
245 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
247 # calculate the size of the file we need to allocate.
248 # Default free space in the FS is 50GB, but you can specify more via
249 # SCRATCH_DEV_EMPTY_SPACE
250 file_size=$(($fs_size - 50*1024*1024*1024))
251 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
253 # mount the filesystem, create the file, unmount it
254 _scratch_mount 2>&1 >$tmp_dir/mnt.err
256 if [ $status -ne 0 ]; then
258 cat $tmp_dir/mnt.err >&2
259 rm -f $tmp_dir/mnt.err
262 rm -f $tmp_dir/mnt.err
265 -c "truncate $file_size" \
266 -c "falloc -k 0 $file_size" \
268 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
269 export NUM_SPACE_FILES=1
272 if [ $status -ne 0 ]; then
273 echo "large file prealloc failed"
274 cat $tmp_dir/mnt.err >&2
280 _scratch_mkfs_xfs_opts()
284 _scratch_options mkfs
286 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
290 _scratch_mkfs_xfs_supported()
294 _scratch_options mkfs
296 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
301 # extra mkfs options can be added by tests
302 local extra_mkfs_options=$*
306 # save mkfs output in case conflict means we need to run again.
307 # only the output for the mkfs that applies should be shown
308 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
309 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
313 # a mkfs failure may be caused by conflicts between
314 # $MKFS_OPTIONS and $extra_mkfs_options
315 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
317 echo -n "** mkfs failed with extra mkfs options "
318 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
319 echo -n "** attempting to mkfs using only test $seq "
320 echo "options: $extra_mkfs_options **"
323 # running mkfs again. overwrite previous mkfs output files
324 _scratch_mkfs_xfs_opts $extra_mkfs_options \
325 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
329 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
330 # manually parse the mkfs output to get the fs size in bytes
332 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
333 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
335 print STDOUT "$size\n";
337 _setup_large_xfs_fs $fs_size
341 # output stored mkfs output
342 cat $tmp_dir.mkfserr >&2
344 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
349 # xfs_check script is planned to be deprecated. But, we want to
350 # be able to invoke "xfs_check" behavior in xfstests in order to
351 # maintain the current verification levels.
356 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
358 while getopts "b:fi:l:stvV" c
364 i) OPTS=$OPTS"-i "$OPTARG" ";;
365 b) OPTS=$OPTS"-b "$OPTARG" ";;
366 f) DBOPTS=$DBOPTS" -f";;
367 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
368 V) $XFS_DB_PROG -p xfs_check -V
376 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
386 _setup_large_ext4_fs()
391 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
392 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
393 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
395 # Default free space in the FS is 50GB, but you can specify more via
396 # SCRATCH_DEV_EMPTY_SPACE
397 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
399 # mount the filesystem and create 16TB - 4KB files until we consume
400 # all the necessary space.
401 _scratch_mount 2>&1 >$tmp_dir/mnt.err
403 if [ $status -ne 0 ]; then
405 cat $tmp_dir/mnt.err >&2
406 rm -f $tmp_dir/mnt.err
409 rm -f $tmp_dir/mnt.err
411 file_size=$((16*1024*1024*1024*1024 - 4096))
413 while [ $space_to_consume -gt $file_size ]; do
416 -c "truncate $file_size" \
417 -c "falloc -k 0 $file_size" \
418 $SCRATCH_MNT/.use_space.$nfiles 2>&1
420 if [ $status -ne 0 ]; then
424 space_to_consume=$(( $space_to_consume - $file_size ))
425 nfiles=$(($nfiles + 1))
428 # consume the remaining space.
429 if [ $space_to_consume -gt 0 ]; then
431 -c "truncate $space_to_consume" \
432 -c "falloc -k 0 $space_to_consume" \
433 $SCRATCH_MNT/.use_space.$nfiles 2>&1
436 export NUM_SPACE_FILES=$nfiles
439 if [ $status -ne 0 ]; then
440 echo "large file prealloc failed"
441 cat $tmp_dir/mnt.err >&2
449 # extra mkfs options can be added by tests
450 local extra_mkfs_options=$*
454 /sbin/mkfs -t ext4 -- -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
455 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
458 # a mkfs failure may be caused by conflicts between
459 # $MKFS_OPTIONS and $extra_mkfs_options
460 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
462 echo -n "** mkfs failed with extra mkfs options "
463 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
464 echo -n "** attempting to mkfs using only test $seq "
465 echo "options: $extra_mkfs_options **"
468 # running mkfs again. overwrite previous mkfs output files
469 /sbin/mkfs -t ext4 -- -F $extra_mkfs_options $SCRATCH_DEV \
470 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
474 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
475 # manually parse the mkfs output to get the fs size in bytes
476 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
477 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
478 / inodes, / { blks = $3 } \
479 /reserved for the super user/ { resv = $1 } \
480 END { fssize = bs * blks - resv; print fssize }'`
482 _setup_large_ext4_fs $fs_size
486 # output stored mkfs output
487 cat $tmp_dir.mkfserr >&2
489 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
501 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
504 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
507 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
522 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
525 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
528 _scratch_mkfs_ext4 $*
531 # do nothing for tmpfs
534 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
543 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
546 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
551 # Create fs of certain size on scratch device
552 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
553 _scratch_mkfs_sized()
557 [ -z "$blocksize" ] && blocksize=4096
560 if ! [[ $fssize =~ $re ]] ; then
561 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
563 if ! [[ $blocksize =~ $re ]] ; then
564 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
567 blocks=`expr $fssize / $blocksize`
569 if [ "$HOSTOS" == "Linux" ]; then
570 devsize=`blockdev --getsize64 $SCRATCH_DEV`
571 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
576 # don't override MKFS_OPTIONS that set a block size.
577 echo $MKFS_OPTIONS |egrep -q "b?size="
578 if [ $? -eq 0 ]; then
579 _scratch_mkfs_xfs -d size=$fssize
581 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
584 ext2|ext3|ext4|ext4dev)
585 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
588 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
591 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
594 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
599 # Emulate an N-data-disk stripe w/ various stripe units
600 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
606 [ -z "$blocksize" ] && blocksize=4096
608 let sunit_blocks=$sunit_bytes/$blocksize
609 let swidth_blocks=$sunit_blocks*$swidth_mult
613 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
616 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
619 _notrun "can't mkfs $FSTYP with geometry"
629 xfs_io -x -c "resblks $1" $SCRATCH_MNT
636 _scratch_xfs_db_options()
639 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
640 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
641 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
644 _scratch_xfs_logprint()
647 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
648 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
649 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
655 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
656 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
657 [ "$LARGE_SCRATCH_DEV" = yes ] && \
658 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
659 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
662 _scratch_xfs_repair()
665 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
666 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
667 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
668 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
669 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
670 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
677 echo "Usage: _get_pids_by_name process-name" 1>&2
681 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
682 # HH:MM:SS before the psargs field, use this as the search anchor.
684 # Matches with $1 (process-name) occur if the first psarg is $1
685 # or ends in /$1 ... the matching uses sed's regular expressions,
686 # so passing a regex into $1 will work.
694 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
695 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
698 # fix malloc libs output
702 # filter out the Electric Fence notice
705 if (defined $o && /^\s+Electric Fence/) {
711 print $o if (defined $o);
715 print $o if (defined $o);
719 # check if run as root
723 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
726 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
733 # _df_device : get an IRIX style df line for a given device
735 # - returns "" if not mounted
736 # - returns fs type in field two (ala IRIX)
737 # - joins line together if split by fancy df formatting
738 # - strips header etc
745 echo "Usage: _df_device device" 1>&2
749 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
750 match($1,what) && NF==1 {
764 # _df_dir : get an IRIX style df line for device where a directory resides
766 # - returns fs type in field two (ala IRIX)
767 # - joins line together if split by fancy df formatting
768 # - strips header etc
775 echo "Usage: _df_dir device" 1>&2
779 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
795 # return percentage used disk space for mounted device
801 echo "Usage: _used device" 1>&2
805 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
808 # return the FS type of a mounted device
814 echo "Usage: _fs_type device" 1>&2
819 # The Linux kernel shows NFSv4 filesystems in df output as
820 # filesystem type nfs4, although we mounted it as nfs earlier.
821 # Fix the filesystem type up here so that the callers don't
822 # have to bother with this quirk.
824 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
827 # return the FS mount options of a mounted device
829 # should write a version which just parses the output of mount for IRIX
830 # compatibility, but since this isn't used at all, at the moment I'll leave
837 echo "Usage: _fs_options device" 1>&2
841 $AWK_PROG -v dev=$1 '
842 match($1,dev) { print $4 }
846 # returns device number if a file is a block device
852 echo "Usage: _is_block_dev dev" 1>&2
857 if [ -L "${_dev}" ]; then
858 _dev=`readlink -f ${_dev}`
861 if [ -b "${_dev}" ]; then
862 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
866 # Do a command, log it to $seqres.full, optionally test return status
867 # and die if command fails. If called with one argument _do executes the
868 # command, logs it, and returns its exit status. With two arguments _do
869 # first prints the message passed in the first argument, and then "done"
870 # or "fail" depending on the return status of the command passed in the
871 # second argument. If the command fails and the variable _do_die_on_error
872 # is set to "always" or the two argument form is used and _do_die_on_error
873 # is set to "message_only" _do will print an error message to
874 # $seqres.out and exit.
878 if [ $# -eq 1 ]; then
880 elif [ $# -eq 2 ]; then
885 echo "Usage: _do [note] cmd" 1>&2
889 (eval "echo '---' \"$_cmd\"") >>$seqres.full
890 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
891 cat $tmp._out | _fix_malloc >>$seqres.full
892 if [ $# -eq 2 ]; then
893 if [ $ret -eq 0 ]; then
900 && [ "$_do_die_on_error" = "always" \
901 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
904 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
911 # bail out, setting up .notrun file
915 echo "$*" > $seqres.notrun
916 echo "$seq not run: $*"
921 # just plain bail out
925 echo "$*" | tee -a $seqres.full
926 echo "(see $seqres.full for details)"
931 # tests whether $FSTYP is one of the supported filesystems for a test
937 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
943 _notrun "not suitable for this filesystem type: $FSTYP"
947 # tests whether $FSTYP is one of the supported OSes for a test
953 if [ "$h" = "$HOSTOS" ]
959 _notrun "not suitable for this OS: $HOSTOS"
962 # this test needs a scratch partition - check we're ok & unmount it
968 _notrun "requires a scratch device"
971 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
973 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
977 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
979 _notrun "this test requires a valid \$SCRATCH_DEV"
981 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
983 _notrun "this test requires a valid \$SCRATCH_DEV"
985 if [ ! -d "$SCRATCH_MNT" ]
987 _notrun "this test requires a valid \$SCRATCH_MNT"
993 if _mount | grep -q $SCRATCH_DEV
995 # if it's mounted, make sure its on $SCRATCH_MNT
996 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
998 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1001 # and then unmount it
1002 if ! $UMOUNT_PROG $SCRATCH_DEV
1004 echo "failed to unmount $SCRATCH_DEV"
1008 touch ${RESULT_DIR}/require_scratch
1011 # this test needs a test partition - check we're ok & unmount it
1017 _notrun "requires a test device"
1020 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1022 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1026 if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
1028 _notrun "this test requires a valid \$TEST_DEV"
1030 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1032 _notrun "this test requires a valid \$TEST_DEV"
1034 if [ ! -d "$TEST_DIR" ]
1036 _notrun "this test requires a valid \$TEST_DIR"
1042 if _mount | grep -q $TEST_DEV
1044 # if it's mounted, make sure its on $TEST_DIR
1045 if ! _mount | grep $TEST_DEV | grep -q $TEST_DIR
1047 echo "\$TEST_DEV is mounted but not on \$TEST_DIR - aborting"
1051 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1052 if [ $? -ne 1 ]; then
1057 touch ${RESULT_DIR}/require_test
1060 # this test needs a logdev
1064 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1065 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1066 [ "$USE_EXTERNAL" != yes ] && \
1067 _notrun "This test requires USE_EXTERNAL to be enabled"
1069 # ensure its not mounted
1070 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1073 # this test requires loopback device support
1077 if [ "$HOSTOS" != "Linux" ]
1079 _notrun "This test requires linux for loopback device support"
1082 modprobe loop >/dev/null 2>&1
1083 if grep loop /proc/devices >/dev/null 2>&1
1087 _notrun "This test requires loopback device support"
1091 # this test requires ext2 filesystem support
1095 if [ "$HOSTOS" != "Linux" ]
1097 _notrun "This test requires linux for ext2 filesystem support"
1100 modprobe ext2 >/dev/null 2>&1
1101 if grep ext2 /proc/filesystems >/dev/null 2>&1
1105 _notrun "This test requires ext2 filesystem support"
1109 # this test requires that (large) loopback device files are not in use
1111 _require_no_large_scratch_dev()
1113 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1114 _notrun "Large filesystem testing in progress, skipped this test"
1117 # this test requires that a realtime subvolume is in use, and
1118 # that the kernel supports realtime as well.
1122 [ "$USE_EXTERNAL" = yes ] || \
1123 _notrun "External volumes not in use, skipped this test"
1124 [ "$SCRATCH_RTDEV" = "" ] && \
1125 _notrun "Realtime device required, skipped this test"
1128 # this test requires that a specified command (executable) exists
1129 # $1 - command, $2 - name for error message
1133 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1134 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1137 # this test requires the device mapper flakey target
1139 _require_dm_flakey()
1141 _require_command $DMSETUP_PROG
1143 modprobe dm-flakey >/dev/null 2>&1
1144 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1149 _notrun "This test requires dm flakey support"
1153 # this test requires the projid32bit feature to be available in mkfs.xfs.
1155 _require_projid32bit()
1157 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1158 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1161 _require_projid16bit()
1163 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1164 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1167 # this test requires the crc feature to be available in mkfs.xfs
1169 _require_xfs_mkfs_crc()
1171 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1172 || _notrun "mkfs.xfs doesn't have crc feature"
1175 # this test requires the xfs kernel support crc feature
1179 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1180 _scratch_mount >/dev/null 2>&1 \
1181 || _notrun "Kernel doesn't support crc feature"
1185 # this test requires the bigalloc feature to be available in mkfs.ext4
1187 _require_ext4_mkfs_bigalloc()
1189 _scratch_mkfs_ext4 -O bigalloc >/dev/null 2>&1 \
1190 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1193 # this test requires the ext4 kernel support bigalloc feature
1195 _require_ext4_bigalloc()
1197 _scratch_mkfs_ext4 -O bigalloc >/dev/null 2>&1
1198 _scratch_mount >/dev/null 2>&1 \
1199 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1203 # this test requires the finobt feature to be available in mkfs.xfs
1205 _require_xfs_mkfs_finobt()
1207 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1208 || _notrun "mkfs.xfs doesn't have finobt feature"
1211 # this test requires the xfs kernel support finobt feature
1213 _require_xfs_finobt()
1215 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1216 _scratch_mount >/dev/null 2>&1 \
1217 || _notrun "Kernel doesn't support finobt feature"
1221 # this test requires xfs sysfs attribute support
1223 _require_xfs_sysfs()
1226 sysfsdir=/sys/fs/xfs
1227 testdev=`_short_dev $TEST_DEV`
1229 if [ ! -e $sysfsdir ]; then
1230 _notrun "no kernel support for XFS sysfs attributes"
1233 if [ ! -z $1 ] && [ ! -e $sysfsdir/$testdev/$attr ]; then
1234 _notrun "sysfs attribute '$attr' is not supported"
1238 # this test requires that external log/realtime devices are not in use
1240 _require_nonexternal()
1242 [ "$USE_EXTERNAL" = yes ] && \
1243 _notrun "External device testing in progress, skipped this test"
1246 # this test requires that a (specified) aio-dio executable exists
1247 # $1 - command (optional)
1253 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1254 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1256 AIO_TEST=src/aio-dio-regress/$1
1257 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1261 # run an aio-dio program
1267 echo "usage: _run_aiodio command_name" 2>&1
1273 local testtemp=$TEST_DIR/aio-testfile
1275 $AIO_TEST $testtemp 2>&1
1282 # indicate whether YP/NIS is active or not
1287 dn=$(domainname 2>/dev/null)
1288 test -n "${dn}" -a "${dn}" != "(none)"
1292 # cat the password file
1296 [ $(_yp_active) -eq 0 ] && ypcat passwd
1300 # cat the group file
1304 [ $(_yp_active) -eq 0 ] && ypcat group
1308 # check for the fsgqa user on the machine
1313 _cat_passwd | grep -q $qa_user
1314 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1315 echo /bin/true | su $qa_user
1316 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1319 # check for the fsgqa group on the machine
1324 _cat_group | grep -q $qa_group
1325 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1331 s,.*Permission\sdenied.*,Permission denied,;
1332 s,.*no\saccess\sto\stty.*,,;
1333 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1340 if [ "$HOSTOS" == "IRIX" ]
1342 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1344 echo $1 | su $qa_user 2>&1 | _filter_user_do
1348 _require_xfs_io_command()
1352 echo "Usage: _require_xfs_io_command command" 1>&2
1357 testfile=$TEST_DIR/$$.xfs_io
1360 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1362 "fpunch" | "fcollapse" | "zero" | "fzero" )
1363 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1364 -c "$command 4k 8k" $testfile 2>&1`
1367 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1368 -c "fiemap -v" $testfile 2>&1`
1371 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1373 echo $testio | egrep -q "invalid option|Is a directory" && \
1374 _notrun "xfs_io $command support is missing"
1377 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1380 rm -f $testfile 2>&1 > /dev/null
1381 echo $testio | grep -q "not found" && \
1382 _notrun "xfs_io $command support is missing"
1383 echo $testio | grep -q "Operation not supported" && \
1384 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1387 # Check that a fs has enough free space (in 1024b blocks)
1392 BLOCKS=$2 # in units of 1024
1393 let GB=$BLOCKS/1024/1024
1395 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1396 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1397 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1401 # Check if the filesystem supports sparse files.
1403 # Unfortunately there is no better way to do this than a manual black list.
1405 _require_sparse_files()
1409 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1418 #boot_params always present in debugfs
1419 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1422 _require_fail_make_request()
1424 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1425 || _notrun "$DEBUGFS_MNT/fail_make_request \
1426 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1430 # Check if the file system supports seek_data/hole
1432 _require_seek_data_hole()
1434 testfile=$TEST_DIR/$$.seek
1435 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1436 rm -f $testfile &>/dev/null
1437 echo $testseek | grep -q "Kernel does not support" && \
1438 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1441 # check that a FS on a device is mounted
1442 # if so, return mount point
1448 echo "Usage: _is_mounted device" 1>&2
1454 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1455 pattern { print $3 ; exit 0 }
1459 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1464 # remount a FS to a new mode (ro or rw)
1470 echo "Usage: _remount device ro/rw" 1>&2
1476 if ! mount -o remount,$mode $device
1478 echo "_remount: failed to remount filesystem on $device as $mode"
1483 # Run the appropriate repair/check on a filesystem
1485 # if the filesystem is mounted, it's either remounted ro before being
1486 # checked or it's unmounted and then remounted
1489 # If set, we remount ro instead of unmounting for fsck
1492 _umount_or_remount_ro()
1496 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1501 mountpoint=`_is_mounted $device`
1503 if [ $USE_REMOUNT -eq 0 ]; then
1504 $UMOUNT_PROG $device
1511 _mount_or_remount_rw()
1515 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1522 if [ $USE_REMOUNT -eq 0 ]
1524 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1526 echo "!!! failed to remount $device on $mountpoint"
1536 # Check a generic filesystem in no-op mode; this assumes that the
1537 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1538 # and that it will still return an errno for corruption in this mode.
1540 # Filesystems which don't support this will need to define their
1541 # own check routine.
1543 _check_generic_filesystem()
1547 # If type is set, we're mounted
1548 type=`_fs_type $device`
1551 if [ "$type" = "$FSTYP" ]
1554 mountpoint=`_umount_or_remount_ro $device`
1557 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1560 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1562 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1563 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1564 cat $tmp.fsck >>$seqres.full
1565 echo "*** end fsck.$FSTYP output" >>$seqres.full
1573 echo "*** mount output ***" >>$seqres.full
1574 _mount >>$seqres.full
1575 echo "*** end mount output" >>$seqres.full
1576 elif [ "$type" = "$FSTYP" ]
1579 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1583 if [ $ok -eq 0 ]; then
1591 # run xfs_check and friends on a FS.
1593 _check_xfs_filesystem()
1597 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1601 extra_mount_options=""
1603 if [ "$2" != "none" ]; then
1604 extra_log_options="-l$2"
1605 extra_mount_options="-ologdev=$2"
1608 if [ "$3" != "none" ]; then
1609 extra_rt_options="-r$3"
1610 extra_mount_options=$extra_mount_options" -ortdev=$3"
1612 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1614 [ "$FSTYP" != xfs ] && return 0
1616 type=`_fs_type $device`
1619 if [ "$type" = "xfs" ]
1622 mountpoint=`_umount_or_remount_ro $device`
1625 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1626 | tee $tmp.logprint | grep -q "<CLEAN>"
1627 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1629 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1631 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1632 echo "*** xfs_logprint -t output ***" >>$seqres.full
1633 cat $tmp.logprint >>$seqres.full
1634 echo "*** end xfs_logprint output" >>$seqres.full
1639 # xfs_check runs out of memory on large files, so even providing the test
1640 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1641 # large filesystems. Avoid it.
1642 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1643 _xfs_check $extra_log_options $device 2>&1 |\
1644 _fix_malloc >$tmp.fs_check
1646 if [ -s $tmp.fs_check ]
1648 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1650 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1651 echo "*** xfs_check output ***" >>$seqres.full
1652 cat $tmp.fs_check >>$seqres.full
1653 echo "*** end xfs_check output" >>$seqres.full
1658 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1661 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1663 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1664 echo "*** xfs_repair -n output ***" >>$seqres.full
1665 cat $tmp.repair | _fix_malloc >>$seqres.full
1666 echo "*** end xfs_repair output" >>$seqres.full
1670 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1674 echo "*** mount output ***" >>$seqres.full
1675 _mount >>$seqres.full
1676 echo "*** end mount output" >>$seqres.full
1677 elif [ "$type" = "xfs" ]
1679 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1682 if [ $ok -eq 0 ]; then
1690 # Filter the knowen errors the UDF Verifier reports.
1691 _udf_test_known_error_filter()
1693 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."
1697 _check_udf_filesystem()
1699 [ "$DISABLE_UDF_TEST" == "1" ] && return
1701 if [ $# -ne 1 -a $# -ne 2 ]
1703 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1707 if [ ! -x $here/src/udf_test ]
1709 echo "udf_test not installed, please download and build the Philips"
1710 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1711 echo "Then copy the udf_test binary to $here/src/."
1712 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1720 LAST_BLOCK=`expr \( $2 - 1 \)`
1721 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1724 rm -f $seqres.checkfs
1725 sleep 1 # Due to a problem with time stamps in udf_test
1726 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1727 _udf_test_known_error_filter | \
1728 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1729 echo "Warning UDF Verifier reported errors see $seqres.checkfs."
1732 _check_xfs_test_fs()
1736 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1737 TEST_LOG="$TEST_LOGDEV"
1739 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1740 TEST_RT="$TEST_RTDEV"
1742 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1744 # check for ipath consistency
1745 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1746 # errors go to stderr
1747 xfs_check_ipaths $TEST_DIR >/dev/null
1748 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1752 _check_btrfs_filesystem()
1756 # If type is set, we're mounted
1757 type=`_fs_type $device`
1760 if [ "$type" = "$FSTYP" ]
1763 mountpoint=`_umount_or_remount_ro $device`
1766 btrfsck $device >$tmp.fsck 2>&1
1769 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1771 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1772 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1773 cat $tmp.fsck >>$seqres.full
1774 echo "*** end fsck.$FSTYP output" >>$seqres.full
1782 echo "*** mount output ***" >>$seqres.full
1783 _mount >>$seqres.full
1784 echo "*** end mount output" >>$seqres.full
1785 elif [ "$type" = "$FSTYP" ]
1788 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1792 if [ $ok -eq 0 ]; then
1807 # no way to check consistency for nfs
1810 # do nothing for now
1813 _check_btrfs_filesystem $TEST_DEV
1816 # no way to check consistency for tmpfs
1819 _check_generic_filesystem $TEST_DEV
1827 [ $# -eq 1 ] && device=$1
1833 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1834 SCRATCH_LOG="$SCRATCH_LOGDEV"
1836 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1837 SCRATCH_RT="$SCRATCH_RTDEV"
1839 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1842 _check_udf_filesystem $device $udf_fsize
1845 # Don't know how to check an NFS filesystem, yet.
1848 _check_btrfs_filesystem $device
1851 # no way to check consistency for tmpfs
1854 _check_generic_filesystem $device
1859 _full_fstyp_details()
1861 [ -z "$FSTYP" ] && FSTYP=xfs
1862 if [ $FSTYP = xfs ]; then
1863 if [ -d /proc/fs/xfs ]; then
1864 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1865 FSTYP="$FSTYP (non-debug)"
1866 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1867 FSTYP="$FSTYP (debug)"
1870 if uname -a | grep -qi 'debug'; then
1871 FSTYP="$FSTYP (debug)"
1873 FSTYP="$FSTYP (non-debug)"
1880 _full_platform_details()
1886 echo "$os/$platform $host $kernel"
1891 if [ -z "$1" -o -z "$2" ]; then
1892 echo Error must pass src and dst.
1896 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1898 elif [ "`uname`" == "Linux" ]; then
1901 echo Error test $seq does not run on the operating system: `uname`
1912 #takes files, randomdata
1920 if [ $size -gt 0 ]; then
1921 if [ "$2" == "false" ]; then
1922 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
1924 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
1931 # takes dirname, depth, randomdata
1934 dirname=$1; depth=$2; randomdata=$3
1935 mkdir $dirname || die "mkdir $dirname failed"
1938 _nfiles $files $randomdata # files for this dir and data type
1940 [ $depth -eq 0 ] && return
1941 let deep=$depth-1 # go 1 down
1943 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
1946 while [ $d -lt $dirs ]
1948 _descend d$d $deep &
1954 # Populate a filesystem with inodes for performance experiments
1956 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
1961 dirs=5 # ndirs in each subdir till leaves
1962 size=0 # sizeof files in K
1963 files=100 # num files in _each_ subdir
1964 depth=2 # depth of tree from root to leaves
1966 root=root # path of initial root of directory tree
1967 randomdata=false # -x data type urandom or zero
1970 while getopts "d:f:n:r:s:v:x" c
1979 x) randomdata=true;;
1983 _descend $root $depth $randomdata
1988 [ $verbose = true ] && echo done
1991 # query whether the given file has the given inode flag set
1998 if which $XFS_IO_PROG >/dev/null; then
1999 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2006 # query the given files extsize allocator hint in bytes (if any)
2013 if which $XFS_IO_PROG >/dev/null; then
2014 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2015 awk '/^xattr.extsize =/ { print $3 }'`
2017 [ -z "$blocks" ] && blocks="0"
2021 # scratch_dev_pool should contain the disks pool for the btrfs raid
2022 _require_scratch_dev_pool()
2027 if [ -z "$SCRATCH_DEV_POOL" ]; then
2028 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2031 if [ -z "$1" ]; then
2037 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2041 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2042 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2046 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2050 for i in $SCRATCH_DEV_POOL; do
2051 if [ "`_is_block_dev $i`" = "" ]; then
2052 _notrun "this test requires valid block disk $i"
2054 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
2055 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2057 if _mount | grep -q $i; then
2058 if ! $UMOUNT_PROG $i; then
2059 echo "failed to unmount $i - aborting"
2063 # to help better debug when something fails, we remove
2064 # traces of previous btrfs FS on the dev.
2065 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2069 # We will check if the device is deletable
2070 _require_deletable_scratch_dev_pool()
2074 for i in $SCRATCH_DEV_POOL; do
2075 x=`echo $i | cut -d"/" -f 3`
2076 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2077 _notrun "$i is a device which is not deletable"
2082 # We check for btrfs and (optionally) features of the btrfs command
2086 _require_command $BTRFS_UTIL_PROG btrfs
2087 if [ -z "$1" ]; then
2090 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2091 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2094 # Check that fio is present, and it is able to execute given jobfile
2099 _require_command $FIO_PROG
2100 if [ -z "$1" ]; then
2104 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2105 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2108 # Does freeze work on this fs?
2111 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2113 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2114 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2117 # arg 1 is dev to remove and is output of the below eg.
2118 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2124 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2126 stat $disk > /dev/null 2>&1
2127 while [ $? -eq 0 ]; do
2129 stat $disk > /dev/null 2>&1
2133 # arg 1 is dev to add and is output of the below eg.
2134 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2139 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2140 h=`echo ${1} | cut -d":" -f 1`
2141 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2143 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2145 # ensure the device comes online
2147 for i in `seq 1 10`; do
2148 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2149 dev=`ls /sys/class/scsi_device/${1}/device/block`
2150 for j in `seq 1 10`;
2152 stat /dev/$dev > /dev/null 2>&1
2153 if [ $? -eq 0 ]; then
2164 if [ $dev_back_oneline -eq 0 ]; then
2165 echo "/dev/$dev online failed" >> $seqres.full
2167 echo "/dev/$dev is back online" >> $seqres.full
2173 if [ -z "$FSTRIM_PROG" ]; then
2174 _notrun "This test requires fstrim utility."
2178 _test_batched_discard()
2180 if [ $# -ne 1 ]; then
2181 echo "Usage: _test_batched_discard mnt_point" 1>&2
2185 $FSTRIM_PROG ${1} &>/dev/null
2190 if [ -z "$DUMPE2FS_PROG" ]; then
2191 _notrun "This test requires dumpe2fs utility."
2197 if [ ! -e /proc/self/uid_map ]; then
2198 _notrun "This test requires procfs uid_map support."
2200 if [ ! -e /proc/self/gid_map ]; then
2201 _notrun "This test requires procfs gid_map support."
2205 _require_cp_reflink()
2207 cp --help | grep -q reflink || \
2208 _notrun "This test requires a cp with --reflink support."
2213 FSSUM_PROG=$here/src/fssum
2214 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2217 _require_btrfs_cloner()
2219 CLONER_PROG=$here/src/cloner
2220 [ -x $CLONER_PROG ] || \
2221 _notrun "cloner binary not present at $CLONER_PROG"
2224 # Given 2 files, verify that they have the same mapping but different
2225 # inodes - i.e. an undisturbed reflink
2226 # Silent if so, make noise if not
2229 # not a hard link or symlink?
2230 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2231 && echo "$1 and $2 are not reflinks: same inode number"
2234 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2235 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2236 || echo "$1 and $2 are not reflinks: different extents"
2241 _scratch_mkfs > /dev/null 2>&1
2242 _mount -t $FSTYP -o relatime $SCRATCH_DEV $SCRATCH_MNT || \
2243 _notrun "relatime not supported by the current kernel"
2249 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2250 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2253 _create_loop_device()
2256 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2260 _destroy_loop_device()
2263 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2266 _scale_fsstress_args()
2269 while [ $# -gt 0 ]; do
2271 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2272 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2273 *) args="$args $1" ;;
2281 # Return the logical block size if running on a block device,
2282 # else substitute the page size.
2284 _min_dio_alignment()
2288 if [ -b "$dev" ]; then
2289 blockdev --getss $dev
2291 $here/src/feature -s
2297 echo "# $@" >> $seqres.full 2>&1
2298 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2301 _run_btrfs_util_prog()
2303 run_check $BTRFS_UTIL_PROG $*
2306 _require_btrfs_send_stream_version()
2308 $BTRFS_UTIL_PROG send 2>&1 | \
2309 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2310 if [ $? -ne 0 ]; then
2311 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2315 _require_btrfs_mkfs_feature()
2318 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
2322 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
2323 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
2325 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
2328 _require_btrfs_fs_feature()
2331 echo "Missing feature name argument for _require_btrfs_fs_feature"
2335 modprobe btrfs > /dev/null 2>&1
2336 [ -e /sys/fs/btrfs/features/$feat ] || \
2337 _notrun "Feature $feat not supported by the available btrfs version"
2342 if [ -z "$1" ]; then
2343 echo "Usage: _get_total_inode <mnt>"
2347 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
2353 if [ -z "$1" ]; then
2354 echo "Usage: _get_used_inode <mnt>"
2358 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
2364 if [ -z "$1" ]; then
2365 echo "Usage: _get_free_inode <mnt>"
2369 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
2375 if [ "$iam" == new ]
2379 # make some further configuration checks here
2380 if [ "$TEST_DEV" = "" ]
2382 echo "common/rc: Error: \$TEST_DEV is not set"
2386 # if $TEST_DEV is not mounted, mount it now as XFS
2387 if [ -z "`_fs_type $TEST_DEV`" ]
2389 # $TEST_DEV is not mounted
2392 echo "common/rc: retrying test device mount with external set"
2393 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2396 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2402 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2404 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2408 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2409 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2410 export XFS_IO_PROG="$XFS_IO_PROG -F"
2413 # get real device path name by following link
2417 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
2418 _dev=`readlink -f "$_dev"`
2423 # basename of a device
2426 echo `basename $(_real_dev $1)`
2431 ################################################################################
2432 # make sure this script returns success