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