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
451 /sbin/mkfs -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV \
452 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
455 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
456 # manually parse the mkfs output to get the fs size in bytes
457 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
458 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
459 / inodes, / { blks = $3 } \
460 /reserved for the super user/ { resv = $1 } \
461 END { fssize = bs * blks - resv; print fssize }'`
463 _setup_large_ext4_fs $fs_size
467 # output stored mkfs output
468 cat $tmp_dir.mkfserr >&2
470 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
482 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
485 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
488 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
503 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
506 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
509 _scratch_mkfs_ext4 $*
512 # do nothing for tmpfs
515 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
524 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
527 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
532 # Create fs of certain size on scratch device
533 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
534 _scratch_mkfs_sized()
538 [ -z "$blocksize" ] && blocksize=4096
541 if ! [[ $fssize =~ $re ]] ; then
542 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
544 if ! [[ $blocksize =~ $re ]] ; then
545 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
548 blocks=`expr $fssize / $blocksize`
550 if [ "$HOSTOS" == "Linux" ]; then
551 devsize=`blockdev --getsize64 $SCRATCH_DEV`
552 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
557 # don't override MKFS_OPTIONS that set a block size.
558 echo $MKFS_OPTIONS |egrep -q "b?size="
559 if [ $? -eq 0 ]; then
560 _scratch_mkfs_xfs -d size=$fssize
562 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
565 ext2|ext3|ext4|ext4dev)
566 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
569 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
572 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
575 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
580 # Emulate an N-data-disk stripe w/ various stripe units
581 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
587 [ -z "$blocksize" ] && blocksize=4096
589 let sunit_blocks=$sunit_bytes/$blocksize
590 let swidth_blocks=$sunit_blocks*$swidth_mult
594 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
597 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
600 _notrun "can't mkfs $FSTYP with geometry"
610 xfs_io -x -c "resblks $1" $SCRATCH_MNT
617 _scratch_xfs_db_options()
620 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
621 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
622 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
625 _scratch_xfs_logprint()
628 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
629 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
630 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
636 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
637 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
638 [ "$LARGE_SCRATCH_DEV" = yes ] && \
639 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
640 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
643 _scratch_xfs_repair()
646 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
647 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
648 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
649 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
650 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
651 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
658 echo "Usage: _get_pids_by_name process-name" 1>&2
662 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
663 # HH:MM:SS before the psargs field, use this as the search anchor.
665 # Matches with $1 (process-name) occur if the first psarg is $1
666 # or ends in /$1 ... the matching uses sed's regular expressions,
667 # so passing a regex into $1 will work.
675 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
676 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
679 # fix malloc libs output
683 # filter out the Electric Fence notice
686 if (defined $o && /^\s+Electric Fence/) {
692 print $o if (defined $o);
696 print $o if (defined $o);
700 # check if run as root
704 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
707 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
714 # _df_device : get an IRIX style df line for a given device
716 # - returns "" if not mounted
717 # - returns fs type in field two (ala IRIX)
718 # - joins line together if split by fancy df formatting
719 # - strips header etc
726 echo "Usage: _df_device device" 1>&2
730 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
731 match($1,what) && NF==1 {
745 # _df_dir : get an IRIX style df line for device where a directory resides
747 # - returns fs type in field two (ala IRIX)
748 # - joins line together if split by fancy df formatting
749 # - strips header etc
756 echo "Usage: _df_dir device" 1>&2
760 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
776 # return percentage used disk space for mounted device
782 echo "Usage: _used device" 1>&2
786 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
789 # return the FS type of a mounted device
795 echo "Usage: _fs_type device" 1>&2
800 # The Linux kernel shows NFSv4 filesystems in df output as
801 # filesystem type nfs4, although we mounted it as nfs earlier.
802 # Fix the filesystem type up here so that the callers don't
803 # have to bother with this quirk.
805 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
808 # return the FS mount options of a mounted device
810 # should write a version which just parses the output of mount for IRIX
811 # compatibility, but since this isn't used at all, at the moment I'll leave
818 echo "Usage: _fs_options device" 1>&2
822 $AWK_PROG -v dev=$1 '
823 match($1,dev) { print $4 }
827 # returns device number if a file is a block device
833 echo "Usage: _is_block_dev dev" 1>&2
838 if [ -L "${_dev}" ]; then
839 _dev=`readlink -f ${_dev}`
842 if [ -b "${_dev}" ]; then
843 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
847 # Do a command, log it to $seqres.full, optionally test return status
848 # and die if command fails. If called with one argument _do executes the
849 # command, logs it, and returns its exit status. With two arguments _do
850 # first prints the message passed in the first argument, and then "done"
851 # or "fail" depending on the return status of the command passed in the
852 # second argument. If the command fails and the variable _do_die_on_error
853 # is set to "always" or the two argument form is used and _do_die_on_error
854 # is set to "message_only" _do will print an error message to
855 # $seqres.out and exit.
859 if [ $# -eq 1 ]; then
861 elif [ $# -eq 2 ]; then
866 echo "Usage: _do [note] cmd" 1>&2
870 (eval "echo '---' \"$_cmd\"") >>$seqres.full
871 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
872 cat $tmp._out | _fix_malloc >>$seqres.full
873 if [ $# -eq 2 ]; then
874 if [ $ret -eq 0 ]; then
881 && [ "$_do_die_on_error" = "always" \
882 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
885 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
892 # bail out, setting up .notrun file
896 echo "$*" > $seqres.notrun
897 echo "$seq not run: $*"
902 # just plain bail out
906 echo "$*" | tee -a $seqres.full
907 echo "(see $seqres.full for details)"
912 # tests whether $FSTYP is one of the supported filesystems for a test
918 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
924 _notrun "not suitable for this filesystem type: $FSTYP"
928 # tests whether $FSTYP is one of the supported OSes for a test
934 if [ "$h" = "$HOSTOS" ]
940 _notrun "not suitable for this OS: $HOSTOS"
943 # this test needs a scratch partition - check we're ok & unmount it
949 _notrun "requires a scratch device"
952 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
954 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
958 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
960 _notrun "this test requires a valid \$SCRATCH_DEV"
962 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
964 _notrun "this test requires a valid \$SCRATCH_DEV"
966 if [ ! -d "$SCRATCH_MNT" ]
968 _notrun "this test requires a valid \$SCRATCH_MNT"
974 if _mount | grep -q $SCRATCH_DEV
976 # if it's mounted, make sure its on $SCRATCH_MNT
977 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
979 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
982 # and then unmount it
983 if ! $UMOUNT_PROG $SCRATCH_DEV
985 echo "failed to unmount $SCRATCH_DEV"
991 # this test needs a logdev
995 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
996 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
997 [ "$USE_EXTERNAL" != yes ] && \
998 _notrun "This test requires USE_EXTERNAL to be enabled"
1000 # ensure its not mounted
1001 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1004 # this test requires loopback device support
1008 if [ "$HOSTOS" != "Linux" ]
1010 _notrun "This test requires linux for loopback device support"
1013 modprobe loop >/dev/null 2>&1
1014 if grep loop /proc/devices >/dev/null 2>&1
1018 _notrun "This test requires loopback device support"
1022 # this test requires ext2 filesystem support
1026 if [ "$HOSTOS" != "Linux" ]
1028 _notrun "This test requires linux for ext2 filesystem support"
1031 modprobe ext2 >/dev/null 2>&1
1032 if grep ext2 /proc/filesystems >/dev/null 2>&1
1036 _notrun "This test requires ext2 filesystem support"
1040 # this test requires that (large) loopback device files are not in use
1042 _require_no_large_scratch_dev()
1044 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1045 _notrun "Large filesystem testing in progress, skipped this test"
1048 # this test requires that a realtime subvolume is in use, and
1049 # that the kernel supports realtime as well.
1053 [ "$USE_EXTERNAL" = yes ] || \
1054 _notrun "External volumes not in use, skipped this test"
1055 [ "$SCRATCH_RTDEV" = "" ] && \
1056 _notrun "Realtime device required, skipped this test"
1059 # this test requires that a specified command (executable) exists
1060 # $1 - command, $2 - name for error message
1064 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1065 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1068 # this test requires the device mapper flakey target
1070 _require_dm_flakey()
1072 _require_command $DMSETUP_PROG
1074 modprobe dm-flakey >/dev/null 2>&1
1075 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1080 _notrun "This test requires dm flakey support"
1084 # this test requires the projid32bit feature to be available in mkfs.xfs.
1086 _require_projid32bit()
1088 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1089 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1092 _require_projid16bit()
1094 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1095 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1098 # this test requires the crc feature to be available in mkfs.xfs
1100 _require_xfs_mkfs_crc()
1102 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1103 || _notrun "mkfs.xfs doesn't have crc feature"
1106 # this test requires the xfs kernel support crc feature
1110 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1111 _scratch_mount >/dev/null 2>&1 \
1112 || _notrun "Kernel doesn't support crc feature"
1116 # this test requires that external log/realtime devices are not in use
1118 _require_nonexternal()
1120 [ "$USE_EXTERNAL" = yes ] && \
1121 _notrun "External device testing in progress, skipped this test"
1124 # this test requires that a (specified) aio-dio executable exists
1125 # $1 - command (optional)
1131 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1132 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1134 AIO_TEST=src/aio-dio-regress/$1
1135 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1139 # run an aio-dio program
1145 echo "usage: _run_aiodio command_name" 2>&1
1151 local testtemp=$TEST_DIR/aio-testfile
1153 $AIO_TEST $testtemp 2>&1
1160 # indicate whether YP/NIS is active or not
1165 dn=$(domainname 2>/dev/null)
1166 test -n "${dn}" -a "${dn}" != "(none)"
1170 # cat the password file
1174 [ $(_yp_active) -eq 0 ] && ypcat passwd
1178 # cat the group file
1182 [ $(_yp_active) -eq 0 ] && ypcat group
1186 # check for the fsgqa user on the machine
1191 _cat_passwd | grep -q $qa_user
1192 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1193 echo /bin/true | su $qa_user
1194 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1197 # check for the fsgqa group on the machine
1202 _cat_group | grep -q $qa_group
1203 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1209 s,.*Permission\sdenied.*,Permission denied,;
1210 s,.*no\saccess\sto\stty.*,,;
1211 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1218 if [ "$HOSTOS" == "IRIX" ]
1220 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1222 echo $1 | su $qa_user 2>&1 | _filter_user_do
1226 _require_xfs_io_command()
1230 echo "Usage: _require_xfs_io_command command" 1>&2
1235 testfile=$TEST_DIR/$$.xfs_io
1238 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1240 "fpunch" | "fcollapse" | "zero" | "fzero" )
1241 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1242 -c "$command 4k 8k" $testfile 2>&1`
1245 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1246 -c "fiemap -v" $testfile 2>&1`
1249 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1253 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1256 rm -f $testfile 2>&1 > /dev/null
1257 echo $testio | grep -q "not found" && \
1258 _notrun "xfs_io $command support is missing"
1259 echo $testio | grep -q "Operation not supported" && \
1260 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1263 # Check that a fs has enough free space (in 1024b blocks)
1268 BLOCKS=$2 # in units of 1024
1269 let GB=$BLOCKS/1024/1024
1271 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1272 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1273 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1277 # Check if the filesystem supports sparse files.
1279 # Unfortunately there is no better way to do this than a manual black list.
1281 _require_sparse_files()
1285 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1294 #boot_params always present in debugfs
1295 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1298 _require_fail_make_request()
1300 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1301 || _notrun "$DEBUGFS_MNT/fail_make_request \
1302 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1306 # Check if the file system supports seek_data/hole
1308 _require_seek_data_hole()
1310 testfile=$TEST_DIR/$$.seek
1311 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1312 rm -f $testfile &>/dev/null
1313 echo $testseek | grep -q "Kernel does not support" && \
1314 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1317 # check that a FS on a device is mounted
1318 # if so, return mount point
1324 echo "Usage: _is_mounted device" 1>&2
1330 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1331 pattern { print $3 ; exit 0 }
1335 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1340 # remount a FS to a new mode (ro or rw)
1346 echo "Usage: _remount device ro/rw" 1>&2
1352 if ! mount -o remount,$mode $device
1354 echo "_remount: failed to remount filesystem on $device as $mode"
1359 # Run the appropriate repair/check on a filesystem
1361 # if the filesystem is mounted, it's either remounted ro before being
1362 # checked or it's unmounted and then remounted
1365 # If set, we remount ro instead of unmounting for fsck
1368 _umount_or_remount_ro()
1372 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1377 mountpoint=`_is_mounted $device`
1379 if [ $USE_REMOUNT -eq 0 ]; then
1380 $UMOUNT_PROG $device
1387 _mount_or_remount_rw()
1391 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1398 if [ $USE_REMOUNT -eq 0 ]
1400 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1402 echo "!!! failed to remount $device on $mountpoint"
1412 # Check a generic filesystem in no-op mode; this assumes that the
1413 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1414 # and that it will still return an errno for corruption in this mode.
1416 # Filesystems which don't support this will need to define their
1417 # own check routine.
1419 _check_generic_filesystem()
1423 # If type is set, we're mounted
1424 type=`_fs_type $device`
1427 if [ "$type" = "$FSTYP" ]
1430 mountpoint=`_umount_or_remount_ro $device`
1433 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1436 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1438 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1439 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1440 cat $tmp.fsck >>$seqres.full
1441 echo "*** end fsck.$FSTYP output" >>$seqres.full
1449 echo "*** mount output ***" >>$seqres.full
1450 _mount >>$seqres.full
1451 echo "*** end mount output" >>$seqres.full
1452 elif [ "$type" = "$FSTYP" ]
1455 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1459 if [ $ok -eq 0 ]; then
1467 # run xfs_check and friends on a FS.
1469 _check_xfs_filesystem()
1473 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1477 extra_mount_options=""
1479 if [ "$2" != "none" ]; then
1480 extra_log_options="-l$2"
1481 extra_mount_options="-ologdev=$2"
1484 if [ "$3" != "none" ]; then
1485 extra_rt_options="-r$3"
1486 extra_mount_options=$extra_mount_options" -ortdev=$3"
1488 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1490 [ "$FSTYP" != xfs ] && return 0
1492 type=`_fs_type $device`
1495 if [ "$type" = "xfs" ]
1498 mountpoint=`_umount_or_remount_ro $device`
1501 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1502 | tee $tmp.logprint | grep -q "<CLEAN>"
1503 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1505 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1507 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1508 echo "*** xfs_logprint -t output ***" >>$seqres.full
1509 cat $tmp.logprint >>$seqres.full
1510 echo "*** end xfs_logprint output" >>$seqres.full
1515 # xfs_check runs out of memory on large files, so even providing the test
1516 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1517 # large filesystems. Avoid it.
1518 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1519 _xfs_check $extra_log_options $device 2>&1 |\
1520 _fix_malloc >$tmp.fs_check
1522 if [ -s $tmp.fs_check ]
1524 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1526 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1527 echo "*** xfs_check output ***" >>$seqres.full
1528 cat $tmp.fs_check >>$seqres.full
1529 echo "*** end xfs_check output" >>$seqres.full
1534 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1537 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1539 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1540 echo "*** xfs_repair -n output ***" >>$seqres.full
1541 cat $tmp.repair | _fix_malloc >>$seqres.full
1542 echo "*** end xfs_repair output" >>$seqres.full
1546 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1550 echo "*** mount output ***" >>$seqres.full
1551 _mount >>$seqres.full
1552 echo "*** end mount output" >>$seqres.full
1553 elif [ "$type" = "xfs" ]
1555 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1558 if [ $ok -eq 0 ]; then
1566 # Filter the knowen errors the UDF Verifier reports.
1567 _udf_test_known_error_filter()
1569 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."
1573 _check_udf_filesystem()
1575 [ "$DISABLE_UDF_TEST" == "1" ] && return
1577 if [ $# -ne 1 -a $# -ne 2 ]
1579 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1583 if [ ! -x $here/src/udf_test ]
1585 echo "udf_test not installed, please download and build the Philips"
1586 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1587 echo "Then copy the udf_test binary to $here/src/."
1588 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1596 LAST_BLOCK=`expr \( $2 - 1 \)`
1597 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1600 rm -f $seqres.checkfs
1601 sleep 1 # Due to a problem with time stamps in udf_test
1602 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1603 _udf_test_known_error_filter | \
1604 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1605 echo "Warning UDF Verifier reported errors see $seqres.checkfs."
1608 _check_xfs_test_fs()
1612 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1613 TEST_LOG="$TEST_LOGDEV"
1615 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1616 TEST_RT="$TEST_RTDEV"
1618 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1620 # check for ipath consistency
1621 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1622 # errors go to stderr
1623 xfs_check_ipaths $TEST_DIR >/dev/null
1624 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1628 _check_btrfs_filesystem()
1632 # If type is set, we're mounted
1633 type=`_fs_type $device`
1636 if [ "$type" = "$FSTYP" ]
1639 mountpoint=`_umount_or_remount_ro $device`
1642 btrfsck $device >$tmp.fsck 2>&1
1645 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1647 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1648 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1649 cat $tmp.fsck >>$seqres.full
1650 echo "*** end fsck.$FSTYP output" >>$seqres.full
1658 echo "*** mount output ***" >>$seqres.full
1659 _mount >>$seqres.full
1660 echo "*** end mount output" >>$seqres.full
1661 elif [ "$type" = "$FSTYP" ]
1664 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1668 if [ $ok -eq 0 ]; then
1683 # no way to check consistency for nfs
1686 # do nothing for now
1689 _check_btrfs_filesystem $TEST_DEV
1692 # no way to check consistency for tmpfs
1695 _check_generic_filesystem $TEST_DEV
1703 [ $# -eq 1 ] && device=$1
1709 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1710 SCRATCH_LOG="$SCRATCH_LOGDEV"
1712 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1713 SCRATCH_RT="$SCRATCH_RTDEV"
1715 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1718 _check_udf_filesystem $device $udf_fsize
1721 # Don't know how to check an NFS filesystem, yet.
1724 _check_btrfs_filesystem $device
1727 # no way to check consistency for tmpfs
1730 _check_generic_filesystem $device
1735 _full_fstyp_details()
1737 [ -z "$FSTYP" ] && FSTYP=xfs
1738 if [ $FSTYP = xfs ]; then
1739 if [ -d /proc/fs/xfs ]; then
1740 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1741 FSTYP="$FSTYP (non-debug)"
1742 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1743 FSTYP="$FSTYP (debug)"
1746 if uname -a | grep -qi 'debug'; then
1747 FSTYP="$FSTYP (debug)"
1749 FSTYP="$FSTYP (non-debug)"
1756 _full_platform_details()
1762 echo "$os/$platform $host $kernel"
1767 if [ -z "$1" -o -z "$2" ]; then
1768 echo Error must pass src and dst.
1772 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1774 elif [ "`uname`" == "Linux" ]; then
1777 echo Error test $seq does not run on the operating system: `uname`
1788 #takes files, randomdata
1796 if [ $size -gt 0 ]; then
1797 if [ "$2" == "false" ]; then
1798 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
1800 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
1807 # takes dirname, depth, randomdata
1810 dirname=$1; depth=$2; randomdata=$3
1811 mkdir $dirname || die "mkdir $dirname failed"
1814 _nfiles $files $randomdata # files for this dir and data type
1816 [ $depth -eq 0 ] && return
1817 let deep=$depth-1 # go 1 down
1819 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
1822 while [ $d -lt $dirs ]
1824 _descend d$d $deep &
1830 # Populate a filesystem with inodes for performance experiments
1832 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
1837 dirs=5 # ndirs in each subdir till leaves
1838 size=0 # sizeof files in K
1839 files=100 # num files in _each_ subdir
1840 depth=2 # depth of tree from root to leaves
1842 root=root # path of initial root of directory tree
1843 randomdata=false # -x data type urandom or zero
1846 while getopts "d:f:n:r:s:v:x" c
1855 x) randomdata=true;;
1859 _descend $root $depth $randomdata
1864 [ $verbose = true ] && echo done
1867 # query whether the given file has the given inode flag set
1874 if which $XFS_IO_PROG >/dev/null; then
1875 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
1882 # query the given files extsize allocator hint in bytes (if any)
1889 if which $XFS_IO_PROG >/dev/null; then
1890 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
1891 awk '/^xattr.extsize =/ { print $3 }'`
1893 [ -z "$blocks" ] && blocks="0"
1897 # scratch_dev_pool should contain the disks pool for the btrfs raid
1898 _require_scratch_dev_pool()
1903 if [ -z "$SCRATCH_DEV_POOL" ]; then
1904 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
1907 if [ -z "$1" ]; then
1913 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
1917 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
1918 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
1922 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
1926 for i in $SCRATCH_DEV_POOL; do
1927 if [ "`_is_block_dev $i`" = "" ]; then
1928 _notrun "this test requires valid block disk $i"
1930 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
1931 _notrun "$i is part of TEST_DEV, this test requires unique disks"
1933 if _mount | grep -q $i; then
1934 if ! $UMOUNT_PROG $i; then
1935 echo "failed to unmount $i - aborting"
1939 # to help better debug when something fails, we remove
1940 # traces of previous btrfs FS on the dev.
1941 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
1945 # We will check if the device is deletable
1946 _require_deletable_scratch_dev_pool()
1950 for i in $SCRATCH_DEV_POOL; do
1951 x=`echo $i | cut -d"/" -f 3`
1952 if [ ! -f /sys/class/block/${x}/device/delete ]; then
1953 _notrun "$i is a device which is not deletable"
1958 # We check for btrfs and (optionally) features of the btrfs command
1962 _require_command $BTRFS_UTIL_PROG btrfs
1963 if [ -z "$1" ]; then
1966 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
1967 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
1970 # Check that fio is present, and it is able to execute given jobfile
1975 _require_command $FIO_PROG
1976 if [ -z "$1" ]; then
1980 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
1981 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
1984 # Does freeze work on this fs?
1987 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
1989 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
1990 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
1993 # arg 1 is dev to remove and is output of the below eg.
1994 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2000 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2002 stat $disk > /dev/null 2>&1
2003 while [ $? -eq 0 ]; do
2005 stat $disk > /dev/null 2>&1
2009 # arg 1 is dev to add and is output of the below eg.
2010 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2015 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2016 h=`echo ${1} | cut -d":" -f 1`
2017 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2019 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2024 if [ -z "$FSTRIM_PROG" ]; then
2025 _notrun "This test requires fstrim utility."
2029 _test_batched_discard()
2031 if [ $# -ne 1 ]; then
2032 echo "Usage: _test_batched_discard mnt_point" 1>&2
2036 $FSTRIM_PROG ${1} &>/dev/null
2041 if [ -z "$DUMPE2FS_PROG" ]; then
2042 _notrun "This test requires dumpe2fs utility."
2048 if [ ! -e /proc/self/uid_map ]; then
2049 _notrun "This test requires procfs uid_map support."
2051 if [ ! -e /proc/self/gid_map ]; then
2052 _notrun "This test requires procfs gid_map support."
2056 _require_cp_reflink()
2058 cp --help | grep -q reflink || \
2059 _notrun "This test requires a cp with --reflink support."
2064 FSSUM_PROG=$here/src/fssum
2065 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2068 # Given 2 files, verify that they have the same mapping but different
2069 # inodes - i.e. an undisturbed reflink
2070 # Silent if so, make noise if not
2073 # not a hard link or symlink?
2074 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2075 && echo "$1 and $2 are not reflinks: same inode number"
2078 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2079 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2080 || echo "$1 and $2 are not reflinks: different extents"
2085 _scratch_mkfs > /dev/null 2>&1
2086 _mount -t $FSTYP -o relatime $SCRATCH_DEV $SCRATCH_MNT || \
2087 _notrun "relatime not supported by the current kernel"
2091 _create_loop_device()
2094 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2098 _destroy_loop_device()
2101 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2104 _scale_fsstress_args()
2107 while [ $# -gt 0 ]; do
2109 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2110 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2111 *) args="$args $1" ;;
2119 # Return the logical block size if running on a block device,
2120 # else substitute the page size.
2122 _min_dio_alignment()
2126 if [ -b "$dev" ]; then
2127 blockdev --getss $dev
2129 $here/src/feature -s
2135 echo "# $@" >> $seqres.full 2>&1
2136 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2139 _run_btrfs_util_prog()
2141 run_check $BTRFS_UTIL_PROG $*
2144 _require_btrfs_send_stream_version()
2146 $BTRFS_UTIL_PROG send 2>&1 | \
2147 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2148 if [ $? -ne 0 ]; then
2149 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2155 if [ "$iam" == new ]
2159 # make some further configuration checks here
2160 if [ "$TEST_DEV" = "" ]
2162 echo "common/rc: Error: \$TEST_DEV is not set"
2166 # if $TEST_DEV is not mounted, mount it now as XFS
2167 if [ -z "`_fs_type $TEST_DEV`" ]
2169 # $TEST_DEV is not mounted
2172 echo "common/rc: retrying test device mount with external set"
2173 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2176 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2182 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2184 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2188 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2189 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2190 export XFS_IO_PROG="$XFS_IO_PROG -F"
2193 # get real device path name by following link
2197 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
2198 _dev=`readlink -f "$_dev"`
2203 # basename of a device
2206 echo `basename $(_real_dev $1)`
2211 ################################################################################
2212 # make sure this script returns success