Whamcloud - gitweb
use do_facet instead of direct use sysctl for set fail_loc on OST
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 # bug number for skipped test: 4900 4900 2108 9789 3637 9789 3561 5188/5749 10764
11 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"27o 27q  42a  42b  42c  42d  45   68        75"}
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13
14 [ "$SLOW" = "no" ] && EXCEPT="$EXCEPT 24o 27m 36f 36g 51b 51c 60c 63 64b 71 73 101 103 115 120g"
15
16 # Tests that fail on uml, maybe elsewhere, FIXME
17 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
18 #                                    buffer i/o errs             sock spc runas
19 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT 27m 27n 27o 27p 27q 27r 31d 54a  64b 99a 99b 99c 99d 99e 99f 101"
20
21 case `uname -r` in
22 2.4*) FSTYPE=${FSTYPE:-ext3};    ALWAYS_EXCEPT="$ALWAYS_EXCEPT 76"
23         [ "$CPU" = "UML" ] && ALWAYS_EXCEPT="$ALWAYS_EXCEPT 105a";;
24 2.6*) FSTYPE=${FSTYPE:-ldiskfs}; ALWAYS_EXCEPT="$ALWAYS_EXCEPT " ;;
25 *) error "unsupported kernel" ;;
26 esac
27
28 SRCDIR=`dirname $0`
29 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH:/sbin
30
31 TMP=${TMP:-/tmp}
32
33 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
34 CREATETEST=${CREATETEST:-createtest}
35 LFS=${LFS:-lfs}
36 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
37 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
38 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
39 LFIND=${LFIND:-"$LFS find"}
40 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
41 LSTRIPEINFO=${LSTRIPEINFO:-ll_getstripe_info}
42 LCTL=${LCTL:-lctl}
43 MCREATE=${MCREATE:-mcreate}
44 OPENFILE=${OPENFILE:-openfile}
45 OPENUNLINK=${OPENUNLINK:-openunlink}
46 RANDOM_READS=${RANDOM_READS:-"random-reads"}
47 TOEXCL=${TOEXCL:-toexcl}
48 TRUNCATE=${TRUNCATE:-truncate}
49 MUNLINK=${MUNLINK:-munlink}
50 SOCKETSERVER=${SOCKETSERVER:-socketserver}
51 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
52 IOPENTEST1=${IOPENTEST1:-iopentest1}
53 IOPENTEST2=${IOPENTEST2:-iopentest2}
54 MEMHOG=${MEMHOG:-memhog}
55 DIRECTIO=${DIRECTIO:-directio}
56 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
57 UMOUNT=${UMOUNT:-"umount -d"}
58
59 if [ $UID -ne 0 ]; then
60         echo "Warning: running as non-root uid $UID"
61         RUNAS_ID="$UID"
62         RUNAS=""
63 else
64         RUNAS_ID=${RUNAS_ID:-500}
65         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
66
67         # $RUNAS_ID may get set incorrectly somewhere else
68         if [ $RUNAS_ID -eq 0 ]; then
69                 echo "Error: \$RUNAS_ID set to 0, but \$UID is also 0!"
70                 exit 1
71         fi
72 fi
73
74 SANITYLOG=${SANITYLOG:-$TMP/sanity.log}
75
76 export NAME=${NAME:-local}
77
78 SAVE_PWD=$PWD
79
80 LUSTRE=${LUSTRE:-`dirname $0`/..}
81 . $LUSTRE/tests/test-framework.sh
82 init_test_env $@
83 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
84
85 cleanup() {
86         echo -n "cln.."
87         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
88 }
89 CLEANUP=${CLEANUP:-:}
90
91 setup() {
92         echo -n "mnt.."
93         load_modules
94         setupall || exit 10
95         echo "done"
96 }
97 SETUP=${SETUP:-:}
98
99 log() {
100         echo "$*"
101         $LCTL mark "$*" 2> /dev/null || true
102 }
103
104 trace() {
105         log "STARTING: $*"
106         strace -o $TMP/$1.strace -ttt $*
107         RC=$?
108         log "FINISHED: $*: rc $RC"
109         return 1
110 }
111 TRACE=${TRACE:-""}
112
113 check_kernel_version() {
114         VERSION_FILE=$LPROC/version
115         WANT_VER=$1
116         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
117         GOT_VER=$(awk '/kernel:/ {print $2}' $VERSION_FILE)
118         [ $GOT_VER == "patchless" ] && return 0
119         [ $GOT_VER -ge $WANT_VER ] && return 0
120         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
121         return 1
122 }
123
124 _basetest() {
125     echo $*
126 }
127
128 basetest() {
129     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
130 }
131
132 run_one() {
133         if ! grep -q $DIR /proc/mounts; then
134                 $SETUP
135         fi
136         testnum=$1
137         message=$2
138         BEFORE=`date +%s`
139         log "== test $testnum: $message= `date +%H:%M:%S` ($BEFORE)"
140         export TESTNAME=test_$testnum
141         export tfile=f${testnum}
142         export tdir=d${base}
143         test_${testnum} || error "exit with rc=$?"
144         unset TESTNAME
145         pass "($((`date +%s` - $BEFORE))s)"
146         cd $SAVE_PWD
147         $CLEANUP
148 }
149
150 build_test_filter() {
151         [ "$ALWAYS_EXCEPT$EXCEPT$SANITY_EXCEPT" ] && \
152             echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT $SANITY_EXCEPT`"
153
154         for O in $ONLY; do
155             eval ONLY_${O}=true
156         done
157         for E in $EXCEPT $ALWAYS_EXCEPT $SANITY_EXCEPT; do
158             eval EXCEPT_${E}=true
159         done
160 }
161
162 _basetest() {
163         echo $*
164 }
165
166 basetest() {
167         IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
168 }
169
170 run_test() {
171          export base=`basetest $1`
172          if [ "$ONLY" ]; then
173                  testname=ONLY_$1
174                  if [ ${!testname}x != x ]; then
175                         run_one $1 "$2"
176                         return $?
177                  fi
178                  testname=ONLY_$base
179                  if [ ${!testname}x != x ]; then
180                          run_one $1 "$2"
181                          return $?
182                  fi
183                  echo -n "."
184                  return 0
185         fi
186         testname=EXCEPT_$1
187         if [ ${!testname}x != x ]; then
188                  echo "skipping excluded test $1"
189                  return 0
190         fi
191         testname=EXCEPT_$base
192         if [ ${!testname}x != x ]; then
193                  echo "skipping excluded test $1 (base $base)"
194                  return 0
195         fi
196         run_one $1 "$2"
197         return $?
198 }
199
200 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
201
202 error() { 
203         sysctl -w lustre.fail_loc=0
204         log "$0: FAIL: $TESTNAME $@"
205         $LCTL dk $TMP/lustre-log-$TESTNAME.log
206         if [ "$SANITYLOG" ]; then
207                 echo "$0: FAIL: $TESTNAME $@" >> $SANITYLOG
208         else
209                 exit 1
210         fi
211 }
212
213 pass() { 
214         echo PASS $@
215 }
216
217 mounted_lustre_filesystems() {
218         awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
219 }
220
221 MOUNTED="`mounted_lustre_filesystems`"
222 if [ -z "$MOUNTED" ]; then
223         formatall
224         setupall
225         MOUNTED="`mounted_lustre_filesystems`"
226         [ -z "$MOUNTED" ] && error "NAME=$NAME not mounted"
227         I_MOUNTED=yes
228 fi
229
230 DIR=${DIR:-$MOUNT}
231 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
232
233 LOVNAME=`cat $LPROC/llite/*/lov/common_name | tail -n 1`
234 OSTCOUNT=`cat $LPROC/lov/$LOVNAME/numobd`
235 STRIPECOUNT=`cat $LPROC/lov/$LOVNAME/stripecount`
236 STRIPESIZE=`cat $LPROC/lov/$LOVNAME/stripesize`
237 ORIGFREE=`cat $LPROC/lov/$LOVNAME/kbytesavail`
238 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
239 MDS=$(\ls $LPROC/mds 2> /dev/null | grep -v num_refs | tail -n 1)
240
241 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
242 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
243 rm -rf $DIR/[Rdfs][1-9]*
244
245 build_test_filter
246
247 echo "preparing for tests involving mounts"
248 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
249 touch $EXT2_DEV
250 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
251 echo # add a newline after mke2fs.
252
253 umask 077
254
255 OLDDEBUG="`sysctl lnet.debug 2> /dev/null`"
256 sysctl -w lnet.debug=-1 2> /dev/null || true
257 test_0() {
258         touch $DIR/$tfile
259         $CHECKSTAT -t file $DIR/$tfile || error
260         rm $DIR/$tfile
261         $CHECKSTAT -a $DIR/$tfile || error
262 }
263 run_test 0 "touch .../$tfile ; rm .../$tfile ====================="
264
265 test_0b() {
266         chmod 0755 $DIR || error
267         $CHECKSTAT -p 0755 $DIR || error
268 }
269 run_test 0b "chmod 0755 $DIR ============================="
270
271 test_1a() {
272         mkdir $DIR/d1
273         mkdir $DIR/d1/d2
274         $CHECKSTAT -t dir $DIR/d1/d2 || error
275 }
276 run_test 1a "mkdir .../d1; mkdir .../d1/d2 ====================="
277
278 test_1b() {
279         rmdir $DIR/d1/d2
280         rmdir $DIR/d1
281         $CHECKSTAT -a $DIR/d1 || error
282 }
283 run_test 1b "rmdir .../d1/d2; rmdir .../d1 ====================="
284
285 test_2a() {
286         mkdir $DIR/d2
287         touch $DIR/d2/f
288         $CHECKSTAT -t file $DIR/d2/f || error
289 }
290 run_test 2a "mkdir .../d2; touch .../d2/f ======================"
291
292 test_2b() {
293         rm -r $DIR/d2
294         $CHECKSTAT -a $DIR/d2 || error
295 }
296 run_test 2b "rm -r .../d2; checkstat .../d2/f ======================"
297
298 test_3a() {
299         mkdir $DIR/d3
300         $CHECKSTAT -t dir $DIR/d3 || error
301 }
302 run_test 3a "mkdir .../d3 ======================================"
303
304 test_3b() {
305         if [ ! -d $DIR/d3 ]; then
306                 mkdir $DIR/d3
307         fi
308         touch $DIR/d3/f
309         $CHECKSTAT -t file $DIR/d3/f || error
310 }
311 run_test 3b "touch .../d3/f ===================================="
312
313 test_3c() {
314         rm -r $DIR/d3
315         $CHECKSTAT -a $DIR/d3 || error
316 }
317 run_test 3c "rm -r .../d3 ======================================"
318
319 test_4a() {
320         mkdir $DIR/d4
321         $CHECKSTAT -t dir $DIR/d4 || error
322 }
323 run_test 4a "mkdir .../d4 ======================================"
324
325 test_4b() {
326         if [ ! -d $DIR/d4 ]; then
327                 mkdir $DIR/d4
328         fi
329         mkdir $DIR/d4/d2
330         $CHECKSTAT -t dir $DIR/d4/d2 || error
331 }
332 run_test 4b "mkdir .../d4/d2 ==================================="
333
334 test_5() {
335         mkdir $DIR/d5
336         mkdir $DIR/d5/d2
337         chmod 0707 $DIR/d5/d2
338         $CHECKSTAT -t dir -p 0707 $DIR/d5/d2 || error
339 }
340 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
341
342 test_6a() {
343         touch $DIR/f6a
344         chmod 0666 $DIR/f6a || error
345         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
346 }
347 run_test 6a "touch .../f6a; chmod .../f6a ======================"
348
349 test_6b() {
350         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
351         if [ ! -f $DIR/f6a ]; then
352                 touch $DIR/f6a
353                 chmod 0666 $DIR/f6a
354         fi
355         $RUNAS chmod 0444 $DIR/f6a && error
356         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
357 }
358 run_test 6b "$RUNAS chmod .../f6a (should return error) =="
359
360 test_6c() {
361         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
362         touch $DIR/f6c
363         chown $RUNAS_ID $DIR/f6c || error
364         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
365 }
366 run_test 6c "touch .../f6c; chown .../f6c ======================"
367
368 test_6d() {
369         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
370         if [ ! -f $DIR/f6c ]; then
371                 touch $DIR/f6c
372                 chown $RUNAS_ID $DIR/f6c
373         fi
374         $RUNAS chown $UID $DIR/f6c && error
375         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
376 }
377 run_test 6d "$RUNAS chown .../f6c (should return error) =="
378
379 test_6e() {
380         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
381         touch $DIR/f6e
382         chgrp $RUNAS_ID $DIR/f6e || error
383         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
384 }
385 run_test 6e "touch .../f6e; chgrp .../f6e ======================"
386
387 test_6f() {
388         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
389         if [ ! -f $DIR/f6e ]; then
390                 touch $DIR/f6e
391                 chgrp $RUNAS_ID $DIR/f6e
392         fi
393         $RUNAS chgrp $UID $DIR/f6e && error
394         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
395 }
396 run_test 6f "$RUNAS chgrp .../f6e (should return error) =="
397
398 test_6g() {
399         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
400         mkdir $DIR/d6g || error
401         chmod 777 $DIR/d6g || error
402         $RUNAS mkdir $DIR/d6g/d || error
403         chmod g+s $DIR/d6g/d || error
404         mkdir $DIR/d6g/d/subdir
405         $CHECKSTAT -g \#$RUNAS_ID $DIR/d6g/d/subdir || error
406 }
407 run_test 6g "Is new dir in sgid dir inheriting group?"
408
409 test_6h() { # bug 7331
410         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
411         touch $DIR/f6h || error "touch failed"
412         chown $RUNAS_ID:$RUNAS_ID $DIR/f6h || error "initial chown failed"
413         $RUNAS -G$RUNAS_ID chown $RUNAS_ID:0 $DIR/f6h && error "chown worked"
414         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_ID $DIR/f6h || error
415 }
416 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
417
418 test_7a() {
419         mkdir $DIR/d7
420         $MCREATE $DIR/d7/f
421         chmod 0666 $DIR/d7/f
422         $CHECKSTAT -t file -p 0666 $DIR/d7/f || error
423 }
424 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
425
426 test_7b() {
427         if [ ! -d $DIR/d7 ]; then
428                 mkdir $DIR/d7
429         fi
430         $MCREATE $DIR/d7/f2
431         echo -n foo > $DIR/d7/f2
432         [ "`cat $DIR/d7/f2`" = "foo" ] || error
433         $CHECKSTAT -t file -s 3 $DIR/d7/f2 || error
434 }
435 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
436
437 test_8() {
438         mkdir $DIR/d8
439         touch $DIR/d8/f
440         chmod 0666 $DIR/d8/f
441         $CHECKSTAT -t file -p 0666 $DIR/d8/f || error
442 }
443 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
444
445 test_9() {
446         mkdir $DIR/d9
447         mkdir $DIR/d9/d2
448         mkdir $DIR/d9/d2/d3
449         $CHECKSTAT -t dir $DIR/d9/d2/d3 || error
450 }
451 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
452
453 test_10() {
454         mkdir $DIR/d10
455         mkdir $DIR/d10/d2
456         touch $DIR/d10/d2/f
457         $CHECKSTAT -t file $DIR/d10/d2/f || error
458 }
459 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
460
461 test_11() {
462         mkdir $DIR/d11
463         mkdir $DIR/d11/d2
464         chmod 0666 $DIR/d11/d2
465         chmod 0705 $DIR/d11/d2
466         $CHECKSTAT -t dir -p 0705 $DIR/d11/d2 || error
467 }
468 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
469
470 test_12() {
471         mkdir $DIR/d12
472         touch $DIR/d12/f
473         chmod 0666 $DIR/d12/f
474         chmod 0654 $DIR/d12/f
475         $CHECKSTAT -t file -p 0654 $DIR/d12/f || error
476 }
477 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
478
479 test_13() {
480         mkdir $DIR/d13
481         dd if=/dev/zero of=$DIR/d13/f count=10
482         >  $DIR/d13/f
483         $CHECKSTAT -t file -s 0 $DIR/d13/f || error
484 }
485 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
486
487 test_14() {
488         mkdir $DIR/d14
489         touch $DIR/d14/f
490         rm $DIR/d14/f
491         $CHECKSTAT -a $DIR/d14/f || error
492 }
493 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
494
495 test_15() {
496         mkdir $DIR/d15
497         touch $DIR/d15/f
498         mv $DIR/d15/f $DIR/d15/f2
499         $CHECKSTAT -t file $DIR/d15/f2 || error
500 }
501 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
502
503 test_16() {
504         mkdir $DIR/d16
505         touch $DIR/d16/f
506         rm -rf $DIR/d16/f
507         $CHECKSTAT -a $DIR/d16/f || error
508 }
509 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
510
511 test_17a() {
512         mkdir -p $DIR/d17
513         touch $DIR/d17/f
514         ln -s $DIR/d17/f $DIR/d17/l-exist
515         ls -l $DIR/d17
516         $CHECKSTAT -l $DIR/d17/f $DIR/d17/l-exist || error
517         $CHECKSTAT -f -t f $DIR/d17/l-exist || error
518         rm -f $DIR/d17/l-exist
519         $CHECKSTAT -a $DIR/d17/l-exist || error
520 }
521 run_test 17a "symlinks: create, remove (real) =================="
522
523 test_17b() {
524         mkdir -p $DIR/d17
525         ln -s no-such-file $DIR/d17/l-dangle
526         ls -l $DIR/d17
527         $CHECKSTAT -l no-such-file $DIR/d17/l-dangle || error
528         $CHECKSTAT -fa $DIR/d17/l-dangle || error
529         rm -f $DIR/d17/l-dangle
530         $CHECKSTAT -a $DIR/d17/l-dangle || error
531 }
532 run_test 17b "symlinks: create, remove (dangling) =============="
533
534 test_17c() { # bug 3440 - don't save failed open RPC for replay
535         mkdir -p $DIR/d17
536         ln -s foo $DIR/d17/f17c
537         cat $DIR/d17/f17c && error "opened non-existent symlink" || true
538 }
539 run_test 17c "symlinks: open dangling (should return error) ===="
540
541 test_17d() {
542         mkdir -p $DIR/d17
543         ln -s foo $DIR/d17/f17d
544         touch $DIR/d17/f17d || error "creating to new symlink"
545 }
546 run_test 17d "symlinks: create dangling ========================"
547
548 test_18() {
549         touch $DIR/f
550         ls $DIR || error
551 }
552 run_test 18 "touch .../f ; ls ... =============================="
553
554 test_19a() {
555         touch $DIR/f19
556         ls -l $DIR
557         rm $DIR/f19
558         $CHECKSTAT -a $DIR/f19 || error
559 }
560 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
561
562 test_19b() {
563         ls -l $DIR/f19 && error || true
564 }
565 run_test 19b "ls -l .../f19 (should return error) =============="
566
567 test_19c() {
568         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
569         $RUNAS touch $DIR/f19 && error || true
570 }
571 run_test 19c "$RUNAS touch .../f19 (should return error) =="
572
573 test_19d() {
574         cat $DIR/f19 && error || true
575 }
576 run_test 19d "cat .../f19 (should return error) =============="
577
578 test_20() {
579         touch $DIR/f
580         rm $DIR/f
581         log "1 done"
582         touch $DIR/f
583         rm $DIR/f
584         log "2 done"
585         touch $DIR/f
586         rm $DIR/f
587         log "3 done"
588         $CHECKSTAT -a $DIR/f || error
589 }
590 run_test 20 "touch .../f ; ls -l ... ==========================="
591
592 test_21() {
593         mkdir $DIR/d21
594         [ -f $DIR/d21/dangle ] && rm -f $DIR/d21/dangle
595         ln -s dangle $DIR/d21/link
596         echo foo >> $DIR/d21/link
597         cat $DIR/d21/dangle
598         $CHECKSTAT -t link $DIR/d21/link || error
599         $CHECKSTAT -f -t file $DIR/d21/link || error
600 }
601 run_test 21 "write to dangling link ============================"
602
603 test_22() {
604         WDIR=$DIR/$tdir
605         mkdir $WDIR
606         chown $RUNAS_ID $WDIR
607         (cd $WDIR || error "cd $WDIR failed";
608         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
609         $RUNAS tar xf -)
610         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
611         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
612         $CHECKSTAT -u \#$RUNAS_ID $WDIR/etc || error "checkstat -u failed"
613 }
614 run_test 22 "unpack tar archive as non-root user ==============="
615
616 test_23() {
617         mkdir $DIR/d23
618         $TOEXCL $DIR/d23/f23
619         $TOEXCL -e $DIR/d23/f23 || error
620 }
621 run_test 23 "O_CREAT|O_EXCL in subdir =========================="
622
623 test_24a() {
624         echo '== rename sanity =============================================='
625         echo '-- same directory rename'
626         mkdir $DIR/R1
627         touch $DIR/R1/f
628         mv $DIR/R1/f $DIR/R1/g
629         $CHECKSTAT -t file $DIR/R1/g || error
630 }
631 run_test 24a "touch .../R1/f; rename .../R1/f .../R1/g ========="
632
633 test_24b() {
634         mkdir $DIR/R2
635         touch $DIR/R2/{f,g}
636         mv $DIR/R2/f $DIR/R2/g
637         $CHECKSTAT -a $DIR/R2/f || error
638         $CHECKSTAT -t file $DIR/R2/g || error
639 }
640 run_test 24b "touch .../R2/{f,g}; rename .../R2/f .../R2/g ====="
641
642 test_24c() {
643         mkdir $DIR/R3
644         mkdir $DIR/R3/f
645         mv $DIR/R3/f $DIR/R3/g
646         $CHECKSTAT -a $DIR/R3/f || error
647         $CHECKSTAT -t dir $DIR/R3/g || error
648 }
649 run_test 24c "mkdir .../R3/f; rename .../R3/f .../R3/g ========="
650
651 test_24d() {
652         mkdir $DIR/R4
653         mkdir $DIR/R4/{f,g}
654         mrename $DIR/R4/f $DIR/R4/g
655         $CHECKSTAT -a $DIR/R4/f || error
656         $CHECKSTAT -t dir $DIR/R4/g || error
657 }
658 run_test 24d "mkdir .../R4/{f,g}; rename .../R4/f .../R4/g ====="
659
660 test_24e() {
661         echo '-- cross directory renames --' 
662         mkdir $DIR/R5{a,b}
663         touch $DIR/R5a/f
664         mv $DIR/R5a/f $DIR/R5b/g
665         $CHECKSTAT -a $DIR/R5a/f || error
666         $CHECKSTAT -t file $DIR/R5b/g || error
667 }
668 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
669
670 test_24f() {
671         mkdir $DIR/R6{a,b}
672         touch $DIR/R6a/f $DIR/R6b/g
673         mv $DIR/R6a/f $DIR/R6b/g
674         $CHECKSTAT -a $DIR/R6a/f || error
675         $CHECKSTAT -t file $DIR/R6b/g || error
676 }
677 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
678
679 test_24g() {
680         mkdir $DIR/R7{a,b}
681         mkdir $DIR/R7a/d
682         mv $DIR/R7a/d $DIR/R7b/e
683         $CHECKSTAT -a $DIR/R7a/d || error
684         $CHECKSTAT -t dir $DIR/R7b/e || error
685 }
686 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R5b/e ======"
687
688 test_24h() {
689         mkdir $DIR/R8{a,b}
690         mkdir $DIR/R8a/d $DIR/R8b/e
691         mrename $DIR/R8a/d $DIR/R8b/e
692         $CHECKSTAT -a $DIR/R8a/d || error
693         $CHECKSTAT -t dir $DIR/R8b/e || error
694 }
695 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
696
697 test_24i() {
698         echo "-- rename error cases"
699         mkdir $DIR/R9
700         mkdir $DIR/R9/a
701         touch $DIR/R9/f
702         mrename $DIR/R9/f $DIR/R9/a
703         $CHECKSTAT -t file $DIR/R9/f || error
704         $CHECKSTAT -t dir  $DIR/R9/a || error
705         $CHECKSTAT -a file $DIR/R9/a/f || error
706 }
707 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
708
709 test_24j() {
710         mkdir $DIR/R10
711         mrename $DIR/R10/f $DIR/R10/g
712         $CHECKSTAT -t dir $DIR/R10 || error
713         $CHECKSTAT -a $DIR/R10/f || error
714         $CHECKSTAT -a $DIR/R10/g || error
715 }
716 run_test 24j "source does not exist ============================" 
717
718 test_24k() {
719         mkdir $DIR/R11a $DIR/R11a/d
720         touch $DIR/R11a/f
721         mv $DIR/R11a/f $DIR/R11a/d
722         $CHECKSTAT -a $DIR/R11a/f || error
723         $CHECKSTAT -t file $DIR/R11a/d/f || error
724 }
725 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
726
727 # bug 2429 - rename foo foo foo creates invalid file
728 test_24l() {
729         f="$DIR/f24l"
730         multiop $f OcNs || error
731 }
732 run_test 24l "Renaming a file to itself ========================"
733
734 test_24m() {
735         f="$DIR/f24m"
736         multiop $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
737         # on ext3 this does not remove either the source or target files
738         # though the "expected" operation would be to remove the source
739         $CHECKSTAT -t file ${f} || error "${f} missing"
740         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
741 }
742 run_test 24m "Renaming a file to a hard link to itself ========="
743
744 test_24n() {
745     f="$DIR/f24n"
746     # this stats the old file after it was renamed, so it should fail
747     touch ${f}
748     $CHECKSTAT ${f}
749     mv ${f} ${f}.rename
750     $CHECKSTAT ${f}.rename
751     $CHECKSTAT -a ${f}
752 }
753 run_test 24n "Statting the old file after renaming (Posix rename 2)"
754
755 test_24o() {
756         check_kernel_version 37 || return 0
757         mkdir -p $DIR/d24o
758         rename_many -s random -v -n 10 $DIR/d24o
759 }
760 run_test 24o "rename of files during htree split ==============="
761
762 test_24p() {
763         mkdir $DIR/R12{a,b}
764         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
765         mrename $DIR/R12a $DIR/R12b
766         $CHECKSTAT -a $DIR/R12a || error
767         $CHECKSTAT -t dir $DIR/R12b || error
768         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
769         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
770 }
771 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
772
773 test_24q() {
774         mkdir $DIR/R13{a,b}
775         DIRINO=`ls -lid $DIR/R13a | awk '{ print $1 }'`
776         multiop $DIR/R13b D_c &
777         MULTIPID=$!
778         usleep 500
779
780         mrename $DIR/R13a $DIR/R13b
781         $CHECKSTAT -a $DIR/R13a || error
782         $CHECKSTAT -t dir $DIR/R13b || error
783         DIRINO2=`ls -lid $DIR/R13b | awk '{ print $1 }'`
784         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
785         kill -USR1 $MULTIPID
786         wait $MULTIPID || error "multiop close failed"
787 }
788 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
789
790 test_24r() { #bug 3789
791         mkdir $DIR/R14a $DIR/R14a/b
792         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
793         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
794         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
795 }
796 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
797
798 test_24s() {
799         mkdir $DIR/R15a $DIR/R15a/b $DIR/R15a/b/c
800         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
801         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
802         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
803 }
804 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
805 test_24t() {
806         mkdir $DIR/R16a $DIR/R16a/b $DIR/R16a/b/c
807         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
808         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
809         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
810 }
811 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
812
813 test_25a() {
814         echo '== symlink sanity ============================================='
815
816         mkdir $DIR/d25
817         ln -s d25 $DIR/s25
818         touch $DIR/s25/foo || error
819 }
820 run_test 25a "create file in symlinked directory ==============="
821
822 test_25b() {
823         [ ! -d $DIR/d25 ] && test_25a
824         $CHECKSTAT -t file $DIR/s25/foo || error
825 }
826 run_test 25b "lookup file in symlinked directory ==============="
827
828 test_26a() {
829         mkdir $DIR/d26
830         mkdir $DIR/d26/d26-2
831         ln -s d26/d26-2 $DIR/s26
832         touch $DIR/s26/foo || error
833 }
834 run_test 26a "multiple component symlink ======================="
835
836 test_26b() {
837         mkdir -p $DIR/d26b/d26-2
838         ln -s d26b/d26-2/foo $DIR/s26-2
839         touch $DIR/s26-2 || error
840 }
841 run_test 26b "multiple component symlink at end of lookup ======"
842
843 test_26c() {
844         mkdir $DIR/d26.2
845         touch $DIR/d26.2/foo
846         ln -s d26.2 $DIR/s26.2-1
847         ln -s s26.2-1 $DIR/s26.2-2
848         ln -s s26.2-2 $DIR/s26.2-3
849         chmod 0666 $DIR/s26.2-3/foo
850 }
851 run_test 26c "chain of symlinks ================================"
852
853 # recursive symlinks (bug 439)
854 test_26d() {
855         ln -s d26-3/foo $DIR/d26-3
856 }
857 run_test 26d "create multiple component recursive symlink ======"
858
859 test_26e() {
860         [ ! -h $DIR/d26-3 ] && test_26d
861         rm $DIR/d26-3
862 }
863 run_test 26e "unlink multiple component recursive symlink ======"
864
865 # recursive symlinks (bug 7022)
866 test_26f() {
867         mkdir $DIR/$tfile        || error "mkdir $DIR/$tfile failed"
868         cd $DIR/$tfile           || error "cd $DIR/$tfile failed"
869         mkdir -p $tdir/bar1      || error "mkdir $tdir/bar1 failed"
870         mkdir $tfile             || error "mkdir $tfile failed"
871         cd $tfile                || error "cd $tfile failed"
872         ln -s .. dotdot          || error "ln dotdot failed"
873         ln -s dotdot/$tdir $tdir || error "ln $tdir failed"
874         cd ../..                 || error "cd ../.. failed"
875         output=`ls $tfile/$tfile/$tdir/bar1`
876         [ "$output" = bar1 ] && error "unexpected output"
877         rm -r $tfile             || error "rm $tfile failed"
878         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
879 }
880 run_test 26f "rm -r of a directory which has recursive symlink ="
881
882 test_27a() {
883         echo '== stripe sanity =============================================='
884         mkdir -p $DIR/d27 || error "mkdir failed"
885         $SETSTRIPE $DIR/d27/f0 65536 0 1 || error "lstripe failed"
886         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
887         pass
888         log "== test_27b: write to one stripe file ========================="
889         cp /etc/hosts $DIR/d27/f0 || error
890 }
891 run_test 27a "one stripe file =================================="
892
893 test_27c() {
894         [ "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
895         mkdir -p $DIR/d27
896         $SETSTRIPE $DIR/d27/f01 65536 0 2 || error "lstripe failed"
897         [ `$GETSTRIPE $DIR/d27/f01 | grep -A 10 obdidx | wc -l` -eq 4 ] ||
898                 error "two-stripe file doesn't have two stripes"
899         pass
900         log "== test_27d: write to two stripe file file f01 ================"
901         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
902 }
903 run_test 27c "create two stripe file f01 ======================="
904
905 test_27d() {
906         mkdir -p $DIR/d27
907         $SETSTRIPE $DIR/d27/fdef 0 -1 0 || error "lstripe failed"
908         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
909         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
910 }
911 run_test 27d "create file with default settings ================"
912
913 test_27e() {
914         mkdir -p $DIR/d27
915         $SETSTRIPE $DIR/d27/f12 65536 0 2 || error "lstripe failed"
916         $SETSTRIPE $DIR/d27/f12 65536 0 2 && error "lstripe succeeded twice"
917         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
918 }
919 run_test 27e "lstripe existing file (should return error) ======"
920
921 test_27f() {
922         mkdir -p $DIR/d27
923         $SETSTRIPE $DIR/d27/fbad 100 0 1 && error "lstripe failed"
924         dd if=/dev/zero of=$DIR/d27/f12 bs=4k count=4 || error "dd failed"
925         $GETSTRIPE $DIR/d27/fbad || error "lfs getstripe failed"
926 }
927 run_test 27f "lstripe with bad stripe size (should return error)"
928
929 test_27g() {
930         mkdir -p $DIR/d27
931         $MCREATE $DIR/d27/fnone || error "mcreate failed"
932         pass
933         log "== test 27h: lfs getstripe with no objects ===================="
934         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" || error "has object"
935         pass
936         log "== test 27i: lfs getstripe with some objects =================="
937         touch $DIR/d27/fsome || error "touch failed"
938         $GETSTRIPE $DIR/d27/fsome | grep obdidx || error "missing objects"
939 }
940 run_test 27g "test lfs getstripe ==========================================="
941
942 test_27j() {
943         mkdir -p $DIR/d27
944         $SETSTRIPE $DIR/d27/f27j 65536 $OSTCOUNT 1 && error "lstripe failed"||true
945 }
946 run_test 27j "lstripe with bad stripe offset (should return error)"
947
948 test_27k() { # bug 2844
949         mkdir -p $DIR/d27
950         FILE=$DIR/d27/f27k
951         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
952         [ ! -d $DIR/d27 ] && mkdir -p $DIR/d27
953         $SETSTRIPE $FILE 67108864 -1 0 || error "lstripe failed"
954         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
955         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
956         dd if=/dev/zero of=$FILE bs=4k count=1
957         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
958         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
959 }
960 run_test 27k "limit i_blksize for broken user apps ============="
961
962 test_27l() {
963         mkdir -p $DIR/d27
964         mcreate $DIR/f27l || error "creating file"
965         $RUNAS $SETSTRIPE $DIR/f27l 65536 -1 1 && \
966                 error "lstripe should have failed" || true
967 }
968 run_test 27l "check setstripe permissions (should return error)"
969
970 test_27m() {
971         [ "$OSTCOUNT" -lt "2" ] && echo "skipping out-of-space test on OST0" && return
972         if [ $ORIGFREE -gt $MAXFREE ]; then
973                 echo "skipping out-of-space test on OST0"
974                 return
975         fi
976         mkdir -p $DIR/d27
977         $SETSTRIPE $DIR/d27/f27m_1 0 0 1
978         dd if=/dev/zero of=$DIR/d27/f27m_1 bs=1024 count=$MAXFREE && \
979                 error "dd should fill OST0"
980         i=2
981         while $SETSTRIPE $DIR/d27/f27m_$i 0 0 1 ; do
982                 i=`expr $i + 1`
983                 [ $i -gt 256 ] && break
984         done
985         i=`expr $i + 1`
986         touch $DIR/d27/f27m_$i
987         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
988                 error "OST0 was full but new created file still use it"
989         i=`expr $i + 1`
990         touch $DIR/d27/f27m_$i
991         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
992                 error "OST0 was full but new created file still use it"
993         rm -r $DIR/d27
994 }
995 run_test 27m "create file while OST0 was full =================="
996
997 # osc's keep a NOSPC stick flag that gets unset with rmdir
998 reset_enospc() {
999         [ "$1" ] && FAIL_LOC=$1 || FAIL_LOC=0
1000         mkdir -p $DIR/d27/nospc
1001         rmdir $DIR/d27/nospc
1002         sysctl -w lustre.fail_loc=$FAIL_LOC
1003 }
1004
1005 exhaust_precreations() {
1006         OSTIDX=$1
1007         OST=$(grep ${OSTIDX}": " $LPROC/lov/${LOVNAME}/target_obd | \
1008             awk '{print $2}' | sed -e 's/_UUID$//')
1009         # on the mdt's osc
1010         last_id=$(cat $LPROC/osc/${OST}-osc/prealloc_last_id)
1011         next_id=$(cat $LPROC/osc/${OST}-osc/prealloc_next_id)
1012
1013         mkdir -p $DIR/d27/${OST}
1014         $SETSTRIPE $DIR/d27/${OST} 0 $OSTIDX 1
1015         #define OBD_FAIL_OST_ENOSPC 0x215
1016         sysctl -w lustre.fail_loc=0x215
1017         echo "Creating to objid $last_id on ost $OST..."
1018         createmany -o $DIR/d27/${OST}/f $next_id $((last_id - next_id + 2))
1019         grep '[0-9]' $LPROC/osc/${OST}-osc/prealloc*
1020         reset_enospc $2
1021 }
1022
1023 exhaust_all_precreations() {
1024         local i
1025         for (( i=0; i < OSTCOUNT; i++ )) ; do
1026                 exhaust_precreations $i 0x215
1027         done
1028         reset_enospc $1
1029 }
1030
1031 test_27n() {
1032         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && \
1033                 echo "skip $TESTNAME for remote MDS or OST count" && return
1034
1035         reset_enospc
1036         rm -f $DIR/d27/f27n
1037         exhaust_precreations 0 0x80000215
1038
1039         touch $DIR/d27/f27n || error
1040
1041         reset_enospc
1042 }
1043 run_test 27n "create file with some full OSTs =================="
1044
1045 test_27o() {
1046         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1047
1048         reset_enospc
1049         rm -f $DIR/d27/f27o
1050         exhaust_all_precreations 0x215
1051         sleep 5
1052
1053         touch $DIR/d27/f27o && error "able to create $DIR/d27/f27o"
1054
1055         reset_enospc
1056 }
1057 run_test 27o "create file with all full OSTs (should error) ===="
1058
1059 test_27p() {
1060         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1061
1062         reset_enospc
1063         rm -f $DIR/d27/f27p
1064
1065         $MCREATE $DIR/d27/f27p || error
1066         $TRUNCATE $DIR/d27/f27p 80000000 || error
1067         $CHECKSTAT -s 80000000 $DIR/d27/f27p || error
1068
1069         exhaust_precreations 0 0x80000215
1070         echo foo >> $DIR/d27/f27p || error
1071         $CHECKSTAT -s 80000004 $DIR/d27/f27p || error
1072
1073         reset_enospc
1074 }
1075 run_test 27p "append to a truncated file with some full OSTs ==="
1076
1077 test_27q() {
1078         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1079
1080         reset_enospc
1081         rm -f $DIR/d27/f27q
1082
1083         $MCREATE $DIR/d27/f27q || error "mcreate $DIR/d27/f27q failed"
1084         $TRUNCATE $DIR/d27/f27q 80000000 ||error "truncate $DIR/d27/f27q failed"
1085         $CHECKSTAT -s 80000000 $DIR/d27/f27q || error "checkstat failed"
1086
1087         exhaust_all_precreations 0x215
1088
1089         echo foo >> $DIR/d27/f27q && error "append succeeded"
1090         $CHECKSTAT -s 80000000 $DIR/d27/f27q || error "checkstat 2 failed"
1091
1092         reset_enospc
1093 }
1094 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1095
1096 test_27r() {
1097         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1098
1099         reset_enospc
1100         rm -f $DIR/d27/f27r
1101         exhaust_precreations 0 0x80000215
1102
1103         $SETSTRIPE $DIR/d27/f27r 0 0 2 # && error
1104
1105         reset_enospc
1106 }
1107 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1108
1109 test_27s() { # bug 10725
1110         mkdir -p $DIR/$tdir
1111         $LSTRIPE $DIR/$tdir $((2048 * 1024 * 1024)) -1 2 && \
1112                 error "stripe width >= 2^32 succeeded" || true
1113 }
1114 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1115
1116 test_27t() { # bug 10864
1117         WDIR=`pwd`
1118         WLFS=`which lfs`
1119         cd $DIR
1120         touch $tfile
1121         $WLFS getstripe $tfile
1122         cd $WDIR
1123 }
1124 run_test 27t "check that utils parse path correctly"
1125
1126 test_27x() { # bug 10997
1127         mkdir -p $DIR/d27w || error "mkdir failed"
1128         $LSTRIPE $DIR/d27w/f0 -s 65536 || error "lstripe failed"
1129         size=`$LSTRIPEINFO $DIR/d27w/f0 | awk {'print $1'}`
1130         [ $size -ne 65536 ] && error "stripe size $size != 65536" || true
1131
1132         [ "$OSTCOUNT" -lt "2" ] && echo "skipping multiple stripe count/offset test" && return
1133         for i in `seq 1 $OSTCOUNT`; do
1134                 offset=$(($i-1))
1135                 $LSTRIPE $DIR/d27w/f$i -c $i -i $offset || error "lstripe -c $i -i $offset failed"
1136                 count=`$LSTRIPEINFO $DIR/d27w/f$i | awk {'print $2'}`
1137                 index=`$LSTRIPEINFO $DIR/d27w/f$i | awk {'print $3'}`
1138                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1139                 [ $index -ne $offset ] && error "stripe offset $index != $offset" || true
1140         done
1141 }
1142 run_test 27x "check lfs setstripe -c -s -i options ============="
1143
1144 test_28() {
1145         mkdir $DIR/d28
1146         $CREATETEST $DIR/d28/ct || error
1147 }
1148 run_test 28 "create/mknod/mkdir with bad file types ============"
1149
1150 test_29() {
1151         cancel_lru_locks mdc
1152         mkdir $DIR/d29
1153         touch $DIR/d29/foo
1154         log 'first d29'
1155         ls -l $DIR/d29
1156         MDCDIR=${MDCDIR:-`find $LPROC/ldlm/namespaces | grep mdc | head -1`}
1157         LOCKCOUNTORIG=`cat $MDCDIR/lock_count`
1158         LOCKUNUSEDCOUNTORIG=`cat $MDCDIR/lock_unused_count`
1159         [ -z $"LOCKCOUNTORIG" ] && echo "No mdc lock count" && return 1
1160         log 'second d29'
1161         ls -l $DIR/d29
1162         log 'done'
1163         LOCKCOUNTCURRENT=`cat $MDCDIR/lock_count`
1164         LOCKUNUSEDCOUNTCURRENT=`cat $MDCDIR/lock_unused_count`
1165         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1166                 echo > $LPROC/ldlm/dump_namespaces
1167                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1168                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1169                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1170                 return 2
1171         fi
1172         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1173                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1174                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1175                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1176                 return 3
1177         fi
1178 }
1179 run_test 29 "IT_GETATTR regression  ============================"
1180
1181 test_30() {
1182         cp `which ls` $DIR
1183         $DIR/ls /
1184         rm $DIR/ls
1185 }
1186 run_test 30 "run binary from Lustre (execve) ==================="
1187
1188 test_31a() {
1189         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1190         $CHECKSTAT -a $DIR/f31 || error
1191 }
1192 run_test 31a "open-unlink file =================================="
1193
1194 test_31b() {
1195         touch $DIR/f31 || error
1196         ln $DIR/f31 $DIR/f31b || error
1197         multiop $DIR/f31b Ouc || error
1198         $CHECKSTAT -t file $DIR/f31 || error
1199 }
1200 run_test 31b "unlink file with multiple links while open ======="
1201
1202 test_31c() {
1203         touch $DIR/f31 || error
1204         ln $DIR/f31 $DIR/f31c || error
1205         multiop $DIR/f31 O_uc &
1206         MULTIPID=$!
1207         multiop $DIR/f31c Ouc
1208         usleep 500
1209         kill -USR1 $MULTIPID
1210         wait $MULTIPID
1211 }
1212 run_test 31c "open-unlink file with multiple links ============="
1213
1214 test_31d() {
1215         opendirunlink $DIR/d31d $DIR/d31d || error
1216         $CHECKSTAT -a $DIR/d31d || error
1217 }
1218 run_test 31d "remove of open directory ========================="
1219
1220 test_31e() { # bug 2904
1221         check_kernel_version 34 || return 0
1222         openfilleddirunlink $DIR/d31e || error
1223 }
1224 run_test 31e "remove of open non-empty directory ==============="
1225
1226 test_31f() { # bug 4554
1227         set -vx
1228         mkdir $DIR/d31f
1229         lfs setstripe $DIR/d31f 1048576 -1 1
1230         cp /etc/hosts $DIR/d31f
1231         ls -l $DIR/d31f
1232         lfs getstripe $DIR/d31f/hosts
1233         multiop $DIR/d31f D_c &
1234         MULTIPID=$!
1235
1236         sleep 1
1237
1238         rm -rv $DIR/d31f || error "first of $DIR/d31f"
1239         mkdir $DIR/d31f
1240         lfs setstripe $DIR/d31f 1048576 -1 1
1241         cp /etc/hosts $DIR/d31f
1242         ls -l $DIR/d31f
1243         lfs getstripe $DIR/d31f/hosts
1244         multiop $DIR/d31f D_c &
1245         MULTIPID2=$!
1246
1247         sleep 6
1248
1249         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
1250         wait $MULTIPID || error "first opendir $MULTIPID failed"
1251
1252         sleep 6
1253
1254         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
1255         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
1256         set +vx
1257 }
1258 run_test 31f "remove of open directory with open-unlink file ==="
1259
1260 test_32a() {
1261         echo "== more mountpoints and symlinks ================="
1262         [ -e $DIR/d32a ] && rm -fr $DIR/d32a
1263         mkdir -p $DIR/d32a/ext2-mountpoint 
1264         mount -t ext2 -o loop $EXT2_DEV $DIR/d32a/ext2-mountpoint || error
1265         $CHECKSTAT -t dir $DIR/d32a/ext2-mountpoint/.. || error  
1266         $UMOUNT $DIR/d32a/ext2-mountpoint || error
1267 }
1268 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
1269
1270 test_32b() {
1271         [ -e $DIR/d32b ] && rm -fr $DIR/d32b
1272         mkdir -p $DIR/d32b/ext2-mountpoint 
1273         mount -t ext2 -o loop $EXT2_DEV $DIR/d32b/ext2-mountpoint || error
1274         ls -al $DIR/d32b/ext2-mountpoint/.. || error
1275         $UMOUNT $DIR/d32b/ext2-mountpoint || error
1276 }
1277 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
1278  
1279 test_32c() {
1280         [ -e $DIR/d32c ] && rm -fr $DIR/d32c
1281         mkdir -p $DIR/d32c/ext2-mountpoint 
1282         mount -t ext2 -o loop $EXT2_DEV $DIR/d32c/ext2-mountpoint || error
1283         mkdir -p $DIR/d32c/d2/test_dir    
1284         $CHECKSTAT -t dir $DIR/d32c/ext2-mountpoint/../d2/test_dir || error
1285         $UMOUNT $DIR/d32c/ext2-mountpoint || error
1286 }
1287 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
1288
1289 test_32d() {
1290         [ -e $DIR/d32d ] && rm -fr $DIR/d32d
1291         mkdir -p $DIR/d32d/ext2-mountpoint 
1292         mount -t ext2 -o loop $EXT2_DEV $DIR/d32d/ext2-mountpoint || error
1293         mkdir -p $DIR/d32d/d2/test_dir    
1294         ls -al $DIR/d32d/ext2-mountpoint/../d2/test_dir || error
1295         $UMOUNT $DIR/d32d/ext2-mountpoint || error
1296 }
1297 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
1298
1299 test_32e() {
1300         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
1301         mkdir -p $DIR/d32e/tmp    
1302         TMP_DIR=$DIR/d32e/tmp       
1303         ln -s $DIR/d32e $TMP_DIR/symlink11 
1304         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1305         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
1306         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
1307 }
1308 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
1309
1310 test_32f() {
1311         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
1312         mkdir -p $DIR/d32f/tmp    
1313         TMP_DIR=$DIR/d32f/tmp       
1314         ln -s $DIR/d32f $TMP_DIR/symlink11 
1315         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1316         ls $DIR/d32f/tmp/symlink11  || error
1317         ls $DIR/d32f/symlink01 || error
1318 }
1319 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
1320
1321 test_32g() {
1322         TMP_DIR=$DIR/$tdir/tmp       
1323         mkdir -p $TMP_DIR $DIR/${tdir}2
1324         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12 
1325         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1326         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
1327         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
1328         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
1329         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
1330 }
1331 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1332
1333 test_32h() {
1334         rm -fr $DIR/$tdir $DIR/${tdir}2
1335         TMP_DIR=$DIR/$tdir/tmp       
1336         mkdir -p $TMP_DIR $DIR/${tdir}2 
1337         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12 
1338         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1339         ls $TMP_DIR/symlink12 || error
1340         ls $DIR/$tdir/symlink02  || error
1341 }
1342 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1343
1344 test_32i() {
1345         [ -e $DIR/d32i ] && rm -fr $DIR/d32i
1346         mkdir -p $DIR/d32i/ext2-mountpoint 
1347         mount -t ext2 -o loop $EXT2_DEV $DIR/d32i/ext2-mountpoint || error
1348         touch $DIR/d32i/test_file
1349         $CHECKSTAT -t file $DIR/d32i/ext2-mountpoint/../test_file || error  
1350         $UMOUNT $DIR/d32i/ext2-mountpoint || error
1351 }
1352 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
1353
1354 test_32j() {
1355         [ -e $DIR/d32j ] && rm -fr $DIR/d32j
1356         mkdir -p $DIR/d32j/ext2-mountpoint 
1357         mount -t ext2 -o loop $EXT2_DEV $DIR/d32j/ext2-mountpoint || error
1358         touch $DIR/d32j/test_file
1359         cat $DIR/d32j/ext2-mountpoint/../test_file || error
1360         $UMOUNT $DIR/d32j/ext2-mountpoint || error
1361 }
1362 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
1363
1364 test_32k() {
1365         rm -fr $DIR/d32k
1366         mkdir -p $DIR/d32k/ext2-mountpoint 
1367         mount -t ext2 -o loop $EXT2_DEV $DIR/d32k/ext2-mountpoint  
1368         mkdir -p $DIR/d32k/d2
1369         touch $DIR/d32k/d2/test_file || error
1370         $CHECKSTAT -t file $DIR/d32k/ext2-mountpoint/../d2/test_file || error
1371         $UMOUNT $DIR/d32k/ext2-mountpoint || error
1372 }
1373 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
1374
1375 test_32l() {
1376         rm -fr $DIR/d32l
1377         mkdir -p $DIR/d32l/ext2-mountpoint 
1378         mount -t ext2 -o loop $EXT2_DEV $DIR/d32l/ext2-mountpoint || error
1379         mkdir -p $DIR/d32l/d2
1380         touch $DIR/d32l/d2/test_file
1381         cat  $DIR/d32l/ext2-mountpoint/../d2/test_file || error
1382         $UMOUNT $DIR/d32l/ext2-mountpoint || error
1383 }
1384 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
1385
1386 test_32m() {
1387         rm -fr $DIR/d32m
1388         mkdir -p $DIR/d32m/tmp    
1389         TMP_DIR=$DIR/d32m/tmp       
1390         ln -s $DIR $TMP_DIR/symlink11 
1391         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1392         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
1393         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
1394 }
1395 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
1396
1397 test_32n() {
1398         rm -fr $DIR/d32n
1399         mkdir -p $DIR/d32n/tmp    
1400         TMP_DIR=$DIR/d32n/tmp       
1401         ln -s $DIR $TMP_DIR/symlink11 
1402         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1403         ls -l $DIR/d32n/tmp/symlink11  || error
1404         ls -l $DIR/d32n/symlink01 || error
1405 }
1406 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
1407
1408 test_32o() {
1409         rm -fr $DIR/d32o $DIR/$tfile
1410         touch $DIR/$tfile 
1411         mkdir -p $DIR/d32o/tmp    
1412         TMP_DIR=$DIR/d32o/tmp       
1413         ln -s $DIR/$tfile $TMP_DIR/symlink12 
1414         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1415         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
1416         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
1417         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
1418         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
1419 }
1420 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
1421
1422 test_32p() {
1423     log 32p_1
1424         rm -fr $DIR/d32p
1425     log 32p_2
1426         rm -f $DIR/$tfile
1427     log 32p_3
1428         touch $DIR/$tfile 
1429     log 32p_4
1430         mkdir -p $DIR/d32p/tmp    
1431     log 32p_5
1432         TMP_DIR=$DIR/d32p/tmp       
1433     log 32p_6
1434         ln -s $DIR/$tfile $TMP_DIR/symlink12 
1435     log 32p_7
1436         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1437     log 32p_8
1438         cat $DIR/d32p/tmp/symlink12 || error
1439     log 32p_9
1440         cat $DIR/d32p/symlink02 || error
1441     log 32p_10
1442 }
1443 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
1444
1445 test_32q() {
1446         [ -e $DIR/d32q ] && rm -fr $DIR/d32q
1447         mkdir -p $DIR/d32q
1448         touch $DIR/d32q/under_the_mount
1449         mount -t ext2 -o loop $EXT2_DEV $DIR/d32q
1450         ls $DIR/d32q/under_the_mount && error || true
1451         $UMOUNT $DIR/d32q || error
1452 }
1453 run_test 32q "stat follows mountpoints in Lustre (should return error)"
1454
1455 test_32r() {
1456         [ -e $DIR/d32r ] && rm -fr $DIR/d32r
1457         mkdir -p $DIR/d32r
1458         touch $DIR/d32r/under_the_mount
1459         mount -t ext2 -o loop $EXT2_DEV $DIR/d32r
1460         ls $DIR/d32r | grep -q under_the_mount && error || true
1461         $UMOUNT $DIR/d32r || error
1462 }
1463 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
1464
1465 test_33() {
1466         rm -f $DIR/$tfile
1467         touch $DIR/$tfile
1468         chmod 444 $DIR/$tfile
1469         chown $RUNAS_ID $DIR/$tfile
1470         log 33_1
1471         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
1472         log 33_2
1473 }
1474 run_test 33 "write file with mode 444 (should return error) ===="
1475
1476 test_33a() {
1477         rm -fr $DIR/d33
1478         mkdir -p $DIR/d33
1479         chown $RUNAS_ID $DIR/d33
1480         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
1481         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
1482                 error "open RDWR" || true
1483 }
1484 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
1485
1486 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
1487 test_34a() {
1488         rm -f $DIR/f34
1489         $MCREATE $DIR/f34 || error
1490         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1491         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
1492         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1493         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1494 }
1495 run_test 34a "truncate file that has not been opened ==========="
1496
1497 test_34b() {
1498         [ ! -f $DIR/f34 ] && test_34a
1499         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1500         $OPENFILE -f O_RDONLY $DIR/f34
1501         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1502         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1503 }
1504 run_test 34b "O_RDONLY opening file doesn't create objects ====="
1505
1506 test_34c() {
1507         [ ! -f $DIR/f34 ] && test_34a 
1508         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1509         $OPENFILE -f O_RDWR $DIR/f34
1510         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
1511         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1512 }
1513 run_test 34c "O_RDWR opening file-with-size works =============="
1514
1515 test_34d() {
1516         [ ! -f $DIR/f34 ] && test_34a 
1517         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
1518         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1519         rm $DIR/f34
1520 }
1521 run_test 34d "write to sparse file ============================="
1522
1523 test_34e() {
1524         rm -f $DIR/f34e
1525         $MCREATE $DIR/f34e || error
1526         $TRUNCATE $DIR/f34e 1000 || error
1527         $CHECKSTAT -s 1000 $DIR/f34e || error
1528         $OPENFILE -f O_RDWR $DIR/f34e
1529         $CHECKSTAT -s 1000 $DIR/f34e || error
1530 }
1531 run_test 34e "create objects, some with size and some without =="
1532
1533 test_34f() { # bug 6242, 6243
1534         SIZE34F=48000
1535         rm -f $DIR/f34f
1536         $MCREATE $DIR/f34f || error
1537         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
1538         dd if=$DIR/f34f of=$TMP/f34f
1539         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
1540         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
1541         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
1542         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
1543         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
1544 }
1545 run_test 34f "read from a file with no objects until EOF ======="
1546
1547 test_35a() {
1548         cp /bin/sh $DIR/f35a
1549         chmod 444 $DIR/f35a
1550         chown $RUNAS_ID $DIR/f35a
1551         $RUNAS $DIR/f35a && error || true
1552         rm $DIR/f35a
1553 }
1554 run_test 35a "exec file with mode 444 (should return and not leak) ====="
1555
1556 test_36a() {
1557         rm -f $DIR/f36
1558         utime $DIR/f36 || error
1559 }
1560 run_test 36a "MDS utime check (mknod, utime) ==================="
1561
1562 test_36b() {
1563         echo "" > $DIR/f36
1564         utime $DIR/f36 || error
1565 }
1566 run_test 36b "OST utime check (open, utime) ===================="
1567
1568 test_36c() {
1569         rm -f $DIR/d36/f36
1570         mkdir $DIR/d36
1571         chown $RUNAS_ID $DIR/d36
1572         $RUNAS utime $DIR/d36/f36 || error
1573 }
1574 run_test 36c "non-root MDS utime check (mknod, utime) =========="
1575
1576 test_36d() {
1577         [ ! -d $DIR/d36 ] && test_36c
1578         echo "" > $DIR/d36/f36
1579         $RUNAS utime $DIR/d36/f36 || error
1580 }
1581 run_test 36d "non-root OST utime check (open, utime) ==========="
1582
1583 test_36e() {
1584         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
1585         mkdir -p $DIR/$tdir
1586         touch $DIR/$tdir/$tfile
1587         $RUNAS utime $DIR/$tdir/$tfile && \
1588                 error "utime worked, expected failure" || true
1589 }
1590 run_test 36e "utime on non-owned file (should return error) ===="
1591
1592 test_36f() {
1593         export LANG=C LC_LANG=C # for date language
1594
1595         DATESTR="Dec 20  2000"
1596         mkdir -p $DIR/$tdir
1597         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
1598         sysctl -w lustre.fail_loc=0x80000214
1599         date; date +%s
1600         cp /etc/hosts $DIR/$tdir/$tfile
1601         sync & # write RPC generated with "current" inode timestamp, but delayed
1602         sleep 1
1603         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
1604         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
1605         cancel_lru_locks osc
1606         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
1607         date; date +%s
1608         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
1609                 echo "BEFORE: $LS_BEFORE" && \
1610                 echo "AFTER : $LS_AFTER" && \
1611                 echo "WANT  : $DATESTR" && \
1612                 error "$DIR/$tdir/$tfile timestamps changed" || true
1613 }
1614 run_test 36f "utime on file racing with OST BRW write =========="
1615
1616 export FMD_MAX_AGE=`cat $LPROC/obdfilter/*/client_cache_seconds 2> /dev/null | head -n 1`
1617 test_36g() {
1618         [ -z "$FMD_MAX_AGE" ] && echo "skip $TESTNAME for remote OST" && return
1619         FMD_BEFORE="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1620         touch $DIR/d36/$tfile
1621         sleep $((FMD_MAX_AGE + 12))
1622         FMD_AFTER="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1623         [ "$FMD_AFTER" -gt "$FMD_BEFORE" ] && \
1624                 echo "AFTER : $FMD_AFTER > BEFORE $FMD_BEFORE" && \
1625                 error "fmd didn't expire after ping" || true
1626 }
1627 run_test 36g "filter mod data cache expiry ====================="
1628
1629 test_37() {
1630         mkdir -p $DIR/$tdir
1631         echo f > $DIR/$tdir/fbugfile
1632         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
1633         ls $DIR/$tdir | grep "\<fbugfile\>" && error
1634         $UMOUNT $DIR/$tdir || error
1635         rm -f $DIR/$tdir/fbugfile || error
1636 }
1637 run_test 37 "ls a mounted file system to check old content ====="
1638
1639 test_38() {
1640         o_directory $DIR/$tfile
1641 }
1642 run_test 38 "open a regular file with O_DIRECTORY =============="
1643
1644 test_39() {
1645         touch $DIR/$tfile
1646         touch $DIR/${tfile}2
1647 #       ls -l  $DIR/$tfile $DIR/${tfile}2
1648 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
1649 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
1650         sleep 2
1651         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
1652         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
1653                 echo "mtime"
1654                 ls -l  $DIR/$tfile $DIR/${tfile}2
1655                 echo "atime"
1656                 ls -lu  $DIR/$tfile $DIR/${tfile}2
1657                 echo "ctime"
1658                 ls -lc  $DIR/$tfile $DIR/${tfile}2
1659                 error "O_TRUNC didn't change timestamps"
1660         fi
1661 }
1662 run_test 39 "mtime changed on create ==========================="
1663
1664 test_40() {
1665         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
1666         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
1667         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
1668 }
1669 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
1670
1671 test_41() {
1672         # bug 1553
1673         small_write $DIR/f41 18
1674 }
1675 run_test 41 "test small file write + fstat ====================="
1676
1677 count_ost_writes() {
1678         cat $LPROC/osc/*/stats |
1679             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
1680 }
1681
1682 # decent default
1683 WRITEBACK_SAVE=500
1684 DIRTY_RATIO_SAVE=40
1685 MAX_DIRTY_RATIO=50
1686 BG_DIRTY_RATIO_SAVE=10
1687 MAX_BG_DIRTY_RATIO=25
1688
1689 start_writeback() {
1690         trap 0
1691         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
1692         # dirty_ratio, dirty_background_ratio
1693         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1694                 echo $WRITEBACK_SAVE > /proc/sys/vm/dirty_writeback_centisecs
1695                 echo $BG_DIRTY_RATIO_SAVE > /proc/sys/vm/dirty_background_ratio
1696                 echo $DIRTY_RATIO_SAVE > /proc/sys/vm/dirty_ratio
1697         else
1698                 # if file not here, we are a 2.4 kernel
1699                 kill -CONT `pidof kupdated`
1700         fi
1701 }
1702
1703 stop_writeback() {
1704         # setup the trap first, so someone cannot exit the test at the
1705         # exact wrong time and mess up a machine
1706         trap start_writeback EXIT
1707         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
1708         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1709                 WRITEBACK_SAVE=`cat /proc/sys/vm/dirty_writeback_centisecs`
1710                 echo 0 > /proc/sys/vm/dirty_writeback_centisecs
1711                 # save and increase /proc/sys/vm/dirty_ratio
1712                 DIRTY_RATIO_SAVE=`cat /proc/sys/vm/dirty_ratio`
1713                 echo $MAX_DIRTY_RATIO > /proc/sys/vm/dirty_ratio
1714                 # save and increase /proc/sys/vm/dirty_background_ratio
1715                 BG_DIRTY_RATIO_SAVE=`cat /proc/sys/vm/dirty_background_ratio`
1716                 echo $MAX_BG_DIRTY_RATIO > /proc/sys/vm/dirty_background_ratio
1717         else
1718                 # if file not here, we are a 2.4 kernel
1719                 kill -STOP `pidof kupdated`
1720         fi
1721 }
1722
1723 # ensure that all stripes have some grant before we test client-side cache
1724 setup_test42() {
1725         [ "$SETUP_TEST42" ] && return
1726         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
1727                 dd if=/dev/zero of=$i bs=4k count=1
1728                 rm $i
1729         done
1730         SETUP_TEST42=DONE
1731 }
1732
1733 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
1734 # file truncation, and file removal.
1735 test_42a() {
1736         setup_test42
1737         cancel_lru_locks osc
1738         stop_writeback
1739         sync; sleep 1; sync # just to be safe
1740         BEFOREWRITES=`count_ost_writes`
1741         grep "[0-9]" $LPROC/osc/*[oO][sS][cC][_-]*/cur_grant_bytes
1742         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
1743         AFTERWRITES=`count_ost_writes`
1744         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1745                 error "$BEFOREWRITES < $AFTERWRITES"
1746         start_writeback
1747 }
1748 run_test 42a "ensure that we don't flush on close =============="
1749
1750 test_42b() {
1751         setup_test42
1752         cancel_lru_locks osc
1753         stop_writeback
1754         sync
1755         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
1756         BEFOREWRITES=`count_ost_writes`
1757         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
1758         AFTERWRITES=`count_ost_writes`
1759         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1760                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
1761         fi
1762         BEFOREWRITES=`count_ost_writes`
1763         sync || error "sync: $?"
1764         AFTERWRITES=`count_ost_writes`
1765         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1766                 error "$BEFOREWRITES < $AFTERWRITES on sync"
1767         fi
1768         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
1769         start_writeback
1770         return 0
1771 }
1772 run_test 42b "test destroy of file with cached dirty data ======"
1773
1774 # if these tests just want to test the effect of truncation,
1775 # they have to be very careful.  consider:
1776 # - the first open gets a {0,EOF}PR lock
1777 # - the first write conflicts and gets a {0, count-1}PW
1778 # - the rest of the writes are under {count,EOF}PW
1779 # - the open for truncate tries to match a {0,EOF}PR
1780 #   for the filesize and cancels the PWs.
1781 # any number of fixes (don't get {0,EOF} on open, match
1782 # composite locks, do smarter file size management) fix
1783 # this, but for now we want these tests to verify that
1784 # the cancellation with truncate intent works, so we
1785 # start the file with a full-file pw lock to match against
1786 # until the truncate.
1787 trunc_test() {
1788         test=$1
1789         file=$DIR/$test
1790         offset=$2
1791         cancel_lru_locks osc
1792         stop_writeback
1793         # prime the file with 0,EOF PW to match
1794         touch $file
1795         $TRUNCATE $file 0
1796         sync; sync
1797         # now the real test..
1798         dd if=/dev/zero of=$file bs=1024 count=100
1799         BEFOREWRITES=`count_ost_writes`
1800         $TRUNCATE $file $offset
1801         cancel_lru_locks osc
1802         AFTERWRITES=`count_ost_writes`
1803         start_writeback
1804 }
1805
1806 test_42c() {
1807         trunc_test 42c 1024
1808         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
1809             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
1810         rm $file
1811 }
1812 run_test 42c "test partial truncate of file with cached dirty data"
1813
1814 test_42d() {
1815         trunc_test 42d 0
1816         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1817             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
1818         rm $file
1819 }
1820 run_test 42d "test complete truncate of file with cached dirty data"
1821
1822 test_43() {
1823         mkdir $DIR/$tdir
1824         cp -p /bin/ls $DIR/$tdir/$tfile
1825         exec 100>> $DIR/$tdir/$tfile
1826         $DIR/$tdir/$tfile && error || true
1827         exec 100<&-
1828 }
1829 run_test 43 "execution of file opened for write should return -ETXTBSY"
1830
1831 test_43a() {
1832         mkdir -p $DIR/d43
1833         cp -p `which multiop` $DIR/d43/multiop
1834         $DIR/d43/multiop $TMP/test43.junk O_c &
1835         MULTIPID=$!
1836         sleep 1
1837         multiop $DIR/d43/multiop Oc && error "expected error, got success"
1838         kill -USR1 $MULTIPID || return 2
1839         wait $MULTIPID || return 3
1840         rm $TMP/test43.junk
1841 }
1842 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
1843
1844 test_43b() {
1845         mkdir -p $DIR/d43
1846         cp -p `which multiop` $DIR/d43/multiop
1847         $DIR/d43/multiop $TMP/test43.junk O_c &
1848         MULTIPID=$!
1849         sleep 1
1850         truncate $DIR/d43/multiop 0 && error "expected error, got success"
1851         kill -USR1 $MULTIPID || return 2
1852         wait $MULTIPID || return 3
1853         rm $TMP/test43.junk
1854 }
1855 run_test 43b "truncate of file being executed should return -ETXTBSY"
1856
1857 test_43c() {
1858         local testdir="$DIR/d43c"
1859         mkdir -p $testdir
1860         cp $SHELL $testdir/
1861         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
1862                 ( cd $testdir && md5sum -c)
1863 }
1864 run_test 43c "md5sum of copy into lustre========================"
1865
1866 test_44() {
1867         [  "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
1868         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
1869         dd if=$DIR/f1 of=/dev/null bs=4k count=1
1870 }
1871 run_test 44 "zero length read from a sparse stripe ============="
1872
1873 test_44a() {
1874     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
1875                          awk '{print $2}'`
1876     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
1877                       awk '{print $2}'`
1878     if [ $nstripe -eq 0 ] ; then
1879         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
1880     fi
1881     [ -z "$nstripe" ] && error "can't get stripe info"
1882
1883     OFFSETS="0 $((stride/2)) $((stride-1))"
1884     for offset in $OFFSETS ; do
1885       for i in `seq 0 $((nstripe-1))`; do
1886         rm -f $DIR/d44a
1887         local GLOBALOFFSETS=""
1888         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
1889         ll_sparseness_write $DIR/d44a $size  || error "ll_sparseness_write"
1890         GLOBALOFFSETS="$GLOBALOFFSETS $size"
1891         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
1892                             || error "ll_sparseness_verify $GLOBALOFFSETS"
1893
1894         for j in `seq 0 $((nstripe-1))`; do
1895             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
1896             ll_sparseness_write $DIR/d44a $size || error "ll_sparseness_write"
1897             GLOBALOFFSETS="$GLOBALOFFSETS $size"
1898         done
1899         ll_sparseness_verify $DIR/d44a $GLOBALOFFSETS \
1900                             || error "ll_sparseness_verify $GLOBALOFFSETS"
1901       done
1902     done
1903 }
1904 run_test 44a "test sparse pwrite ==============================="
1905
1906 dirty_osc_total() {
1907         tot=0
1908         for d in $LPROC/osc/*/cur_dirty_bytes; do
1909                 tot=$(($tot + `cat $d`))
1910         done
1911         echo $tot
1912 }
1913 do_dirty_record() {
1914         before=`dirty_osc_total`
1915         echo executing "\"$*\""
1916         eval $*
1917         after=`dirty_osc_total`
1918         echo before $before, after $after
1919 }
1920 test_45() {
1921         f="$DIR/f45"
1922         # Obtain grants from OST if it supports it
1923         echo blah > ${f}_grant
1924         stop_writeback
1925         sync
1926         do_dirty_record "echo blah > $f"
1927         [ $before -eq $after ] && error "write wasn't cached"
1928         do_dirty_record "> $f"
1929         [ $before -gt $after ] || error "truncate didn't lower dirty count"
1930         do_dirty_record "echo blah > $f"
1931         [ $before -eq $after ] && error "write wasn't cached"
1932         do_dirty_record "sync"
1933         [ $before -gt $after ] || error "writeback didn't lower dirty count"
1934         do_dirty_record "echo blah > $f"
1935         [ $before -eq $after ] && error "write wasn't cached"
1936         do_dirty_record "cancel_lru_locks osc"
1937         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
1938         start_writeback
1939 }
1940 run_test 45 "osc io page accounting ============================"
1941
1942 page_size() {
1943         getconf PAGE_SIZE
1944 }
1945
1946 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
1947 # test tickles a bug where re-dirtying a page was failing to be mapped to the
1948 # objects offset and an assert hit when an rpc was built with 1023's mapped 
1949 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
1950 test_46() {
1951         f="$DIR/f46"
1952         stop_writeback
1953         sync
1954         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
1955         sync
1956         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
1957         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
1958         sync
1959         start_writeback
1960 }
1961 run_test 46 "dirtying a previously written page ================"
1962
1963 # Check that device nodes are created and then visible correctly (#2091)
1964 test_47() {
1965         cmknod $DIR/test_47_node || error
1966 }
1967 run_test 47 "Device nodes check ================================"
1968
1969 test_48a() { # bug 2399
1970         check_kernel_version 34 || return 0
1971         mkdir -p $DIR/d48a
1972         cd $DIR/d48a
1973         mv $DIR/d48a $DIR/d48.new || error "move directory failed"
1974         mkdir $DIR/d48a || error "recreate directory failed"
1975         touch foo || error "'touch foo' failed after recreating cwd"
1976         mkdir bar || error "'mkdir foo' failed after recreating cwd"
1977         if check_kernel_version 44; then
1978                 touch .foo || error "'touch .foo' failed after recreating cwd"
1979                 mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
1980         fi
1981         ls . || error "'ls .' failed after recreating cwd"
1982         ls .. || error "'ls ..' failed after removing cwd"
1983         cd . || error "'cd .' failed after recreating cwd"
1984         mkdir . && error "'mkdir .' worked after recreating cwd"
1985         rmdir . && error "'rmdir .' worked after recreating cwd"
1986         ln -s . baz || error "'ln -s .' failed after recreating cwd"
1987         cd .. || error "'cd ..' failed after recreating cwd"
1988 }
1989 run_test 48a "Access renamed working dir (should return errors)="
1990
1991 test_48b() { # bug 2399
1992         check_kernel_version 34 || return 0
1993         mkdir -p $DIR/d48b
1994         cd $DIR/d48b
1995         rmdir $DIR/d48b || error "remove cwd $DIR/d48b failed"
1996         touch foo && error "'touch foo' worked after removing cwd"
1997         mkdir foo && error "'mkdir foo' worked after removing cwd"
1998         if check_kernel_version 44; then
1999                 touch .foo && error "'touch .foo' worked after removing cwd"
2000                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
2001         fi
2002         ls . && error "'ls .' worked after removing cwd"
2003         ls .. || error "'ls ..' failed after removing cwd"
2004         cd . && error "'cd .' worked after removing cwd"
2005         mkdir . && error "'mkdir .' worked after removing cwd"
2006         rmdir . && error "'rmdir .' worked after removing cwd"
2007         ln -s . foo && error "'ln -s .' worked after removing cwd"
2008         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
2009 }
2010 run_test 48b "Access removed working dir (should return errors)="
2011
2012 test_48c() { # bug 2350
2013         check_kernel_version 36 || return 0
2014         #sysctl -w lnet.debug=-1
2015         #set -vx
2016         mkdir -p $DIR/d48c/dir
2017         cd $DIR/d48c/dir
2018         $TRACE rmdir $DIR/d48c/dir || error "remove cwd $DIR/d48c/dir failed"
2019         $TRACE touch foo && error "'touch foo' worked after removing cwd"
2020         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
2021         if check_kernel_version 44; then
2022                 touch .foo && error "'touch .foo' worked after removing cwd"
2023                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
2024         fi
2025         $TRACE ls . && error "'ls .' worked after removing cwd"
2026         $TRACE ls .. || error "'ls ..' failed after removing cwd"
2027         $TRACE cd . && error "'cd .' worked after removing cwd"
2028         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
2029         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
2030         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
2031         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
2032 }
2033 run_test 48c "Access removed working subdir (should return errors)"
2034
2035 test_48d() { # bug 2350
2036         check_kernel_version 36 || return 0
2037         #sysctl -w lnet.debug=-1
2038         #set -vx
2039         mkdir -p $DIR/d48d/dir
2040         cd $DIR/d48d/dir
2041         $TRACE rmdir $DIR/d48d/dir || error "remove cwd $DIR/d48d/dir failed"
2042         $TRACE rmdir $DIR/d48d || error "remove parent $DIR/d48d failed"
2043         $TRACE touch foo && error "'touch foo' worked after removing parent"
2044         $TRACE mkdir foo && error "'mkdir foo' worked after removing parent"
2045         if check_kernel_version 44; then
2046                 touch .foo && error "'touch .foo' worked after removing parent"
2047                 mkdir .foo && error "'mkdir .foo' worked after removing parent"
2048         fi
2049         $TRACE ls . && error "'ls .' worked after removing parent"
2050         $TRACE ls .. && error "'ls ..' worked after removing parent"
2051         $TRACE cd . && error "'cd .' worked after recreate parent"
2052         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
2053         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
2054         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
2055         $TRACE cd .. && error "'cd ..' worked after removing parent" || true
2056 }
2057 run_test 48d "Access removed parent subdir (should return errors)"
2058
2059 test_48e() { # bug 4134
2060         check_kernel_version 41 || return 0
2061         #sysctl -w lnet.debug=-1
2062         #set -vx
2063         mkdir -p $DIR/d48e/dir
2064         cd $DIR/d48e/dir
2065         $TRACE rmdir $DIR/d48e/dir || error "remove cwd $DIR/d48e/dir failed"
2066         $TRACE rmdir $DIR/d48e || error "remove parent $DIR/d48e failed"
2067         $TRACE touch $DIR/d48e || error "'touch $DIR/d48e' failed"
2068         $TRACE chmod +x $DIR/d48e || error "'chmod +x $DIR/d48e' failed"
2069         # On a buggy kernel addition of "touch foo" after cd .. will
2070         # produce kernel oops in lookup_hash_it
2071         touch ../foo && error "'cd ..' worked after recreate parent"
2072         cd $DIR
2073         $TRACE rm $DIR/d48e || error "rm '$DIR/d48e' failed"
2074 }
2075 run_test 48e "Access to recreated parent subdir (should return errors)"
2076
2077 test_50() {
2078         # bug 1485
2079         mkdir $DIR/d50
2080         cd $DIR/d50
2081         ls /proc/$$/cwd || error
2082 }
2083 run_test 50 "special situations: /proc symlinks  ==============="
2084
2085 test_51() {
2086         # bug 1516 - create an empty entry right after ".." then split dir
2087         mkdir $DIR/d51
2088         touch $DIR/d51/foo
2089         $MCREATE $DIR/d51/bar
2090         rm $DIR/d51/foo
2091         createmany -m $DIR/d51/longfile 201
2092         FNUM=202
2093         while [ `ls -sd $DIR/d51 | awk '{ print $1 }'` -eq 4 ]; do
2094                 $MCREATE $DIR/d51/longfile$FNUM
2095                 FNUM=$(($FNUM + 1))
2096                 echo -n "+"
2097         done
2098         ls -l $DIR/d51 > /dev/null || error
2099 }
2100 run_test 51 "special situations: split htree with empty entry =="
2101
2102 export NUMTEST=70000
2103 test_51b() {
2104         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
2105         [ $NUMFREE -lt 21000 ] && \
2106                 echo "skipping $TESTNAME, not enough free inodes ($NUMFREE)" && \
2107                 return
2108
2109         check_kernel_version 40 || NUMTEST=31000
2110         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 50))
2111
2112         mkdir -p $DIR/d51b
2113         createmany -d $DIR/d51b/t- $NUMTEST
2114 }
2115 run_test 51b "mkdir .../t-0 --- .../t-$NUMTEST ===================="
2116
2117 test_51c() {
2118         [ ! -d $DIR/d51b ] && echo "skipping $TESTNAME: $DIR/51b missing" && \
2119                 return
2120
2121         unlinkmany -d $DIR/d51b/t- $NUMTEST
2122 }
2123 run_test 51c "rmdir .../t-0 --- .../t-$NUMTEST ===================="
2124
2125 test_51d() {
2126         [  "$OSTCOUNT" -lt "3" ] && echo "skipping test with few OSTs" && return
2127         mkdir -p $DIR/d51d
2128         createmany -o $DIR/d51d/t- 1000
2129         $LFS getstripe $DIR/d51d > $TMP/files
2130         for N in `seq 0 $((OSTCOUNT - 1))`; do
2131             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
2132             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
2133             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
2134         done
2135         unlinkmany $DIR/d51d/t- 1000
2136
2137         NLAST=0
2138         for N in `seq 1 $((OSTCOUNT - 1))`; do
2139             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
2140                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2141             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
2142                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2143             
2144             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
2145                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2146             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
2147                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2148             NLAST=$N
2149         done
2150 }
2151 run_test 51d "check object distribution ===================="
2152
2153 test_52a() {
2154         [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
2155         mkdir -p $DIR/d52a
2156         touch $DIR/d52a/foo
2157         chattr =a $DIR/d52a/foo || error "chattr =a failed"
2158         echo bar >> $DIR/d52a/foo || error "append bar failed"
2159         cp /etc/hosts $DIR/d52a/foo && error "cp worked"
2160         rm -f $DIR/d52a/foo 2>/dev/null && error "rm worked"
2161         link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error "link worked"
2162         echo foo >> $DIR/d52a/foo || error "append foo failed"
2163         mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error "rename worked"
2164         lsattr $DIR/d52a/foo | egrep -q "^-+a-+ $DIR/d52a/foo" || error "lsattr"
2165         chattr -a $DIR/d52a/foo || error "chattr -a failed"
2166
2167         rm -fr $DIR/d52a || error "cleanup rm failed"
2168 }
2169 run_test 52a "append-only flag test (should return errors) ====="
2170
2171 test_52b() {
2172         [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
2173         mkdir -p $DIR/d52b
2174         touch $DIR/d52b/foo
2175         chattr =i $DIR/d52b/foo || error
2176         cat test > $DIR/d52b/foo && error
2177         cp /etc/hosts $DIR/d52b/foo && error
2178         rm -f $DIR/d52b/foo 2>/dev/null && error
2179         link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error
2180         echo foo >> $DIR/d52b/foo && error
2181         mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error
2182         [ -f $DIR/d52b/foo ] || error
2183         [ -f $DIR/d52b/foo_ren ] && error
2184         lsattr $DIR/d52b/foo | egrep -q "^-+i-+ $DIR/d52b/foo" || error
2185         chattr -i $DIR/d52b/foo || error
2186
2187         rm -fr $DIR/d52b || error
2188 }
2189 run_test 52b "immutable flag test (should return errors) ======="
2190
2191 test_52c() { # 12848 simulating client < 1.4.7
2192         [ -f $DIR/d52c/foo ] && chattr -i $DIR/d52b/foo
2193         mkdir -p $DIR/d52c
2194         touch $DIR/d52c/foo
2195         # skip MDS_BFLAG_EXT_FLAGS in mdc_getattr_pack
2196 #define OBD_FAIL_MDC_OLD_EXT_FLAGS       0x802
2197         sysctl -w lustre.fail_loc=0x802
2198         chattr =i $DIR/d52c/foo || error
2199         lsattr $DIR/d52c/foo | egrep -q "^-+i-+ $DIR/d52c/foo" || error
2200         chattr -i $DIR/d52c/foo || error
2201         sysctl -w lustre.fail_loc=0
2202
2203         rm -fr $DIR/d52c || error
2204 }
2205 run_test 52c "immutable flag test for client < 1.4.7 ======="
2206
2207 test_53() {
2208         [ -z "$MDS" ] && echo "skipping $TESTNAME with remote MDS" && return
2209         
2210         for i in `ls -d $LPROC/osc/*-osc 2> /dev/null` ; do
2211                 ostname=`basename $i | cut -d - -f 1-2`
2212                 ost_last=`cat $LPROC/obdfilter/$ostname/last_id`
2213                 mds_last=`cat $i/prealloc_last_id`
2214                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2215                 if [ $ost_last != $mds_last ]; then
2216                     error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2217                 fi
2218         done
2219 }
2220 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
2221
2222 test_54a() {
2223         [ ! -f "$SOCKETSERVER" ] && echo "no socketserver, skipping" && return
2224         [ ! -f "$SOCKETCLIENT" ] && echo "no socketclient, skipping" && return
2225         $SOCKETSERVER $DIR/socket
2226         $SOCKETCLIENT $DIR/socket || error
2227         $MUNLINK $DIR/socket
2228 }
2229 run_test 54a "unix domain socket test =========================="
2230
2231 test_54b() {
2232         f="$DIR/f54b"
2233         mknod $f c 1 3
2234         chmod 0666 $f
2235         dd if=/dev/zero of=$f bs=`page_size` count=1 
2236 }
2237 run_test 54b "char device works in lustre ======================"
2238
2239 find_loop_dev() {
2240         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
2241         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
2242         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
2243
2244         for i in `seq 3 7`; do
2245                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
2246                 LOOPDEV=$LOOPBASE$i
2247                 LOOPNUM=$i
2248                 break
2249         done
2250 }
2251
2252 test_54c() {
2253         tfile="$DIR/f54c"
2254         tdir="$DIR/d54c"
2255         loopdev="$DIR/loop54c"
2256
2257         find_loop_dev 
2258         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
2259         mknod $loopdev b 7 $LOOPNUM
2260         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
2261         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
2262         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
2263         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
2264         mkdir -p $tdir
2265         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
2266         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
2267         df $tdir
2268         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
2269         $UMOUNT $tdir
2270         losetup -d $loopdev
2271         rm $loopdev
2272 }
2273 run_test 54c "block device works in lustre ====================="
2274
2275 test_54d() {
2276         f="$DIR/f54d"
2277         string="aaaaaa"
2278         mknod $f p
2279         [ "$string" = `echo $string > $f | cat $f` ] || error
2280 }
2281 run_test 54d "fifo device works in lustre ======================"
2282
2283 test_54e() {
2284         check_kernel_version 46 || return 0
2285         f="$DIR/f54e"
2286         string="aaaaaa"
2287         mknod $f c 4 0
2288         echo $string > $f || error
2289 }
2290 run_test 54e "console/tty device works in lustre ======================"
2291
2292 check_fstype() {
2293         grep -q $FSTYPE /proc/filesystems && return 1
2294         modprobe $FSTYPE
2295         grep -q $FSTYPE /proc/filesystems && return 1
2296         insmod ../$FSTYPE/$FSTYPE.o
2297         grep -q $FSTYPE /proc/filesystems && return 1
2298         insmod ../$FSTYPE/$FSTYPE.ko
2299         grep -q $FSTYPE /proc/filesystems && return 1
2300         return 0
2301 }
2302
2303 test_55() {
2304         rm -rf $DIR/d55
2305         mkdir $DIR/d55
2306         check_fstype && echo "can't find fs $FSTYPE, skipping $TESTNAME" && return
2307         mount -t $FSTYPE -o loop,iopen $EXT2_DEV $DIR/d55 || error "mounting"
2308         touch $DIR/d55/foo
2309         $IOPENTEST1 $DIR/d55/foo $DIR/d55 || error "running $IOPENTEST1"
2310         $IOPENTEST2 $DIR/d55 || error "running $IOPENTEST2"
2311         echo "check for $EXT2_DEV. Please wait..."
2312         rm -rf $DIR/d55/*
2313         $UMOUNT $DIR/d55 || error "unmounting"
2314 }
2315 run_test 55 "check iopen_connect_dentry() ======================"
2316
2317 test_56() {
2318         rm -rf $DIR/d56
2319         $SETSTRIPE -d $DIR
2320         mkdir $DIR/d56
2321         mkdir $DIR/d56/dir
2322         NUMFILES=3
2323         NUMFILESx2=$(($NUMFILES * 2))
2324         for i in `seq 1 $NUMFILES` ; do
2325                 touch $DIR/d56/file$i
2326                 touch $DIR/d56/dir/file$i
2327         done
2328
2329         # test lfs getstripe with --recursive
2330         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | grep -c obdidx`
2331         [ $FILENUM -eq $NUMFILESx2 ] || error \
2332                 "lfs getstripe --recursive $DIR/d56 wrong: found $FILENUM, expected $NUMFILESx2"
2333         FILENUM=`$GETSTRIPE $DIR/d56 | grep -c obdidx`
2334         [ $FILENUM -eq $NUMFILES ] || error \
2335                 "lfs getstripe $DIR/d56 without --recursive wrong: found $FILENUM, expected $NUMFILES"
2336         echo "lfs getstripe --recursive passed."
2337
2338         # test lfs getstripe with file instead of dir
2339         FILENUM=`$GETSTRIPE $DIR/d56/file1 | grep -c obdidx`
2340         [ $FILENUM  -eq 1 ] || error \
2341                  "lfs getstripe $DIR/d56/file1 wrong:found $FILENUM, expected 1"
2342         echo "lfs getstripe file passed."
2343
2344         #test lfs getstripe with --verbose
2345         [ `$GETSTRIPE --verbose $DIR/d56 | grep -c lmm_magic` -eq $NUMFILES ] ||\
2346                 error "lfs getstripe --verbose $DIR/d56 wrong: should find $NUMFILES lmm_magic info"
2347         [ `$GETSTRIPE $DIR/d56 | grep -c lmm_magic` -eq 0 ] || error \
2348                 "lfs getstripe $DIR/d56 without --verbose wrong: should not show lmm_magic info"
2349         echo "lfs getstripe --verbose passed."
2350
2351         #test lfs getstripe with --obd
2352         $GETSTRIPE --obd wrong_uuid $DIR/d56 2>&1 | grep -q "unknown obduuid" || \
2353                 error "lfs getstripe --obd wrong_uuid should return error message"
2354
2355         [  "$OSTCOUNT" -lt 2 ] && \
2356                 echo "skipping other lfs getstripe --obd test" && return
2357         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1[    ]/p' | wc -l`
2358         OBDUUID=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1:/p' | awk '{print $2}'`
2359         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/d56 | wc -l`
2360         [ $FOUND -eq $FILENUM ] || \
2361                 error "lfs getstripe --obd wrong: found $FOUND, expected $FILENUM"
2362         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/d56 | sed '/^[   ]*1[    ]/d' |\
2363                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] || \
2364                 error "lfs getstripe --obd wrong: should not show file on other obd"
2365         echo "lfs getstripe --obd passed."
2366 }
2367 run_test 56 "check lfs getstripe ===================================="
2368
2369 NUMFILES=3
2370 NUMDIRS=3
2371 setup_56() {
2372         LOCAL_NUMFILES=$1
2373         LOCAL_NUMDIRS=$2
2374         if [ ! -d "$DIR/${tdir}g" ] ; then
2375                 mkdir -p $DIR/${tdir}g
2376                 for i in `seq 1 $LOCAL_NUMFILES` ; do
2377                         touch $DIR/${tdir}g/file$i
2378                 done
2379                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
2380                         mkdir $DIR/${tdir}g/dir$i
2381                         for j in `seq 1 $LOCAL_NUMFILES` ; do
2382                                 touch $DIR/${tdir}g/dir$i/file$j
2383                         done
2384                 done
2385         fi
2386 }
2387
2388 test_56g() {
2389         $LSTRIPE -d $DIR
2390
2391         setup_56 $NUMFILES $NUMDIRS
2392
2393         EXPECTED=$(($NUMDIRS + 2))
2394         # test lfs find with -name
2395         for i in `seq 1 $NUMFILES` ; do
2396                 NUMS=`$LFIND -name "*$i" $DIR/${tdir}g | wc -l`
2397                 [ $NUMS -eq $EXPECTED ] || error \
2398                         "lfs find -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2399         done
2400         echo "lfs find -name passed."
2401 }
2402 run_test 56g "check lfs find -name ============================="
2403
2404 test_56h() {
2405         $LSTRIPE -d $DIR
2406
2407         setup_56 $NUMFILES $NUMDIRS
2408
2409         EXPECTED=$((($NUMDIRS+1)*($NUMFILES-1)+$NUMFILES))
2410         # test lfs find with ! -name
2411         for i in `seq 1 $NUMFILES` ; do
2412                 NUMS=`$LFIND ! -name "*$i" $DIR/${tdir}g | wc -l`
2413                 [ $NUMS -eq $EXPECTED ] || error \
2414                         "lfs find ! -name \"*$i\" $DIR/${tdir}g wrong: found $NUMS, expected $EXPECTED"
2415         done
2416         echo "lfs find ! -name passed."
2417 }
2418 run_test 56h "check lfs find ! -name ============================="
2419
2420 test_57a() {
2421         [ -z "$MDS" ] && echo "skipping $TESTNAME for remote MDS" && return
2422         for DEV in `cat $LPROC/mds/*/mntdev`; do
2423                 dumpe2fs -h $DEV > $TMP/t57a.dump || error "can't access $DEV"
2424                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
2425                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
2426                 rm $TMP/t57a.dump
2427         done
2428 }
2429 run_test 57a "verify MDS filesystem created with large inodes =="
2430
2431 test_57b() {
2432         FILECOUNT=100
2433         FILE1=$DIR/d57b/f1
2434         FILEN=$DIR/d57b/f$FILECOUNT
2435         rm -rf $DIR/d57b || error "removing $DIR/d57b"
2436         mkdir -p $DIR/d57b || error "creating $DIR/d57b"
2437         echo "mcreating $FILECOUNT files"
2438         createmany -m $DIR/d57b/f 1 $FILECOUNT || \
2439                 error "creating files in $DIR/d57b"
2440
2441         # verify that files do not have EAs yet
2442         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
2443         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
2444
2445         MDSFREE="`cat $LPROC/mds/*/kbytesfree 2> /dev/null`"
2446         MDCFREE="`cat $LPROC/mdc/*/kbytesfree | head -n 1`"
2447         echo "opening files to create objects/EAs"
2448         for FILE in `seq -f $DIR/d57b/f%g 1 $FILECOUNT`; do
2449                 $OPENFILE -f O_RDWR $FILE > /dev/null || error "opening $FILE"
2450         done
2451
2452         # verify that files have EAs now
2453         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
2454         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
2455
2456         sleep 1 # make sure we get new statfs data
2457         MDSFREE2="`cat $LPROC/mds/*/kbytesfree 2> /dev/null`"
2458         MDCFREE2="`cat $LPROC/mdc/*/kbytesfree | head -n 1`"
2459         if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
2460                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
2461                         error "MDC before $MDCFREE != after $MDCFREE2"
2462                 else
2463                         echo "MDC before $MDCFREE != after $MDCFREE2"
2464                         echo "unable to confirm if MDS has large inodes"
2465                 fi
2466         fi
2467         rm -rf $DIR/d57b
2468 }
2469 run_test 57b "default LOV EAs are stored inside large inodes ==="
2470
2471 test_58() {
2472     [ -z "$(which wiretest 2>/dev/null)" ] && echo "skipping $TESTNAME (could not find wiretest)" && return
2473     wiretest
2474 }
2475 run_test 58 "verify cross-platform wire constants =============="
2476
2477 test_59() {
2478         echo "touch 130 files"
2479         createmany -o $DIR/f59- 130
2480         echo "rm 130 files"
2481         unlinkmany $DIR/f59- 130
2482         sync
2483         sleep 2
2484         # wait for commitment of removal
2485 }
2486 run_test 59 "verify cancellation of llog records async ========="
2487
2488 TEST60_HEAD="test_60 run $RANDOM"
2489 test_60() {
2490         [ ! -f run-llog.sh ] && echo "missing subtest, skipping" && return
2491         log "$TEST60_HEAD - from kernel mode"
2492         sh run-llog.sh
2493 }
2494 run_test 60 "llog sanity tests run from kernel module =========="
2495
2496 test_60b() { # bug 6411
2497         dmesg > $DIR/$tfile
2498         LLOG_COUNT=`dmesg | grep -A 1000 "$TEST60_HEAD" | grep -c llog_test`
2499         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages"|| true
2500 }
2501 run_test 60b "limit repeated messages from CERROR/CWARN ========"
2502
2503 test_60c() {
2504         echo "create 5000 files" 
2505         createmany -o $DIR/f60c- 5000
2506         #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
2507         sysctl -w lustre.fail_loc=0x80000137
2508         unlinkmany $DIR/f60c- 5000
2509 }
2510 run_test 60c "unlink file when mds full"
2511
2512 test_61() {
2513         f="$DIR/f61"
2514         dd if=/dev/zero of=$f bs=`page_size` count=1
2515         cancel_lru_locks osc
2516         multiop $f OSMWUc || error
2517         sync
2518 }
2519 run_test 61 "mmap() writes don't make sync hang ================"
2520
2521 # bug 2330 - insufficient obd_match error checking causes LBUG
2522 test_62() {
2523         f="$DIR/f62"
2524         echo foo > $f
2525         cancel_lru_locks osc
2526         #define OBD_FAIL_OSC_MATCH 0x405
2527         sysctl -w lustre.fail_loc=0x405
2528         cat $f && error "cat succeeded, expect -EIO"
2529         sysctl -w lustre.fail_loc=0
2530 }
2531 run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
2532
2533 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
2534 test_63() {
2535         MAX_DIRTY_MB=`cat $LPROC/osc/*/max_dirty_mb | head -n 1`
2536         for i in $LPROC/osc/*/max_dirty_mb ; do
2537                 echo 0 > $i
2538         done
2539         for i in `seq 10` ; do
2540                 dd if=/dev/zero of=$DIR/f63 bs=8k &
2541                 sleep 5
2542                 kill $!
2543                 sleep 1
2544         done
2545
2546         for i in $LPROC/osc/*/max_dirty_mb ; do
2547                 echo $MAX_DIRTY_MB > $i
2548         done
2549         rm -f $DIR/f63 || true
2550 }
2551 run_test 63 "Verify oig_wait interruption does not crash ======="
2552
2553 # bug 2248 - async write errors didn't return to application on sync
2554 # bug 3677 - async write errors left page locked
2555 test_63b() {
2556         DBG_SAVE="`sysctl -n lnet.debug`"
2557         sysctl -w lnet.debug=-1
2558
2559         # ensure we have a grant to do async writes
2560         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
2561         rm $DIR/$tfile
2562
2563         #define OBD_FAIL_OSC_BRW_PREP_REQ 0x406
2564         sysctl -w lustre.fail_loc=0x80000406
2565         multiop $DIR/$tfile Owy && \
2566                 $LCTL dk /tmp/test63b.debug && \
2567                 sysctl -w lnet.debug="$DBG_SAVE" && \
2568                 error "sync didn't return ENOMEM"
2569         sync; sleep 2; sync     # do a real sync this time to flush page
2570         grep locked $LPROC/llite/*/dump_page_cache && \
2571                 $LCTL dk /tmp/test63b.debug && \
2572                 sysctl -w lnet.debug="$DBG_SAVE" && \
2573                 error "locked page left in cache after async error" || true
2574         sysctl -w lnet.debug="$DBG_SAVE"
2575 }
2576 run_test 63b "async write errors should be returned to fsync ==="
2577
2578 test_64a () {
2579         df $DIR
2580         grep "[0-9]" $LPROC/osc/*[oO][sS][cC][_-]*/cur*
2581 }
2582 run_test 64a "verify filter grant calculations (in kernel) ====="
2583
2584 test_64b () {
2585         [ ! -f oos.sh ] && echo "missing subtest, skipping" && return
2586         sh oos.sh $MOUNT
2587 }
2588 run_test 64b "check out-of-space detection on client ==========="
2589
2590 # bug 1414 - set/get directories' stripe info
2591 test_65a() {
2592         mkdir -p $DIR/d65
2593         touch $DIR/d65/f1
2594         $LVERIFY $DIR/d65 $DIR/d65/f1 || error "lverify failed"
2595 }
2596 run_test 65a "directory with no stripe info ===================="
2597
2598 test_65b() {
2599         mkdir -p $DIR/d65
2600         $SETSTRIPE $DIR/d65 $(($STRIPESIZE * 2)) 0 1 || error "setstripe"
2601         touch $DIR/d65/f2
2602         $LVERIFY $DIR/d65 $DIR/d65/f2 || error "lverify failed"
2603 }
2604 run_test 65b "directory setstripe $(($STRIPESIZE * 2)) 0 1 ==============="
2605
2606 test_65c() {
2607         if [ $OSTCOUNT -gt 1 ]; then
2608                 mkdir -p $DIR/d65
2609                 $SETSTRIPE $DIR/d65 $(($STRIPESIZE * 4)) 1 \
2610                         $(($OSTCOUNT - 1)) || error "setstripe"
2611                 touch $DIR/d65/f3
2612                 $LVERIFY $DIR/d65 $DIR/d65/f3 || error "lverify failed"
2613         fi
2614 }
2615 run_test 65c "directory setstripe $(($STRIPESIZE * 4)) 1 $(($OSTCOUNT - 1))"
2616
2617 [ $STRIPECOUNT -eq 0 ] && sc=1 || sc=$(($STRIPECOUNT - 1))
2618
2619 test_65d() {
2620         mkdir -p $DIR/d65
2621         $SETSTRIPE $DIR/d65 $STRIPESIZE -1 $sc || error "setstripe"
2622         touch $DIR/d65/f4 $DIR/d65/f5
2623         $LVERIFY $DIR/d65 $DIR/d65/f4 $DIR/d65/f5 || error "lverify failed"
2624 }
2625 run_test 65d "directory setstripe $STRIPESIZE -1 $sc =============="
2626
2627 test_65e() {
2628         mkdir -p $DIR/d65
2629
2630         $SETSTRIPE $DIR/d65 0 -1 0 || error "setstripe"
2631         $GETSTRIPE -v $DIR/d65 | grep "has no stripe info" || error "no stripe info failed"
2632         touch $DIR/d65/f6
2633         $LVERIFY $DIR/d65 $DIR/d65/f6 || error "lverify failed"
2634 }
2635 run_test 65e "directory setstripe 0 -1 0 ======================="
2636
2637 test_65f() {
2638         mkdir -p $DIR/d65f
2639         $RUNAS $SETSTRIPE $DIR/d65f 0 -1 0 && error "setstripe succeeded" || true
2640 }
2641 run_test 65f "dir setstripe permission (should return error) ==="
2642
2643 test_65g() {
2644         mkdir -p $DIR/d65
2645         $SETSTRIPE $DIR/d65 $(($STRIPESIZE * 2)) 0 1 || error "setstripe"
2646         $SETSTRIPE -d $DIR/d65 || error "setstripe"
2647         $GETSTRIPE -v $DIR/d65 | grep "has no stripe info" || \
2648                 error "delete default stripe failed"
2649 }
2650 run_test 65g "directory setstripe -d ==========================="
2651
2652 test_65h() {
2653         mkdir -p $DIR/d65
2654         $SETSTRIPE $DIR/d65 $(($STRIPESIZE * 2)) 0 1 || error "setstripe"
2655         mkdir -p $DIR/d65/dd1
2656         [ "`$GETSTRIPE -v $DIR/d65 | grep "^count"`" == \
2657           "`$GETSTRIPE -v $DIR/d65/dd1 | grep "^count"`" ] || error "stripe info inherit failed"
2658 }
2659 run_test 65h "directory stripe info inherit ===================="
2660  
2661 test_65i() { # bug6367
2662         $SETSTRIPE $MOUNT 65536 -1 -1
2663 }
2664 run_test 65i "set non-default striping on root directory (bug 6367)="
2665
2666 test_65j() { # bug6367
2667         # if we aren't already remounting for each test, do so for this test
2668         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
2669                 cleanup -f || error "failed to unmount"
2670                 setup
2671         fi
2672         $SETSTRIPE -d $MOUNT
2673 }
2674 run_test 65j "set default striping on root directory (bug 6367)="
2675
2676 # bug 2543 - update blocks count on client
2677 test_66() {
2678         COUNT=${COUNT:-8}
2679         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
2680         sync; sleep 1; sync
2681         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
2682         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
2683 }
2684 run_test 66 "update inode blocks count on client ==============="
2685
2686 test_67() { # bug 3285 - supplementary group fails on MDS, passes on client
2687         [ "$RUNAS_ID" = "$UID" ] && echo "skipping $TESTNAME" && return
2688         check_kernel_version 35 || return 0
2689         mkdir $DIR/$tdir
2690         chmod 771 $DIR/$tdir
2691         chgrp $RUNAS_ID $DIR/$tdir
2692         $RUNAS -u $RUNAS_ID -g $(($RUNAS_ID + 1)) -G1,2,$RUNAS_ID ls $DIR/$tdir
2693         RC=$?
2694         if [ "$MDS" ]; then
2695                 # can't tell which is correct otherwise
2696                 GROUP_UPCALL=`cat $LPROC/mds/$MDS/group_upcall`
2697                 [ "$GROUP_UPCALL" = "NONE" -a $RC -eq 0 ] && \
2698                         error "no-upcall passed" || true
2699                 [ "$GROUP_UPCALL" != "NONE" -a $RC -ne 0 ] && \
2700                         error "upcall failed" || true
2701         fi
2702 }
2703 run_test 67 "supplementary group failure (should return error) ="
2704
2705 cleanup_67b() {
2706         set +vx
2707         trap 0
2708         echo NONE > $LPROC/mds/$MDS/group_upcall
2709 }
2710
2711 test_67b() { # bug 3285 - supplementary group fails on MDS, passes on client
2712         T67_UID=${T67_UID:-1}   # needs to be in /etc/groups on MDS, gid == uid
2713         [ "$UID" = "$T67_UID" ] && echo "skipping $TESTNAME" && return
2714         check_kernel_version 35 || return 0
2715         [ -z "$MDS" ] && echo "skipping $TESTNAME - no MDS" && return
2716         GROUP_UPCALL=`cat $LPROC/mds/$MDS/group_upcall`
2717         [ "$GROUP_UPCALL" != "NONE" ] && echo "skip $TESTNAME - upcall" &&return
2718         set -vx
2719         trap cleanup_67b EXIT
2720         mkdir -p $DIR/$tdir
2721         chmod 771 $DIR/$tdir
2722         chgrp $T67_UID $DIR/$tdir
2723         echo `which l_getgroups` > $LPROC/mds/$MDS/group_upcall
2724         l_getgroups -d $T67_UID
2725         $RUNAS -u $T67_UID -g 999 -G8,9,$T67_UID touch $DIR/$tdir/$tfile || \
2726                 error "'touch $DIR/$tdir/$tfile' failed"
2727         [ -f $DIR/$tdir/$tfile ] || error "$DIR/$tdir/$tfile create error"
2728         cleanup_67b
2729 }
2730 run_test 67b "supplementary group test ========================="
2731
2732 cleanup_68() {
2733         trap 0
2734         if [ "$LOOPDEV" ]; then
2735                 swapoff $LOOPDEV || error "swapoff failed"
2736                 losetup -d $LOOPDEV || error "losetup -d failed"
2737                 unset LOOPDEV LOOPNUM
2738         fi
2739         rm -f $DIR/f68
2740 }
2741
2742 meminfo() {
2743         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
2744 }
2745
2746 swap_used() {
2747         swapon -s | awk '($1 == "'$1'") { print $4 }'
2748 }
2749
2750 # excercise swapping to lustre by adding a high priority swapfile entry
2751 # and then consuming memory until it is used.
2752 test_68() {
2753         [ "$UID" != 0 ] && echo "skipping $TESTNAME (must run as root)" && return
2754         grep -q obdfilter $LPROC/devices && \
2755                 echo "skip $TESTNAME (local OST)" && return
2756
2757         find_loop_dev
2758         dd if=/dev/zero of=$DIR/f68 bs=64k count=1024
2759
2760         trap cleanup_68 EXIT
2761
2762         losetup $LOOPDEV $DIR/f68 || error "losetup $LOOPDEV failed"
2763         mkswap $LOOPDEV
2764         swapon -p 32767 $LOOPDEV || error "swapon $LOOPDEV failed"
2765
2766         echo "before: `swapon -s | grep $LOOPDEV`"
2767         KBFREE=`meminfo MemTotal`
2768         $MEMHOG $KBFREE || error "error allocating $KBFREE kB"
2769         echo "after: `swapon -s | grep $LOOPDEV`"
2770         SWAPUSED=`swap_used $LOOPDEV`
2771
2772         cleanup_68
2773
2774         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
2775 }
2776 run_test 68 "support swapping to Lustre ========================"
2777
2778 # bug5265, obdfilter oa2dentry return -ENOENT
2779 # #define OBD_FAIL_OST_ENOENT 0x217
2780 test_69() {
2781         [ $(grep -c obdfilter $LPROC/devices) -eq 0 ] &&
2782                 echo "skipping $TESTNAME for remote OST" && return
2783
2784         f="$DIR/$tfile"
2785         touch $f
2786
2787         if ! $DIRECTIO write ${f}.2 0 1; then
2788                 echo "skipping $TESTNAME - O_DIRECT not implemented"
2789                 return 0
2790         fi
2791
2792         #define OBD_FAIL_OST_ENOENT 0x217
2793         sysctl -w lustre.fail_loc=0x217
2794         truncate $f 1 # vmtruncate() will ignore truncate() error.
2795         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
2796
2797         sysctl -w lustre.fail_loc=0
2798         $DIRECTIO write $f 0 2 || error "write error"
2799
2800         cancel_lru_locks osc
2801         $DIRECTIO read $f 0 1 || error "read error"
2802
2803         #define OBD_FAIL_OST_ENOENT 0x217
2804         sysctl -w lustre.fail_loc=0x217
2805         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
2806
2807         sysctl -w lustre.fail_loc=0
2808         rm -f $f
2809 }
2810 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
2811
2812 test_71() {
2813         which dbench > /dev/null 2>&1 || echo "dbench not installed, skip this test" && return 0
2814         DBENCH_LIB=${DBENCH_LIB:-/usr/lib/dbench}
2815         PATH=${DBENCH_LIB}:${PATH}
2816         cp `which dbench` $DIR
2817
2818         TGT=$DIR/client.txt
2819         SRC=${SRC:-$DBENCH_LIB/client.txt}
2820         [ ! -e $TGT -a -e $SRC ] && echo "copying $SRC to $TGT" && cp $SRC $TGT
2821         SRC=$DBENCH_LIB/client_plain.txt
2822         [ ! -e $TGT -a -e $SRC ] && echo "copying $SRC to $TGT" && cp $SRC $TGT
2823
2824         echo "copying necessary lib to $DIR"
2825         [ -d /lib64 ] && LIB71=/lib64 || LIB71=/lib
2826         mkdir -p $DIR$LIB71 || error "can't create $DIR$LIB71"
2827         cp $LIB71/libc* $DIR$LIB71 || error "can't copy $LIB71/libc*"
2828         cp $LIB71/ld-* $DIR$LIB71 || error "can't create $LIB71/ld-*"
2829
2830         echo "chroot $DIR /dbench -c client.txt 2"
2831         chroot $DIR /dbench -c client.txt 2
2832         RC=$?
2833
2834         rm -rf $DIR/dbench $TGT $DIR$LIB71
2835
2836         return $RC
2837 }
2838 run_test 71 "Running dbench on lustre (don't segment fault) ===="
2839
2840 test_72() { # bug 5695 - Test that on 2.6 remove_suid works properly
2841         check_kernel_version 43 || return 0
2842         [ "$RUNAS_ID" = "$UID" ] && echo "skipping $TESTNAME" && return
2843         touch $DIR/f72
2844         chmod 777 $DIR/f72
2845         chmod ug+s $DIR/f72
2846         $RUNAS -u $(($RUNAS_ID + 1)) dd if=/dev/zero of=$DIR/f72 bs=512 count=1 || error
2847         # See if we are still setuid/sgid
2848         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on write"
2849         # Now test that MDS is updated too
2850         cancel_lru_locks mdc
2851         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on MDS"
2852         true
2853 }
2854 run_test 72 "Test that remove suid works properly (bug5695) ===="
2855
2856 # bug 3462 - multiple simultaneous MDC requests
2857 test_73() {
2858         mkdir $DIR/d73-1 
2859         mkdir $DIR/d73-2
2860         multiop $DIR/d73-1/f73-1 O_c &
2861         pid1=$!
2862         #give multiop a chance to open
2863         usleep 500
2864
2865         #define OBD_FAIL_MDS_PAUSE_OPEN 0x129
2866         sysctl -w lustre.fail_loc=0x80000129
2867         multiop $DIR/d73-1/f73-2 Oc &
2868         sleep 1
2869         sysctl -w lustre.fail_loc=0
2870
2871         multiop $DIR/d73-2/f73-3 Oc &
2872         pid3=$!
2873
2874         kill -USR1 $pid1
2875         wait $pid1 || return 1
2876
2877         sleep 25
2878
2879         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
2880         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5 
2881         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6 
2882
2883         rm -rf $DIR/d73-*
2884 }
2885 run_test 73 "multiple MDC requests (should not deadlock)"
2886
2887 test_74() { # bug 6149, 6184
2888         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
2889         #
2890         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
2891         # will spin in a tight reconnection loop
2892         sysctl -w lustre.fail_loc=0x8000030e
2893         # get any lock
2894         touch $DIR/f74
2895         sysctl -w lustre.fail_loc=0
2896         true
2897 }
2898 run_test 74 "ldlm_enqueue freed-export error path (shouldn't LBUG)"
2899
2900 JOIN=${JOIN:-"lfs join"}
2901 F75=$DIR/f75
2902 F128k=${F75}_128k
2903 FHEAD=${F75}_head
2904 FTAIL=${F75}_tail
2905 export T75_PREP=no
2906 test75_prep() {
2907         [ $T75_PREP = "yes" ] && return
2908         echo "using F75=$F75, F128k=$F128k, FHEAD=$FHEAD, FTAIL=$FTAIL"
2909  
2910         dd if=/dev/urandom of=${F75}_128k bs=128k count=1 || error "dd failed"
2911         log "finished dd"
2912         chmod 777 ${F128k}
2913         T75_PREP=yes
2914 }
2915  
2916 test_75a() {
2917         test75_prep
2918  
2919         cp -p ${F128k} ${FHEAD}
2920         log "finished cp to $FHEAD"
2921         cp -p ${F128k} ${FTAIL}
2922         log "finished cp to $FTAIL"
2923         cat ${F128k} ${F128k} > ${F75}_sim_sim
2924  
2925         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
2926         log "finished join $FHEAD to ${F75}_sim_sim"
2927         cmp ${FHEAD} ${F75}_sim_sim || error "${FHEAD} ${F75}_sim_sim differ"
2928         log "finished cmp $FHEAD to ${F75}_sim_sim"
2929         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} still exist after join"
2930 }
2931 run_test 75a "TEST join file ===================================="
2932  
2933 test_75b() {
2934         test75_prep
2935  
2936         cp -p ${F128k} ${FTAIL}
2937         cat ${F75}_sim_sim >> ${F75}_join_sim
2938         cat ${F128k} >> ${F75}_join_sim
2939         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
2940         cmp ${FHEAD} ${F75}_join_sim || \
2941                 error "${FHEAD} ${F75}_join_sim are different"
2942         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join"
2943 }
2944 run_test 75b "TEST join file 2 =================================="
2945  
2946 test_75c() {
2947         test75_prep
2948  
2949         cp -p ${F128k} ${FTAIL}
2950         cat ${F128k} >> ${F75}_sim_join
2951         cat ${F75}_join_sim >> ${F75}_sim_join
2952         $JOIN ${FTAIL} ${FHEAD} || error "join error"
2953         cmp ${FTAIL} ${F75}_sim_join || \
2954                 error "${FTAIL} ${F75}_sim_join are different"
2955         $CHECKSTAT -a ${FHEAD} || error "tail ${FHEAD} exist after join"
2956 }
2957 run_test 75c "TEST join file 3 =================================="
2958  
2959 test_75d() {
2960         test75_prep
2961  
2962         cp -p ${F128k} ${FHEAD}
2963         cp -p ${F128k} ${FHEAD}_tmp
2964         cat ${F75}_sim_sim >> ${F75}_join_join
2965         cat ${F75}_sim_join >> ${F75}_join_join
2966         $JOIN ${FHEAD} ${FHEAD}_tmp || error "join ${FHEAD} ${FHEAD}_tmp error"
2967         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
2968         cmp ${FHEAD} ${F75}_join_join ||error "${FHEAD} ${F75}_join_join differ"        $CHECKSTAT -a ${FHEAD}_tmp || error "${FHEAD}_tmp exist after join"
2969         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join (2)"
2970 }
2971 run_test 75d "TEST join file 4 =================================="
2972  
2973 test_75e() {
2974         test75_prep
2975  
2976         rm -rf ${FHEAD} || "delete join file error"
2977 }
2978 run_test 75e "TEST join file 5 (remove joined file) ============="
2979  
2980 test_75f() {
2981         test75_prep
2982  
2983         cp -p ${F128k} ${F75}_join_10_compare
2984         cp -p ${F128k} ${F75}_join_10
2985         for ((i = 0; i < 10; i++)); do
2986                 cat ${F128k} >> ${F75}_join_10_compare
2987                 cp -p ${F128k} ${FTAIL}
2988                 $JOIN ${F75}_join_10 ${FTAIL} || \
2989                         error "join ${F75}_join_10 ${FTAIL} error"
2990                 $CHECKSTAT -a ${FTAIL} || error "tail file exist after join"
2991         done
2992         cmp ${F75}_join_10 ${F75}_join_10_compare || \
2993                 error "files ${F75}_join_10 ${F75}_join_10_compare differ"
2994 }
2995 run_test 75f "TEST join file 6 (join 10 files) =================="
2996  
2997 test_75g() {
2998         [ ! -f ${F75}_join_10 ] && echo "${F75}_join_10 missing" && return
2999         $LFS getstripe ${F75}_join_10
3000  
3001         $OPENUNLINK ${F75}_join_10 ${F75}_join_10 || error "files unlink open"
3002  
3003         ls -l $F75*
3004 }
3005 run_test 75g "TEST join file 7 (open unlink) ===================="
3006
3007 num_inodes() {
3008         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
3009 }
3010
3011 test_76() { # bug 1443
3012         DETH=$(grep deathrow /proc/kallsyms /proc/ksyms 2> /dev/null | wc -l)
3013         [ $DETH -eq 0 ] && echo "No _iget, skipping" && return 0
3014         BEFORE_INODES=`num_inodes`
3015         echo "before inodes: $BEFORE_INODES"
3016         for i in `seq 1000`; do
3017                 touch $DIR/$tfile
3018                 rm -f $DIR/$tfile
3019         done
3020         AFTER_INODES=`num_inodes`
3021         echo "after inodes: $AFTER_INODES"
3022         [ $AFTER_INODES -gt $((BEFORE_INODES + 32)) ] && \
3023                 error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
3024         true
3025 }
3026 run_test 76 "destroy duplicate inodes in client inode cache ===="
3027
3028 export ORIG_CSUM=""
3029 set_checksums()
3030 {
3031         [ "$ORIG_CSUM" ]||ORIG_CSUM=`cat $LPROC/llite/*/checksum_pages|head -n1`
3032         for f in $LPROC/llite/*/checksum_pages; do
3033                 echo $1 >> $f
3034         done
3035
3036         return 0
3037 }
3038
3039 F77_TMP=$TMP/f77-temp
3040 F77SZ=8
3041 setup_f77() {
3042         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
3043                 error "error writing to $F77_TMP"
3044 }
3045
3046 test_77a() { # bug 10889
3047         [ ! -f $F77_TMP ] && setup_f77
3048         set_checksums 1
3049         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
3050         set_checksums 0
3051 }
3052 run_test 77a "normal checksum read/write operation ============="
3053
3054 test_77b() { # bug 10889
3055         [ ! -f $F77_TMP ] && setup_f77
3056         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3057         sysctl -w lustre.fail_loc=0x80000409
3058         set_checksums 1
3059         dd if=$F77_TMP of=$DIR/f77b bs=1M count=$F77SZ conv=sync || \
3060                 error "dd error: $?"
3061         sysctl -w lustre.fail_loc=0
3062         set_checksums 0
3063 }
3064 run_test 77b "checksum error on client write ===================="
3065
3066 test_77c() { # bug 10889
3067         [ ! -f $DIR/f77b ] && log "requires 77b - skipping" && return  
3068         cancel_lru_locks osc
3069         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
3070         sysctl -w lustre.fail_loc=0x80000408
3071         set_checksums 1
3072         cmp $F77_TMP $DIR/f77b || error "file compare failed"
3073         sysctl -w lustre.fail_loc=0
3074         set_checksums 0
3075 }
3076 run_test 77c "checksum error on client read ==================="
3077
3078 test_77d() { # bug 10889
3079         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3080         sysctl -w lustre.fail_loc=0x80000409
3081         set_checksums 1
3082         directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
3083                 error "direct write: rc=$?"
3084         sysctl -w lustre.fail_loc=0
3085         set_checksums 0
3086 }
3087 run_test 77d "checksum error on OST direct write ==============="
3088
3089 test_77e() { # bug 10889
3090         [ ! -f $DIR/f77 ] && log "requires 77d - skipping" && return  
3091         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
3092         sysctl -w lustre.fail_loc=0x80000408
3093         set_checksums 1
3094         cancel_lru_locks osc
3095         directio read $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
3096                 error "direct read: rc=$?"
3097         sysctl -w lustre.fail_loc=0
3098         set_checksums 0
3099 }
3100 run_test 77e "checksum error on OST direct read ================"
3101
3102 test_77f() { # bug 10889
3103         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
3104         sysctl -w lustre.fail_loc=0x409
3105         set_checksums 1
3106         directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) && \
3107                 error "direct write succeeded"
3108         sysctl -w lustre.fail_loc=0
3109         set_checksums 0
3110 }
3111 run_test 77f "repeat checksum error on write (expect error) ===="
3112
3113 test_77g() { # bug 10889
3114         [ $(grep -c obdfilter $LPROC/devices) -eq 0 ] && \
3115                 echo "skipping $TESTNAME (remote OST)" && return
3116         [ ! -f $F77_TMP ] && setup_f77
3117         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
3118         sysctl -w lustre.fail_loc=0x8000021a
3119         set_checksums 1
3120         dd if=$F77_TMP of=$DIR/f77g bs=1M count=$F77SZ || \
3121                 error "write error: rc=$?"
3122         sysctl -w lustre.fail_loc=0
3123         set_checksums 0
3124 }
3125 run_test 77g "checksum error on OST write ======================"
3126
3127 test_77h() { # bug 10889
3128         [ $(grep -c obdfilter $LPROC/devices) -eq 0 ] && \
3129                 echo "skipping $TESTNAME (remote OST)" && return
3130         [ ! -f $DIR/f77g ] && log "requires 77g - skipping" && return  
3131         cancel_lru_locks osc
3132         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
3133         sysctl -w lustre.fail_loc=0x8000021b
3134         set_checksums 1
3135         cmp $F77_TMP $DIR/f77g || error "file compare failed"
3136         sysctl -w lustre.fail_loc=0
3137         set_checksums 0
3138 }
3139 run_test 77h "checksum error on OST read ======================="
3140
3141 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
3142 rm -f $F77_TMP
3143 unset F77_TMP
3144
3145 test_78() { # bug 10901
3146         NSEQ=5
3147         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
3148         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
3149         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 2048))
3150         echo "MemTotal: $((MEMTOTAL * 2))"
3151         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
3152         [ $F78SIZE -gt 512 ] && F78SIZE=512
3153         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
3154         SMALLESTOST=`lfs df $DIR |grep OST | awk '{print $4}' |sort -n |head -1`
3155         echo "Smallest OST: $SMALLESTOST"
3156         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024)) ] && \
3157                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024))
3158         echo "File size: $F78SIZE"
3159         $SETSTRIPE $DIR/$tfile 0 -1 -1 || error "setstripe failed"
3160         for i in `seq 1 $NSEQ`
3161         do
3162                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
3163                 echo directIO rdwr round $i of $NSEQ
3164                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
3165         done
3166
3167         rm -f $DIR/$tfile
3168 }
3169 run_test 78 "handle large O_DIRECT writes correctly ============"
3170
3171 # on the LLNL clusters, runas will still pick up root's $TMP settings,
3172 # which will not be writable for the runas user, and then you get a CVS
3173 # error message with a corrupt path string (CVS bug) and panic.
3174 # We're not using much space, so just stick it in /tmp, which is safe.
3175 OLDTMPDIR=$TMPDIR
3176 OLDTMP=$TMP
3177 TMPDIR=/tmp
3178 TMP=/tmp
3179 OLDHOME=$HOME
3180 [ $RUNAS_ID -ne $UID ] && HOME=/tmp
3181
3182 test_99a() {
3183         mkdir -p $DIR/d99cvsroot || error "mkdir $DIR/d99cvsroot failed"
3184         chown $RUNAS_ID $DIR/d99cvsroot || error "chown $DIR/d99cvsroot failed"
3185         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
3186 }
3187 run_test 99a "cvs init ========================================="
3188
3189 test_99b() {
3190         [ ! -d $DIR/d99cvsroot ] && test_99a
3191         cd /etc/init.d || error "cd /etc/init.d failed"
3192         # some versions of cvs import exit(1) when asked to import links or
3193         # files they can't read.  ignore those files.
3194         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
3195                         ! -perm +4 -printf '-I %f\n')
3196         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
3197                 d99reposname vtag rtag || error "cvs import failed"
3198 }
3199 run_test 99b "cvs import ======================================="
3200
3201 test_99c() {
3202         [ ! -d $DIR/d99cvsroot ] && test_99b
3203         cd $DIR || error "cd $DIR failed"
3204         mkdir -p $DIR/d99reposname || error "mkdir $DIR/d99reposname failed"
3205         chown $RUNAS_ID $DIR/d99reposname || \
3206                 error "chown $DIR/d99reposname failed"
3207         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname || \
3208                 error "cvs co d99reposname failed"
3209 }
3210 run_test 99c "cvs checkout ====================================="
3211
3212 test_99d() {
3213         [ ! -d $DIR/d99cvsroot ] && test_99c
3214         cd $DIR/d99reposname
3215         $RUNAS touch foo99
3216         $RUNAS cvs add -m 'addmsg' foo99
3217 }
3218 run_test 99d "cvs add =========================================="
3219
3220 test_99e() {
3221         [ ! -d $DIR/d99cvsroot ] && test_99c
3222         cd $DIR/d99reposname
3223         $RUNAS cvs update
3224 }
3225 run_test 99e "cvs update ======================================="
3226
3227 test_99f() {
3228         [ ! -d $DIR/d99cvsroot ] && test_99d
3229         cd $DIR/d99reposname
3230         $RUNAS cvs commit -m 'nomsg' foo99
3231 }
3232 run_test 99f "cvs commit ======================================="
3233
3234 test_100() {
3235         netstat -tna | while read PROT SND RCV LOCAL REMOTE STAT; do
3236                 [ "$PROT" != "tcp" ] && continue
3237                 RPORT=`echo $REMOTE | cut -d: -f2`
3238                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
3239                 LPORT=`echo $LOCAL | cut -d: -f2`
3240                 if [ $LPORT -ge 1024 ]; then
3241                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
3242                         netstat -tna
3243                         error "local: $LPORT > 1024, remote: $RPORT"
3244                 fi
3245         done
3246         true
3247 }
3248 run_test 100 "check local port using privileged port ==========="
3249
3250 function get_named_value()
3251 {
3252     local tag
3253
3254     tag=$1
3255     while read ;do
3256         line=$REPLY
3257         case $line in
3258         $tag*)
3259             echo $line | sed "s/^$tag//"
3260             break
3261             ;;
3262         esac
3263     done
3264 }
3265
3266 export CACHE_MAX=`cat $LPROC/llite/*/max_cached_mb | head -n 1`
3267 cleanup_101() {
3268         for s in $LPROC/llite/*/max_cached_mb; do
3269                 echo $CACHE_MAX > $s
3270         done
3271         trap 0
3272 }
3273
3274 test_101() {
3275         local s
3276         local discard
3277         local nreads=10000
3278         [ "$CPU" = "UML" ] && nreads=1000
3279         local cache_limit=32
3280
3281         for s in $LPROC/osc/*/rpc_stats; do
3282                 echo 0 > $s
3283         done
3284         trap cleanup_101 EXIT
3285         for s in $LPROC/llite/*; do
3286                 echo 0 > $s/read_ahead_stats
3287                 echo $cache_limit > $s/max_cached_mb
3288         done
3289
3290         #
3291         # randomly read 10000 of 64K chunks from file 3x 32MB in size
3292         #
3293         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
3294         $RANDOM_READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
3295
3296         discard=0
3297         for s in $LPROC/llite/*; do
3298                 discard=$(($discard + $(cat $s/read_ahead_stats | get_named_value 'read but discarded')))
3299         done
3300         cleanup_101
3301
3302         if [ $(($discard * 10)) -gt $nreads ] ;then
3303                 for s in $LPROC/osc/*/rpc_stats; do
3304                         echo $s; cat $s
3305                 done
3306                 for s in $LPROC/llite/*/read_ahead_stats; do
3307                         echo $s; cat $s
3308                 done
3309                 error "too many ($discard) discarded pages" 
3310         fi
3311         rm -f $DIR/$tfile || true
3312 }
3313 run_test 101 "check read-ahead for random reads ================"
3314
3315 export SETUP_TEST102=no
3316 setup_test102() {
3317         [ "$SETUP_TEST102" = "yes" ] && return
3318         mkdir -p $DIR/$tdir
3319         STRIPE_SIZE=65536
3320         STRIPE_COUNT=4 
3321         STRIPE_OFFSET=2
3322
3323         trap cleanup_test102 EXIT
3324         cd $DIR
3325         $SETSTRIPE $tdir $STRIPE_SIZE  $STRIPE_OFFSET $STRIPE_COUNT
3326         cd $DIR/$tdir 
3327         for num in 1 2 3 4
3328         do
3329                 for count in 1 2 3 4
3330                 do
3331                         for offset in 0 1 2 3 
3332                         do
3333                                 local stripe_size=`expr $STRIPE_SIZE \* $num`
3334                                 local file=file"$num-$offset-$count"
3335                                 $SETSTRIPE $file $stripe_size  $offset $count
3336                         done
3337                 done
3338         done
3339
3340         cd ..
3341         star -c  f=$TMP/f102.tar $tdir 
3342         SETUP_TEST102=yes
3343 }
3344
3345 cleanup_test102() {
3346         [ "$SETUP_TEST102" = "yes" ] || return
3347         trap 0
3348         rm -f $TMP/f102.tar
3349         rm -rf $DIR/$tdir
3350         SETUP_TEST102=no
3351 }
3352
3353 test_102a() {
3354         local testfile=$DIR/xattr_testfile
3355
3356         rm -f $testfile
3357         touch $testfile
3358
3359         [ "$UID" != 0 ] && echo "skipping $TESTNAME (must run as root)" && return
3360         [ -z "`grep xattr $LPROC/mdc/*[mM][dD][cC]*/connect_flags`" ] && echo "skipping $TESTNAME (must have user_xattr)" && return
3361         [ -z "$(which setfattr 2>/dev/null)" ] && echo "skipping $TESTNAME (could not find setfattr)" && return
3362
3363         echo "set/get xattr..."
3364         setfattr -n trusted.name1 -v value1 $testfile || error
3365         [ "`getfattr -n trusted.name1 $testfile 2> /dev/null | \
3366         grep "trusted.name1"`" == "trusted.name1=\"value1\"" ] || error
3367  
3368         setfattr -n user.author1 -v author1 $testfile || error
3369         [ "`getfattr -n user.author1 $testfile 2> /dev/null | \
3370         grep "user.author1"`" == "user.author1=\"author1\"" ] || error
3371
3372         echo "listxattr..."
3373         setfattr -n trusted.name2 -v value2 $testfile || error
3374         setfattr -n trusted.name3 -v value3 $testfile || error
3375         [ `getfattr -d -m "^trusted" $testfile 2> /dev/null | \
3376         grep "trusted.name" | wc -l` -eq 3 ] || error
3377
3378  
3379         setfattr -n user.author2 -v author2 $testfile || error
3380         setfattr -n user.author3 -v author3 $testfile || error
3381         [ `getfattr -d -m "^user" $testfile 2> /dev/null | \
3382         grep "user" | wc -l` -eq 3 ] || error
3383
3384         echo "remove xattr..."
3385         setfattr -x trusted.name1 $testfile || error
3386         getfattr -d -m trusted $testfile 2> /dev/null | \
3387         grep "trusted.name1" && error || true
3388
3389         setfattr -x user.author1 $testfile || error
3390         getfattr -d -m user $testfile 2> /dev/null | \
3391         grep "user.author1" && error || true
3392
3393         # b10667: setting lustre special xattr be silently discarded
3394         echo "set lustre special xattr ..."
3395         setfattr -n "trusted.lov" -v "invalid value" $testfile || error
3396
3397         rm -f $testfile
3398 }
3399 run_test 102a "user xattr test =================================="
3400
3401 test_102b() {
3402         # b10930: get/set/list trusted.lov xattr
3403         echo "get/set/list trusted.lov xattr ..."
3404         [ "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
3405         local testfile=$DIR/$tfile
3406         $SETSTRIPE $testfile 65536 1 2
3407         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
3408         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
3409
3410         local testfile2=${testfile}2
3411         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
3412                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
3413         
3414         $MCREATE $testfile2
3415         setfattr -n trusted.lov -v $value $testfile2    
3416         local tmp_file=${testfile}3
3417         $GETSTRIPE -v $testfile2 > $tmp_file
3418         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
3419         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
3420         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
3421         [ $stripe_count -eq 2 ] || error "stripe count $stripe_count != 2"
3422 }
3423 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
3424
3425 test_102c() {
3426         # b10930: get/set/list trusted.lov xattr
3427         echo "get/set/list trusted.lov xattr ..."
3428         [ "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
3429         mkdir -p $DIR/$tdir
3430         chown $RUNAS_ID $DIR/$tdir
3431         local testfile=$DIR/$tdir/$tfile
3432         $RUNAS $SETSTRIPE $testfile 65536 1 2
3433         $RUNAS getfattr -d -m "^trusted" $testfile 2> /dev/null | \
3434         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
3435
3436         local testfile2=${testfile}2
3437         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
3438                      grep "trusted.lov" |sed -e 's/[^=]\+=//'  `
3439         
3440         $RUNAS $MCREATE $testfile2
3441         $RUNAS setfattr -n trusted.lov -v $value $testfile2     
3442         local tmp_file=${testfile}3
3443         $RUNAS $GETSTRIPE -v $testfile2 > $tmp_file
3444         local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
3445         local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
3446         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
3447         [ $stripe_count -eq 2 ] || error "stripe count $stripe_count != 2"
3448 }
3449 run_test 102c "non-root getfattr/setfattr for trusted.lov EAs ==========="
3450
3451 get_stripe_info() {
3452         stripe_size=0
3453         stripe_count=0
3454         stripe_offset=0
3455         local lines=`sed -n '/obdidx/=' $1`
3456         stripe_size=`awk '{if($1~/size/) print $2}' $1`
3457         stripe_count=`awk '{if($1~/count/) print $2}' $1`
3458         lines=`expr $lines + 1`
3459         stripe_offset=`sed -n ${lines}p $1 |awk '{print $1}'`
3460 }
3461
3462 compare_stripe_info1() {
3463         for num in 1 2 3 4
3464         do
3465                 for count in 1 2 3 4
3466                 do
3467                         for offset in 0 1 2 3 
3468                         do
3469                                 local size=`expr $STRIPE_SIZE \* $num`
3470                                 local file=file"$num-$offset-$count"
3471                                 local tmp_file=out
3472                                 $GETSTRIPE -v $file > $tmp_file 
3473                                 get_stripe_info  $tmp_file
3474                                 if test $stripe_size -ne $size
3475                                 then
3476                                         error "$file: different stripe size" && return
3477                                 fi
3478                                 if test $stripe_count -ne $count
3479                                 then
3480                                         error "$file: different stripe count" && return
3481                                 fi
3482                                 if test $stripe_offset -ne 0
3483                                 then
3484                                         error "$file: different stripe offset" && return
3485                                 fi
3486                                 rm -f $tmp_file
3487                         done
3488                 done
3489         done
3490 }
3491
3492 compare_stripe_info2() {
3493         for num in 1 2 3 4
3494         do
3495                 for count in 1 2 3 4
3496                 do
3497                         for offset in 0 1 2 3 
3498                         do
3499                                 local size=`expr $STRIPE_SIZE \* $num`
3500                                 local file=file"$num-$offset-$count"
3501                                 local tmp_file=out
3502                                 $GETSTRIPE -v $file > $tmp_file
3503                                 get_stripe_info  $tmp_file
3504                                 if test $stripe_size -ne $size
3505                                 then
3506                                         error "$file: different stripe size" && return  
3507                                 fi
3508                                 if test $stripe_count -ne $count
3509                                 then
3510                                         error "$file: different stripe count" && return
3511                                 fi
3512                                 if test $stripe_offset -ne $offset
3513                                 then
3514                                         error "$file: different stripe offset" && return
3515                                 fi
3516                                 rm -f $tmp_file
3517                         done
3518                 done
3519         done
3520 }
3521
3522 test_102d() {
3523         # b10930: star test for trusted.lov xattr
3524         star --xhelp 2>&1 | grep -q nolustre  
3525         if [ $? -ne 0 ]
3526         then
3527                 echo "$TESTNUM being skipped because a lustre-aware star is not installed." && return
3528         fi
3529         [ "$OSTCOUNT" -lt "4" ] && echo "skipping 4-stripe test" && return
3530         setup_test102
3531         mkdir -p $DIR/d102d
3532         star -x  f=$TMP/f102.tar -C $DIR/d102d
3533         cd $DIR/d102d/$tdir
3534         compare_stripe_info1
3535
3536 }
3537 run_test 102d "star restore stripe info from tarfile,not keep osts ==========="
3538
3539 test_102e() {
3540         # b10930: star test for trusted.lov xattr
3541         star --xhelp 2>&1 | grep -q nolustre  
3542         if [ $? -ne 0 ]
3543         then
3544                 echo "$TESTNUM being skipped because a lustre-aware star is not installed." && return
3545         fi
3546         [ "$OSTCOUNT" -lt "4" ] && echo "skipping 4-stripe test" && return
3547         setup_test102
3548         mkdir -p $DIR/d102e
3549         star -x  -preserve-osts f=$TMP/f102.tar -C $DIR/d102e
3550         cd $DIR/d102e/$tdir
3551         compare_stripe_info2
3552 }
3553 run_test 102e "star restore stripe info from tarfile, keep osts ==========="
3554
3555 test_102f() {
3556         # b10930: star test for trusted.lov xattr
3557         star --xhelp 2>&1 | grep -q nolustre  
3558         if [ $? -ne 0 ]
3559         then
3560                 echo "$TESTNUM being skipped because a lustre-aware star is not installed." && return
3561         fi
3562         [ "$OSTCOUNT" -lt "4" ] && echo "skipping 4-stripe test" && return
3563         setup_test102
3564         mkdir -p $DIR/d102f
3565         cd $DIR
3566         star -copy  $tdir $DIR/d102f
3567         cd $DIR/d102f/$tdir
3568         compare_stripe_info1
3569 }
3570 run_test 102f "star copy files, not keep osts ==========="
3571
3572 test_102g() {
3573         # b10930: star test for trusted.lov xattr
3574         star --xhelp 2>&1 | grep -q nolustre  
3575         if [ $? -ne 0 ]
3576         then
3577                 echo "$TESTNUM being skipped because a lustre-aware star is not installed." && return
3578         fi
3579         [ "$OSTCOUNT" -lt "4" ] && echo "skipping 4-stripe test" && return
3580         setup_test102
3581         mkdir -p $DIR/d102g
3582         cd $DIR
3583         star -copy -preserve-osts $tdir $DIR/d102g
3584         cd $DIR/d102g/$tdir
3585         compare_stripe_info2
3586         cleanup_test102
3587 }
3588 run_test 102g "star copy files, keep osts ==========="
3589
3590 run_acl_subtest()
3591 {
3592     $SAVE_PWD/acl/run $SAVE_PWD/acl/$1.test
3593     return $?
3594 }
3595
3596 test_103 () {
3597     [ "$UID" != 0 ] && echo "skipping $TESTNAME (must run as root)" && return
3598     [ -z "$(grep acl $LPROC/mdc/*[mM][dD][cC]*/connect_flags)" ] && echo "skipping $TESTNAME (must have acl enabled)" && return
3599     [ -z "$(which setfacl 2>/dev/null)" ] && echo "skipping $TESTNAME (could not find setfacl)" && return
3600
3601     SAVE_UMASK=`umask`
3602     umask 0022
3603     cd $DIR
3604
3605     echo "performing cp ..."
3606     run_acl_subtest cp || error
3607     echo "performing getfacl-noacl..."
3608     run_acl_subtest getfacl-noacl || error
3609     echo "performing misc..."
3610     run_acl_subtest misc || error
3611 #    XXX add back permission test when we support supplementary groups.
3612 #    echo "performing permissions..."
3613 #    run_acl_subtest permissions || error
3614     echo "performing setfacl..."
3615     run_acl_subtest setfacl || error
3616
3617     # inheritance test got from HP
3618     echo "performing inheritance..."
3619     cp $SAVE_PWD/acl/make-tree . || error
3620     chmod +x make-tree || error
3621     run_acl_subtest inheritance || error
3622     rm -f make-tree
3623
3624     cd $SAVE_PWD
3625     umask $SAVE_UMASK
3626 }
3627 run_test 103 "acl test ========================================="
3628
3629 test_104() {
3630         touch $DIR/$tfile
3631         lfs df || error "lfs df failed"
3632         lfs df -ih || error "lfs df -ih failed"
3633         lfs df -h $DIR || error "lfs df -h $DIR failed"
3634         lfs df -i $DIR || error "lfs df -i $DIR failed"
3635         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
3636         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
3637         
3638         OSC=`awk '/-osc-|OSC.*MNT/ {print $4}' $LPROC/devices | head -n 1`
3639         lctl --device %$OSC deactivate
3640         lfs df || error "lfs df with deactivated OSC failed"
3641         lctl --device %$OSC recover
3642         lfs df || error "lfs df with reactivated OSC failed"
3643 }
3644 run_test 104 "lfs df [-ih] [path] test ========================="
3645
3646 test_105a() {
3647         # doesn't work on 2.4 kernels
3648         touch $DIR/$tfile
3649         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
3650         then
3651                 flocks_test on -f $DIR/$tfile || error "fail flock on"
3652         else
3653                 flocks_test off -f $DIR/$tfile || error "fail flock off"
3654         fi
3655 }
3656 run_test 105a "flock when mounted without -o flock test ========"
3657
3658 test_105b() {
3659         touch $DIR/$tfile
3660         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
3661         then
3662                 flocks_test on -c $DIR/$tfile || error "fail flock on"
3663         else
3664                 flocks_test off -c $DIR/$tfile || error "fail flock off"
3665         fi
3666 }
3667 run_test 105b "fcntl when mounted without -o flock test ========"
3668
3669 test_105c() {
3670         touch $DIR/$tfile
3671         if [ -n "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ];
3672         then
3673                 flocks_test on -l $DIR/$tfile || error "fail flock on"
3674         else
3675                 flocks_test off -l $DIR/$tfile || error "fail flock off"
3676         fi
3677 }
3678 run_test 105c "lockf when mounted without -o flock test ========"
3679
3680 test_106() { #bug 10921
3681         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3682         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
3683         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
3684 }
3685 run_test 106 "attempt exec of dir followed by chown of that dir"
3686
3687 test_107() {
3688         CDIR=`pwd`
3689         cd $DIR
3690         ulimit -c unlimited
3691         sleep 60 &
3692         SLEEPPID=$!
3693
3694         file=`cat /proc/sys/kernel/core_pattern`
3695         core_pid=`cat /proc/sys/kernel/core_uses_pid`
3696         [ $core_pid -eq 1 ] && file=$file.$SLEEPPID
3697         rm -f $file
3698         sleep 1
3699
3700         kill -s 11 $SLEEPPID
3701         wait $SLEEPPID
3702         if [ -e $file ]; then
3703                 size=`stat -c%s $file`
3704                 [ $size -eq 0 ] && error "Zero length core file $file"
3705         else
3706                 error "Fail to create core file $file"
3707         fi
3708         rm -f $file
3709         cd $CDIR
3710 }
3711 run_test 107 "Coredump on SIG"
3712
3713 test_115() {
3714         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
3715             cut -c11-20)
3716         [ -z "$OSTIO_pre" ] && echo "skipping $TESTNAME: no OSS threads" && \
3717             return
3718         echo "Starting with $OSTIO_pre threads"
3719
3720         NUMTEST=20000
3721         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
3722         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
3723         echo "$NUMTEST creates/unlinks"
3724         mkdir -p $DIR/$tdir
3725         createmany -o $DIR/$tdir/$tfile $NUMTEST
3726         unlinkmany $DIR/$tdir/$tfile $NUMTEST
3727
3728         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
3729             cut -c11-20)
3730
3731         # don't return an error
3732         [ $OSTIO_post -eq $OSTIO_pre ] && echo \
3733             "FAIL: No addition ll_ost_io threads were created ($OSTIO_pre)" &&\
3734             echo "This may be fine, depending on what ran before this test" &&\
3735             echo "and how fast this system is." && return
3736
3737         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
3738 }
3739 run_test 115 "verify dynamic thread creation===================="
3740
3741 free_min_max () {
3742         AVAIL=($(cat $LPROC/osc/*[oO][sS][cC][-_]*/kbytesavail))
3743         echo OST kbytes available: ${AVAIL[@]}
3744         MAXI=0; MAXV=${AVAIL[0]}
3745         MINI=0; MINV=${AVAIL[0]}
3746         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
3747             #echo OST $i: ${AVAIL[i]}kb
3748             if [ ${AVAIL[i]} -gt $MAXV ]; then
3749                 MAXV=${AVAIL[i]}; MAXI=$i
3750             fi
3751             if [ ${AVAIL[i]} -lt $MINV ]; then
3752                 MINV=${AVAIL[i]}; MINI=$i
3753             fi
3754         done
3755         echo Min free space: OST $MINI: $MINV 
3756         echo Max free space: OST $MAXI: $MAXV 
3757 }
3758
3759 test_116() {
3760         [ "$OSTCOUNT" -lt "2" ] && echo "not enough OSTs" && return
3761         [ $(grep -c obdfilter $LPROC/devices) -eq 0 ] &&
3762                 echo "remote MDS, skipping test" && return
3763
3764         echo -n "Free space priority "
3765         cat $LPROC/lov/*/qos_prio_free
3766         DELAY=$(cat $LPROC/lov/*/qos_maxage | head -1 | awk '{print $1}')
3767         declare -a AVAIL
3768         free_min_max
3769         [ $MINV -gt 960000 ] && echo "too much free space in OST$MINI, skip" &&\
3770                 return
3771
3772         # generate uneven OSTs
3773         mkdir -p $DIR/$tdir/OST${MINI}
3774         declare -i FILL
3775         FILL=$(($MINV / 4))
3776         echo "Filling 25% remaining space in OST${MINI} with ${FILL}Kb"
3777         $SETSTRIPE $DIR/$tdir/OST${MINI} 0 $MINI 1
3778         i=1
3779         while [ $FILL -gt 0 ]; do
3780             dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i bs=2M count=1 2>/dev/null
3781             FILL=$(($FILL - 2048))
3782             echo -n .
3783             i=$(($i + 1))
3784         done
3785         FILL=$(($MINV / 4))
3786         sync
3787         sleep $DELAY
3788
3789         free_min_max
3790         DIFF=$(($MAXV - $MINV))
3791         DIFF2=$(($DIFF * 100 / $MINV))
3792         echo -n "diff=${DIFF}=${DIFF2}% must be > 20% for QOS mode..."
3793         if [ $DIFF2 -gt 20 ]; then
3794             echo "ok"
3795         else
3796             echo "failed - QOS mode won't be used"
3797             error "QOS imbalance criteria not met"
3798             return
3799         fi
3800
3801         MINI1=$MINI; MINV1=$MINV
3802         MAXI1=$MAXI; MAXV1=$MAXV
3803
3804         # now fill using QOS
3805         echo writing a bunch of files to QOS-assigned OSTs
3806         i=1
3807         while [ $FILL -gt 0 ]; do
3808             dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1024 count=200 2>/dev/null
3809             FILL=$(($FILL - 200))
3810             echo -n .
3811             i=$(($i + 1))
3812         done
3813         echo "wrote $i 200k files"
3814         sync
3815         sleep $DELAY
3816
3817         echo "Note: free space may not be updated, so measurements might be off"
3818         free_min_max
3819         DIFF2=$(($MAXV - $MINV))
3820         echo "free space delta: orig $DIFF final $DIFF2"
3821         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!" 
3822         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
3823         echo "Wrote $DIFF to smaller OST $MINI1"
3824         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
3825         echo "Wrote $DIFF2 to larger OST $MAXI1"
3826         [ $DIFF -gt 0 ] && echo "Wrote $(($DIFF2 * 100 / $DIFF - 100))% more data to larger OST $MAXI1"
3827
3828         # Figure out which files were written where 
3829         UUID=$(awk '/'$MINI1': / {print $2; exit}' $LPROC/lov/${FSNAME}-clilov-*/target_obd)
3830         echo $UUID
3831         MINC=$($LFS getstripe --obd $UUID $DIR/$tdir | wc -l)
3832         echo "$MINC files created on smaller OST $MINI1"
3833         UUID=$(awk '/'$MAXI1': / {print $2; exit}' $LPROC/lov/${FSNAME}-clilov-*/target_obd)
3834         MAXC=$($LFS getstripe --obd $UUID $DIR/$tdir | wc -l)
3835         echo "$MAXC files created on larger OST $MAXI1"
3836         [ $MINC -gt 0 ] && echo "Wrote $(($MAXC * 100 / $MINC - 100))% more files to larger OST $MAXI1"
3837         [ $MAXC -gt $MINC ] || error "stripe QOS didn't balance free space"
3838 }
3839 run_test 116 "stripe QOS: free space balance ==================="
3840
3841 test_117() # bug 10891
3842 {
3843         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
3844         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
3845         sysctl -w lustre.fail_loc=0x21e
3846         > $DIR/$tfile || error "truncate failed"
3847         sysctl -w lustre.fail_loc=0
3848         echo "Truncate succeeded."
3849 }
3850 run_test 117 "verify fsfilt_extend ============================="
3851
3852 # Reset async IO behavior after error case
3853 reset_async() {
3854         FILE=$DIR/reset_async
3855
3856         # Ensure all OSCs are cleared
3857         $LSTRIPE $FILE 0 -1 -1
3858         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
3859         sync
3860         rm $FILE
3861 }
3862
3863 test_118a() #bug 11710
3864 {
3865         reset_async
3866
3867         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
3868         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
3869         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
3870
3871         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
3872                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
3873                 return 1;
3874         fi
3875 }
3876 run_test 118a "verify O_SYNC works ============================="
3877
3878 test_118b()
3879 {
3880         reset_async
3881
3882         #define OBD_FAIL_OST_ENOENT 0x217
3883         do_facet ost sysctl -w lustre.fail_loc=0x217
3884         multiop $DIR/$tfile Ow4096yc
3885         RC=$?
3886         do_facet ost sysctl -w lustre.fail_loc=0
3887         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
3888         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
3889
3890         if [[ $RC -eq 0 ]]; then
3891                 error "Must return error due to dropped pages, rc=$RC"
3892                 return 1;
3893         fi
3894
3895         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
3896                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
3897                 return 1;
3898         fi
3899
3900         echo "Dirty pages not leaked on ENOENT"
3901
3902         # Due to the above error the OSC will issue all RPCs syncronously
3903         # until a subsequent RPC completes successfully without error.
3904         multiop $DIR/$tfile Ow4096yc
3905         rm -f $DIR/$tfile
3906         
3907         return 0
3908 }
3909 run_test 118b "Reclaim dirty pages on fatal error =============="
3910
3911 test_118c()
3912 {
3913         reset_async
3914
3915         #define OBD_FAIL_OST_EROFS               0x216
3916         do_facet ost sysctl -w lustre.fail_loc=0x216
3917
3918         # multiop should block due to fsync until pages are written
3919         multiop $DIR/$tfile Ow4096yc &
3920         MULTIPID=$!
3921         sleep 1
3922
3923         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
3924                 error "Multiop failed to block on fsync, pid=$MULTIPID"
3925         fi
3926
3927         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
3928         if [[ $WRITEBACK -eq 0 ]]; then
3929                 error "No page in writeback, writeback=$WRITEBACK"
3930         fi
3931
3932         do_facet ost sysctl -w lustre.fail_loc=0
3933         wait $MULTIPID
3934         RC=$?
3935         if [[ $RC -ne 0 ]]; then
3936                 error "Multiop fsync failed, rc=$RC"
3937         fi
3938
3939         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
3940         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
3941         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
3942                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
3943         fi
3944         
3945         rm -f $DIR/$tfile
3946         echo "Dirty pages flushed via fsync on EROFS"
3947         return 0
3948 }
3949 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed"
3950
3951 test_118d()
3952 {
3953         reset_async
3954
3955         #define OBD_FAIL_OST_BRW_PAUSE_BULK
3956         do_facet ost sysctl -w lustre.fail_loc=0x214
3957         # set 10s timeout
3958         echo "10" > $LPROC/osc/resend_timeout
3959         # multiop should block due to fsync until pages are written
3960         multiop $DIR/$tfile Ow4096yc &
3961         
3962         MULTIPID=$!
3963         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
3964                 error "Multiop failed to block on fsync, pid=$MULTIPID"
3965         fi
3966
3967         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
3968         if [[ $WRITEBACK -eq 0 ]]; then
3969                 error "No page in writeback, writeback=$WRITEBACK"
3970         fi
3971
3972         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
3973         do_facet ost sysctl -w lustre.fail_loc=0
3974
3975         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
3976         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)   
3977         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
3978                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
3979         fi
3980
3981         rm -f $DIR/$tfile
3982         echo "Dirty pages gaurenteed flushed via fsync"
3983         return 0
3984 }
3985 run_test 118d "Fsync validation inject a delay of the bulk ====="
3986
3987 test_118f() {
3988         reset_async
3989
3990         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
3991         sysctl -w lustre.fail_loc=0x8000040a
3992
3993         # Should simulate EINVAL error which is fatal
3994         multiop $DIR/$tfile Owy
3995         RC=$?
3996         if [[ $RC -eq 0 ]]; then
3997                 error "Must return error due to dropped pages, rc=$RC"
3998         fi
3999         
4000         sysctl -w lustre.fail_loc=0x0
4001         
4002         LOCKED=$(grep -c locked $LPROC/llite/*/dump_page_cache)
4003         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4004         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4005         if [[ $LOCKED -ne 0 ]]; then
4006                 error "Locked pages remain in cache, locked=$LOCKED"
4007         fi
4008         
4009         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4010                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4011         fi
4012
4013         rm -f $DIR/$tfile
4014         echo "No pages locked after fsync"
4015
4016         reset_async
4017         return 0
4018 }
4019 run_test 118f "Simulate unrecoverable OSC side error ==========="
4020
4021 test_118g() {
4022         reset_async
4023
4024         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4025         sysctl -w lustre.fail_loc=0x406
4026
4027         # simulate local -ENOMEM
4028         multiop $DIR/$tfile Owy
4029         RC=$?
4030         
4031         sysctl -w lustre.fail_loc=0
4032         if [[ $RC -eq 0 ]]; then
4033                 error "Must return error due to dropped pages, rc=$RC"
4034         fi
4035
4036         LOCKED=$(grep -c locked $LPROC/llite/*/dump_page_cache)
4037         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4038         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4039         if [[ $LOCKED -ne 0 ]]; then
4040                 error "Locked pages remain in cache, locked=$LOCKED"
4041         fi
4042         
4043         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4044                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4045         fi
4046
4047         rm -f $DIR/$tfile
4048         echo "No pages locked after fsync"
4049
4050         reset_async
4051         return 0
4052 }
4053 run_test 118g "Don't stay in wait if we got local -ENOMEM ======"
4054
4055 test_118h() {
4056         reset_async
4057
4058         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
4059         do_facet ost sysctl -w lustre.fail_loc=0x20e
4060         # set 10s timeout
4061         echo "10" > $LPROC/osc/resend_timeout
4062         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
4063         multiop $DIR/$tfile Owy
4064         RC=$?
4065         
4066         do_facet ost sysctl -w lustre.fail_loc=0
4067         if [[ $RC -eq 0 ]]; then
4068                 error "Must return error due to dropped pages, rc=$RC"
4069         fi
4070
4071         LOCKED=$(grep -c locked $LPROC/llite/*/dump_page_cache)
4072         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4073         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4074         if [[ $LOCKED -ne 0 ]]; then
4075                 error "Locked pages remain in cache, locked=$LOCKED"
4076         fi
4077         
4078         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4079                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4080         fi
4081
4082         rm -f $DIR/$tfile
4083         echo "No pages locked after fsync"
4084
4085         reset_async
4086         return 0
4087 }
4088 run_test 118h "Verify timeout in handling recoverables errors =="
4089
4090 test_118i() {
4091         reset_async
4092
4093         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
4094         do_facet ost sysctl -w lustre.fail_loc=0x20e
4095         
4096         # set 10s timeout
4097         echo "10" > $LPROC/osc/resend_timeout
4098         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
4099         multiop $DIR/$tfile Owy &
4100         PID=$!
4101         sleep 5
4102         do_facet ost sysctl -w lustre.fail_loc=0
4103         
4104         wait $PID
4105         RC=$?
4106         if [[ $RC -ne 0 ]]; then
4107                 error "got error, but should be not, rc=$RC"
4108         fi
4109
4110         LOCKED=$(grep -c locked $LPROC/llite/*/dump_page_cache)
4111         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4112         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4113         if [[ $LOCKED -ne 0 ]]; then
4114                 error "Locked pages remain in cache, locked=$LOCKED"
4115         fi
4116         
4117         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4118                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4119         fi
4120
4121         rm -f $DIR/$tfile
4122         echo "No pages locked after fsync"
4123
4124         reset_async
4125         return 0
4126 }
4127 run_test 118i "Fix error before timeout in recoverable error ==="
4128
4129 test_118j() {
4130         reset_async
4131
4132         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
4133         do_facet ost sysctl -w lustre.fail_loc=0x220
4134
4135         # return -EIO from OST
4136         multiop $DIR/$tfile Owy
4137         RC=$?
4138         do_facet ost sysctl -w lustre.fail_loc=0x0
4139         if [[ $RC -eq 0 ]]; then
4140                 error "Must return error due to dropped pages, rc=$RC"
4141         fi
4142
4143         LOCKED=$(grep -c locked $LPROC/llite/*/dump_page_cache)
4144         DIRTY=$(grep -c dirty $LPROC/llite/*/dump_page_cache)
4145         WRITEBACK=$(grep -c writeback $LPROC/llite/*/dump_page_cache)
4146         if [[ $LOCKED -ne 0 ]]; then
4147                 error "Locked pages remain in cache, locked=$LOCKED"
4148         fi
4149         
4150         # in recoverable error on OST we want resend and stay until it finished
4151         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
4152                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
4153         fi
4154
4155
4156         rm -f $DIR/$tfile
4157         echo "No pages locked after fsync"
4158
4159         reset_async
4160         return 0
4161 }
4162 run_test 118j "Simulate unrecoverable OST side error ==========="
4163
4164 test_119a() # bug 11737
4165 {
4166         BSIZE=$((512 * 1024))
4167         directio write $DIR/$tfile 0 1 $BSIZE
4168         # We ask to read two blocks, which is more than a file size.
4169         # directio will indicate an error when requested and actual
4170         # sizes aren't equeal (a normal situation in this case) and
4171         # print actual read amount.
4172         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
4173         if [ "$NOB" != "$BSIZE" ]; then
4174                 error "read $NOB bytes instead of $BSIZE"
4175         fi
4176         rm -f $DIR/$tfile
4177 }
4178 run_test 119a "Short directIO read must return actual read amount"
4179
4180 test_119b() # bug 11737
4181 {
4182         [ "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
4183
4184         lfs setstripe $DIR/$tfile 0 -1 2
4185         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
4186         sync
4187         multiop $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
4188                 error "direct read failed"
4189 }
4190 run_test 119b "Sparse directIO read must return actual read amount"
4191
4192 test_120a() {
4193         mkdir $DIR/$tdir
4194         cancel_lru_locks mdc
4195         stat $DIR/$tdir > /dev/null
4196         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4197         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4198         mkdir $DIR/$tdir/d1
4199         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4200         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4201         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4202         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4203 }
4204 run_test 120a "Early Lock Cancel: mkdir test ==================="
4205
4206 test_120b() {
4207         mkdir $DIR/$tdir
4208         cancel_lru_locks mdc
4209         stat $DIR/$tdir > /dev/null
4210         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4211         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4212         touch $DIR/$tdir/f1
4213         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4214         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4215         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4216         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4217 }
4218 run_test 120b "Early Lock Cancel: create test =================="
4219
4220 test_120c() {
4221         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
4222         touch $DIR/$tdir/d1/f1
4223         cancel_lru_locks mdc
4224         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
4225         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4226         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4227         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
4228         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4229         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4230         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4231         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4232 }
4233 run_test 120c "Early Lock Cancel: link test ===================="
4234
4235 test_120d() {
4236         touch $DIR/$tdir
4237         cancel_lru_locks mdc
4238         stat $DIR/$tdir > /dev/null
4239         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4240         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4241         chmod a+x $DIR/$tdir
4242         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4243         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4244         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4245         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4246 }
4247 run_test 120d "Early Lock Cancel: setattr test ================="
4248
4249 test_120e() {
4250         mkdir $DIR/$tdir
4251         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
4252         cancel_lru_locks mdc
4253         cancel_lru_locks osc
4254         dd if=$DIR/$tdir/f1 of=/dev/null
4255         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
4256         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4257         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4258         unlink $DIR/$tdir/f1
4259         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4260         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4261         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4262         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4263 }
4264 run_test 120e "Early Lock Cancel: unlink test =================="
4265
4266 test_120f() {
4267         mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
4268         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
4269         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
4270         cancel_lru_locks mdc
4271         cancel_lru_locks osc
4272         dd if=$DIR/$tdir/d1/f1 of=/dev/null
4273         dd if=$DIR/$tdir/d2/f2 of=/dev/null
4274         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
4275         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4276         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4277         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
4278         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4279         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4280         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
4281         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
4282 }
4283 run_test 120f "Early Lock Cancel: rename test =================="
4284
4285 test_120g() {
4286         count=10000
4287         echo create $count files
4288         mkdir  $DIR/$tdir
4289         cancel_lru_locks mdc
4290         cancel_lru_locks osc
4291         t0=`date +%s`
4292         
4293         can0=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4294         blk0=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4295         createmany -o $DIR/$tdir/f $count
4296         sync
4297         can1=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4298         blk1=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4299         t1=`date +%s`
4300         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
4301         echo rm $count files
4302         rm -r $DIR/$tdir
4303         sync
4304         can2=`awk '/ldlm_cancel/ {print $2}' $LPROC/ldlm/services/ldlm_canceld/stats`
4305         blk2=`awk '/ldlm_bl_callback/ {print $2}' $LPROC/ldlm/services/ldlm_cbd/stats`
4306         t2=`date +%s`
4307         echo total: $count removes in $((t2-t1))
4308         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
4309         sleep 2
4310         # wait for commitment of removal
4311 }
4312 run_test 120g "Early Lock Cancel: performance test ============="
4313
4314 test_121() { #bug #10589
4315         rm -rf $DIR/$tfile
4316         writes=`dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk 'BEGIN { FS="+" } /out/ {print $1}'`
4317         sysctl -w lustre.fail_loc=0x310
4318         cancel_lru_locks osc > /dev/null
4319         reads=`dd if=$DIR/$tfile of=/dev/null 2>&1 | awk 'BEGIN { FS="+" } /in/ {print $1}'`
4320         sysctl -w lustre.fail_loc=0
4321         [ $reads -eq $writes ] || error "read" $reads "blocks, must be" $writes
4322 }
4323 run_test 121 "read cancel race ================================="
4324
4325 test_122() { #bug #11544
4326         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
4327         sysctl -w lustre.fail_loc=0x508
4328         dd if=/dev/zero of=$DIR/$tfile count=1
4329         sync
4330         sysctl -w lustre.fail_loc=0
4331 }
4332 run_test 122 "fail client bulk callback (shouldn't LBUG) ======="
4333
4334 TMPDIR=$OLDTMPDIR
4335 TMP=$OLDTMP
4336 HOME=$OLDHOME
4337
4338 log "cleanup: ======================================================"
4339 if [ "`mount | grep $MOUNT`" ]; then
4340         rm -rf $DIR/[Rdfs][1-9]*
4341 fi
4342 if [ "$I_MOUNTED" = "yes" ]; then
4343         cleanupall -f || error "cleanup failed"
4344 else
4345         sysctl -w lnet.debug="$OLDDEBUG" 2> /dev/null || true
4346 fi
4347
4348
4349 echo '=========================== finished ==============================='
4350 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true
4351 echo "$0: completed"