0b0ce507529a82ad3e09d5869c61e4dd37f6e2cb
[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=2097152"
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 }
61
62 _log_traffic()
63 {
64     count=$1
65     echo "*** generate log traffic"
66
67     out=$SCRATCH_MNT/$$.tmp
68
69     echo "   *** mount"
70     if ! _scratch_mount
71     then
72         echo "failed to mount $SCRATCH_DEV"
73         exit 1
74     fi
75
76     # having any quota enabled (acct/enfd) means extra log traffic - evil!
77     $here/src/feature -U $SCRATCH_DEV && \
78                 _notrun "UQuota are enabled, test needs controlled log traffic"
79     $here/src/feature -G $SCRATCH_DEV && \
80                 _notrun "GQuota are enabled, test needs controlled log traffic"
81     $here/src/feature -P $SCRATCH_DEV && \
82                 _notrun "PQuota are enabled, test needs controlled log traffic"
83
84     echo "   *** fiddle"
85     while [ $count -ge 0 ]
86     do
87         touch $out
88         rm $out
89         let "count = count - 1"
90     done
91
92     echo "   *** unmount"
93     if ! umount $SCRATCH_DEV
94     then
95         echo "failed to unmount $SCRATCH_DEV"
96         exit 1
97     fi
98 }
99
100 _log_size()
101 {
102     _scratch_xfs_logprint -tb | $AWK_PROG '
103         /log file: / || /log device: / { print $7}
104     '
105 }
106
107 _log_head()
108 {
109     _scratch_xfs_logprint -tb | $AWK_PROG '
110         /head:/ { print $5 }
111     '
112 }
113
114 # Get log stripe unit for v2 logs; if none specified,
115 # (or v1 log) just return "1" block
116
117 _log_sunit()
118 {
119     if [ ${lsunit:-0} -eq 0 ]; then
120         echo $dbsize
121     else
122         expr $lsunit \* $dbsize
123     fi
124 }
125
126 _after_log()
127 {
128     xfs_db -r $1 -c "sb" -c "print" | $AWK_PROG '
129         /logstart/  { logstart = $3 }
130         /logblocks/ { logblocks = $3 }
131         END {
132             print logstart + logblocks
133         }
134     '
135 }
136
137 _check_corrupt()
138 {
139     f="c6c6c6c6"
140     echo "*** check for corruption"
141     echo "expect $f..." >>$seq.full
142     xfs_db -r -c "fsblock $2" -c "print" $1 | head | tee -a $seq.full | \
143         grep -q -v "$f $f $f $f $f $f $f $f" && \
144             _fail "!!! block $2 corrupted!"
145 }
146
147 # get standard environment, filters and checks
148 . ./common.rc
149 . ./common.filter
150
151 # real QA test starts here
152 _supported_fs xfs
153 _supported_os Linux
154
155 rm -f $seq.full
156
157 _require_scratch
158 _init
159
160 block=`_after_log $SCRATCH_DEV`
161 echo "fsblock after log = $block"               >>$seq.full
162 _check_corrupt $SCRATCH_DEV $block
163
164 size=`_log_size`
165 echo "log size = $size BB"                      >>$seq.full
166 head=`_log_head`
167 echo "log position = $head"                     >>$seq.full
168 lsunit=`_log_sunit`
169 echo "log sunit = $lsunit"                      >>$seq.full
170
171 [ $size -eq 4096 ] || \
172     _fail "!!! unexpected log size $size"
173 [ $head -eq 2 -o $head -eq $((lsunit/512)) ] || \
174     _fail "!!! unexpected initial log position $head vs. $((lsunit/512))"
175
176 echo "    lots of traffic"                      >>$seq.full
177 _log_traffic 850
178 head=`_log_head`
179 echo "log position = $head"                     >>$seq.full
180
181 [ $head -gt 3850 -a $head -lt 4050 ] || \
182     _fail "!!! unexpected log position $head"
183
184 for c in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
185 do
186     echo "   little traffic"            >>$seq.full
187     _log_traffic 2
188     head=`_log_head`
189     echo "log position = $head"         >>$seq.full
190     _check_corrupt $SCRATCH_DEV $block
191 done
192
193 [ $head -lt 1000 ] || \
194     _fail "!!! unexpected log position $head"
195
196 # success, all done
197 status=0
198 exit