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