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 [ -z "$FSTYP" ] && FSTYP=xfs
172 [ -z "$MOUNT_OPTIONS" ] && _mount_opts
173 [ -z "$MKFS_OPTIONS" ] && _mkfs_opts
174 [ -z "$FSCK_OPTIONS" ] && _fsck_opts
177 # we need common/config
178 if [ "$iam" != "check" ]
180 if ! . ./common/config
182 echo "$iam: failed to source common/config"
187 # check for correct setup
190 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
191 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
192 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
193 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
196 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
199 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
205 # make sure we have a standard umask
210 $MOUNT_PROG `_mount_ops_filter $*`
218 if [ "$FSTYP" != "xfs" ]; then
224 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
233 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
234 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
235 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
236 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
244 if [ "$FSTYP" != "xfs" ]; then
258 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
259 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
260 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
261 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
268 #get mount point to handle dmapi mtpt option correctly
270 [ $last_index -gt 0 ] && shift $last_index
273 # irix is fussy about how it is fed its mount options
274 # - multiple -o's are not allowed
275 # - no spaces between comma delimitered options
276 # the sed script replaces all -o's (except the first) with a comma
277 # not required for linux, but won't hurt
279 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
280 | sed -e 's/dmapi/dmi/' \
281 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
285 _scratch_mount_options()
287 _scratch_options mount
289 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
294 _mount -t $FSTYP `_scratch_mount_options $*`
299 $UMOUNT_PROG $SCRATCH_DEV
311 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
314 _scratch_mkfs_options()
316 _scratch_options mkfs
317 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
325 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
326 options="-l $SCRATCH_LOGDEV"
328 xfs_metadump $options $SCRATCH_DEV $dumpfile
331 _setup_large_xfs_fs()
336 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
337 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
338 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
340 # calculate the size of the file we need to allocate.
341 # Default free space in the FS is 50GB, but you can specify more via
342 # SCRATCH_DEV_EMPTY_SPACE
343 file_size=$(($fs_size - 50*1024*1024*1024))
344 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
346 # mount the filesystem, create the file, unmount it
347 _scratch_mount 2>&1 >$tmp_dir/mnt.err
349 if [ $status -ne 0 ]; then
351 cat $tmp_dir/mnt.err >&2
352 rm -f $tmp_dir/mnt.err
355 rm -f $tmp_dir/mnt.err
358 -c "truncate $file_size" \
359 -c "falloc -k 0 $file_size" \
361 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
362 export NUM_SPACE_FILES=1
365 if [ $status -ne 0 ]; then
366 echo "large file prealloc failed"
367 cat $tmp_dir/mnt.err >&2
373 _scratch_mkfs_xfs_opts()
377 _scratch_options mkfs
379 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
383 _scratch_mkfs_xfs_supported()
387 _scratch_options mkfs
389 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
394 # extra mkfs options can be added by tests
395 local extra_mkfs_options=$*
399 # save mkfs output in case conflict means we need to run again.
400 # only the output for the mkfs that applies should be shown
401 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
402 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
406 # a mkfs failure may be caused by conflicts between
407 # $MKFS_OPTIONS and $extra_mkfs_options
408 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
410 echo -n "** mkfs failed with extra mkfs options "
411 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
412 echo -n "** attempting to mkfs using only test $seq "
413 echo "options: $extra_mkfs_options **"
416 # running mkfs again. overwrite previous mkfs output files
417 _scratch_mkfs_xfs_opts $extra_mkfs_options \
418 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
422 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
423 # manually parse the mkfs output to get the fs size in bytes
425 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
426 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
428 print STDOUT "$size\n";
430 _setup_large_xfs_fs $fs_size
434 # output stored mkfs output
435 cat $tmp_dir.mkfserr >&2
437 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
442 # xfs_check script is planned to be deprecated. But, we want to
443 # be able to invoke "xfs_check" behavior in xfstests in order to
444 # maintain the current verification levels.
449 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
451 while getopts "b:fi:l:stvV" c
457 i) OPTS=$OPTS"-i "$OPTARG" ";;
458 b) OPTS=$OPTS"-b "$OPTARG" ";;
459 f) DBOPTS=$DBOPTS" -f";;
460 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
461 V) $XFS_DB_PROG -p xfs_check -V
469 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
479 _setup_large_ext4_fs()
484 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
485 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
486 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
488 # Default free space in the FS is 50GB, but you can specify more via
489 # SCRATCH_DEV_EMPTY_SPACE
490 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
492 # mount the filesystem and create 16TB - 4KB files until we consume
493 # all the necessary space.
494 _scratch_mount 2>&1 >$tmp_dir/mnt.err
496 if [ $status -ne 0 ]; then
498 cat $tmp_dir/mnt.err >&2
499 rm -f $tmp_dir/mnt.err
502 rm -f $tmp_dir/mnt.err
504 file_size=$((16*1024*1024*1024*1024 - 4096))
506 while [ $space_to_consume -gt $file_size ]; do
509 -c "truncate $file_size" \
510 -c "falloc -k 0 $file_size" \
511 $SCRATCH_MNT/.use_space.$nfiles 2>&1
513 if [ $status -ne 0 ]; then
517 space_to_consume=$(( $space_to_consume - $file_size ))
518 nfiles=$(($nfiles + 1))
521 # consume the remaining space.
522 if [ $space_to_consume -gt 0 ]; then
524 -c "truncate $space_to_consume" \
525 -c "falloc -k 0 $space_to_consume" \
526 $SCRATCH_MNT/.use_space.$nfiles 2>&1
529 export NUM_SPACE_FILES=$nfiles
532 if [ $status -ne 0 ]; then
533 echo "large file prealloc failed"
534 cat $tmp_dir/mnt.err >&2
543 /sbin/mkfs -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV \
544 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
547 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
548 # manually parse the mkfs output to get the fs size in bytes
549 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
550 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
551 / inodes, / { blks = $3 } \
552 /reserved for the super user/ { resv = $1 } \
553 END { fssize = bs * blks - resv; print fssize }'`
555 _setup_large_ext4_fs $fs_size
559 # output stored mkfs output
560 cat $tmp_dir.mkfserr >&2
562 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
577 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
580 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
583 _scratch_mkfs_ext4 $*
586 # do nothing for tmpfs
589 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
598 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
601 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
606 # Create fs of certain size on scratch device
607 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
608 _scratch_mkfs_sized()
612 [ -z "$blocksize" ] && blocksize=4096
615 if ! [[ $fssize =~ $re ]] ; then
616 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
618 if ! [[ $blocksize =~ $re ]] ; then
619 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
622 blocks=`expr $fssize / $blocksize`
624 if [ "$HOSTOS" == "Linux" ]; then
625 devsize=`blockdev --getsize64 $SCRATCH_DEV`
626 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
631 # don't override MKFS_OPTIONS that set a block size.
632 echo $MKFS_OPTIONS |egrep -q "b?size="
633 if [ $? -eq 0 ]; then
634 _scratch_mkfs_xfs -d size=$fssize
636 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
639 ext2|ext3|ext4|ext4dev)
640 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
643 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
646 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
649 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
654 # Emulate an N-data-disk stripe w/ various stripe units
655 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
661 [ -z "$blocksize" ] && blocksize=4096
663 let sunit_blocks=$sunit_bytes/$blocksize
664 let swidth_blocks=$sunit_blocks*$swidth_mult
668 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
671 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
674 _notrun "can't mkfs $FSTYP with geometry"
684 xfs_io -x -c "resblks $1" $SCRATCH_MNT
691 _scratch_xfs_db_options()
694 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
695 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
696 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
699 _scratch_xfs_logprint()
702 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
703 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
704 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
710 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
711 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
712 [ "$LARGE_SCRATCH_DEV" = yes ] && \
713 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
714 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
717 _scratch_xfs_repair()
720 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
721 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
722 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
723 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
724 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
725 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
732 echo "Usage: _get_pids_by_name process-name" 1>&2
736 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
737 # HH:MM:SS before the psargs field, use this as the search anchor.
739 # Matches with $1 (process-name) occur if the first psarg is $1
740 # or ends in /$1 ... the matching uses sed's regular expressions,
741 # so passing a regex into $1 will work.
749 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
750 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
753 # fix malloc libs output
757 # filter out the Electric Fence notice
760 if (defined $o && /^\s+Electric Fence/) {
766 print $o if (defined $o);
770 print $o if (defined $o);
774 # check if run as root
778 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
781 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
788 # _df_device : get an IRIX style df line for a given device
790 # - returns "" if not mounted
791 # - returns fs type in field two (ala IRIX)
792 # - joins line together if split by fancy df formatting
793 # - strips header etc
800 echo "Usage: _df_device device" 1>&2
804 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
805 match($1,what) && NF==1 {
819 # _df_dir : get an IRIX style df line for device where a directory resides
821 # - returns fs type in field two (ala IRIX)
822 # - joins line together if split by fancy df formatting
823 # - strips header etc
830 echo "Usage: _df_dir device" 1>&2
834 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
850 # return percentage used disk space for mounted device
856 echo "Usage: _used device" 1>&2
860 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
863 # return the FS type of a mounted device
869 echo "Usage: _fs_type device" 1>&2
874 # The Linux kernel shows NFSv4 filesystems in df output as
875 # filesystem type nfs4, although we mounted it as nfs earlier.
876 # Fix the filesystem type up here so that the callers don't
877 # have to bother with this quirk.
879 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
882 # return the FS mount options of a mounted device
884 # should write a version which just parses the output of mount for IRIX
885 # compatibility, but since this isn't used at all, at the moment I'll leave
892 echo "Usage: _fs_options device" 1>&2
896 $AWK_PROG -v dev=$1 '
897 match($1,dev) { print $4 }
901 # returns device number if a file is a block device
907 echo "Usage: _is_block_dev dev" 1>&2
912 if [ -L "${_dev}" ]; then
913 _dev=`readlink -f ${_dev}`
916 if [ -b "${_dev}" ]; then
917 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
921 # Do a command, log it to $seqres.full, optionally test return status
922 # and die if command fails. If called with one argument _do executes the
923 # command, logs it, and returns its exit status. With two arguments _do
924 # first prints the message passed in the first argument, and then "done"
925 # or "fail" depending on the return status of the command passed in the
926 # second argument. If the command fails and the variable _do_die_on_error
927 # is set to "always" or the two argument form is used and _do_die_on_error
928 # is set to "message_only" _do will print an error message to
929 # $seqres.out and exit.
933 if [ $# -eq 1 ]; then
935 elif [ $# -eq 2 ]; then
940 echo "Usage: _do [note] cmd" 1>&2
944 (eval "echo '---' \"$_cmd\"") >>$seqres.full
945 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
946 cat $tmp._out | _fix_malloc >>$seqres.full
947 if [ $# -eq 2 ]; then
948 if [ $ret -eq 0 ]; then
955 && [ "$_do_die_on_error" = "always" \
956 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
959 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
966 # bail out, setting up .notrun file
970 echo "$*" > $seqres.notrun
971 echo "$seq not run: $*"
976 # just plain bail out
980 echo "$*" | tee -a $seqres.full
981 echo "(see $seqres.full for details)"
986 # tests whether $FSTYP is one of the supported filesystems for a test
992 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
998 _notrun "not suitable for this filesystem type: $FSTYP"
1001 # tests whether $FSTYP is one of the supported OSes for a test
1007 if [ "$h" = "$HOSTOS" ]
1013 _notrun "not suitable for this OS: $HOSTOS"
1016 # this test needs a scratch partition - check we're ok & unmount it
1022 _notrun "requires a scratch device"
1025 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1027 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1031 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
1033 _notrun "this test requires a valid \$SCRATCH_DEV"
1035 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1037 _notrun "this test requires a valid \$SCRATCH_DEV"
1039 if [ ! -d "$SCRATCH_MNT" ]
1041 _notrun "this test requires a valid \$SCRATCH_MNT"
1047 if _mount | grep -q $SCRATCH_DEV
1049 # if it's mounted, make sure its on $SCRATCH_MNT
1050 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1052 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1055 # and then unmount it
1056 if ! $UMOUNT_PROG $SCRATCH_DEV
1058 echo "failed to unmount $SCRATCH_DEV"
1064 # this test needs a logdev
1068 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1069 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1070 [ "$USE_EXTERNAL" != yes ] && \
1071 _notrun "This test requires USE_EXTERNAL to be enabled"
1073 # ensure its not mounted
1074 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1077 # this test requires loopback device support
1081 if [ "$HOSTOS" != "Linux" ]
1083 _notrun "This test requires linux for loopback device support"
1086 modprobe loop >/dev/null 2>&1
1087 if grep loop /proc/devices >/dev/null 2>&1
1091 _notrun "This test requires loopback device support"
1095 # this test requires ext2 filesystem support
1099 if [ "$HOSTOS" != "Linux" ]
1101 _notrun "This test requires linux for ext2 filesystem support"
1104 modprobe ext2 >/dev/null 2>&1
1105 if grep ext2 /proc/filesystems >/dev/null 2>&1
1109 _notrun "This test requires ext2 filesystem support"
1113 # this test requires that (large) loopback device files are not in use
1115 _require_no_large_scratch_dev()
1117 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1118 _notrun "Large filesystem testing in progress, skipped this test"
1121 # this test requires that a realtime subvolume is in use, and
1122 # that the kernel supports realtime as well.
1126 [ "$USE_EXTERNAL" = yes ] || \
1127 _notrun "External volumes not in use, skipped this test"
1128 [ "$SCRATCH_RTDEV" = "" ] && \
1129 _notrun "Realtime device required, skipped this test"
1132 # this test requires that a specified command (executable) exists
1133 # $1 - command, $2 - name for error message
1137 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1138 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1141 # this test requires the device mapper flakey target
1143 _require_dm_flakey()
1145 _require_command $DMSETUP_PROG
1147 modprobe dm-flakey >/dev/null 2>&1
1148 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1153 _notrun "This test requires dm flakey support"
1157 # this test requires the projid32bit feature to be available in mkfs.xfs.
1159 _require_projid32bit()
1161 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1162 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1165 _require_projid16bit()
1167 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1168 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1171 # this test requires the crc feature to be available in mkfs.xfs
1173 _require_xfs_mkfs_crc()
1175 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1176 || _notrun "mkfs.xfs doesn't have crc feature"
1179 # this test requires the xfs kernel support crc feature
1183 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1184 _scratch_mount >/dev/null 2>&1 \
1185 || _notrun "Kernel doesn't support crc feature"
1189 # this test requires that external log/realtime devices are not in use
1191 _require_nonexternal()
1193 [ "$USE_EXTERNAL" = yes ] && \
1194 _notrun "External device testing in progress, skipped this test"
1197 # this test requires that a (specified) aio-dio executable exists
1198 # $1 - command (optional)
1204 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1205 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1207 AIO_TEST=src/aio-dio-regress/$1
1208 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1212 # run an aio-dio program
1218 echo "usage: _run_aiodio command_name" 2>&1
1224 local testtemp=$TEST_DIR/aio-testfile
1226 $AIO_TEST $testtemp 2>&1
1233 # indicate whether YP/NIS is active or not
1238 dn=$(domainname 2>/dev/null)
1239 test -n "${dn}" -a "${dn}" != "(none)"
1243 # cat the password file
1247 [ $(_yp_active) -eq 0 ] && ypcat passwd
1251 # cat the group file
1255 [ $(_yp_active) -eq 0 ] && ypcat group
1259 # check for the fsgqa user on the machine
1264 _cat_passwd | grep -q $qa_user
1265 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1266 echo /bin/true | su $qa_user
1267 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1270 # check for the fsgqa group on the machine
1275 _cat_group | grep -q $qa_group
1276 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1282 s,.*Permission\sdenied.*,Permission denied,;
1283 s,.*no\saccess\sto\stty.*,,;
1284 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1291 if [ "$HOSTOS" == "IRIX" ]
1293 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1295 echo $1 | su $qa_user 2>&1 | _filter_user_do
1299 # check that xfs_io, kernel, and filesystem all support zero
1300 _require_xfs_io_zero()
1302 testio=`$XFS_IO_PROG -c "zero help" 2>&1`
1303 echo $testio | grep -q 'command "zero" not found' && \
1304 _notrun "zero command not supported"
1307 # check that xfs_io, glibc, kernel, and filesystem all (!) support
1310 _require_xfs_io_falloc()
1312 testfile=$TEST_DIR/$$.falloc
1313 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1314 rm -f $testfile 2>&1 > /dev/null
1315 echo $testio | grep -q "not found" && \
1316 _notrun "xfs_io fallocate support is missing"
1317 echo $testio | grep -q "Operation not supported" && \
1318 _notrun "xfs_io fallocate command failed (old kernel/wrong fs?)"
1321 # check that xfs_io, kernel and filesystem all support fallocate with hole
1323 _require_xfs_io_falloc_punch()
1325 testfile=$TEST_DIR/$$.falloc
1326 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1327 -c "fpunch 4k 8k" $testfile 2>&1`
1328 rm -f $testfile 2>&1 > /dev/null
1329 echo $testio | grep -q "not found" && \
1330 _notrun "xfs_io fallocate punch support is missing"
1331 echo $testio | grep -q "Operation not supported" && \
1332 _notrun "xfs_io fallocate punch command failed (no fs support?)"
1335 # check that xfs_io, kernel and filesystem support fiemap
1336 _require_xfs_io_fiemap()
1338 testfile=$TEST_DIR/$$.fiemap
1339 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1340 -c "fiemap -v" $testfile 2>&1`
1341 rm -f $testfile 2>&1 > /dev/null
1342 echo $testio | grep -q "not found" && \
1343 _notrun "xfs_io fiemap support is missing"
1344 echo $testio | grep -q "Operation not supported" && \
1345 _notrun "xfs_io fiemap command failed (no fs support?)"
1348 # Check that a fs has enough free space (in 1024b blocks)
1353 BLOCKS=$2 # in units of 1024
1354 let GB=$BLOCKS/1024/1024
1356 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1357 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1358 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1362 # Check if the filesystem supports sparse files.
1364 # Unfortunately there is no better way to do this than a manual black list.
1366 _require_sparse_files()
1370 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1379 #boot_params always present in debugfs
1380 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1383 _require_fail_make_request()
1385 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1386 || _notrun "$DEBUGFS_MNT/fail_make_request \
1387 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1391 # Check if the file system supports seek_data/hole
1393 _require_seek_data_hole()
1395 testfile=$TEST_DIR/$$.seek
1396 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1397 rm -f $testfile &>/dev/null
1398 echo $testseek | grep -q "Kernel does not support" && \
1399 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1402 # check that a FS on a device is mounted
1403 # if so, return mount point
1409 echo "Usage: _is_mounted device" 1>&2
1415 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1416 pattern { print $3 ; exit 0 }
1420 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1425 # remount a FS to a new mode (ro or rw)
1431 echo "Usage: _remount device ro/rw" 1>&2
1437 if ! mount -o remount,$mode $device
1439 echo "_remount: failed to remount filesystem on $device as $mode"
1444 # Run the appropriate repair/check on a filesystem
1446 # if the filesystem is mounted, it's either remounted ro before being
1447 # checked or it's unmounted and then remounted
1450 # If set, we remount ro instead of unmounting for fsck
1453 _umount_or_remount_ro()
1457 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1462 mountpoint=`_is_mounted $device`
1464 if [ $USE_REMOUNT -eq 0 ]; then
1465 $UMOUNT_PROG $device
1472 _mount_or_remount_rw()
1476 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1483 if [ $USE_REMOUNT -eq 0 ]
1485 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1487 echo "!!! failed to remount $device on $mountpoint"
1497 # Check a generic filesystem in no-op mode; this assumes that the
1498 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1499 # and that it will still return an errno for corruption in this mode.
1501 # Filesystems which don't support this will need to define their
1502 # own check routine.
1504 _check_generic_filesystem()
1508 # If type is set, we're mounted
1509 type=`_fs_type $device`
1512 if [ "$type" = "$FSTYP" ]
1515 mountpoint=`_umount_or_remount_ro $device`
1518 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1521 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1523 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1524 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1525 cat $tmp.fsck >>$seqres.full
1526 echo "*** end fsck.$FSTYP output" >>$seqres.full
1534 echo "*** mount output ***" >>$seqres.full
1535 _mount >>$seqres.full
1536 echo "*** end mount output" >>$seqres.full
1537 elif [ "$type" = "$FSTYP" ]
1540 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1544 if [ $ok -eq 0 ]; then
1552 # run xfs_check and friends on a FS.
1554 _check_xfs_filesystem()
1558 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1562 extra_mount_options=""
1564 if [ "$2" != "none" ]; then
1565 extra_log_options="-l$2"
1566 extra_mount_options="-ologdev=$2"
1569 if [ "$3" != "none" ]; then
1570 extra_rt_options="-r$3"
1571 extra_mount_options=$extra_mount_options" -ortdev=$3"
1573 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1575 [ "$FSTYP" != xfs ] && return 0
1577 type=`_fs_type $device`
1580 if [ "$type" = "xfs" ]
1583 mountpoint=`_umount_or_remount_ro $device`
1586 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1587 | tee $tmp.logprint | grep -q "<CLEAN>"
1588 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1590 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1592 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1593 echo "*** xfs_logprint -t output ***" >>$seqres.full
1594 cat $tmp.logprint >>$seqres.full
1595 echo "*** end xfs_logprint output" >>$seqres.full
1600 # xfs_check runs out of memory on large files, so even providing the test
1601 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1602 # large filesystems. Avoid it.
1603 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1604 _xfs_check $extra_log_options $device 2>&1 |\
1605 _fix_malloc >$tmp.fs_check
1607 if [ -s $tmp.fs_check ]
1609 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1611 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1612 echo "*** xfs_check output ***" >>$seqres.full
1613 cat $tmp.fs_check >>$seqres.full
1614 echo "*** end xfs_check output" >>$seqres.full
1619 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1622 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1624 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1625 echo "*** xfs_repair -n output ***" >>$seqres.full
1626 cat $tmp.repair | _fix_malloc >>$seqres.full
1627 echo "*** end xfs_repair output" >>$seqres.full
1631 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1635 echo "*** mount output ***" >>$seqres.full
1636 _mount >>$seqres.full
1637 echo "*** end mount output" >>$seqres.full
1638 elif [ "$type" = "xfs" ]
1640 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1643 if [ $ok -eq 0 ]; then
1651 # Filter the knowen errors the UDF Verifier reports.
1652 _udf_test_known_error_filter()
1654 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."
1658 _check_udf_filesystem()
1660 [ "$DISABLE_UDF_TEST" == "1" ] && return
1662 if [ $# -ne 1 -a $# -ne 2 ]
1664 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1668 if [ ! -x $here/src/udf_test ]
1670 echo "udf_test not installed, please download and build the Philips"
1671 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1672 echo "Then copy the udf_test binary to $here/src/."
1673 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1681 LAST_BLOCK=`expr \( $2 - 1 \)`
1682 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1685 rm -f $seqres.checkfs
1686 sleep 1 # Due to a problem with time stamps in udf_test
1687 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1688 _udf_test_known_error_filter | \
1689 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1690 echo "Warning UDF Verifier reported errors see $seqres.checkfs."
1693 _check_xfs_test_fs()
1697 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1698 TEST_LOG="$TEST_LOGDEV"
1700 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1701 TEST_RT="$TEST_RTDEV"
1703 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1705 # check for ipath consistency
1706 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1707 # errors go to stderr
1708 xfs_check_ipaths $TEST_DIR >/dev/null
1709 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1713 _check_btrfs_filesystem()
1717 # If type is set, we're mounted
1718 type=`_fs_type $device`
1721 if [ "$type" = "$FSTYP" ]
1724 mountpoint=`_umount_or_remount_ro $device`
1727 btrfsck $device >$tmp.fsck 2>&1
1730 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1732 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1733 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1734 cat $tmp.fsck >>$seqres.full
1735 echo "*** end fsck.$FSTYP output" >>$seqres.full
1743 echo "*** mount output ***" >>$seqres.full
1744 _mount >>$seqres.full
1745 echo "*** end mount output" >>$seqres.full
1746 elif [ "$type" = "$FSTYP" ]
1749 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1753 if [ $ok -eq 0 ]; then
1768 # no way to check consistency for nfs
1771 # do nothing for now
1774 _check_btrfs_filesystem $TEST_DEV
1777 # no way to check consistency for tmpfs
1780 _check_generic_filesystem $TEST_DEV
1788 [ $# -eq 1 ] && device=$1
1794 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1795 SCRATCH_LOG="$SCRATCH_LOGDEV"
1797 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1798 SCRATCH_RT="$SCRATCH_RTDEV"
1800 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1803 _check_udf_filesystem $device $udf_fsize
1806 # Don't know how to check an NFS filesystem, yet.
1809 _check_btrfs_filesystem $device
1812 # no way to check consistency for tmpfs
1815 _check_generic_filesystem $device
1820 _full_fstyp_details()
1822 [ -z "$FSTYP" ] && FSTYP=xfs
1823 if [ $FSTYP = xfs ]; then
1824 if [ -d /proc/fs/xfs ]; then
1825 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1826 FSTYP="$FSTYP (non-debug)"
1827 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1828 FSTYP="$FSTYP (debug)"
1831 if uname -a | grep -qi 'debug'; then
1832 FSTYP="$FSTYP (debug)"
1834 FSTYP="$FSTYP (non-debug)"
1841 _full_platform_details()
1847 echo "$os/$platform $host $kernel"
1852 if [ -z "$1" -o -z "$2" ]; then
1853 echo Error must pass src and dst.
1857 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1859 elif [ "`uname`" == "Linux" ]; then
1862 echo Error test $seq does not run on the operating system: `uname`
1873 #takes files, randomdata
1881 if [ $size -gt 0 ]; then
1882 if [ "$2" == "false" ]; then
1883 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
1885 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
1892 # takes dirname, depth, randomdata
1895 dirname=$1; depth=$2; randomdata=$3
1896 mkdir $dirname || die "mkdir $dirname failed"
1899 _nfiles $files $randomdata # files for this dir and data type
1901 [ $depth -eq 0 ] && return
1902 let deep=$depth-1 # go 1 down
1904 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
1907 while [ $d -lt $dirs ]
1909 _descend d$d $deep &
1915 # Populate a filesystem with inodes for performance experiments
1917 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
1922 dirs=5 # ndirs in each subdir till leaves
1923 size=0 # sizeof files in K
1924 files=100 # num files in _each_ subdir
1925 depth=2 # depth of tree from root to leaves
1927 root=root # path of initial root of directory tree
1928 randomdata=false # -x data type urandom or zero
1931 while getopts "d:f:n:r:s:v:x" c
1940 x) randomdata=true;;
1944 _descend $root $depth $randomdata
1949 [ $verbose = true ] && echo done
1952 # query whether the given file has the given inode flag set
1959 if which $XFS_IO_PROG >/dev/null; then
1960 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
1967 # query the given files extsize allocator hint in bytes (if any)
1974 if which $XFS_IO_PROG >/dev/null; then
1975 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
1976 awk '/^xattr.extsize =/ { print $3 }'`
1978 [ -z "$blocks" ] && blocks="0"
1982 # scratch_dev_pool should contain the disks pool for the btrfs raid
1983 _require_scratch_dev_pool()
1988 if [ -z "$SCRATCH_DEV_POOL" ]; then
1989 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
1992 if [ -z "$1" ]; then
1998 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2002 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2003 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2007 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2011 for i in $SCRATCH_DEV_POOL; do
2012 if [ "`_is_block_dev $i`" = "" ]; then
2013 _notrun "this test requires valid block disk $i"
2015 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
2016 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2018 if _mount | grep -q $i; then
2019 if ! $UMOUNT_PROG $i; then
2020 echo "failed to unmount $i - aborting"
2024 # to help better debug when something fails, we remove
2025 # traces of previous btrfs FS on the dev.
2026 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2030 # We will check if the device is deletable
2031 _require_deletable_scratch_dev_pool()
2035 for i in $SCRATCH_DEV_POOL; do
2036 x=`echo $i | cut -d"/" -f 3`
2037 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2038 _notrun "$i is a device which is not deletable"
2043 # We check for btrfs and (optionally) features of the btrfs command
2047 _require_command $BTRFS_UTIL_PROG btrfs
2048 if [ -z "$1" ]; then
2051 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2052 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2055 # Check that fio is present, and it is able to execute given jobfile
2060 _require_command $FIO_PROG
2061 if [ -z "$1" ]; then
2065 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2066 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2069 # Does freeze work on this fs?
2072 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2074 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2075 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2078 # arg 1 is dev to remove and is output of the below eg.
2079 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2085 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2087 stat $disk > /dev/null 2>&1
2088 while [ $? -eq 0 ]; do
2090 stat $disk > /dev/null 2>&1
2094 # arg 1 is dev to add and is output of the below eg.
2095 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2100 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2101 h=`echo ${1} | cut -d":" -f 1`
2102 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2104 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2109 if [ -z "$FSTRIM_PROG" ]; then
2110 _notrun "This test requires fstrim utility."
2114 _test_batched_discard()
2116 if [ $# -ne 1 ]; then
2117 echo "Usage: _test_batched_discard mnt_point" 1>&2
2121 $FSTRIM_PROG ${1} &>/dev/null
2126 if [ -z "$DUMPE2FS_PROG" ]; then
2127 _notrun "This test requires dumpe2fs utility."
2133 if [ ! -e /proc/self/uid_map ]; then
2134 _notrun "This test requires procfs uid_map support."
2136 if [ ! -e /proc/self/gid_map ]; then
2137 _notrun "This test requires procfs gid_map support."
2141 _require_cp_reflink()
2143 cp --help | grep -q reflink || \
2144 _notrun "This test requires a cp with --reflink support."
2147 # Given 2 files, verify that they have the same mapping but different
2148 # inodes - i.e. an undisturbed reflink
2149 # Silent if so, make noise if not
2152 # not a hard link or symlink?
2153 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2154 && echo "$1 and $2 are not reflinks: same inode number"
2157 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2158 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2159 || echo "$1 and $2 are not reflinks: different extents"
2162 _create_loop_device()
2165 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2169 _destroy_loop_device()
2172 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2175 _scale_fsstress_args()
2178 while [ $# -gt 0 ]; do
2180 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2181 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2182 *) args="$args $1" ;;
2190 # Return the logical block size if running on a block device,
2191 # else substitute the page size.
2193 _min_dio_alignment()
2197 if [ -b "$dev" ]; then
2198 blockdev --getss $dev
2200 $here/src/feature -s
2206 echo "# $@" >> $seqres.full 2>&1
2207 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2210 _run_btrfs_util_prog()
2212 run_check $BTRFS_UTIL_PROG $*
2217 if [ "$iam" == new ]
2221 # make some further configuration checks here
2222 if [ "$TEST_DEV" = "" ]
2224 echo "common/rc: Error: \$TEST_DEV is not set"
2228 # if $TEST_DEV is not mounted, mount it now as XFS
2229 if [ -z "`_fs_type $TEST_DEV`" ]
2231 # $TEST_DEV is not mounted
2234 echo "common/rc: retrying test device mount with external set"
2235 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2238 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2244 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2246 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2250 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2251 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2252 export XFS_IO_PROG="$XFS_IO_PROG -F"
2257 ################################################################################
2258 # make sure this script returns success