Fixed merge problems
[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         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
127     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     [ "$HOSTOS" != "IRIX" ] && \
170         SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
171
172     $MKFS_XFS_PROG $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
173     mkfs_status=$?
174
175     if [ "$USE_BIG_LOOPFS" = yes ]; then
176         [ -z "$RETAIN_AG_BYTES" ] && RETAIN_AG_BYTES=0
177         ./tools/ag-wipe -q -r $RETAIN_AG_BYTES $SCRATCH_DEV
178     fi
179
180     return $mkfs_status
181 }
182
183 _scratch_mkfs()
184 {
185     case $FSTYP in
186     xfs)
187         _scratch_mkfs_xfs $*
188         ;;
189     nfs*)
190         # do nothing for nfs
191         ;;
192     udf|*)
193         $MKFS_PROG -t $FSTYP $MKFS_OPTIONS $* > /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_BIG_LOOPFS" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
220     $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
221 }
222
223 _get_pids_by_name()
224 {
225     if [ $# -ne 1 ]
226     then
227         echo "Usage: _get_pids_by_name process-name" 1>&2
228         exit 1
229     fi
230
231     # Algorithm ... all ps(1) variants have a time of the form MM:SS or
232     # HH:MM:SS before the psargs field, use this as the search anchor.
233     #
234     # Matches with $1 (process-name) occur if the first psarg is $1
235     # or ends in /$1 ... the matching uses sed's regular expressions,
236     # so passing a regex into $1 will work.
237
238     ps $PS_ALL_FLAGS \
239     | sed -n \
240         -e 's/$/ /' \
241         -e 's/[         ][      ]*/ /g' \
242         -e 's/^ //' \
243         -e 's/^[^ ]* //' \
244         -e "/[0-9]:[0-9][0-9]  *[^ ]*\/$1 /s/ .*//p" \
245         -e "/[0-9]:[0-9][0-9]  *$1 /s/ .*//p"
246 }
247
248 # fqdn for localhost
249 #
250 _get_fqdn()
251 {
252     host=`hostname`
253     $NSLOOKUP_PROG $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
254 }
255
256 # fix malloc libs output
257 #
258 _fix_malloc()
259 {
260     # filter out the Electric Fence notice
261     $PERL_PROG -e '
262         while (<>) {
263             if (defined $o && /^\s+Electric Fence/) {
264                 chomp($o);
265                 print "$o";
266                 undef $o;
267                 next;
268             }
269             print $o if (defined $o);
270
271             $o=$_;
272         }
273         print $o if (defined $o);
274     '
275 }
276
277 # check if run as root
278 #
279 _need_to_be_root()
280 {
281     id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
282     if [ "$id" -ne 0 ]
283     then
284         echo "Arrgh ... you need to be root (not uid=$id) to run this test"
285         exit 1
286     fi
287 }
288
289
290 #
291 # _df_device : get an IRIX style df line for a given device 
292 #
293 #       - returns "" if not mounted
294 #       - returns fs type in field two (ala IRIX)
295 #       - joins line together if split by fancy df formatting
296 #       - strips header etc
297 #
298
299 _df_device()
300 {
301     if [ $# -ne 1 ]
302     then
303         echo "Usage: _df_device device" 1>&2
304         exit 1
305     fi
306     
307     $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
308         match($1,what) && NF==1 { 
309             v=$1
310             getline
311             print v, $0
312             exit
313         }
314         match($1,what) {
315             print
316             exit
317         }
318     '
319 }
320
321 #
322 # _df_dir : get an IRIX style df line for device where a directory resides
323 #
324 #       - returns fs type in field two (ala IRIX)
325 #       - joins line together if split by fancy df formatting
326 #       - strips header etc
327 #
328
329 _df_dir()
330 {
331     if [ $# -ne 1 ]
332     then
333         echo "Usage: _df_dir device" 1>&2
334         exit 1
335     fi
336     
337     $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
338         NR == 2 && NF==1 { 
339             v=$1
340             getline 
341             print v, $0;
342             exit 0
343         }
344         NR == 2 {
345             print;
346             exit 0
347         }
348         {}
349     '
350     # otherwise, nada
351 }
352
353 # return percentage used disk space for mounted device
354
355 _used()
356 {
357     if [ $# -ne 1 ]
358     then
359         echo "Usage: _used device" 1>&2
360         exit 1
361     fi
362     
363     _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
364 }
365
366 # return the FS type of a mounted device
367 #
368 _fs_type()
369 {
370     if [ $# -ne 1 ]
371     then
372         echo "Usage: _fs_type device" 1>&2
373         exit 1
374     fi
375     
376     _df_device $1 | $AWK_PROG '{ print $2 }'
377 }
378
379 # return the FS mount options of a mounted device
380 #
381 # should write a version which just parses the output of mount for IRIX
382 # compatibility, but since this isn't used at all, at the moment I'll leave
383 # this for now
384 #
385 _fs_options()
386 {
387     if [ $# -ne 1 ]
388     then
389         echo "Usage: _fs_options device" 1>&2
390         exit 1
391     fi
392     
393     $AWK_PROG -v dev=$1 '
394         match($1,dev) { print $4 }
395     ' </proc/mounts
396     
397 }
398
399 # returns device number if a file is a block device
400 #
401 _is_block_dev()
402 {
403     if [ $# -ne 1 ]
404     then
405         echo "Usage: _is_block_dev dev" 1>&2
406         exit 1
407     fi
408     
409     [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
410 }
411
412 # Do a command, log it to $seq.full, optionally test return status
413 # and die if command fails. If called with one argument _do executes the
414 # command, logs it, and returns its exit status. With two arguments _do
415 # first prints the message passed in the first argument, and then "done"
416 # or "fail" depending on the return status of the command passed in the
417 # second argument. If the command fails and the variable _do_die_on_error
418 # is set to "always" or the two argument form is used and _do_die_on_error
419 # is set to "message_only" _do will print an error message to
420 # $seq.out and exit.
421
422 _do()
423 {
424     if [ $# -eq 1 ]; then
425         _cmd=$1
426     elif [ $# -eq 2 ]; then
427         _note=$1
428         _cmd=$2
429         echo -n "$_note... "
430     else
431         echo "Usage: _do [note] cmd" 1>&2
432         status=1; exit
433     fi
434
435     (eval "echo '---' \"$_cmd\"") >>$here/$seq.full
436     (eval "$_cmd") >$tmp._out 2>&1; ret=$?
437     cat $tmp._out | _fix_malloc >>$here/$seq.full
438     if [ $# -eq 2 ]; then
439         if [ $ret -eq 0 ]; then
440             echo "done"
441         else
442             echo "fail"
443         fi
444     fi
445     if [ $ret -ne 0  ] \
446         && [ "$_do_die_on_error" = "always" \
447             -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
448     then
449         [ $# -ne 2 ] && echo
450         eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
451         status=1; exit
452     fi
453
454     return $ret
455 }
456
457 # bail out, setting up .notrun file
458
459 _notrun()
460 {
461     echo "$*" >$seq.notrun
462     echo "$seq not run: $*"
463     status=0
464     exit
465 }
466
467 # just plain bail out
468
469 _fail()
470 {
471     echo "$*" | tee -a $here/$seq.full
472     echo "(see $seq.full for details)"
473     status=1
474     exit 1
475 }
476
477 # tests whether $FSTYP is one of the supported filesystems for a test
478 #
479 _supported_fs()
480 {
481     for f
482     do
483         if [ "$f" = "$FSTYP" ]
484         then
485             return
486         fi
487     done
488
489     _notrun "not suitable for this filesystem type: $FSTYP"
490 }
491
492 # tests whether $FSTYP is one of the supported OSes for a test
493 #
494 _supported_os()
495 {
496     for h
497     do
498         if [ "$h" = "$HOSTOS" ]
499         then
500             return
501         fi
502     done
503
504     _notrun "not suitable for this OS: $HOSTOS"
505 }
506
507 # this test needs a scratch partition - check we're ok & unmount it
508
509 _require_scratch()
510 {
511     case "$FSTYP" in
512         xfs|udf)
513                  if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
514                  then
515                      _notrun "this test requires a valid \$SCRATCH_DEV"
516                  fi
517                  
518                  if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
519                  then
520                      _notrun "this test requires a valid \$SCRATCH_DEV"
521                  fi
522                  ;;
523         nfs*)
524                  echo $SCRATCH_DEV | grep -q ":" > /dev/null 2>&1
525                  if [ ! -z "$SCRATCH_DEV" -a ! -b "$SCRATCH_DEV" -a "$?" != "0" ]
526                  then
527                      _notrun "this test requires a valid \$SCRATCH_DEV"
528                  fi
529                  ;;
530         *)
531                  _notrun "\$FSTYP ($FSTYP) unknown or not specified"
532                  ;;
533     esac
534
535     
536     # mounted?
537     if _mount | grep -q $SCRATCH_DEV
538     then 
539         # if it's mounted, make sure its on $SCRATCH_MNT
540         if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
541         then 
542             echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
543             exit 1
544         fi
545         # and then unmount it
546         if ! $UMOUNT_PROG $SCRATCH_DEV
547         then
548             echo "failed to unmount $SCRATCH_DEV"
549             exit 1
550         fi
551     fi
552 }
553
554 # this test needs a logdev 
555
556 _require_logdev()
557 {
558     [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
559         _notrun "This test requires a valid \$SCRATCH_LOGDEV" 
560     [ "$USE_EXTERNAL" != yes ] && \
561         _notrun "This test requires USE_EXTERNAL to be enabled"
562
563     # ensure its not mounted
564     $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
565 }
566
567 # this test requires loopback device support
568
569 _require_loop()
570 {
571     if [ "$HOSTOS" != "Linux" ]
572     then
573         _notrun "This test requires linux for loopback device support"
574     fi
575
576     modprobe loop >/dev/null 2>&1
577     if grep loop /proc/devices >/dev/null 2>&1
578     then
579         :
580     else
581         _notrun "This test requires loopback device support"
582     fi
583 }
584
585 # this test requires that (large) loopback device files are not in use
586
587 _require_nobigloopfs()
588 {
589     [ "$USE_BIG_LOOPFS" = yes ] && \
590         _notrun "Large filesystem testing in progress, skipped this test"
591 }
592
593 # this test requires that external log/realtime devices are not in use
594
595 _require_nonexternal()
596 {
597     [ "$USE_EXTERNAL" = yes ] && \
598         _notrun "External device testing in progress, skipped this test"
599 }
600
601 # check that a FS is mounted as XFS. if so, return mount point
602 #
603 _xfs_mounted()
604 {
605     if [ $# -ne 1 ]
606     then
607         echo "Usage: _xfs_mounted device" 1>&2
608         exit 1
609     fi
610     
611     device=$1
612     
613     if _mount | grep $device | $AWK_PROG '
614         /type xfs/  { print $3 ; exit 0 }
615         END         { exit 1 }
616     '
617     then
618         echo "_xfs_mounted: $device is not a mounted XFS FS"
619         exit 1
620     fi
621 }
622
623
624 # remount a FS to a new mode (ro or rw)
625 #
626 _remount()
627 {
628     if [ $# -ne 2 ]
629     then
630         echo "Usage: _remount device ro/rw" 1>&2
631         exit 1
632     fi
633     device=$1
634     mode=$2
635     
636     if ! mount -o remount,$mode $device
637     then
638         echo "_remount: failed to remount filesystem on $device as $mode"
639         exit 1
640     fi
641 }
642
643 # run xfs_check and friends on a FS. 
644 #
645 # if the filesystem is mounted, it's either remounted ro before being
646 # checked or it's unmounted and then remounted
647 #
648
649 USE_REMOUNT=0
650
651 _check_xfs_filesystem()
652 {
653     if [ $# -ne 1 -a $# -ne 2 ]
654     then
655         echo "Usage: _check_fs device [logdevice]" 1>&2
656         exit 1
657     fi
658     
659     device=$1
660     if [ $# -eq 2 -a "$2" != "" ]; then
661         extra_log_options="-l$2"
662         extra_mount_options="-ologdev=$2"
663     fi
664
665     [ "$FSTYP" != xfs ] && return 0
666     testoption=""
667     [ "$USE_BIG_LOOPFS" = yes ] && testoption=-t
668
669     type=`_fs_type $device`
670     ok=1
671     
672     if [ "$type" = "xfs" ]
673     then
674         # mounted... 
675         
676         if [ $USE_REMOUNT -eq 0 ]
677         then
678             mountpoint=`_xfs_mounted $device`
679             $UMOUNT_PROG $device
680         else
681             _remount $device ro
682         fi
683     fi
684
685     $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
686                 | tee $tmp.fs_check | grep -q "<CLEAN>"
687     if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
688     then
689         echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
690         
691         echo "_check_fs: filesystem on $device has dirty log"   >>$here/$seq.full
692         echo "*** xfs_logprint -t output ***"                   >>$here/$seq.full
693         cat $tmp.fs_check                                       >>$here/$seq.full
694         echo "*** end xfs_logprint output"                      >>$here/$seq.full
695         
696         ok=0
697     fi
698
699     $XFS_CHECK_PROG $testoption $extra_log_options $device 2>&1 |\
700          _fix_malloc >$tmp.fs_check 
701     if [ -s $tmp.fs_check ]
702     then
703         echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
704         
705         echo "_check_fs: filesystem on $device is inconsistent" >>$here/$seq.full
706         echo "*** xfs_check output ***"                         >>$here/$seq.full
707         cat $tmp.fs_check                                       >>$here/$seq.full
708         echo "*** end xfs_check output"                         >>$here/$seq.full
709         
710         ok=0
711     fi
712     # repair doesn't scale massively at this stage, optionally skip it for now
713     [ "$USE_BIG_LOOPFS" = yes ] || \
714     $XFS_REPAIR_PROG -n $extra_log_options $device >$tmp.fs_check 2>&1
715     if [ $? -ne 0 ]
716     then
717         echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
718         
719         echo "_check_fs: filesystem on $device is inconsistent" >>$here/$seq.full
720         echo "*** xfs_repair -n output ***"                     >>$here/$seq.full
721         cat $tmp.fs_check | _fix_malloc                         >>$here/$seq.full
722         echo "*** end xfs_repair output"                        >>$here/$seq.full
723         
724         ok=0
725     fi
726     rm -f $tmp.fs_check
727  
728     if [ $ok -eq 0 ]
729     then
730         echo "*** mount output ***"                             >>$here/$seq.full
731         _mount                                                  >>$here/$seq.full
732         echo "*** end mount output"                             >>$here/$seq.full
733     elif [ "$type" = "xfs" ]
734     then
735         # mounted... 
736         if [ $USE_REMOUNT -eq 0 ]
737         then
738             if ! _mount -t xfs $extra_mount_options $device $mountpoint
739             then
740                 echo "!!! failed to remount $device on $mountpoint"
741                 ok=0
742             fi
743         else
744             _remount $device rw
745         fi
746     fi
747     
748     [ $ok -eq 0 ] && exit 1
749     return 0    
750 }
751
752 _check_udf_filesystem()
753 {
754     if [ $# -ne 1 -a $# -ne 2 ]
755     then
756         echo "Usage: _check_fs device [last_block]" 1>&2
757         exit 1
758     fi
759
760     device=$1
761     if [ $# -eq 2 ];
762     then
763         LAST_BLOCK=`expr \( $2 - 1 \)`
764         OPT_ARG="-lastvalidblock $LAST_BLOCK"
765     fi
766
767     # Output messages format:
768     #       Error messages contain :   "Error:" or   "error:"
769     #     Warning messages contain : "Warning:" or "warning:"
770     #   Attention messages contain :    "Note:" or    "note:"
771     # Message continuation lines start with a "-" character.
772
773     rm -f $seq.checkfs
774     sleep 1 # Due to a problem with time stamps in udf_test
775     $here/src/udf_test $OPT_ARG $device | tee $here/$seq.checkfs | \
776         egrep -i "error:|warning:|Error count:|Warning count:" | \
777         egrep -v "Error count:   0|Warning count:   0"
778 }
779
780 _check_test_fs()
781 {
782     TEST_LOG=""
783     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
784         TEST_LOG="$TEST_LOGDEV"
785
786     _check_xfs_filesystem $TEST_DEV $TEST_LOG
787 }
788
789 _check_scratch_fs()
790 {
791
792
793     case $FSTYP in
794     xfs)
795         SCRATCH_LOG=""
796         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
797             SCRATCH_LOG="$SCRATCH_LOGDEV"
798
799         _check_xfs_filesystem $SCRATCH_DEV $SCRATCH_LOG
800         ;;
801     udf)
802         _check_udf_filesystem $SCRATCH_DEV $udf_fsize
803         ;;
804     nfs*)
805         # Don't know how to check an NFS filesystem, yet.
806         ;;
807     *)
808         ;;
809     esac
810 }
811
812 _full_fstyp_details()
813 {
814      [ -z "$FSTYP" ] && FSTYP=xfs
815      if [ $FSTYP = xfs ]; then
816         if grep 'debug 0' /proc/fs/xfs/stat >/dev/null; then
817             FSTYP="$FSTYP (non-debug)"
818         elif grep 'debug 1' /proc/fs/xfs/stat >/dev/null; then
819             FSTYP="$FSTYP (debug)"
820         fi
821      fi
822      echo $FSTYP
823 }
824
825 _full_platform_details()
826 {
827      os=`uname -s`
828      host=`hostname -s`
829      kernel=`uname -r`
830      platform=`uname -m`
831      echo "$os/$platform $host $kernel"
832 }
833
834 _check_testdir()
835 {
836   
837
838     case $FSTYP in
839     xfs)
840         _check_test_fs
841         ;;
842     udf)
843         _cleanup_testdir
844         _check_scratch_fs
845         _scratch_mount
846         ;;
847     nfs*)
848         # Don't know how to check an NFS filesystem, yet.
849         ;;
850     *)
851         ;;
852     esac
853 }
854
855
856 _setup_xfs_testdir()
857 {
858     [ "$FSTYP" != "xfs" ] \
859         && _fail "setup_xfs_testdir: \$FSTYP ($FSTYP) is not xfs"
860     
861     testdir=$TEST_DIR
862 }
863
864 _setup_udf_testdir()
865 {
866     [ "$FSTYP" != "udf" ] \
867         && _fail "setup_udf_testdir: \$FSTYP is not udf"
868     [ -z "$SCRATCH_DEV" -o ! -b "$SCRATCH_DEV" ] \
869         && _notrun "this test requires a valid \$SCRATCH_DEV"
870     [ -z "$SCRATCH_MNT" ] \
871         && _notrun "this test requires a valid \$SCRATCH_MNT"
872     
873     # mounted?
874     if _mount | grep -q $SCRATCH_DEV
875     then 
876         # if it's mounted, make sure its on $TEST_RW_DIR
877         if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
878         then 
879             _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
880         fi
881         $UMOUNT_PROG $SCRATCH_DEV
882     fi 
883
884     _scratch_mkfs
885     _scratch_mount
886
887     testdir=$SCRATCH_MNT
888 }
889
890 _setup_nfs_testdir()
891 {
892     [ "$FSTYP" != "nfs" ] \
893         && _fail "setup_udf_testdir: \$FSTYP is not nfs"
894     [ -z "$SCRATCH_DEV" ] \
895         && _notrun "this test requires a valid host fs for \$SCRATCH_DEV"
896     [ -z "$SCRATCH_MNT" ] \
897         && _notrun "this test requires a valid \$SCRATCH_MNT"
898     
899     # mounted?
900     if _mount | grep -q $SCRATCH_DEV
901     then 
902         # if it's mounted, make sure its on $TEST_RW_DIR
903         if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
904         then 
905             _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
906         fi
907         $UMOUNT_PROG $SCRATCH_DEV
908     fi 
909
910     _scratch_mkfs
911     _scratch_mount
912
913     testdir=$SCRATCH_MNT
914 }
915
916 _setup_testdir()
917 {
918
919
920     case $FSTYP in
921     xfs)
922         _setup_xfs_testdir
923         ;;
924     udf)
925         _setup_udf_testdir
926         ;;
927     nfs*)
928         _setup_nfs_testdir
929         ;;
930     *)
931         _fail "\$FSTYP is not xfs, udf or nfs"
932         ;;
933     esac    
934 }
935
936 _cleanup_testdir()
937 {
938
939
940     case $FSTYP in
941     xfs)
942         # do nothing, testdir is $TEST_DIR
943         ;;
944     udf)
945         # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
946         [ -n "$testdir" ] && $UMOUNT_PROG $testdir
947         ;;
948     nfs*)
949         # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
950         [ -n "$testdir" ] && $UMOUNT_PROG $testdir
951         ;;
952     *)
953         _fail "\$FSTYP is not xfs, udf or nfs"
954         ;;
955     esac    
956 }
957
958 ################################################################################
959
960 if [ "$iam" != new -a "$iam" != bench ]
961 then
962     # make some further configuration checks here
963
964     if [ "$TEST_DEV" = ""  ]
965     then
966         echo "common.rc: Error: \$TEST_DEV is not set"
967         exit 1
968     fi
969     
970     # if $TEST_DEV is not mounted, mount it now as XFS
971     if [ -z "`_fs_type $TEST_DEV`" ]
972     then
973         # $TEST_DEV is not mounted
974         if ! _test_mount
975         then
976             echo "common.rc: retrying test device mount with external set"
977             [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
978             if ! _test_mount
979             then
980                 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
981                 exit 1
982             fi
983         fi
984     fi
985     
986     if [ "`_fs_type $TEST_DEV`" != "xfs" ]
987     then
988         echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
989         $DF_PROG $TEST_DEV
990         exit 1
991     fi
992
993 fi
994
995 _link_out_file()
996 {
997    if [ -z "$1" ]; then
998       echo Error must pass \$seq.
999       exit      
1000    fi
1001    rm -f $1
1002    if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1003       ln -s $1.irix $1
1004    elif [ "`uname`" == "Linux" ]; then
1005       ln -s $1.linux $1
1006    else
1007       echo Error test $seq does not run on the operating system: `uname`
1008       exit
1009    fi
1010 }
1011
1012 _get_os()
1013 {
1014    
1015    if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1016       os=irix
1017    elif [ "`uname`" == "Linux" ]; then
1018       os=linux
1019    else
1020       echo Error test does not run on the operating system: `uname`
1021       exit
1022    fi
1023 }
1024
1025 # make sure this script returns success
1026 /bin/true