Add a test for ENOSPC when fallocating.
[xfstests-dev.git] / 114
1 #! /bin/sh
2 # FS QA Test No. 114
3 #
4 # Test some parent ptr stuff
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24 # creator
25 owner=tes@crackle.melbourne.sgi.com
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     cd /
38     rm -f $tmp.*
39 }
40
41
42 _check_paths()
43 {
44         _path=$1 # might want to only check this path
45
46         sync; sleep 1
47         echo ""
48         echo "Check parent"
49         if ! xfs_io -x -c 'parent -c' $SCRATCH_MNT | _filter_num; then
50                 exit 1
51         fi
52 }
53
54 _print_names()
55 {
56         echo ""
57         echo "Print out hardlink names for given path, $1"
58         echo ""
59
60         xfs_io -x -c parent $1 | awk '/p_ino.*=/ {$3 = "inodeXXX"; print; next} {print}' 
61 }
62
63 _test_create()
64 {
65         echo ""
66         echo "Testing create"
67         echo ""
68
69         # Test out some creations
70         cd $SCRATCH_MNT
71         touch file1
72
73         mkdir dir2
74         touch dir2/file2
75
76         mkdir dir2/dir3
77         touch dir2/dir3/file3
78
79         mkdir dir2/dir3/dir4
80
81         p=dir2/dir3/dir4/file4
82         touch $p
83
84         #_print_names $p >>$here/$seq.full
85         _print_names $p | tee -a $here/$seq.full
86
87         _check_paths $SCRATCH_MNT/$p
88 }
89
90 _test_symlink()
91 {
92         echo ""
93         echo "Testing symlink"
94         echo ""
95
96         d=sym1/sym2/sym3
97         f=$d/sym4_f
98
99         mkdir -p $d
100         ln -s $f symlink1
101         ln symlink1 hlink1
102         ln symlink1 hlink2
103         ln symlink1 hlink3
104         _check_paths $SCRATCH_MNT/symlink1
105         _check_paths $SCRATCH_MNT/hlink1
106         _check_paths $SCRATCH_MNT/hlink2
107         _check_paths $SCRATCH_MNT/hlink3
108 }
109
110 #
111 # create hardlinks from the same dir
112 # and some from different dirs
113 #
114 # test out removing hardlinks too
115 #
116 _test_hardlink()
117 {
118         echo ""
119         echo "Testing hardlink"
120         echo ""
121
122         d=dir2/dir3/dir4
123         d2=dir2/dir5/dir6
124         mkdir -p $d
125         mkdir -p $d2
126         p=$d/file4
127         touch $p
128
129         # create hardlinks
130         paths="$d/l1 $d/l2 $d/l3 $d2/l4 $d2/l5 $d2/l6"
131         for x in $paths; do
132                 ln $p $x
133         done
134
135         _print_names $p >>$here/$seq.full
136
137         echo ""
138         echo "print out names and check after created hardlinks"
139         echo ""
140         for x in $paths; do
141                 _print_names $x | tee -a $here/$seq.full
142                 _check_paths $SCRATCH_MNT/$x
143         done
144
145
146         echo ""
147         echo "now try removing half of the hardlinks"
148         echo ""
149         paths="$d/l1 $d/l2 $d/l3 $d2/l4 $d2/l5 $d2/l6"
150         i=0
151         for x in $paths; do
152                 let i=$i+1
153                 let j=$i%2
154                 if [ $j -eq 0 ]; then
155                         echo "rm'ing $x"
156                         rm $x
157                 fi
158         done
159
160         echo ""
161         echo "print out names and check after removed hardlinks"
162         echo ""
163         for x in $paths; do
164                 if [ -e $x ]; then 
165                         _print_names $x | tee -a $here/$seq.full
166                         _check_paths $SCRATCH_MNT/$x
167                 fi
168         done
169
170 }
171
172 #
173 # in dir, file1 to file2 where file2 does not exist
174 # in dir, file1 to file2 where file2 does exist 
175 # dir/file1 to dir2/file2 where file2 does not exist
176 # dir/file1 to dir2/file2 where file2 does exist
177 # dir to dir2 where dir2 does not exist
178 # dir to dir/dir3 - not allowed
179 #
180 #
181 _test_rename()
182 {
183         echo ""
184         echo "Testing rename"
185         echo ""
186
187         echo ""
188         echo "1. in dir, file1 to file2 where file2 does not exist" 
189         echo ""
190         d1=$SCRATCH_MNT/ren1/ren2/ren3/ren4
191         mkdir -p $d1
192         p1=$d1/f1
193         p2=$d1/f2
194         touch $p1
195         mv $p1 $p2
196         _check_paths $p2
197
198         echo ""
199         echo "2. in dir, file1 to file2 where file2 does exist" 
200         echo ""
201         touch $p1
202         mv $p1 $p2
203         _check_paths $p2
204
205         echo ""
206         echo "3. dir/file1 to dir2/file2 where file2 does not exist"
207         echo ""
208         d2=$SCRATCH_MNT/ren1/ren2/ren3/ren5
209         mkdir -p $d2
210         p3=$d2/f3
211         touch $p1
212         mv $p1 $p3
213         _check_paths $p3
214
215         echo ""
216         echo "4. dir/file1 to dir2/file2 where file2 does exist"
217         echo ""
218         d2=$SCRATCH_MNT/ren1/ren2/ren3/ren5
219         p3=$d2/f3
220         touch $p1
221         mv $p1 $p3
222         _check_paths $p3
223
224         echo ""
225         echo "5. dir to dir2 where dir2 does not exist"
226         echo ""
227         d3=$SCRATCH_MNT/ren1/ren2/ren3/ren6
228         mv $d1 $d3
229         _check_paths $d3
230 }
231
232 _filter_num()
233 {
234         tee -a $here/$seq.full |\
235         sed -e 's/[0-9][0-9]* inodes/I inodes/g' \
236             -e 's/[0-9][0-9]* paths/P paths/g' \
237             -e 's/seed = [0-9][0-9]*/seed = S/'
238 }
239
240
241 _test_fsstress()
242 {
243         echo ""
244         echo "Testing fsstress"
245         echo ""
246
247         out=$SCRATCH_MNT/fsstress.$$
248         count=1000
249         args="-z \
250 -f rmdir=10 -f link=10 -f creat=10 \
251 -f mkdir=10 -f rename=30 -f unlink=10 \
252 -f symlink=10 \
253 -n $count -d $out -p 3"
254
255         echo "fsstress $args" | sed -e "s#$out#outdir#"
256         if ! $FSSTRESS_PROG $args | _filter_num
257         then
258                 echo "    fsstress $args returned $?"
259                 cat $tmp.out | tee -a $here/$seq.full
260                 status=1
261         fi
262
263         _check_paths
264 }
265
266
267 _test_dirstress()
268 {
269         echo ""
270         echo "Testing dirstress"
271         echo ""
272
273         out=$SCRATCH_MNT/dirstress.$$
274         count=1000
275
276         if ! mkdir $out
277         then
278             echo "!! couldn't mkdir $out"
279             status=1
280             exit
281         fi
282
283         args="-d $out -f $count -k -p 3 -n 1"
284         echo "dirstress $args" | sed -e "s#$out#outdir#"
285         if ! $here/src/dirstress $args >$tmp.out 2>&1 | _filter_num
286         then
287                 echo "    dirstress failed"
288                 echo "*** dirstress $args" | tee -a $here/$seq.full
289                 cat $tmp.out >>$here/$seq.full
290                 status=1
291                 exit
292         fi
293
294         args="-d $out -f $count -k -p 3 -n 5"
295         echo "dirstress $args" | sed -e "s#$out#outdir#"
296         if ! $here/src/dirstress $args >$tmp.out 2>&1 | _filter_num
297         then
298                 echo "    dirstress failed"
299                 echo "*** dirstress $args" | tee -a $here/$seq.full
300                 cat $tmp.out >>$here/$seq.full
301                 status=1
302                 exit
303         fi
304
305         _check_paths
306 }
307
308 # get standard environment, filters and checks
309 . ./common.rc
310 . ./common.filter
311
312 _supported_fs xfs
313 _supported_os IRIX
314
315 _require_scratch
316 _need_to_be_root
317
318 rm -f $here/$seq.full
319
320 echo "mkfs"
321 _scratch_mkfs_xfs >>$here/$seq.full 2>&1 \
322     || _fail "mkfs scratch failed"
323 _scratch_mkfs_xfs -i parent=1 >>$here/$seq.full 2>&1 \
324     || _notrun "parent inodes not supported"
325
326 echo "mount"
327 _scratch_mount >>$here/$seq.full 2>&1 \
328     || _fail "mount failed: $MOUNT_OPTIONS"
329
330 # real QA test starts here
331
332 verbose=false
333
334 _test_create
335 _test_hardlink
336 _test_rename
337 _test_symlink
338
339 # stress testing with verification by parent checking programs
340 _test_fsstress
341 _test_dirstress
342
343 # success, all done
344 status=0
345 exit