xfstests: add _scratch_mkfs_sized support for btrfs
[xfstests-dev.git] / common.rc
1 ##/bin/bash
2 #-----------------------------------------------------------------------
3 #  Copyright (c) 2000-2006 Silicon Graphics, Inc.  All Rights Reserved.
4 #  This program is free software; you can redistribute it and/or modify
5 #  it under the terms of the GNU General Public License as published by
6 #  the Free Software Foundation; either version 2 of the License, or
7 #  (at your option) any later version.
8 #
9 #  This program is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #  GNU General Public License for more details.
13 #
14 #  You should have received a copy of the GNU General Public License
15 #  along with this program; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
17 #  USA
18 #
19 #  Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
20 #  Mountain View, CA 94043, USA, or: http://www.sgi.com
21 #-----------------------------------------------------------------------
22
23 dd()
24 {
25    if [ "$HOSTOS" == "Linux" ]
26    then 
27         command dd --help | grep noxfer > /dev/null 2>&1
28         
29         if [ "$?" -eq 0 ]
30             then
31                 command dd status=noxfer $@
32             else
33                 command dd $@
34         fi
35    else
36         command dd $@
37    fi
38 }
39
40 # ls -l w/ selinux sometimes puts a dot at the end:
41 # -rwxrw-r--. id1 id2 file1
42
43 _ls_l()
44 {
45         ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /"
46 }
47
48 _mount_opts()
49 {
50     # SELinux adds extra xattrs which can mess up our expected output.
51     # So, mount with a context, and they won't be created
52     # nfs_t is a "liberal" context so we can use it.
53     if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
54         SELINUX_MOUNT_OPTIONS="-o context=system_u:object_r:nfs_t:s0"
55     fi
56
57     case $FSTYP in
58     xfs)
59         export SELINUX_MOUNT_OPTIONS
60         export MOUNT_OPTIONS=$XFS_MOUNT_OPTIONS
61         ;;
62     udf)
63         export MOUNT_OPTIONS=$UDF_MOUNT_OPTIONS
64         ;;
65     nfs)
66         export MOUNT_OPTIONS=$NFS_MOUNT_OPTIONS
67         ;;
68     ext2|ext3|ext4)
69         # acls & xattrs aren't turned on by default on ext$FOO
70         export MOUNT_OPTIONS="-o acl,user_xattr $EXT_MOUNT_OPTIONS"
71         ;;
72     reiserfs)
73         # acls & xattrs aren't turned on by default on reiserfs
74         export MOUNT_OPTIONS="-o acl,user_xattr $REISERFS_MOUNT_OPTIONS"
75         ;;
76     gfs2)
77         # acls aren't turned on by default on gfs2
78         export MOUNT_OPTIONS="-o acl $GFS2_MOUNT_OPTIONS"
79         ;;
80     *)
81         ;;
82     esac
83 }
84
85 _mkfs_opts()
86 {
87     case $FSTYP in
88     xfs)
89         export MKFS_OPTIONS=$XFS_MKFS_OPTIONS
90         ;;
91     udf)
92         [ ! -z "$udf_fsize" ] && \
93             UDF_MKFS_OPTIONS="$UDF_MKFS_OPTIONS -s $udf_fsize"
94         export MKFS_OPTIONS=$UDF_MKFS_OPTIONS
95         ;;
96     nfs)
97         export MKFS_OPTIONS=$NFS_MKFS_OPTIONS
98         ;;
99     reiserfs)
100         export MKFS_OPTIONS="$REISERFS_MKFS_OPTIONS -q"
101         ;;
102     gfs2)
103         export MKFS_OPTIONS="$GFS2_MKFS_OPTIONS -O -p lock_nolock"
104         ;;
105     *)
106         ;;
107     esac
108 }
109
110 _fsck_opts()
111 {
112     case $FSTYP in
113     ext2|ext3|ext4)
114         export FSCK_OPTIONS="-nf"
115         ;;
116     reiserfs)
117         export FSCK_OPTIONS="--yes"
118         ;;
119     *)
120         export FSCK_OPTIONS="-n"
121         ;;
122     esac
123 }
124
125 [ -z "$FSTYP" ] && FSTYP=xfs
126 [ -z "$MOUNT_OPTIONS" ] && _mount_opts
127 [ -z "$MKFS_OPTIONS" ] && _mkfs_opts
128 [ -z "$FSCK_OPTIONS" ] && _fsck_opts
129
130
131 # we need common.config
132 if [ "$iam" != "check" ]
133 then
134     if ! . ./common.config
135         then
136         echo "$iam: failed to source common.config"
137         exit 1
138     fi
139 fi
140
141 # make sure we have a standard umask
142 umask 022
143
144 _mount()
145 {
146     $MOUNT_PROG `_mount_ops_filter $*`
147 }
148
149 _scratch_options()
150 {
151     type=$1
152     SCRATCH_OPTIONS=""
153
154     if [ "$FSTYP" != "xfs" ]; then
155         return
156     fi
157
158     case $type in
159     mkfs)
160         [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
161         rt_opt="-r"
162         log_opt="-l"
163         ;;
164     mount)
165         rt_opt="-o"
166         log_opt="-o"
167         ;;
168     esac
169     [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
170         SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
171     [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
172         SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
173 }
174
175 _test_options()
176 {
177     type=$1
178     TEST_OPTIONS=""
179
180     if [ "$FSTYP" != "xfs" ]; then
181         return
182     fi
183
184     case $type in
185     mkfs)
186         rt_opt="-r"
187         log_opt="-l"
188         ;;
189     mount)
190         rt_opt="-o"
191         log_opt="-o"
192         ;;
193     esac
194     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
195         TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
196     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
197         TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
198 }
199
200 _mount_ops_filter()
201 {
202     params="$*"
203     
204     #get mount point to handle dmapi mtpt option correctly
205     let last_index=$#-1
206     [ $last_index -gt 0 ] && shift $last_index
207     FS_ESCAPED=$1
208     
209     # irix is fussy about how it is fed its mount options
210     # - multiple -o's are not allowed
211     # - no spaces between comma delimitered options
212     # the sed script replaces all -o's (except the first) with a comma
213     # not required for linux, but won't hurt
214     
215     echo $params | sed -e 's/[[:space:]]*-o[[:space:]]*/UnIqUe/1; s/[[:space:]]*-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
216         | sed -e 's/dmapi/dmi/' \
217         | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
218
219 }
220
221 _scratch_mount_options()
222 {
223     _scratch_options mount
224
225     echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
226 }
227
228 _scratch_mount()
229 {
230     _mount -t $FSTYP `_scratch_mount_options $*`
231 }
232
233 _scratch_unmount()
234 {
235     $UMOUNT_PROG $SCRATCH_DEV
236 }
237
238 _scratch_remount()
239 {
240     _scratch_unmount
241     _scratch_mount
242 }
243
244 _test_mount()
245 {
246     _test_options mount
247     _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
248 }
249
250 _scratch_mkfs_options()
251 {
252     _scratch_options mkfs
253     echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
254 }
255
256 _scratch_mkfs_xfs()
257 {
258     # extra mkfs options can be added by tests
259     local extra_mkfs_options=$*
260
261     local tmp_dir=/tmp/
262
263     _scratch_options mkfs
264
265     # save mkfs output in case conflict means we need to run again.
266     # only the output for the mkfs that applies should be shown
267     $MKFS_XFS_PROG $SCRATCH_OPTIONS $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
268         2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
269     local mkfs_status=$?
270
271     # a mkfs failure may be caused by conflicts between
272     # $MKFS_OPTIONS and $extra_mkfs_options
273
274     if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
275         echo "** mkfs failed with extra mkfs options added to \"$MKFS_OPTIONS\" by test $seq **" \
276             >>$here/$seq.full
277         echo "** attempting to mkfs using only test $seq options: $extra_mkfs_options **" \
278             >>$here/$seq.full
279         # running mkfs again. overwrite previous mkfs output files
280         $MKFS_XFS_PROG $SCRATCH_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
281             2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
282         mkfs_status=$?
283     fi
284
285     # output stored mkfs output
286     cat $tmp_dir.mkfserr >&2
287     cat $tmp_dir.mkfsstd
288     rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
289
290     if [ "$USE_BIG_LOOPFS" = yes ]; then
291         [ -z "$RETAIN_AG_BYTES" ] && RETAIN_AG_BYTES=0
292         ./tools/ag-wipe -q -r $RETAIN_AG_BYTES $SCRATCH_DEV
293     fi
294
295     return $mkfs_status
296 }
297
298 _scratch_mkfs()
299 {
300     case $FSTYP in
301     xfs)
302         _scratch_mkfs_xfs $*
303         ;;
304     nfs*)
305         # do nothing for nfs
306         ;;
307     udf)
308         $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
309         ;;
310     *)
311         /sbin/mkfs -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
312         ;;
313     esac
314 }
315
316 # Create fs of certain size on scratch device
317 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
318 _scratch_mkfs_sized()
319 {
320     fssize=$1
321     blocksize=$2
322     [ -z "$blocksize" ] && blocksize=4096
323     blocks=`expr $fssize / $blocksize`
324
325     case $FSTYP in
326     xfs)
327         _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
328         ;;
329     ext2|ext3|ext4)
330         /sbin/mkfs.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
331         ;;
332      btrfs)
333         /sbin/mkfs.$FSTYP $MKFS_OPTIONS $SCRATCH_DEV -b $fssize
334         ;;
335     *)
336         _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
337         ;;
338     esac
339 }
340
341 # Emulate an N-data-disk stripe w/ various stripe units
342 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
343 _scratch_mkfs_geom()
344 {
345     sunit_bytes=$1
346     swidth_mult=$2
347     blocksize=$3
348     [ -z "$blocksize" ] && blocksize=4096
349
350     let sunit_blocks=$sunit_bytes/$blocksize
351     let swidth_blocks=$sunit_blocks*$swidth_mult
352
353     case $FSTYP in
354     xfs)
355         MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
356         ;;
357     ext4)
358         MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
359         ;;
360     *)
361         _notrun "can't mkfs $FSTYP with geometry"
362         ;;
363     esac
364     _scratch_mkfs
365 }
366
367 _scratch_resvblks()
368 {
369         case $FSTYP in
370         xfs)
371                 xfs_io -x -c "resblks $1" $SCRATCH_MNT
372                 ;;
373         *)
374                 ;;
375         esac
376 }
377
378 _scratch_xfs_db_options()
379 {
380     SCRATCH_OPTIONS=""
381     [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
382         SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
383     echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
384 }
385
386 _scratch_xfs_logprint()
387 {
388     SCRATCH_OPTIONS=""
389     [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
390         SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
391     $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
392 }
393
394 _scratch_xfs_check()
395 {
396     SCRATCH_OPTIONS=""
397     [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
398         SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
399     $XFS_CHECK_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
400 }
401
402 _scratch_xfs_repair()
403 {
404     SCRATCH_OPTIONS=""
405     [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
406         SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
407     [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
408         SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
409     [ "$USE_BIG_LOOPFS" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
410     $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
411 }
412
413 _get_pids_by_name()
414 {
415     if [ $# -ne 1 ]
416     then
417         echo "Usage: _get_pids_by_name process-name" 1>&2
418         exit 1
419     fi
420
421     # Algorithm ... all ps(1) variants have a time of the form MM:SS or
422     # HH:MM:SS before the psargs field, use this as the search anchor.
423     #
424     # Matches with $1 (process-name) occur if the first psarg is $1
425     # or ends in /$1 ... the matching uses sed's regular expressions,
426     # so passing a regex into $1 will work.
427
428     ps $PS_ALL_FLAGS \
429     | sed -n \
430         -e 's/$/ /' \
431         -e 's/[         ][      ]*/ /g' \
432         -e 's/^ //' \
433         -e 's/^[^ ]* //' \
434         -e "/[0-9]:[0-9][0-9]  *[^ ]*\/$1 /s/ .*//p" \
435         -e "/[0-9]:[0-9][0-9]  *$1 /s/ .*//p"
436 }
437
438 # fix malloc libs output
439 #
440 _fix_malloc()
441 {
442     # filter out the Electric Fence notice
443     $PERL_PROG -e '
444         while (<>) {
445             if (defined $o && /^\s+Electric Fence/) {
446                 chomp($o);
447                 print "$o";
448                 undef $o;
449                 next;
450             }
451             print $o if (defined $o);
452
453             $o=$_;
454         }
455         print $o if (defined $o);
456     '
457 }
458
459 # check if run as root
460 #
461 _need_to_be_root()
462 {
463     id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
464     if [ "$id" -ne 0 ]
465     then
466         echo "Arrgh ... you need to be root (not uid=$id) to run this test"
467         exit 1
468     fi
469 }
470
471
472 #
473 # _df_device : get an IRIX style df line for a given device
474 #
475 #       - returns "" if not mounted
476 #       - returns fs type in field two (ala IRIX)
477 #       - joins line together if split by fancy df formatting
478 #       - strips header etc
479 #
480
481 _df_device()
482 {
483     if [ $# -ne 1 ]
484     then
485         echo "Usage: _df_device device" 1>&2
486         exit 1
487     fi
488
489     $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
490         match($1,what) && NF==1 {
491             v=$1
492             getline
493             print v, $0
494             exit
495         }
496         match($1,what) {
497             print
498             exit
499         }
500     '
501 }
502
503 #
504 # _df_dir : get an IRIX style df line for device where a directory resides
505 #
506 #       - returns fs type in field two (ala IRIX)
507 #       - joins line together if split by fancy df formatting
508 #       - strips header etc
509 #
510
511 _df_dir()
512 {
513     if [ $# -ne 1 ]
514     then
515         echo "Usage: _df_dir device" 1>&2
516         exit 1
517     fi
518
519     $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
520         NR == 2 && NF==1 {
521             v=$1
522             getline
523             print v, $0;
524             exit 0
525         }
526         NR == 2 {
527             print;
528             exit 0
529         }
530         {}
531     '
532     # otherwise, nada
533 }
534
535 # return percentage used disk space for mounted device
536
537 _used()
538 {
539     if [ $# -ne 1 ]
540     then
541         echo "Usage: _used device" 1>&2
542         exit 1
543     fi
544
545     _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
546 }
547
548 # return the FS type of a mounted device
549 #
550 _fs_type()
551 {
552     if [ $# -ne 1 ]
553     then
554         echo "Usage: _fs_type device" 1>&2
555         exit 1
556     fi
557
558     _df_device $1 | $AWK_PROG '{ print $2 }'
559 }
560
561 # return the FS mount options of a mounted device
562 #
563 # should write a version which just parses the output of mount for IRIX
564 # compatibility, but since this isn't used at all, at the moment I'll leave
565 # this for now
566 #
567 _fs_options()
568 {
569     if [ $# -ne 1 ]
570     then
571         echo "Usage: _fs_options device" 1>&2
572         exit 1
573     fi
574
575     $AWK_PROG -v dev=$1 '
576         match($1,dev) { print $4 }
577     ' </proc/mounts
578 }
579
580 # returns device number if a file is a block device
581 #
582 _is_block_dev()
583 {
584     if [ $# -ne 1 ]
585     then
586         echo "Usage: _is_block_dev dev" 1>&2
587         exit 1
588     fi
589
590     [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
591 }
592
593 # Do a command, log it to $seq.full, optionally test return status
594 # and die if command fails. If called with one argument _do executes the
595 # command, logs it, and returns its exit status. With two arguments _do
596 # first prints the message passed in the first argument, and then "done"
597 # or "fail" depending on the return status of the command passed in the
598 # second argument. If the command fails and the variable _do_die_on_error
599 # is set to "always" or the two argument form is used and _do_die_on_error
600 # is set to "message_only" _do will print an error message to
601 # $seq.out and exit.
602
603 _do()
604 {
605     if [ $# -eq 1 ]; then
606         _cmd=$1
607     elif [ $# -eq 2 ]; then
608         _note=$1
609         _cmd=$2
610         echo -n "$_note... "
611     else
612         echo "Usage: _do [note] cmd" 1>&2
613         status=1; exit
614     fi
615
616     (eval "echo '---' \"$_cmd\"") >>$here/$seq.full
617     (eval "$_cmd") >$tmp._out 2>&1; ret=$?
618     cat $tmp._out | _fix_malloc >>$here/$seq.full
619     if [ $# -eq 2 ]; then
620         if [ $ret -eq 0 ]; then
621             echo "done"
622         else
623             echo "fail"
624         fi
625     fi
626     if [ $ret -ne 0  ] \
627         && [ "$_do_die_on_error" = "always" \
628             -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
629     then
630         [ $# -ne 2 ] && echo
631         eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
632         status=1; exit
633     fi
634
635     return $ret
636 }
637
638 # bail out, setting up .notrun file
639 #
640 _notrun()
641 {
642     echo "$*" >$seq.notrun
643     echo "$seq not run: $*"
644     status=0
645     exit
646 }
647
648 # just plain bail out
649 #
650 _fail()
651 {
652     echo "$*" | tee -a $here/$seq.full
653     echo "(see $seq.full for details)"
654     status=1
655     exit 1
656 }
657
658 # tests whether $FSTYP is one of the supported filesystems for a test
659 #
660 _supported_fs()
661 {
662     for f
663     do
664         if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
665         then
666             return
667         fi
668     done
669
670     _notrun "not suitable for this filesystem type: $FSTYP"
671 }
672
673 # tests whether $FSTYP is one of the supported OSes for a test
674 #
675 _supported_os()
676 {
677     for h
678     do
679         if [ "$h" = "$HOSTOS" ]
680         then
681             return
682         fi
683     done
684
685     _notrun "not suitable for this OS: $HOSTOS"
686 }
687
688 # this test needs a scratch partition - check we're ok & unmount it
689 #
690 _require_scratch()
691 {
692     case "$FSTYP" in
693         nfs*)
694                  echo $SCRATCH_DEV | grep -q ":" > /dev/null 2>&1
695                  if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]
696                  then
697                      _notrun "this test requires a valid \$SCRATCH_DEV"
698                  fi
699                  ;;
700         *)
701                  if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
702                  then
703                      _notrun "this test requires a valid \$SCRATCH_DEV"
704                  fi
705                  if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
706                  then
707                      _notrun "this test requires a valid \$SCRATCH_DEV"
708                  fi
709                 if [ ! -d "$SCRATCH_MNT" ]
710                 then
711                      _notrun "this test requires a valid \$SCRATCH_MNT"
712                 fi
713                  ;;
714     esac
715
716     # mounted?
717     if _mount | grep -q $SCRATCH_DEV
718     then
719         # if it's mounted, make sure its on $SCRATCH_MNT
720         if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
721         then
722             echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
723             exit 1
724         fi
725         # and then unmount it
726         if ! $UMOUNT_PROG $SCRATCH_DEV
727         then
728             echo "failed to unmount $SCRATCH_DEV"
729             exit 1
730         fi
731     fi
732 }
733
734 # this test needs a logdev
735 #
736 _require_logdev()
737 {
738     [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
739         _notrun "This test requires a valid \$SCRATCH_LOGDEV"
740     [ "$USE_EXTERNAL" != yes ] && \
741         _notrun "This test requires USE_EXTERNAL to be enabled"
742
743     # ensure its not mounted
744     $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
745 }
746
747 # this test requires loopback device support
748 #
749 _require_loop()
750 {
751     if [ "$HOSTOS" != "Linux" ]
752     then
753         _notrun "This test requires linux for loopback device support"
754     fi
755
756     modprobe loop >/dev/null 2>&1
757     if grep loop /proc/devices >/dev/null 2>&1
758     then
759         :
760     else
761         _notrun "This test requires loopback device support"
762     fi
763 }
764
765 # this test requires that (large) loopback device files are not in use
766 #
767 _require_nobigloopfs()
768 {
769     [ "$USE_BIG_LOOPFS" = yes ] && \
770         _notrun "Large filesystem testing in progress, skipped this test"
771 }
772
773 # this test requires that a realtime subvolume is in use, and
774 # that the kernel supports realtime as well.
775 #
776 _require_realtime()
777 {
778     [ "$USE_EXTERNAL" = yes ] || \
779         _notrun "External volumes not in use, skipped this test"
780     [ "$SCRATCH_RTDEV" = "" ] && \
781         _notrun "Realtime device required, skipped this test"
782 }
783
784 # this test requires that a specified command (executable) exists
785 # $1 - command, $2 - name for error message
786 #
787 _require_command()
788 {
789     [ -n "$1" ] && _cmd="$1" || _cmd="$2"
790     [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
791 }
792
793 # this test requires that external log/realtime devices are not in use
794 #
795 _require_nonexternal()
796 {
797     [ "$USE_EXTERNAL" = yes ] && \
798         _notrun "External device testing in progress, skipped this test"
799 }
800
801 # indicate whether YP/NIS is active or not
802 #
803 _yp_active()
804 {
805         local dn
806         dn=$(domainname 2>/dev/null)
807         test -n "${dn}" -a "${dn}" != "(none)"
808         echo $?
809 }
810
811 # cat the password file
812 #
813 _cat_passwd()
814 {
815         [ $(_yp_active) -eq 0 ] && ypcat passwd
816         cat /etc/passwd
817 }
818
819 # cat the group file
820 #
821 _cat_group()
822 {
823         [ $(_yp_active) -eq 0 ] && ypcat group
824         cat /etc/group
825 }
826
827 # check for the fsgqa user on the machine
828 #
829 _require_user()
830 {
831     qa_user=fsgqa
832     _cat_passwd | grep -q $qa_user
833     [ "$?" == "0" ] || _notrun "$qa_user user not defined."
834 }
835
836 # check that xfs_io, glibc, kernel, and filesystem all (!) support
837 # fallocate
838 #
839 _require_xfs_io_falloc()
840 {
841         testfile=$TEST_DIR/$$.falloc
842         testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
843         rm -f $testfile 2>&1 > /dev/null
844         echo $testio | grep -q "not found" && \
845                 _notrun "xfs_io fallocate support is missing"
846         echo $testio | grep -q "Operation not supported" && \
847                 _notrun "xfs_io fallocate command failed (old kernel/wrong fs?)"
848 }
849
850 # Check that a fs has enough free space (in 1024b blocks)
851 #
852 _require_fs_space()
853 {
854         MNT=$1
855         BLOCKS=$2       # in units of 1024
856         let GB=$BLOCKS/1024/1024
857
858         FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
859         [ $FREE_BLOCKS -lt $BLOCKS ] && \
860                 _notrun "This test requires at least ${GB}GB free on $MNT to run"
861 }
862
863 #
864 # Check if the filesystem supports sparse files.
865 #
866 # Unfortunately there is no better way to do this than a manual black list.
867 #
868 _require_sparse_files()
869 {
870     case $FSTYP in
871     hfsplus)
872         _notrun "Sparse files not supported by this filesystem type: $FSTYP"
873         ;;
874     *)
875         ;;
876     esac
877 }
878
879 # check that a FS on a device is mounted
880 # if so, return mount point
881 #
882 _is_mounted()
883 {
884     if [ $# -ne 1 ]
885     then
886         echo "Usage: _is_mounted device" 1>&2
887         exit 1
888     fi
889
890     device=$1
891
892     if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
893         pattern        { print $3 ; exit 0 }
894         END            { exit 1 }
895     '
896     then
897         echo "_is_mounted: $device is not a mounted $FSTYP FS"
898         exit 1
899     fi
900 }
901
902 # remount a FS to a new mode (ro or rw)
903 #
904 _remount()
905 {
906     if [ $# -ne 2 ]
907     then
908         echo "Usage: _remount device ro/rw" 1>&2
909         exit 1
910     fi
911     device=$1
912     mode=$2
913
914     if ! mount -o remount,$mode $device
915     then
916         echo "_remount: failed to remount filesystem on $device as $mode"
917         exit 1
918     fi
919 }
920
921 # Run the appropriate repair/check on a filesystem
922 #
923 # if the filesystem is mounted, it's either remounted ro before being
924 # checked or it's unmounted and then remounted
925 #
926
927 # If set, we remount ro instead of unmounting for fsck
928 USE_REMOUNT=0
929
930 _umount_or_remount_ro()
931 {
932     if [ $# -ne 1 ]
933     then
934         echo "Usage: _umount_or_remount_ro <device>" 1>&2
935         exit 1
936     fi
937
938     device=$1
939     mountpoint=`_is_mounted $device`
940
941     if [ $USE_REMOUNT -eq 0 ]; then
942         $UMOUNT_PROG $device
943     else
944         _remount $device ro
945     fi
946     echo "$mountpoint"
947 }
948
949 _mount_or_remount_rw()
950 {
951     if [ $# -ne 3 ]
952     then
953         echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
954         exit 1
955     fi
956     mount_opts=$1
957     device=$2
958     mountpoint=$3
959
960     if [ $USE_REMOUNT -eq 0 ]
961     then
962         if ! _mount -t $FSTYP $mount_opts $device $mountpoint
963         then
964             echo "!!! failed to remount $device on $mountpoint"
965             return 0 # ok=0
966         fi
967     else
968         _remount $device rw
969     fi
970
971     return 1 # ok=1
972 }
973
974 # Check a generic filesystem in no-op mode; this assumes that the
975 # underlying fsck program accepts "-n" for a no-op (check-only) run,
976 # and that it will still return an errno for corruption in this mode.
977 #
978 # Filesystems which don't support this will need to define their
979 # own check routine.
980 #
981 _check_generic_filesystem()
982 {
983     device=$1
984
985     # If type is set, we're mounted
986     type=`_fs_type $device`
987     ok=1
988
989     if [ "$type" = "$FSTYP" ]
990     then
991         # mounted ...
992         mountpoint=`_umount_or_remount_ro $device`
993     fi
994
995     fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
996     if [ $? -ne 0 ]
997     then
998         echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seq.full)"
999
1000         echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$here/$seq.full
1001         echo "*** fsck.$FSTYP output ***"                     >>$here/$seq.full
1002         cat $tmp.fsck                                         >>$here/$seq.full
1003         echo "*** end fsck.$FSTYP output"                     >>$here/$seq.full
1004
1005         ok=0
1006     fi
1007     rm -f $tmp.fsck
1008
1009     if [ $ok -eq 0 ]
1010     then
1011         echo "*** mount output ***"                             >>$here/$seq.full
1012         _mount                                                  >>$here/$seq.full
1013         echo "*** end mount output"                             >>$here/$seq.full
1014     elif [ "$type" = "$FSTYP" ]
1015     then
1016         # was mounted ...
1017         _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1018         ok=$?
1019     fi
1020
1021     if [ $ok -eq 0 ]; then
1022         status=1
1023         exit 1
1024     fi
1025
1026     return 0
1027 }
1028
1029 # run xfs_check and friends on a FS.
1030
1031 _check_xfs_filesystem()
1032 {
1033     if [ $# -ne 3 ]
1034     then
1035         echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1036         exit 1
1037     fi
1038
1039     extra_mount_options=""
1040     device=$1
1041     if [ "$2" != "none" ]; then
1042         extra_log_options="-l$2"
1043         extra_mount_options="-ologdev=$2"
1044     fi
1045
1046     if [ "$3" != "none" ]; then
1047         extra_rt_options="-r$3"
1048         extra_mount_options=$extra_mount_options" -ortdev=$3"
1049     fi
1050     extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1051
1052     [ "$FSTYP" != xfs ] && return 0
1053     testoption=""
1054     [ "$USE_BIG_LOOPFS" = yes ] && testoption=-t
1055
1056     type=`_fs_type $device`
1057     ok=1
1058
1059     if [ "$type" = "xfs" ]
1060     then
1061         # mounted ...
1062         mountpoint=`_umount_or_remount_ro $device`
1063     fi
1064
1065     $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1066                 | tee $tmp.logprint | grep -q "<CLEAN>"
1067     if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1068     then
1069         echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seq.full)"
1070
1071         echo "_check_xfs_filesystem: filesystem on $device has dirty log"   >>$here/$seq.full
1072         echo "*** xfs_logprint -t output ***"                   >>$here/$seq.full
1073         cat $tmp.logprint                                       >>$here/$seq.full
1074         echo "*** end xfs_logprint output"                      >>$here/$seq.full
1075
1076         ok=0
1077     fi
1078
1079     $XFS_CHECK_PROG $testoption $extra_log_options $device 2>&1 |\
1080          _fix_malloc >$tmp.fs_check
1081     if [ -s $tmp.fs_check ]
1082     then
1083         echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seq.full)"
1084
1085         echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$here/$seq.full
1086         echo "*** xfs_check output ***"                         >>$here/$seq.full
1087         cat $tmp.fs_check                                       >>$here/$seq.full
1088         echo "*** end xfs_check output"                         >>$here/$seq.full
1089
1090         ok=0
1091     fi
1092     # repair doesn't scale massively at this stage, optionally skip it for now
1093     [ "$USE_BIG_LOOPFS" = yes ] || \
1094     $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1095     if [ $? -ne 0 ]
1096     then
1097         echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seq.full)"
1098
1099         echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$here/$seq.full
1100         echo "*** xfs_repair -n output ***"                     >>$here/$seq.full
1101         cat $tmp.repair | _fix_malloc                           >>$here/$seq.full
1102         echo "*** end xfs_repair output"                        >>$here/$seq.full
1103
1104         ok=0
1105     fi
1106     rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1107
1108     if [ $ok -eq 0 ]
1109     then
1110         echo "*** mount output ***"                             >>$here/$seq.full
1111         _mount                                                  >>$here/$seq.full
1112         echo "*** end mount output"                             >>$here/$seq.full
1113     elif [ "$type" = "xfs" ]
1114     then
1115         _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1116     fi
1117
1118     if [ $ok -eq 0 ]; then
1119         status=1
1120         exit 1
1121     fi
1122
1123     return 0
1124 }
1125
1126 # Filter the knowen errors the UDF Verifier reports.
1127 _udf_test_known_error_filter()
1128 {
1129         egrep -v "PVD  60  Error: Interchange Level: 1, Maximum Interchange Level: 0|FSD  28  Error: Interchange Level: 1, Maximum Interchange Level: 1,|PVD  72  Warning: Volume Set Identifier: \"\*IRIX UDF\",|Warning: [0-9]+ unused blocks NOT marked as unallocated."
1130
1131 }
1132
1133 _check_udf_filesystem()
1134 {
1135     [ "$DISABLE_UDF_TEST" == "1" ] && return
1136
1137     if [ $# -ne 1 -a $# -ne 2 ]
1138     then
1139         echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1140         exit 1
1141     fi
1142
1143     if [ ! -x $here/src/udf_test ]
1144     then
1145         echo "udf_test not installed, please download and build the Philips"
1146         echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1147         echo "Then copy the udf_test binary to $here/src/."
1148         echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1149         echo "to 1."
1150         return
1151     fi
1152
1153     device=$1
1154     if [ $# -eq 2 ];
1155     then
1156         LAST_BLOCK=`expr \( $2 - 1 \)`
1157         OPT_ARG="-lastvalidblock $LAST_BLOCK"
1158     fi
1159
1160     rm -f $seq.checkfs
1161     sleep 1 # Due to a problem with time stamps in udf_test
1162     $here/src/udf_test $OPT_ARG $device | tee $here/$seq.checkfs | egrep "Error|Warning" | \
1163         _udf_test_known_error_filter | \
1164         egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" | \
1165         sed "s/^.*$/Warning UDF Verifier reported errors see $seq.checkfs./g"
1166
1167 }
1168
1169 _check_xfs_test_fs()
1170 {
1171     TEST_LOG="none"
1172     TEST_RT="none"
1173     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1174         TEST_LOG="$TEST_LOGDEV"
1175
1176     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1177         TEST_RT="$TEST_RTDEV"
1178
1179     _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1180
1181     # check for ipath consistency
1182     if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1183         # errors go to stderr
1184         xfs_check_ipaths $TEST_DIR >/dev/null
1185         xfs_repair_ipaths -n $TEST_DIR >/dev/null
1186     fi
1187 }
1188
1189 _check_test_fs()
1190 {
1191     case $FSTYP in
1192     xfs)
1193         _check_xfs_test_fs
1194         ;;
1195     nfs)
1196         # no way to check consistency for nfs
1197         ;;
1198     udf)
1199         # do nothing for now
1200         ;;
1201     *)
1202         _check_generic_filesystem $TEST_DEV
1203         ;;
1204     esac
1205 }
1206
1207 _check_scratch_fs()
1208 {
1209     case $FSTYP in
1210     xfs)
1211         SCRATCH_LOG="none"
1212         SCRATCH_RT="none"
1213         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1214             SCRATCH_LOG="$SCRATCH_LOGDEV"
1215
1216         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1217             SCRATCH_RT="$SCRATCH_RTDEV"
1218
1219         _check_xfs_filesystem $SCRATCH_DEV $SCRATCH_LOG $SCRATCH_RT
1220         ;;
1221     udf)
1222         _check_udf_filesystem $SCRATCH_DEV $udf_fsize
1223         ;;
1224     nfs*)
1225         # Don't know how to check an NFS filesystem, yet.
1226         ;;
1227     *)
1228         _check_generic_filesystem $SCRATCH_DEV
1229         ;;
1230     esac
1231 }
1232
1233 _full_fstyp_details()
1234 {
1235      [ -z "$FSTYP" ] && FSTYP=xfs
1236      if [ $FSTYP = xfs ]; then
1237         if [ -d /proc/fs/xfs ]; then
1238             if grep -q 'debug 0' /proc/fs/xfs/stat; then
1239                 FSTYP="$FSTYP (non-debug)"
1240             elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1241                 FSTYP="$FSTYP (debug)"
1242             fi
1243         else
1244             if uname -a | grep -qi 'debug'; then
1245                 FSTYP="$FSTYP (debug)"
1246             else
1247                 FSTYP="$FSTYP (non-debug)"
1248             fi
1249         fi
1250      fi
1251      echo $FSTYP
1252 }
1253
1254 _full_platform_details()
1255 {
1256      os=`uname -s`
1257      host=`hostname -s`
1258      kernel=`uname -r`
1259      platform=`uname -m`
1260      echo "$os/$platform $host $kernel"
1261 }
1262
1263 _setup_udf_scratchdir()
1264 {
1265     [ "$FSTYP" != "udf" ] \
1266         && _fail "setup_udf_testdir: \$FSTYP is not udf"
1267     [ -z "$SCRATCH_DEV" -o ! -b "$SCRATCH_DEV" ] \
1268         && _notrun "this test requires a valid \$SCRATCH_DEV"
1269     [ -z "$SCRATCH_MNT" ] \
1270         && _notrun "this test requires a valid \$SCRATCH_MNT"
1271
1272     # mounted?
1273     if _mount | grep -q $SCRATCH_DEV
1274     then
1275         # if it's mounted, make sure its on $TEST_RW_DIR
1276         if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1277         then
1278             _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1279         fi
1280         $UMOUNT_PROG $SCRATCH_DEV
1281     fi
1282
1283     _scratch_mkfs
1284     _scratch_mount
1285
1286     testdir=$SCRATCH_MNT
1287 }
1288
1289 _setup_nfs_scratchdir()
1290 {
1291     [ "$FSTYP" != "nfs" ] \
1292         && _fail "setup_nfs_testdir: \$FSTYP is not nfs"
1293     [ -z "$SCRATCH_DEV" ] \
1294         && _notrun "this test requires a valid host fs for \$SCRATCH_DEV"
1295     [ -z "$SCRATCH_MNT" ] \
1296         && _notrun "this test requires a valid \$SCRATCH_MNT"
1297
1298     # mounted?
1299     if _mount | grep -q $SCRATCH_DEV
1300     then
1301         # if it's mounted, make sure its on $SCRATCH_MNT
1302         if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1303         then
1304             _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1305         fi
1306         $UMOUNT_PROG $SCRATCH_DEV
1307     fi
1308
1309     _scratch_mkfs
1310     _scratch_mount
1311
1312     testdir=$SCRATCH_MNT
1313 }
1314
1315 #
1316 # Warning for UDF and NFS:
1317 # this function calls _setup_udf_scratchdir and _setup_udf_scratchdir
1318 # which actually uses the scratch dir for the test dir.
1319 #
1320 # This was done because testdir was intended to be a persistent
1321 # XFS only partition.  This should eventually change, and treat
1322 # at least local filesystems all the same.
1323 #
1324 _setup_testdir()
1325 {
1326     case $FSTYP in
1327     udf)
1328         _setup_udf_scratchdir
1329         ;;
1330     nfs*)
1331         _setup_nfs_scratchdir
1332         ;;
1333     *)
1334         testdir=$TEST_DIR
1335         ;;
1336     esac
1337 }
1338
1339 _cleanup_testdir()
1340 {
1341     case $FSTYP in
1342     udf)
1343         # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
1344         [ -n "$testdir" ] && $UMOUNT_PROG $testdir
1345         ;;
1346     nfs*)
1347         # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
1348         [ -n "$testdir" ] && $UMOUNT_PROG $testdir
1349         ;;
1350     *)
1351         # do nothing, testdir is $TEST_DIR
1352         :
1353         ;;
1354     esac
1355 }
1356
1357 _link_out_file()
1358 {
1359    if [ -z "$1" ]; then
1360       echo Error must pass \$seq.
1361       exit
1362    fi
1363    rm -f $1
1364    if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1365       ln -s $1.irix $1
1366    elif [ "`uname`" == "Linux" ]; then
1367       ln -s $1.linux $1
1368    else
1369       echo Error test $seq does not run on the operating system: `uname`
1370       exit
1371    fi
1372 }
1373
1374 _die()
1375 {
1376         echo $@
1377         exit 1
1378 }
1379
1380 _nfiles()
1381 {
1382         f=0
1383         while [ $f -lt $1 ]
1384         do
1385                 file=f$f
1386                 echo > $file
1387                 if [ $size -gt 0 ]; then
1388                     dd if=/dev/zero of=$file bs=1024 count=$size
1389                 fi
1390                 let f=$f+1
1391         done
1392 }
1393
1394 # takes dirname, depth
1395 _descend()
1396 {
1397         dirname=$1; depth=$2
1398         mkdir $dirname  || die "mkdir $dirname failed"
1399         cd $dirname
1400
1401         _nfiles $files           # files for this dir
1402
1403         [ $depth -eq 0 ] && return
1404         let deep=$depth-1 # go 1 down
1405
1406         [ $verbose = true ] && echo "descending, depth from leaves = $deep"
1407
1408         d=0
1409         while [ $d -lt $dirs ]
1410         do
1411                 _descend d$d $deep &
1412                 let d=$d+1
1413                 wait
1414         done
1415 }
1416
1417 # Populate a filesystem with inodes for performance experiments
1418 #
1419 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size]
1420 #
1421 _populate_fs()
1422 {
1423     here=`pwd`
1424     dirs=5          # ndirs in each subdir till leaves
1425     size=0          # sizeof files in K
1426     files=100       # num files in _each_ subdir
1427     depth=2         # depth of tree from root to leaves
1428     verbose=false
1429     root=root       # path of initial root of directory tree
1430
1431     while getopts "d:f:n:r:s:v" c
1432     do
1433         case $c in
1434         d)      depth=$OPTARG;;
1435         n)      dirs=$OPTARG;;
1436         f)      files=$OPTARG;;
1437         s)      size=$OPTARG;;
1438         v)      verbose=true;;
1439         r)      root=$OPTARG;;
1440         esac
1441     done
1442
1443     _descend $root $depth
1444     wait
1445
1446     cd $here
1447
1448     [ $verbose = true ] && echo done
1449 }
1450
1451 # query whether the given file has the given inode flag set
1452 #
1453 _test_inode_flag()
1454 {
1455     flag=$1
1456     file=$2
1457
1458     if which $XFS_IO_PROG >/dev/null; then
1459         if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
1460             return 0
1461         fi
1462     fi
1463     return 1
1464 }
1465
1466 # query the given files extsize allocator hint in bytes (if any)
1467 #
1468 _test_inode_extsz()
1469 {
1470     file=$1
1471     blocks=""
1472
1473     if which $XFS_IO_PROG >/dev/null; then
1474         blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
1475                 awk '/^xattr.extsize =/ { print $3 }'`
1476     fi
1477     [ -z "$blocks" ] && blocks="0"
1478     echo $blocks
1479 }
1480
1481
1482 ################################################################################
1483
1484 if [ "$iam" != new -a "$iam" != bench ]
1485 then
1486     # make some further configuration checks here
1487
1488     if [ "$TEST_DEV" = ""  ]
1489     then
1490         echo "common.rc: Error: \$TEST_DEV is not set"
1491         exit 1
1492     fi
1493
1494     # if $TEST_DEV is not mounted, mount it now as XFS
1495     if [ -z "`_fs_type $TEST_DEV`" ]
1496     then
1497         # $TEST_DEV is not mounted
1498         if ! _test_mount
1499         then
1500             echo "common.rc: retrying test device mount with external set"
1501             [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
1502             if ! _test_mount
1503             then
1504                 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
1505                 exit 1
1506             fi
1507         fi
1508     fi
1509
1510     if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
1511     then
1512         echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
1513         $DF_PROG $TEST_DEV
1514         exit 1
1515     fi
1516 fi
1517
1518 # make sure this script returns success
1519 /bin/true