Update configure scripts in xfstests directory.
[xfstests-dev.git] / common.rc
1 ##/bin/sh
2 #
3 # Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
4
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.
8
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.
12
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.
19
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.
23
24 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 # Mountain View, CA  94043, or:
26
27 # http://www.sgi.com 
28
29 # For further information regarding this notice, see: 
30
31 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #
33
34
35 _mount_opts()
36 {
37     case $FSTYP in
38     xfs)
39         export MOUNT_OPTIONS=$XFS_MOUNT_OPTIONS
40         ;;
41     udf)
42         export MOUNT_OPTIONS=$UDF_MOUNT_OPTIONS
43         ;;
44     nfs)
45         export MOUNT_OPTIONS=$NFS_MOUNT_OPTIONS
46         ;;
47     *)
48         ;;
49     esac
50 }
51
52 _mkfs_opts()
53 {
54     case $FSTYP in
55     xfs)
56         export MKFS_OPTIONS=$XFS_MKFS_OPTIONS
57         ;;
58     udf)
59         [ ! -z "$udf_fsize" ] && \
60             UDF_MKFS_OPTIONS="$UDF_MKFS_OPTIONS -s $udf_fsize"
61         export MKFS_OPTIONS=$UDF_MKFS_OPTIONS
62         ;;
63     nfs)
64         export MKFS_OPTIONS=$NFS_MKFS_OPTIONS
65         ;;
66     *)
67         ;;
68     esac
69 }
70
71 [ -z "$FSTYP" ] && FSTYP=xfs
72 [ -z "$MOUNT_OPTIONS" ] && _mount_opts
73 [ -z "$MKFS_OPTIONS" ] && _mkfs_opts
74
75
76 # we need common.config
77 if ! . ./common.config
78 then
79     echo "$iam: failed to source common.config"
80     exit 1
81 fi
82
83 # make sure we have a standard umask
84 umask 022
85
86 _mount()
87 {
88     $MOUNT_PROG $*
89 }
90
91 _scratch_options()
92 {
93     type=$1
94     SCRATCH_OPTIONS=""
95
96     if [ $FSTYP != "xfs" ]; then
97         return
98     fi
99
100     case $type in
101     mkfs)
102         [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
103         rt_opt="-r"
104         log_opt="-l"
105         ;;
106     mount)
107         rt_opt="-o"
108         log_opt="-o"
109         ;;
110     esac
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"
115 }
116
117 _test_options()
118 {
119     type=$1
120     TEST_OPTIONS=""
121
122     if [ $FSTYP != "xfs" ]; then
123         return
124     fi
125
126     case $type in
127     mkfs)
128         rt_opt="-r"
129         log_opt="-l"
130         ;;
131     mount)
132         rt_opt="-o"
133         log_opt="-o"
134         ;;
135     esac
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"
140 }
141
142 _scratch_mount_options()
143 {
144     _scratch_options mount
145     echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
146 }
147
148 _scratch_mount()
149 {
150     _mount -t $FSTYP `_scratch_mount_options $*`
151 }
152
153 _test_mount()
154 {
155     _test_options mount 
156     _mount -t $FSTYP $TEST_OPTIONS $MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
157 }
158
159 _scratch_mkfs_options()
160 {
161     _scratch_options mkfs 
162     echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
163 }
164
165 _scratch_mkfs_xfs()
166 {
167     _scratch_options mkfs 
168
169     $MKFS_XFS_PROG $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
170     mkfs_status=$?
171
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
175     fi
176
177     return $mkfs_status
178 }
179
180 _scratch_mkfs()
181 {
182     case $FSTYP in
183     xfs)
184         _scratch_mkfs_xfs $*
185         ;;
186     nfs*)
187         # do nothing for nfs
188         ;;
189     udf*)
190         $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
191         ;;
192     *)
193         /sbin/mkfs -t $FSTYP $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
194         ;;
195     esac
196 }
197
198 _scratch_xfs_db_options()
199 {
200     SCRATCH_OPTIONS=""
201     [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
202         SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
203     echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
204 }
205
206 _scratch_xfs_logprint()
207 {
208     SCRATCH_OPTIONS=""
209     [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
210         SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
211     $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
212 }
213
214 _scratch_xfs_repair()
215 {
216     SCRATCH_OPTIONS=""
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
223 }
224
225 _get_pids_by_name()
226 {
227     if [ $# -ne 1 ]
228     then
229         echo "Usage: _get_pids_by_name process-name" 1>&2
230         exit 1
231     fi
232
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.
235     #
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.
239
240     ps $PS_ALL_FLAGS \
241     | sed -n \
242         -e 's/$/ /' \
243         -e 's/[         ][      ]*/ /g' \
244         -e 's/^ //' \
245         -e 's/^[^ ]* //' \
246         -e "/[0-9]:[0-9][0-9]  *[^ ]*\/$1 /s/ .*//p" \
247         -e "/[0-9]:[0-9][0-9]  *$1 /s/ .*//p"
248 }
249
250 # fqdn for localhost
251 #
252 _get_fqdn()
253 {
254     host=`hostname`
255     $NSLOOKUP_PROG $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
256 }
257
258 # fix malloc libs output
259 #
260 _fix_malloc()
261 {
262     # filter out the Electric Fence notice
263     $PERL_PROG -e '
264         while (<>) {
265             if (defined $o && /^\s+Electric Fence/) {
266                 chomp($o);
267                 print "$o";
268                 undef $o;
269                 next;
270             }
271             print $o if (defined $o);
272
273             $o=$_;
274         }
275         print $o if (defined $o);
276     '
277 }
278
279 # check if run as root
280 #
281 _need_to_be_root()
282 {
283     id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
284     if [ "$id" -ne 0 ]
285     then
286         echo "Arrgh ... you need to be root (not uid=$id) to run this test"
287         exit 1
288     fi
289 }
290
291
292 #
293 # _df_device : get an IRIX style df line for a given device 
294 #
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
299 #
300
301 _df_device()
302 {
303     if [ $# -ne 1 ]
304     then
305         echo "Usage: _df_device device" 1>&2
306         exit 1
307     fi
308     
309     $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
310         match($1,what) && NF==1 { 
311             v=$1
312             getline
313             print v, $0
314             exit
315         }
316         match($1,what) {
317             print
318             exit
319         }
320     '
321 }
322
323 #
324 # _df_dir : get an IRIX style df line for device where a directory resides
325 #
326 #       - returns fs type in field two (ala IRIX)
327 #       - joins line together if split by fancy df formatting
328 #       - strips header etc
329 #
330
331 _df_dir()
332 {
333     if [ $# -ne 1 ]
334     then
335         echo "Usage: _df_dir device" 1>&2
336         exit 1
337     fi
338     
339     $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
340         NR == 2 && NF==1 { 
341             v=$1
342             getline 
343             print v, $0;
344             exit 0
345         }
346         NR == 2 {
347             print;
348             exit 0
349         }
350         {}
351     '
352     # otherwise, nada
353 }
354
355 # return percentage used disk space for mounted device
356
357 _used()
358 {
359     if [ $# -ne 1 ]
360     then
361         echo "Usage: _used device" 1>&2
362         exit 1
363     fi
364     
365     _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
366 }
367
368 # return the FS type of a mounted device
369 #
370 _fs_type()
371 {
372     if [ $# -ne 1 ]
373     then
374         echo "Usage: _fs_type device" 1>&2
375         exit 1
376     fi
377     
378     _df_device $1 | $AWK_PROG '{ print $2 }'
379 }
380
381 # return the FS mount options of a mounted device
382 #
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
385 # this for now
386 #
387 _fs_options()
388 {
389     if [ $# -ne 1 ]
390     then
391         echo "Usage: _fs_options device" 1>&2
392         exit 1
393     fi
394     
395     $AWK_PROG -v dev=$1 '
396         match($1,dev) { print $4 }
397     ' </proc/mounts
398     
399 }
400
401 # returns device number if a file is a block device
402 #
403 _is_block_dev()
404 {
405     if [ $# -ne 1 ]
406     then
407         echo "Usage: _is_block_dev dev" 1>&2
408         exit 1
409     fi
410     
411     [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
412 }
413
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
422 # $seq.out and exit.
423
424 _do()
425 {
426     if [ $# -eq 1 ]; then
427         _cmd=$1
428     elif [ $# -eq 2 ]; then
429         _note=$1
430         _cmd=$2
431         echo -n "$_note... "
432     else
433         echo "Usage: _do [note] cmd" 1>&2
434         status=1; exit
435     fi
436
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
442             echo "done"
443         else
444             echo "fail"
445         fi
446     fi
447     if [ $ret -ne 0  ] \
448         && [ "$_do_die_on_error" = "always" \
449             -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
450     then
451         [ $# -ne 2 ] && echo
452         eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
453         status=1; exit
454     fi
455
456     return $ret
457 }
458
459 # bail out, setting up .notrun file
460
461 _notrun()
462 {
463     echo "$*" >$seq.notrun
464     echo "$seq not run: $*"
465     status=0
466     exit
467 }
468
469 # just plain bail out
470
471 _fail()
472 {
473     echo "$*" | tee -a $here/$seq.full
474     echo "(see $seq.full for details)"
475     status=1
476     exit 1
477 }
478
479 # tests whether $FSTYP is one of the supported filesystems for a test
480 #
481 _supported_fs()
482 {
483     for f
484     do
485         if [ "$f" = "$FSTYP" ]
486         then
487             return
488         fi
489     done
490
491     _notrun "not suitable for this filesystem type: $FSTYP"
492 }
493
494 # tests whether $FSTYP is one of the supported OSes for a test
495 #
496 _supported_os()
497 {
498     for h
499     do
500         if [ "$h" = "$HOSTOS" ]
501         then
502             return
503         fi
504     done
505
506     _notrun "not suitable for this OS: $HOSTOS"
507 }
508
509 # this test needs a scratch partition - check we're ok & unmount it
510
511 _require_scratch()
512 {
513     case "$FSTYP" in
514         xfs|udf)
515                  if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
516                  then
517                      _notrun "this test requires a valid \$SCRATCH_DEV"
518                  fi
519                  
520                  if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
521                  then
522                      _notrun "this test requires a valid \$SCRATCH_DEV"
523                  fi
524                  ;;
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" ]
528                  then
529                      _notrun "this test requires a valid \$SCRATCH_DEV"
530                  fi
531                  ;;
532         *)
533                  _notrun "\$FSTYP ($FSTYP) unknown or not specified"
534                  ;;
535     esac
536
537     
538     # mounted?
539     if _mount | grep -q $SCRATCH_DEV
540     then 
541         # if it's mounted, make sure its on $SCRATCH_MNT
542         if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
543         then 
544             echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
545             exit 1
546         fi
547         # and then unmount it
548         if ! $UMOUNT_PROG $SCRATCH_DEV
549         then
550             echo "failed to unmount $SCRATCH_DEV"
551             exit 1
552         fi
553     fi
554 }
555
556 # this test needs a logdev 
557
558 _require_logdev()
559 {
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"
564
565     # ensure its not mounted
566     $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
567 }
568
569 # this test requires loopback device support
570
571 _require_loop()
572 {
573     if [ "$HOSTOS" != "Linux" ]
574     then
575         _notrun "This test requires linux for loopback device support"
576     fi
577
578     modprobe loop >/dev/null 2>&1
579     if grep loop /proc/devices >/dev/null 2>&1
580     then
581         :
582     else
583         _notrun "This test requires loopback device support"
584     fi
585 }
586
587 # this test requires that (large) loopback device files are not in use
588
589 _require_nobigloopfs()
590 {
591     [ "$USE_BIG_LOOPFS" = yes ] && \
592         _notrun "Large filesystem testing in progress, skipped this test"
593 }
594
595 # this test requires that a realtime subvolume is in use, and
596 # that the kernel supports realtime as well.
597
598 _require_realtime()
599 {
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"
604 }
605
606 # this test requires that external log/realtime devices are not in use
607
608 _require_nonexternal()
609 {
610     [ "$USE_EXTERNAL" = yes ] && \
611         _notrun "External device testing in progress, skipped this test"
612 }
613
614 # check that a FS is mounted as XFS. if so, return mount point
615 #
616 _xfs_mounted()
617 {
618     if [ $# -ne 1 ]
619     then
620         echo "Usage: _xfs_mounted device" 1>&2
621         exit 1
622     fi
623     
624     device=$1
625     
626     if _mount | grep $device | $AWK_PROG '
627         /type xfs/  { print $3 ; exit 0 }
628         END         { exit 1 }
629     '
630     then
631         echo "_xfs_mounted: $device is not a mounted XFS FS"
632         exit 1
633     fi
634 }
635
636
637 # remount a FS to a new mode (ro or rw)
638 #
639 _remount()
640 {
641     if [ $# -ne 2 ]
642     then
643         echo "Usage: _remount device ro/rw" 1>&2
644         exit 1
645     fi
646     device=$1
647     mode=$2
648     
649     if ! mount -o remount,$mode $device
650     then
651         echo "_remount: failed to remount filesystem on $device as $mode"
652         exit 1
653     fi
654 }
655
656 # run xfs_check and friends on a FS. 
657 #
658 # if the filesystem is mounted, it's either remounted ro before being
659 # checked or it's unmounted and then remounted
660 #
661
662 USE_REMOUNT=0
663
664 _check_xfs_filesystem()
665 {
666     if [ $# -ne 3 ]
667     then
668         echo "Usage: _check_fs device <logdev>|none <rtdev>|none" 1>&2
669         exit 1
670     fi
671
672     device=$1
673     if [ "$2" != "none" ]; then
674         extra_log_options="-l$2"
675         extra_mount_options="-ologdev=$2"
676     fi
677
678     if [ "$3" != "none" ]; then
679         extra_rt_options="-r$3"
680         extra_mount_options=$extra_mount_options" -ortdev=$3"
681     fi
682
683     [ "$FSTYP" != xfs ] && return 0
684     testoption=""
685     [ "$USE_BIG_LOOPFS" = yes ] && testoption=-t
686
687     type=`_fs_type $device`
688     ok=1
689     
690     if [ "$type" = "xfs" ]
691     then
692         # mounted... 
693         
694         if [ $USE_REMOUNT -eq 0 ]
695         then
696             mountpoint=`_xfs_mounted $device`
697             $UMOUNT_PROG $device
698         else
699             _remount $device ro
700         fi
701     fi
702
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" ]
706     then
707         echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
708         
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
713         
714         ok=0
715     fi
716
717     $XFS_CHECK_PROG $testoption $extra_log_options $device 2>&1 |\
718          _fix_malloc >$tmp.fs_check 
719     if [ -s $tmp.fs_check ]
720     then
721         echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
722         
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
727         
728         ok=0
729     fi
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
733     if [ $? -ne 0 ]
734     then
735         echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
736         
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
741         
742         ok=0
743     fi
744     rm -f $tmp.fs_check $tmp.logprint $tmp.repair
745  
746     if [ $ok -eq 0 ]
747     then
748         echo "*** mount output ***"                             >>$here/$seq.full
749         _mount                                                  >>$here/$seq.full
750         echo "*** end mount output"                             >>$here/$seq.full
751     elif [ "$type" = "xfs" ]
752     then
753         # mounted... 
754         if [ $USE_REMOUNT -eq 0 ]
755         then
756             if ! _mount -t xfs $extra_mount_options $device $mountpoint
757             then
758                 echo "!!! failed to remount $device on $mountpoint"
759                 ok=0
760             fi
761         else
762             _remount $device rw
763         fi
764     fi
765     
766     [ $ok -eq 0 ] && exit 1
767     return 0    
768 }
769
770 _check_udf_filesystem()
771 {
772     if [ $# -ne 1 -a $# -ne 2 ]
773     then
774         echo "Usage: _check_fs device [last_block]" 1>&2
775         exit 1
776     fi
777
778     device=$1
779     if [ $# -eq 2 ];
780     then
781         LAST_BLOCK=`expr \( $2 - 1 \)`
782         OPT_ARG="-lastvalidblock $LAST_BLOCK"
783     fi
784
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.
790
791     rm -f $seq.checkfs
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"
796 }
797
798 _check_test_fs()
799 {
800     TEST_LOG="none"
801     TEST_RT="none"
802     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
803         TEST_LOG="$TEST_LOGDEV"
804
805     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
806         TEST_RT="$TEST_RTDEV"
807
808     _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
809 }
810
811 _check_scratch_fs()
812 {
813     case $FSTYP in
814     xfs)
815         SCRATCH_LOG="none"
816         SCRATCH_RT="none"
817         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
818             SCRATCH_LOG="$SCRATCH_LOGDEV"
819
820         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
821             SCRATCH_RT="$SCRATCH_RTDEV"
822
823         _check_xfs_filesystem $SCRATCH_DEV $SCRATCH_LOG $SCRATCH_RT
824         ;;
825     udf)
826         _check_udf_filesystem $SCRATCH_DEV $udf_fsize
827         ;;
828     nfs*)
829         # Don't know how to check an NFS filesystem, yet.
830         ;;
831     *)
832         ;;
833     esac
834 }
835
836 _full_fstyp_details()
837 {
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)"
844         fi
845      fi
846      echo $FSTYP
847 }
848
849 _full_platform_details()
850 {
851      os=`uname -s`
852      host=`hostname -s`
853      kernel=`uname -r`
854      platform=`uname -m`
855      echo "$os/$platform $host $kernel"
856 }
857
858 _check_testdir()
859 {
860     case $FSTYP in
861     xfs)
862         _check_test_fs
863         ;;
864     udf)
865         _cleanup_testdir
866         _check_scratch_fs
867         _scratch_mount
868         ;;
869     nfs*)
870         # Don't know how to check an NFS filesystem, yet.
871         ;;
872     *)
873         ;;
874     esac
875 }
876
877
878 _setup_xfs_testdir()
879 {
880     [ "$FSTYP" != "xfs" ] \
881         && _fail "setup_xfs_testdir: \$FSTYP ($FSTYP) is not xfs"
882     
883     testdir=$TEST_DIR
884 }
885
886 _setup_udf_testdir()
887 {
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"
894     
895     # mounted?
896     if _mount | grep -q $SCRATCH_DEV
897     then 
898         # if it's mounted, make sure its on $TEST_RW_DIR
899         if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
900         then 
901             _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
902         fi
903         $UMOUNT_PROG $SCRATCH_DEV
904     fi 
905
906     _scratch_mkfs
907     _scratch_mount
908
909     testdir=$SCRATCH_MNT
910 }
911
912 _setup_nfs_testdir()
913 {
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"
920     
921     # mounted?
922     if _mount | grep -q $SCRATCH_DEV
923     then 
924         # if it's mounted, make sure its on $TEST_RW_DIR
925         if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
926         then 
927             _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
928         fi
929         $UMOUNT_PROG $SCRATCH_DEV
930     fi 
931
932     _scratch_mkfs
933     _scratch_mount
934
935     testdir=$SCRATCH_MNT
936 }
937
938 _setup_testdir()
939 {
940     case $FSTYP in
941     xfs)
942         _setup_xfs_testdir
943         ;;
944     udf)
945         _setup_udf_testdir
946         ;;
947     nfs*)
948         _setup_nfs_testdir
949         ;;
950     *)
951         _fail "\$FSTYP is not xfs, udf or nfs"
952         ;;
953     esac    
954 }
955
956 _cleanup_testdir()
957 {
958     case $FSTYP in
959     xfs)
960         # do nothing, testdir is $TEST_DIR
961         ;;
962     udf)
963         # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
964         [ -n "$testdir" ] && $UMOUNT_PROG $testdir
965         ;;
966     nfs*)
967         # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
968         [ -n "$testdir" ] && $UMOUNT_PROG $testdir
969         ;;
970     *)
971         _fail "\$FSTYP is not xfs, udf or nfs"
972         ;;
973     esac    
974 }
975
976 ################################################################################
977
978 if [ "$iam" != new -a "$iam" != bench ]
979 then
980     # make some further configuration checks here
981
982     if [ "$TEST_DEV" = ""  ]
983     then
984         echo "common.rc: Error: \$TEST_DEV is not set"
985         exit 1
986     fi
987     
988     # if $TEST_DEV is not mounted, mount it now as XFS
989     if [ -z "`_fs_type $TEST_DEV`" ]
990     then
991         # $TEST_DEV is not mounted
992         if ! _test_mount
993         then
994             echo "common.rc: retrying test device mount with external set"
995             [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
996             if ! _test_mount
997             then
998                 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
999                 exit 1
1000             fi
1001         fi
1002     fi
1003     
1004     if [ "`_fs_type $TEST_DEV`" != "xfs" ]
1005     then
1006         echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
1007         $DF_PROG $TEST_DEV
1008         exit 1
1009     fi
1010
1011 fi
1012
1013 _link_out_file()
1014 {
1015    if [ -z "$1" ]; then
1016       echo Error must pass \$seq.
1017       exit      
1018    fi
1019    rm -f $1
1020    if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1021       ln -s $1.irix $1
1022    elif [ "`uname`" == "Linux" ]; then
1023       ln -s $1.linux $1
1024    else
1025       echo Error test $seq does not run on the operating system: `uname`
1026       exit
1027    fi
1028 }
1029
1030 # make sure this script returns success
1031 /bin/true