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
321 _setup_large_xfs_fs()
326 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
327 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
328 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
330 # calculate the size of the file we need to allocate.
331 # Default free space in the FS is 50GB, but you can specify more via
332 # SCRATCH_DEV_EMPTY_SPACE
333 file_size=$(($fs_size - 50*1024*1024*1024))
334 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
336 # mount the filesystem, create the file, unmount it
337 _scratch_mount 2>&1 >$tmp_dir/mnt.err
339 if [ $status -ne 0 ]; then
341 cat $tmp_dir/mnt.err >&2
342 rm -f $tmp_dir/mnt.err
345 rm -f $tmp_dir/mnt.err
348 -c "truncate $file_size" \
349 -c "falloc -k 0 $file_size" \
351 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
352 export NUM_SPACE_FILES=1
355 if [ $status -ne 0 ]; then
356 echo "large file prealloc failed"
357 cat $tmp_dir/mnt.err >&2
363 _scratch_mkfs_xfs_opts()
367 _scratch_options mkfs
369 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
373 _scratch_mkfs_xfs_supported()
377 _scratch_options mkfs
379 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
384 # extra mkfs options can be added by tests
385 local extra_mkfs_options=$*
389 # save mkfs output in case conflict means we need to run again.
390 # only the output for the mkfs that applies should be shown
391 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
392 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
396 # a mkfs failure may be caused by conflicts between
397 # $MKFS_OPTIONS and $extra_mkfs_options
398 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
400 echo -n "** mkfs failed with extra mkfs options "
401 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
402 echo -n "** attempting to mkfs using only test $seq "
403 echo "options: $extra_mkfs_options **"
406 # running mkfs again. overwrite previous mkfs output files
407 _scratch_mkfs_xfs_opts $extra_mkfs_options \
408 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
412 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
413 # manually parse the mkfs output to get the fs size in bytes
415 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
416 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
418 print STDOUT "$size\n";
420 _setup_large_xfs_fs $fs_size
424 # output stored mkfs output
425 cat $tmp_dir.mkfserr >&2
427 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
432 # xfs_check script is planned to be deprecated. But, we want to
433 # be able to invoke "xfs_check" behavior in xfstests in order to
434 # maintain the current verification levels.
439 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
441 while getopts "b:fi:l:stvV" c
447 i) OPTS=$OPTS"-i "$OPTARG" ";;
448 b) OPTS=$OPTS"-b "$OPTARG" ";;
449 f) DBOPTS=$DBOPTS" -f";;
450 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
451 V) $XFS_DB_PROG -p xfs_check -V
459 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
469 _setup_large_ext4_fs()
474 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
475 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
476 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
478 # Default free space in the FS is 50GB, but you can specify more via
479 # SCRATCH_DEV_EMPTY_SPACE
480 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
482 # mount the filesystem and create 16TB - 4KB files until we consume
483 # all the necessary space.
484 _scratch_mount 2>&1 >$tmp_dir/mnt.err
486 if [ $status -ne 0 ]; then
488 cat $tmp_dir/mnt.err >&2
489 rm -f $tmp_dir/mnt.err
492 rm -f $tmp_dir/mnt.err
494 file_size=$((16*1024*1024*1024*1024 - 4096))
496 while [ $space_to_consume -gt $file_size ]; do
499 -c "truncate $file_size" \
500 -c "falloc -k 0 $file_size" \
501 $SCRATCH_MNT/.use_space.$nfiles 2>&1
503 if [ $status -ne 0 ]; then
507 space_to_consume=$(( $space_to_consume - $file_size ))
508 nfiles=$(($nfiles + 1))
511 # consume the remaining space.
512 if [ $space_to_consume -gt 0 ]; then
514 -c "truncate $space_to_consume" \
515 -c "falloc -k 0 $space_to_consume" \
516 $SCRATCH_MNT/.use_space.$nfiles 2>&1
519 export NUM_SPACE_FILES=$nfiles
522 if [ $status -ne 0 ]; then
523 echo "large file prealloc failed"
524 cat $tmp_dir/mnt.err >&2
533 /sbin/mkfs -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV \
534 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
537 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
538 # manually parse the mkfs output to get the fs size in bytes
539 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
540 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
541 / inodes, / { blks = $3 } \
542 /reserved for the super user/ { resv = $1 } \
543 END { fssize = bs * blks - resv; print fssize }'`
545 _setup_large_ext4_fs $fs_size
549 # output stored mkfs output
550 cat $tmp_dir.mkfserr >&2
552 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
567 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
570 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
573 _scratch_mkfs_ext4 $*
576 # do nothing for tmpfs
579 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
588 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
591 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
596 # Create fs of certain size on scratch device
597 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
598 _scratch_mkfs_sized()
602 [ -z "$blocksize" ] && blocksize=4096
605 if ! [[ $fssize =~ $re ]] ; then
606 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
608 if ! [[ $blocksize =~ $re ]] ; then
609 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
612 blocks=`expr $fssize / $blocksize`
614 if [ "$HOSTOS" == "Linux" ]; then
615 devsize=`blockdev --getsize64 $SCRATCH_DEV`
616 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
621 # don't override MKFS_OPTIONS that set a block size.
622 echo $MKFS_OPTIONS |egrep -q "b?size="
623 if [ $? -eq 0 ]; then
624 _scratch_mkfs_xfs -d size=$fssize
626 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
629 ext2|ext3|ext4|ext4dev)
630 yes | ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
633 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
636 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
639 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
644 # Emulate an N-data-disk stripe w/ various stripe units
645 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
651 [ -z "$blocksize" ] && blocksize=4096
653 let sunit_blocks=$sunit_bytes/$blocksize
654 let swidth_blocks=$sunit_blocks*$swidth_mult
658 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
661 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
664 _notrun "can't mkfs $FSTYP with geometry"
674 xfs_io -x -c "resblks $1" $SCRATCH_MNT
681 _scratch_xfs_db_options()
684 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
685 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
686 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
689 _scratch_xfs_logprint()
692 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
693 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
694 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
700 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
701 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
702 [ "$LARGE_SCRATCH_DEV" = yes ] && \
703 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
704 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
707 _scratch_xfs_repair()
710 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
711 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
712 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
713 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
714 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
715 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
722 echo "Usage: _get_pids_by_name process-name" 1>&2
726 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
727 # HH:MM:SS before the psargs field, use this as the search anchor.
729 # Matches with $1 (process-name) occur if the first psarg is $1
730 # or ends in /$1 ... the matching uses sed's regular expressions,
731 # so passing a regex into $1 will work.
739 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
740 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
743 # fix malloc libs output
747 # filter out the Electric Fence notice
750 if (defined $o && /^\s+Electric Fence/) {
756 print $o if (defined $o);
760 print $o if (defined $o);
764 # check if run as root
768 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
771 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
778 # _df_device : get an IRIX style df line for a given device
780 # - returns "" if not mounted
781 # - returns fs type in field two (ala IRIX)
782 # - joins line together if split by fancy df formatting
783 # - strips header etc
790 echo "Usage: _df_device device" 1>&2
794 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
795 match($1,what) && NF==1 {
809 # _df_dir : get an IRIX style df line for device where a directory resides
811 # - returns fs type in field two (ala IRIX)
812 # - joins line together if split by fancy df formatting
813 # - strips header etc
820 echo "Usage: _df_dir device" 1>&2
824 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
840 # return percentage used disk space for mounted device
846 echo "Usage: _used device" 1>&2
850 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
853 # return the FS type of a mounted device
859 echo "Usage: _fs_type device" 1>&2
864 # The Linux kernel shows NFSv4 filesystems in df output as
865 # filesystem type nfs4, although we mounted it as nfs earlier.
866 # Fix the filesystem type up here so that the callers don't
867 # have to bother with this quirk.
869 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
872 # return the FS mount options of a mounted device
874 # should write a version which just parses the output of mount for IRIX
875 # compatibility, but since this isn't used at all, at the moment I'll leave
882 echo "Usage: _fs_options device" 1>&2
886 $AWK_PROG -v dev=$1 '
887 match($1,dev) { print $4 }
891 # returns device number if a file is a block device
897 echo "Usage: _is_block_dev dev" 1>&2
902 if [ -L "${_dev}" ]; then
903 _dev=`readlink -f ${_dev}`
906 if [ -b "${_dev}" ]; then
907 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
911 # Do a command, log it to $seqres.full, optionally test return status
912 # and die if command fails. If called with one argument _do executes the
913 # command, logs it, and returns its exit status. With two arguments _do
914 # first prints the message passed in the first argument, and then "done"
915 # or "fail" depending on the return status of the command passed in the
916 # second argument. If the command fails and the variable _do_die_on_error
917 # is set to "always" or the two argument form is used and _do_die_on_error
918 # is set to "message_only" _do will print an error message to
919 # $seqres.out and exit.
923 if [ $# -eq 1 ]; then
925 elif [ $# -eq 2 ]; then
930 echo "Usage: _do [note] cmd" 1>&2
934 (eval "echo '---' \"$_cmd\"") >>$seqres.full
935 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
936 cat $tmp._out | _fix_malloc >>$seqres.full
937 if [ $# -eq 2 ]; then
938 if [ $ret -eq 0 ]; then
945 && [ "$_do_die_on_error" = "always" \
946 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
949 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
956 # bail out, setting up .notrun file
960 echo "$*" > $seqres.notrun
961 echo "$seq not run: $*"
966 # just plain bail out
970 echo "$*" | tee -a $seqres.full
971 echo "(see $seqres.full for details)"
976 # tests whether $FSTYP is one of the supported filesystems for a test
982 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
988 _notrun "not suitable for this filesystem type: $FSTYP"
991 # tests whether $FSTYP is one of the supported OSes for a test
997 if [ "$h" = "$HOSTOS" ]
1003 _notrun "not suitable for this OS: $HOSTOS"
1006 # this test needs a scratch partition - check we're ok & unmount it
1012 _notrun "requires a scratch device"
1015 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1017 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1021 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
1023 _notrun "this test requires a valid \$SCRATCH_DEV"
1025 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1027 _notrun "this test requires a valid \$SCRATCH_DEV"
1029 if [ ! -d "$SCRATCH_MNT" ]
1031 _notrun "this test requires a valid \$SCRATCH_MNT"
1037 if _mount | grep -q $SCRATCH_DEV
1039 # if it's mounted, make sure its on $SCRATCH_MNT
1040 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1042 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1045 # and then unmount it
1046 if ! $UMOUNT_PROG $SCRATCH_DEV
1048 echo "failed to unmount $SCRATCH_DEV"
1054 # this test needs a logdev
1058 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1059 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1060 [ "$USE_EXTERNAL" != yes ] && \
1061 _notrun "This test requires USE_EXTERNAL to be enabled"
1063 # ensure its not mounted
1064 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1067 # this test requires loopback device support
1071 if [ "$HOSTOS" != "Linux" ]
1073 _notrun "This test requires linux for loopback device support"
1076 modprobe loop >/dev/null 2>&1
1077 if grep loop /proc/devices >/dev/null 2>&1
1081 _notrun "This test requires loopback device support"
1085 # this test requires ext2 filesystem support
1089 if [ "$HOSTOS" != "Linux" ]
1091 _notrun "This test requires linux for ext2 filesystem support"
1094 modprobe ext2 >/dev/null 2>&1
1095 if grep ext2 /proc/filesystems >/dev/null 2>&1
1099 _notrun "This test requires ext2 filesystem support"
1103 # this test requires that (large) loopback device files are not in use
1105 _require_no_large_scratch_dev()
1107 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1108 _notrun "Large filesystem testing in progress, skipped this test"
1111 # this test requires that a realtime subvolume is in use, and
1112 # that the kernel supports realtime as well.
1116 [ "$USE_EXTERNAL" = yes ] || \
1117 _notrun "External volumes not in use, skipped this test"
1118 [ "$SCRATCH_RTDEV" = "" ] && \
1119 _notrun "Realtime device required, skipped this test"
1122 # this test requires that a specified command (executable) exists
1123 # $1 - command, $2 - name for error message
1127 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1128 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1131 # this test requires the device mapper flakey target
1133 _require_dm_flakey()
1135 _require_command $DMSETUP_PROG
1137 modprobe dm-flakey >/dev/null 2>&1
1138 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1143 _notrun "This test requires dm flakey support"
1147 # this test requires the projid32bit feature to be available in
1150 _require_projid32bit()
1152 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1153 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1156 # this test requires the crc feature to be available in mkfs.xfs
1158 _require_xfs_mkfs_crc()
1160 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1161 || _notrun "mkfs.xfs doesn't have crc feature"
1164 # this test requires the xfs kernel support crc feature
1168 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1 \
1169 _scratch_mount >/dev/null 2>&1 \
1170 || _notrun "Kernel doesn't support crc feature"
1174 # this test requires that external log/realtime devices are not in use
1176 _require_nonexternal()
1178 [ "$USE_EXTERNAL" = yes ] && \
1179 _notrun "External device testing in progress, skipped this test"
1182 # this test requires that a (specified) aio-dio executable exists
1183 # $1 - command (optional)
1189 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1190 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1192 AIO_TEST=src/aio-dio-regress/$1
1193 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1197 # run an aio-dio program
1203 echo "usage: _run_aiodio command_name" 2>&1
1209 local testtemp=$TEST_DIR/aio-testfile
1211 $AIO_TEST $testtemp 2>&1
1218 # indicate whether YP/NIS is active or not
1223 dn=$(domainname 2>/dev/null)
1224 test -n "${dn}" -a "${dn}" != "(none)"
1228 # cat the password file
1232 [ $(_yp_active) -eq 0 ] && ypcat passwd
1236 # cat the group file
1240 [ $(_yp_active) -eq 0 ] && ypcat group
1244 # check for the fsgqa user on the machine
1249 _cat_passwd | grep -q $qa_user
1250 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1251 echo /bin/true | su $qa_user
1252 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1255 # check for the fsgqa group on the machine
1260 _cat_group | grep -q $qa_group
1261 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1267 s,.*Permission\sdenied.*,Permission denied,;
1268 s,.*no\saccess\sto\stty.*,,;
1269 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1276 if [ "$HOSTOS" == "IRIX" ]
1278 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1280 echo $1 | su $qa_user 2>&1 | _filter_user_do
1284 # check that xfs_io, kernel, and filesystem all support zero
1285 _require_xfs_io_zero()
1287 testio=`$XFS_IO_PROG -c "zero help" 2>&1`
1288 echo $testio | grep -q 'command "zero" not found' && \
1289 _notrun "zero command not supported"
1292 # check that xfs_io, glibc, kernel, and filesystem all (!) support
1295 _require_xfs_io_falloc()
1297 testfile=$TEST_DIR/$$.falloc
1298 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1299 rm -f $testfile 2>&1 > /dev/null
1300 echo $testio | grep -q "not found" && \
1301 _notrun "xfs_io fallocate support is missing"
1302 echo $testio | grep -q "Operation not supported" && \
1303 _notrun "xfs_io fallocate command failed (old kernel/wrong fs?)"
1306 # check that xfs_io, kernel and filesystem all support fallocate with hole
1308 _require_xfs_io_falloc_punch()
1310 testfile=$TEST_DIR/$$.falloc
1311 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1312 -c "fpunch 4k 8k" $testfile 2>&1`
1313 rm -f $testfile 2>&1 > /dev/null
1314 echo $testio | grep -q "not found" && \
1315 _notrun "xfs_io fallocate punch support is missing"
1316 echo $testio | grep -q "Operation not supported" && \
1317 _notrun "xfs_io fallocate punch command failed (no fs support?)"
1320 # check that xfs_io, kernel and filesystem support fiemap
1321 _require_xfs_io_fiemap()
1323 testfile=$TEST_DIR/$$.fiemap
1324 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1325 -c "fiemap -v" $testfile 2>&1`
1326 rm -f $testfile 2>&1 > /dev/null
1327 echo $testio | grep -q "not found" && \
1328 _notrun "xfs_io fiemap support is missing"
1329 echo $testio | grep -q "Operation not supported" && \
1330 _notrun "xfs_io fiemap command failed (no fs support?)"
1333 # Check that a fs has enough free space (in 1024b blocks)
1338 BLOCKS=$2 # in units of 1024
1339 let GB=$BLOCKS/1024/1024
1341 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1342 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1343 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1347 # Check if the filesystem supports sparse files.
1349 # Unfortunately there is no better way to do this than a manual black list.
1351 _require_sparse_files()
1355 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1364 #boot_params always present in debugfs
1365 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1368 _require_fail_make_request()
1370 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1371 || _notrun "$DEBUGFS_MNT/fail_make_request \
1372 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1376 # Check if the file system supports seek_data/hole
1378 _require_seek_data_hole()
1380 testfile=$TEST_DIR/$$.seek
1381 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1382 rm -f $testfile &>/dev/null
1383 echo $testseek | grep -q "Kernel does not support" && \
1384 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1387 # check that a FS on a device is mounted
1388 # if so, return mount point
1394 echo "Usage: _is_mounted device" 1>&2
1400 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1401 pattern { print $3 ; exit 0 }
1405 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1410 # remount a FS to a new mode (ro or rw)
1416 echo "Usage: _remount device ro/rw" 1>&2
1422 if ! mount -o remount,$mode $device
1424 echo "_remount: failed to remount filesystem on $device as $mode"
1429 # Run the appropriate repair/check on a filesystem
1431 # if the filesystem is mounted, it's either remounted ro before being
1432 # checked or it's unmounted and then remounted
1435 # If set, we remount ro instead of unmounting for fsck
1438 _umount_or_remount_ro()
1442 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1447 mountpoint=`_is_mounted $device`
1449 if [ $USE_REMOUNT -eq 0 ]; then
1450 $UMOUNT_PROG $device
1457 _mount_or_remount_rw()
1461 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1468 if [ $USE_REMOUNT -eq 0 ]
1470 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1472 echo "!!! failed to remount $device on $mountpoint"
1482 # Check a generic filesystem in no-op mode; this assumes that the
1483 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1484 # and that it will still return an errno for corruption in this mode.
1486 # Filesystems which don't support this will need to define their
1487 # own check routine.
1489 _check_generic_filesystem()
1493 # If type is set, we're mounted
1494 type=`_fs_type $device`
1497 if [ "$type" = "$FSTYP" ]
1500 mountpoint=`_umount_or_remount_ro $device`
1503 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1506 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1508 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1509 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1510 cat $tmp.fsck >>$seqres.full
1511 echo "*** end fsck.$FSTYP output" >>$seqres.full
1519 echo "*** mount output ***" >>$seqres.full
1520 _mount >>$seqres.full
1521 echo "*** end mount output" >>$seqres.full
1522 elif [ "$type" = "$FSTYP" ]
1525 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1529 if [ $ok -eq 0 ]; then
1537 # run xfs_check and friends on a FS.
1539 _check_xfs_filesystem()
1543 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1547 extra_mount_options=""
1549 if [ "$2" != "none" ]; then
1550 extra_log_options="-l$2"
1551 extra_mount_options="-ologdev=$2"
1554 if [ "$3" != "none" ]; then
1555 extra_rt_options="-r$3"
1556 extra_mount_options=$extra_mount_options" -ortdev=$3"
1558 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1560 [ "$FSTYP" != xfs ] && return 0
1562 type=`_fs_type $device`
1565 if [ "$type" = "xfs" ]
1568 mountpoint=`_umount_or_remount_ro $device`
1571 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1572 | tee $tmp.logprint | grep -q "<CLEAN>"
1573 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1575 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1577 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1578 echo "*** xfs_logprint -t output ***" >>$seqres.full
1579 cat $tmp.logprint >>$seqres.full
1580 echo "*** end xfs_logprint output" >>$seqres.full
1585 # xfs_check runs out of memory on large files, so even providing the test
1586 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1587 # large filesystems. Avoid it.
1588 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1589 _xfs_check $extra_log_options $device 2>&1 |\
1590 _fix_malloc >$tmp.fs_check
1592 if [ -s $tmp.fs_check ]
1594 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1596 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1597 echo "*** xfs_check output ***" >>$seqres.full
1598 cat $tmp.fs_check >>$seqres.full
1599 echo "*** end xfs_check output" >>$seqres.full
1604 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1607 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1609 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1610 echo "*** xfs_repair -n output ***" >>$seqres.full
1611 cat $tmp.repair | _fix_malloc >>$seqres.full
1612 echo "*** end xfs_repair output" >>$seqres.full
1616 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1620 echo "*** mount output ***" >>$seqres.full
1621 _mount >>$seqres.full
1622 echo "*** end mount output" >>$seqres.full
1623 elif [ "$type" = "xfs" ]
1625 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1628 if [ $ok -eq 0 ]; then
1636 # Filter the knowen errors the UDF Verifier reports.
1637 _udf_test_known_error_filter()
1639 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."
1643 _check_udf_filesystem()
1645 [ "$DISABLE_UDF_TEST" == "1" ] && return
1647 if [ $# -ne 1 -a $# -ne 2 ]
1649 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1653 if [ ! -x $here/src/udf_test ]
1655 echo "udf_test not installed, please download and build the Philips"
1656 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1657 echo "Then copy the udf_test binary to $here/src/."
1658 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1666 LAST_BLOCK=`expr \( $2 - 1 \)`
1667 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1670 rm -f $seqres.checkfs
1671 sleep 1 # Due to a problem with time stamps in udf_test
1672 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1673 _udf_test_known_error_filter | \
1674 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1675 echo "Warning UDF Verifier reported errors see $seqres.checkfs."
1678 _check_xfs_test_fs()
1682 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1683 TEST_LOG="$TEST_LOGDEV"
1685 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1686 TEST_RT="$TEST_RTDEV"
1688 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1690 # check for ipath consistency
1691 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1692 # errors go to stderr
1693 xfs_check_ipaths $TEST_DIR >/dev/null
1694 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1698 _check_btrfs_filesystem()
1702 # If type is set, we're mounted
1703 type=`_fs_type $device`
1706 if [ "$type" = "$FSTYP" ]
1709 mountpoint=`_umount_or_remount_ro $device`
1712 btrfsck $device >$tmp.fsck 2>&1
1715 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1717 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1718 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1719 cat $tmp.fsck >>$seqres.full
1720 echo "*** end fsck.$FSTYP output" >>$seqres.full
1728 echo "*** mount output ***" >>$seqres.full
1729 _mount >>$seqres.full
1730 echo "*** end mount output" >>$seqres.full
1731 elif [ "$type" = "$FSTYP" ]
1734 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1738 if [ $ok -eq 0 ]; then
1753 # no way to check consistency for nfs
1756 # do nothing for now
1759 _check_btrfs_filesystem $TEST_DEV
1762 # no way to check consistency for tmpfs
1765 _check_generic_filesystem $TEST_DEV
1773 [ $# -eq 1 ] && device=$1
1779 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1780 SCRATCH_LOG="$SCRATCH_LOGDEV"
1782 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1783 SCRATCH_RT="$SCRATCH_RTDEV"
1785 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
1788 _check_udf_filesystem $device $udf_fsize
1791 # Don't know how to check an NFS filesystem, yet.
1794 _check_btrfs_filesystem $device
1797 # no way to check consistency for tmpfs
1800 _check_generic_filesystem $device
1805 _full_fstyp_details()
1807 [ -z "$FSTYP" ] && FSTYP=xfs
1808 if [ $FSTYP = xfs ]; then
1809 if [ -d /proc/fs/xfs ]; then
1810 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1811 FSTYP="$FSTYP (non-debug)"
1812 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1813 FSTYP="$FSTYP (debug)"
1816 if uname -a | grep -qi 'debug'; then
1817 FSTYP="$FSTYP (debug)"
1819 FSTYP="$FSTYP (non-debug)"
1826 _full_platform_details()
1832 echo "$os/$platform $host $kernel"
1837 if [ -z "$1" -o -z "$2" ]; then
1838 echo Error must pass src and dst.
1842 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1844 elif [ "`uname`" == "Linux" ]; then
1847 echo Error test $seq does not run on the operating system: `uname`
1858 #takes files, randomdata
1866 if [ $size -gt 0 ]; then
1867 if [ "$2" == "false" ]; then
1868 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
1870 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
1877 # takes dirname, depth, randomdata
1880 dirname=$1; depth=$2; randomdata=$3
1881 mkdir $dirname || die "mkdir $dirname failed"
1884 _nfiles $files $randomdata # files for this dir and data type
1886 [ $depth -eq 0 ] && return
1887 let deep=$depth-1 # go 1 down
1889 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
1892 while [ $d -lt $dirs ]
1894 _descend d$d $deep &
1900 # Populate a filesystem with inodes for performance experiments
1902 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
1907 dirs=5 # ndirs in each subdir till leaves
1908 size=0 # sizeof files in K
1909 files=100 # num files in _each_ subdir
1910 depth=2 # depth of tree from root to leaves
1912 root=root # path of initial root of directory tree
1913 randomdata=false # -x data type urandom or zero
1916 while getopts "d:f:n:r:s:v:x" c
1925 x) randomdata=true;;
1929 _descend $root $depth $randomdata
1934 [ $verbose = true ] && echo done
1937 # query whether the given file has the given inode flag set
1944 if which $XFS_IO_PROG >/dev/null; then
1945 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
1952 # query the given files extsize allocator hint in bytes (if any)
1959 if which $XFS_IO_PROG >/dev/null; then
1960 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
1961 awk '/^xattr.extsize =/ { print $3 }'`
1963 [ -z "$blocks" ] && blocks="0"
1967 # scratch_dev_pool should contain the disks pool for the btrfs raid
1968 _require_scratch_dev_pool()
1973 if [ -z "$SCRATCH_DEV_POOL" ]; then
1974 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
1977 if [ -z "$1" ]; then
1983 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
1987 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
1988 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
1992 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
1996 for i in $SCRATCH_DEV_POOL; do
1997 if [ "`_is_block_dev $i`" = "" ]; then
1998 _notrun "this test requires valid block disk $i"
2000 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
2001 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2003 if _mount | grep -q $i; then
2004 if ! $UMOUNT_PROG $i; then
2005 echo "failed to unmount $i - aborting"
2009 # to help better debug when something fails, we remove
2010 # traces of previous btrfs FS on the dev.
2011 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2015 # We will check if the device is deletable
2016 _require_deletable_scratch_dev_pool()
2020 for i in $SCRATCH_DEV_POOL; do
2021 x=`echo $i | cut -d"/" -f 3`
2022 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2023 _notrun "$i is a device which is not deletable"
2028 # We check for btrfs and (optionally) features of the btrfs command
2032 _require_command $BTRFS_UTIL_PROG btrfs
2033 if [ -z "$1" ]; then
2036 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2037 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2040 # Check that fio is present, and it is able to execute given jobfile
2045 _require_command $FIO_PROG
2046 if [ -z "$1" ]; then
2050 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2051 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2054 # Does freeze work on this fs?
2057 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2059 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2060 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2063 # arg 1 is dev to remove and is output of the below eg.
2064 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2070 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2072 stat $disk > /dev/null 2>&1
2073 while [ $? -eq 0 ]; do
2075 stat $disk > /dev/null 2>&1
2079 # arg 1 is dev to add and is output of the below eg.
2080 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2085 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2086 h=`echo ${1} | cut -d":" -f 1`
2087 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2089 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2094 if [ -z "$FSTRIM_PROG" ]; then
2095 _notrun "This test requires fstrim utility."
2099 _test_batched_discard()
2101 if [ $# -ne 1 ]; then
2102 echo "Usage: _test_batched_discard mnt_point" 1>&2
2106 $FSTRIM_PROG ${1} &>/dev/null
2111 if [ -z "$DUMPE2FS_PROG" ]; then
2112 _notrun "This test requires dumpe2fs utility."
2118 if [ ! -e /proc/self/uid_map ]; then
2119 _notrun "This test requires procfs uid_map support."
2121 if [ ! -e /proc/self/gid_map ]; then
2122 _notrun "This test requires procfs gid_map support."
2126 _require_cp_reflink()
2128 cp --help | grep -q reflink || \
2129 _notrun "This test requires a cp with --reflink support."
2132 # Given 2 files, verify that they have the same mapping but different
2133 # inodes - i.e. an undisturbed reflink
2134 # Silent if so, make noise if not
2137 # not a hard link or symlink?
2138 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2139 && echo "$1 and $2 are not reflinks: same inode number"
2142 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2143 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2144 || echo "$1 and $2 are not reflinks: different extents"
2147 _create_loop_device()
2150 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2154 _destroy_loop_device()
2157 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2160 _scale_fsstress_args()
2163 while [ $# -gt 0 ]; do
2165 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2166 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2167 *) args="$args $1" ;;
2175 # Return the logical block size if running on a block device,
2176 # else substitute the page size.
2178 _min_dio_alignment()
2182 if [ -b "$dev" ]; then
2183 blockdev --getss $dev
2185 $here/src/feature -s
2191 echo "# $@" >> $seqres.full 2>&1
2192 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2197 if [ "$iam" == new ]
2201 # make some further configuration checks here
2202 if [ "$TEST_DEV" = "" ]
2204 echo "common/rc: Error: \$TEST_DEV is not set"
2208 # if $TEST_DEV is not mounted, mount it now as XFS
2209 if [ -z "`_fs_type $TEST_DEV`" ]
2211 # $TEST_DEV is not mounted
2214 echo "common/rc: retrying test device mount with external set"
2215 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2218 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2224 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2226 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2230 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2231 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2232 export XFS_IO_PROG="$XFS_IO_PROG -F"
2237 ################################################################################
2238 # make sure this script returns success