Whamcloud - gitweb
b=892
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 # bug number for skipped test: 1979
11 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"42b"}
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13
14 [ "$ALWAYS_EXCEPT$EXCEPT" ] && echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
15
16 SRCDIR=`dirname $0`
17 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
18
19 TMP=${TMP:-/tmp}
20
21 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
22 CREATETEST=${CREATETEST:-createtest}
23 LFIND=${LFIND:-lfind}
24 LSTRIPE=${LSTRIPE:-lstripe}
25 LCTL=${LCTL:-lctl}
26 MCREATE=${MCREATE:-mcreate}
27 OPENFILE=${OPENFILE:-openfile}
28 OPENUNLINK=${OPENUNLINK:-openunlink}
29 TOEXCL=${TOEXCL:-toexcl}
30 TRUNCATE=${TRUNCATE:-truncate}
31 MUNLINK=${MUNLINK:-munlink}
32 SOCKETSERVER=${SOCKETSERVER:-socketserver}
33 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
34 IOPENTEST1=${IOPENTEST1:-iopentest1}
35 IOPENTEST2=${IOPENTEST2:-iopentest2}
36
37 if [ $UID -ne 0 ]; then
38         RUNAS_ID="$UID"
39         RUNAS=""
40 else
41         RUNAS_ID=${RUNAS_ID:-500}
42         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
43 fi
44
45 export NAME=${NAME:-local}
46
47 SAVE_PWD=$PWD
48
49 clean() {
50         echo -n "cln.."
51         sh llmountcleanup.sh > /dev/null || exit 20
52         I_MOUNTED=no
53 }
54 CLEAN=${CLEAN:-clean}
55
56 start() {
57         echo -n "mnt.."
58         sh llrmount.sh > /dev/null || exit 10
59         I_MOUNTED=yes
60         echo "done"
61 }
62 START=${START:-start}
63
64 log() {
65         echo "$*"
66         lctl mark "$*" 2> /dev/null || true
67 }
68
69 run_one() {
70         if ! mount | grep -q $DIR; then
71                 $START
72         fi
73         log "== test $1: $2"
74         export TESTNAME=test_$1
75         test_$1 || error "test_$1: $?"
76         unset TESTNAME
77         pass
78         cd $SAVE_PWD
79         $CLEAN
80 }
81
82 build_test_filter() {
83         for O in $ONLY; do
84             eval ONLY_${O}=true
85         done
86         for E in $EXCEPT $ALWAYS_EXCEPT; do
87             eval EXCEPT_${E}=true
88         done
89 }
90
91 _basetest() {
92     echo $*
93 }
94
95 basetest() {
96     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
97 }
98
99 run_test() {
100          base=`basetest $1`
101          if [ "$ONLY" ]; then
102                  testname=ONLY_$1
103                  if [ ${!testname}x != x ]; then
104                         run_one $1 "$2"
105                         return $?
106                  fi
107                  testname=ONLY_$base
108                  if [ ${!testname}x != x ]; then
109                          run_one $1 "$2"
110                          return $?
111                  fi
112                  echo -n "."
113                  return 0
114         fi
115         testname=EXCEPT_$1
116         if [ ${!testname}x != x ]; then
117                  echo "skipping excluded test $1"
118                  return 0
119         fi
120         testname=EXCEPT_$base
121         if [ ${!testname}x != x ]; then
122                  echo "skipping excluded test $1 (base $base)"
123                  return 0
124         fi
125         run_one $1 "$2"
126         return $?
127 }
128
129 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
130
131 error() { 
132         log "FAIL: $@"
133         if [ "$SANITYLOG" ]; then
134                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
135         else
136                 exit 1
137         fi
138 }
139
140 pass() { 
141         echo PASS
142 }
143
144 MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
145 if [ -z "$MOUNT" ]; then
146         sh llmount.sh
147         MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
148         [ -z "$MOUNT" ] && error "NAME=$NAME not mounted"
149         I_MOUNTED=yes
150 fi
151
152 [ `echo $MOUNT | wc -w` -gt 1 ] && error "NAME=$NAME mounted more than once"
153
154 DIR=${DIR:-$MOUNT}
155 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
156
157 LOVNAME=`cat /proc/fs/lustre/llite/fs0/lov/common_name`
158 STRIPECOUNT=`cat /proc/fs/lustre/lov/$LOVNAME/numobd`
159
160 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
161 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
162 rm -rf $DIR/[Rdfs][1-9]*
163
164 build_test_filter
165
166 echo preparing for tests involving mounts
167 EXT2_DEV=${EXT2_DEV:-/tmp/SANITY.LOOP}
168 touch $EXT2_DEV
169 mke2fs -F $EXT2_DEV 1000 > /dev/null
170
171 test_0() {
172         touch $DIR/f
173         $CHECKSTAT -t file $DIR/f || error
174         rm $DIR/f
175         $CHECKSTAT -a $DIR/f || error
176 }
177 run_test 0 "touch .../f ; rm .../f ============================="
178
179 test_1a() {
180         mkdir $DIR/d1
181         mkdir $DIR/d1/d2
182         $CHECKSTAT -t dir $DIR/d1/d2 || error
183 }
184 run_test 1a "mkdir .../d1; mkdir .../d1/d2 ====================="
185
186 test_1b() {
187         rmdir $DIR/d1/d2
188         rmdir $DIR/d1
189         $CHECKSTAT -a $DIR/d1 || error
190 }
191 run_test 1b "rmdir .../d1/d2; rmdir .../d1 ====================="
192
193 test_2a() {
194         mkdir $DIR/d2
195         touch $DIR/d2/f
196         $CHECKSTAT -t file $DIR/d2/f || error
197 }
198 run_test 2a "mkdir .../d2; touch .../d2/f ======================"
199
200 test_2b() {
201         rm -r $DIR/d2
202         $CHECKSTAT -a $DIR/d2 || error
203 }
204 run_test 2b "rm -r .../d2; checkstat .../d2/f ======================"
205
206 test_3a() {
207         mkdir $DIR/d3
208         $CHECKSTAT -t dir $DIR/d3 || error
209 }
210 run_test 3a "mkdir .../d3 ======================================"
211
212 test_3b() {
213         if [ ! -d $DIR/d3 ]; then
214                 mkdir $DIR/d3
215         fi
216         touch $DIR/d3/f
217         $CHECKSTAT -t file $DIR/d3/f || error
218 }
219 run_test 3b "touch .../d3/f ===================================="
220
221 test_3c() {
222         rm -r $DIR/d3
223         $CHECKSTAT -a $DIR/d3 || error
224 }
225 run_test 3c "rm -r .../d3 ======================================"
226
227 test_4a() {
228         mkdir $DIR/d4
229         $CHECKSTAT -t dir $DIR/d4 || error
230 }
231 run_test 4a "mkdir .../d4 ======================================"
232
233 test_4b() {
234         if [ ! -d $DIR/d4 ]; then
235                 mkdir $DIR/d4
236         fi
237         mkdir $DIR/d4/d2
238         $CHECKSTAT -t dir $DIR/d4/d2 || error
239 }
240 run_test 4b "mkdir .../d4/d2 ==================================="
241
242 test_5() {
243         mkdir $DIR/d5
244         mkdir $DIR/d5/d2
245         chmod 0707 $DIR/d5/d2
246         $CHECKSTAT -t dir -p 0707 $DIR/d5/d2 || error
247 }
248 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
249
250 test_6a() {
251         touch $DIR/f6a
252         chmod 0666 $DIR/f6a || error
253         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
254 }
255 run_test 6a "touch .../f6a; chmod .../f6a ======================"
256
257 test_6b() {
258         [ $RUNAS_ID -eq $UID ] && echo "skipping test 6b" && return
259         if [ ! -f $DIR/f6a ]; then
260                 touch $DIR/f6a
261                 chmod 0666 $DIR/f6a
262         fi
263         $RUNAS chmod 0444 $DIR/f6a && error
264         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
265 }
266 run_test 6b "$RUNAS chmod .../f6a (should return error) =="
267
268 test_6c() {
269         [ $RUNAS_ID -eq $UID ] && echo "skipping test 6c" && return
270         touch $DIR/f6c
271         chown $RUNAS_ID $DIR/f6c || error
272         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
273 }
274 run_test 6c "touch .../f6c; chown .../f6c ======================"
275
276 test_6d() {
277         [ $RUNAS_ID -eq $UID ] && echo "skipping test 6d" && return
278         if [ ! -f $DIR/f6c ]; then
279                 touch $DIR/f6c
280                 chown $RUNAS_ID $DIR/f6c
281         fi
282         $RUNAS chown $UID $DIR/f6c && error
283         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
284 }
285 run_test 6d "$RUNAS chown .../f6c (should return error) =="
286
287 test_6e() {
288         [ $RUNAS_ID -eq $UID ] && echo "skipping test 6e" && return
289         touch $DIR/f6e
290         chgrp $RUNAS_ID $DIR/f6e || error
291         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
292 }
293 run_test 6e "touch .../f6e; chgrp .../f6e ======================"
294
295 test_6f() {
296         [ $RUNAS_ID -eq $UID ] && echo "skipping test 6f" && return
297         if [ ! -f $DIR/f6e ]; then
298                 touch $DIR/f6e
299                 chgrp $RUNAS_ID $DIR/f6e
300         fi
301         $RUNAS chgrp $UID $DIR/f6e && error
302         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
303 }
304 run_test 6f "$RUNAS chgrp .../f6e (should return error) =="
305
306 test_6g() {
307         [ $RUNAS_ID -eq $UID ] && echo "skipping test 6g" && return
308         mkdir $DIR/d6g || error
309         chmod 777 $DIR/d6g || error
310         $RUNAS mkdir $DIR/d6g/d || error
311         chmod g+s $DIR/d6g/d || error
312         mkdir $DIR/d6g/d/subdir
313         $CHECKSTAT -g \#$RUNAS_ID $DIR/d6g/d/subdir || error
314 }
315 run_test 6g "Is new dir in sgid dir inheriting group?"
316
317 test_7a() {
318         mkdir $DIR/d7
319         $MCREATE $DIR/d7/f
320         chmod 0666 $DIR/d7/f
321         $CHECKSTAT -t file -p 0666 $DIR/d7/f || error
322 }
323 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
324
325 test_7b() {
326         if [ ! -d $DIR/d7 ]; then
327                 mkdir $DIR/d7
328         fi
329         $MCREATE $DIR/d7/f2
330         echo -n foo > $DIR/d7/f2
331         [ "`cat $DIR/d7/f2`" = "foo" ] || error
332         $CHECKSTAT -t file -s 3 $DIR/d7/f2 || error
333 }
334 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
335
336 test_8() {
337         mkdir $DIR/d8
338         touch $DIR/d8/f
339         chmod 0666 $DIR/d8/f
340         $CHECKSTAT -t file -p 0666 $DIR/d8/f || error
341 }
342 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
343
344 test_9() {
345         mkdir $DIR/d9
346         mkdir $DIR/d9/d2
347         mkdir $DIR/d9/d2/d3
348         $CHECKSTAT -t dir $DIR/d9/d2/d3 || error
349 }
350 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
351
352 test_10() {
353         mkdir $DIR/d10
354         mkdir $DIR/d10/d2
355         touch $DIR/d10/d2/f
356         $CHECKSTAT -t file $DIR/d10/d2/f || error
357 }
358 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
359
360 test_11() {
361         mkdir $DIR/d11
362         mkdir $DIR/d11/d2
363         chmod 0666 $DIR/d11/d2
364         chmod 0705 $DIR/d11/d2
365         $CHECKSTAT -t dir -p 0705 $DIR/d11/d2 || error
366 }
367 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
368
369 test_12() {
370         mkdir $DIR/d12
371         touch $DIR/d12/f
372         chmod 0666 $DIR/d12/f
373         chmod 0654 $DIR/d12/f
374         $CHECKSTAT -t file -p 0654 $DIR/d12/f || error
375 }
376 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
377
378 test_13() {
379         mkdir $DIR/d13
380         dd if=/dev/zero of=$DIR/d13/f count=10
381         >  $DIR/d13/f
382         $CHECKSTAT -t file -s 0 $DIR/d13/f || error
383 }
384 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
385
386 test_14() {
387         mkdir $DIR/d14
388         touch $DIR/d14/f
389         rm $DIR/d14/f
390         $CHECKSTAT -a $DIR/d14/f || error
391 }
392 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
393
394 test_15() {
395         mkdir $DIR/d15
396         touch $DIR/d15/f
397         mv $DIR/d15/f $DIR/d15/f2
398         $CHECKSTAT -t file $DIR/d15/f2 || error
399 }
400 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
401
402 test_16() {
403         mkdir $DIR/d16
404         touch $DIR/d16/f
405         rm -rf $DIR/d16/f
406         $CHECKSTAT -a $DIR/d16/f || error
407 }
408 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
409
410 test_17a() {
411         mkdir $DIR/d17
412         touch $DIR/d17/f
413         ln -s $DIR/d17/f $DIR/d17/l-exist
414         ls -l $DIR/d17
415         $CHECKSTAT -l $DIR/d17/f $DIR/d17/l-exist || error
416         $CHECKSTAT -f -t f $DIR/d17/l-exist || error
417         rm -f $DIR/l-exist
418         $CHECKSTAT -a $DIR/l-exist || error
419 }
420 run_test 17a "symlinks: create, remove (real) =================="
421
422 test_17b() {
423         if [ ! -d $DIR/d17 ]; then
424                 mkdir $DIR/d17
425         fi
426         ln -s no-such-file $DIR/d17/l-dangle
427         ls -l $DIR/d17
428         $CHECKSTAT -l no-such-file $DIR/d17/l-dangle || error
429         $CHECKSTAT -fa $DIR/d17/l-dangle || error
430         rm -f $DIR/l-dangle
431         $CHECKSTAT -a $DIR/l-dangle || error
432 }
433 run_test 17b "symlinks: create, remove (dangling) =============="
434
435 test_18() {
436         touch $DIR/f
437         ls $DIR || error
438 }
439 run_test 18 "touch .../f ; ls ... =============================="
440
441 test_19a() {
442         touch $DIR/f19
443         ls -l $DIR
444         rm $DIR/f19
445         $CHECKSTAT -a $DIR/f19 || error
446 }
447 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
448
449 test_19b() {
450         ls -l $DIR/f19 && error || true
451 }
452 run_test 19b "ls -l .../f19 (should return error) =============="
453
454 test_19c() {
455         [ $RUNAS_ID -eq $UID ] && echo "skipping test 19c" && return
456         $RUNAS touch $DIR/f19 && error || true
457 }
458 run_test 19c "$RUNAS touch .../f19 (should return error) =="
459
460 test_19d() {
461         cat $DIR/f19 && error || true
462 }
463 run_test 19d "cat .../f19 (should return error) =============="
464
465 test_20() {
466         touch $DIR/f
467         rm $DIR/f
468         log "1 done"
469         touch $DIR/f
470         rm $DIR/f
471         log "2 done"
472         touch $DIR/f
473         rm $DIR/f
474         log "3 done"
475         $CHECKSTAT -a $DIR/f || error
476 }
477 run_test 20 "touch .../f ; ls -l ... ==========================="
478
479 test_21() {
480         mkdir $DIR/d21
481         [ -f $DIR/d21/dangle ] && rm -f $DIR/d21/dangle
482         ln -s dangle $DIR/d21/link
483         echo foo >> $DIR/d21/link
484         cat $DIR/d21/dangle
485         $CHECKSTAT -t link $DIR/d21/link || error
486         $CHECKSTAT -f -t file $DIR/d21/link || error
487 }
488 run_test 21 "write to dangling link ============================"
489
490 test_22() {
491         mkdir $DIR/d22
492         chown $RUNAS_ID $DIR/d22
493         # Tar gets pissy if it can't access $PWD *sigh*
494         (cd /tmp;
495         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
496         $RUNAS tar xfC - $DIR/d22)
497         ls -lR $DIR/d22/etc
498         $CHECKSTAT -t dir $DIR/d22/etc || error
499         $CHECKSTAT -u \#$RUNAS_ID $DIR/d22/etc || error
500 }
501 run_test 22 "unpack tar archive as non-root user ==============="
502
503 test_23() {
504         mkdir $DIR/d23
505         $TOEXCL $DIR/d23/f23
506         $TOEXCL -e $DIR/d23/f23 || error
507 }
508 run_test 23 "O_CREAT|O_EXCL in subdir =========================="
509
510 test_24a() {
511         echo '== rename sanity =============================================='
512         echo '-- same directory rename'
513         mkdir $DIR/R1
514         touch $DIR/R1/f
515         mv $DIR/R1/f $DIR/R1/g
516         $CHECKSTAT -t file $DIR/R1/g || error
517 }
518 run_test 24a "touch .../R1/f; rename .../R1/f .../R1/g ========="
519
520 test_24b() {
521         mkdir $DIR/R2
522         touch $DIR/R2/{f,g}
523         mv $DIR/R2/f $DIR/R2/g
524         $CHECKSTAT -a $DIR/R2/f || error
525         $CHECKSTAT -t file $DIR/R2/g || error
526 }
527 run_test 24b "touch .../R2/{f,g}; rename .../R2/f .../R2/g ====="
528
529 test_24c() {
530         mkdir $DIR/R3
531         mkdir $DIR/R3/f
532         mv $DIR/R3/f $DIR/R3/g
533         $CHECKSTAT -a $DIR/R3/f || error
534         $CHECKSTAT -t dir $DIR/R3/g || error
535 }
536 run_test 24c "mkdir .../R3/f; rename .../R3/f .../R3/g ========="
537
538 test_24d() {
539         mkdir $DIR/R4
540         mkdir $DIR/R4/{f,g}
541         perl -e "rename \"$DIR/R4/f\", \"$DIR/R4/g\";"
542         $CHECKSTAT -a $DIR/R4/f || error
543         $CHECKSTAT -t dir $DIR/R4/g || error
544 }
545 run_test 24d "mkdir .../R4/{f,g}; rename .../R4/f .../R4/g ====="
546
547 test_24e() {
548         echo '-- cross directory renames --' 
549         mkdir $DIR/R5{a,b}
550         touch $DIR/R5a/f
551         mv $DIR/R5a/f $DIR/R5b/g
552         $CHECKSTAT -a $DIR/R5a/f || error
553         $CHECKSTAT -t file $DIR/R5b/g || error
554 }
555 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
556
557 test_24f() {
558         mkdir $DIR/R6{a,b}
559         touch $DIR/R6a/f $DIR/R6b/g
560         mv $DIR/R6a/f $DIR/R6b/g
561         $CHECKSTAT -a $DIR/R6a/f || error
562         $CHECKSTAT -t file $DIR/R6b/g || error
563 }
564 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
565
566 test_24g() {
567         mkdir $DIR/R7{a,b}
568         mkdir $DIR/R7a/d
569         mv $DIR/R7a/d $DIR/R7b/e
570         $CHECKSTAT -a $DIR/R7a/d || error
571         $CHECKSTAT -t dir $DIR/R7b/e || error
572 }
573 run_test 24g "mkdir .../R7a/d; rename .../R7a/d .../R5b/e ======"
574
575 test_24h() {
576         mkdir $DIR/R8{a,b}
577         mkdir $DIR/R8a/d $DIR/R8b/e
578         perl -e "rename \"$DIR/R8a/d\", \"$DIR/R8b/e\";"
579         $CHECKSTAT -a $DIR/R8a/d || error
580         $CHECKSTAT -t dir $DIR/R8b/e || error
581 }
582 run_test 24h "mkdir .../R8{a,b} R8a/{d,e}; mv .../R8a/d .../R8b/e"
583
584 test_24i() {
585         echo "-- rename error cases"
586         mkdir $DIR/R9
587         mkdir $DIR/R9/a
588         touch $DIR/R9/f
589         perl -e "rename \"$DIR/R9/f\", \"$DIR/R9/a\";"
590         $CHECKSTAT -t file $DIR/R9/f || error
591         $CHECKSTAT -t dir  $DIR/R9/a || error
592         $CHECKSTAT -a file $DIR/R9/a/f || error
593 }
594 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
595
596 test_24j() {
597         mkdir $DIR/R10
598         perl -e "rename \"$DIR/R10/f\", \"$DIR/R10/g\"" 
599         $CHECKSTAT -t dir $DIR/R10 || error
600         $CHECKSTAT -a $DIR/R10/f || error
601         $CHECKSTAT -a $DIR/R10/g || error
602 }
603 run_test 24j "source does not exist ============================" 
604
605 test_24k() {
606         mkdir $DIR/R11a $DIR/R11a/d
607         touch $DIR/R11a/f
608         mv $DIR/R11a/f $DIR/R11a/d
609         $CHECKSTAT -a $DIR/R11a/f || error
610         $CHECKSTAT -t file $DIR/R11a/d/f || error
611 }
612 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
613
614 # bug 2429 - rename foo foo foo creates invalid file
615 test_24l() {
616         f="$DIR/f24l"
617         multiop $f OcNs || error
618 }
619 run_test 24l "Renaming a file to itself ========================"
620
621 test_24m() {
622         f="$DIR/f24m"
623         multiop $f OcLN ${f}2 ${f}2 || error
624 }
625 run_test 24m "Renaming a file to a hard link to itself ========="
626
627 test_25a() {
628         echo '== symlink sanity ============================================='
629         mkdir $DIR/d25
630         ln -s d25 $DIR/s25
631         touch $DIR/s25/foo || error
632 }
633 run_test 25a "create file in symlinked directory ==============="
634
635 test_25b() {
636         if [ ! -d $DIR/d25 ]; then
637                 run_one 25a
638         fi
639         $CHECKSTAT -t file $DIR/s25/foo || error
640 }
641 run_test 25b "lookup file in symlinked directory ==============="
642
643 test_26a() {
644         mkdir $DIR/d26
645         mkdir $DIR/d26/d26-2
646         ln -s d26/d26-2 $DIR/s26
647         touch $DIR/s26/foo || error
648 }
649 run_test 26a "multiple component symlink ======================="
650
651 test_26b() {
652         mkdir -p $DIR/d26b/d26-2
653         ln -s d26b/d26-2/foo $DIR/s26-2
654         touch $DIR/s26-2 || error
655 }
656 run_test 26b "multiple component symlink at end of lookup ======"
657
658 test_26c() {
659         mkdir $DIR/d26.2
660         touch $DIR/d26.2/foo
661         ln -s d26.2 $DIR/s26.2-1
662         ln -s s26.2-1 $DIR/s26.2-2
663         ln -s s26.2-2 $DIR/s26.2-3
664         chmod 0666 $DIR/s26.2-3/foo
665 }
666 run_test 26c "chain of symlinks ================================"
667
668 # recursive symlinks (bug 439)
669 test_26d() {
670         ln -s d26-3/foo $DIR/d26-3
671 }
672 run_test 26d "create multiple component recursive symlink ======"
673
674 test_26e() {
675         if [ ! -h $DIR/d26-3 ]; then
676                 run_one 26d
677         fi
678         rm $DIR/d26-3
679 }
680 run_test 26e "unlink multiple component recursive symlink ======"
681
682 test_27a() {
683         echo '== stripe sanity =============================================='
684         mkdir $DIR/d27
685         $LSTRIPE $DIR/d27/f0 8192 0 1 || error
686         $CHECKSTAT -t file $DIR/d27/f0 || error
687         pass
688         log "== test_27b: write to one stripe file ========================="
689         cp /etc/hosts $DIR/d27/f0 || error
690 }
691 run_test 27a "one stripe file =================================="
692
693 test_27c() {
694         [ "$STRIPECOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
695         if [ ! -d $DIR/d27 ]; then
696                 mkdir $DIR/d27
697         fi
698         $LSTRIPE $DIR/d27/f01 8192 0 2 || error
699         [ `$LFIND $DIR/d27/f01 | grep -A 10 obdidx | wc -l` -eq 4 ] ||
700                 error "two-stripe file doesn't have two stripes"
701         pass
702         log "== test_27d: write to two stripe file file f01 ================"
703         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error
704 }
705 run_test 27c "create two stripe file f01 ======================="
706
707 test_27d() {
708         if [ ! -d $DIR/d27 ]; then
709                 mkdir $DIR/d27
710         fi
711         $LSTRIPE $DIR/d27/fdef 0 -1 0 || error
712         $CHECKSTAT -t file $DIR/d27/fdef || error
713         #dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
714 }
715 run_test 27d "create file with default settings ================"
716
717 test_27e() {
718         if [ ! -d $DIR/d27 ]; then
719                 mkdir $DIR/d27
720         fi
721         $LSTRIPE $DIR/d27/f12 8192 0 2 || error
722         $LSTRIPE $DIR/d27/f12 8192 0 2 && error
723         $CHECKSTAT -t file $DIR/d27/f12 || error
724 }
725 run_test 27e "lstripe existing file (should return error) ======"
726
727 test_27f() {
728         if [ ! -d $DIR/d27 ]; then
729                 mkdir $DIR/d27
730         fi
731         $LSTRIPE $DIR/d27/fbad 100 0 1 && error
732         dd if=/dev/zero of=$DIR/d27/f12 bs=4k count=4 || error
733         $LFIND $DIR/d27/fbad || error
734 }
735 run_test 27f "lstripe with bad stripe size (should return error)"
736
737 test_27g() {
738         if [ ! -d $DIR/d27 ]; then
739                 mkdir $DIR/d27
740         fi
741         $MCREATE $DIR/d27/fnone || error
742         pass
743         log "== test 27h: lfind with no objects ============================"
744         $LFIND $DIR/d27/fnone 2>&1 | grep -q "no stripe info" || error
745         pass
746         log "== test 27i: lfind with some objects =========================="
747         touch $DIR/d27/fsome || error
748         $LFIND $DIR/d27/fsome | grep -q obdidx || error
749 }
750 run_test 27g "test lfind ======================================="
751
752 test_27j() {
753         if [ ! -d $DIR/d27 ]; then
754                 mkdir $DIR/d27
755         fi
756         $LSTRIPE $DIR/d27/f27j 8192 $STRIPECOUNT 1 && error || true
757 }
758 run_test 27j "lstripe with bad stripe offset (should return error)"
759
760 test_28() {
761         mkdir $DIR/d28
762         $CREATETEST $DIR/d28/ct || error
763 }
764 run_test 28 "create/mknod/mkdir with bad file types ============"
765
766 cancel_lru_locks() {
767         for d in /proc/fs/lustre/ldlm/namespaces/$1*; do
768                 echo clear > $d/lru_size
769         done
770         grep [0-9] /proc/fs/lustre/ldlm/namespaces/$1*/lock_unused_count /dev/null
771 }
772
773 test_29() {
774         cancel_lru_locks MDC
775         mkdir $DIR/d29
776         touch $DIR/d29/foo
777         log 'first d29'
778         ls -l $DIR/d29
779         MDCDIR=${MDCDIR:-/proc/fs/lustre/ldlm/namespaces/MDC_*}
780         LOCKCOUNTORIG=`cat $MDCDIR/lock_count`
781         LOCKUNUSEDCOUNTORIG=`cat $MDCDIR/lock_unused_count`
782         log 'second d29'
783         ls -l $DIR/d29
784         log 'done'
785         LOCKCOUNTCURRENT=`cat $MDCDIR/lock_count`
786         LOCKUNUSEDCOUNTCURRENT=`cat $MDCDIR/lock_unused_count`
787         if [ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]; then
788                 echo "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
789                 error
790         fi
791         if [ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]; then
792                 echo "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
793                 error
794         fi
795 }
796 run_test 29 "IT_GETATTR regression  ============================"
797
798 test_30() {
799         cp `which ls` $DIR
800         $DIR/ls /
801         rm $DIR/ls
802 }
803 run_test 30 "run binary from Lustre (execve) ==================="
804
805 test_31a() {
806         $OPENUNLINK $DIR/f31 $DIR/f31 || error
807         $CHECKSTAT -a $DIR/f31 || error
808 }
809 run_test 31a "open-unlink file =================================="
810
811 test_31b() {
812         touch $DIR/f31 || error
813         ln $DIR/f31 $DIR/f31b || error
814         multiop $DIR/f31b Ouc || error
815         $CHECKSTAT -t file $DIR/f31 || error
816 }
817 run_test 31b "unlink file with multiple links while open ======="
818
819 test_31c() {
820         touch $DIR/f31 || error
821         ln $DIR/f31 $DIR/f31c || error
822         multiop $DIR/f31 O_uc &
823         MULTIPID=$!
824         multiop $DIR/f31c Ouc
825         usleep 500
826         kill -USR1 $MULTIPID
827         wait $MUTLIPID
828 }
829 run_test 31c "open-unlink file with multiple links ============="
830
831 test_31d() {
832         opendirunlink $DIR/d31d $DIR/d31d || error
833         $CHECKSTAT -a $DIR/d31d || error
834 }
835 run_test 31d "remove of open directory ========================="
836
837 test_32a() {
838         echo "== more mountpoints and symlinks ================="
839         [ -e $DIR/d32a ] && rm -fr $DIR/d32a
840         mkdir -p $DIR/d32a/ext2-mountpoint 
841         mount -t ext2 -o loop $EXT2_DEV $DIR/d32a/ext2-mountpoint || error
842         $CHECKSTAT -t dir $DIR/d32a/ext2-mountpoint/.. || error  
843         umount $DIR/d32a/ext2-mountpoint || error
844 }
845 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
846
847 test_32b() {
848         [ -e $DIR/d32b ] && rm -fr $DIR/d32b
849         mkdir -p $DIR/d32b/ext2-mountpoint 
850         mount -t ext2 -o loop $EXT2_DEV $DIR/d32b/ext2-mountpoint || error
851         ls -al $DIR/d32b/ext2-mountpoint/.. || error
852         umount $DIR/d32b/ext2-mountpoint || error
853 }
854 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
855  
856 test_32c() {
857         [ -e $DIR/d32c ] && rm -fr $DIR/d32c
858         mkdir -p $DIR/d32c/ext2-mountpoint 
859         mount -t ext2 -o loop $EXT2_DEV $DIR/d32c/ext2-mountpoint || error
860         mkdir -p $DIR/d32c/d2/test_dir    
861         $CHECKSTAT -t dir $DIR/d32c/ext2-mountpoint/../d2/test_dir || error
862         umount $DIR/d32c/ext2-mountpoint || error
863 }
864 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
865
866 test_32d() {
867         [ -e $DIR/d32d ] && rm -fr $DIR/d32d
868         mkdir -p $DIR/d32d/ext2-mountpoint 
869         mount -t ext2 -o loop $EXT2_DEV $DIR/d32d/ext2-mountpoint || error
870         mkdir -p $DIR/d32d/d2/test_dir    
871         ls -al $DIR/d32d/ext2-mountpoint/../d2/test_dir || error
872         umount $DIR/d32d/ext2-mountpoint || error
873 }
874 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
875
876 test_32e() {
877         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
878         mkdir -p $DIR/d32e/tmp    
879         TMP_DIR=$DIR/d32e/tmp       
880         ln -s $DIR/d32e $TMP_DIR/symlink11 
881         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
882         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
883         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
884 }
885 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
886
887 test_32f() {
888         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
889         mkdir -p $DIR/d32f/tmp    
890         TMP_DIR=$DIR/d32f/tmp       
891         ln -s $DIR/d32f $TMP_DIR/symlink11 
892         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
893         ls $DIR/d32f/tmp/symlink11  || error
894         ls $DIR/d32f/symlink01 || error
895 }
896 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
897
898 test_32g() {
899         [ -e $DIR/d32g ] && rm -fr $DIR/d32g
900         [ -e $DIR/test_dir ] && rm -fr $DIR/test_dir
901         mkdir -p $DIR/test_dir 
902         mkdir -p $DIR/d32g/tmp    
903         TMP_DIR=$DIR/d32g/tmp       
904         ln -s $DIR/test_dir $TMP_DIR/symlink12 
905         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
906         $CHECKSTAT -t link $DIR/d32g/tmp/symlink12 || error
907         $CHECKSTAT -t link $DIR/d32g/symlink02 || error
908         $CHECKSTAT -t dir -f $DIR/d32g/tmp/symlink12 || error
909         $CHECKSTAT -t dir -f $DIR/d32g/symlink02 || error
910 }
911 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/test_dir"
912
913 test_32h() {
914         [ -e $DIR/d32h ] && rm -fr $DIR/d32h
915         [ -e $DIR/test_dir ] && rm -fr $DIR/test_dir
916         mkdir -p $DIR/test_dir 
917         mkdir -p $DIR/d32h/tmp    
918         TMP_DIR=$DIR/d32h/tmp       
919         ln -s $DIR/test_dir $TMP_DIR/symlink12 
920         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
921         ls $DIR/d32h/tmp/symlink12 || error
922         ls $DIR/d32h/symlink02  || error
923 }
924 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/test_dir"
925
926 test_32i() {
927         [ -e $DIR/d32i ] && rm -fr $DIR/d32i
928         mkdir -p $DIR/d32i/ext2-mountpoint 
929         mount -t ext2 -o loop $EXT2_DEV $DIR/d32i/ext2-mountpoint || error
930         touch $DIR/d32i/test_file
931         $CHECKSTAT -t file $DIR/d32i/ext2-mountpoint/../test_file || error  
932         umount $DIR/d32i/ext2-mountpoint || error
933 }
934 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
935
936 test_32j() {
937         [ -e $DIR/d32j ] && rm -fr $DIR/d32j
938         mkdir -p $DIR/d32j/ext2-mountpoint 
939         mount -t ext2 -o loop $EXT2_DEV $DIR/d32j/ext2-mountpoint || error
940         touch $DIR/d32j/test_file
941         cat $DIR/d32j/ext2-mountpoint/../test_file || error
942         umount $DIR/d32j/ext2-mountpoint || error
943 }
944 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
945
946 test_32k() {
947         rm -fr $DIR/d32k
948         mkdir -p $DIR/d32k/ext2-mountpoint 
949         mount -t ext2 -o loop $EXT2_DEV $DIR/d32k/ext2-mountpoint  
950         mkdir -p $DIR/d32k/d2
951         touch $DIR/d32k/d2/test_file || error
952         $CHECKSTAT -t file $DIR/d32k/ext2-mountpoint/../d2/test_file || error
953         umount $DIR/d32k/ext2-mountpoint || error
954 }
955 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
956
957 test_32l() {
958         rm -fr $DIR/d32l
959         mkdir -p $DIR/d32l/ext2-mountpoint 
960         mount -t ext2 -o loop $EXT2_DEV $DIR/d32l/ext2-mountpoint || error
961         mkdir -p $DIR/d32l/d2
962         touch $DIR/d32l/d2/test_file
963         cat  $DIR/d32l/ext2-mountpoint/../d2/test_file || error
964         umount $DIR/d32l/ext2-mountpoint || error
965 }
966 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
967
968 test_32m() {
969         rm -fr $DIR/d32m
970         mkdir -p $DIR/d32m/tmp    
971         TMP_DIR=$DIR/d32m/tmp       
972         ln -s $DIR $TMP_DIR/symlink11 
973         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
974         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
975         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
976 }
977 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
978
979 test_32n() {
980         rm -fr $DIR/d32n
981         mkdir -p $DIR/d32n/tmp    
982         TMP_DIR=$DIR/d32n/tmp       
983         ln -s $DIR $TMP_DIR/symlink11 
984         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
985         ls -l $DIR/d32n/tmp/symlink11  || error
986         ls -l $DIR/d32n/symlink01 || error
987 }
988 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
989
990 test_32o() {
991         rm -fr $DIR/d32o
992         rm -f $DIR/test_file
993         touch $DIR/test_file 
994         mkdir -p $DIR/d32o/tmp    
995         TMP_DIR=$DIR/d32o/tmp       
996         ln -s $DIR/test_file $TMP_DIR/symlink12 
997         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
998         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
999         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
1000         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
1001         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
1002 }
1003 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/test_file"
1004
1005 test_32p() {
1006     log 32p_1
1007         rm -fr $DIR/d32p
1008     log 32p_2
1009         rm -f $DIR/test_file
1010     log 32p_3
1011         touch $DIR/test_file 
1012     log 32p_4
1013         mkdir -p $DIR/d32p/tmp    
1014     log 32p_5
1015         TMP_DIR=$DIR/d32p/tmp       
1016     log 32p_6
1017         ln -s $DIR/test_file $TMP_DIR/symlink12 
1018     log 32p_7
1019         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1020     log 32p_8
1021         cat $DIR/d32p/tmp/symlink12 || error
1022     log 32p_9
1023         cat $DIR/d32p/symlink02 || error
1024     log 32p_10
1025 }
1026 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/test_file"
1027
1028 test_32q() {
1029         [ -e $DIR/d32q ] && rm -fr $DIR/d32q
1030         mkdir -p $DIR/d32q
1031         touch $DIR/d32q/under_the_mount
1032         mount -t ext2 -o loop $EXT2_DEV $DIR/d32q
1033         ls $DIR/d32q/under_the_mount &&  error || true
1034         umount $DIR/d32q || error
1035 }
1036 run_test 32q "stat follows mountpoints in Lustre ========================="
1037
1038 test_32r() {
1039         [ -e $DIR/d32r ] && rm -fr $DIR/d32r
1040         mkdir -p $DIR/d32r
1041         touch $DIR/d32r/under_the_mount
1042         mount -t ext2 -o loop $EXT2_DEV $DIR/d32r
1043         ls $DIR/d32r | grep -q under_the_mount &&  error || true
1044         umount $DIR/d32r || error
1045 }
1046 run_test 32r "opendir follows mountpoints in Lustre ========================="
1047
1048 #   chmod 444 /mnt/lustre/somefile
1049 #   open(/mnt/lustre/somefile, O_RDWR)
1050 #   Should return -1
1051 test_33() {
1052         rm -f $DIR/test_33_file
1053         touch $DIR/test_33_file
1054         chmod 444 $DIR/test_33_file
1055         chown $RUNAS_ID $DIR/test_33_file
1056         log 33_1
1057         $RUNAS $OPENFILE -f O_RDWR $DIR/test_33_file && error || true
1058         log 33_2
1059 }
1060 run_test 33 "write file with mode 444 (should return error) ===="
1061                                                                                                                                                
1062 test_33a() {
1063         rm -fr $DIR/d33
1064         mkdir -p $DIR/d33
1065         chown $RUNAS_ID $DIR/d33
1066         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 || error
1067         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && error || true
1068 }
1069 run_test 33a "test open file(mode=0444) with O_RDWR (should return error) ===="
1070
1071 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
1072 test_34a() {
1073         rm -f $DIR/test_34_file
1074         $MCREATE $DIR/test_34_file || error
1075         $LFIND $DIR/test_34_file 2>&1 | grep -q "no stripe info" || error
1076         $TRUNCATE $DIR/test_34_file $TEST_34_SIZE || error
1077         $LFIND $DIR/test_34_file 2>&1 | grep -q "no stripe info" || error
1078         $CHECKSTAT -s $TEST_34_SIZE $DIR/test_34_file || error
1079 }
1080 run_test 34a "truncate file that has not been opened ==========="
1081
1082 test_34b() {
1083         [ ! -f $DIR/test_34_file ] && run_one 34a
1084         $CHECKSTAT -s $TEST_34_SIZE $DIR/test_34_file || error
1085         $OPENFILE -f O_RDONLY $DIR/test_34_file
1086         $LFIND $DIR/test_34_file 2>&1 | grep -q "no stripe info" || error
1087         $CHECKSTAT -s $TEST_34_SIZE $DIR/test_34_file || error
1088 }
1089 run_test 34b "O_RDONLY opening file doesn't create objects ====="
1090
1091 test_34c() {
1092         [ ! -f $DIR/test_34_file ] && run_one 34a 
1093         $CHECKSTAT -s $TEST_34_SIZE $DIR/test_34_file || error
1094         $OPENFILE -f O_RDWR $DIR/test_34_file
1095         $LFIND $DIR/test_34_file 2>&1 | grep -q "no stripe info" && error
1096         $CHECKSTAT -s $TEST_34_SIZE $DIR/test_34_file || error
1097 }
1098 run_test 34c "O_RDWR opening file-with-size works =============="
1099
1100 test_34d() {
1101         dd if=/dev/zero of=$DIR/test_34_file conv=notrunc bs=4k count=1 || error
1102         $CHECKSTAT -s $TEST_34_SIZE $DIR/test_34_file || error
1103         rm $DIR/test_34_file
1104 }
1105 run_test 34d "write to sparse file ============================="
1106
1107 test_34e() {
1108         rm -f $DIR/test_34_file
1109         $MCREATE $DIR/test_34_file || error
1110         $TRUNCATE $DIR/test_34_file 1000 || error
1111         $CHECKSTAT -s 1000 $DIR/test_34_file || error
1112         $OPENFILE -f O_RDWR $DIR/test_34_file
1113         $CHECKSTAT -s 1000 $DIR/test_34_file || error
1114 }
1115 run_test 34e "create objects, some with size and some without =="
1116
1117 test_35a() {
1118         cp /bin/sh $DIR/test_35a_file
1119         chmod 444 $DIR/test_35a_file
1120         chown $RUNAS_ID $DIR/test_35a_file
1121         $RUNAS $DIR/test_35a_file && error || true
1122         rm $DIR/test_35a_file
1123 }
1124 run_test 35a "exec file with mode 444 (should return and not leak) ====="
1125
1126
1127 test_36a() {
1128         rm -f $DIR/test_36_file
1129         utime $DIR/test_36_file || error
1130 }
1131 run_test 36a "MDS utime check (mknod, utime) ==================="
1132
1133 test_36b() {
1134         echo "" > $DIR/test_36_file
1135         utime $DIR/test_36_file || error
1136 }
1137 run_test 36b "OST utime check (open, utime) ===================="
1138
1139 test_36c() {
1140         rm -f $DIR/d36/test_36_file
1141         mkdir $DIR/d36
1142         chown $RUNAS_ID $DIR/d36
1143         $RUNAS utime $DIR/d36/test_36_file || error
1144 }
1145 run_test 36c "non-root MDS utime check (mknod, utime) =========="
1146
1147 test_36d() {
1148         [ ! -d $DIR/d36 ] && run_one 36c
1149         echo "" > $DIR/d36/test_36_file
1150         $RUNAS utime $DIR/d36/test_36_file || error
1151 }
1152 run_test 36d "non-root OST utime check (open, utime) ==========="
1153
1154 test_36e() {
1155         [ $RUNAS_ID -eq $UID ] && return
1156         [ ! -d $DIR/d36 ] && mkdir $DIR/d36
1157         touch $DIR/d36/test_36_file2
1158         $RUNAS utime $DIR/d36/test_36_file2 && error || true
1159 }
1160 run_test 36e "utime on non-owned file (should return error) ===="
1161
1162 test_37() {
1163         mkdir -p $DIR/dextra
1164         echo f > $DIR/dextra/fbugfile
1165         mount -t ext2 -o loop $EXT2_DEV $DIR/dextra
1166         ls $DIR/dextra | grep "\<fbugfile\>" && error
1167         umount $DIR/dextra || error
1168         rm -f $DIR/dextra/fbugfile || error
1169 }
1170 run_test 37 "ls a mounted file system to check old content ====="
1171
1172 test_38() {
1173         o_directory $DIR/test38
1174 }
1175 run_test 38 "open a regular file with O_DIRECTORY =============="
1176
1177 test_39() {
1178         touch $DIR/test_39_file
1179         touch $DIR/test_39_file2
1180 #       ls -l  $DIR/test_39_file $DIR/test_39_file2
1181 #       ls -lu  $DIR/test_39_file $DIR/test_39_file2
1182 #       ls -lc  $DIR/test_39_file $DIR/test_39_file2
1183         sleep 2
1184         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/test_39_file2
1185 #       ls -l  $DIR/test_39_file $DIR/test_39_file2
1186 #       ls -lu  $DIR/test_39_file $DIR/test_39_file2
1187 #       ls -lc  $DIR/test_39_file $DIR/test_39_file2
1188         [ $DIR/test_39_file2 -nt $DIR/test_39_file ] || error
1189 }
1190 run_test 39 "mtime changed on create ==========================="
1191
1192 test_40() {
1193         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
1194         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
1195         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
1196 }
1197 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
1198
1199 test_41() {
1200         # bug 1553
1201         small_write $DIR/f41 18
1202 }
1203 run_test 41 "test small file write + fstat ====================="
1204
1205 count_ost_writes() {
1206         cat /proc/fs/lustre/osc/*/stats |
1207             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
1208 }
1209 start_kupdated() {
1210         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs
1211         kill -CONT `pidof kupdated`
1212 }
1213 stop_kupdated() {
1214         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
1215         kill -STOP `pidof kupdated`
1216         trap start_kupdated EXIT
1217 }
1218
1219 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
1220 # file truncation, and file removal.
1221 test_42a() {
1222         cancel_lru_locks OSC
1223         stop_kupdated
1224         sync # just to be safe
1225         BEFOREWRITES=`count_ost_writes`
1226         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
1227         AFTERWRITES=`count_ost_writes`
1228         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1229                 error "$BEFOREWRITES < $AFTERWRITES"
1230         start_kupdated
1231 }
1232 run_test 42a "ensure that we don't flush on close =============="
1233
1234 test_42b() {
1235         cancel_lru_locks OSC
1236         stop_kupdated
1237         sync
1238         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
1239         BEFOREWRITES=`count_ost_writes`
1240         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
1241         AFTERWRITES=`count_ost_writes`
1242         [ $BEFOREWRITES -eq $AFTERWRITES ] ||
1243             error "$BEFOREWRITES < $AFTERWRITES on unlink"
1244         BEFOREWRITES=`count_ost_writes`
1245         sync || error "sync: $?"
1246         AFTERWRITES=`count_ost_writes`
1247         [ $BEFOREWRITES -eq $AFTERWRITES ] ||
1248             error "$BEFOREWRITES < $AFTERWRITES on sync"
1249         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
1250         start_kupdated
1251         return 0
1252 }
1253 run_test 42b "test destroy of file with cached dirty data ======"
1254
1255 # if these tests just want to test the effect of truncation,
1256 # they have to be very careful.  consider:
1257 # - the first open gets a {0,EOF}PR lock
1258 # - the first write conflicts and gets a {0, count-1}PW
1259 # - the rest of the writes are under {count,EOF}PW
1260 # - the open for truncate tries to match a {0,EOF}PR
1261 #   for the filesize and cancels the PWs.
1262 # any number of fixes (don't get {0,EOF} on open, match
1263 # composite locks, do smarter file size management) fix
1264 # this, but for now we want these tests to verify that
1265 # the cancelation with truncate intent works, so we
1266 # start the file with a full-file pw lock to match against
1267 # until the truncate.
1268 trunc_test() {
1269         test=$1
1270         file=$DIR/$test
1271         offset=$2
1272         cancel_lru_locks OSC
1273         stop_kupdated
1274         # prime the file with 0,EOF PW to match
1275         touch $file
1276         $TRUNCATE $file 0
1277         sync; sync
1278         # now the real test..
1279         dd if=/dev/zero of=$file bs=1024 count=100
1280         BEFOREWRITES=`count_ost_writes`
1281         $TRUNCATE $file $offset
1282         cancel_lru_locks OSC
1283         AFTERWRITES=`count_ost_writes`
1284         start_kupdated
1285 }
1286
1287 test_42c() {
1288         trunc_test 42c 1024
1289         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
1290             error "$BEFOREWRITES < $AFTERWRITES on truncate"
1291         rm $file
1292 }
1293 run_test 42c "test partial truncate of file with cached dirty data ===="
1294
1295 test_42d() {
1296         trunc_test 42d 0
1297         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1298             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
1299         rm $file
1300 }
1301 run_test 42d "test complete truncate of file with cached dirty data ===="
1302
1303 test_43() {
1304         mkdir $DIR/d43
1305         cp -p /bin/ls $DIR/d43/f
1306         exec 100>> $DIR/d43/f   
1307         $DIR/d43/f && error || true
1308         exec 100<&-
1309 }
1310 run_test 43 "execution of file opened for write should return -ETXTBSY=="
1311
1312 test_43a() {
1313         mkdir -p $DIR/d43
1314         cp -p `which multiop` $DIR/d43/multiop
1315         touch $DIR/d43/g
1316         $DIR/d43/multiop $DIR/d43/g o_c &
1317         MULTIPID=$!
1318         sleep 1
1319         multiop $DIR/d43/multiop Oc && error "expected error, got success"
1320         kill -USR1 $MULTIPID || return 2
1321         wait $MULTIPID || return 3
1322 }
1323 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY=="
1324
1325 test_43b() {
1326         mkdir -p $DIR/d43
1327         cp -p `which multiop` $DIR/d43/multiop
1328         touch $DIR/d43/g
1329         $DIR/d43/multiop $DIR/d43/g o_c &
1330         MULTIPID=$!
1331         sleep 1
1332         truncate $DIR/d43/multiop 0 && error "expected error, got success"
1333         kill -USR1 $MULTIPID || return 2
1334         wait $MULTIPID || return 3
1335 }
1336 run_test 43b "truncate of file being executed should return -ETXTBSY===="
1337
1338 test_43c() {
1339         local testdir="$DIR/d43c"
1340         mkdir -p $testdir
1341         cp $SHELL $testdir/
1342         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) |  \
1343                 ( cd $testdir && md5sum -c)
1344 }
1345 run_test 43c "md5sum of copy into lustre================================"
1346
1347 test_44() {
1348         [  "$STRIPECOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
1349         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=127
1350         dd if=$DIR/f1 bs=4k count=1
1351 }
1352 run_test 44 "zero length read from a sparse stripe ============="
1353
1354 test_44a() {
1355     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
1356                          awk '{print $2}'`
1357     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
1358                       awk '{print $2}'`
1359     if [ $nstripe -eq 0 ] ; then
1360         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
1361     fi
1362
1363     OFFSETS="0 $((stride/2)) $((stride-1))"
1364     for offset in $OFFSETS ; do
1365       for i in `seq 0 $((nstripe-1))`; do
1366         rm -f $DIR/d44a
1367         local GLOBALOFFSETS=""
1368         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
1369         ll_sparseness_write $DIR/d44a $size  || error "ll_sparseness_write"
1370         GLOBALOFFSETS="$GLOBALOFFSETS $size"
1371         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
1372                             || error "ll_sparseness_verify $GLOBALOFFSETS"
1373
1374         for j in `seq 0 $((nstripe-1))`; do
1375             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
1376             ll_sparseness_write $DIR/d44a $size || error "ll_sparseness_write"
1377             GLOBALOFFSETS="$GLOBALOFFSETS $size"
1378         done
1379         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
1380                             || error "ll_sparseness_verify $GLOBALOFFSETS"
1381       done
1382     done
1383 }
1384 run_test 44a "test sparse pwrite ==============================="
1385
1386 dirty_osc_total() {
1387         tot=0
1388         for d in /proc/fs/lustre/osc/*/cur_dirty_bytes; do
1389                 tot=$(($tot + `cat $d`))
1390         done
1391         echo $tot
1392 }
1393 do_dirty_record() {
1394         before=`dirty_osc_total`
1395         echo executing "\"$*\""
1396         eval $*
1397         after=`dirty_osc_total`
1398         echo before $before, after $after
1399 }
1400 test_45() {
1401         f="$DIR/f45"
1402         stop_kupdated
1403         sync
1404         do_dirty_record "echo blah > $f"
1405         [ $before -eq $after ] && error "write wasn't cached"
1406         do_dirty_record "> $f"
1407         [ $before -gt $after ] || error "truncate didn't lower dirty count"
1408         do_dirty_record "echo blah > $f"
1409         [ $before -eq $after ] && error "write wasn't cached"
1410         do_dirty_record "sync"
1411         [ $before -gt $after ] || error "writeback didn't lower dirty count"
1412         do_dirty_record "echo blah > $f"
1413         [ $before -eq $after ] && error "write wasn't cached"
1414         do_dirty_record "cancel_lru_locks OSC"
1415         [ $before -gt $after ] || error "lock cancelation didn't lower dirty count"
1416         start_kupdated
1417 }
1418 run_test 45 "osc io page accounting ============================"
1419
1420 page_size() {
1421         getconf PAGE_SIZE
1422 }
1423
1424 # in a 2 stripe file (lov.sh), page 63 maps to page 31 in its object.  this
1425 # test tickles a bug where re-dirtying a page was failing to be mapped to the
1426 # objects offset and an assert hit when an rpc was built with 63's mapped 
1427 # offset 31 and 31's raw 31 offset. it also found general redirtying bugs.
1428 test_46() {
1429         f="$DIR/f46"
1430         stop_kupdated
1431         sync
1432         dd if=/dev/zero of=$f bs=`page_size` seek=31 count=1
1433         sync
1434         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=63 count=1
1435         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=31 count=1
1436         sync
1437         start_kupdated
1438 }
1439 run_test 46 "dirtying a previously written page ================"
1440
1441 # Check that device nodes are created and then visible correctly (#2091)
1442 test_47() {
1443         cmknod $DIR/test_47_node || error
1444 }
1445 run_test 47 "Device nodes check ================================"
1446
1447 test_48() {
1448         mkdir $DIR/d48
1449         cd $DIR/d48
1450         mv $DIR/d48 $DIR/d48.new || error "move directory failed"
1451         mkdir $DIR/d48 || error "recreate diectory failed"
1452         ls || error "can't list after recreate directory"
1453 }
1454 run_test 48 "Access renamed current working directory ========="
1455
1456 test_50() {
1457         # bug 1485
1458         mkdir $DIR/d50
1459         cd $DIR/d50
1460         ls /proc/$$/cwd || error
1461 }
1462 run_test 50 "special situations: /proc symlinks  ==============="
1463
1464 test_51() {
1465         # bug 1516 - create an empty entry right after ".." then split dir
1466         mkdir $DIR/d49
1467         touch $DIR/d49/foo
1468         $MCREATE $DIR/d49/bar
1469         rm $DIR/d49/foo
1470         createmany -m $DIR/d49/longfile 201
1471         FNUM=202
1472         while [ `ls -sd $DIR/d49 | awk '{ print $1 }'` -eq 4 ]; do
1473                 $MCREATE $DIR/d49/longfile$FNUM
1474                 FNUM=$(($FNUM + 1))
1475                 echo -n "+"
1476         done
1477         ls -l $DIR/d49 > /dev/null || error
1478 }
1479 run_test 51 "special situations: split htree with empty entry =="
1480
1481 test_52a() {
1482         [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
1483         mkdir -p $DIR/d52a
1484         touch $DIR/d52a/foo
1485         chattr =a $DIR/d52a/foo || error
1486         echo bar >> $DIR/d52a/foo || error
1487         cp /etc/hosts $DIR/d52a/foo && error
1488         rm -f $DIR/d52a/foo 2>/dev/null && error
1489         link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error
1490         echo foo >> $DIR/d52a/foo || error
1491         mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error
1492         lsattr $DIR/d52a/foo | egrep -q "^-+a-+ $DIR/d52a/foo" || error
1493         chattr -a $DIR/d52a/foo || error
1494
1495         rm -fr $DIR/d52a || error
1496 }
1497 run_test 52a "append-only flag test (should return errors) ====="
1498
1499 test_52b() {
1500         [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
1501         mkdir -p $DIR/d52b
1502         touch $DIR/d52b/foo
1503         chattr =i $DIR/d52b/foo || error
1504         cat test > $DIR/d52b/foo && error
1505         cp /etc/hosts $DIR/d52b/foo && error
1506         rm -f $DIR/d52b/foo 2>/dev/null && error
1507         link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error
1508         echo foo >> $DIR/d52b/foo && error
1509         mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error
1510         [ -f $DIR/d52b/foo ] || error
1511         [ -f $DIR/d52b/foo_ren ] && error
1512         lsattr $DIR/d52b/foo | egrep -q "^-+i-+ $DIR/d52b/foo" || error
1513         chattr -i $DIR/d52b/foo || error
1514
1515         rm -fr $DIR/d52b || error
1516 }
1517 run_test 52b "immutable flag test (should return errors) ======="
1518
1519 test_53() {
1520         for i in /proc/fs/lustre/osc/OSC*mds1 ; do
1521                 ostname=`echo $i | cut -d _ -f 3-4 | sed -e s/_mds1//`
1522                 ost_last=`cat /proc/fs/lustre/obdfilter/$ostname/last_id`
1523                 mds_last=`cat $i/prealloc_last_id`
1524                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
1525                 if [ $ost_last != $mds_last ]; then
1526                     error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
1527                 fi
1528         done
1529 }
1530 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
1531
1532 test_54() {
1533         $SOCKETSERVER $DIR/socket &
1534         sleep 1
1535         $SOCKETCLIENT $DIR/socket || error
1536         $MUNLINK $DIR/socket
1537 }
1538 run_test 54 "unix damain socket test ==========================="
1539
1540 test_59() {
1541         echo "touch 130 files"
1542         for i in `seq 1 130` ; do
1543                 touch $DIR/59-$i
1544         done
1545         echo "rm 130 files"
1546         for i in `seq 1 130` ; do
1547                 rm -f $DIR/59-$i
1548         done
1549         sync
1550         sleep 2
1551         # wait for commitment of removal
1552 }
1553 run_test 59 "verify cancellation of llog records async ========="
1554
1555 test_60() {
1556         echo 60 "llog tests run from kernel mode"
1557         sh run-llog.sh
1558 }
1559 run_test 60 "llog sanity tests run from kernel module =========="
1560
1561 test_61() {
1562         f="$DIR/f61"
1563         dd if=/dev/zero of=$f bs=`page_size` count=1
1564         cancel_lru_locks OSC
1565         multiop $f OSMWUc || error
1566         sync
1567 }
1568 run_test 61 "mmap() writes don't make sync hang =========="
1569
1570 # bug 2330 - insufficient obd_match error checking causes LBUG
1571 test_62() {
1572         f="$DIR/f62"
1573         echo foo > $f
1574         cancel_lru_locks OSC
1575         echo 0x405 > /proc/sys/lustre/fail_loc
1576         cat $f && error # expect -EIO
1577         multiop $f Owc && error
1578         echo 0 > /proc/sys/lustre/fail_loc
1579 }
1580 run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
1581
1582 # bug 2319 - osic_wait() interrupted causes crash because of invalid waitq.
1583 test_63() {
1584         MAX_DIRTY_MB=`cat /proc/fs/lustre/osc/*/max_dirty_mb | head -1`
1585         for i in /proc/fs/lustre/osc/*/max_dirty_mb ; do
1586                 echo 0 > $i
1587         done
1588         for i in `seq 10` ; do
1589                 dd if=/dev/zero of=$DIR/f63 bs=8k &
1590                 sleep 5
1591                 kill $!
1592                 sleep 1
1593         done
1594
1595         for i in /proc/fs/lustre/osc/*/max_dirty_mb ; do
1596                 echo $MAX_DIRTY_MB > $i
1597         done
1598         true
1599 }
1600 run_test 63 "Verify osic_wait interruption does not crash ======"
1601
1602 # on the LLNL clusters, runas will still pick up root's $TMP settings,
1603 # which will not be writable for the runas user, and then you get a CVS
1604 # error message with a corrupt path string (CVS bug) and panic.
1605 # We're not using much space, so just stick it in /tmp, which is safe.
1606 OLDTMPDIR=$TMPDIR
1607 OLDTMP=$TMP
1608 TMPDIR=/tmp
1609 TMP=/tmp
1610 OLDHOME=$HOME
1611 [ $RUNAS_ID -ne $UID ] && HOME=/tmp
1612
1613 test_99a() {
1614         mkdir -p $DIR/d99cvsroot
1615         chown $RUNAS_ID $DIR/d99cvsroot
1616         $RUNAS cvs -d $DIR/d99cvsroot init || error
1617 }
1618 run_test 99a "cvs init ========================================="
1619
1620 test_99b() {
1621         [ ! -d $DIR/d99cvsroot ] && run_one 99a
1622         cd /etc/init.d
1623         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" d99reposname vtag rtag
1624 }
1625 run_test 99b "cvs import ======================================="
1626
1627 test_99c() {
1628         [ ! -d $DIR/d99cvsroot ] && run_one 99b
1629         cd $DIR
1630         mkdir -p $DIR/d99reposname
1631         chown $RUNAS_ID $DIR/d99reposname
1632         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
1633 }
1634 run_test 99c "cvs checkout ====================================="
1635
1636 test_99d() {
1637         [ ! -d $DIR/d99cvsroot ] && run_one 99c
1638         cd $DIR/d99reposname
1639         $RUNAS touch foo99
1640         $RUNAS cvs add -m 'addmsg' foo99
1641 }
1642 run_test 99d "cvs add =========================================="
1643
1644 test_99e() {
1645         [ ! -d $DIR/d99cvsroot ] && run_one 99c
1646         cd $DIR/d99reposname
1647         $RUNAS cvs update
1648 }
1649 run_test 99e "cvs update ======================================="
1650
1651 test_99f() {
1652         [ ! -d $DIR/d99cvsroot ] && run_one 99d
1653         cd $DIR/d99reposname
1654         $RUNAS cvs commit -m 'nomsg' foo99
1655 }
1656 run_test 99f "cvs commit ======================================="
1657
1658 TMPDIR=$OLDTMPDIR
1659 TMP=$OLDTMP
1660 HOME=$OLDHOME
1661
1662 log "cleanup: ======================================================"
1663 if [ "`mount | grep ^$NAME`" ]; then
1664         rm -rf $DIR/[Rdfs][1-9]*
1665         if [ "$I_MOUNTED" = "yes" ]; then
1666                 sh llmountcleanup.sh || error
1667         fi
1668 fi
1669
1670 echo '=========================== finished ==============================='
1671 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true