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