956c47729f4709dc18936daa7dfd2d20e25ad018
[xfstests-dev.git] / tests / xfs / 009
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 009
6 #
7 # XFS allocator test (preallocation - allocp, resvsp ,etc)
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     echo "*** unmount"
21     _scratch_unmount
22 }
23
24 _init()
25 {
26     echo "*** mkfs"
27     if ! _scratch_mkfs_xfs >$tmp.out 2>&1
28     then
29         cat $tmp.out
30         echo "failed to mkfs $SCRATCH_DEV"
31         exit 1
32     fi
33
34     echo "*** mount"
35     if ! _try_scratch_mount
36     then
37         echo "failed to mount $SCRATCH_DEV"
38         exit 1
39     fi
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45
46 # real QA test starts here
47 _supported_fs xfs
48 _supported_os Linux
49
50 _require_scratch
51 _require_xfs_io_command "falloc"
52
53 _filesize()
54 {
55     ls -l $1 | $AWK_PROG -v bsize="$bsize" '{print "filesize = " $5 / bsize}'
56 }
57
58 _block_filter()
59 {
60         $AWK_PROG -v bsize="$bsize" '
61         /blocksize/ {
62                 printf("    blocksize BSIZE\n")
63
64                 next
65         }
66
67         /CMD/ {
68                 split($3, off, "=")
69                 offset = off[2]
70                 if (offset != -1)
71                         offset = offset / bsize
72
73                 split($4, len, "=")
74                 nr_blocks = len[2]
75                 if (nr_blocks != -1)
76                         nr_blocks = nr_blocks / bsize
77
78                 printf("    %s %s off=%s, len=%d\n", $1, $2, offset, nr_blocks)
79
80                 next
81         }
82
83         /MAP/ {
84                 split($2, off, "=")
85                 offset = off[2]
86                 if (offset != -1)
87                         offset = offset / bsize
88
89                 split($3, len, "=")
90
91                 nr_blocks = len[2]
92
93                 if (nr_blocks != -1)
94                         nr_blocks = nr_blocks / bsize
95
96                 printf("    %s off=%s, len=%d %s\n", $1, offset, nr_blocks, $4)
97
98                 next
99         }
100
101         /TRUNCATE/ {
102                 split($2, off, "=")
103                 offset = off[2] / bsize
104
105                 printf("    %s off=%s\n", $1, offset)
106
107                 next
108         }
109
110         /\[[0-9]+,[0-9]+\]:/ {
111                 printf("        %s BLOCKRANGE\n", $1)
112
113                 next
114         }
115
116         {
117                 print
118
119                 next
120         }
121         '
122 }
123
124 _init
125 out=$SCRATCH_MNT/$$.tmp
126
127 # This isn't really related to fs block size, it's just what
128 # alloc uses for the "block" unit in it's input parameters...
129 # However, xfs_alloc_file_space() rounds up allocation
130 # request by the filesystem's block size.
131 bsize=$(_get_file_block_size $SCRATCH_MNT)
132
133 # since we're using a clean FS here, we make some assumptions
134 # about availability of contiguous blocks
135
136 # also interesting to note is that ALLOC == FREE. seriously.
137 # the _length is ignored_ in irix. the file is allocated up
138 # to the specified offset, and zero filled if previously
139 # unallocated. the file is truncated at the specified point.
140
141 echo "*** test 1 - reservations cleared on O_TRUNC"
142 rm -f $out
143 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
144 r 0 1000b
145 m
146 EOF
147 _filesize $out
148
149 cat <<EOF | $here/src/alloc -n -b $bsize -f $out -t | _block_filter
150 m
151 EOF
152 _filesize $out
153
154 echo "*** test 2 - reserve & filesize"
155 rm -f $out
156 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
157 r 0 1000b
158 EOF
159
160 _filesize $out
161
162 echo "*** test 3 - alloc & filesize"
163 rm -f $out
164 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
165 a 1000b
166 EOF
167
168 _filesize $out
169
170 echo "*** test 4 - allocations cleared on O_TRUNC"
171 rm -f $out
172 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
173 a 1000b
174 EOF
175 _filesize $out
176
177 cat <<EOF | $here/src/alloc -n -b $bsize -f $out -t | _block_filter
178 m
179 EOF
180 _filesize $out
181
182 echo "*** test 5 - reserve / unreserve"
183 rm -f $out
184 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
185 r 0 100b
186 u 100b 500b
187 m
188 u 900b 200b
189 m
190 EOF
191
192 echo "*** test 6 - reserve adjacent"
193 rm -f $out
194 cat <<EOF | $here/src/alloc -t -n -b $bsize -f $out | _block_filter
195 r 0 100b
196 r 100b 100b
197 m
198 EOF
199
200 echo "*** test 7 - alloc"
201 rm -f $out
202 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
203 a 1000b
204 m
205 a 2000b
206 m
207 EOF
208
209 _filesize $out
210
211 echo "*** test 8 - alloc & truncate"
212 rm -f $out
213 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
214 a 1000b
215 m
216 t 500b
217 m
218 EOF
219
220 _filesize $out
221
222 echo "*** test 9 - reserve & truncate"
223 rm -f $out
224 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
225 r 0 1000b
226 m
227 t 500b
228 m
229 EOF
230
231 _filesize $out
232
233 status=0
234 exit