paranoid testing that mkfs of scratch works without ipaths option
[xfstests-dev.git] / 004
1 #! /bin/sh
2 # FS QA Test No. 004
3 #
4 # exercise xfs_db bug #789674 and other freesp functionality
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
8
9 # This program is free software; you can redistribute it and/or modify it
10 # under the terms of version 2 of the GNU General Public License as
11 # published by the Free Software Foundation.
12
13 # This program is distributed in the hope that it would be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17 # Further, this software is distributed without any warranty that it is
18 # free of the rightful claim of any third person regarding infringement
19 # or the like.  Any license provided herein, whether implied or
20 # otherwise, applies only to this software file.  Patent licenses, if
21 # any, provided herein do not apply to combinations of this program with
22 # other software, or any other product whatsoever.
23
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, write the Free Software Foundation, Inc., 59
26 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
27
28 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
29 # Mountain View, CA  94043, or:
30
31 # http://www.sgi.com 
32
33 # For further information regarding this notice, see: 
34
35 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 #-----------------------------------------------------------------------
37 #
38 # creator
39 owner=nathans@sgi.com
40
41 seq=`basename $0`
42 echo "QA output created by $seq"
43
44 here=`pwd`
45 tmp=/tmp/$$
46 status=0
47
48 _cleanup()
49 {
50         umount $SCRATCH_MNT
51         rm -f $tmp.*
52         exit $status
53 }
54 trap "_cleanup" 0 1 2 3 15
55
56 _populate_scratch()
57 {
58         echo "=== mkfs output ===" >>$seq.full
59         _scratch_mkfs_xfs | tee -a $seq.full | _filter_mkfs 2>$tmp.mkfs
60         . $tmp.mkfs
61         _scratch_mount
62         dd if=/dev/zero of=$SCRATCH_MNT/foo count=200 bs=4096 >/dev/null 2>&1 &
63         dd if=/dev/zero of=$SCRATCH_MNT/goo count=400 bs=4096 >/dev/null 2>&1 &
64         dd if=/dev/zero of=$SCRATCH_MNT/moo count=800 bs=4096 >/dev/null 2>&1 &
65         wait
66         umount $SCRATCH_MNT                     # flush everything
67         _scratch_mount                          # and then remount
68 }
69
70
71 # get standard environment, filters and checks
72 . ./common.rc
73 . ./common.filter
74
75 # real QA test starts here
76 _supported_fs xfs
77 _supported_os IRIX Linux
78
79 _need_to_be_root
80 _require_scratch
81 _require_nobigloopfs
82
83 rm -f $seq.full
84
85 _populate_scratch
86
87 [ "$HOSTOS" = "Linux" ] && DF_PROG="$DF_PROG -P --block-size=512"
88
89 eval `$DF_PROG $SCRATCH_MNT 2>&1 \
90         | tail -1 | $AWK_PROG '{ printf "blocks=%u used=%u avail=%u\n", $3, $4, $5 }'`
91 echo "df gave: blocks=$blocks used=$used avail=$avail" >>$seq.full
92 echo "blocksize from mkfs is '$dbsize'" >>$seq.full
93
94 xfs_db -r -c "freesp -s" $SCRATCH_DEV >$tmp.xfs_db
95 echo "xfs_db for $SCRATCH_DEV" >>$seq.full
96 cat $tmp.xfs_db >>$seq.full
97
98 # check the 'blocks' field from freesp command is OK
99 perl -ne '
100             BEGIN       { $avail ='$avail' * 512;
101                           $answer="(no xfs_db free blocks line?)" }
102             /free blocks (\d+)$/        || next;
103             $freesp = $1 * '$dbsize';
104             if ($freesp == $avail)      { $answer = "yes"; }
105             else                        { $answer = "no ($freesp != $avail)"; }
106             END { print "$answer\n" }
107         ' <$tmp.xfs_db >$tmp.ans
108 ans="`cat $tmp.ans`"
109 echo "Checking blocks column same as df: $ans"
110 if [ "$ans" != yes ]
111 then
112         echo "Error: $SCRATCH_DEV: freesp mismatch: $ans"
113         echo "xfs_db output ..."
114         cat $tmp.xfs_db
115         status=1
116 fi
117
118 # check the 'pct' field from freesp command is good
119 perl -ne '
120             BEGIN       { $percent = 0; }
121             /free/      && next;        # skip over free extent size number
122             if (/\s+(\d+\.\d+)$/) {
123                 $percent += $1;
124             }
125             END { $percent += 0.5; print int($percent), "\n" }  # round up
126 ' <$tmp.xfs_db >$tmp.ans
127 ans="`cat $tmp.ans`"
128 echo "Checking percent column yields 100: $ans"
129 if [ "$ans" != 100 ]
130 then
131         echo "Error: $SCRATCH_DEV: pct mismatch: $ans (expected 100)"
132         echo "xfs_db output ..."
133         cat $tmp.xfs_db
134         status=1
135 fi
136
137 exit