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