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