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