4 # Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of version 2 of the GNU General Public License as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it would be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 # Further, this software is distributed without any warranty that it is
15 # free of the rightful claim of any third person regarding infringement
16 # or the like. Any license provided herein, whether implied or
17 # otherwise, applies only to this software file. Patent licenses, if
18 # any, provided herein do not apply to combinations of this program with
19 # other software, or any other product whatsoever.
21 # You should have received a copy of the GNU General Public License along
22 # with this program; if not, write the Free Software Foundation, Inc., 59
23 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
25 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26 # Mountain View, CA 94043, or:
30 # For further information regarding this notice, see:
32 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
40 export MOUNT_OPTIONS=$XFS_MOUNT_OPTIONS
43 export MOUNT_OPTIONS=$UDF_MOUNT_OPTIONS
46 export MOUNT_OPTIONS=$NFS_MOUNT_OPTIONS
57 export MKFS_OPTIONS=$XFS_MKFS_OPTIONS
60 [ ! -z "$udf_fsize" ] && \
61 UDF_MKFS_OPTIONS="$UDF_MKFS_OPTIONS -s $udf_fsize"
62 export MKFS_OPTIONS=$UDF_MKFS_OPTIONS
65 export MKFS_OPTIONS=$NFS_MKFS_OPTIONS
72 [ -z "$FSTYP" ] && FSTYP=xfs
73 [ -z "$MOUNT_OPTIONS" ] && _mount_opts
74 [ -z "$MKFS_OPTIONS" ] && _mkfs_opts
77 # we need common.config
78 if ! . ./common.config
80 echo "$iam: failed to source common.config"
84 # make sure we have a standard umask
97 if [ $FSTYP != "xfs" ]; then
111 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
112 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
113 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
114 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
122 if [ $FSTYP != "xfs" ]; then
137 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
138 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
139 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
140 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
143 _scratch_mount_options()
145 _scratch_options mount
146 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
151 _mount -t $FSTYP `_scratch_mount_options $*`
157 _mount -t $FSTYP $TEST_OPTIONS $MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
160 _scratch_mkfs_options()
162 _scratch_options mkfs
163 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
168 _scratch_options mkfs
169 [ "$HOSTOS" != "IRIX" ] && \
170 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
172 $MKFS_XFS_PROG $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
175 if [ "$USE_BIG_LOOPFS" = yes ]; then
176 [ -z "$RETAIN_AG_BYTES" ] && RETAIN_AG_BYTES=0
177 ./tools/ag-wipe -q -r $RETAIN_AG_BYTES $SCRATCH_DEV
193 $MKFS_PROG -t $FSTYP $MKFS_OPTIONS $* > /dev/null
198 _scratch_xfs_db_options()
201 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
202 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
203 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
206 _scratch_xfs_logprint()
209 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
210 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
211 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
214 _scratch_xfs_repair()
217 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
218 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
219 [ "$USE_BIG_LOOPFS" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
220 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
227 echo "Usage: _get_pids_by_name process-name" 1>&2
231 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
232 # HH:MM:SS before the psargs field, use this as the search anchor.
234 # Matches with $1 (process-name) occur if the first psarg is $1
235 # or ends in /$1 ... the matching uses sed's regular expressions,
236 # so passing a regex into $1 will work.
244 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
245 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
253 $NSLOOKUP_PROG $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
256 # fix malloc libs output
260 # filter out the Electric Fence notice
263 if (defined $o && /^\s+Electric Fence/) {
269 print $o if (defined $o);
273 print $o if (defined $o);
277 # check if run as root
281 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
284 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
291 # _df_device : get an IRIX style df line for a given device
293 # - returns "" if not mounted
294 # - returns fs type in field two (ala IRIX)
295 # - joins line together if split by fancy df formatting
296 # - strips header etc
303 echo "Usage: _df_device device" 1>&2
307 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
308 match($1,what) && NF==1 {
322 # _df_dir : get an IRIX style df line for device where a directory resides
324 # - returns fs type in field two (ala IRIX)
325 # - joins line together if split by fancy df formatting
326 # - strips header etc
333 echo "Usage: _df_dir device" 1>&2
337 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
353 # return percentage used disk space for mounted device
359 echo "Usage: _used device" 1>&2
363 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
366 # return the FS type of a mounted device
372 echo "Usage: _fs_type device" 1>&2
376 _df_device $1 | $AWK_PROG '{ print $2 }'
379 # return the FS mount options of a mounted device
381 # should write a version which just parses the output of mount for IRIX
382 # compatibility, but since this isn't used at all, at the moment I'll leave
389 echo "Usage: _fs_options device" 1>&2
393 $AWK_PROG -v dev=$1 '
394 match($1,dev) { print $4 }
399 # returns device number if a file is a block device
405 echo "Usage: _is_block_dev dev" 1>&2
409 [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
412 # Do a command, log it to $seq.full, optionally test return status
413 # and die if command fails. If called with one argument _do executes the
414 # command, logs it, and returns its exit status. With two arguments _do
415 # first prints the message passed in the first argument, and then "done"
416 # or "fail" depending on the return status of the command passed in the
417 # second argument. If the command fails and the variable _do_die_on_error
418 # is set to "always" or the two argument form is used and _do_die_on_error
419 # is set to "message_only" _do will print an error message to
424 if [ $# -eq 1 ]; then
426 elif [ $# -eq 2 ]; then
431 echo "Usage: _do [note] cmd" 1>&2
435 (eval "echo '---' \"$_cmd\"") >>$here/$seq.full
436 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
437 cat $tmp._out | _fix_malloc >>$here/$seq.full
438 if [ $# -eq 2 ]; then
439 if [ $ret -eq 0 ]; then
446 && [ "$_do_die_on_error" = "always" \
447 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
450 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
457 # bail out, setting up .notrun file
461 echo "$*" >$seq.notrun
462 echo "$seq not run: $*"
467 # just plain bail out
471 echo "$*" | tee -a $here/$seq.full
472 echo "(see $seq.full for details)"
477 # tests whether $FSTYP is one of the supported filesystems for a test
483 if [ "$f" = "$FSTYP" ]
489 _notrun "not suitable for this filesystem type: $FSTYP"
492 # tests whether $FSTYP is one of the supported OSes for a test
498 if [ "$h" = "$HOSTOS" ]
504 _notrun "not suitable for this OS: $HOSTOS"
507 # this test needs a scratch partition - check we're ok & unmount it
513 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
515 _notrun "this test requires a valid \$SCRATCH_DEV"
518 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
520 _notrun "this test requires a valid \$SCRATCH_DEV"
524 echo $SCRATCH_DEV | grep -q ":" > /dev/null 2>&1
525 if [ ! -z "$SCRATCH_DEV" -a ! -b "$SCRATCH_DEV" -a "$?" != "0" ]
527 _notrun "this test requires a valid \$SCRATCH_DEV"
531 _notrun "\$FSTYP ($FSTYP) unknown or not specified"
537 if _mount | grep -q $SCRATCH_DEV
539 # if it's mounted, make sure its on $SCRATCH_MNT
540 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
542 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
545 # and then unmount it
546 if ! $UMOUNT_PROG $SCRATCH_DEV
548 echo "failed to unmount $SCRATCH_DEV"
554 # this test needs a logdev
558 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
559 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
560 [ "$USE_EXTERNAL" != yes ] && \
561 _notrun "This test requires USE_EXTERNAL to be enabled"
563 # ensure its not mounted
564 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
567 # this test requires loopback device support
571 if [ "$HOSTOS" != "Linux" ]
573 _notrun "This test requires linux for loopback device support"
576 modprobe loop >/dev/null 2>&1
577 if grep loop /proc/devices >/dev/null 2>&1
581 _notrun "This test requires loopback device support"
585 # this test requires that (large) loopback device files are not in use
587 _require_nobigloopfs()
589 [ "$USE_BIG_LOOPFS" = yes ] && \
590 _notrun "Large filesystem testing in progress, skipped this test"
593 # this test requires that external log/realtime devices are not in use
595 _require_nonexternal()
597 [ "$USE_EXTERNAL" = yes ] && \
598 _notrun "External device testing in progress, skipped this test"
601 # check that a FS is mounted as XFS. if so, return mount point
607 echo "Usage: _xfs_mounted device" 1>&2
613 if _mount | grep $device | $AWK_PROG '
614 /type xfs/ { print $3 ; exit 0 }
618 echo "_xfs_mounted: $device is not a mounted XFS FS"
624 # remount a FS to a new mode (ro or rw)
630 echo "Usage: _remount device ro/rw" 1>&2
636 if ! mount -o remount,$mode $device
638 echo "_remount: failed to remount filesystem on $device as $mode"
643 # run xfs_check and friends on a FS.
645 # if the filesystem is mounted, it's either remounted ro before being
646 # checked or it's unmounted and then remounted
651 _check_xfs_filesystem()
653 if [ $# -ne 1 -a $# -ne 2 ]
655 echo "Usage: _check_fs device [logdevice]" 1>&2
660 if [ $# -eq 2 -a "$2" != "" ]; then
661 extra_log_options="-l$2"
662 extra_mount_options="-ologdev=$2"
665 [ "$FSTYP" != xfs ] && return 0
667 [ "$USE_BIG_LOOPFS" = yes ] && testoption=-t
669 type=`_fs_type $device`
672 if [ "$type" = "xfs" ]
676 if [ $USE_REMOUNT -eq 0 ]
678 mountpoint=`_xfs_mounted $device`
685 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
686 | tee $tmp.fs_check | grep -q "<CLEAN>"
687 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
689 echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
691 echo "_check_fs: filesystem on $device has dirty log" >>$here/$seq.full
692 echo "*** xfs_logprint -t output ***" >>$here/$seq.full
693 cat $tmp.fs_check >>$here/$seq.full
694 echo "*** end xfs_logprint output" >>$here/$seq.full
699 $XFS_CHECK_PROG $testoption $extra_log_options $device 2>&1 |\
700 _fix_malloc >$tmp.fs_check
701 if [ -s $tmp.fs_check ]
703 echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
705 echo "_check_fs: filesystem on $device is inconsistent" >>$here/$seq.full
706 echo "*** xfs_check output ***" >>$here/$seq.full
707 cat $tmp.fs_check >>$here/$seq.full
708 echo "*** end xfs_check output" >>$here/$seq.full
712 # repair doesn't scale massively at this stage, optionally skip it for now
713 [ "$USE_BIG_LOOPFS" = yes ] || \
714 $XFS_REPAIR_PROG -n $extra_log_options $device >$tmp.fs_check 2>&1
717 echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
719 echo "_check_fs: filesystem on $device is inconsistent" >>$here/$seq.full
720 echo "*** xfs_repair -n output ***" >>$here/$seq.full
721 cat $tmp.fs_check | _fix_malloc >>$here/$seq.full
722 echo "*** end xfs_repair output" >>$here/$seq.full
730 echo "*** mount output ***" >>$here/$seq.full
731 _mount >>$here/$seq.full
732 echo "*** end mount output" >>$here/$seq.full
733 elif [ "$type" = "xfs" ]
736 if [ $USE_REMOUNT -eq 0 ]
738 if ! _mount -t xfs $extra_mount_options $device $mountpoint
740 echo "!!! failed to remount $device on $mountpoint"
748 [ $ok -eq 0 ] && exit 1
752 _check_udf_filesystem()
754 if [ $# -ne 1 -a $# -ne 2 ]
756 echo "Usage: _check_fs device [last_block]" 1>&2
763 LAST_BLOCK=`expr \( $2 - 1 \)`
764 OPT_ARG="-lastvalidblock $LAST_BLOCK"
767 # Output messages format:
768 # Error messages contain : "Error:" or "error:"
769 # Warning messages contain : "Warning:" or "warning:"
770 # Attention messages contain : "Note:" or "note:"
771 # Message continuation lines start with a "-" character.
774 sleep 1 # Due to a problem with time stamps in udf_test
775 $here/src/udf_test $OPT_ARG $device | tee $here/$seq.checkfs | \
776 egrep -i "error:|warning:|Error count:|Warning count:" | \
777 egrep -v "Error count: 0|Warning count: 0"
783 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
784 TEST_LOG="$TEST_LOGDEV"
786 _check_xfs_filesystem $TEST_DEV $TEST_LOG
796 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
797 SCRATCH_LOG="$SCRATCH_LOGDEV"
799 _check_xfs_filesystem $SCRATCH_DEV $SCRATCH_LOG
802 _check_udf_filesystem $SCRATCH_DEV $udf_fsize
805 # Don't know how to check an NFS filesystem, yet.
812 _full_fstyp_details()
814 [ -z "$FSTYP" ] && FSTYP=xfs
815 if [ $FSTYP = xfs ]; then
816 if grep 'debug 0' /proc/fs/xfs/stat >/dev/null; then
817 FSTYP="$FSTYP (non-debug)"
818 elif grep 'debug 1' /proc/fs/xfs/stat >/dev/null; then
819 FSTYP="$FSTYP (debug)"
825 _full_platform_details()
831 echo "$os/$platform $host $kernel"
848 # Don't know how to check an NFS filesystem, yet.
858 [ "$FSTYP" != "xfs" ] \
859 && _fail "setup_xfs_testdir: \$FSTYP ($FSTYP) is not xfs"
866 [ "$FSTYP" != "udf" ] \
867 && _fail "setup_udf_testdir: \$FSTYP is not udf"
868 [ -z "$SCRATCH_DEV" -o ! -b "$SCRATCH_DEV" ] \
869 && _notrun "this test requires a valid \$SCRATCH_DEV"
870 [ -z "$SCRATCH_MNT" ] \
871 && _notrun "this test requires a valid \$SCRATCH_MNT"
874 if _mount | grep -q $SCRATCH_DEV
876 # if it's mounted, make sure its on $TEST_RW_DIR
877 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
879 _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
881 $UMOUNT_PROG $SCRATCH_DEV
892 [ "$FSTYP" != "nfs" ] \
893 && _fail "setup_udf_testdir: \$FSTYP is not nfs"
894 [ -z "$SCRATCH_DEV" ] \
895 && _notrun "this test requires a valid host fs for \$SCRATCH_DEV"
896 [ -z "$SCRATCH_MNT" ] \
897 && _notrun "this test requires a valid \$SCRATCH_MNT"
900 if _mount | grep -q $SCRATCH_DEV
902 # if it's mounted, make sure its on $TEST_RW_DIR
903 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
905 _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
907 $UMOUNT_PROG $SCRATCH_DEV
931 _fail "\$FSTYP is not xfs, udf or nfs"
942 # do nothing, testdir is $TEST_DIR
945 # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
946 [ -n "$testdir" ] && $UMOUNT_PROG $testdir
949 # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
950 [ -n "$testdir" ] && $UMOUNT_PROG $testdir
953 _fail "\$FSTYP is not xfs, udf or nfs"
958 ################################################################################
960 if [ "$iam" != new -a "$iam" != bench ]
962 # make some further configuration checks here
964 if [ "$TEST_DEV" = "" ]
966 echo "common.rc: Error: \$TEST_DEV is not set"
970 # if $TEST_DEV is not mounted, mount it now as XFS
971 if [ -z "`_fs_type $TEST_DEV`" ]
973 # $TEST_DEV is not mounted
976 echo "common.rc: retrying test device mount with external set"
977 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
980 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
986 if [ "`_fs_type $TEST_DEV`" != "xfs" ]
988 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
998 echo Error must pass \$seq.
1002 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1004 elif [ "`uname`" == "Linux" ]; then
1007 echo Error test $seq does not run on the operating system: `uname`
1015 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1017 elif [ "`uname`" == "Linux" ]; then
1020 echo Error test does not run on the operating system: `uname`
1025 # make sure this script returns success