xfstests: convert tests to use new results directory
[xfstests-dev.git] / tests / xfs / 016
1 #! /bin/bash
2 # FS QA Test No. 016
3 #
4 # test end of log overwrite bug #796141
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2003 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 #
26 # pv 796141
27 #
28 # create a new FS, mostly fill the log. Then wrap the log back to the
29 # start bit by bit to force wiping of stale blocks near the end of the
30 # log. Check the block after the log ends to check for corruption
31 #
32 # assumptions :
33 #    - given we're only touching a single inode, the block after the
34 #      log which is in the middle ag should never be touched.
35 #      if it changes, we assume the log is writing over it
36 #
37
38 seq=`basename $0`
39 seqres=$RESULT_DIR/$seq
40 seqres=$RESULT_DIR/$seq
41 seqres=$RESULT_DIR/$seq
42 echo "QA output created by $seq"
43
44 here=`pwd`
45 tmp=/tmp/$$
46 status=1
47
48 trap "_cleanup; exit \$status" 0 1 2 3 15
49
50 _cleanup()
51 {
52     cd /
53     rm -f $tmp.*
54     echo "*** unmount"
55     umount $SCRATCH_MNT 2>/dev/null
56 }
57
58 _block_filter()
59 {
60     sed -e 's/[0-9][0-9]*\.\.[0-9][0-9]*/BLOCKRANGE/g'
61 }
62
63 _init()
64 {
65     echo "*** reset partition"
66     $here/src/devzero -b 2048 -n 50 -v 198 $SCRATCH_DEV
67     echo "*** mkfs"
68     force_opts="-dsize=50m -lsize=$log_size"
69     #
70     # Do not discard blocks as we check for patterns in free space.
71     # 
72     # First, make sure that mkfs supports '-K' option by using its
73     # dry run (-N option) and then add it to the force_opts.
74     #
75     if _scratch_mkfs_xfs -N -K $force_opts >/dev/null 2>&1; then
76         force_opts="-K $force_opts"
77     fi
78     echo mkfs_xfs $force_opts $SCRATCH_DEV >>$seqres.full
79     _scratch_mkfs_xfs $force_opts >$tmp.mkfs0 2>&1
80     [ $? -ne 0 ] && \
81         _notrun "Cannot mkfs for this test using MKFS_OPTIONS specified"
82     _filter_mkfs <$tmp.mkfs0 >/dev/null 2>$tmp.mkfs
83     . $tmp.mkfs
84     [ $logsunit -ne 0 ] && \
85         _notrun "Cannot run this test using log MKFS_OPTIONS specified"
86 }
87
88 _log_traffic()
89 {
90     count=$1
91     echo "*** generate log traffic"
92
93     out=$SCRATCH_MNT/$$.tmp
94
95     echo "   *** mount"
96     if ! _scratch_mount
97     then
98         echo "failed to mount $SCRATCH_DEV"
99         exit 1
100     fi
101
102     # having any quota enabled (acct/enfd) means extra log traffic - evil!
103     $here/src/feature -U $SCRATCH_DEV && \
104                 _notrun "UQuota are enabled, test needs controlled log traffic"
105     $here/src/feature -G $SCRATCH_DEV && \
106                 _notrun "GQuota are enabled, test needs controlled log traffic"
107     $here/src/feature -P $SCRATCH_DEV && \
108                 _notrun "PQuota are enabled, test needs controlled log traffic"
109
110     echo "   *** fiddle"
111     while [ $count -ge 0 ]
112     do
113         touch $out
114         sync
115         rm $out
116         sync
117         let "count = count - 1"
118     done
119
120     echo "   *** unmount"
121     if ! umount $SCRATCH_DEV
122     then
123         echo "failed to unmount $SCRATCH_DEV"
124         exit 1
125     fi
126 }
127
128 _log_size()
129 {
130     _scratch_xfs_logprint -tb | $AWK_PROG '
131         /log file: / || /log device: / { print $7}
132     '
133 }
134
135 _log_head()
136 {
137     _scratch_xfs_logprint -tb | $AWK_PROG '
138         /head:/ { print $5 }
139     '
140 }
141
142 # Get log stripe unit for v2 logs; if none specified,
143 # (or v1 log) just return "1" block
144
145 _log_sunit()
146 {
147     if [ ${lsunit:-0} -eq 0 ]; then
148         echo $dbsize
149     else
150         expr $lsunit \* $dbsize
151     fi
152 }
153
154 _after_log()
155 {
156     xfs_db -r $1 -c "sb" -c "print" | $AWK_PROG '
157         /logstart/  { logstart = $3 }
158         /logblocks/ { logblocks = $3 }
159         END {
160             print logstart + logblocks
161         }
162     '
163 }
164
165 _check_corrupt()
166 {
167     f="c6c6c6c6"
168     echo "*** check for corruption"
169     echo "expect $f..." >>$seqres.full
170     xfs_db -r -c "fsblock $2" -c "print" $1 | head | tee -a $seqres.full | \
171         grep -q -v "$f $f $f $f $f $f $f $f" && \
172             _fail "!!! block $2 corrupted!"
173 }
174
175 # get standard environment, filters and checks
176 . ./common.rc
177 . ./common.filter
178
179 # real QA test starts here
180 _supported_fs xfs
181 _supported_os Linux
182
183 rm -f $seqres.full
184
185 # mkfs sizes
186 log_size=2097152
187 log_size_bb=`expr $log_size / 512`
188
189 _require_scratch
190 _init
191
192 block=`_after_log $SCRATCH_DEV`
193 echo "fsblock after log = $block"               >>$seqres.full
194 _check_corrupt $SCRATCH_DEV $block
195
196 actual_log_size=`_log_size`
197 echo "log size = $actual_log_size BB"                      >>$seqres.full
198 head=`_log_head`
199 echo "log position = $head"                     >>$seqres.full
200 lsunit=`_log_sunit`
201 echo "log sunit = $lsunit"                      >>$seqres.full
202
203 # sanity checks
204 [ $actual_log_size -eq $log_size_bb ] || \
205     _fail "!!! unexpected log size $size"
206 [ $head -eq 2 -o $head -eq $((lsunit/512)) ] || \
207     _fail "!!! unexpected initial log position $head vs. $((lsunit/512))"
208
209 # find how how many blocks per op for 100 ops
210 # ignore the fact that it will also include an unmount record etc...
211 # this should be small overall
212 echo "    lots of traffic for sampling" >>$seqres.full
213 sample_size_ops=100
214 _log_traffic $sample_size_ops
215 head1=`_log_head`
216 num_blocks=`expr $head1 - $head`
217 blocks_per_op=`echo "scale=3; $num_blocks / $sample_size_ops" | bc`
218 echo "blocks_per_op = $blocks_per_op" >>$seqres.full
219 num_expected_ops=`echo "$log_size_bb / $blocks_per_op" | bc`
220 echo "num_expected_ops = $num_expected_ops" >>$seqres.full
221 num_expected_to_go=`echo "$num_expected_ops - $sample_size_ops" | bc`
222 echo "num_expected_to_go = $num_expected_to_go" >>$seqres.full
223
224 echo "    lots more traffic" >>$seqres.full
225 _log_traffic $num_expected_to_go
226 head=`_log_head`
227 echo "log position = $head"                     >>$seqres.full
228
229 # e.g. 3891
230 near_end_min=`echo "0.95 * $log_size_bb" | bc | sed 's/\..*//'`
231 echo "near_end_min = $near_end_min" >>$seqres.full
232
233 [ $head -gt $near_end_min -a $head -lt $log_size_bb ] || \
234     _fail "!!! unexpected near end log position $head"
235
236 for c in `seq 0 20`
237 do
238     echo "   little traffic"            >>$seqres.full
239     _log_traffic 2
240     head=`_log_head`
241     echo "log position = $head"         >>$seqres.full
242     _check_corrupt $SCRATCH_DEV $block
243 done
244
245 [ $head -lt 1000 ] || \
246     _fail "!!! unexpected wrapped log position $head"
247
248 # success, all done
249 status=0
250 exit