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