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 $@
60 # ls -l w/ selinux sometimes puts a dot at the end:
61 # -rwxrw-r--. id1 id2 file1
65 ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /"
70 # SELinux adds extra xattrs which can mess up our expected output.
71 # So, mount with a context, and they won't be created
72 # nfs_t is a "liberal" context so we can use it.
73 if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
74 SELINUX_MOUNT_OPTIONS="-o context=system_u:object_r:nfs_t:s0"
75 export SELINUX_MOUNT_OPTIONS
80 export MOUNT_OPTIONS=$XFS_MOUNT_OPTIONS
83 export MOUNT_OPTIONS=$UDF_MOUNT_OPTIONS
86 export MOUNT_OPTIONS=$NFS_MOUNT_OPTIONS
88 ext2|ext3|ext4|ext4dev)
89 # acls & xattrs aren't turned on by default on ext$FOO
90 export MOUNT_OPTIONS="-o acl,user_xattr $EXT_MOUNT_OPTIONS"
93 # acls & xattrs aren't turned on by default on reiserfs
94 export MOUNT_OPTIONS="-o acl,user_xattr $REISERFS_MOUNT_OPTIONS"
97 # acls aren't turned on by default on gfs2
98 export MOUNT_OPTIONS="-o acl $GFS2_MOUNT_OPTIONS"
109 export MKFS_OPTIONS=$XFS_MKFS_OPTIONS
112 [ ! -z "$udf_fsize" ] && \
113 UDF_MKFS_OPTIONS="$UDF_MKFS_OPTIONS -s $udf_fsize"
114 export MKFS_OPTIONS=$UDF_MKFS_OPTIONS
117 export MKFS_OPTIONS=$NFS_MKFS_OPTIONS
120 export MKFS_OPTIONS="$REISERFS_MKFS_OPTIONS -q"
123 export MKFS_OPTIONS="$GFS2_MKFS_OPTIONS -O -p lock_nolock"
126 export MKFS_OPTIONS="$JFS_MKFS_OPTIONS -q"
136 ext2|ext3|ext4|ext4dev)
137 export FSCK_OPTIONS="-nf"
140 export FSCK_OPTIONS="--yes"
143 export FSCK_OPTIONS="-n"
148 [ -z "$FSTYP" ] && FSTYP=xfs
149 [ -z "$MOUNT_OPTIONS" ] && _mount_opts
150 [ -z "$MKFS_OPTIONS" ] && _mkfs_opts
151 [ -z "$FSCK_OPTIONS" ] && _fsck_opts
154 # we need common.config
155 if [ "$iam" != "check" ]
157 if ! . ./common.config
159 echo "$iam: failed to source common.config"
164 # make sure we have a standard umask
169 $MOUNT_PROG `_mount_ops_filter $*`
177 if [ "$FSTYP" != "xfs" ]; then
183 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
192 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
193 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
194 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
195 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
203 if [ "$FSTYP" != "xfs" ]; then
217 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
218 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
219 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
220 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
227 #get mount point to handle dmapi mtpt option correctly
229 [ $last_index -gt 0 ] && shift $last_index
232 # irix is fussy about how it is fed its mount options
233 # - multiple -o's are not allowed
234 # - no spaces between comma delimitered options
235 # the sed script replaces all -o's (except the first) with a comma
236 # not required for linux, but won't hurt
238 echo $params | sed -e 's/[[:space:]]*-o[[:space:]]*/UnIqUe/1; s/[[:space:]]*-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
239 | sed -e 's/dmapi/dmi/' \
240 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
244 _scratch_mount_options()
246 _scratch_options mount
248 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
253 _mount -t $FSTYP `_scratch_mount_options $*`
258 $UMOUNT_PROG $SCRATCH_DEV
270 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
273 _scratch_mkfs_options()
275 _scratch_options mkfs
276 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
281 # extra mkfs options can be added by tests
282 local extra_mkfs_options=$*
286 _scratch_options mkfs
288 # save mkfs output in case conflict means we need to run again.
289 # only the output for the mkfs that applies should be shown
290 $MKFS_XFS_PROG $SCRATCH_OPTIONS $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
291 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
294 # a mkfs failure may be caused by conflicts between
295 # $MKFS_OPTIONS and $extra_mkfs_options
297 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
298 echo "** mkfs failed with extra mkfs options added to \"$MKFS_OPTIONS\" by test $seq **" \
300 echo "** attempting to mkfs using only test $seq options: $extra_mkfs_options **" \
302 # running mkfs again. overwrite previous mkfs output files
303 $MKFS_XFS_PROG $SCRATCH_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
304 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
308 # output stored mkfs output
309 cat $tmp_dir.mkfserr >&2
311 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
313 if [ "$USE_BIG_LOOPFS" = yes ]; then
314 [ -z "$RETAIN_AG_BYTES" ] && RETAIN_AG_BYTES=0
315 ./tools/ag-wipe -q -r $RETAIN_AG_BYTES $SCRATCH_DEV
331 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
334 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
337 /sbin/mkfs -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
342 # Create fs of certain size on scratch device
343 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
344 _scratch_mkfs_sized()
348 [ -z "$blocksize" ] && blocksize=4096
349 blocks=`expr $fssize / $blocksize`
353 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
355 ext2|ext3|ext4|ext4dev)
356 /sbin/mkfs.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
359 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
362 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
367 # Emulate an N-data-disk stripe w/ various stripe units
368 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
374 [ -z "$blocksize" ] && blocksize=4096
376 let sunit_blocks=$sunit_bytes/$blocksize
377 let swidth_blocks=$sunit_blocks*$swidth_mult
381 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
384 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
387 _notrun "can't mkfs $FSTYP with geometry"
397 xfs_io -x -c "resblks $1" $SCRATCH_MNT
404 _scratch_xfs_db_options()
407 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
408 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
409 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
412 _scratch_xfs_logprint()
415 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
416 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
417 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
423 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
424 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
425 $XFS_CHECK_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
428 _scratch_xfs_repair()
431 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
432 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
433 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
434 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
435 [ "$USE_BIG_LOOPFS" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
436 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
443 echo "Usage: _get_pids_by_name process-name" 1>&2
447 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
448 # HH:MM:SS before the psargs field, use this as the search anchor.
450 # Matches with $1 (process-name) occur if the first psarg is $1
451 # or ends in /$1 ... the matching uses sed's regular expressions,
452 # so passing a regex into $1 will work.
460 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
461 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
464 # fix malloc libs output
468 # filter out the Electric Fence notice
471 if (defined $o && /^\s+Electric Fence/) {
477 print $o if (defined $o);
481 print $o if (defined $o);
485 # check if run as root
489 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
492 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
499 # _df_device : get an IRIX style df line for a given device
501 # - returns "" if not mounted
502 # - returns fs type in field two (ala IRIX)
503 # - joins line together if split by fancy df formatting
504 # - strips header etc
511 echo "Usage: _df_device device" 1>&2
515 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
516 match($1,what) && NF==1 {
530 # _df_dir : get an IRIX style df line for device where a directory resides
532 # - returns fs type in field two (ala IRIX)
533 # - joins line together if split by fancy df formatting
534 # - strips header etc
541 echo "Usage: _df_dir device" 1>&2
545 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
561 # return percentage used disk space for mounted device
567 echo "Usage: _used device" 1>&2
571 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
574 # return the FS type of a mounted device
580 echo "Usage: _fs_type device" 1>&2
585 # The Linux kernel shows NFSv4 filesystems in df output as
586 # filesystem type nfs4, although we mounted it as nfs earlier.
587 # Fix the filesystem type up here so that the callers don't
588 # have to bother with this quirk.
590 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
593 # return the FS mount options of a mounted device
595 # should write a version which just parses the output of mount for IRIX
596 # compatibility, but since this isn't used at all, at the moment I'll leave
603 echo "Usage: _fs_options device" 1>&2
607 $AWK_PROG -v dev=$1 '
608 match($1,dev) { print $4 }
612 # returns device number if a file is a block device
618 echo "Usage: _is_block_dev dev" 1>&2
623 if [ -L "${_dev}" ]; then
624 _dev=`readlink -f ${_dev}`
627 if [ -b "${_dev}" ]; then
628 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
632 # Do a command, log it to $seq.full, optionally test return status
633 # and die if command fails. If called with one argument _do executes the
634 # command, logs it, and returns its exit status. With two arguments _do
635 # first prints the message passed in the first argument, and then "done"
636 # or "fail" depending on the return status of the command passed in the
637 # second argument. If the command fails and the variable _do_die_on_error
638 # is set to "always" or the two argument form is used and _do_die_on_error
639 # is set to "message_only" _do will print an error message to
644 if [ $# -eq 1 ]; then
646 elif [ $# -eq 2 ]; then
651 echo "Usage: _do [note] cmd" 1>&2
655 (eval "echo '---' \"$_cmd\"") >>$here/$seq.full
656 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
657 cat $tmp._out | _fix_malloc >>$here/$seq.full
658 if [ $# -eq 2 ]; then
659 if [ $ret -eq 0 ]; then
666 && [ "$_do_die_on_error" = "always" \
667 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
670 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
677 # bail out, setting up .notrun file
681 echo "$*" >$seq.notrun
682 echo "$seq not run: $*"
687 # just plain bail out
691 echo "$*" | tee -a $here/$seq.full
692 echo "(see $seq.full for details)"
697 # tests whether $FSTYP is one of the supported filesystems for a test
703 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
709 _notrun "not suitable for this filesystem type: $FSTYP"
712 # tests whether $FSTYP is one of the supported OSes for a test
718 if [ "$h" = "$HOSTOS" ]
724 _notrun "not suitable for this OS: $HOSTOS"
727 # this test needs a scratch partition - check we're ok & unmount it
733 echo $SCRATCH_DEV | grep -q ":" > /dev/null 2>&1
734 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]
736 _notrun "this test requires a valid \$SCRATCH_DEV"
740 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
742 _notrun "this test requires a valid \$SCRATCH_DEV"
744 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
746 _notrun "this test requires a valid \$SCRATCH_DEV"
748 if [ ! -d "$SCRATCH_MNT" ]
750 _notrun "this test requires a valid \$SCRATCH_MNT"
756 if _mount | grep -q $SCRATCH_DEV
758 # if it's mounted, make sure its on $SCRATCH_MNT
759 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
761 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
764 # and then unmount it
765 if ! $UMOUNT_PROG $SCRATCH_DEV
767 echo "failed to unmount $SCRATCH_DEV"
773 # this test needs a logdev
777 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
778 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
779 [ "$USE_EXTERNAL" != yes ] && \
780 _notrun "This test requires USE_EXTERNAL to be enabled"
782 # ensure its not mounted
783 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
786 # this test requires loopback device support
790 if [ "$HOSTOS" != "Linux" ]
792 _notrun "This test requires linux for loopback device support"
795 modprobe loop >/dev/null 2>&1
796 if grep loop /proc/devices >/dev/null 2>&1
800 _notrun "This test requires loopback device support"
804 # this test requires ext2 filesystem support
808 if [ "$HOSTOS" != "Linux" ]
810 _notrun "This test requires linux for ext2 filesystem support"
813 modprobe ext2 >/dev/null 2>&1
814 if grep ext2 /proc/filesystems >/dev/null 2>&1
818 _notrun "This test requires ext2 filesystem support"
822 # this test requires that (large) loopback device files are not in use
824 _require_nobigloopfs()
826 [ "$USE_BIG_LOOPFS" = yes ] && \
827 _notrun "Large filesystem testing in progress, skipped this test"
830 # this test requires that a realtime subvolume is in use, and
831 # that the kernel supports realtime as well.
835 [ "$USE_EXTERNAL" = yes ] || \
836 _notrun "External volumes not in use, skipped this test"
837 [ "$SCRATCH_RTDEV" = "" ] && \
838 _notrun "Realtime device required, skipped this test"
841 # this test requires that a specified command (executable) exists
842 # $1 - command, $2 - name for error message
846 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
847 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
850 # this test requires the projid32bit feature to be available in
853 _require_projid32bit()
855 _scratch_mkfs_xfs -f -i projid32bit=0 2>&1 >/dev/null \
856 || _notrun "mkfs.xfs doesn't have projid32bit feature"
859 # this test requires that external log/realtime devices are not in use
861 _require_nonexternal()
863 [ "$USE_EXTERNAL" = yes ] && \
864 _notrun "External device testing in progress, skipped this test"
867 # this test requires that a (specified) aio-dio executable exists
868 # $1 - command (optional)
874 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
875 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
877 AIO_TEST=src/aio-dio-regress/$1
878 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
882 # run an aio-dio program
888 echo "usage: _run_aiodio command_name" 2>&1
894 local testtemp=$TEST_DIR/aio-testfile
896 $AIO_TEST $testtemp 2>&1
903 # indicate whether YP/NIS is active or not
908 dn=$(domainname 2>/dev/null)
909 test -n "${dn}" -a "${dn}" != "(none)"
913 # cat the password file
917 [ $(_yp_active) -eq 0 ] && ypcat passwd
925 [ $(_yp_active) -eq 0 ] && ypcat group
929 # check for the fsgqa user on the machine
934 _cat_passwd | grep -q $qa_user
935 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
936 echo /bin/true | su $qa_user
937 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
943 s,.*Permission\sdenied.*,Permission denied,;
944 s,.*no\saccess\sto\stty.*,,;
945 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
952 if [ "$HOSTOS" == "IRIX" ]
954 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
956 echo $1 | su $qa_user 2>&1 | _filter_user_do
960 # check that xfs_io, glibc, kernel, and filesystem all (!) support
963 _require_xfs_io_falloc()
965 testfile=$TEST_DIR/$$.falloc
966 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
967 rm -f $testfile 2>&1 > /dev/null
968 echo $testio | grep -q "not found" && \
969 _notrun "xfs_io fallocate support is missing"
970 echo $testio | grep -q "Operation not supported" && \
971 _notrun "xfs_io fallocate command failed (old kernel/wrong fs?)"
974 # check that xfs_io, kernel and filesystem all support fallocate with hole
976 _require_xfs_io_falloc_punch()
978 testfile=$TEST_DIR/$$.falloc
979 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
980 -c "fpunch 4k 8k" $testfile 2>&1`
981 rm -f $testfile 2>&1 > /dev/null
982 echo $testio | grep -q "not found" && \
983 _notrun "xfs_io fallocate punch support is missing"
984 echo $testio | grep -q "Operation not supported" && \
985 _notrun "xfs_io fallocate punch command failed (no fs support?)"
988 # check that xfs_io, kernel and filesystem support fiemap
989 _require_xfs_io_fiemap()
991 testfile=$TEST_DIR/$$.fiemap
992 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
993 -c "fiemap -v" $testfile 2>&1`
994 rm -f $testfile 2>&1 > /dev/null
995 echo $testio | grep -q "not found" && \
996 _notrun "xfs_io fiemap support is missing"
997 echo $testio | grep -q "Operation not supported" && \
998 _notrun "xfs_io fiemap command failed (no fs support?)"
1001 # Check that a fs has enough free space (in 1024b blocks)
1006 BLOCKS=$2 # in units of 1024
1007 let GB=$BLOCKS/1024/1024
1009 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1010 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1011 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1015 # Check if the filesystem supports sparse files.
1017 # Unfortunately there is no better way to do this than a manual black list.
1019 _require_sparse_files()
1023 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1030 # check that a FS on a device is mounted
1031 # if so, return mount point
1037 echo "Usage: _is_mounted device" 1>&2
1043 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1044 pattern { print $3 ; exit 0 }
1048 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1053 # remount a FS to a new mode (ro or rw)
1059 echo "Usage: _remount device ro/rw" 1>&2
1065 if ! mount -o remount,$mode $device
1067 echo "_remount: failed to remount filesystem on $device as $mode"
1072 # Run the appropriate repair/check on a filesystem
1074 # if the filesystem is mounted, it's either remounted ro before being
1075 # checked or it's unmounted and then remounted
1078 # If set, we remount ro instead of unmounting for fsck
1081 _umount_or_remount_ro()
1085 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1090 mountpoint=`_is_mounted $device`
1092 if [ $USE_REMOUNT -eq 0 ]; then
1093 $UMOUNT_PROG $device
1100 _mount_or_remount_rw()
1104 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1111 if [ $USE_REMOUNT -eq 0 ]
1113 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1115 echo "!!! failed to remount $device on $mountpoint"
1125 # Check a generic filesystem in no-op mode; this assumes that the
1126 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1127 # and that it will still return an errno for corruption in this mode.
1129 # Filesystems which don't support this will need to define their
1130 # own check routine.
1132 _check_generic_filesystem()
1136 # If type is set, we're mounted
1137 type=`_fs_type $device`
1140 if [ "$type" = "$FSTYP" ]
1143 mountpoint=`_umount_or_remount_ro $device`
1146 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1149 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seq.full)"
1151 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$here/$seq.full
1152 echo "*** fsck.$FSTYP output ***" >>$here/$seq.full
1153 cat $tmp.fsck >>$here/$seq.full
1154 echo "*** end fsck.$FSTYP output" >>$here/$seq.full
1162 echo "*** mount output ***" >>$here/$seq.full
1163 _mount >>$here/$seq.full
1164 echo "*** end mount output" >>$here/$seq.full
1165 elif [ "$type" = "$FSTYP" ]
1168 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1172 if [ $ok -eq 0 ]; then
1180 # run xfs_check and friends on a FS.
1182 _check_xfs_filesystem()
1186 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1190 extra_mount_options=""
1192 if [ "$2" != "none" ]; then
1193 extra_log_options="-l$2"
1194 extra_mount_options="-ologdev=$2"
1197 if [ "$3" != "none" ]; then
1198 extra_rt_options="-r$3"
1199 extra_mount_options=$extra_mount_options" -ortdev=$3"
1201 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1203 [ "$FSTYP" != xfs ] && return 0
1205 [ "$USE_BIG_LOOPFS" = yes ] && testoption=-t
1207 type=`_fs_type $device`
1210 if [ "$type" = "xfs" ]
1213 mountpoint=`_umount_or_remount_ro $device`
1216 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1217 | tee $tmp.logprint | grep -q "<CLEAN>"
1218 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1220 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seq.full)"
1222 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$here/$seq.full
1223 echo "*** xfs_logprint -t output ***" >>$here/$seq.full
1224 cat $tmp.logprint >>$here/$seq.full
1225 echo "*** end xfs_logprint output" >>$here/$seq.full
1230 $XFS_CHECK_PROG $testoption $extra_log_options $device 2>&1 |\
1231 _fix_malloc >$tmp.fs_check
1232 if [ -s $tmp.fs_check ]
1234 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seq.full)"
1236 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$here/$seq.full
1237 echo "*** xfs_check output ***" >>$here/$seq.full
1238 cat $tmp.fs_check >>$here/$seq.full
1239 echo "*** end xfs_check output" >>$here/$seq.full
1243 # repair doesn't scale massively at this stage, optionally skip it for now
1244 [ "$USE_BIG_LOOPFS" = yes ] || \
1245 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1248 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seq.full)"
1250 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$here/$seq.full
1251 echo "*** xfs_repair -n output ***" >>$here/$seq.full
1252 cat $tmp.repair | _fix_malloc >>$here/$seq.full
1253 echo "*** end xfs_repair output" >>$here/$seq.full
1257 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1261 echo "*** mount output ***" >>$here/$seq.full
1262 _mount >>$here/$seq.full
1263 echo "*** end mount output" >>$here/$seq.full
1264 elif [ "$type" = "xfs" ]
1266 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1269 if [ $ok -eq 0 ]; then
1277 # Filter the knowen errors the UDF Verifier reports.
1278 _udf_test_known_error_filter()
1280 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."
1284 _check_udf_filesystem()
1286 [ "$DISABLE_UDF_TEST" == "1" ] && return
1288 if [ $# -ne 1 -a $# -ne 2 ]
1290 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1294 if [ ! -x $here/src/udf_test ]
1296 echo "udf_test not installed, please download and build the Philips"
1297 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1298 echo "Then copy the udf_test binary to $here/src/."
1299 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1307 LAST_BLOCK=`expr \( $2 - 1 \)`
1308 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1312 sleep 1 # Due to a problem with time stamps in udf_test
1313 $here/src/udf_test $OPT_ARG $device | tee $here/$seq.checkfs | egrep "Error|Warning" | \
1314 _udf_test_known_error_filter | \
1315 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" | \
1316 sed "s/^.*$/Warning UDF Verifier reported errors see $seq.checkfs./g"
1320 _check_xfs_test_fs()
1324 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1325 TEST_LOG="$TEST_LOGDEV"
1327 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1328 TEST_RT="$TEST_RTDEV"
1330 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1332 # check for ipath consistency
1333 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1334 # errors go to stderr
1335 xfs_check_ipaths $TEST_DIR >/dev/null
1336 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1340 _check_btrfs_filesystem()
1344 # If type is set, we're mounted
1345 type=`_fs_type $device`
1348 if [ "$type" = "$FSTYP" ]
1351 mountpoint=`_umount_or_remount_ro $device`
1354 btrfsck $device >$tmp.fsck 2>&1
1357 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seq.full)"
1359 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$here/$seq.full
1360 echo "*** fsck.$FSTYP output ***" >>$here/$seq.full
1361 cat $tmp.fsck >>$here/$seq.full
1362 echo "*** end fsck.$FSTYP output" >>$here/$seq.full
1370 echo "*** mount output ***" >>$here/$seq.full
1371 _mount >>$here/$seq.full
1372 echo "*** end mount output" >>$here/$seq.full
1373 elif [ "$type" = "$FSTYP" ]
1376 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1380 if [ $ok -eq 0 ]; then
1395 # no way to check consistency for nfs
1398 # do nothing for now
1401 _check_btrfs_filesystem $TEST_DEV
1404 _check_generic_filesystem $TEST_DEV
1415 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1416 SCRATCH_LOG="$SCRATCH_LOGDEV"
1418 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1419 SCRATCH_RT="$SCRATCH_RTDEV"
1421 _check_xfs_filesystem $SCRATCH_DEV $SCRATCH_LOG $SCRATCH_RT
1424 _check_udf_filesystem $SCRATCH_DEV $udf_fsize
1427 # Don't know how to check an NFS filesystem, yet.
1430 _check_btrfs_filesystem $SCRATCH_DEV
1433 _check_generic_filesystem $SCRATCH_DEV
1438 _full_fstyp_details()
1440 [ -z "$FSTYP" ] && FSTYP=xfs
1441 if [ $FSTYP = xfs ]; then
1442 if [ -d /proc/fs/xfs ]; then
1443 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1444 FSTYP="$FSTYP (non-debug)"
1445 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1446 FSTYP="$FSTYP (debug)"
1449 if uname -a | grep -qi 'debug'; then
1450 FSTYP="$FSTYP (debug)"
1452 FSTYP="$FSTYP (non-debug)"
1459 _full_platform_details()
1465 echo "$os/$platform $host $kernel"
1468 _setup_udf_scratchdir()
1470 [ "$FSTYP" != "udf" ] \
1471 && _fail "setup_udf_testdir: \$FSTYP is not udf"
1472 [ -z "$SCRATCH_DEV" -o ! -b "$SCRATCH_DEV" ] \
1473 && _notrun "this test requires a valid \$SCRATCH_DEV"
1474 [ -z "$SCRATCH_MNT" ] \
1475 && _notrun "this test requires a valid \$SCRATCH_MNT"
1478 if _mount | grep -q $SCRATCH_DEV
1480 # if it's mounted, make sure its on $TEST_RW_DIR
1481 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1483 _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1485 $UMOUNT_PROG $SCRATCH_DEV
1491 testdir=$SCRATCH_MNT
1494 _setup_nfs_scratchdir()
1496 [ "$FSTYP" != "nfs" ] \
1497 && _fail "setup_nfs_testdir: \$FSTYP is not nfs"
1498 [ -z "$SCRATCH_DEV" ] \
1499 && _notrun "this test requires a valid host fs for \$SCRATCH_DEV"
1500 [ -z "$SCRATCH_MNT" ] \
1501 && _notrun "this test requires a valid \$SCRATCH_MNT"
1504 if _mount | grep -q $SCRATCH_DEV
1506 # if it's mounted, make sure its on $SCRATCH_MNT
1507 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1509 _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1511 $UMOUNT_PROG $SCRATCH_DEV
1517 testdir=$SCRATCH_MNT
1521 # Warning for UDF and NFS:
1522 # this function calls _setup_udf_scratchdir and _setup_udf_scratchdir
1523 # which actually uses the scratch dir for the test dir.
1525 # This was done because testdir was intended to be a persistent
1526 # XFS only partition. This should eventually change, and treat
1527 # at least local filesystems all the same.
1533 _setup_udf_scratchdir
1536 _setup_nfs_scratchdir
1548 # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
1549 [ -n "$testdir" ] && $UMOUNT_PROG $testdir
1552 # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
1553 [ -n "$testdir" ] && $UMOUNT_PROG $testdir
1556 # do nothing, testdir is $TEST_DIR
1564 if [ -z "$1" ]; then
1565 echo Error must pass \$seq.
1569 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1571 elif [ "`uname`" == "Linux" ]; then
1574 echo Error test $seq does not run on the operating system: `uname`
1585 #takes files, randomdata
1593 if [ $size -gt 0 ]; then
1594 if [ "$2" == "false" ]; then
1595 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
1597 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
1604 # takes dirname, depth, randomdata
1607 dirname=$1; depth=$2; randomdata=$3
1608 mkdir $dirname || die "mkdir $dirname failed"
1611 _nfiles $files $randomdata # files for this dir and data type
1613 [ $depth -eq 0 ] && return
1614 let deep=$depth-1 # go 1 down
1616 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
1619 while [ $d -lt $dirs ]
1621 _descend d$d $deep &
1627 # Populate a filesystem with inodes for performance experiments
1629 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
1634 dirs=5 # ndirs in each subdir till leaves
1635 size=0 # sizeof files in K
1636 files=100 # num files in _each_ subdir
1637 depth=2 # depth of tree from root to leaves
1639 root=root # path of initial root of directory tree
1640 randomdata=false # -x data type urandom or zero
1643 while getopts "d:f:n:r:s:v:x" c
1652 x) randomdata=true;;
1656 _descend $root $depth $randomdata
1661 [ $verbose = true ] && echo done
1664 # query whether the given file has the given inode flag set
1671 if which $XFS_IO_PROG >/dev/null; then
1672 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
1679 # query the given files extsize allocator hint in bytes (if any)
1686 if which $XFS_IO_PROG >/dev/null; then
1687 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
1688 awk '/^xattr.extsize =/ { print $3 }'`
1690 [ -z "$blocks" ] && blocks="0"
1694 # scratch_dev_pool should contain the disks pool for the btrfs raid
1695 _require_scratch_dev_pool()
1698 if [ -z "$SCRATCH_DEV_POOL" ]; then
1699 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
1702 # btrfs test case needs 2 or more scratch_dev_pool; other FS not sure
1706 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt 2 ]; then
1707 _notrun "btrfs and this test needs 2 or more disks in SCRATCH_DEV_POOL"
1711 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
1715 for i in $SCRATCH_DEV_POOL; do
1716 if [ "`_is_block_dev $i`" = "" ]; then
1717 _notrun "this test requires valid block disk $i"
1719 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
1720 _notrun "$i is part of TEST_DEV, this test requires unique disks"
1722 if _mount | grep -q $i; then
1723 if ! $UMOUNT_PROG $i; then
1724 echo "failed to unmount $i - aborting"
1728 # to help better debug when something fails, we remove
1729 # traces of previous btrfs FS on the dev.
1730 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
1734 # We will check if the device is virtual (eg: loop device) since it does not
1735 # have the delete entry-point. Otherwise SCSI and USB devices are fine.
1736 _require_deletable_scratch_dev_pool()
1740 for i in $SCRATCH_DEV_POOL; do
1741 x=`echo $i | cut -d"/" -f 3`
1742 ls -l /sys/class/block/${x} | grep -q "virtual"
1743 if [ $? == "0" ]; then
1744 _notrun "$i is a virtual device which is not deletable"
1749 # We check for btrfs and (optionally) features of the btrfs command
1753 _require_command $BTRFS_UTIL_PROG btrfs
1754 if [ -z "$1" ]; then
1757 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
1758 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
1761 # Does freeze work on this fs?
1764 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
1766 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
1767 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
1770 # arg 1 is dev to remove and is output of the below eg.
1771 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
1774 echo 1 > /sys/class/scsi_device/${1}/device/delete || _fail "Remove disk failed"
1777 # arg 1 is dev to add and is output of the below eg.
1778 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
1783 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
1784 h=`echo ${1} | cut -d":" -f 1`
1785 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
1787 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
1792 if [ -z "$FSTRIM_PROG" ]; then
1793 _notrun "This test requires fstrim utility."
1797 _test_batched_discard()
1799 if [ $# -ne 1 ]; then
1800 echo "Usage: _test_batched_discard mnt_point" 1>&2
1804 $FSTRIM_PROG ${1} &>/dev/null
1807 ################################################################################
1809 if [ "$iam" != new -a "$iam" != bench ]
1811 # make some further configuration checks here
1813 if [ "$TEST_DEV" = "" ]
1815 echo "common.rc: Error: \$TEST_DEV is not set"
1819 # if $TEST_DEV is not mounted, mount it now as XFS
1820 if [ -z "`_fs_type $TEST_DEV`" ]
1822 # $TEST_DEV is not mounted
1825 echo "common.rc: retrying test device mount with external set"
1826 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
1829 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
1835 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
1837 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
1843 # make sure this script returns success