3 # Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of version 2 of the GNU General Public License as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it would be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 # Further, this software is distributed without any warranty that it is
14 # free of the rightful claim of any third person regarding infringement
15 # or the like. Any license provided herein, whether implied or
16 # otherwise, applies only to this software file. Patent licenses, if
17 # any, provided herein do not apply to combinations of this program with
18 # other software, or any other product whatsoever.
20 # You should have received a copy of the GNU General Public License along
21 # with this program; if not, write the Free Software Foundation, Inc., 59
22 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
24 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 # Mountain View, CA 94043, or:
29 # For further information regarding this notice, see:
31 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
39 export MOUNT_OPTIONS=$XFS_MOUNT_OPTIONS
42 export MOUNT_OPTIONS=$UDF_MOUNT_OPTIONS
45 export MOUNT_OPTIONS=$NFS_MOUNT_OPTIONS
56 export MKFS_OPTIONS=$XFS_MKFS_OPTIONS
59 [ ! -z "$udf_fsize" ] && \
60 UDF_MKFS_OPTIONS="$UDF_MKFS_OPTIONS -s $udf_fsize"
61 export MKFS_OPTIONS=$UDF_MKFS_OPTIONS
64 export MKFS_OPTIONS=$NFS_MKFS_OPTIONS
71 [ -z "$FSTYP" ] && FSTYP=xfs
72 [ -z "$MOUNT_OPTIONS" ] && _mount_opts
73 [ -z "$MKFS_OPTIONS" ] && _mkfs_opts
76 # we need common.config
77 if ! . ./common.config
79 echo "$iam: failed to source common.config"
83 # make sure we have a standard umask
96 if [ $FSTYP != "xfs" ]; then
102 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
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
136 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
137 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
138 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
139 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
142 _scratch_mount_options()
144 _scratch_options mount
145 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
150 _mount -t $FSTYP `_scratch_mount_options $*`
156 _mount -t $FSTYP $TEST_OPTIONS $MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
159 _scratch_mkfs_options()
161 _scratch_options mkfs
162 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
167 _scratch_options mkfs
169 $MKFS_XFS_PROG $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
172 if [ "$USE_BIG_LOOPFS" = yes ]; then
173 [ -z "$RETAIN_AG_BYTES" ] && RETAIN_AG_BYTES=0
174 ./tools/ag-wipe -q -r $RETAIN_AG_BYTES $SCRATCH_DEV
190 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
193 /sbin/mkfs -t $FSTYP $MKFS_OPTIONS $* $SCRATCH_DEV > /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_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
220 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
221 [ "$USE_BIG_LOOPFS" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
222 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
229 echo "Usage: _get_pids_by_name process-name" 1>&2
233 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
234 # HH:MM:SS before the psargs field, use this as the search anchor.
236 # Matches with $1 (process-name) occur if the first psarg is $1
237 # or ends in /$1 ... the matching uses sed's regular expressions,
238 # so passing a regex into $1 will work.
246 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
247 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
255 $NSLOOKUP_PROG $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
258 # fix malloc libs output
262 # filter out the Electric Fence notice
265 if (defined $o && /^\s+Electric Fence/) {
271 print $o if (defined $o);
275 print $o if (defined $o);
279 # check if run as root
283 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
286 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
293 # _df_device : get an IRIX style df line for a given device
295 # - returns "" if not mounted
296 # - returns fs type in field two (ala IRIX)
297 # - joins line together if split by fancy df formatting
298 # - strips header etc
305 echo "Usage: _df_device device" 1>&2
309 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
310 match($1,what) && NF==1 {
324 # _df_dir : get an IRIX style df line for device where a directory resides
326 # - returns fs type in field two (ala IRIX)
327 # - joins line together if split by fancy df formatting
328 # - strips header etc
335 echo "Usage: _df_dir device" 1>&2
339 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
355 # return percentage used disk space for mounted device
361 echo "Usage: _used device" 1>&2
365 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
368 # return the FS type of a mounted device
374 echo "Usage: _fs_type device" 1>&2
378 _df_device $1 | $AWK_PROG '{ print $2 }'
381 # return the FS mount options of a mounted device
383 # should write a version which just parses the output of mount for IRIX
384 # compatibility, but since this isn't used at all, at the moment I'll leave
391 echo "Usage: _fs_options device" 1>&2
395 $AWK_PROG -v dev=$1 '
396 match($1,dev) { print $4 }
401 # returns device number if a file is a block device
407 echo "Usage: _is_block_dev dev" 1>&2
411 [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
414 # Do a command, log it to $seq.full, optionally test return status
415 # and die if command fails. If called with one argument _do executes the
416 # command, logs it, and returns its exit status. With two arguments _do
417 # first prints the message passed in the first argument, and then "done"
418 # or "fail" depending on the return status of the command passed in the
419 # second argument. If the command fails and the variable _do_die_on_error
420 # is set to "always" or the two argument form is used and _do_die_on_error
421 # is set to "message_only" _do will print an error message to
426 if [ $# -eq 1 ]; then
428 elif [ $# -eq 2 ]; then
433 echo "Usage: _do [note] cmd" 1>&2
437 (eval "echo '---' \"$_cmd\"") >>$here/$seq.full
438 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
439 cat $tmp._out | _fix_malloc >>$here/$seq.full
440 if [ $# -eq 2 ]; then
441 if [ $ret -eq 0 ]; then
448 && [ "$_do_die_on_error" = "always" \
449 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
452 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
459 # bail out, setting up .notrun file
463 echo "$*" >$seq.notrun
464 echo "$seq not run: $*"
469 # just plain bail out
473 echo "$*" | tee -a $here/$seq.full
474 echo "(see $seq.full for details)"
479 # tests whether $FSTYP is one of the supported filesystems for a test
485 if [ "$f" = "$FSTYP" ]
491 _notrun "not suitable for this filesystem type: $FSTYP"
494 # tests whether $FSTYP is one of the supported OSes for a test
500 if [ "$h" = "$HOSTOS" ]
506 _notrun "not suitable for this OS: $HOSTOS"
509 # this test needs a scratch partition - check we're ok & unmount it
515 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
517 _notrun "this test requires a valid \$SCRATCH_DEV"
520 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
522 _notrun "this test requires a valid \$SCRATCH_DEV"
525 nfs*|ext2|ext3|reiserfs)
526 echo $SCRATCH_DEV | grep -q ":" > /dev/null 2>&1
527 if [ ! -z "$SCRATCH_DEV" -a ! -b "$SCRATCH_DEV" -a "$?" != "0" ]
529 _notrun "this test requires a valid \$SCRATCH_DEV"
533 _notrun "\$FSTYP ($FSTYP) unknown or not specified"
539 if _mount | grep -q $SCRATCH_DEV
541 # if it's mounted, make sure its on $SCRATCH_MNT
542 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
544 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
547 # and then unmount it
548 if ! $UMOUNT_PROG $SCRATCH_DEV
550 echo "failed to unmount $SCRATCH_DEV"
556 # this test needs a logdev
560 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
561 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
562 [ "$USE_EXTERNAL" != yes ] && \
563 _notrun "This test requires USE_EXTERNAL to be enabled"
565 # ensure its not mounted
566 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
569 # this test requires loopback device support
573 if [ "$HOSTOS" != "Linux" ]
575 _notrun "This test requires linux for loopback device support"
578 modprobe loop >/dev/null 2>&1
579 if grep loop /proc/devices >/dev/null 2>&1
583 _notrun "This test requires loopback device support"
587 # this test requires that (large) loopback device files are not in use
589 _require_nobigloopfs()
591 [ "$USE_BIG_LOOPFS" = yes ] && \
592 _notrun "Large filesystem testing in progress, skipped this test"
595 # this test requires that a realtime subvolume is in use, and
596 # that the kernel supports realtime as well.
600 [ "$USE_EXTERNAL" = yes ] || \
601 _notrun "External volumes not in use, skipped this test"
602 [ "$SCRATCH_RTDEV" = "" ] && \
603 _notrun "Realtime device required, skipped this test"
606 # this test requires that external log/realtime devices are not in use
608 _require_nonexternal()
610 [ "$USE_EXTERNAL" = yes ] && \
611 _notrun "External device testing in progress, skipped this test"
614 # check that a FS is mounted as XFS. if so, return mount point
620 echo "Usage: _xfs_mounted device" 1>&2
626 if _mount | grep $device | $AWK_PROG '
627 /type xfs/ { print $3 ; exit 0 }
631 echo "_xfs_mounted: $device is not a mounted XFS FS"
637 # remount a FS to a new mode (ro or rw)
643 echo "Usage: _remount device ro/rw" 1>&2
649 if ! mount -o remount,$mode $device
651 echo "_remount: failed to remount filesystem on $device as $mode"
656 # run xfs_check and friends on a FS.
658 # if the filesystem is mounted, it's either remounted ro before being
659 # checked or it's unmounted and then remounted
664 _check_xfs_filesystem()
668 echo "Usage: _check_fs device <logdev>|none <rtdev>|none" 1>&2
673 if [ "$2" != "none" ]; then
674 extra_log_options="-l$2"
675 extra_mount_options="-ologdev=$2"
678 if [ "$3" != "none" ]; then
679 extra_rt_options="-r$3"
680 extra_mount_options=$extra_mount_options" -ortdev=$3"
683 [ "$FSTYP" != xfs ] && return 0
685 [ "$USE_BIG_LOOPFS" = yes ] && testoption=-t
687 type=`_fs_type $device`
690 if [ "$type" = "xfs" ]
694 if [ $USE_REMOUNT -eq 0 ]
696 mountpoint=`_xfs_mounted $device`
703 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
704 | tee $tmp.logprint | grep -q "<CLEAN>"
705 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
707 echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
709 echo "_check_fs: filesystem on $device has dirty log" >>$here/$seq.full
710 echo "*** xfs_logprint -t output ***" >>$here/$seq.full
711 cat $tmp.logprint >>$here/$seq.full
712 echo "*** end xfs_logprint output" >>$here/$seq.full
717 $XFS_CHECK_PROG $testoption $extra_log_options $device 2>&1 |\
718 _fix_malloc >$tmp.fs_check
719 if [ -s $tmp.fs_check ]
721 echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
723 echo "_check_fs: filesystem on $device is inconsistent" >>$here/$seq.full
724 echo "*** xfs_check output ***" >>$here/$seq.full
725 cat $tmp.fs_check >>$here/$seq.full
726 echo "*** end xfs_check output" >>$here/$seq.full
730 # repair doesn't scale massively at this stage, optionally skip it for now
731 [ "$USE_BIG_LOOPFS" = yes ] || \
732 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
735 echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
737 echo "_check_fs: filesystem on $device is inconsistent" >>$here/$seq.full
738 echo "*** xfs_repair -n output ***" >>$here/$seq.full
739 cat $tmp.repair | _fix_malloc >>$here/$seq.full
740 echo "*** end xfs_repair output" >>$here/$seq.full
744 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
748 echo "*** mount output ***" >>$here/$seq.full
749 _mount >>$here/$seq.full
750 echo "*** end mount output" >>$here/$seq.full
751 elif [ "$type" = "xfs" ]
754 if [ $USE_REMOUNT -eq 0 ]
756 if ! _mount -t xfs $extra_mount_options $device $mountpoint
758 echo "!!! failed to remount $device on $mountpoint"
766 [ $ok -eq 0 ] && exit 1
770 _check_udf_filesystem()
772 if [ $# -ne 1 -a $# -ne 2 ]
774 echo "Usage: _check_fs device [last_block]" 1>&2
781 LAST_BLOCK=`expr \( $2 - 1 \)`
782 OPT_ARG="-lastvalidblock $LAST_BLOCK"
785 # Output messages format:
786 # Error messages contain : "Error:" or "error:"
787 # Warning messages contain : "Warning:" or "warning:"
788 # Attention messages contain : "Note:" or "note:"
789 # Message continuation lines start with a "-" character.
792 sleep 1 # Due to a problem with time stamps in udf_test
793 $here/src/udf_test $OPT_ARG $device | tee $here/$seq.checkfs | \
794 egrep -i "error:|warning:|Error count:|Warning count:" | \
795 egrep -v "Error count: 0|Warning count: 0"
802 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
803 TEST_LOG="$TEST_LOGDEV"
805 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
806 TEST_RT="$TEST_RTDEV"
808 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
817 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
818 SCRATCH_LOG="$SCRATCH_LOGDEV"
820 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
821 SCRATCH_RT="$SCRATCH_RTDEV"
823 _check_xfs_filesystem $SCRATCH_DEV $SCRATCH_LOG $SCRATCH_RT
826 _check_udf_filesystem $SCRATCH_DEV $udf_fsize
829 # Don't know how to check an NFS filesystem, yet.
836 _full_fstyp_details()
838 [ -z "$FSTYP" ] && FSTYP=xfs
839 if [ $FSTYP = xfs ]; then
840 if grep 'debug 0' /proc/fs/xfs/stat >/dev/null; then
841 FSTYP="$FSTYP (non-debug)"
842 elif grep 'debug 1' /proc/fs/xfs/stat >/dev/null; then
843 FSTYP="$FSTYP (debug)"
849 _full_platform_details()
855 echo "$os/$platform $host $kernel"
870 # Don't know how to check an NFS filesystem, yet.
880 [ "$FSTYP" != "xfs" ] \
881 && _fail "setup_xfs_testdir: \$FSTYP ($FSTYP) is not xfs"
888 [ "$FSTYP" != "udf" ] \
889 && _fail "setup_udf_testdir: \$FSTYP is not udf"
890 [ -z "$SCRATCH_DEV" -o ! -b "$SCRATCH_DEV" ] \
891 && _notrun "this test requires a valid \$SCRATCH_DEV"
892 [ -z "$SCRATCH_MNT" ] \
893 && _notrun "this test requires a valid \$SCRATCH_MNT"
896 if _mount | grep -q $SCRATCH_DEV
898 # if it's mounted, make sure its on $TEST_RW_DIR
899 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
901 _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
903 $UMOUNT_PROG $SCRATCH_DEV
914 [ "$FSTYP" != "nfs" ] \
915 && _fail "setup_udf_testdir: \$FSTYP is not nfs"
916 [ -z "$SCRATCH_DEV" ] \
917 && _notrun "this test requires a valid host fs for \$SCRATCH_DEV"
918 [ -z "$SCRATCH_MNT" ] \
919 && _notrun "this test requires a valid \$SCRATCH_MNT"
922 if _mount | grep -q $SCRATCH_DEV
924 # if it's mounted, make sure its on $TEST_RW_DIR
925 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
927 _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
929 $UMOUNT_PROG $SCRATCH_DEV
951 _fail "\$FSTYP is not xfs, udf or nfs"
960 # do nothing, testdir is $TEST_DIR
963 # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
964 [ -n "$testdir" ] && $UMOUNT_PROG $testdir
967 # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
968 [ -n "$testdir" ] && $UMOUNT_PROG $testdir
971 _fail "\$FSTYP is not xfs, udf or nfs"
976 ################################################################################
978 if [ "$iam" != new -a "$iam" != bench ]
980 # make some further configuration checks here
982 if [ "$TEST_DEV" = "" ]
984 echo "common.rc: Error: \$TEST_DEV is not set"
988 # if $TEST_DEV is not mounted, mount it now as XFS
989 if [ -z "`_fs_type $TEST_DEV`" ]
991 # $TEST_DEV is not mounted
994 echo "common.rc: retrying test device mount with external set"
995 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
998 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
1004 if [ "`_fs_type $TEST_DEV`" != "xfs" ]
1006 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
1015 if [ -z "$1" ]; then
1016 echo Error must pass \$seq.
1020 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1022 elif [ "`uname`" == "Linux" ]; then
1025 echo Error test $seq does not run on the operating system: `uname`
1030 # make sure this script returns success