xfs: test what happens when we reset the root dir and it has xattrs
[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
49 _require_scratch
50 _require_xfs_io_command "falloc"
51
52 _filesize()
53 {
54     ls -l $1 | $AWK_PROG -v bsize="$bsize" '{print "filesize = " $5 / bsize}'
55 }
56
57 _block_filter()
58 {
59         $AWK_PROG -v bsize="$bsize" '
60         /blocksize/ {
61                 printf("    blocksize BSIZE\n")
62
63                 next
64         }
65
66         /CMD/ {
67                 split($3, off, "=")
68                 offset = strtonum(off[2])
69                 if (offset != -1)
70                         offset = offset / bsize
71
72                 split($4, len, "=")
73                 nr_blocks = strtonum(len[2])
74                 if (nr_blocks != -1)
75                         nr_blocks = nr_blocks / bsize
76
77                 printf("    %s %s off=%s, len=%d\n", $1, $2, offset, nr_blocks)
78
79                 next
80         }
81
82         /MAP/ {
83                 split($2, off, "=")
84                 offset = strtonum(off[2])
85                 if (offset != -1)
86                         offset = offset / bsize
87
88                 split($3, len, "=")
89
90                 nr_blocks = strtonum(len[2])
91
92                 if (nr_blocks != -1)
93                         nr_blocks = nr_blocks / bsize
94
95                 printf("    %s off=%s, len=%d %s\n", $1, offset, nr_blocks, $4)
96
97                 next
98         }
99
100         /TRUNCATE/ {
101                 split($2, off, "=")
102                 offset = strtonum(off[2]) / bsize
103
104                 printf("    %s off=%s\n", $1, offset)
105
106                 next
107         }
108
109         /\[[0-9]+,[0-9]+\]:/ {
110                 printf("        %s BLOCKRANGE\n", $1)
111
112                 next
113         }
114
115         {
116                 print
117
118                 next
119         }
120         '
121 }
122
123 _init
124 out=$SCRATCH_MNT/$$.tmp
125
126 # This isn't really related to fs block size, it's just what
127 # alloc uses for the "block" unit in it's input parameters...
128 # However, xfs_alloc_file_space() rounds up allocation
129 # request by the filesystem's block size.
130 bsize=$(_get_file_block_size $SCRATCH_MNT)
131
132 # since we're using a clean FS here, we make some assumptions
133 # about availability of contiguous blocks
134
135 # also interesting to note is that ALLOC == FREE. seriously.
136 # the _length is ignored_ in irix. the file is allocated up
137 # to the specified offset, and zero filled if previously
138 # unallocated. the file is truncated at the specified point.
139
140 echo "*** test 1 - reservations cleared on O_TRUNC"
141 rm -f $out
142 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
143 r 0 1000b
144 m
145 EOF
146 _filesize $out
147
148 cat <<EOF | $here/src/alloc -n -b $bsize -f $out -t | _block_filter
149 m
150 EOF
151 _filesize $out
152
153 echo "*** test 2 - reserve & filesize"
154 rm -f $out
155 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
156 r 0 1000b
157 EOF
158
159 _filesize $out
160
161 echo "*** test 3 - alloc & filesize"
162 rm -f $out
163 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
164 a 1000b
165 EOF
166
167 _filesize $out
168
169 echo "*** test 4 - allocations cleared on O_TRUNC"
170 rm -f $out
171 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
172 a 1000b
173 EOF
174 _filesize $out
175
176 cat <<EOF | $here/src/alloc -n -b $bsize -f $out -t | _block_filter
177 m
178 EOF
179 _filesize $out
180
181 echo "*** test 5 - reserve / unreserve"
182 rm -f $out
183 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
184 r 0 100b
185 u 100b 500b
186 m
187 u 900b 200b
188 m
189 EOF
190
191 echo "*** test 6 - reserve adjacent"
192 rm -f $out
193 cat <<EOF | $here/src/alloc -t -n -b $bsize -f $out | _block_filter
194 r 0 100b
195 r 100b 100b
196 m
197 EOF
198
199 echo "*** test 7 - alloc"
200 rm -f $out
201 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
202 a 1000b
203 m
204 a 2000b
205 m
206 EOF
207
208 _filesize $out
209
210 echo "*** test 8 - alloc & truncate"
211 rm -f $out
212 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
213 a 1000b
214 m
215 t 500b
216 m
217 EOF
218
219 _filesize $out
220
221 echo "*** test 9 - reserve & truncate"
222 rm -f $out
223 cat <<EOF | $here/src/alloc -n -b $bsize -f $out | _block_filter
224 r 0 1000b
225 m
226 t 500b
227 m
228 EOF
229
230 _filesize $out
231
232 status=0
233 exit