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
103 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
112 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
113 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
114 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
115 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
123 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
170 $MKFS_XFS_PROG $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
173 if [ "$USE_BIG_LOOPFS" = yes ]; then
174 [ -z "$RETAIN_AG_BYTES" ] && RETAIN_AG_BYTES=0
175 ./tools/ag-wipe -q -r $RETAIN_AG_BYTES $SCRATCH_DEV
191 $MKFS_PROG -t $FSTYP $MKFS_OPTIONS $* > /dev/null
196 _scratch_xfs_db_options()
199 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
200 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
201 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
204 _scratch_xfs_logprint()
207 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
208 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
209 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
212 _scratch_xfs_repair()
215 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
216 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
217 [ "$USE_BIG_LOOPFS" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
218 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
225 echo "Usage: _get_pids_by_name process-name" 1>&2
229 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
230 # HH:MM:SS before the psargs field, use this as the search anchor.
232 # Matches with $1 (process-name) occur if the first psarg is $1
233 # or ends in /$1 ... the matching uses sed's regular expressions,
234 # so passing a regex into $1 will work.
242 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
243 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
251 $NSLOOKUP_PROG $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
254 # fix malloc libs output
258 # filter out the Electric Fence notice
261 if (defined $o && /^\s+Electric Fence/) {
267 print $o if (defined $o);
271 print $o if (defined $o);
275 # check if run as root
279 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
282 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
289 # _df_device : get an IRIX style df line for a given device
291 # - returns "" if not mounted
292 # - returns fs type in field two (ala IRIX)
293 # - joins line together if split by fancy df formatting
294 # - strips header etc
301 echo "Usage: _df_device device" 1>&2
305 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
306 match($1,what) && NF==1 {
320 # _df_dir : get an IRIX style df line for device where a directory resides
322 # - returns fs type in field two (ala IRIX)
323 # - joins line together if split by fancy df formatting
324 # - strips header etc
331 echo "Usage: _df_dir device" 1>&2
335 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
351 # return percentage used disk space for mounted device
357 echo "Usage: _used device" 1>&2
361 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
364 # return the FS type of a mounted device
370 echo "Usage: _fs_type device" 1>&2
374 _df_device $1 | $AWK_PROG '{ print $2 }'
377 # return the FS mount options of a mounted device
379 # should write a version which just parses the output of mount for IRIX
380 # compatibility, but since this isn't used at all, at the moment I'll leave
387 echo "Usage: _fs_options device" 1>&2
391 $AWK_PROG -v dev=$1 '
392 match($1,dev) { print $4 }
397 # returns device number if a file is a block device
403 echo "Usage: _is_block_dev dev" 1>&2
407 [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
410 # Do a command, log it to $seq.full, optionally test return status
411 # and die if command fails. If called with one argument _do executes the
412 # command, logs it, and returns its exit status. With two arguments _do
413 # first prints the message passed in the first argument, and then "done"
414 # or "fail" depending on the return status of the command passed in the
415 # second argument. If the command fails and the variable _do_die_on_error
416 # is set to "always" or the two argument form is used and _do_die_on_error
417 # is set to "message_only" _do will print an error message to
422 if [ $# -eq 1 ]; then
424 elif [ $# -eq 2 ]; then
429 echo "Usage: _do [note] cmd" 1>&2
433 (eval "echo '---' \"$_cmd\"") >>$here/$seq.full
434 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
435 cat $tmp._out | _fix_malloc >>$here/$seq.full
436 if [ $# -eq 2 ]; then
437 if [ $ret -eq 0 ]; then
444 && [ "$_do_die_on_error" = "always" \
445 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
448 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
455 # bail out, setting up .notrun file
459 echo "$*" >$seq.notrun
460 echo "$seq not run: $*"
465 # just plain bail out
469 echo "$*" | tee -a $here/$seq.full
470 echo "(see $seq.full for details)"
475 # tests whether $FSTYP is one of the supported filesystems for a test
481 if [ "$f" = "$FSTYP" ]
487 _notrun "not suitable for this filesystem type: $FSTYP"
490 # tests whether $FSTYP is one of the supported OSes for a test
496 if [ "$h" = "$HOSTOS" ]
502 _notrun "not suitable for this OS: $HOSTOS"
505 # this test needs a scratch partition - check we're ok & unmount it
511 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
513 _notrun "this test requires a valid \$SCRATCH_DEV"
516 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
518 _notrun "this test requires a valid \$SCRATCH_DEV"
522 echo $SCRATCH_DEV | grep -q ":" > /dev/null 2>&1
523 if [ ! -z "$SCRATCH_DEV" -a ! -b "$SCRATCH_DEV" -a "$?" != "0" ]
525 _notrun "this test requires a valid \$SCRATCH_DEV"
529 _notrun "\$FSTYP ($FSTYP) unknown or not specified"
535 if _mount | grep -q $SCRATCH_DEV
537 # if it's mounted, make sure its on $SCRATCH_MNT
538 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
540 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
543 # and then unmount it
544 if ! $UMOUNT_PROG $SCRATCH_DEV
546 echo "failed to unmount $SCRATCH_DEV"
552 # this test needs a logdev
556 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
557 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
558 [ "$USE_EXTERNAL" != yes ] && \
559 _notrun "This test requires USE_EXTERNAL to be enabled"
561 # ensure its not mounted
562 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
565 # this test requires loopback device support
569 if [ "$HOSTOS" != "Linux" ]
571 _notrun "This test requires linux for loopback device support"
574 modprobe loop >/dev/null 2>&1
575 if grep loop /proc/devices >/dev/null 2>&1
579 _notrun "This test requires loopback device support"
583 # this test requires that (large) loopback device files are not in use
585 _require_nobigloopfs()
587 [ "$USE_BIG_LOOPFS" = yes ] && \
588 _notrun "Large filesystem testing in progress, skipped this test"
591 # this test requires that external log/realtime devices are not in use
593 _require_nonexternal()
595 [ "$USE_EXTERNAL" = yes ] && \
596 _notrun "External device testing in progress, skipped this test"
599 # check that a FS is mounted as XFS. if so, return mount point
605 echo "Usage: _xfs_mounted device" 1>&2
611 if _mount | grep $device | $AWK_PROG '
612 /type xfs/ { print $3 ; exit 0 }
616 echo "_xfs_mounted: $device is not a mounted XFS FS"
622 # remount a FS to a new mode (ro or rw)
628 echo "Usage: _remount device ro/rw" 1>&2
634 if ! mount -o remount,$mode $device
636 echo "_remount: failed to remount filesystem on $device as $mode"
641 # run xfs_check and friends on a FS.
643 # if the filesystem is mounted, it's either remounted ro before being
644 # checked or it's unmounted and then remounted
649 _check_xfs_filesystem()
651 if [ $# -ne 1 -a $# -ne 2 ]
653 echo "Usage: _check_fs device [logdevice]" 1>&2
658 if [ $# -eq 2 -a "$2" != "" ]; then
659 extra_log_options="-l$2"
660 extra_mount_options="-ologdev=$2"
663 [ "$FSTYP" != xfs ] && return 0
665 [ "$USE_BIG_LOOPFS" = yes ] && testoption=-t
667 type=`_fs_type $device`
670 if [ "$type" = "xfs" ]
674 if [ $USE_REMOUNT -eq 0 ]
676 mountpoint=`_xfs_mounted $device`
683 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
684 | tee $tmp.logprint | grep -q "<CLEAN>"
685 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
687 echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
689 echo "_check_fs: filesystem on $device has dirty log" >>$here/$seq.full
690 echo "*** xfs_logprint -t output ***" >>$here/$seq.full
691 cat $tmp.logprint >>$here/$seq.full
692 echo "*** end xfs_logprint output" >>$here/$seq.full
697 $XFS_CHECK_PROG $testoption $extra_log_options $device 2>&1 |\
698 _fix_malloc >$tmp.fs_check
699 if [ -s $tmp.fs_check ]
701 echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
703 echo "_check_fs: filesystem on $device is inconsistent" >>$here/$seq.full
704 echo "*** xfs_check output ***" >>$here/$seq.full
705 cat $tmp.fs_check >>$here/$seq.full
706 echo "*** end xfs_check output" >>$here/$seq.full
710 # repair doesn't scale massively at this stage, optionally skip it for now
711 [ "$USE_BIG_LOOPFS" = yes ] || \
712 $XFS_REPAIR_PROG -n $extra_log_options $device >$tmp.repair 2>&1
715 echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
717 echo "_check_fs: filesystem on $device is inconsistent" >>$here/$seq.full
718 echo "*** xfs_repair -n output ***" >>$here/$seq.full
719 cat $tmp.repair | _fix_malloc >>$here/$seq.full
720 echo "*** end xfs_repair output" >>$here/$seq.full
724 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
728 echo "*** mount output ***" >>$here/$seq.full
729 _mount >>$here/$seq.full
730 echo "*** end mount output" >>$here/$seq.full
731 elif [ "$type" = "xfs" ]
734 if [ $USE_REMOUNT -eq 0 ]
736 if ! _mount -t xfs $extra_mount_options $device $mountpoint
738 echo "!!! failed to remount $device on $mountpoint"
746 [ $ok -eq 0 ] && exit 1
750 _check_udf_filesystem()
752 if [ $# -ne 1 -a $# -ne 2 ]
754 echo "Usage: _check_fs device [last_block]" 1>&2
761 LAST_BLOCK=`expr \( $2 - 1 \)`
762 OPT_ARG="-lastvalidblock $LAST_BLOCK"
765 # Output messages format:
766 # Error messages contain : "Error:" or "error:"
767 # Warning messages contain : "Warning:" or "warning:"
768 # Attention messages contain : "Note:" or "note:"
769 # Message continuation lines start with a "-" character.
772 sleep 1 # Due to a problem with time stamps in udf_test
773 $here/src/udf_test $OPT_ARG $device | tee $here/$seq.checkfs | \
774 egrep -i "error:|warning:|Error count:|Warning count:" | \
775 egrep -v "Error count: 0|Warning count: 0"
781 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
782 TEST_LOG="$TEST_LOGDEV"
784 _check_xfs_filesystem $TEST_DEV $TEST_LOG
792 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
793 SCRATCH_LOG="$SCRATCH_LOGDEV"
795 _check_xfs_filesystem $SCRATCH_DEV $SCRATCH_LOG
798 _check_udf_filesystem $SCRATCH_DEV $udf_fsize
801 # Don't know how to check an NFS filesystem, yet.
808 _full_fstyp_details()
810 [ -z "$FSTYP" ] && FSTYP=xfs
811 if [ $FSTYP = xfs ]; then
812 if grep 'debug 0' /proc/fs/xfs/stat >/dev/null; then
813 FSTYP="$FSTYP (non-debug)"
814 elif grep 'debug 1' /proc/fs/xfs/stat >/dev/null; then
815 FSTYP="$FSTYP (debug)"
821 _full_platform_details()
827 echo "$os/$platform $host $kernel"
842 # Don't know how to check an NFS filesystem, yet.
852 [ "$FSTYP" != "xfs" ] \
853 && _fail "setup_xfs_testdir: \$FSTYP ($FSTYP) is not xfs"
860 [ "$FSTYP" != "udf" ] \
861 && _fail "setup_udf_testdir: \$FSTYP is not udf"
862 [ -z "$SCRATCH_DEV" -o ! -b "$SCRATCH_DEV" ] \
863 && _notrun "this test requires a valid \$SCRATCH_DEV"
864 [ -z "$SCRATCH_MNT" ] \
865 && _notrun "this test requires a valid \$SCRATCH_MNT"
868 if _mount | grep -q $SCRATCH_DEV
870 # if it's mounted, make sure its on $TEST_RW_DIR
871 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
873 _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
875 $UMOUNT_PROG $SCRATCH_DEV
886 [ "$FSTYP" != "nfs" ] \
887 && _fail "setup_udf_testdir: \$FSTYP is not nfs"
888 [ -z "$SCRATCH_DEV" ] \
889 && _notrun "this test requires a valid host fs for \$SCRATCH_DEV"
890 [ -z "$SCRATCH_MNT" ] \
891 && _notrun "this test requires a valid \$SCRATCH_MNT"
894 if _mount | grep -q $SCRATCH_DEV
896 # if it's mounted, make sure its on $TEST_RW_DIR
897 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
899 _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
901 $UMOUNT_PROG $SCRATCH_DEV
923 _fail "\$FSTYP is not xfs, udf or nfs"
932 # do nothing, testdir is $TEST_DIR
935 # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
936 [ -n "$testdir" ] && $UMOUNT_PROG $testdir
939 # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
940 [ -n "$testdir" ] && $UMOUNT_PROG $testdir
943 _fail "\$FSTYP is not xfs, udf or nfs"
948 ################################################################################
950 if [ "$iam" != new -a "$iam" != bench ]
952 # make some further configuration checks here
954 if [ "$TEST_DEV" = "" ]
956 echo "common.rc: Error: \$TEST_DEV is not set"
960 # if $TEST_DEV is not mounted, mount it now as XFS
961 if [ -z "`_fs_type $TEST_DEV`" ]
963 # $TEST_DEV is not mounted
966 echo "common.rc: retrying test device mount with external set"
967 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
970 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
976 if [ "`_fs_type $TEST_DEV`" != "xfs" ]
978 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
988 echo Error must pass \$seq.
992 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
994 elif [ "`uname`" == "Linux" ]; then
997 echo Error test $seq does not run on the operating system: `uname`
1002 # make sure this script returns success