Whamcloud - gitweb
b=5881
[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 tests:
11 # skipped test: 
12 # - 51b 51c depend on used kernel
13 #   more than only LOV EAs
14 # - 65h (default stripe inheritance) is not implemented for LMV 
15 #   configurations. Will be done in second phase of collibri.
16
17 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"51b 51c 65h"}
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
19
20 [ "$ALWAYS_EXCEPT$EXCEPT" ] && echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
21
22 SRCDIR=`dirname $0`
23 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
24 export SECURITY=${SECURITY:-"null"}
25
26 TMP=${TMP:-/tmp}
27 FSTYPE=${FSTYPE:-ext3}
28
29 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
30 CREATETEST=${CREATETEST:-createtest}
31 LFS=${LFS:-lfs}
32 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
33 LFIND=${LFIND:-"$LFS find"}
34 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
35 LCTL=${LCTL:-lctl}
36 MCREATE=${MCREATE:-mcreate}
37 OPENFILE=${OPENFILE:-openfile}
38 OPENUNLINK=${OPENUNLINK:-openunlink}
39 TOEXCL=${TOEXCL:-toexcl}
40 TRUNCATE=${TRUNCATE:-truncate}
41 MUNLINK=${MUNLINK:-munlink}
42 SOCKETSERVER=${SOCKETSERVER:-socketserver}
43 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
44 IOPENTEST1=${IOPENTEST1:-iopentest1}
45 IOPENTEST2=${IOPENTEST2:-iopentest2}
46 MEMHOG=${MEMHOG:-memhog}
47
48 . krb5_env.sh
49
50 if [ $UID -ne 0 ]; then
51         RUNAS_ID="$UID"
52         RUNAS=""
53 else
54         RUNAS_ID=${RUNAS_ID:-500}
55         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
56 fi
57
58 if [ `using_krb5_sec $SECURITY` == 'y' ] ; then
59     start_krb5_kdc || exit 1
60     if [ $RUNAS_ID -ne $UID ]; then
61         $RUNAS ./krb5_refresh_cache.sh || exit 2
62     fi
63 fi
64
65 export NAME=${NAME:-local}
66
67 SAVE_PWD=$PWD
68
69 clean() {
70         echo -n "cln.."
71         sh llmountcleanup.sh > /dev/null || exit 20
72         I_MOUNTED=no
73 }
74 CLEAN=${CLEAN:-:}
75
76 start() {
77         echo -n "mnt.."
78         sh llrmount.sh > /dev/null || exit 10
79         I_MOUNTED=yes
80         echo "done"
81 }
82 START=${START:-}
83
84 log() {
85         echo "$*"
86         lctl mark "$*" 2> /dev/null || true
87 }
88
89 trace() {
90         log "STARTING: $*"
91         strace -o $TMP/$1.strace -ttt $*
92         RC=$?
93         log "FINISHED: $*: rc $RC"
94         return 1
95 }
96 TRACE=${TRACE:-""}
97
98 check_kernel_version() {
99         VERSION_FILE=/proc/fs/lustre/kernel_version
100         WANT_VER=$1
101         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
102         GOT_VER=`cat $VERSION_FILE`
103         [ $GOT_VER -ge $WANT_VER ] && return 0
104         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
105         return 1
106 }
107
108 run_one() {
109         if ! mount | grep -q $DIR; then
110                 $START
111         fi
112         BEFORE=`date +%s`
113         log "== test $1: $2= `date +%H:%M:%S` ($BEFORE)"
114         export TESTNAME=test_$1
115         test_$1 || error "test_$1: exit with rc=$?"
116         unset TESTNAME
117         pass "($((`date +%s` - $BEFORE))s)"
118         cd $SAVE_PWD
119         $CLEAN
120 }
121
122 build_test_filter() {
123         for O in $ONLY; do
124             eval ONLY_${O}=true
125         done
126         for E in $EXCEPT $ALWAYS_EXCEPT; do
127             eval EXCEPT_${E}=true
128         done
129 }
130
131 _basetest() {
132         echo $*
133 }
134
135 basetest() {
136         IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
137 }
138
139 run_test() {
140          base=`basetest $1`
141          if [ "$ONLY" ]; then
142                  testname=ONLY_$1
143                  if [ ${!testname}x != x ]; then
144                         run_one $1 "$2"
145                         return $?
146                  fi
147                  testname=ONLY_$base
148                  if [ ${!testname}x != x ]; then
149                          run_one $1 "$2"
150                          return $?
151                  fi
152                  echo -n "."
153                  return 0
154         fi
155         testname=EXCEPT_$1
156         if [ ${!testname}x != x ]; then
157                  echo "skipping excluded test $1"
158                  return 0
159         fi
160         testname=EXCEPT_$base
161         if [ ${!testname}x != x ]; then
162                  echo "skipping excluded test $1 (base $base)"
163                  return 0
164         fi
165         run_one $1 "$2"
166         return $?
167 }
168
169 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
170
171 error() { 
172         log "FAIL: $@"
173         if [ "$SANITYLOG" ]; then
174                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
175         else
176                 exit 1
177         fi
178 }
179
180 pass() { 
181         echo PASS $@
182 }
183
184 MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
185 if [ -z "$MOUNT" ]; then
186         sh llmount.sh
187         MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
188         [ -z "$MOUNT" ] && error "NAME=$NAME not mounted"
189         I_MOUNTED=yes
190 fi
191
192 [ `echo $MOUNT | wc -w` -gt 1 ] && error "NAME=$NAME mounted more than once"
193
194 DIR=${DIR:-$MOUNT}
195 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
196
197 OSTCOUNT=`cat /proc/fs/lustre/llite/fs0/lov/numobd`
198 STRIPECOUNT=`cat /proc/fs/lustre/llite/fs0/lov/stripecount`
199 STRIPESIZE=`cat /proc/fs/lustre/llite/fs0/lov/stripesize`
200 ORIGFREE=`cat /proc/fs/lustre/llite/fs0/lov/kbytesavail`
201 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
202
203 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
204 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
205 rm -rf $DIR/[Rdfs][1-9]*
206
207 build_test_filter
208
209 echo preparing for tests involving mounts
210 EXT2_DEV=${EXT2_DEV:-/tmp/SANITY.LOOP}
211 touch $EXT2_DEV
212 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
213
214 umask 077
215
216 test_0() {
217         touch $DIR/f
218         $CHECKSTAT -t file $DIR/f || error
219         rm $DIR/f
220         $CHECKSTAT -a $DIR/f || error
221 }
222 run_test 0 "touch .../f ; rm .../f ============================="
223
224 test_0b() {
225        chmod 0755 $DIR || error
226        $CHECKSTAT -p 0755 $DIR || error
227 }
228 run_test 0b "chmod 0755 $DIR ============================="
229
230
231 test_1a() {
232         mkdir $DIR/d1
233         mkdir $DIR/d1/d2
234         $CHECKSTAT -t dir $DIR/d1/d2 || error
235 }
236 run_test 1a "mkdir .../d1; mkdir .../d1/d2 ====================="
237
238 test_1b() {
239         rmdir $DIR/d1/d2
240         rmdir $DIR/d1
241         $CHECKSTAT -a $DIR/d1 || error
242 }
243 run_test 1b "rmdir .../d1/d2; rmdir .../d1 ====================="
244
245 test_2a() {
246         mkdir $DIR/d2
247         touch $DIR/d2/f
248         $CHECKSTAT -t file $DIR/d2/f || error
249 }
250 run_test 2a "mkdir .../d2; touch .../d2/f ======================"
251
252 test_2b() {
253         rm -r $DIR/d2
254         $CHECKSTAT -a $DIR/d2 || error
255 }
256 run_test 2b "rm -r .../d2; checkstat .../d2/f ======================"
257
258 test_3a() {
259         mkdir $DIR/d3
260         $CHECKSTAT -t dir $DIR/d3 || error
261 }
262 run_test 3a "mkdir .../d3 ======================================"
263
264 test_3b() {
265         if [ ! -d $DIR/d3 ]; then
266                 mkdir $DIR/d3
267         fi
268         touch $DIR/d3/f
269         $CHECKSTAT -t file $DIR/d3/f || error
270 }
271 run_test 3b "touch .../d3/f ===================================="
272
273 test_3c() {
274         rm -r $DIR/d3
275         $CHECKSTAT -a $DIR/d3 || error
276 }
277 run_test 3c "rm -r .../d3 ======================================"
278
279 test_4a() {
280         mkdir $DIR/d4
281         $CHECKSTAT -t dir $DIR/d4 || error
282 }
283 run_test 4a "mkdir .../d4 ======================================"
284
285 test_4b() {
286         if [ ! -d $DIR/d4 ]; then
287                 mkdir $DIR/d4
288         fi
289         mkdir $DIR/d4/d2
290         $CHECKSTAT -t dir $DIR/d4/d2 || error
291 }
292 run_test 4b "mkdir .../d4/d2 ==================================="
293
294 test_5() {
295         mkdir $DIR/d5
296         mkdir $DIR/d5/d2
297         chmod 0707 $DIR/d5/d2
298         $CHECKSTAT -t dir -p 0707 $DIR/d5/d2 || error
299 }
300 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
301
302 test_6a() {
303         touch $DIR/f6a
304         chmod 0666 $DIR/f6a || error
305         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
306 }
307 run_test 6a "touch .../f6a; chmod .../f6a ======================"
308
309 test_6b() {
310         [ $RUNAS_ID -eq $UID ] && echo "skipping test 6b" && return
311         if [ ! -f $DIR/f6a ]; then
312                 touch $DIR/f6a
313                 chmod 0666 $DIR/f6a
314         fi
315         $RUNAS chmod 0444 $DIR/f6a && error
316         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
317 }
318 run_test 6b "$RUNAS chmod .../f6a (should return error) =="
319
320 test_6c() {
321         [ $RUNAS_ID -eq $UID ] && echo "skipping test 6c" && return
322         touch $DIR/f6c
323         chown $RUNAS_ID $DIR/f6c || error
324         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
325 }
326 run_test 6c "touch .../f6c; chown .../f6c ======================"
327
328 test_6d() {
329         [ $RUNAS_ID -eq $UID ] && echo "skipping test 6d" && return
330         if [ ! -f $DIR/f6c ]; then
331                 touch $DIR/f6c
332                 chown $RUNAS_ID $DIR/f6c
333         fi
334         $RUNAS chown $UID $DIR/f6c && error
335         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
336 }
337 run_test 6d "$RUNAS chown .../f6c (should return error) =="
338
339 test_6e() {
340         [ $RUNAS_ID -eq $UID ] && echo "skipping test 6e" && return
341         touch $DIR/f6e
342         chgrp $RUNAS_ID $DIR/f6e || error
343         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
344 }
345 run_test 6e "touch .../f6e; chgrp .../f6e ======================"
346
347 test_6f() {
348         [ $RUNAS_ID -eq $UID ] && echo "skipping test 6f" && return
349         if [ ! -f $DIR/f6e ]; then
350                 touch $DIR/f6e
351                 chgrp $RUNAS_ID $DIR/f6e
352         fi
353         $RUNAS chgrp $UID $DIR/f6e && error
354         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
355 }
356 run_test 6f "$RUNAS chgrp .../f6e (should return error) =="
357
358 test_6g() {
359         [ $RUNAS_ID -eq $UID ] && echo "skipping test 6g" && return
360         mkdir $DIR/d6g || error
361         chmod 777 $DIR/d6g || error
362         $RUNAS mkdir $DIR/d6g/d || error
363         chmod g+s $DIR/d6g/d || error
364         mkdir $DIR/d6g/d/subdir
365         $CHECKSTAT -g \#$RUNAS_ID $DIR/d6g/d/subdir || error
366 }
367 run_test 6g "Is new dir in sgid dir inheriting group?"
368
369 test_7a() {
370         mkdir $DIR/d7
371         $MCREATE $DIR/d7/f
372         chmod 0666 $DIR/d7/f
373         $CHECKSTAT -t file -p 0666 $DIR/d7/f || error
374 }
375 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
376
377 test_7b() {
378         if [ ! -d $DIR/d7 ]; then
379                 mkdir $DIR/d7
380         fi
381         $MCREATE $DIR/d7/f2
382         echo -n foo > $DIR/d7/f2
383         [ "`cat $DIR/d7/f2`" = "foo" ] || error
384         $CHECKSTAT -t file -s 3 $DIR/d7/f2 || error
385 }
386 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
387
388 test_8() {
389         mkdir $DIR/d8
390         touch $DIR/d8/f
391         chmod 0666 $DIR/d8/f
392         $CHECKSTAT -t file -p 0666 $DIR/d8/f || error
393 }
394 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
395
396 test_9() {
397         mkdir $DIR/d9
398         mkdir $DIR/d9/d2
399         mkdir $DIR/d9/d2/d3
400         $CHECKSTAT -t dir $DIR/d9/d2/d3 || error
401 }
402 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
403
404 test_10() {
405         mkdir $DIR/d10
406         mkdir $DIR/d10/d2
407         touch $DIR/d10/d2/f
408         $CHECKSTAT -t file $DIR/d10/d2/f || error
409 }
410 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
411
412 test_11() {
413         mkdir $DIR/d11
414         mkdir $DIR/d11/d2
415         chmod 0666 $DIR/d11/d2
416         chmod 0705 $DIR/d11/d2
417         $CHECKSTAT -t dir -p 0705 $DIR/d11/d2 || error
418 }
419 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
420
421 test_12() {
422         mkdir $DIR/d12
423         touch $DIR/d12/f
424         chmod 0666 $DIR/d12/f
425         chmod 0654 $DIR/d12/f
426         $CHECKSTAT -t file -p 0654 $DIR/d12/f || error
427 }
428 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
429
430 test_13() {
431         mkdir $DIR/d13
432         dd if=/dev/zero of=$DIR/d13/f count=10
433         >  $DIR/d13/f
434         $CHECKSTAT -t file -s 0 $DIR/d13/f || error
435 }
436 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
437
438 test_14() {
439         mkdir $DIR/d14
440         touch $DIR/d14/f
441         rm $DIR/d14/f
442         $CHECKSTAT -a $DIR/d14/f || error
443 }
444 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
445
446 test_15() {
447         mkdir $DIR/d15
448         touch $DIR/d15/f
449         mv $DIR/d15/f $DIR/d15/f2
450         $CHECKSTAT -t file $DIR/d15/f2 || error
451 }
452 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
453
454 test_16() {
455         mkdir $DIR/d16
456         touch $DIR/d16/f
457         rm -rf $DIR/d16/f
458         $CHECKSTAT -a $DIR/d16/f || error
459 }
460 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
461
462 test_17a() {
463         mkdir -p $DIR/d17
464         touch $DIR/d17/f
465         ln -s $DIR/d17/f $DIR/d17/l-exist
466         ls -l $DIR/d17
467         $CHECKSTAT -l $DIR/d17/f $DIR/d17/l-exist || error
468         $CHECKSTAT -f -t f $DIR/d17/l-exist || error
469         rm -f $DIR/l-exist
470         $CHECKSTAT -a $DIR/l-exist || error
471 }
472 run_test 17a "symlinks: create, remove (real) =================="
473
474 test_17b() {
475         mkdir -p $DIR/d17
476         ln -s no-such-file $DIR/d17/l-dangle
477         ls -l $DIR/d17
478         $CHECKSTAT -l no-such-file $DIR/d17/l-dangle || error
479         $CHECKSTAT -fa $DIR/d17/l-dangle || error
480         rm -f $DIR/l-dangle
481         $CHECKSTAT -a $DIR/l-dangle || error
482 }
483 run_test 17b "symlinks: create, remove (dangling) =============="
484
485 test_17c() { # bug 3440 - don't save failed open RPC for replay
486         mkdir -p $DIR/d17
487         ln -s foo $DIR/d17/f17c
488         cat $DIR/d17/f17c && error "opened non-existent symlink" || true
489 }
490 run_test 17c "symlinks: open dangling (should return error) ===="
491
492 test_17d() {
493         mkdir -p $DIR/d17
494         ln -s foo $DIR/d17/f17d
495         touch $DIR/d17/f17d || error "creating to new symlink"
496 }
497 run_test 17d "symlinks: create dangling ========================"
498
499 test_18() {
500         touch $DIR/f
501         ls $DIR || error
502 }
503 run_test 18 "touch .../f ; ls ... =============================="
504
505 test_19a() {
506         touch $DIR/f19
507         ls -l $DIR
508         rm $DIR/f19
509         $CHECKSTAT -a $DIR/f19 || error
510 }
511 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
512
513 test_19b() {
514         ls -l $DIR/f19 && error || true
515 }
516 run_test 19b "ls -l .../f19 (should return error) =============="
517
518 test_19c() {
519         [ $RUNAS_ID -eq $UID ] && echo "skipping test 19c" && return
520         $RUNAS touch $DIR/f19 && error || true
521 }
522 run_test 19c "$RUNAS touch .../f19 (should return error) =="
523
524 test_19d() {
525         cat $DIR/f19 && error || true
526 }
527 run_test 19d "cat .../f19 (should return error) =============="
528
529 test_20() {
530         touch $DIR/f
531         rm $DIR/f
532         log "1 done"
533         touch $DIR/f
534         rm $DIR/f
535         log "2 done"
536         touch $DIR/f
537         rm $DIR/f
538         log "3 done"
539         $CHECKSTAT -a $DIR/f || error
540 }
541 run_test 20 "touch .../f ; ls -l ... ==========================="
542
543 test_21() {
544         mkdir $DIR/d21
545         [ -f $DIR/d21/dangle ] && rm -f $DIR/d21/dangle
546         ln -s dangle $DIR/d21/link
547         echo foo >> $DIR/d21/link
548         cat $DIR/d21/dangle
549         $CHECKSTAT -t link $DIR/d21/link || error
550         $CHECKSTAT -f -t file $DIR/d21/link || error
551 }
552 run_test 21 "write to dangling link ============================"
553
554 test_22() {
555         mkdir $DIR/d22
556         chown $RUNAS_ID $DIR/d22
557         # Tar gets pissy if it can't access $PWD *sigh*
558         (cd /tmp;
559         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
560         $RUNAS tar xfC - $DIR/d22)
561         ls -lR $DIR/d22/etc
562         $CHECKSTAT -t dir $DIR/d22/etc || error
563         $CHECKSTAT -u \#$RUNAS_ID $DIR/d22/etc || error
564 }
565 run_test 22 "unpack tar archive as non-root user ==============="
566
567 test_23() {
568         mkdir $DIR/d23
569         $TOEXCL $DIR/d23/f23
570         $TOEXCL -e $DIR/d23/f23 || error
571 }
572 run_test 23 "O_CREAT|O_EXCL in subdir =========================="
573
574 test_24a() {
575         echo '== rename sanity =============================================='
576         echo '-- same directory rename'
577         mkdir $DIR/R1
578         touch $DIR/R1/f
579         mv $DIR/R1/f $DIR/R1/g
580         $CHECKSTAT -t file $DIR/R1/g || error
581 }
582 run_test 24a "touch .../R1/f; rename .../R1/f .../R1/g ========="
583
584 test_24b() {
585         mkdir $DIR/R2
586         touch $DIR/R2/{f,g}
587         mv $DIR/R2/f $DIR/R2/g
588         $CHECKSTAT -a $DIR/R2/f || error
589         $CHECKSTAT -t file $DIR/R2/g || error
590 }
591 run_test 24b "touch .../R2/{f,g}; rename .../R2/f .../R2/g ====="
592
593 test_24c() {
594         mkdir $DIR/R3
595         mkdir $DIR/R3/f
596         mv $DIR/R3/f $DIR/R3/g
597         $CHECKSTAT -a $DIR/R3/f || error
598         $CHECKSTAT -t dir $DIR/R3/g || error
599 }
600 run_test 24c "mkdir .../R3/f; rename .../R3/f .../R3/g ========="
601
602 test_24d() {
603         mkdir $DIR/R4
604         mkdir $DIR/R4/{f,g}
605         mrename $DIR/R4/f $DIR/R4/g
606         $CHECKSTAT -a $DIR/R4/f || error
607         $CHECKSTAT -t dir $DIR/R4/g || error
608 }
609 run_test 24d "mkdir .../R4/{f,g}; rename .../R4/f .../R4/g ====="
610
611 test_24e() {
612         echo '-- cross directory renames --' 
613         mkdir $DIR/R5{a,b}
614         touch $DIR/R5a/f
615         mv $DIR/R5a/f $DIR/R5b/g
616         $CHECKSTAT -a $DIR/R5a/f || error
617         $CHECKSTAT -t file $DIR/R5b/g || error
618 }
619 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
620
621 test_24f() {
622         mkdir $DIR/R6{a,b}
623         touch $DIR/R6a/f $DIR/R6b/g
624         mv $DIR/R6a/f $DIR/R6b/g
625         $CHECKSTAT -a $DIR/R6a/f || error
626         $CHECKSTAT -t file $DIR/R6b/g || error
627 }
628 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
629
630 test_24g() {
631         mkdir $DIR/R7{a,b}
632         mkdir $DIR/R7a/d
633         mv $DIR/R7a/d $DIR/R7b/e
634         $CHECKSTAT -a $DIR/R7a/d || error
635         $CHECKSTAT -t dir $DIR/R7b/e || error
636 }
637 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R5b/e ======"
638
639 test_24h() {
640         mkdir $DIR/R8{a,b}
641         mkdir $DIR/R8a/d $DIR/R8b/e
642         mrename $DIR/R8a/d $DIR/R8b/e
643         $CHECKSTAT -a $DIR/R8a/d || error
644         $CHECKSTAT -t dir $DIR/R8b/e || error
645 }
646 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
647
648 test_24i() {
649         echo "-- rename error cases"
650         mkdir $DIR/R9
651         mkdir $DIR/R9/a
652         touch $DIR/R9/f
653         mrename $DIR/R9/f $DIR/R9/a
654         $CHECKSTAT -t file $DIR/R9/f || error
655         $CHECKSTAT -t dir  $DIR/R9/a || error
656         $CHECKSTAT -a file $DIR/R9/a/f || error
657 }
658 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
659
660 test_24j() {
661         mkdir $DIR/R10
662         mrename $DIR/R10/f $DIR/R10/g
663         $CHECKSTAT -t dir $DIR/R10 || error
664         $CHECKSTAT -a $DIR/R10/f || error
665         $CHECKSTAT -a $DIR/R10/g || error
666 }
667 run_test 24j "source does not exist ============================" 
668
669 test_24k() {
670         mkdir $DIR/R11a $DIR/R11a/d
671         touch $DIR/R11a/f
672         mv $DIR/R11a/f $DIR/R11a/d
673         $CHECKSTAT -a $DIR/R11a/f || error
674         $CHECKSTAT -t file $DIR/R11a/d/f || error
675 }
676 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
677
678 # bug 2429 - rename foo foo foo creates invalid file
679 test_24l() {
680         f="$DIR/f24l"
681         multiop $f OcNs || error
682 }
683 run_test 24l "Renaming a file to itself ========================"
684
685 test_24m() {
686         f="$DIR/f24m"
687         multiop $f OcLN ${f}2 ${f}2 || error
688 }
689 run_test 24m "Renaming a file to a hard link to itself ========="
690
691 test_24n() {
692     f="$DIR/f24n"
693     # this stats the old file after it was renamed, so it should fail
694     touch ${f}
695     $CHECKSTAT ${f}
696     mv ${f} ${f}.rename
697     $CHECKSTAT ${f}.rename
698     $CHECKSTAT -a ${f}
699 }
700 run_test 24n "Statting the old file after renameing (Posix rename 2)"
701
702 test_24o() {
703         check_kernel_version 37 || return 0
704         rename_many -s random -v -n 10 $DIR
705 }
706 run_test 24o "rename of files during htree split ==============="
707
708 test_24p() {
709        mkdir $DIR/R12{a,b}
710        DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
711        mrename $DIR/R12a $DIR/R12b
712        $CHECKSTAT -a $DIR/R12a || error
713        $CHECKSTAT -t dir $DIR/R12b || error
714        DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
715        [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
716 }
717 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
718
719 test_24q() {
720        mkdir $DIR/R13{a,b}
721        DIRINO=`ls -lid $DIR/R13a | awk '{ print $1 }'`
722        multiop $DIR/R13b D_c &
723        MULTIPID=$!
724
725        mrename $DIR/R13a $DIR/R13b
726        $CHECKSTAT -a $DIR/R13a || error
727        $CHECKSTAT -t dir $DIR/R13b || error
728        DIRINO2=`ls -lid $DIR/R13b | awk '{ print $1 }'`
729        [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
730        kill -USR1 $MULTIPID
731        wait $MULTIPID || error "multiop close failed"
732 }
733 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
734
735 test_24r() { #bug 3789
736        mkdir $DIR/R14a $DIR/R14a/b
737        mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
738        $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
739        $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
740 }
741 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
742
743 test_24s() {
744        mkdir $DIR/R15a $DIR/R15a/b $DIR/R15a/b/c
745        mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
746        $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
747        $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
748 }
749 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
750 test_24t() {
751        mkdir $DIR/R16a $DIR/R16a/b $DIR/R16a/b/c
752        mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
753        $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
754        $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
755 }
756 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
757
758 test_25a() {
759         echo '== symlink sanity ============================================='
760         mkdir $DIR/d25
761         ln -s d25 $DIR/s25
762         touch $DIR/s25/foo || error
763 }
764 run_test 25a "create file in symlinked directory ==============="
765
766 test_25b() {
767         [ ! -d $DIR/d25 ] && test_25a
768         $CHECKSTAT -t file $DIR/s25/foo || error
769 }
770 run_test 25b "lookup file in symlinked directory ==============="
771
772 test_26a() {
773         mkdir $DIR/d26
774         mkdir $DIR/d26/d26-2
775         ln -s d26/d26-2 $DIR/s26
776         touch $DIR/s26/foo || error
777 }
778 run_test 26a "multiple component symlink ======================="
779
780 test_26b() {
781         mkdir -p $DIR/d26b/d26-2
782         ln -s d26b/d26-2/foo $DIR/s26-2
783         touch $DIR/s26-2 || error
784 }
785 run_test 26b "multiple component symlink at end of lookup ======"
786
787 test_26c() {
788         mkdir $DIR/d26.2
789         touch $DIR/d26.2/foo
790         ln -s d26.2 $DIR/s26.2-1
791         ln -s s26.2-1 $DIR/s26.2-2
792         ln -s s26.2-2 $DIR/s26.2-3
793         chmod 0666 $DIR/s26.2-3/foo
794 }
795 run_test 26c "chain of symlinks ================================"
796
797 # recursive symlinks (bug 439)
798 test_26d() {
799         ln -s d26-3/foo $DIR/d26-3
800 }
801 run_test 26d "create multiple component recursive symlink ======"
802
803 test_26e() {
804         [ ! -h $DIR/d26-3 ] && test_26d
805         rm $DIR/d26-3
806 }
807 run_test 26e "unlink multiple component recursive symlink ======"
808
809 test_27a() {
810         echo '== stripe sanity =============================================='
811         mkdir $DIR/d27
812         $LSTRIPE $DIR/d27/f0 65536 0 1 || error "lstripe failed"
813         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
814         pass
815         log "== test_27b: write to one stripe file ========================="
816         cp /etc/hosts $DIR/d27/f0 || error
817 }
818 run_test 27a "one stripe file =================================="
819
820 test_27c() {
821         [ "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
822         if [ ! -d $DIR/d27 ]; then
823                 mkdir $DIR/d27
824         fi
825         $LSTRIPE $DIR/d27/f01 65536 0 2 || error "lstripe failed"
826         [ `$LFIND $DIR/d27/f01 --quiet | grep [^[:blank:]*] | wc -l` -eq 2 ] ||
827                 error "two-stripe file doesn't have two stripes"
828         pass
829         log "== test_27d: write to two stripe file file f01 ================"
830         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
831 }
832 run_test 27c "create two stripe file f01 ======================="
833
834 test_27d() {
835         if [ ! -d $DIR/d27 ]; then
836                 mkdir $DIR/d27
837         fi
838         $LSTRIPE $DIR/d27/fdef 0 -1 0 || error "lstripe failed"
839         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
840         #dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
841 }
842 run_test 27d "create file with default settings ================"
843
844 test_27e() {
845         if [ ! -d $DIR/d27 ]; then
846                 mkdir $DIR/d27
847         fi
848         $LSTRIPE $DIR/d27/f12 65536 0 2 || error "lstripe failed"
849         $LSTRIPE $DIR/d27/f12 65536 0 2 && error "lstripe succeeded twice"
850         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
851 }
852 run_test 27e "lstripe existing file (should return error) ======"
853
854 test_27f() {
855         if [ ! -d $DIR/d27 ]; then
856                 mkdir $DIR/d27
857         fi
858         $LSTRIPE $DIR/d27/fbad 100 0 1 && error "lstripe failed"
859         dd if=/dev/zero of=$DIR/d27/f12 bs=4k count=4 || error "dd failed"
860         $LFIND $DIR/d27/fbad || error "lfind failed"
861
862 }
863 run_test 27f "lstripe with bad stripe size (should return error)"
864
865 test_27g() {
866         if [ ! -d $DIR/d27 ]; then
867                 mkdir $DIR/d27
868         fi
869         $MCREATE $DIR/d27/fnone || error "mcreate failed"
870         pass
871         log "== test 27h: lfind with no objects ============================"
872         $LFIND $DIR/d27/fnone 2>&1 | grep "no stripe info" || error "has object"
873         pass
874         log "== test 27i: lfind with some objects =========================="
875         touch $DIR/d27/fsome || error "touch failed"
876         $LFIND $DIR/d27/fsome | grep obdidx || error "missing objects"
877
878 }
879 run_test 27g "test lfind ======================================="
880
881 test_27j() {
882         if [ ! -d $DIR/d27 ]; then
883                 mkdir $DIR/d27
884         fi
885         $LSTRIPE $DIR/d27/f27j 65536 $OSTCOUNT 1 && error "lstripe failed"||true
886 }
887 run_test 27j "lstripe with bad stripe offset (should return error)"
888
889 test_27k() { # bug 2844
890         FILE=$DIR/d27/f27k
891         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
892         [ ! -d $DIR/d27 ] && mkdir -p $DIR/d27
893         $LSTRIPE $FILE 67108864 -1 0 || error "lstripe failed"
894         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
895         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
896         dd if=/dev/zero of=$FILE bs=4k count=1
897         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
898         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
899 }
900 run_test 27k "limit i_blksize for broken user apps ============="
901
902 test_27l() {
903         mcreate $DIR/f27l || error "creating file"
904         $RUNAS $LSTRIPE $DIR/f27l 65536 -1 1 && \
905                 error "lstripe should have failed" || true
906 }
907 run_test 27l "check setstripe permissions (should return error)"
908
909 test_27m() {
910         [ "$OSTCOUNT" -lt "2" ] && echo "skipping out-of-space test on OST0" && return
911         if [ $ORIGFREE -gt $MAXFREE ]; then
912                 echo "skipping out-of-space test on OST0"
913                 return
914         fi
915         mkdir -p $DIR/d27
916         $LSTRIPE $DIR/d27/f27m_1 0 0 1
917         dd if=/dev/zero of=$DIR/d27/f27m_1 bs=1024 count=$MAXFREE && \
918                 error "dd should fill OST0"
919         i=2
920         while $LSTRIPE $DIR/d27/f27m_$i 0 0 1 ; do
921                 i=`expr $i + 1`
922                 [ $i -gt 256 ] && break
923         done
924         i=`expr $i + 1`
925         touch $DIR/d27/f27m_$i
926         [ `$LFIND $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
927                 error "OST0 was full but new created file still use it"
928         i=`expr $i + 1`
929         touch $DIR/d27/f27m_$i
930         [ `$LFIND $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
931                 error "OST0 was full but new created file still use it"
932         rm $DIR/d27/f27m_1
933 }
934 run_test 27m "create file while OST0 was full =================="
935
936 test_28() {
937         mkdir $DIR/d28
938         $CREATETEST $DIR/d28/ct || error
939 }
940 run_test 28 "create/mknod/mkdir with bad file types ============"
941
942 cancel_lru_locks() {
943         for d in /proc/fs/lustre/ldlm/namespaces/$1*; do
944                 echo clear > $d/lru_size
945         done
946         grep [0-9] /proc/fs/lustre/ldlm/namespaces/$1*/lock_unused_count /dev/null
947 }
948
949 test_29() {
950         cancel_lru_locks MDC
951         mkdir $DIR/d29
952         touch $DIR/d29/foo
953         log 'first d29'
954         ls -l $DIR/d29
955         MDCDIR=${MDCDIR:-/proc/fs/lustre/ldlm/namespaces/MDC_*}
956         LOCKCOUNTORIG=`cat $MDCDIR/lock_count`
957         LOCKUNUSEDCOUNTORIG=`cat $MDCDIR/lock_unused_count`
958         log 'second d29'
959         ls -l $DIR/d29
960         log 'done'
961         LOCKCOUNTCURRENT=`cat $MDCDIR/lock_count`
962         LOCKUNUSEDCOUNTCURRENT=`cat $MDCDIR/lock_unused_count`
963         if [ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]; then
964                 echo "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
965                 error
966         fi
967         if [ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]; then
968                 echo "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
969                 error
970         fi
971 }
972 run_test 29 "IT_GETATTR regression  ============================"
973
974 test_30() {
975         cp `which ls` $DIR
976         $DIR/ls /
977         rm $DIR/ls
978 }
979 run_test 30 "run binary from Lustre (execve) ==================="
980
981 test_31a() {
982         $OPENUNLINK $DIR/f31 $DIR/f31 || error
983         $CHECKSTAT -a $DIR/f31 || error
984 }
985 run_test 31a "open-unlink file =================================="
986
987 test_31b() {
988         touch $DIR/f31 || error
989         ln $DIR/f31 $DIR/f31b || error
990         multiop $DIR/f31b Ouc || error
991         $CHECKSTAT -t file $DIR/f31 || error
992 }
993 run_test 31b "unlink file with multiple links while open ======="
994
995 test_31c() {
996         touch $DIR/f31 || error
997         ln $DIR/f31 $DIR/f31c || error
998         multiop $DIR/f31 O_uc &
999         MULTIPID=$!
1000         multiop $DIR/f31c Ouc
1001         usleep 500
1002         kill -USR1 $MULTIPID
1003         wait $MULTIPID
1004 }
1005 run_test 31c "open-unlink file with multiple links ============="
1006
1007 test_31d() {
1008         opendirunlink $DIR/d31d $DIR/d31d || error
1009         $CHECKSTAT -a $DIR/d31d || error
1010 }
1011 run_test 31d "remove of open directory ========================="
1012
1013 test_31e() { # bug 2904
1014         check_kernel_version 34 || return 0
1015         openfilleddirunlink $DIR/d31e || error
1016 }
1017 run_test 31e "remove of open non-empty directory ==============="
1018
1019 test_31f() { # bug 4554
1020         set -vx
1021         mkdir $DIR/d31f
1022         lfs setstripe $DIR/d31f 1048576 -1 1
1023         cp /etc/hosts $DIR/d31f
1024         ls -l $DIR/d31f
1025         lfs getstripe $DIR/d31f/hosts
1026         multiop $DIR/d31f D_c &
1027         MULTIPID=$!
1028
1029         sleep 1
1030
1031         rm -rv $DIR/d31f || error "first of $DIR/d31f"
1032         mkdir $DIR/d31f
1033         lfs setstripe $DIR/d31f 1048576 -1 1
1034         cp /etc/hosts $DIR/d31f
1035         ls -l $DIR/d31f
1036         lfs getstripe $DIR/d31f/hosts
1037         multiop $DIR/d31f D_c &
1038         MULTIPID2=$!
1039
1040         sleep 6
1041
1042         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
1043         wait $MULTIPID || error "first opendir $MULTIPID failed"
1044
1045         sleep 6
1046
1047         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
1048         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
1049         set +vx
1050 }
1051 run_test 31f "remove of open directory with open-unlink file ==="
1052
1053 test_32a() {
1054         echo "== more mountpoints and symlinks ================="
1055         [ -e $DIR/d32a ] && rm -fr $DIR/d32a
1056         mkdir -p $DIR/d32a/ext2-mountpoint 
1057         mount -t ext2 -o loop $EXT2_DEV $DIR/d32a/ext2-mountpoint || error
1058         $CHECKSTAT -t dir $DIR/d32a/ext2-mountpoint/.. || error  
1059         umount $DIR/d32a/ext2-mountpoint || error
1060 }
1061 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
1062
1063 test_32b() {
1064         [ -e $DIR/d32b ] && rm -fr $DIR/d32b
1065         mkdir -p $DIR/d32b/ext2-mountpoint 
1066         mount -t ext2 -o loop $EXT2_DEV $DIR/d32b/ext2-mountpoint || error
1067         ls -al $DIR/d32b/ext2-mountpoint/.. || error
1068         umount $DIR/d32b/ext2-mountpoint || error
1069 }
1070 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
1071  
1072 test_32c() {
1073         [ -e $DIR/d32c ] && rm -fr $DIR/d32c
1074         mkdir -p $DIR/d32c/ext2-mountpoint 
1075         mount -t ext2 -o loop $EXT2_DEV $DIR/d32c/ext2-mountpoint || error
1076         mkdir -p $DIR/d32c/d2/test_dir    
1077         $CHECKSTAT -t dir $DIR/d32c/ext2-mountpoint/../d2/test_dir || error
1078         umount $DIR/d32c/ext2-mountpoint || error
1079 }
1080 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
1081
1082 test_32d() {
1083         [ -e $DIR/d32d ] && rm -fr $DIR/d32d
1084         mkdir -p $DIR/d32d/ext2-mountpoint 
1085         mount -t ext2 -o loop $EXT2_DEV $DIR/d32d/ext2-mountpoint || error
1086         mkdir -p $DIR/d32d/d2/test_dir    
1087         ls -al $DIR/d32d/ext2-mountpoint/../d2/test_dir || error
1088         umount $DIR/d32d/ext2-mountpoint || error
1089 }
1090 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
1091
1092 test_32e() {
1093         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
1094         mkdir -p $DIR/d32e/tmp    
1095         TMP_DIR=$DIR/d32e/tmp       
1096         ln -s $DIR/d32e $TMP_DIR/symlink11 
1097         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1098         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
1099         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
1100 }
1101 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
1102
1103 test_32f() {
1104         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
1105         mkdir -p $DIR/d32f/tmp    
1106         TMP_DIR=$DIR/d32f/tmp       
1107         ln -s $DIR/d32f $TMP_DIR/symlink11 
1108         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1109         ls $DIR/d32f/tmp/symlink11  || error
1110         ls $DIR/d32f/symlink01 || error
1111 }
1112 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
1113
1114 test_32g() {
1115         [ -e $DIR/d32g ] && rm -fr $DIR/d32g
1116         [ -e $DIR/test_dir ] && rm -fr $DIR/test_dir
1117         mkdir -p $DIR/test_dir 
1118         mkdir -p $DIR/d32g/tmp    
1119         TMP_DIR=$DIR/d32g/tmp       
1120         ln -s $DIR/test_dir $TMP_DIR/symlink12 
1121         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1122         $CHECKSTAT -t link $DIR/d32g/tmp/symlink12 || error
1123         $CHECKSTAT -t link $DIR/d32g/symlink02 || error
1124         $CHECKSTAT -t dir -f $DIR/d32g/tmp/symlink12 || error
1125         $CHECKSTAT -t dir -f $DIR/d32g/symlink02 || error
1126 }
1127 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/test_dir"
1128
1129 test_32h() {
1130         [ -e $DIR/d32h ] && rm -fr $DIR/d32h
1131         [ -e $DIR/test_dir ] && rm -fr $DIR/test_dir
1132         mkdir -p $DIR/test_dir 
1133         mkdir -p $DIR/d32h/tmp    
1134         TMP_DIR=$DIR/d32h/tmp       
1135         ln -s $DIR/test_dir $TMP_DIR/symlink12 
1136         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1137         ls $DIR/d32h/tmp/symlink12 || error
1138         ls $DIR/d32h/symlink02  || error
1139 }
1140 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/test_dir"
1141
1142 test_32i() {
1143         [ -e $DIR/d32i ] && rm -fr $DIR/d32i
1144         mkdir -p $DIR/d32i/ext2-mountpoint 
1145         mount -t ext2 -o loop $EXT2_DEV $DIR/d32i/ext2-mountpoint || error
1146         touch $DIR/d32i/test_file
1147         $CHECKSTAT -t file $DIR/d32i/ext2-mountpoint/../test_file || error  
1148         umount $DIR/d32i/ext2-mountpoint || error
1149 }
1150 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
1151
1152 test_32j() {
1153         [ -e $DIR/d32j ] && rm -fr $DIR/d32j
1154         mkdir -p $DIR/d32j/ext2-mountpoint 
1155         mount -t ext2 -o loop $EXT2_DEV $DIR/d32j/ext2-mountpoint || error
1156         touch $DIR/d32j/test_file
1157         cat $DIR/d32j/ext2-mountpoint/../test_file || error
1158         umount $DIR/d32j/ext2-mountpoint || error
1159 }
1160 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
1161
1162 test_32k() {
1163         rm -fr $DIR/d32k
1164         mkdir -p $DIR/d32k/ext2-mountpoint 
1165         mount -t ext2 -o loop $EXT2_DEV $DIR/d32k/ext2-mountpoint  
1166         mkdir -p $DIR/d32k/d2
1167         touch $DIR/d32k/d2/test_file || error
1168         $CHECKSTAT -t file $DIR/d32k/ext2-mountpoint/../d2/test_file || error
1169         umount $DIR/d32k/ext2-mountpoint || error
1170 }
1171 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
1172
1173 test_32l() {
1174         rm -fr $DIR/d32l
1175         mkdir -p $DIR/d32l/ext2-mountpoint 
1176         mount -t ext2 -o loop $EXT2_DEV $DIR/d32l/ext2-mountpoint || error
1177         mkdir -p $DIR/d32l/d2
1178         touch $DIR/d32l/d2/test_file
1179         cat  $DIR/d32l/ext2-mountpoint/../d2/test_file || error
1180         umount $DIR/d32l/ext2-mountpoint || error
1181 }
1182 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
1183
1184 test_32m() {
1185         rm -fr $DIR/d32m
1186         mkdir -p $DIR/d32m/tmp    
1187         TMP_DIR=$DIR/d32m/tmp       
1188         ln -s $DIR $TMP_DIR/symlink11 
1189         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1190         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
1191         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
1192 }
1193 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
1194
1195 test_32n() {
1196         rm -fr $DIR/d32n
1197         mkdir -p $DIR/d32n/tmp    
1198         TMP_DIR=$DIR/d32n/tmp       
1199         ln -s $DIR $TMP_DIR/symlink11 
1200         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1201         ls -l $DIR/d32n/tmp/symlink11  || error
1202         ls -l $DIR/d32n/symlink01 || error
1203 }
1204 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
1205
1206 test_32o() {
1207         rm -fr $DIR/d32o
1208         rm -f $DIR/test_file
1209         touch $DIR/test_file 
1210         mkdir -p $DIR/d32o/tmp    
1211         TMP_DIR=$DIR/d32o/tmp       
1212         ln -s $DIR/test_file $TMP_DIR/symlink12 
1213         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1214         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
1215         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
1216         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
1217         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
1218 }
1219 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/test_file"
1220
1221 test_32p() {
1222     log 32p_1
1223         rm -fr $DIR/d32p
1224     log 32p_2
1225         rm -f $DIR/test_file
1226     log 32p_3
1227         touch $DIR/test_file 
1228     log 32p_4
1229         mkdir -p $DIR/d32p/tmp    
1230     log 32p_5
1231         TMP_DIR=$DIR/d32p/tmp       
1232     log 32p_6
1233         ln -s $DIR/test_file $TMP_DIR/symlink12 
1234     log 32p_7
1235         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1236     log 32p_8
1237         cat $DIR/d32p/tmp/symlink12 || error
1238     log 32p_9
1239         cat $DIR/d32p/symlink02 || error
1240     log 32p_10
1241 }
1242 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/test_file"
1243
1244 test_32q() {
1245         [ -e $DIR/d32q ] && rm -fr $DIR/d32q
1246         mkdir -p $DIR/d32q
1247         touch $DIR/d32q/under_the_mount
1248         mount -t ext2 -o loop $EXT2_DEV $DIR/d32q
1249         ls $DIR/d32q/under_the_mount && error || true
1250         umount $DIR/d32q || error
1251 }
1252 run_test 32q "stat follows mountpoints in Lustre (should return error)"
1253
1254 test_32r() {
1255         [ -e $DIR/d32r ] && rm -fr $DIR/d32r
1256         mkdir -p $DIR/d32r
1257         touch $DIR/d32r/under_the_mount
1258         mount -t ext2 -o loop $EXT2_DEV $DIR/d32r
1259         ls $DIR/d32r | grep -q under_the_mount && error || true
1260         umount $DIR/d32r || error
1261 }
1262 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
1263
1264 #   chmod 444 /mnt/lustre/somefile
1265 #   open(/mnt/lustre/somefile, O_RDWR)
1266 #   Should return -1
1267 test_33() {
1268         rm -f $DIR/test_33_file
1269         touch $DIR/test_33_file
1270         chmod 444 $DIR/test_33_file
1271         chown $RUNAS_ID $DIR/test_33_file
1272         log 33_1
1273         $RUNAS $OPENFILE -f O_RDWR $DIR/test_33_file && error || true
1274         log 33_2
1275 }
1276 run_test 33 "write file with mode 444 (should return error) ===="
1277                                                                                                                                                
1278 test_33a() {
1279         rm -fr $DIR/d33
1280         mkdir -p $DIR/d33
1281         chown $RUNAS_ID $DIR/d33
1282         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 || error
1283         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && error || true
1284 }
1285 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
1286
1287 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
1288 test_34a() {
1289         rm -f $DIR/f34
1290         $MCREATE $DIR/f34 || error
1291         $LFIND $DIR/f34 2>&1 | grep -q "no stripe info" || error
1292         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
1293         $LFIND $DIR/f34 2>&1 | grep -q "no stripe info" || error
1294         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1295 }
1296 run_test 34a "truncate file that has not been opened ==========="
1297
1298 test_34b() {
1299         [ ! -f $DIR/f34 ] && test_34a
1300         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1301         $OPENFILE -f O_RDONLY $DIR/f34
1302         $LFIND $DIR/f34 2>&1 | grep -q "no stripe info" || error
1303         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1304 }
1305 run_test 34b "O_RDONLY opening file doesn't create objects ====="
1306
1307 test_34c() {
1308         [ ! -f $DIR/f34 ] && test_34a 
1309         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1310         $OPENFILE -f O_RDWR $DIR/f34
1311         $LFIND $DIR/f34 2>&1 | grep -q "no stripe info" && error
1312         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1313 }
1314 run_test 34c "O_RDWR opening file-with-size works =============="
1315
1316 test_34d() {
1317         [ ! -f $DIR/f34 ] && test_34a 
1318         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
1319         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1320         rm $DIR/f34
1321 }
1322 run_test 34d "write to sparse file ============================="
1323
1324 test_34e() {
1325         rm -f $DIR/f34e
1326         $MCREATE $DIR/f34e || error
1327         $TRUNCATE $DIR/f34e 1000 || error
1328         $CHECKSTAT -s 1000 $DIR/f34e || error
1329         $OPENFILE -f O_RDWR $DIR/f34e
1330         $CHECKSTAT -s 1000 $DIR/f34e || error
1331 }
1332 run_test 34e "create objects, some with size and some without =="
1333
1334 test_35a() {
1335         cp /bin/sh $DIR/f35a
1336         chmod 444 $DIR/f35a
1337         chown $RUNAS_ID $DIR/f35a
1338         $RUNAS $DIR/f35a && error || true
1339         rm $DIR/f35a
1340 }
1341 run_test 35a "exec file with mode 444 (should return and not leak) ====="
1342
1343 test_36a() {
1344         rm -f $DIR/f36
1345         utime $DIR/f36 || error
1346 }
1347 run_test 36a "MDS utime check (mknod, utime) ==================="
1348
1349 test_36b() {
1350         echo "" > $DIR/f36
1351         utime $DIR/f36 || error
1352 }
1353 run_test 36b "OST utime check (open, utime) ===================="
1354
1355 test_36c() {
1356         rm -f $DIR/d36/f36
1357         mkdir $DIR/d36
1358         chown $RUNAS_ID $DIR/d36
1359         $RUNAS utime $DIR/d36/f36 || error
1360 }
1361 run_test 36c "non-root MDS utime check (mknod, utime) =========="
1362
1363 test_36d() {
1364         [ ! -d $DIR/d36 ] && test_36c
1365         echo "" > $DIR/d36/f36
1366         $RUNAS utime $DIR/d36/f36 || error
1367 }
1368 run_test 36d "non-root OST utime check (open, utime) ==========="
1369
1370 test_36e() {
1371         [ $RUNAS_ID -eq $UID ] && echo "skipping test 36e" && return
1372         [ ! -d $DIR/d36 ] && mkdir $DIR/d36
1373         touch $DIR/d36/f36e
1374         $RUNAS utime $DIR/d36/f36e && error "utime worked, want failure" || true
1375 }
1376 run_test 36e "utime on non-owned file (should return error) ===="
1377
1378 test_37() {
1379         mkdir -p $DIR/dextra
1380         echo f > $DIR/dextra/fbugfile
1381         mount -t ext2 -o loop $EXT2_DEV $DIR/dextra
1382         ls $DIR/dextra | grep "\<fbugfile\>" && error
1383         umount $DIR/dextra || error
1384         rm -f $DIR/dextra/fbugfile || error
1385 }
1386 run_test 37 "ls a mounted file system to check old content ====="
1387
1388 test_38() {
1389         o_directory $DIR/test38
1390 }
1391 run_test 38 "open a regular file with O_DIRECTORY =============="
1392
1393 test_39() {
1394         touch $DIR/test_39_file
1395         touch $DIR/test_39_file2
1396 #       ls -l  $DIR/test_39_file $DIR/test_39_file2
1397 #       ls -lu  $DIR/test_39_file $DIR/test_39_file2
1398 #       ls -lc  $DIR/test_39_file $DIR/test_39_file2
1399         sleep 2
1400         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/test_39_file2
1401 #       ls -l  $DIR/test_39_file $DIR/test_39_file2
1402 #       ls -lu  $DIR/test_39_file $DIR/test_39_file2
1403 #       ls -lc  $DIR/test_39_file $DIR/test_39_file2
1404         [ $DIR/test_39_file2 -nt $DIR/test_39_file ] || error
1405 }
1406 run_test 39 "mtime changed on create ==========================="
1407
1408 test_40() {
1409         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
1410         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
1411         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
1412 }
1413 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
1414
1415 test_41() {
1416         # bug 1553
1417         small_write $DIR/f41 18
1418 }
1419 run_test 41 "test small file write + fstat ====================="
1420
1421 count_ost_writes() {
1422         cat /proc/fs/lustre/osc/*/stats |
1423             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
1424 }
1425
1426 # decent default
1427 WRITEBACK_SAVE=500
1428
1429 start_writeback() {
1430         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs
1431         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1432                 echo $WRITEBACK_SAVE > /proc/sys/vm/dirty_writeback_centisecs
1433         else
1434                 # if file not here, we are a 2.4 kernel
1435                 kill -CONT `pidof kupdated`
1436         fi
1437 }
1438 stop_writeback() {
1439         # setup the trap first, so someone cannot exit the test at the
1440         # exact wrong time and mess up a machine
1441         trap start_writeback EXIT
1442         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
1443         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1444                 WRITEBACK_SAVE=`cat /proc/sys/vm/dirty_writeback_centisecs`
1445                 echo 0 > /proc/sys/vm/dirty_writeback_centisecs
1446         else
1447                 # if file not here, we are a 2.4 kernel
1448                 kill -STOP `pidof kupdated`
1449         fi
1450 }
1451
1452 # ensure that all stripes have some grant before we test client-side cache
1453 setup_test42() {
1454         [ "$SETUP_TEST42" ] && return
1455         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
1456                 dd if=/dev/zero of=$i bs=4k count=1
1457                 rm $i
1458         done
1459         SETUP_TEST42=DONE
1460 }
1461
1462 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
1463 # file truncation, and file removal.
1464 test_42a() {
1465         setup_test42
1466         cancel_lru_locks OSC
1467         stop_writeback
1468         sync; sleep 1; sync # just to be safe
1469         BEFOREWRITES=`count_ost_writes`
1470         grep [0-9] /proc/fs/lustre/osc/OSC*MNT*/cur_grant_bytes
1471         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
1472         AFTERWRITES=`count_ost_writes`
1473         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1474                 error "$BEFOREWRITES < $AFTERWRITES"
1475         start_writeback
1476 }
1477 run_test 42a "ensure that we don't flush on close =============="
1478
1479 test_42b() {
1480         setup_test42
1481         cancel_lru_locks OSC
1482         stop_writeback
1483         sync
1484         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
1485         BEFOREWRITES=`count_ost_writes`
1486         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
1487         AFTERWRITES=`count_ost_writes`
1488         [ $BEFOREWRITES -eq $AFTERWRITES ] ||
1489             error "$BEFOREWRITES < $AFTERWRITES on unlink"
1490         BEFOREWRITES=`count_ost_writes`
1491         sync || error "sync: $?"
1492         AFTERWRITES=`count_ost_writes`
1493         [ $BEFOREWRITES -eq $AFTERWRITES ] ||
1494             error "$BEFOREWRITES < $AFTERWRITES on sync"
1495         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
1496         start_writeback
1497         return 0
1498 }
1499 run_test 42b "test destroy of file with cached dirty data ======"
1500
1501 # if these tests just want to test the effect of truncation,
1502 # they have to be very careful.  consider:
1503 # - the first open gets a {0,EOF}PR lock
1504 # - the first write conflicts and gets a {0, count-1}PW
1505 # - the rest of the writes are under {count,EOF}PW
1506 # - the open for truncate tries to match a {0,EOF}PR
1507 #   for the filesize and cancels the PWs.
1508 # any number of fixes (don't get {0,EOF} on open, match
1509 # composite locks, do smarter file size management) fix
1510 # this, but for now we want these tests to verify that
1511 # the cancellation with truncate intent works, so we
1512 # start the file with a full-file pw lock to match against
1513 # until the truncate.
1514 trunc_test() {
1515         test=$1
1516         file=$DIR/$test
1517         offset=$2
1518         cancel_lru_locks OSC
1519         stop_writeback
1520         # prime the file with 0,EOF PW to match
1521         touch $file
1522         $TRUNCATE $file 0
1523         sync; sync
1524         # now the real test..
1525         dd if=/dev/zero of=$file bs=1024 count=100
1526         BEFOREWRITES=`count_ost_writes`
1527         $TRUNCATE $file $offset
1528         cancel_lru_locks OSC
1529         AFTERWRITES=`count_ost_writes`
1530         start_writeback
1531 }
1532
1533 test_42c() {
1534         trunc_test 42c 1024
1535         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
1536                 error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
1537         rm $file
1538 }
1539 run_test 42c "test partial truncate of file with cached dirty data"
1540
1541 test_42d() {
1542         trunc_test 42d 0
1543         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1544             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
1545         rm $file
1546 }
1547 run_test 42d "test complete truncate of file with cached dirty data"
1548
1549 test_43() {
1550         mkdir $DIR/d43
1551         cp -p /bin/ls $DIR/d43/f
1552         exec 100>> $DIR/d43/f
1553         $DIR/d43/f && error || true
1554         exec 100<&-
1555 }
1556 run_test 43 "execution of file opened for write should return -ETXTBSY"
1557
1558 test_43a() {
1559         mkdir -p $DIR/d43
1560         cp -p `which multiop` $DIR/d43/multiop
1561         $DIR/d43/multiop $TMP/test43.junk O_c &
1562         MULTIPID=$!
1563         sleep 1
1564         multiop $DIR/d43/multiop Oc && error "expected error, got success"
1565         kill -USR1 $MULTIPID || return 2
1566         wait $MULTIPID || return 3
1567 }
1568 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
1569
1570 test_43b() {
1571         mkdir -p $DIR/d43
1572         cp -p `which multiop` $DIR/d43/multiop
1573         $DIR/d43/multiop $TMP/test43.junk O_c &
1574         MULTIPID=$!
1575         sleep 1
1576         truncate $DIR/d43/multiop 0 && error "expected error, got success"
1577         kill -USR1 $MULTIPID || return 2
1578         wait $MULTIPID || return 3
1579 }
1580 run_test 43b "truncate of file being executed should return -ETXTBSY"
1581
1582 test_43c() {
1583         local testdir="$DIR/d43c"
1584         mkdir -p $testdir
1585         cp $SHELL $testdir/
1586         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
1587                 ( cd $testdir && md5sum -c)
1588 }
1589 run_test 43c "md5sum of copy into lustre========================"
1590
1591 test_44() {
1592         [  "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
1593         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
1594         dd if=$DIR/f1 bs=4k count=1
1595 }
1596 run_test 44 "zero length read from a sparse stripe ============="
1597
1598 test_44a() {
1599     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
1600                          awk '{print $2}'`
1601     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
1602                       awk '{print $2}'`
1603     if [ $nstripe -eq 0 ] ; then
1604         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
1605     fi
1606
1607     OFFSETS="0 $((stride/2)) $((stride-1))"
1608     for offset in $OFFSETS ; do
1609       for i in `seq 0 $((nstripe-1))`; do
1610         rm -f $DIR/d44a
1611         local GLOBALOFFSETS=""
1612         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
1613         ll_sparseness_write $DIR/d44a $size  || error "ll_sparseness_write"
1614         GLOBALOFFSETS="$GLOBALOFFSETS $size"
1615         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
1616                             || error "ll_sparseness_verify $GLOBALOFFSETS"
1617
1618         for j in `seq 0 $((nstripe-1))`; do
1619             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
1620             ll_sparseness_write $DIR/d44a $size || error "ll_sparseness_write"
1621             GLOBALOFFSETS="$GLOBALOFFSETS $size"
1622         done
1623         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
1624                             || error "ll_sparseness_verify $GLOBALOFFSETS"
1625       done
1626     done
1627 }
1628 run_test 44a "test sparse pwrite ==============================="
1629
1630 dirty_osc_total() {
1631         tot=0
1632         for d in /proc/fs/lustre/osc/*/cur_dirty_bytes; do
1633                 tot=$(($tot + `cat $d`))
1634         done
1635         echo $tot
1636 }
1637 do_dirty_record() {
1638         before=`dirty_osc_total`
1639         echo executing "\"$*\""
1640         eval $*
1641         after=`dirty_osc_total`
1642         echo before $before, after $after
1643 }
1644 test_45() {
1645         f="$DIR/f45"
1646         # Obtain grants from OST if it supports it
1647         echo blah > ${f}_grant
1648         stop_writeback
1649         sync
1650         do_dirty_record "echo blah > $f"
1651         [ $before -eq $after ] && error "write wasn't cached"
1652         do_dirty_record "> $f"
1653         [ $before -gt $after ] || error "truncate didn't lower dirty count"
1654         do_dirty_record "echo blah > $f"
1655         [ $before -eq $after ] && error "write wasn't cached"
1656         do_dirty_record "sync"
1657         [ $before -gt $after ] || error "writeback didn't lower dirty count"
1658         do_dirty_record "echo blah > $f"
1659         [ $before -eq $after ] && error "write wasn't cached"
1660         do_dirty_record "cancel_lru_locks OSC"
1661         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
1662         start_writeback
1663 }
1664 run_test 45 "osc io page accounting ============================"
1665
1666 page_size() {
1667         getconf PAGE_SIZE
1668 }
1669
1670 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
1671 # test tickles a bug where re-dirtying a page was failing to be mapped to the
1672 # objects offset and an assert hit when an rpc was built with 1023's mapped 
1673 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
1674 test_46() {
1675         f="$DIR/f46"
1676         stop_writeback
1677         sync
1678         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
1679         sync
1680         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
1681         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
1682         sync
1683         start_writeback
1684 }
1685 run_test 46 "dirtying a previously written page ================"
1686
1687 # Check that device nodes are created and then visible correctly (#2091)
1688 test_47() {
1689         cmknod $DIR/test_47_node || error
1690 }
1691 run_test 47 "Device nodes check ================================"
1692
1693 test_48a() { # bug 2399
1694         check_kernel_version 34 || return 0
1695         mkdir -p $DIR/d48a
1696         cd $DIR/d48a
1697         mv $DIR/d48a $DIR/d48.new || error "move directory failed"
1698         mkdir $DIR/d48a || error "recreate directory failed"
1699         touch foo || error "'touch foo' failed after recreating cwd"
1700         mkdir bar || error "'mkdir foo' failed after recreating cwd"
1701         ls . || error "'ls .' failed after recreating cwd"
1702         ls .. || error "'ls ..' failed after removing cwd"
1703         cd . || error "'cd .' failed after recreating cwd"
1704         mkdir . && error "'mkdir .' worked after recreating cwd"
1705         rmdir . && error "'rmdir .' worked after recreating cwd"
1706         ln -s . baz || error "'ln -s .' failed after recreating cwd"
1707         cd .. || error "'cd ..' failed after recreating cwd"
1708 }
1709 run_test 48a "Access renamed working dir (should return errors)="
1710
1711 test_48b() { # bug 2399
1712         check_kernel_version 34 || return 0
1713         mkdir -p $DIR/d48b
1714         cd $DIR/d48b
1715         rmdir $DIR/d48b || error "remove cwd $DIR/d48b failed"
1716         touch foo && error "'touch foo' worked after removing cwd"
1717         mkdir foo && error "'mkdir foo' worked after removing cwd"
1718         ls . && error "'ls .' worked after removing cwd"
1719         ls .. || error "'ls ..' failed after removing cwd"
1720         cd . && error "'cd .' worked after removing cwd"
1721         mkdir . && error "'mkdir .' worked after removing cwd"
1722         rmdir . && error "'rmdir .' worked after removing cwd"
1723         ln -s . foo && error "'ln -s .' worked after removing cwd"
1724         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
1725
1726 }
1727 run_test 48b "Access removed working dir (should return errors)="
1728
1729 test_48c() { # bug 2350
1730         check_kernel_version 36 || return 0
1731         #sysctl -w portals.debug=-1
1732         #set -vx
1733         mkdir -p $DIR/d48c/dir
1734         cd $DIR/d48c/dir
1735         $TRACE rmdir $DIR/d48c/dir || error "remove cwd $DIR/d48c/dir failed"
1736         $TRACE touch foo && error "'touch foo' worked after removing cwd"
1737         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
1738         $TRACE ls . && error "'ls .' worked after removing cwd"
1739         $TRACE ls .. || error "'ls ..' failed after removing cwd"
1740         $TRACE cd . && error "'cd .' worked after removing cwd"
1741         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
1742         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
1743         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
1744         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
1745 }
1746 run_test 48c "Access removed working subdir (should return errors)"
1747
1748 test_48d() { # bug 2350
1749         check_kernel_version 36 || return 0
1750         #sysctl -w portals.debug=-1
1751         #set -vx
1752         mkdir -p $DIR/d48d/dir
1753         cd $DIR/d48d/dir
1754         $TRACE rmdir $DIR/d48d/dir || error "remove cwd $DIR/d48d/dir failed"
1755         $TRACE rmdir $DIR/d48d || error "remove parent $DIR/d48d failed"
1756         $TRACE touch foo && error "'touch foo' worked after removing parent"
1757         $TRACE mkdir foo && error "'mkdir foo' worked after removing parent"
1758         $TRACE ls . && error "'ls .' worked after removing parent"
1759         $TRACE ls .. && error "'ls ..' worked after removing parent"
1760         $TRACE cd . && error "'cd .' worked after recreate parent"
1761         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
1762         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
1763         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
1764         $TRACE cd .. && error "'cd ..' worked after removing parent" || true
1765 }
1766 run_test 48d "Access removed parent subdir (should return errors)"
1767
1768 test_48e() { # bug 4134
1769         check_kernel_version 41 || return 0
1770         #sysctl -w portals.debug=-1
1771         #set -vx
1772         mkdir -p $DIR/d48e/dir
1773         # On a buggy kernel addition of "; touch file" after cd .. will
1774         # produce kernel oops in lookup_hash_it
1775
1776         cd $DIR/d48e/dir
1777         ( sleep 2 && cd -P .. ) &
1778         cdpid=$!
1779         $TRACE rmdir $DIR/d48e/dir || error "remove cwd $DIR/d48e/dir failed"
1780         $TRACE rmdir $DIR/d48e || error "remove parent $DIR/d48e failed"
1781         $TRACE touch $DIR/d48e || error "'touch $DIR/d48e' failed"
1782         $TRACE chmod +x $DIR/d48e || error "'chmod +x $DIR/d48e' failed"
1783         $TRACE wait $cdpid && error "'cd ..' worked after recreate parent"
1784         $TRACE rm $DIR/d48e || error "'$DIR/d48e' failed"
1785 }
1786 run_test 48e "Access to recreated parent (should return errors) "
1787
1788 test_50() {
1789         # bug 1485
1790         mkdir $DIR/d50
1791         cd $DIR/d50
1792         ls /proc/$$/cwd || error
1793 }
1794 run_test 50 "special situations: /proc symlinks  ==============="
1795
1796 test_51() {
1797         # bug 1516 - create an empty entry right after ".." then split dir
1798         mkdir $DIR/d49
1799         touch $DIR/d49/foo
1800         $MCREATE $DIR/d49/bar
1801         rm $DIR/d49/foo
1802         createmany -m $DIR/d49/longfile 201
1803         FNUM=202
1804         while [ `ls -sd $DIR/d49 | awk '{ print $1 }'` -eq 4 ]; do
1805                 $MCREATE $DIR/d49/longfile$FNUM
1806                 FNUM=$(($FNUM + 1))
1807                 echo -n "+"
1808         done
1809         ls -l $DIR/d49 > /dev/null || error
1810 }
1811 run_test 51 "special situations: split htree with empty entry =="
1812
1813 export NUMTEST=70000
1814 test_51b() {
1815         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
1816         [ $NUMFREE -lt 21000 ] && \
1817                 echo "skipping test 51b, not enough free inodes($NUMFREE)" && \
1818                 return
1819
1820         check_kernel_version 40 || NUMTEST=31000
1821         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 50))
1822
1823         mkdir -p $DIR/d51b
1824         (cd $DIR/d51b; mkdirmany t $NUMTEST)
1825 }
1826 run_test 51b "mkdir .../t-0 --- .../t-$NUMTEST ===================="
1827
1828 test_51c() {
1829        NUMTEST=70000
1830        check_kernel_version 40 || NUMTEST=31000
1831        NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
1832        [ $NUMFREE -lt $NUMTEST ] && echo "skipping test 51c" && return
1833        mkdir -p $DIR/d51b
1834        (cd $DIR/d51b; rmdirmany t $NUMTEST)
1835 }
1836 run_test 51c "rmdir .../t-0 --- .../t-$NUMTEST ===================="
1837
1838 test_52a() {
1839         [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
1840         mkdir -p $DIR/d52a
1841         touch $DIR/d52a/foo
1842         chattr =a $DIR/d52a/foo || error
1843         echo bar >> $DIR/d52a/foo || error
1844         cp /etc/hosts $DIR/d52a/foo && error
1845         rm -f $DIR/d52a/foo 2>/dev/null && error
1846         link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error
1847         echo foo >> $DIR/d52a/foo || error
1848         mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error
1849         lsattr $DIR/d52a/foo | egrep -q "^-+a-+ $DIR/d52a/foo" || error
1850         chattr -a $DIR/d52a/foo || error
1851
1852         rm -fr $DIR/d52a || error
1853 }
1854 run_test 52a "append-only flag test (should return errors) ====="
1855
1856 test_52b() {
1857         [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
1858         mkdir -p $DIR/d52b
1859         touch $DIR/d52b/foo
1860         chattr =i $DIR/d52b/foo || error
1861         cat test > $DIR/d52b/foo && error
1862         cp /etc/hosts $DIR/d52b/foo && error
1863         rm -f $DIR/d52b/foo 2>/dev/null && error
1864         link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error
1865         echo foo >> $DIR/d52b/foo && error
1866         mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error
1867         [ -f $DIR/d52b/foo ] || error
1868         [ -f $DIR/d52b/foo_ren ] && error
1869         lsattr $DIR/d52b/foo | egrep -q "^-+i-+ $DIR/d52b/foo" || error
1870         chattr -i $DIR/d52b/foo || error
1871
1872         rm -fr $DIR/d52b || error
1873 }
1874 run_test 52b "immutable flag test (should return errors) ======="
1875
1876 test_53() {
1877         for i in `ls -d /proc/fs/lustre/osc/OSC*mds1 2> /dev/null` ; do
1878                 ostname=`echo $i | cut -d _ -f 3-4 | sed -e s/_mds1//`
1879                 ost_last=`cat /proc/fs/lustre/obdfilter/$ostname/last_id`
1880                 mds_last=`cat $i/prealloc_last_id`
1881                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
1882                 if [ $ost_last != $mds_last ]; then
1883                     error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
1884                 fi
1885         done
1886 }
1887 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
1888
1889 test_54a() {
1890         $SOCKETSERVER $DIR/socket
1891         $SOCKETCLIENT $DIR/socket || error
1892         $MUNLINK $DIR/socket
1893 }
1894 run_test 54a "unix damain socket test =========================="
1895
1896 test_54b() {
1897         f="$DIR/f54b"
1898         mknod $f c 1 3
1899         chmod 0666 $f
1900         dd if=/dev/zero of=$f bs=`page_size` count=1 
1901 }
1902 run_test 54b "char device works in lustre ======================"
1903
1904 find_loop_dev() {
1905        [ "$LOOPNUM" ] && return
1906        [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
1907        [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
1908        [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
1909
1910        for i in `seq 3 7`; do
1911                losetup $LOOPBASE$i > /dev/null 2>&1 && continue
1912                LOOPDEV=$LOOPBASE$i
1913                LOOPNUM=$i
1914                break
1915        done
1916 }
1917
1918 test_54c() {
1919         tfile="$DIR/f54c"
1920         tdir="$DIR/d54c"
1921         loopdev="$DIR/loop54c"
1922         
1923         find_loop_dev
1924         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
1925         mknod $loopdev b 7 $LOOPNUM
1926         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
1927         
1928         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
1929         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
1930         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
1931         mkdir -p $tdir
1932         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
1933         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
1934         df $tdir
1935         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
1936         umount $tdir
1937         losetup -d $loopdev
1938         rm $loopdev
1939 }
1940 run_test 54c "block device works in lustre ====================="
1941
1942 test_54d() {
1943         f="$DIR/f54d"
1944         string="aaaaaa"
1945         mknod $f p
1946         [ "$string" = `echo $string > $f | cat $f` ] || error
1947 }
1948 run_test 54d "fifo device works in lustre ======================"
1949
1950 check_fstype() {
1951         test "x$FSTYPE" = "x$(grep $FSTYPE /proc/filesystems)" && return 0
1952         modprobe $FSTYPE > /dev/null 2>&1
1953         test "x$FSTYPE" = "x$(grep $FSTYPE /proc/filesystems)" && return 0
1954         test "x$(uname -r | grep -o "2.6")" = "x2.6" && MODEXT="ko" || MODEXT="o"
1955         insmod ../$FSTYPE/$FSTYPE.$MODEXT > /dev/null 2>&1
1956         test "x$FSTYPE" = "x$(grep $FSTYPE /proc/filesystems)" && return 0
1957         return 1
1958 }
1959
1960 test_55() {
1961         rm -rf $DIR/d55
1962         mkdir $DIR/d55
1963         check_fstype && echo "can't find fs $FSTYPE, skipping test 55" && return
1964         mount -t $FSTYPE -o loop,iopen $EXT2_DEV $DIR/d55 || error "mounting"
1965         touch $DIR/d55/foo
1966         $IOPENTEST1 $DIR/d55/foo $DIR/d55 || error "running $IOPENTEST1"
1967         $IOPENTEST2 $DIR/d55 || error "running $IOPENTEST2"
1968         echo "check for $EXT2_DEV. Please wait..."
1969         rm -rf $DIR/d55/*
1970         umount $DIR/d55 || error "unmounting"
1971 }
1972 run_test 55 "check iopen_connect_dentry() ======================"
1973
1974 test_56() {
1975         rm -rf $DIR/d56
1976         mkdir $DIR/d56
1977         mkdir $DIR/d56/dir
1978         NUMFILES=3
1979         NUMFILESx2=$(($NUMFILES * 2))
1980         for i in `seq 1 $NUMFILES` ; do
1981                 touch $DIR/d56/file$i
1982                 touch $DIR/d56/dir/file$i
1983         done
1984
1985         # test lfs find with --recursive
1986         FILENUM=`$LFIND --recursive $DIR/d56 | grep -v OBDS | grep -c obdidx`
1987         [ $FILENUM -eq $NUMFILESx2 ] || error \
1988                 "lfs find --recursive $DIR/d56 wrong: found $FILENUM, expected $NUMFILESx2"
1989         FILENUM=`$LFIND $DIR/d56 | grep -v OBDS | grep -c obdidx`
1990         [ $FILENUM -eq $NUMFILES ] || error \
1991                 "lfs find $DIR/d56 without --recursive wrong: found $FILENUM,
1992                 expected $NUMFILES"
1993         echo "lfs find --recursive passed."
1994
1995         # test lfs find with file instead of dir
1996         FILENUM=`$LFIND $DIR/d56/file1 | grep -v OBDS | grep -c obdidx`
1997         [ $FILENUM  -eq 1 ] || error \
1998                  "lfs find $DIR/d56/file1 wrong: found $FILENUM, expected 1"
1999         echo "lfs find file passed."
2000
2001         #test lfs find with --verbose
2002         [ `$LFIND --verbose $DIR/d56 | grep -v OBDS | grep -c lmm_magic` -eq $NUMFILES ] ||\
2003                 error "lfs find --verbose $DIR/d56 wrong: should find $NUMFILES lmm_magic info"
2004         [ `$LFIND $DIR/d56 | grep -v OBDS | grep -c lmm_magic` -eq 0 ] || error \
2005                 "lfs find $DIR/d56 without --verbose wrong: should not show lmm_magic info"
2006         echo "lfs find --verbose passed."
2007
2008         #test lfs find with --obd
2009         $LFIND --obd wrong_uuid $DIR/d56 2>&1 | grep -q "unknown obduuid" || \
2010                 error "lfs find --obd wrong_uuid should return error information"
2011
2012         [  "$OSTCOUNT" -lt 2 ] && \
2013                 echo "skipping other lfs find --obd test" && return
2014         FILENUM=`$LFIND --recursive $DIR/d56 | grep -v OBDS | grep obdidx | wc -l`
2015         OBDUUID=`$LFIND --recursive $DIR/d56 | grep -A 1 OBDS | grep -v OBDS | awk '{print $3}'`
2016         OBDIDX=`$LFIND --recursive $DIR/d56 | grep -A 1 OBDS | grep -v OBDS | awk '{print $1}'`
2017         FOUND=`$LFIND --recursive --obd $OBDUUID $DIR/d56 | wc -l`
2018
2019         [ $FOUND -eq $FILENUM ] || \
2020                 error "lfs find --obd wrong: found $FOUND, expected $FILENUM"
2021
2022         [ `$LFIND -r -v --obd $OBDUUID $DIR/d56 | grep "^[[:blank:]]*$OBDIDX" | wc -l` ] || \
2023                 error "lfs find --obd wrong: should not show file on other obd"
2024
2025         echo "lfs find --obd passed."
2026 }
2027 run_test 56 "check lfs find ===================================="
2028
2029 test_57a() {
2030         # note test will not do anything if MDS is not local
2031         for DEV in `cat /proc/fs/lustre/mds/*/mntdev`; do
2032                 dumpe2fs -hf $DEV > $TMP/t57a.dump || error "can't access $DEV"
2033                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
2034                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
2035                 rm $TMP/t57a.dump
2036         done
2037 }
2038 run_test 57a "verify MDS filesystem created with large inodes =="
2039
2040 test_57b() {
2041         FILECOUNT=100
2042         FILE1=$DIR/d57b/f1
2043         FILEN=$DIR/d57b/f$FILECOUNT
2044         rm -rf $DIR/d57b || error "removing $DIR/d57b"
2045         mkdir -p $DIR/d57b || error "creating $DIR/d57b"
2046         echo "mcreating $FILECOUNT files"
2047         createmany -m $DIR/d57b/f 1 $FILECOUNT || \
2048                 error "creating files in $DIR/d57b"
2049
2050         # verify that files do not have EAs yet
2051         $LFIND $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
2052         $LFIND $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
2053
2054         MDSFREE="`cat /proc/fs/lustre/mds/*/kbytesfree`"
2055         MDCFREE="`cat /proc/fs/lustre/mdc/*/kbytesfree`"
2056         echo "opening files to create objects/EAs"
2057         for FILE in `seq -f $DIR/d57b/f%g 1 $FILECOUNT`; do
2058                 $OPENFILE -f O_RDWR $FILE > /dev/null || error "opening $FILE"
2059         done
2060
2061         # verify that files have EAs now
2062         $LFIND $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
2063         $LFIND $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
2064
2065         MDSFREE2="`cat /proc/fs/lustre/mds/*/kbytesfree`"
2066         MDCFREE2="`cat /proc/fs/lustre/mdc/*/kbytesfree`"
2067         
2068         if [ "$MDCFREE" != "$MDCFREE2" ]; then
2069                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
2070                         error "MDC before $MDCFREE != after $MDCFREE2"
2071                 else
2072                         echo "MDC before $MDCFREE != after $MDCFREE2"
2073                         echo "unable to confirm if MDS has large inodes"
2074                 fi
2075         fi
2076         rm -rf $DIR/d57b
2077 }
2078 run_test 57b "default LOV EAs are stored inside large inodes ==="
2079
2080 test_58() {
2081         wiretest
2082 }
2083 run_test 58 "verify cross-platform wire constants =============="
2084
2085 test_59() {
2086         echo "touch 130 files"
2087         for i in `seq 1 130` ; do
2088                 touch $DIR/59-$i
2089         done
2090         echo "rm 130 files"
2091         for i in `seq 1 130` ; do
2092                 rm -f $DIR/59-$i
2093         done
2094         sync
2095         sleep 2
2096         # wait for commitment of removal
2097 }
2098 run_test 59 "verify cancellation of llog records async ========="
2099
2100 test_60() {
2101         echo 60 "llog tests run from kernel mode"
2102         sh run-llog.sh
2103 }
2104 run_test 60 "llog sanity tests run from kernel module =========="
2105
2106 test_61() {
2107         f="$DIR/f61"
2108         dd if=/dev/zero of=$f bs=`page_size` count=1
2109         cancel_lru_locks OSC
2110         multiop $f OSMWUc || error
2111         sync
2112 }
2113 run_test 61 "mmap() writes don't make sync hang ================"
2114
2115 # bug 2330 - insufficient obd_match error checking causes LBUG
2116 test_62() {
2117         f="$DIR/f62"
2118         echo foo > $f
2119         cancel_lru_locks OSC
2120         echo 0x405 > /proc/sys/lustre/fail_loc
2121         cat $f && error "cat succeeded, expect -EIO"
2122         echo 0 > /proc/sys/lustre/fail_loc
2123 }
2124 run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
2125
2126 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
2127 test_63() {
2128         MAX_DIRTY_MB=`cat /proc/fs/lustre/osc/*/max_dirty_mb | head -n 1`
2129         for i in /proc/fs/lustre/osc/*/max_dirty_mb ; do
2130                 echo 0 > $i
2131         done
2132         for i in `seq 10` ; do
2133                 dd if=/dev/zero of=$DIR/f63 bs=8k &
2134                 sleep 5
2135                 kill $!
2136                 sleep 1
2137         done
2138
2139         for i in /proc/fs/lustre/osc/*/max_dirty_mb ; do
2140                 echo $MAX_DIRTY_MB > $i
2141         done
2142         true
2143 }
2144 run_test 63 "Verify oig_wait interruption does not crash ======"
2145
2146 test_64a () {
2147         df $DIR
2148         grep "[0-9]" /proc/fs/lustre/osc/OSC*MNT*/cur*
2149 }
2150 run_test 64a "verify filter grant calculations (in kernel) ====="
2151
2152 test_64b () {
2153         sh oos.sh $MOUNT
2154 }
2155 run_test 64b "check out-of-space detection on client ==========="
2156
2157 # bug 1414 - set/get directories' stripe info
2158 test_65a() {
2159         mkdir -p $DIR/d65a
2160         touch $DIR/d65a/f1
2161         $LVERIFY $DIR/d65a $DIR/d65a/f1 || error "lverify failed"
2162 }
2163 run_test 65a "directory with no stripe info ===================="
2164
2165 test_65b() {
2166         mkdir -p $DIR/d65b
2167         $LSTRIPE $DIR/d65b $(($STRIPESIZE * 2)) 0 1 || error "setstripe"
2168         touch $DIR/d65b/f2
2169         $LVERIFY $DIR/d65b $DIR/d65b/f2 || error "lverify failed"
2170 }
2171 run_test 65b "directory setstripe $(($STRIPESIZE * 2)) 0 1 ==============="
2172
2173 test_65c() {
2174         if [ $OSTCOUNT -gt 1 ]; then
2175                 mkdir -p $DIR/d65c
2176                 $LSTRIPE $DIR/d65c $(($STRIPESIZE * 4)) 1 \
2177                         $(($OSTCOUNT - 1)) || error "setstripe"
2178                 touch $DIR/d65c/f3
2179                 $LVERIFY $DIR/d65c $DIR/d65c/f3 || error "lverify failed"
2180         fi
2181 }
2182 run_test 65c "directory setstripe $(($STRIPESIZE * 4)) 1 $(($OSTCOUNT - 1))"
2183
2184 [ $STRIPECOUNT -eq 0 ] && sc=1 || sc=$(($STRIPECOUNT - 1))
2185
2186 test_65d() {
2187         mkdir -p $DIR/d65d
2188         $LSTRIPE $DIR/d65d $STRIPESIZE -1 $sc || error "setstripe"
2189         touch $DIR/d65d/f4 $DIR/d65d/f5
2190         $LVERIFY $DIR/d65d $DIR/d65d/f4 $DIR/d65d/f5 || error "lverify failed"
2191 }
2192 run_test 65d "directory setstripe $STRIPESIZE -1 $sc ======================"
2193
2194 test_65e() {
2195         mkdir -p $DIR/d65e
2196
2197         $LSTRIPE $DIR/d65e 0 -1 0 || error "setstripe"
2198         $LFS find -v $DIR/d65e | grep "$DIR/d65e/ has no stripe info" || error "no stripe info failed"
2199         touch $DIR/d65e/f6
2200         $LVERIFY $DIR/d65e $DIR/d65e/f6 || error "lverify failed"
2201 }
2202 run_test 65e "directory setstripe 0 -1 0 (default) ============="
2203
2204 test_65f() {
2205         mkdir -p $DIR/d65f
2206         $RUNAS $LSTRIPE $DIR/d65f 0 -1 0 && error "setstripe succeeded" || true
2207 }
2208 run_test 65f "dir setstripe permission (should return error) ==="
2209
2210 test_65g() {
2211         mkdir -p $DIR/d65g
2212         $LSTRIPE $DIR/d65g $(($STRIPESIZE * 2)) 0 1 || error "setstripe"
2213         $LSTRIPE -d $DIR/d65g || error "deleting stripe info failed"
2214         $LFS find -v $DIR/d65g | grep "$DIR/d65g/ has no stripe info" || error "no stripe info failed"
2215 }
2216 run_test 65g "directory setstripe -d ========"
2217                                                                                                                
2218 test_65h() {
2219         mkdir -p $DIR/d65h
2220         $LSTRIPE $DIR/d65h $(($STRIPESIZE * 2)) 0 1 || error "setstripe"
2221         mkdir -p $DIR/d65h/dd1
2222         [ "`$LFS find -v $DIR/d65h | grep "^count"`" == \
2223           "`$LFS find -v $DIR/d65h/dd1 | grep "^count"`" ] || error "stripe info inherit failed"
2224 }
2225 run_test 65h "directory stripe info inherit ======"
2226
2227 # bug 2543 - update blocks count on client
2228 test_66() {
2229         COUNT=${COUNT:-8}
2230         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
2231         sync
2232         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
2233         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
2234 }
2235 run_test 66 "update inode blocks count on client ==============="
2236
2237 test_67() { # bug 3285 - supplementary group fails on MDS, passes on client
2238         [ "$RUNAS_ID" = "$UID" ] && echo "skipping test 67" && return
2239         check_kernel_version 35 || return 0
2240         mkdir $DIR/d67
2241         chmod 771 $DIR/d67
2242         chgrp $RUNAS_ID $DIR/d67
2243         $RUNAS -g $(($RUNAS_ID + 1)) -G1,2,$RUNAS_ID ls $DIR/d67 && error ||true
2244 }
2245 run_test 67 "supplementary group failure (should return error) ="
2246
2247 cleanup_68() {
2248        if [ "$LOOPDEV" ]; then
2249                swapoff $LOOPDEV || error "swapoff failed"
2250                losetup -d $LOOPDEV || error "losetup -d failed"
2251                unset LOOPDEV LOOPNUM
2252        fi
2253        rm -f $DIR/f68
2254 }
2255
2256 meminfo() {
2257        awk '($1 == "'$1':") { print $2 }' /proc/meminfo
2258 }
2259
2260 swap_used() {
2261        swapon -s | awk '($1 == "'$1'") { print $4 }'
2262 }
2263
2264 # excercise swapping to lustre by adding a high priority swapfile entry
2265 # and then consuming memory until it is used.
2266 test_68() {
2267        [ "$UID" != 0 ] && echo "skipping test 68 (must run as root)" && return
2268        [ "`lsmod|grep obdfilter`" ] && echo "skipping test 68 (local OST)" && \
2269                return
2270
2271        find_loop_dev
2272        dd if=/dev/zero of=$DIR/f68 bs=64k count=1024
2273
2274        trap cleanup_68 EXIT
2275
2276        losetup $LOOPDEV $DIR/f68 || error "losetup $LOOPDEV failed"
2277        mkswap $LOOPDEV
2278        swapon -p 32767 $LOOPDEV || error "swapon $LOOPDEV failed"
2279
2280        echo "before: `swapon -s | grep $LOOPDEV`"
2281        KBFREE=`meminfo MemTotal`
2282        $MEMHOG $KBFREE || error "error allocating $KBFREE kB"
2283        echo "after: `swapon -s | grep $LOOPDEV`"
2284        SWAPUSED=`swap_used $LOOPDEV`
2285
2286        cleanup_68
2287
2288        [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
2289 }
2290 run_test 68 "support swapping to Lustre ========================"
2291
2292 # bug 3462 - multiple simultaneous MDC requests
2293 test_69() {
2294        mkdir $DIR/D68-1 
2295        mkdir $DIR/D68-2
2296        multiop $DIR/D68-1/f68-1 O_c &
2297        pid1=$!
2298        #give multiop a chance to open
2299        usleep 500
2300
2301        echo 0x80000129 > /proc/sys/lustre/fail_loc
2302        multiop $DIR/D68-1/f68-2 Oc &
2303        sleep 1
2304        echo 0 > /proc/sys/lustre/fail_loc
2305
2306        multiop $DIR/D68-2/f68-3 Oc &
2307        pid3=$!
2308
2309        kill -USR1 $pid1
2310        wait $pid1 || return 1
2311
2312        sleep 25
2313
2314        $CHECKSTAT -t file $DIR/D68-1/f68-1 || return 4
2315        $CHECKSTAT -t file $DIR/D68-1/f68-2 || return 5 
2316        $CHECKSTAT -t file $DIR/D68-2/f68-3 || return 6 
2317
2318        rm -rf $DIR/D68-*
2319 }
2320 run_test 69 "multiple MDC requests (should not deadlock)"
2321
2322
2323 test_70() {
2324         STAT="/proc/fs/lustre/osc/OSC*MNT*/stats"
2325         mkdir $DIR/d70
2326         dd if=/dev/zero of=$DIR/d70/file bs=512 count=5
2327         cancel_lru_locks OSC
2328         cat $DIR/d70/file >/dev/null
2329         # Hopefully there is only one.
2330         ENQ=`cat $STAT|awk -vnum=0 '/ldlm_enq/ {num += $2} END {print num;}'`
2331         CONV=`cat $STAT|awk -vnum=0 '/ldlm_conv/ {num += $2} END {print num;}'`
2332         CNCL=`cat $STAT|awk -vnum=0 '/ldlm_canc/ {num += $2} END {print num;}'`
2333         dd if=/dev/zero of=$DIR/d70/file bs=512 count=5
2334         ENQ1=`cat $STAT|awk -vnum=0 '/ldlm_enq/ {num += $2} END {print num;}'`
2335         CONV1=`cat $STAT|awk -vnum=0 '/ldlm_conv/ {num += $2} END {print num;}'`
2336         CNCL1=`cat $STAT|awk -vnum=0 '/ldlm_canc/ {num += $2} END {print num;}'`
2337
2338         if [ $CONV1 -le $CONV ] ; then
2339                 error "No conversion happened. Before: enq $ENQ, conv $CONV, cancel $CNCL ; After: enq $ENQ1, conv $CONV1, cancel $CNCL1"
2340         else
2341                 echo "OK"
2342                 true
2343         fi
2344
2345 }
2346 run_test 70 "Test that PR->PW conversion takes place ==========="
2347
2348 test_71() {
2349         cp `which dbench` $DIR
2350         
2351         [ ! -f $DIR/dbench ] && echo "dbench not installed, skip this test" && return 0
2352
2353         TGT=$DIR/client.txt
2354         SRC=${SRC:-/usr/lib/dbench/client.txt}
2355         [ ! -e $TGT -a -e $SRC ] && echo "copying $SRC to $TGT" && cp $SRC $TGT
2356         SRC=/usr/lib/dbench/client_plain.txt
2357         [ ! -e $TGT -a -e $SRC ] && echo "copying $SRC to $TGT" && cp $SRC $TGT
2358
2359         echo "copying /lib to $DIR"
2360         cp -r /lib $DIR/lib
2361         
2362         echo "chroot $DIR /dbench -c client.txt 2"
2363         chroot $DIR /dbench -c client.txt 2
2364         RC=$?
2365
2366         rm -f $DIR/dbench
2367         rm -f $TGT
2368         rm -fr $DIR/lib
2369
2370         return $RC
2371 }
2372 run_test 71 "Running dbench on lustre (don't segment fault) ===="
2373
2374 # on the LLNL clusters, runas will still pick up root's $TMP settings,
2375 # which will not be writable for the runas user, and then you get a CVS
2376 # error message with a corrupt path string (CVS bug) and panic.
2377 # We're not using much space, so just stick it in /tmp, which is safe.
2378 OLDTMPDIR=$TMPDIR
2379 OLDTMP=$TMP
2380 TMPDIR=/tmp
2381 TMP=/tmp
2382 OLDHOME=$HOME
2383 [ $RUNAS_ID -ne $UID ] && HOME=/tmp
2384
2385 test_99a() {
2386         mkdir -p $DIR/d99cvsroot
2387         chown $RUNAS_ID $DIR/d99cvsroot
2388         $RUNAS cvs -d $DIR/d99cvsroot init || error
2389 }
2390 run_test 99a "cvs init ========================================="
2391
2392 test_99b() {
2393         [ ! -d $DIR/d99cvsroot ] && test_99a
2394         cd /etc/init.d
2395         # some versions of cvs import exit(1) when asked to import links or
2396         # files they can't read.  ignore those files.
2397         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
2398                         ! -perm +4 -printf '-I %f\n')
2399         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
2400                 d99reposname vtag rtag
2401 }
2402 run_test 99b "cvs import ======================================="
2403
2404 test_99c() {
2405         [ ! -d $DIR/d99cvsroot ] && test_99b
2406         cd $DIR
2407         mkdir -p $DIR/d99reposname
2408         chown $RUNAS_ID $DIR/d99reposname
2409         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
2410 }
2411 run_test 99c "cvs checkout ====================================="
2412
2413 test_99d() {
2414         [ ! -d $DIR/d99cvsroot ] && test_99c
2415         cd $DIR/d99reposname
2416         $RUNAS touch foo99
2417         $RUNAS cvs add -m 'addmsg' foo99
2418 }
2419 run_test 99d "cvs add =========================================="
2420
2421 test_99e() {
2422         [ ! -d $DIR/d99cvsroot ] && test_99c
2423         cd $DIR/d99reposname
2424         $RUNAS cvs update
2425 }
2426 run_test 99e "cvs update ======================================="
2427
2428 test_99f() {
2429         [ ! -d $DIR/d99cvsroot ] && test_99d
2430         cd $DIR/d99reposname
2431         $RUNAS cvs commit -m 'nomsg' foo99
2432 }
2433 run_test 99f "cvs commit ======================================="
2434
2435 test_100() {
2436         netstat -ta | while read PROT SND RCV LOCAL REMOTE STAT; do
2437                 LPORT=`echo $LOCAL | cut -d: -f2`
2438                 RPORT=`echo $REMOTE | cut -d: -f2`
2439                 if [ "$PROT" = "tcp" ] && [ "$LPORT" != "*" ] && [ "$RPORT" != "*" ] && [ $RPORT -eq 988 ] && [ $LPORT -gt 1024 ]; then
2440                         echo "local port: $LPORT > 1024"
2441                         error
2442                 fi
2443         done
2444 }
2445 run_test 100 "check local port using privileged port ==========="
2446
2447
2448 TMPDIR=$OLDTMPDIR
2449 TMP=$OLDTMP
2450 HOME=$OLDHOME
2451
2452 log "cleanup: ======================================================"
2453 if [ "`mount | grep ^$NAME`" ]; then
2454         rm -rf $DIR/[Rdfs][1-9]*
2455         if [ "$I_MOUNTED" = "yes" ]; then
2456                 sh llmountcleanup.sh || error
2457         fi
2458 fi
2459
2460 echo '=========================== finished ==============================='
2461 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true