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