09da2fea8a254c1c473b830bfe6c8be9b60b180f
[xfstests-dev.git] / tests / xfs / 004
1 #! /bin/bash
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
10 # modify it under the terms 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,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=0
32
33 _cleanup()
34 {
35         _scratch_unmount
36         rm -f $tmp.*
37         exit $status
38 }
39 trap "_cleanup" 0 1 2 3 15
40
41 _populate_scratch()
42 {
43         echo "=== mkfs output ===" >>$seqres.full
44         _scratch_mkfs_xfs | tee -a $seqres.full | _filter_mkfs 2>$tmp.mkfs
45         . $tmp.mkfs
46         _scratch_mount
47         dd if=/dev/zero of=$SCRATCH_MNT/foo count=200 bs=4096 >/dev/null 2>&1 &
48         dd if=/dev/zero of=$SCRATCH_MNT/goo count=400 bs=4096 >/dev/null 2>&1 &
49         dd if=/dev/zero of=$SCRATCH_MNT/moo count=800 bs=4096 >/dev/null 2>&1 &
50         wait
51         _scratch_unmount                        # flush everything
52         _scratch_mount                          # and then remount
53 }
54
55 # get standard environment, filters and checks
56 . ./common/rc
57 . ./common/filter
58
59 # real QA test starts here
60 _supported_fs xfs
61 _supported_os IRIX Linux
62
63 _require_scratch
64 _require_no_large_scratch_dev
65
66 rm -f $seqres.full
67
68 _populate_scratch
69
70 [ "$HOSTOS" = "Linux" ] && DF_PROG="$DF_PROG -P --block-size=512"
71
72 eval `$DF_PROG $SCRATCH_MNT 2>&1 \
73         | tail -1 | $AWK_PROG '{ printf "blocks=%u used=%u avail=%u\n", $3, $4, $5 }'`
74 echo "df gave: blocks=$blocks used=$used avail=$avail" >>$seqres.full
75 echo "blocksize from mkfs is '$dbsize'" >>$seqres.full
76
77 _scratch_xfs_db -r -c "freesp -s"  >$tmp.xfs_db
78 echo "xfs_db for $SCRATCH_DEV" >>$seqres.full
79 cat $tmp.xfs_db >>$seqres.full
80
81 eval `$XFS_IO_PROG -x -c resblks $SCRATCH_MNT 2>&1 \
82         | $AWK_PROG '/available/ { printf "resblks=%u\n", $5 }'`
83 echo "resblks gave: resblks=$resblks" >>$seqres.full
84
85 # check the 'blocks' field from freesp command is OK
86 # since 2.6.18, df does not report the 4 blocks per AG that cannot
87 # be allocated, hence we check for that exact mismatch.
88 # since ~2.6.22, reserved blocks are used by default and df does
89 # not report them, hence check for an exact mismatch.
90 perl -ne '
91         BEGIN   { $avail ='$avail' * 512;
92                   $answer="(no xfs_db free blocks line?)" }
93         /free blocks (\d+)$/    || next;
94         $freesp = $1 * '$dbsize';
95         if ($freesp == $avail) {
96                 $answer = "yes";
97         } else {
98                 $avail = $avail + (('$agcount' + 1) * '$dbsize' * 4);
99                 if ($freesp == $avail) {
100                         $answer = "yes";
101                 } else {
102                         $avail = $avail + ('$resblks' * '$dbsize');
103                         if ($freesp == $avail) {
104                                 $answer = "yes";
105                         } else {
106                                 $answer = "no ($freesp != $avail)";
107                         }
108                 }
109         }
110         END     { print "$answer\n" }
111         ' <$tmp.xfs_db >$tmp.ans
112 ans="`cat $tmp.ans`"
113 echo "Checking blocks column same as df: $ans"
114 if [ "$ans" != yes ]
115 then
116         echo "Error: $SCRATCH_DEV: freesp mismatch: $ans"
117         echo "xfs_db output ..."
118         cat $tmp.xfs_db
119         status=1
120 fi
121
122 # check the 'pct' field from freesp command is good
123 perl -ne '
124             BEGIN       { $percent = 0; }
125             /free/      && next;        # skip over free extent size number
126             if (/\s+(\d+\.\d+)$/) {
127                 $percent += $1;
128             }
129             END { $percent += 0.5; print int($percent), "\n" }  # round up
130 ' <$tmp.xfs_db >$tmp.ans
131 ans="`cat $tmp.ans`"
132 echo "Checking percent column yields 100: $ans"
133 if [ "$ans" != 100 ]
134 then
135         echo "Error: $SCRATCH_DEV: pct mismatch: $ans (expected 100)"
136         echo "xfs_db output ..."
137         cat $tmp.xfs_db
138         status=1
139 fi
140
141 exit