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