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