xfstests: randholes: hide some Irix/Linux differences more tidily
[xfstests-dev.git] / 136
1 #! /bin/bash
2 # FS QA Test No. 136
3 #
4 # Test the attr2 code
5 # Let's look, xfs_db, at the inode and its literal area for the
6 # extents and the attributes 
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #
24 #-----------------------------------------------------------------------
25 #
26 # creator
27 owner=tes@puffy.melbourne.sgi.com
28
29 seq=`basename $0`
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39     cd /
40     rm -f $tmp.*
41 }
42
43 # get standard environment, filters and checks
44 . ./common.rc
45 . ./common.filter
46
47 # real QA test starts here
48
49 #_notrun "Need to fix up filtering before checkin" 
50
51 # Modify as appropriate.
52 _supported_fs xfs
53 _supported_os IRIX Linux
54 _require_scratch
55
56 export MKFS_OPTIONS="-i size=512,attr=2"
57 _scratch_mkfs_xfs > /dev/null 2>&1
58 _scratch_mount
59
60 file=$SCRATCH_MNT/file
61 touch $file
62 inum=`ls -i $file | awk '{print $1}'`
63 echo "inum=$inum"
64
65 _filter()
66 {
67     sed -e "s#$tmp#TMP#g"
68 }
69
70 add_eas()
71 {
72     start=$1
73     end=$2
74     echo ""; echo "** add $start..$end EAs **"
75     i=$start
76     while [ $i -le $end ]; do 
77         attr -s name.$i -V value $file >/dev/null
78         let i=$i+1
79     done
80 }
81
82 rm_eas()
83 {
84     start=$1
85     end=$2
86     echo ""; echo "** rm $start..$end EAs **"
87     i=$start
88     while [ $i -le $end ]; do 
89         attr -r name.$i $file >/dev/null
90         let i=$i+1
91     done
92 }
93
94 do_extents()
95 {
96     num=$1
97     echo ""; echo "** $num extents **"
98     src/makeextents -v -p -w -n $num $file
99 }
100
101 _print_inode()
102 {
103     umount $SCRATCH_MNT
104     xfs_db -r -c "inode $inum" -c "print" $SCRATCH_DEV |\
105     awk '
106         /nextents/ { print; next }
107         /naextents/ { print; next }
108         /u\./ { print; next }
109         /a\./ { print; next }
110         /forkoff/ { printf("core.forkoff = %d (%d bytes)\n", $3, $3*8); next }
111         /format/ { print; next }
112         /size/ { print; next }
113     '
114     _scratch_mount
115 }
116
117 _print_inode_u()
118 {
119     umount $SCRATCH_MNT
120     xfs_db -r -c "inode $inum" -c "print u" $SCRATCH_DEV
121     _scratch_mount
122 }
123
124 _print_inode_a()
125 {
126     umount $SCRATCH_MNT
127     xfs_db -r -c "inode $inum" -c "print a" $SCRATCH_DEV
128     _scratch_mount
129 }
130
131
132 _test_add_eas()
133 {
134         _print_inode
135
136         add_eas 1 1
137         _print_inode
138
139         add_eas 2 2
140         _print_inode
141
142         add_eas 3 4
143         _print_inode
144
145         add_eas 5 8
146         _print_inode
147
148         add_eas 9 16
149         _print_inode
150
151         add_eas 17 20
152         _print_inode
153
154         add_eas 21 21
155         _print_inode
156
157         add_eas 22 22
158         _print_inode
159
160         add_eas 23 23
161         _print_inode
162
163         add_eas 24 24
164         _print_inode
165
166         add_eas 25 25
167         _print_inode
168
169         add_eas 26 30
170         _print_inode
171
172         add_eas 31 35
173         _print_inode
174
175         rm_eas 1 34
176         _print_inode
177 }
178
179 _test_add_extents()
180 {
181         # now do the extents
182
183         #build up
184         j=1
185         while [ $j -le 30 ]; do
186             do_extents $j
187             _print_inode
188             let j=$j+2
189         done
190
191         #scale down
192         j=30
193         while [ $j -ge 1 ]; do
194             do_extents $j
195             _print_inode
196             let j=$j-2
197         done
198
199         #build up
200         j=1
201         while [ $j -le 30 ]; do
202             do_extents $j
203             _print_inode
204             let j=$j+2
205         done
206 }
207
208 #
209 # Using a nested loop,
210 # for various number of data extents,
211 # try adding EAs and then removing EAs
212 # Check that when we play with the EAs that we don't mess with the extents
213 #
214 _test_extents_eas()
215 {
216         # now do the EAs with the extents
217
218         extents_max=400
219         extents_inc=10
220         EAs_max=100
221         EAs_inc=5
222         for i in `seq 1 $extents_inc $extents_max`; do
223             do_extents $i
224             echo "--- extents: $i ---"
225             _print_inode
226             _print_inode_u > $tmp.u1
227             for j in `seq 1 $EAs_inc $EAs_max`; do
228                 let k=$k+$EAs_inc-1
229                 add_eas $j $k
230             done
231             # should have same extents
232             _print_inode
233             _print_inode_u > $tmp.u2
234             rm_eas 1 $EAs_max
235             _print_inode_u > $tmp.u3
236
237             echo ""
238             echo "*** Extent differences before and after EAs added ***"
239             diff -s $tmp.u1 $tmp.u2 | _filter
240             echo ""
241             if ! diff $tmp.u1 $tmp.u2 >/dev/null; then 
242                 echo "Data extents magically changed"
243                 exit
244             fi
245
246             echo ""
247             echo "*** Extent differences before and after EAs removed ***"
248             diff -s $tmp.u2 $tmp.u3 | _filter
249             echo ""
250             if ! diff $tmp.u2 $tmp.u3 >/dev/null; then 
251                 echo "Data extents magically changed"
252                 exit
253             fi
254         done
255 }
256
257 #
258 # The counterpart of _test_extents_eas
259 # with the nested loops reversed.
260 # For various number of EAs, try adding extents
261 # Check that when we play with the data extents that we don't mess with the EAs
262 #
263 _test_eas_extents()
264 {
265         # now do the EAs with the extents
266
267         extents_max=400
268         extents_inc=10
269         EAs_max=100
270         EAs_inc=5
271         for j in `seq 1 $EAs_inc $EAs_max`; do
272
273             let k=$k+$EAs_inc-1
274             add_eas $j $k
275             echo "--- EAs: $j ---"
276
277             _print_inode
278             _print_inode_a > $tmp.a1
279             for i in `seq 1 $extents_inc $extents_max`; do
280                 do_extents $i
281             done
282
283             # should have same EAs
284             _print_inode
285             _print_inode_a > $tmp.a2
286             >$file 
287             _print_inode_a > $tmp.a3
288
289             echo ""
290             echo "*** EA differences before and after extents added ***"
291             diff -s $tmp.a1 $tmp.a2 | _filter
292             echo ""
293             if ! diff $tmp.a1 $tmp.a2 >/dev/null; then 
294                 echo "EAs magically changed"
295                 exit
296             fi
297
298             echo ""
299             echo "*** EA differences before and after extents removed ***"
300             diff -s $tmp.a2 $tmp.a3 | _filter
301             echo ""
302             if ! diff $tmp.a2 $tmp.a3 >/dev/null; then 
303                 echo "EAs magically changed"
304                 exit
305             fi
306         done
307 }
308
309 #
310 # test to see how we go 
311
312 #
313 # test to ensure it fits a max sf EA
314 #
315 # literal part of inode starts at offset 100 (decimal)
316 # for 512 bytes inode that gives 412 bytes of literal area
317 #
318 # min btree root (numrecs=3) => 3 * 16 + (4 or 8)
319 # for 8 byte alignment => 56 bytes
320 # => 512 - 156 = 356 bytes 
321 #
322 # SF EA of form
323 #   totsize: 2 bytes
324 #   count:   1 byte
325 #   nlen:    1 byte
326 #   vlen:    1 byte
327 #   flags:   1 byte
328 #   name:    nlen
329 #   value:   vlen
330 #
331 # => 6+nlen+vlen
332 #
333 # for nlen=4 "name"
334 # vlen = 356 - (6+4) = 346
335
336 #
337 _test_initial_sf_ea()
338 {
339         rm $file
340         touch $file
341         vlen=402
342         vlen=300
343         dd if=/dev/zero bs=1 count=$vlen | attr -s name $file
344         _print_inode
345 }
346
347 # main
348
349 _test_add_eas
350 _test_add_extents
351 _test_extents_eas
352 _test_eas_extents
353 #_test_initial_sf_ea
354
355 # do a test with a variety of sized EAs
356
357 # success, all done
358 status=0
359 exit