xfstests: randholes: use posix_memalign()
[xfstests-dev.git] / 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 # creator
25 owner=nathans@sgi.com
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=0
33
34 _cleanup()
35 {
36         umount $SCRATCH_MNT
37         rm -f $tmp.*
38         exit $status
39 }
40 trap "_cleanup" 0 1 2 3 15
41
42 _populate_scratch()
43 {
44         echo "=== mkfs output ===" >>$seq.full
45         _scratch_mkfs_xfs | tee -a $seq.full | _filter_mkfs 2>$tmp.mkfs
46         . $tmp.mkfs
47         _scratch_mount
48         dd if=/dev/zero of=$SCRATCH_MNT/foo count=200 bs=4096 >/dev/null 2>&1 &
49         dd if=/dev/zero of=$SCRATCH_MNT/goo count=400 bs=4096 >/dev/null 2>&1 &
50         dd if=/dev/zero of=$SCRATCH_MNT/moo count=800 bs=4096 >/dev/null 2>&1 &
51         wait
52         umount $SCRATCH_MNT                     # flush everything
53         _scratch_mount                          # and then remount
54 }
55
56
57 # get standard environment, filters and checks
58 . ./common.rc
59 . ./common.filter
60
61 # real QA test starts here
62 _supported_fs xfs
63 _supported_os IRIX Linux
64
65 _need_to_be_root
66 _require_scratch
67 _require_nobigloopfs
68
69 rm -f $seq.full
70
71 _populate_scratch
72
73 [ "$HOSTOS" = "Linux" ] && DF_PROG="$DF_PROG -P --block-size=512"
74
75 eval `$DF_PROG $SCRATCH_MNT 2>&1 \
76         | tail -1 | $AWK_PROG '{ printf "blocks=%u used=%u avail=%u\n", $3, $4, $5 }'`
77 echo "df gave: blocks=$blocks used=$used avail=$avail" >>$seq.full
78 echo "blocksize from mkfs is '$dbsize'" >>$seq.full
79
80 xfs_db -r -c "freesp -s" $SCRATCH_DEV >$tmp.xfs_db
81 echo "xfs_db for $SCRATCH_DEV" >>$seq.full
82 cat $tmp.xfs_db >>$seq.full
83
84 eval `$XFS_IO_PROG -x -c resblks $SCRATCH_MNT 2>&1 \
85         | $AWK_PROG '/available/ { printf "resblks=%u\n", $5 }'`
86 echo "resblks gave: resblks=$resblks" >>$seq.full
87
88 # check the 'blocks' field from freesp command is OK
89 # since 2.6.18, df does not report the 4 blocks per AG that cannot
90 # be allocated, hence we check for that exact mismatch.
91 # since ~2.6.22, reserved blocks are used by default and df does
92 # not report them, hence check for an exact mismatch.
93 perl -ne '
94         BEGIN   { $avail ='$avail' * 512;
95                   $answer="(no xfs_db free blocks line?)" }
96         /free blocks (\d+)$/    || next;
97         $freesp = $1 * '$dbsize';
98         if ($freesp == $avail) {
99                 $answer = "yes";
100         } else {
101                 $avail = $avail + (('$agcount' + 1) * '$dbsize' * 4);
102                 if ($freesp == $avail) {
103                         $answer = "yes";
104                 } else {
105                         $avail = $avail + ('$resblks' * '$dbsize');
106                         if ($freesp == $avail) {
107                                 $answer = "yes";
108                         } else {
109                                 $answer = "no ($freesp != $avail)";
110                         }
111                 }
112         }
113         END     { print "$answer\n" }
114         ' <$tmp.xfs_db >$tmp.ans
115 ans="`cat $tmp.ans`"
116 echo "Checking blocks column same as df: $ans"
117 if [ "$ans" != yes ]
118 then
119         echo "Error: $SCRATCH_DEV: freesp mismatch: $ans"
120         echo "xfs_db output ..."
121         cat $tmp.xfs_db
122         status=1
123 fi
124
125 # check the 'pct' field from freesp command is good
126 perl -ne '
127             BEGIN       { $percent = 0; }
128             /free/      && next;        # skip over free extent size number
129             if (/\s+(\d+\.\d+)$/) {
130                 $percent += $1;
131             }
132             END { $percent += 0.5; print int($percent), "\n" }  # round up
133 ' <$tmp.xfs_db >$tmp.ans
134 ans="`cat $tmp.ans`"
135 echo "Checking percent column yields 100: $ans"
136 if [ "$ans" != 100 ]
137 then
138         echo "Error: $SCRATCH_DEV: pct mismatch: $ans (expected 100)"
139         echo "xfs_db output ..."
140         cat $tmp.xfs_db
141         status=1
142 fi
143
144 exit