2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
7 # XFS allocator test (preallocation - allocp, resvsp ,etc)
10 _begin_fstest rw ioctl auto prealloc quick
12 # Override the default cleanup function.
22 if ! _scratch_mkfs_xfs >$tmp.out 2>&1
25 echo "failed to mkfs $SCRATCH_DEV"
30 if ! _try_scratch_mount
32 echo "failed to mount $SCRATCH_DEV"
37 # Import common functions.
40 # real QA test starts here
44 _require_xfs_io_command "falloc"
48 ls -l $1 | $AWK_PROG -v bsize="$bsize" '{print "filesize = " $5 / bsize}'
53 $AWK_PROG -v bsize="$bsize" '
55 printf(" blocksize BSIZE\n")
62 offset = strtonum(off[2])
64 offset = offset / bsize
67 nr_blocks = strtonum(len[2])
69 nr_blocks = nr_blocks / bsize
71 printf(" %s %s off=%s, len=%d\n", $1, $2, offset, nr_blocks)
78 offset = strtonum(off[2])
80 offset = offset / bsize
84 nr_blocks = strtonum(len[2])
87 nr_blocks = nr_blocks / bsize
89 printf(" %s off=%s, len=%d %s\n", $1, offset, nr_blocks, $4)
96 offset = strtonum(off[2]) / bsize
98 printf(" %s off=%s\n", $1, offset)
103 /\[[0-9]+,[0-9]+\]:/ {
104 printf(" %s BLOCKRANGE\n", $1)
118 out=$SCRATCH_MNT/$$.tmp
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)
126 # since we're using a clean FS here, we make some assumptions
127 # about availability of contiguous blocks
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.
134 echo "*** test 1 - reservations cleared on O_TRUNC"
136 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
142 cat <<EOF | $here/src/alloc -n -b $bsize -f $out -t | _block_filter
147 echo "*** test 2 - reserve & filesize"
149 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
155 echo "*** test 3 - alloc & filesize"
157 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
163 echo "*** test 4 - allocations cleared on O_TRUNC"
165 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
170 cat <<EOF | $here/src/alloc -n -b $bsize -f $out -t | _block_filter
175 echo "*** test 5 - reserve / unreserve"
177 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
185 echo "*** test 6 - reserve adjacent"
187 cat <<EOF | $here/src/alloc -t -n -b $bsize -f $out | _block_filter
193 echo "*** test 7 - alloc"
195 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
204 echo "*** test 8 - alloc & truncate"
206 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
215 echo "*** test 9 - reserve & truncate"
217 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter