summaryrefslogtreecommitdiff
path: root/tests/xfs/136
blob: 6479c8c54d056370ba33f777d526d987ba4d69ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#! /bin/bash
# FS QA Test No. 136
#
# Test the attr2 code
# Let's look, xfs_db, at the inode and its literal area for the
# extents and the attributes 
#
#-----------------------------------------------------------------------
# Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
#-----------------------------------------------------------------------
#

seq=`basename $0`
echo "QA output created by $seq"

here=`pwd`
tmp=/tmp/$$
status=1	# failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

_cleanup()
{
    cd /
    rm -f $tmp.*
}

# get standard environment, filters and checks
. ./common.rc
. ./common.filter
. ./common.attr

# real QA test starts here

#_notrun "Need to fix up filtering before checkin" 

# Modify as appropriate.
_supported_fs xfs
_supported_os IRIX Linux

_require_scratch
_require_attrs

export MKFS_OPTIONS="-i size=512,attr=2"
_scratch_mkfs_xfs > /dev/null 2>&1
_scratch_mount

file=$SCRATCH_MNT/file
touch $file
inum=`ls -i $file | awk '{print $1}'`
echo "inum=$inum"

_filter()
{
    sed -e "s#$tmp#TMP#g"
}

add_eas()
{
    start=$1
    end=$2
    echo ""; echo "** add $start..$end EAs **"
    i=$start
    while [ $i -le $end ]; do 
	${ATTR_PROG} -s name.$i -V value $file >/dev/null
	let i=$i+1
    done
}

rm_eas()
{
    start=$1
    end=$2
    echo ""; echo "** rm $start..$end EAs **"
    i=$start
    while [ $i -le $end ]; do 
	${ATTR_PROG} -r name.$i $file >/dev/null
	let i=$i+1
    done
}

do_extents()
{
    num=$1
    echo ""; echo "** $num extents **"
    src/makeextents -v -p -w -n $num $file
}

_print_inode()
{
    umount $SCRATCH_MNT
    xfs_db -r -c "inode $inum" -c "print" $SCRATCH_DEV |\
    awk '
	/nextents/ { print; next }
	/naextents/ { print; next }
	/u\./ { print; next }
	/a\./ { print; next }
	/forkoff/ { printf("core.forkoff = %d (%d bytes)\n", $3, $3*8); next }
	/format/ { print; next }
	/size/ { print; next }
    '
    _scratch_mount
}

_print_inode_u()
{
    umount $SCRATCH_MNT
    xfs_db -r -c "inode $inum" -c "print u" $SCRATCH_DEV
    _scratch_mount
}

_print_inode_a()
{
    umount $SCRATCH_MNT
    xfs_db -r -c "inode $inum" -c "print a" $SCRATCH_DEV
    _scratch_mount
}


_test_add_eas()
{
	_print_inode

	add_eas 1 1
	_print_inode

	add_eas 2 2
	_print_inode

	add_eas 3 4
	_print_inode

	add_eas 5 8
	_print_inode

	add_eas 9 16
	_print_inode

	add_eas 17 20
	_print_inode

	add_eas 21 21
	_print_inode

	add_eas 22 22
	_print_inode

	add_eas 23 23
	_print_inode

	add_eas 24 24
	_print_inode

	add_eas 25 25
	_print_inode

	add_eas 26 30
	_print_inode

	add_eas 31 35
	_print_inode

	rm_eas 1 34
	_print_inode
}

_test_add_extents()
{
	# now do the extents

	#build up
	j=1
	while [ $j -le 30 ]; do
	    do_extents $j
	    _print_inode
	    let j=$j+2
	done

	#scale down
	j=30
	while [ $j -ge 1 ]; do
	    do_extents $j
	    _print_inode
	    let j=$j-2
	done

	#build up
	j=1
	while [ $j -le 30 ]; do
	    do_extents $j
	    _print_inode
	    let j=$j+2
	done
}

#
# Using a nested loop,
# for various number of data extents,
# try adding EAs and then removing EAs
# Check that when we play with the EAs that we don't mess with the extents
#
_test_extents_eas()
{
	# now do the EAs with the extents

	extents_max=400
	extents_inc=10
	EAs_max=100
	EAs_inc=5
	for i in `seq 1 $extents_inc $extents_max`; do
	    do_extents $i
	    echo "--- extents: $i ---"
	    _print_inode
	    _print_inode_u > $tmp.u1
	    for j in `seq 1 $EAs_inc $EAs_max`; do
		let k=$k+$EAs_inc-1
		add_eas $j $k
	    done
	    # should have same extents
	    _print_inode
	    _print_inode_u > $tmp.u2
            rm_eas 1 $EAs_max
	    _print_inode_u > $tmp.u3

	    echo ""
	    echo "*** Extent differences before and after EAs added ***"
	    diff -s $tmp.u1 $tmp.u2 | _filter
	    echo ""
	    if ! diff $tmp.u1 $tmp.u2 >/dev/null; then 
		echo "Data extents magically changed"
		exit
	    fi

	    echo ""
	    echo "*** Extent differences before and after EAs removed ***"
	    diff -s $tmp.u2 $tmp.u3 | _filter
	    echo ""
	    if ! diff $tmp.u2 $tmp.u3 >/dev/null; then 
		echo "Data extents magically changed"
		exit
	    fi
	done
}

#
# The counterpart of _test_extents_eas
# with the nested loops reversed.
# For various number of EAs, try adding extents
# Check that when we play with the data extents that we don't mess with the EAs
#
_test_eas_extents()
{
	# now do the EAs with the extents

	extents_max=400
	extents_inc=10
	EAs_max=100
	EAs_inc=5
	for j in `seq 1 $EAs_inc $EAs_max`; do

	    let k=$k+$EAs_inc-1
	    add_eas $j $k
	    echo "--- EAs: $j ---"

	    _print_inode
	    _print_inode_a > $tmp.a1
	    for i in `seq 1 $extents_inc $extents_max`; do
		do_extents $i
	    done

	    # should have same EAs
	    _print_inode
	    _print_inode_a > $tmp.a2
	    >$file 
	    _print_inode_a > $tmp.a3

	    echo ""
	    echo "*** EA differences before and after extents added ***"
	    diff -s $tmp.a1 $tmp.a2 | _filter
	    echo ""
	    if ! diff $tmp.a1 $tmp.a2 >/dev/null; then 
		echo "EAs magically changed"
		exit
	    fi

	    echo ""
	    echo "*** EA differences before and after extents removed ***"
	    diff -s $tmp.a2 $tmp.a3 | _filter
	    echo ""
	    if ! diff $tmp.a2 $tmp.a3 >/dev/null; then 
		echo "EAs magically changed"
		exit
	    fi
	done
}

#
# test to see how we go 

#
# test to ensure it fits a max sf EA
#
# literal part of inode starts at offset 100 (decimal)
# for 512 bytes inode that gives 412 bytes of literal area
#
# min btree root (numrecs=3) => 3 * 16 + (4 or 8)
# for 8 byte alignment => 56 bytes
# => 512 - 156 = 356 bytes 
#
# SF EA of form
#   totsize: 2 bytes
#   count:   1 byte
#   nlen:    1 byte
#   vlen:    1 byte
#   flags:   1 byte
#   name:    nlen
#   value:   vlen
#
# => 6+nlen+vlen
#
# for nlen=4 "name"
# vlen = 356 - (6+4) = 346
# 
#
_test_initial_sf_ea()
{
	rm $file
	touch $file
	vlen=402
	vlen=300
	dd if=/dev/zero bs=1 count=$vlen | ${ATTR_PROG} -s name $file
	_print_inode
}

# main

_test_add_eas
_test_add_extents
_test_extents_eas
_test_eas_extents
#_test_initial_sf_ea

# do a test with a variety of sized EAs

# success, all done
status=0
exit