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