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