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'
86 # SELinux adds extra xattrs which can mess up our expected output.
87 # So, mount with a context, and they won't be created
88 # nfs_t is a "liberal" context so we can use it.
89 if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
90 SELINUX_MOUNT_OPTIONS="-o context=system_u:object_r:nfs_t:s0"
91 export SELINUX_MOUNT_OPTIONS
96 export MOUNT_OPTIONS=$XFS_MOUNT_OPTIONS
99 export MOUNT_OPTIONS=$UDF_MOUNT_OPTIONS
102 export MOUNT_OPTIONS=$NFS_MOUNT_OPTIONS
104 ext2|ext3|ext4|ext4dev)
105 # acls & xattrs aren't turned on by default on ext$FOO
106 export MOUNT_OPTIONS="-o acl,user_xattr $EXT_MOUNT_OPTIONS"
109 # acls & xattrs aren't turned on by default on reiserfs
110 export MOUNT_OPTIONS="-o acl,user_xattr $REISERFS_MOUNT_OPTIONS"
113 # acls aren't turned on by default on gfs2
114 export MOUNT_OPTIONS="-o acl $GFS2_MOUNT_OPTIONS"
117 # We need to specify the size at mount, use 512 MB by default
118 export MOUNT_OPTIONS="-o size=512M $TMPFS_MOUNT_OPTIONS"
129 export MKFS_OPTIONS=$XFS_MKFS_OPTIONS
132 [ ! -z "$udf_fsize" ] && \
133 UDF_MKFS_OPTIONS="$UDF_MKFS_OPTIONS -s $udf_fsize"
134 export MKFS_OPTIONS=$UDF_MKFS_OPTIONS
137 export MKFS_OPTIONS=$NFS_MKFS_OPTIONS
140 export MKFS_OPTIONS="$REISERFS_MKFS_OPTIONS -q"
143 export MKFS_OPTIONS="$GFS2_MKFS_OPTIONS -O -p lock_nolock"
146 export MKFS_OPTIONS="$JFS_MKFS_OPTIONS -q"
149 export MKFS_OPTIONS="$TMPFS_MKFS_OPTIONS"
159 ext2|ext3|ext4|ext4dev)
160 export FSCK_OPTIONS="-nf"
163 export FSCK_OPTIONS="--yes"
166 export FSCK_OPTIONS="-n"
171 # we need common/config
172 if [ "$iam" != "check" ]
174 if ! . ./common/config
176 echo "$iam: failed to source common/config"
181 # check for correct setup
184 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
185 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
186 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
187 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
190 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
193 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
199 # make sure we have a standard umask
204 $MOUNT_PROG `_mount_ops_filter $*`
212 if [ "$FSTYP" != "xfs" ]; then
218 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
227 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
228 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
229 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
230 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
238 if [ "$FSTYP" != "xfs" ]; then
252 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
253 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
254 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
255 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
262 #get mount point to handle dmapi mtpt option correctly
264 [ $last_index -gt 0 ] && shift $last_index
267 # irix is fussy about how it is fed its mount options
268 # - multiple -o's are not allowed
269 # - no spaces between comma delimitered options
270 # the sed script replaces all -o's (except the first) with a comma
271 # not required for linux, but won't hurt
273 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
274 | sed -e 's/dmapi/dmi/' \
275 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
279 _scratch_mount_options()
281 _scratch_options mount
283 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
288 _mount -t $FSTYP `_scratch_mount_options $*`
293 $UMOUNT_PROG $SCRATCH_DEV
305 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
308 _scratch_mkfs_options()
310 _scratch_options mkfs
311 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
319 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
320 options="-l $SCRATCH_LOGDEV"
322 xfs_metadump $options $SCRATCH_DEV $dumpfile
325 _setup_large_xfs_fs()
330 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
331 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
332 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
334 # calculate the size of the file we need to allocate.
335 # Default free space in the FS is 50GB, but you can specify more via
336 # SCRATCH_DEV_EMPTY_SPACE
337 file_size=$(($fs_size - 50*1024*1024*1024))
338 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
340 # mount the filesystem, create the file, unmount it
341 _scratch_mount 2>&1 >$tmp_dir/mnt.err
343 if [ $status -ne 0 ]; then
345 cat $tmp_dir/mnt.err >&2
346 rm -f $tmp_dir/mnt.err
349 rm -f $tmp_dir/mnt.err
352 -c "truncate $file_size" \
353 -c "falloc -k 0 $file_size" \
355 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
356 export NUM_SPACE_FILES=1
359 if [ $status -ne 0 ]; then
360 echo "large file prealloc failed"
361 cat $tmp_dir/mnt.err >&2
367 _scratch_mkfs_xfs_opts()
371 _scratch_options mkfs
373 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
377 _scratch_mkfs_xfs_supported()
381 _scratch_options mkfs
383 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
388 # extra mkfs options can be added by tests
389 local extra_mkfs_options=$*
393 # save mkfs output in case conflict means we need to run again.
394 # only the output for the mkfs that applies should be shown
395 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
396 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
400 # a mkfs failure may be caused by conflicts between
401 # $MKFS_OPTIONS and $extra_mkfs_options
402 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
404 echo -n "** mkfs failed with extra mkfs options "
405 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
406 echo -n "** attempting to mkfs using only test $seq "
407 echo "options: $extra_mkfs_options **"
410 # running mkfs again. overwrite previous mkfs output files
411 _scratch_mkfs_xfs_opts $extra_mkfs_options \
412 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
416 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
417 # manually parse the mkfs output to get the fs size in bytes
419 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
420 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
422 print STDOUT "$size\n";
424 _setup_large_xfs_fs $fs_size
428 # output stored mkfs output
429 cat $tmp_dir.mkfserr >&2
431 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
436 # xfs_check script is planned to be deprecated. But, we want to
437 # be able to invoke "xfs_check" behavior in xfstests in order to
438 # maintain the current verification levels.
443 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
445 while getopts "b:fi:l:stvV" c
451 i) OPTS=$OPTS"-i "$OPTARG" ";;
452 b) OPTS=$OPTS"-b "$OPTARG" ";;
453 f) DBOPTS=$DBOPTS" -f";;
454 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
455 V) $XFS_DB_PROG -p xfs_check -V
463 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
473 _setup_large_ext4_fs()
478 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
479 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
480 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
482 # Default free space in the FS is 50GB, but you can specify more via
483 # SCRATCH_DEV_EMPTY_SPACE
484 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
486 # mount the filesystem and create 16TB - 4KB files until we consume
487 # all the necessary space.
488 _scratch_mount 2>&1 >$tmp_dir/mnt.err
490 if [ $status -ne 0 ]; then
492 cat $tmp_dir/mnt.err >&2
493 rm -f $tmp_dir/mnt.err
496 rm -f $tmp_dir/mnt.err
498 file_size=$((16*1024*1024*1024*1024 - 4096))
500 while [ $space_to_consume -gt $file_size ]; do
503 -c "truncate $file_size" \
504 -c "falloc -k 0 $file_size" \
505 $SCRATCH_MNT/.use_space.$nfiles 2>&1
507 if [ $status -ne 0 ]; then
511 space_to_consume=$(( $space_to_consume - $file_size ))
512 nfiles=$(($nfiles + 1))
515 # consume the remaining space.
516 if [ $space_to_consume -gt 0 ]; then
518 -c "truncate $space_to_consume" \
519 -c "falloc -k 0 $space_to_consume" \
520 $SCRATCH_MNT/.use_space.$nfiles 2>&1
523 export NUM_SPACE_FILES=$nfiles
526 if [ $status -ne 0 ]; then
527 echo "large file prealloc failed"
528 cat $tmp_dir/mnt.err >&2
538 /sbin/mkfs -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV \
539 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
542 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
543 # manually parse the mkfs output to get the fs size in bytes
544 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
545 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
546 / inodes, / { blks = $3 } \
547 /reserved for the super user/ { resv = $1 } \
548 END { fssize = bs * blks - resv; print fssize }'`
550 _setup_large_ext4_fs $fs_size
554 # output stored mkfs output
555 cat $tmp_dir.mkfserr >&2
557 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
569 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
572 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
575 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
590 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
593 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
596 _scratch_mkfs_ext4 $*
599 # do nothing for tmpfs
602 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
611 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
614 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
619 # Create fs of certain size on scratch device
620 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
621 _scratch_mkfs_sized()
625 [ -z "$blocksize" ] && blocksize=4096
628 if ! [[ $fssize =~ $re ]] ; then
629 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
631 if ! [[ $blocksize =~ $re ]] ; then
632 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
635 blocks=`expr $fssize / $blocksize`
637 if [ "$HOSTOS" == "Linux" ]; then
638 devsize=`blockdev --getsize64 $SCRATCH_DEV`
639 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
644 # don't override MKFS_OPTIONS that set a block size.
645 echo $MKFS_OPTIONS |egrep -q "b?size="
646 if [ $? -eq 0 ]; then
647 _scratch_mkfs_xfs -d size=$fssize
649 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
652 ext2|ext3|ext4|ext4dev)
653 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
656 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
659 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
662 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
667 # Emulate an N-data-disk stripe w/ various stripe units
668 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
674 [ -z "$blocksize" ] && blocksize=4096
676 let sunit_blocks=$sunit_bytes/$blocksize
677 let swidth_blocks=$sunit_blocks*$swidth_mult
681 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
684 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
687 _notrun "can't mkfs $FSTYP with geometry"
697 xfs_io -x -c "resblks $1" $SCRATCH_MNT
704 _scratch_xfs_db_options()
707 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
708 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
709 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
712 _scratch_xfs_logprint()
715 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
716 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
717 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
723 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
724 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
725 [ "$LARGE_SCRATCH_DEV" = yes ] && \
726 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
727 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
730 _scratch_xfs_repair()
733 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
734 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
735 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
736 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
737 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
738 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
745 echo "Usage: _get_pids_by_name process-name" 1>&2
749 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
750 # HH:MM:SS before the psargs field, use this as the search anchor.
752 # Matches with $1 (process-name) occur if the first psarg is $1
753 # or ends in /$1 ... the matching uses sed's regular expressions,
754 # so passing a regex into $1 will work.
762 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
763 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
766 # fix malloc libs output
770 # filter out the Electric Fence notice
773 if (defined $o && /^\s+Electric Fence/) {
779 print $o if (defined $o);
783 print $o if (defined $o);
787 # check if run as root
791 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
794 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
801 # _df_device : get an IRIX style df line for a given device
803 # - returns "" if not mounted
804 # - returns fs type in field two (ala IRIX)
805 # - joins line together if split by fancy df formatting
806 # - strips header etc
813 echo "Usage: _df_device device" 1>&2
817 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
818 match($1,what) && NF==1 {
832 # _df_dir : get an IRIX style df line for device where a directory resides
834 # - returns fs type in field two (ala IRIX)
835 # - joins line together if split by fancy df formatting
836 # - strips header etc
843 echo "Usage: _df_dir device" 1>&2
847 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
863 # return percentage used disk space for mounted device
869 echo "Usage: _used device" 1>&2
873 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
876 # return the FS type of a mounted device
882 echo "Usage: _fs_type device" 1>&2
887 # The Linux kernel shows NFSv4 filesystems in df output as
888 # filesystem type nfs4, although we mounted it as nfs earlier.
889 # Fix the filesystem type up here so that the callers don't
890 # have to bother with this quirk.
892 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
895 # return the FS mount options of a mounted device
897 # should write a version which just parses the output of mount for IRIX
898 # compatibility, but since this isn't used at all, at the moment I'll leave
905 echo "Usage: _fs_options device" 1>&2
909 $AWK_PROG -v dev=$1 '
910 match($1,dev) { print $4 }
914 # returns device number if a file is a block device
920 echo "Usage: _is_block_dev dev" 1>&2
925 if [ -L "${_dev}" ]; then
926 _dev=`readlink -f ${_dev}`
929 if [ -b "${_dev}" ]; then
930 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
934 # Do a command, log it to $seqres.full, optionally test return status
935 # and die if command fails. If called with one argument _do executes the
936 # command, logs it, and returns its exit status. With two arguments _do
937 # first prints the message passed in the first argument, and then "done"
938 # or "fail" depending on the return status of the command passed in the
939 # second argument. If the command fails and the variable _do_die_on_error
940 # is set to "always" or the two argument form is used and _do_die_on_error
941 # is set to "message_only" _do will print an error message to
942 # $seqres.out and exit.
946 if [ $# -eq 1 ]; then
948 elif [ $# -eq 2 ]; then
953 echo "Usage: _do [note] cmd" 1>&2
957 (eval "echo '---' \"$_cmd\"") >>$seqres.full
958 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
959 cat $tmp._out | _fix_malloc >>$seqres.full
960 if [ $# -eq 2 ]; then
961 if [ $ret -eq 0 ]; then
968 && [ "$_do_die_on_error" = "always" \
969 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
972 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
979 # bail out, setting up .notrun file
983 echo "$*" > $seqres.notrun
984 echo "$seq not run: $*"
989 # just plain bail out
993 echo "$*" | tee -a $seqres.full
994 echo "(see $seqres.full for details)"
999 # tests whether $FSTYP is one of the supported filesystems for a test
1005 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1011 _notrun "not suitable for this filesystem type: $FSTYP"
1015 # tests whether $FSTYP is one of the supported OSes for a test
1021 if [ "$h" = "$HOSTOS" ]
1027 _notrun "not suitable for this OS: $HOSTOS"
1030 # this test needs a scratch partition - check we're ok & unmount it
1036 _notrun "requires a scratch device"
1039 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1041 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1045 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
1047 _notrun "this test requires a valid \$SCRATCH_DEV"
1049 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1051 _notrun "this test requires a valid \$SCRATCH_DEV"
1053 if [ ! -d "$SCRATCH_MNT" ]
1055 _notrun "this test requires a valid \$SCRATCH_MNT"
1061 if _mount | grep -q $SCRATCH_DEV
1063 # if it's mounted, make sure its on $SCRATCH_MNT
1064 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1066 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1069 # and then unmount it
1070 if ! $UMOUNT_PROG $SCRATCH_DEV
1072 echo "failed to unmount $SCRATCH_DEV"
1078 # this test needs a logdev
1082 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1083 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1084 [ "$USE_EXTERNAL" != yes ] && \
1085 _notrun "This test requires USE_EXTERNAL to be enabled"
1087 # ensure its not mounted
1088 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1091 # this test requires loopback device support
1095 if [ "$HOSTOS" != "Linux" ]
1097 _notrun "This test requires linux for loopback device support"
1100 modprobe loop >/dev/null 2>&1
1101 if grep loop /proc/devices >/dev/null 2>&1
1105 _notrun "This test requires loopback device support"
1109 # this test requires ext2 filesystem support
1113 if [ "$HOSTOS" != "Linux" ]
1115 _notrun "This test requires linux for ext2 filesystem support"
1118 modprobe ext2 >/dev/null 2>&1
1119 if grep ext2 /proc/filesystems >/dev/null 2>&1
1123 _notrun "This test requires ext2 filesystem support"
1127 # this test requires that (large) loopback device files are not in use
1129 _require_no_large_scratch_dev()
1131 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1132 _notrun "Large filesystem testing in progress, skipped this test"
1135 # this test requires that a realtime subvolume is in use, and
1136 # that the kernel supports realtime as well.
1140 [ "$USE_EXTERNAL" = yes ] || \
1141 _notrun "External volumes not in use, skipped this test"
1142 [ "$SCRATCH_RTDEV" = "" ] && \
1143 _notrun "Realtime device required, skipped this test"
1146 # this test requires that a specified command (executable) exists
1147 # $1 - command, $2 - name for error message
1151 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1152 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1155 # this test requires the device mapper flakey target
1157 _require_dm_flakey()
1159 _require_command $DMSETUP_PROG
1161 modprobe dm-flakey >/dev/null 2>&1
1162 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1167 _notrun "This test requires dm flakey support"
1171 # this test requires the projid32bit feature to be available in mkfs.xfs.
1173 _require_projid32bit()
1175 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1176 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1179 _require_projid16bit()
1181 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1182 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1185 # this test requires the crc feature to be available in mkfs.xfs
1187 _require_xfs_mkfs_crc()
1189 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1190 || _notrun "mkfs.xfs doesn't have crc feature"
1193 # this test requires the xfs kernel support crc feature
1197 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1198 _scratch_mount >/dev/null 2>&1 \
1199 || _notrun "Kernel doesn't support crc feature"
1203 # this test requires that external log/realtime devices are not in use
1205 _require_nonexternal()
1207 [ "$USE_EXTERNAL" = yes ] && \
1208 _notrun "External device testing in progress, skipped this test"
1211 # this test requires that a (specified) aio-dio executable exists
1212 # $1 - command (optional)
1218 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1219 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1221 AIO_TEST=src/aio-dio-regress/$1
1222 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1226 # run an aio-dio program
1232 echo "usage: _run_aiodio command_name" 2>&1
1238 local testtemp=$TEST_DIR/aio-testfile
1240 $AIO_TEST $testtemp 2>&1
1247 # indicate whether YP/NIS is active or not
1252 dn=$(domainname 2>/dev/null)
1253 test -n "${dn}" -a "${dn}" != "(none)"
1257 # cat the password file
1261 [ $(_yp_active) -eq 0 ] && ypcat passwd
1265 # cat the group file
1269 [ $(_yp_active) -eq 0 ] && ypcat group
1273 # check for the fsgqa user on the machine
1278 _cat_passwd | grep -q $qa_user
1279 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1280 echo /bin/true | su $qa_user
1281 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1284 # check for the fsgqa group on the machine
1289 _cat_group | grep -q $qa_group
1290 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1296 s,.*Permission\sdenied.*,Permission denied,;
1297 s,.*no\saccess\sto\stty.*,,;
1298 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1305 if [ "$HOSTOS" == "IRIX" ]
1307 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1309 echo $1 | su $qa_user 2>&1 | _filter_user_do
1313 _require_xfs_io_command()
1317 echo "Usage: _require_xfs_io_command command" 1>&2
1322 testfile=$TEST_DIR/$$.xfs_io
1325 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1327 "fpunch" | "fcollapse" | "zero" | "fzero" )
1328 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1329 -c "$command 4k 8k" $testfile 2>&1`
1332 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1333 -c "fiemap -v" $testfile 2>&1`
1336 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1340 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1343 rm -f $testfile 2>&1 > /dev/null
1344 echo $testio | grep -q "not found" && \
1345 _notrun "xfs_io $command support is missing"
1346 echo $testio | grep -q "Operation not supported" && \
1347 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1350 # check that xfs_io, kernel, and filesystem all support zero
1351 _require_xfs_io_zero()
1353 _require_xfs_io_command "zero"
1356 # check that xfs_io, glibc, kernel, and filesystem all (!) support
1359 _require_xfs_io_falloc()
1361 _require_xfs_io_command "falloc"
1364 # check that xfs_io, kernel and filesystem all support fallocate with hole
1366 _require_xfs_io_falloc_punch()
1368 _require_xfs_io_command "fpunch"
1371 # check that xfs_io, kernel and filesystem all support fallocate with collapse
1373 _require_xfs_io_falloc_collapse()
1375 _require_xfs_io_command "fcollapse"
1378 # check that xfs_io, kernel and filesystem support fiemap
1379 _require_xfs_io_fiemap()
1381 _require_xfs_io_command "fiemap"
1384 # Check that a fs has enough free space (in 1024b blocks)
1389 BLOCKS=$2 # in units of 1024
1390 let GB=$BLOCKS/1024/1024
1392 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1393 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1394 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1398 # Check if the filesystem supports sparse files.
1400 # Unfortunately there is no better way to do this than a manual black list.
1402 _require_sparse_files()
1406 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1415 #boot_params always present in debugfs
1416 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1419 _require_fail_make_request()
1421 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1422 || _notrun "$DEBUGFS_MNT/fail_make_request \
1423 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1427 # Check if the file system supports seek_data/hole
1429 _require_seek_data_hole()
1431 testfile=$TEST_DIR/$$.seek
1432 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1433 rm -f $testfile &>/dev/null
1434 echo $testseek | grep -q "Kernel does not support" && \
1435 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1438 # check that a FS on a device is mounted
1439 # if so, return mount point
1445 echo "Usage: _is_mounted device" 1>&2
1451 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1452 pattern { print $3 ; exit 0 }
1456 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1461 # remount a FS to a new mode (ro or rw)
1467 echo "Usage: _remount device ro/rw" 1>&2
1473 if ! mount -o remount,$mode $device
1475 echo "_remount: failed to remount filesystem on $device as $mode"
1480 # Run the appropriate repair/check on a filesystem
1482 # if the filesystem is mounted, it's either remounted ro before being
1483 # checked or it's unmounted and then remounted
1486 # If set, we remount ro instead of unmounting for fsck
1489 _umount_or_remount_ro()
1493 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1498 mountpoint=`_is_mounted $device`
1500 if [ $USE_REMOUNT -eq 0 ]; then
1501 $UMOUNT_PROG $device
1508 _mount_or_remount_rw()
1512 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1519 if [ $USE_REMOUNT -eq 0 ]
1521 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1523 echo "!!! failed to remount $device on $mountpoint"
1533 # Check a generic filesystem in no-op mode; this assumes that the
1534 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1535 # and that it will still return an errno for corruption in this mode.
1537 # Filesystems which don't support this will need to define their
1538 # own check routine.
1540 _check_generic_filesystem()
1544 # If type is set, we're mounted
1545 type=`_fs_type $device`
1548 if [ "$type" = "$FSTYP" ]
1551 mountpoint=`_umount_or_remount_ro $device`
1554 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1557 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1559 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1560 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1561 cat $tmp.fsck >>$seqres.full
1562 echo "*** end fsck.$FSTYP output" >>$seqres.full
1570 echo "*** mount output ***" >>$seqres.full
1571 _mount >>$seqres.full
1572 echo "*** end mount output" >>$seqres.full
1573 elif [ "$type" = "$FSTYP" ]
1576 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1580 if [ $ok -eq 0 ]; then
1588 # run xfs_check and friends on a FS.
1590 _check_xfs_filesystem()
1594 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1598 extra_mount_options=""
1600 if [ "$2" != "none" ]; then
1601 extra_log_options="-l$2"
1602 extra_mount_options="-ologdev=$2"
1605 if [ "$3" != "none" ]; then
1606 extra_rt_options="-r$3"
1607 extra_mount_options=$extra_mount_options" -ortdev=$3"
1609 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1611 [ "$FSTYP" != xfs ] && return 0
1613 type=`_fs_type $device`
1616 if [ "$type" = "xfs" ]
1619 mountpoint=`_umount_or_remount_ro $device`
1622 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1623 | tee $tmp.logprint | grep -q "<CLEAN>"
1624 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1626 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1628 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1629 echo "*** xfs_logprint -t output ***" >>$seqres.full
1630 cat $tmp.logprint >>$seqres.full
1631 echo "*** end xfs_logprint output" >>$seqres.full
1636 # xfs_check runs out of memory on large files, so even providing the test
1637 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1638 # large filesystems. Avoid it.
1639 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1640 _xfs_check $extra_log_options $device 2>&1 |\
1641 _fix_malloc >$tmp.fs_check
1643 if [ -s $tmp.fs_check ]
1645 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1647 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1648 echo "*** xfs_check output ***" >>$seqres.full
1649 cat $tmp.fs_check >>$seqres.full
1650 echo "*** end xfs_check output" >>$seqres.full
1655 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1658 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1660 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1661 echo "*** xfs_repair -n output ***" >>$seqres.full
1662 cat $tmp.repair | _fix_malloc >>$seqres.full
1663 echo "*** end xfs_repair output" >>$seqres.full
1667 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1671 echo "*** mount output ***" >>$seqres.full
1672 _mount >>$seqres.full
1673 echo "*** end mount output" >>$seqres.full
1674 elif [ "$type" = "xfs" ]
1676 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1679 if [ $ok -eq 0 ]; then
1687 # Filter the knowen errors the UDF Verifier reports.
1688 _udf_test_known_error_filter()
1690 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."
1694 _check_udf_filesystem()
1696 [ "$DISABLE_UDF_TEST" == "1" ] && return
1698 if [ $# -ne 1 -a $# -ne 2 ]
1700 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1704 if [ ! -x $here/src/udf_test ]
1706 echo "udf_test not installed, please download and build the Philips"
1707 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1708 echo "Then copy the udf_test binary to $here/src/."
1709 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1717 LAST_BLOCK=`expr \( $2 - 1 \)`
1718 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1721 rm -f $seqres.checkfs
1722 sleep 1 # Due to a problem with time stamps in udf_test
1723 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1724 _udf_test_known_error_filter | \
1725 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1726 echo "Warning UDF Verifier reported errors see $seqres.checkfs."
1729 _check_xfs_test_fs()
1733 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1734 TEST_LOG="$TEST_LOGDEV"
1736 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1737 TEST_RT="$TEST_RTDEV"
1739 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1741 # check for ipath consistency
1742 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1743 # errors go to stderr
1744 xfs_check_ipaths $TEST_DIR >/dev/null
1745 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1749 _check_btrfs_filesystem()
1753 # If type is set, we're mounted
1754 type=`_fs_type $device`
1757 if [ "$type" = "$FSTYP" ]
1760 mountpoint=`_umount_or_remount_ro $device`
1763 btrfsck $device >$tmp.fsck 2>&1
1766 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1768 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1769 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1770 cat $tmp.fsck >>$seqres.full
1771 echo "*** end fsck.$FSTYP output" >>$seqres.full
1779 echo "*** mount output ***" >>$seqres.full
1780 _mount >>$seqres.full
1781 echo "*** end mount output" >>$seqres.full
1782 elif [ "$type" = "$FSTYP" ]
1785 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1789 if [ $ok -eq 0 ]; then
1804 # no way to check consistency for nfs
1807 # do nothing for now
1810 _check_btrfs_filesystem $TEST_DEV
1813 # no way to check consistency for tmpfs
1816 _check_generic_filesystem $TEST_DEV
1824 [ $# -eq 1 ] && device=$1
1830 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1831 SCRATCH_LOG="$SCRATCH_LOGDEV"
1833 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1834 SCRATCH_RT="$SCRATCH_RTDEV"
1836 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1839 _check_udf_filesystem $device $udf_fsize
1842 # Don't know how to check an NFS filesystem, yet.
1845 _check_btrfs_filesystem $device
1848 # no way to check consistency for tmpfs
1851 _check_generic_filesystem $device
1856 _full_fstyp_details()
1858 [ -z "$FSTYP" ] && FSTYP=xfs
1859 if [ $FSTYP = xfs ]; then
1860 if [ -d /proc/fs/xfs ]; then
1861 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1862 FSTYP="$FSTYP (non-debug)"
1863 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1864 FSTYP="$FSTYP (debug)"
1867 if uname -a | grep -qi 'debug'; then
1868 FSTYP="$FSTYP (debug)"
1870 FSTYP="$FSTYP (non-debug)"
1877 _full_platform_details()
1883 echo "$os/$platform $host $kernel"
1888 if [ -z "$1" -o -z "$2" ]; then
1889 echo Error must pass src and dst.
1893 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1895 elif [ "`uname`" == "Linux" ]; then
1898 echo Error test $seq does not run on the operating system: `uname`
1909 #takes files, randomdata
1917 if [ $size -gt 0 ]; then
1918 if [ "$2" == "false" ]; then
1919 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
1921 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
1928 # takes dirname, depth, randomdata
1931 dirname=$1; depth=$2; randomdata=$3
1932 mkdir $dirname || die "mkdir $dirname failed"
1935 _nfiles $files $randomdata # files for this dir and data type
1937 [ $depth -eq 0 ] && return
1938 let deep=$depth-1 # go 1 down
1940 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
1943 while [ $d -lt $dirs ]
1945 _descend d$d $deep &
1951 # Populate a filesystem with inodes for performance experiments
1953 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
1958 dirs=5 # ndirs in each subdir till leaves
1959 size=0 # sizeof files in K
1960 files=100 # num files in _each_ subdir
1961 depth=2 # depth of tree from root to leaves
1963 root=root # path of initial root of directory tree
1964 randomdata=false # -x data type urandom or zero
1967 while getopts "d:f:n:r:s:v:x" c
1976 x) randomdata=true;;
1980 _descend $root $depth $randomdata
1985 [ $verbose = true ] && echo done
1988 # query whether the given file has the given inode flag set
1995 if which $XFS_IO_PROG >/dev/null; then
1996 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2003 # query the given files extsize allocator hint in bytes (if any)
2010 if which $XFS_IO_PROG >/dev/null; then
2011 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2012 awk '/^xattr.extsize =/ { print $3 }'`
2014 [ -z "$blocks" ] && blocks="0"
2018 # scratch_dev_pool should contain the disks pool for the btrfs raid
2019 _require_scratch_dev_pool()
2024 if [ -z "$SCRATCH_DEV_POOL" ]; then
2025 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2028 if [ -z "$1" ]; then
2034 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2038 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2039 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2043 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2047 for i in $SCRATCH_DEV_POOL; do
2048 if [ "`_is_block_dev $i`" = "" ]; then
2049 _notrun "this test requires valid block disk $i"
2051 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
2052 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2054 if _mount | grep -q $i; then
2055 if ! $UMOUNT_PROG $i; then
2056 echo "failed to unmount $i - aborting"
2060 # to help better debug when something fails, we remove
2061 # traces of previous btrfs FS on the dev.
2062 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2066 # We will check if the device is deletable
2067 _require_deletable_scratch_dev_pool()
2071 for i in $SCRATCH_DEV_POOL; do
2072 x=`echo $i | cut -d"/" -f 3`
2073 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2074 _notrun "$i is a device which is not deletable"
2079 # We check for btrfs and (optionally) features of the btrfs command
2083 _require_command $BTRFS_UTIL_PROG btrfs
2084 if [ -z "$1" ]; then
2087 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2088 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2091 # Check that fio is present, and it is able to execute given jobfile
2096 _require_command $FIO_PROG
2097 if [ -z "$1" ]; then
2101 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2102 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2105 # Does freeze work on this fs?
2108 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2110 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2111 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2114 # arg 1 is dev to remove and is output of the below eg.
2115 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2121 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2123 stat $disk > /dev/null 2>&1
2124 while [ $? -eq 0 ]; do
2126 stat $disk > /dev/null 2>&1
2130 # arg 1 is dev to add and is output of the below eg.
2131 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2136 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2137 h=`echo ${1} | cut -d":" -f 1`
2138 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2140 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2145 if [ -z "$FSTRIM_PROG" ]; then
2146 _notrun "This test requires fstrim utility."
2150 _test_batched_discard()
2152 if [ $# -ne 1 ]; then
2153 echo "Usage: _test_batched_discard mnt_point" 1>&2
2157 $FSTRIM_PROG ${1} &>/dev/null
2162 if [ -z "$DUMPE2FS_PROG" ]; then
2163 _notrun "This test requires dumpe2fs utility."
2169 if [ ! -e /proc/self/uid_map ]; then
2170 _notrun "This test requires procfs uid_map support."
2172 if [ ! -e /proc/self/gid_map ]; then
2173 _notrun "This test requires procfs gid_map support."
2177 _require_cp_reflink()
2179 cp --help | grep -q reflink || \
2180 _notrun "This test requires a cp with --reflink support."
2185 FSSUM_PROG=$here/src/fssum
2186 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2189 # Given 2 files, verify that they have the same mapping but different
2190 # inodes - i.e. an undisturbed reflink
2191 # Silent if so, make noise if not
2194 # not a hard link or symlink?
2195 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2196 && echo "$1 and $2 are not reflinks: same inode number"
2199 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2200 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2201 || echo "$1 and $2 are not reflinks: different extents"
2206 _scratch_mkfs > /dev/null 2>&1
2207 _mount -t $FSTYP -o relatime $SCRATCH_DEV $SCRATCH_MNT || \
2208 _notrun "relatime not supported by the current kernel"
2212 _create_loop_device()
2215 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2219 _destroy_loop_device()
2222 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2225 _scale_fsstress_args()
2228 while [ $# -gt 0 ]; do
2230 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2231 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2232 *) args="$args $1" ;;
2240 # Return the logical block size if running on a block device,
2241 # else substitute the page size.
2243 _min_dio_alignment()
2247 if [ -b "$dev" ]; then
2248 blockdev --getss $dev
2250 $here/src/feature -s
2256 echo "# $@" >> $seqres.full 2>&1
2257 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2260 _run_btrfs_util_prog()
2262 run_check $BTRFS_UTIL_PROG $*
2265 _require_btrfs_send_stream_version()
2267 $BTRFS_UTIL_PROG send 2>&1 | \
2268 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2269 if [ $? -ne 0 ]; then
2270 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2276 if [ "$iam" == new ]
2280 # make some further configuration checks here
2281 if [ "$TEST_DEV" = "" ]
2283 echo "common/rc: Error: \$TEST_DEV is not set"
2287 # if $TEST_DEV is not mounted, mount it now as XFS
2288 if [ -z "`_fs_type $TEST_DEV`" ]
2290 # $TEST_DEV is not mounted
2293 echo "common/rc: retrying test device mount with external set"
2294 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2297 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2303 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2305 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2309 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2310 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2311 export XFS_IO_PROG="$XFS_IO_PROG -F"
2316 ################################################################################
2317 # make sure this script returns success