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/
35 # we need common.config
36 if ! . ./common.config
38 echo "$iam: failed to source common.config"
42 # make sure we have a standard umask
48 # extra parameters for fsstress
51 export AWK_PROG FSSTRESS_AVOID
53 # we override mount and mkfs.xfs so we can specify extra options
66 /bin/mount $* $MOUNT_OPTIONS
77 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
78 TEST_OPTIONS="$TEST_OPTIONS -ortdev=$TEST_RTDEV"
79 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
80 TEST_OPTIONS="$TEST_OPTIONS -ologdev=$TEST_LOGDEV"
81 mount -t xfs $TEST_OPTIONS $MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
84 _scratch_mount_options()
87 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
88 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ortdev=$SCRATCH_RTDEV"
89 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
90 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ologdev=$SCRATCH_LOGDEV"
91 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
97 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
98 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ortdev=$SCRATCH_RTDEV"
99 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
100 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ologdev=$SCRATCH_LOGDEV"
101 mount -t xfs $SCRATCH_OPTIONS $MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
104 _scratch_mkfs_options()
107 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
108 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -rrtdev=$SCRATCH_RTDEV"
109 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
110 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -llogdev=$SCRATCH_LOGDEV"
111 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
117 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
118 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -rrtdev=$SCRATCH_RTDEV"
119 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
120 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -llogdev=$SCRATCH_LOGDEV"
121 /sbin/mkfs.xfs -f $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
124 _scratch_xfs_db_options()
127 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
128 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
129 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
132 _scratch_xfs_logprint()
135 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
136 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
137 /usr/sbin/xfs_logprint $SCRATCH_OPTIONS $* $SCRATCH_DEV
140 _scratch_xfs_repair()
143 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
144 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
145 /sbin/xfs_repair $SCRATCH_OPTIONS $* $SCRATCH_DEV
152 echo "Usage: _get_pids_by_name process-name" 1>&2
156 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
157 # HH:MM:SS before the psargs field, use this as the search anchor.
159 # Matches with $1 (process-name) occur if the first psarg is $1
160 # or ends in /$1 ... the matching uses sed's regular expressions,
161 # so passing a regex into $1 will work.
169 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
170 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
178 nslookup $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
181 # fix malloc libs output
185 # filter out the Electric Fence notice
188 if (defined $o && /^\s+Electric Fence/) {
194 print $o if (defined $o);
198 print $o if (defined $o);
202 # check if run as root
206 id=`id | sed -e 's/(.*//' -e 's/.*=//'`
209 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
216 # _df_device : get an IRIX style df line for a given device
218 # - returns "" if not mounted
219 # - returns fs type in field two (ala IRIX)
220 # - joins line together if split by fancy df formatting
221 # - strips header etc
228 echo "Usage: _df_device device" 1>&2
232 df -T 2>/dev/null | $AWK_PROG -v what=$1 '
233 match($1,what) && NF==1 {
247 # _df_dir : get an IRIX style df line for device where a directory resides
249 # - returns fs type in field two (ala IRIX)
250 # - joins line together if split by fancy df formatting
251 # - strips header etc
258 echo "Usage: _df_dir device" 1>&2
262 df -T $1 2>/dev/null | $AWK_PROG -v what=$1 '
278 # return percentage used disk space for mounted device
284 echo "Usage: _used device" 1>&2
288 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
291 # return the FS type of a mounted device
297 echo "Usage: _fs_type device" 1>&2
301 _df_device $1 | $AWK_PROG '{ print $2 }'
304 # return the FS mount options of a mounted device
310 echo "Usage: _fs_options device" 1>&2
314 $AWK_PROG -v dev=$1 '
315 match($1,dev) { print $4 }
320 # returns device number if a file is a block device
326 echo "Usage: _is_block_dev dev" 1>&2
330 [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
333 # Do a command, log it to $seq.full, optionally test return status
334 # and die if command fails. If called with one argument _do executes the
335 # command, logs it, and returns its exit status. With two arguments _do
336 # first prints the message passed in the first argument, and then "done"
337 # or "fail" depending on the return status of the command passed in the
338 # second argument. If the command fails and the variable _do_die_on_error
339 # is set to "always" or the two argument form is used and _do_die_on_error
340 # is set to "message_only" _do will print an error message to
345 if [ $# -eq 1 ]; then
347 elif [ $# -eq 2 ]; then
352 echo "Usage: _do [note] cmd" 1>&2
356 (eval "echo '---' \"$_cmd\"") >>$seq.full
357 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
358 cat $tmp._out | _fix_malloc >>$seq.full
359 if [ $# -eq 2 ]; then
360 if [ $ret -eq 0 ]; then
367 && [ "$_do_die_on_error" = "always" \
368 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
371 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
378 # bail out, setting up .notrun file
382 echo "$*" >$seq.notrun
383 echo "$seq not run: $*"
388 # just plain bail out
392 echo "$*" | tee -a $seq.full
393 echo "(see $seq.full for details)"
398 # this test needs a scratch partition - check we're ok & unmount it
402 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
404 _notrun "this test requires a valid \$SCRATCH_DEV"
407 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
409 _notrun "this test requires a valid \$SCRATCH_DEV"
413 if mount | grep -q $SCRATCH_DEV
415 # if it's mounted, make sure its on $SCRATCH_MNT
416 if ! mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
418 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
421 # and then unmount it
422 if ! umount $SCRATCH_DEV
424 echo "failed to unmount $SCRATCH_DEV"
430 # this test needs a logdev
434 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
435 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
436 [ "$USE_EXTERNAL" != yes ] && \
437 _notrun "This test requires USE_EXTERNAL to be enabled"
439 # ensure its not mounted
440 umount $SCRATCH_LOGDEV 2>/dev/null
443 # this test requires loopback device support
447 modprobe loop >/dev/null 2>&1
448 if grep loop /proc/devices >/dev/null 2>&1
452 _notrun "This test requires loopback device support"
456 # check that a FS is mounted as XFS. if so, return mount point
462 echo "Usage: _xfs_mounted device" 1>&2
468 if mount | grep $device | $AWK_PROG '
469 /type xfs/ { print $3 ; exit 0 }
473 echo "_xfs_mounted: $device is not a mounted XFS FS"
479 # setup the .out file link, depending on which form of quota is
480 # enabled as this often influences how the test output appears.
481 # [NB: SCRATCH_DEV must be mounted for this to work]
485 # this lets us phase use of this into the dump/restore tests easier...
486 [ -f $seq.ugquota -a -f $seq.noquota -a $seq.usrquota -a $seq.grpquota ] \
490 if src/feature -U $SCRATCH_DEV
492 if src/feature -G $SCRATCH_DEV
494 ln $seq.ugquota $seq.out
496 ln $seq.usrquota $seq.out
498 elif src/feature -G $SCRATCH_DEV
500 ln $seq.grpquota $seq.out
502 ln $seq.noquota $seq.out
507 # remount a FS to a new mode (ro or rw)
513 echo "Usage: _remount device ro/rw" 1>&2
519 if ! mount -o remount,$mode $device
521 echo "_remount: failed to remount filesystem on $device as $mode"
525 # we might like to check here later
526 #options=`_fs_options $device`
530 # run xfs_check and friends on a FS.
532 # if the filesystem is mounted, it's either remounted ro before being
533 # checked or it's unmounted and then remounted
540 if [ $# -ne 1 -a $# -ne 2 ]
542 echo "Usage: _check_fs device [logdevice]" 1>&2
547 if [ $# -eq 2 -a "$2" != "" ]; then
548 extra_log_options="-l$2"
549 extra_mount_options="-ologdev=$2"
551 type=`_fs_type $device`
554 if [ "$type" = "xfs" ]
558 if [ $USE_REMOUNT -eq 0 ]
560 mountpoint=`_xfs_mounted $device`
567 /usr/sbin/xfs_logprint -t $device $extra_log_options 2>&1 \
568 | tee $tmp.fs_check | grep -q "<CLEAN>"
571 echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
573 echo "_check_fs: filesystem on $device has dirty log" >>$seq.full
574 echo "*** xfs_logprint -t output ***" >>$seq.full
575 cat $tmp.fs_check >>$seq.full
576 echo "*** end xfs_logprint output" >>$seq.full
581 /usr/sbin/xfs_check $device 2>&1 | _fix_malloc >$tmp.fs_check
582 if [ -s $tmp.fs_check ]
584 echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
586 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
587 echo "*** xfs_check output ***" >>$seq.full
588 cat $tmp.fs_check >>$seq.full
589 echo "*** end xfs_check output" >>$seq.full
594 if ! /sbin/xfs_repair -n $device $extra_log_options >$tmp.fs_check 2>&1
596 echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
598 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
599 echo "*** xfs_repair -n output ***" >>$seq.full
600 cat $tmp.fs_check | _fix_malloc >>$seq.full
601 echo "*** end xfs_repair output" >>$seq.full
609 echo "*** mount output ***" >>$seq.full
611 echo "*** end mount output" >>$seq.full
612 elif [ "$type" = "xfs" ]
615 if [ $USE_REMOUNT -eq 0 ]
617 if ! mount -t xfs $extra_mount_options $device $mountpoint
619 echo "!!! failed to remount $device on $mountpoint"
627 [ $ok -eq 0 ] && exit 1
634 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
635 TEST_LOG="$TEST_LOGDEV"
636 _check_filesystem $TEST_DEV $TEST_LOG
642 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
643 SCRATCH_LOG="$SCRATCH_LOGDEV"
644 _check_filesystem $SCRATCH_DEV $SCRATCH_LOG
647 ################################################################################
649 [ -d /usr/bsd ] && PATH=$PATH:/usr/bsd
650 [ -d /usr/freeware/bin ] && PATH=$PATH:/usr/freeware/bin
655 # make some further configuration checks here
657 if [ "$TEST_DEV" = "" ]
659 echo "common.rc: Error: \$TEST_DEV is not set"
663 # if $TEST_DEV is not mounted, mount it now as XFS
664 if [ -z "`_fs_type $TEST_DEV`" ]
666 # $TEST_DEV is not mounted
669 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
674 if [ "`_fs_type $TEST_DEV`" != "xfs" ]
676 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
683 # check for some required binaries on our $PATH
685 for exec in mkfs.xfs xfs_logprint xfs_check xfs_repair xfs_db
687 if which $exec >/dev/null 2>&1
691 echo "common.rc: cannot find $exec on \$PATH=$PATH"
696 # make sure this script returns success