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