Whamcloud - gitweb
ab8c5d24bee31e34c4ca3f07b7177cd7250465fa
[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: 2108 9789 3637 9789 3561 5188/5749
11 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"42a 42b 42c 42d 45 68"}
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13
14 [ "$SLOW" = "no" ] && EXCEPT="$EXCEPT 24o 27m 51b 51c 63 64b 71 77 101"
15 # Tests that fail on uml
16 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
17 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT 31d"
18
19 # Tests that always fail with mountconf -- FIXME
20 # 48a moving the working dir succeeds
21
22 case `uname -r` in
23 2.4*) FSTYPE=${FSTYPE:-ext3};    ALWAYS_EXCEPT="$ALWAYS_EXCEPT 76" ;;
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 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
39 LCTL=${LCTL:-lctl}
40 MCREATE=${MCREATE:-mcreate}
41 OPENFILE=${OPENFILE:-openfile}
42 OPENUNLINK=${OPENUNLINK:-openunlink}
43 RANDOM_READS=${RANDOM_READS:-"random-reads"}
44 TOEXCL=${TOEXCL:-toexcl}
45 TRUNCATE=${TRUNCATE:-truncate}
46 MUNLINK=${MUNLINK:-munlink}
47 SOCKETSERVER=${SOCKETSERVER:-socketserver}
48 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
49 IOPENTEST1=${IOPENTEST1:-iopentest1}
50 IOPENTEST2=${IOPENTEST2:-iopentest2}
51 MEMHOG=${MEMHOG:-memhog}
52 DIRECTIO=${DIRECTIO:-directio}
53 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
54 UMOUNT=${UMOUNT:-"umount -d"}
55
56 if [ $UID -ne 0 ]; then
57         echo "Warning: running as non-root uid $UID"
58         RUNAS_ID="$UID"
59         RUNAS=""
60 else
61         RUNAS_ID=${RUNAS_ID:-500}
62         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
63
64         # $RUNAS_ID may get set incorrectly somewhere else
65         if [ $RUNAS_ID -eq 0 ]; then
66                 echo "Error: \$RUNAS_ID set to 0, but \$UID is also 0!"
67                 exit 1
68         fi
69 fi
70
71 SANITYLOG=${SANITYLOG:-/tmp/sanity.log}
72
73 export NAME=${NAME:-local}
74
75 SAVE_PWD=$PWD
76
77 LUSTRE=${LUSTRE:-`dirname $0`/..}
78 . $LUSTRE/tests/test-framework.sh
79 init_test_env $@
80 . ${CONFIG:=$LUSTRE/tests/cfg/local.sh}
81
82 if [ ! -z "$USING_KRB5" ]; then
83     $RUNAS krb5_login.sh || exit 1
84     $RUNAS -u $(($RUNAS_ID + 1)) krb5_login.sh || exit 1
85 fi
86
87 cleanup() {
88         echo -n "cln.."
89         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
90 }
91 CLEANUP=${CLEANUP:-:}
92
93 setup() {
94         echo -n "mnt.."
95         load_modules
96         setupall || exit 10
97         echo "done"
98 }
99
100 SETUP=${SETUP:-:}
101
102 log() {
103         echo "$*"
104         $LCTL mark "$*" 2> /dev/null || true
105 }
106
107 trace() {
108         log "STARTING: $*"
109         strace -o $TMP/$1.strace -ttt $*
110         RC=$?
111         log "FINISHED: $*: rc $RC"
112         return 1
113 }
114 TRACE=${TRACE:-""}
115
116 check_kernel_version() {
117         VERSION_FILE=$LPROC/version
118         WANT_VER=$1
119         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
120         GOT_VER=$(awk '/kernel:/ {print $2}' $VERSION_FILE)
121         [ $GOT_VER -ge $WANT_VER ] && return 0
122         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
123         return 1
124 }
125
126 _basetest() {
127     echo $*
128 }
129
130 basetest() {
131     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
132 }
133
134 run_one() {
135         if ! grep -q $DIR /proc/mounts; then
136                 $SETUP
137         fi
138         testnum=$1
139         message=$2
140         BEFORE=`date +%s`
141         log "== test $testnum: $message= `date +%H:%M:%S` ($BEFORE)"
142         export TESTNAME=test_$testnum
143         export tfile=f${testnum}
144         export tdir=d${base}
145         test_${testnum} || error "exit with rc=$?"
146         unset TESTNAME
147         pass "($((`date +%s` - $BEFORE))s)"
148         cd $SAVE_PWD
149         $CLEANUP
150 }
151
152 build_test_filter() {
153         [ "$ALWAYS_EXCEPT$EXCEPT$SANITY_EXCEPT" ] && \
154             echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT $SANITY_EXCEPT`"
155
156         for O in $ONLY; do
157             eval ONLY_${O}=true
158         done
159         for E in $EXCEPT $ALWAYS_EXCEPT $SANITY_EXCEPT; do
160             eval EXCEPT_${E}=true
161         done
162 }
163
164 _basetest() {
165         echo $*
166 }
167
168 basetest() {
169         IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
170 }
171
172 run_test() {
173          export base=`basetest $1`
174          if [ "$ONLY" ]; then
175                  testname=ONLY_$1
176                  if [ ${!testname}x != x ]; then
177                         run_one $1 "$2"
178                         return $?
179                  fi
180                  testname=ONLY_$base
181                  if [ ${!testname}x != x ]; then
182                          run_one $1 "$2"
183                          return $?
184                  fi
185                  echo -n "."
186                  return 0
187         fi
188         testname=EXCEPT_$1
189         if [ ${!testname}x != x ]; then
190                  echo "skipping excluded test $1"
191                  return 0
192         fi
193         testname=EXCEPT_$base
194         if [ ${!testname}x != x ]; then
195                  echo "skipping excluded test $1 (base $base)"
196                  return 0
197         fi
198         run_one $1 "$2"
199         return $?
200 }
201
202 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
203
204 error() { 
205         sysctl -w lustre.fail_loc=0
206         log "FAIL: $TESTNAME $@"
207         $LCTL dk $TMP/lustre-log-$TESTNAME.log
208         if [ "$SANITYLOG" ]; then
209                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
210         else
211                 exit 1
212         fi
213 }
214
215 pass() { 
216         echo PASS $@
217 }
218
219 mounted_lustre_filesystems() {
220     awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
221 }
222
223 MOUNTED="`mounted_lustre_filesystems`"
224 if [ -z "$MOUNTED" ]; then
225         formatall
226         setupall
227         MOUNTED="`mounted_lustre_filesystems`"
228         [ -z "$MOUNTED" ] && error "NAME=$NAME not mounted"
229         I_MOUNTED=yes
230 fi
231
232 [ `echo $MOUNT | wc -w` -gt 1 ] && error "NAME=$NAME mounted more than once"
233
234 DIR=${DIR:-$MOUNT}
235 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
236
237 LOVNAME=`cat $LPROC/llite/*/lov/common_name | tail -n 1`
238 OSTCOUNT=`cat $LPROC/lov/$LOVNAME/numobd`
239 STRIPECOUNT=`cat $LPROC/lov/$LOVNAME/stripecount`
240 STRIPESIZE=`cat $LPROC/lov/$LOVNAME/stripesize`
241 ORIGFREE=`cat $LPROC/lov/$LOVNAME/kbytesavail`
242 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
243 MDS=$(\ls $LPROC/mdt 2> /dev/null | grep -v num_refs | tail -n 1)
244
245 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
246 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
247 rm -rf $DIR/[Rdfs][1-9]*
248
249 build_test_filter
250
251 echo "preparing for tests involving mounts"
252 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
253 touch $EXT2_DEV
254 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
255 echo # add a newline after mke2fs.
256
257 umask 077
258
259 test_0() {
260         touch $DIR/$tfile
261         $CHECKSTAT -t file $DIR/$tfile || error
262         rm $DIR/$tfile
263         $CHECKSTAT -a $DIR/$tfile || error
264 }
265 run_test 0 "touch .../$tfile ; rm .../$tfile ====================="
266
267 test_0b() {
268         chmod 0755 $DIR || error
269         $CHECKSTAT -p 0755 $DIR || error
270 }
271 run_test 0b "chmod 0755 $DIR ============================="
272
273 test_1a() {
274         mkdir $DIR/d1
275         mkdir $DIR/d1/d2
276         $CHECKSTAT -t dir $DIR/d1/d2 || error
277 }
278 run_test 1a "mkdir .../d1; mkdir .../d1/d2 ====================="
279
280 test_1b() {
281         rmdir $DIR/d1/d2
282         rmdir $DIR/d1
283         $CHECKSTAT -a $DIR/d1 || error
284 }
285 run_test 1b "rmdir .../d1/d2; rmdir .../d1 ====================="
286
287 test_2a() {
288         mkdir $DIR/d2
289         touch $DIR/d2/f
290         $CHECKSTAT -t file $DIR/d2/f || error
291 }
292 run_test 2a "mkdir .../d2; touch .../d2/f ======================"
293
294 test_2b() {
295         rm -r $DIR/d2
296         $CHECKSTAT -a $DIR/d2 || error
297 }
298 run_test 2b "rm -r .../d2; checkstat .../d2/f ======================"
299
300 test_3a() {
301         mkdir $DIR/d3
302         $CHECKSTAT -t dir $DIR/d3 || error
303 }
304 run_test 3a "mkdir .../d3 ======================================"
305
306 test_3b() {
307         if [ ! -d $DIR/d3 ]; then
308                 mkdir $DIR/d3
309         fi
310         touch $DIR/d3/f
311         $CHECKSTAT -t file $DIR/d3/f || error
312 }
313 run_test 3b "touch .../d3/f ===================================="
314
315 test_3c() {
316         rm -r $DIR/d3
317         $CHECKSTAT -a $DIR/d3 || error
318 }
319 run_test 3c "rm -r .../d3 ======================================"
320
321 test_4a() {
322         mkdir $DIR/d4
323         $CHECKSTAT -t dir $DIR/d4 || error
324 }
325 run_test 4a "mkdir .../d4 ======================================"
326
327 test_4b() {
328         if [ ! -d $DIR/d4 ]; then
329                 mkdir $DIR/d4
330         fi
331         mkdir $DIR/d4/d2
332         $CHECKSTAT -t dir $DIR/d4/d2 || error
333 }
334 run_test 4b "mkdir .../d4/d2 ==================================="
335
336 test_5() {
337         mkdir $DIR/d5
338         mkdir $DIR/d5/d2
339         chmod 0707 $DIR/d5/d2
340         $CHECKSTAT -t dir -p 0707 $DIR/d5/d2 || error
341 }
342 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
343
344 test_6a() {
345         touch $DIR/f6a
346         chmod 0666 $DIR/f6a || error
347         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
348 }
349 run_test 6a "touch .../f6a; chmod .../f6a ======================"
350
351 test_6b() {
352         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
353         if [ ! -f $DIR/f6a ]; then
354                 touch $DIR/f6a
355                 chmod 0666 $DIR/f6a
356         fi
357         $RUNAS chmod 0444 $DIR/f6a && error
358         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/f6a || error
359 }
360 run_test 6b "$RUNAS chmod .../f6a (should return error) =="
361
362 test_6c() {
363         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
364         touch $DIR/f6c
365         chown $RUNAS_ID $DIR/f6c || error
366         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
367 }
368 run_test 6c "touch .../f6c; chown .../f6c ======================"
369
370 test_6d() {
371         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
372         if [ ! -f $DIR/f6c ]; then
373                 touch $DIR/f6c
374                 chown $RUNAS_ID $DIR/f6c
375         fi
376         $RUNAS chown $UID $DIR/f6c && error
377         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/f6c || error
378 }
379 run_test 6d "$RUNAS chown .../f6c (should return error) =="
380
381 test_6e() {
382         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
383         touch $DIR/f6e
384         chgrp $RUNAS_ID $DIR/f6e || error
385         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
386 }
387 run_test 6e "touch .../f6e; chgrp .../f6e ======================"
388
389 test_6f() {
390         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
391         if [ ! -f $DIR/f6e ]; then
392                 touch $DIR/f6e
393                 chgrp $RUNAS_ID $DIR/f6e
394         fi
395         $RUNAS chgrp $UID $DIR/f6e && error
396         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/f6e || error
397 }
398 run_test 6f "$RUNAS chgrp .../f6e (should return error) =="
399
400 test_6g() {
401         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
402         mkdir $DIR/d6g || error
403         chmod 777 $DIR/d6g || error
404         $RUNAS mkdir $DIR/d6g/d || error
405         chmod g+s $DIR/d6g/d || error
406         mkdir $DIR/d6g/d/subdir
407         $CHECKSTAT -g \#$RUNAS_ID $DIR/d6g/d/subdir || error
408 }
409 run_test 6g "Is new dir in sgid dir inheriting group?"
410
411 test_6h() { # bug 7331
412         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
413         touch $DIR/f6h || error "touch failed"
414         chown $RUNAS_ID:$RUNAS_ID $DIR/f6h || error "initial chown failed"
415         $RUNAS -G$RUNAS_ID chown $RUNAS_ID:0 $DIR/f6h && error "chown worked"
416         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_ID $DIR/f6h || error
417 }
418 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
419
420 test_7a() {
421         mkdir $DIR/d7
422         $MCREATE $DIR/d7/f
423         chmod 0666 $DIR/d7/f
424         $CHECKSTAT -t file -p 0666 $DIR/d7/f || error
425 }
426 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
427
428 test_7b() {
429         if [ ! -d $DIR/d7 ]; then
430                 mkdir $DIR/d7
431         fi
432         $MCREATE $DIR/d7/f2
433         echo -n foo > $DIR/d7/f2
434         [ "`cat $DIR/d7/f2`" = "foo" ] || error
435         $CHECKSTAT -t file -s 3 $DIR/d7/f2 || error
436 }
437 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
438
439 test_8() {
440         mkdir $DIR/d8
441         touch $DIR/d8/f
442         chmod 0666 $DIR/d8/f
443         $CHECKSTAT -t file -p 0666 $DIR/d8/f || error
444 }
445 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
446
447 test_9() {
448         mkdir $DIR/d9
449         mkdir $DIR/d9/d2
450         mkdir $DIR/d9/d2/d3
451         $CHECKSTAT -t dir $DIR/d9/d2/d3 || error
452 }
453 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
454
455 test_10() {
456         mkdir $DIR/d10
457         mkdir $DIR/d10/d2
458         touch $DIR/d10/d2/f
459         $CHECKSTAT -t file $DIR/d10/d2/f || error
460 }
461 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
462
463 test_11() {
464         mkdir $DIR/d11
465         mkdir $DIR/d11/d2
466         chmod 0666 $DIR/d11/d2
467         chmod 0705 $DIR/d11/d2
468         $CHECKSTAT -t dir -p 0705 $DIR/d11/d2 || error
469 }
470 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
471
472 test_12() {
473         mkdir $DIR/d12
474         touch $DIR/d12/f
475         chmod 0666 $DIR/d12/f
476         chmod 0654 $DIR/d12/f
477         $CHECKSTAT -t file -p 0654 $DIR/d12/f || error
478 }
479 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
480
481 test_13() {
482         mkdir $DIR/d13
483         dd if=/dev/zero of=$DIR/d13/f count=10
484         >  $DIR/d13/f
485         $CHECKSTAT -t file -s 0 $DIR/d13/f || error
486 }
487 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
488
489 test_14() {
490         mkdir $DIR/d14
491         touch $DIR/d14/f
492         rm $DIR/d14/f
493         $CHECKSTAT -a $DIR/d14/f || error
494 }
495 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
496
497 test_15() {
498         mkdir $DIR/d15
499         touch $DIR/d15/f
500         mv $DIR/d15/f $DIR/d15/f2
501         $CHECKSTAT -t file $DIR/d15/f2 || error
502 }
503 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
504
505 test_16() {
506         mkdir $DIR/d16
507         touch $DIR/d16/f
508         rm -rf $DIR/d16/f
509         $CHECKSTAT -a $DIR/d16/f || error
510 }
511 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
512
513 test_17a() {
514         mkdir -p $DIR/d17
515         touch $DIR/d17/f
516         ln -s $DIR/d17/f $DIR/d17/l-exist
517         ls -l $DIR/d17
518         $CHECKSTAT -l $DIR/d17/f $DIR/d17/l-exist || error
519         $CHECKSTAT -f -t f $DIR/d17/l-exist || error
520         rm -f $DIR/l-exist
521         $CHECKSTAT -a $DIR/l-exist || error
522 }
523 run_test 17a "symlinks: create, remove (real) =================="
524
525 test_17b() {
526         mkdir -p $DIR/d17
527         ln -s no-such-file $DIR/d17/l-dangle
528         ls -l $DIR/d17
529         $CHECKSTAT -l no-such-file $DIR/d17/l-dangle || error
530         $CHECKSTAT -fa $DIR/d17/l-dangle || error
531         rm -f $DIR/l-dangle
532         $CHECKSTAT -a $DIR/l-dangle || error
533 }
534 run_test 17b "symlinks: create, remove (dangling) =============="
535
536 test_17c() { # bug 3440 - don't save failed open RPC for replay
537         mkdir -p $DIR/d17
538         ln -s foo $DIR/d17/f17c
539         cat $DIR/d17/f17c && error "opened non-existent symlink" || true
540 }
541 run_test 17c "symlinks: open dangling (should return error) ===="
542
543 test_17d() {
544         mkdir -p $DIR/d17
545         ln -s foo $DIR/d17/f17d
546         touch $DIR/d17/f17d || error "creating to new symlink"
547 }
548 run_test 17d "symlinks: create dangling ========================"
549
550 test_18() {
551         touch $DIR/f
552         ls $DIR || error
553 }
554 run_test 18 "touch .../f ; ls ... =============================="
555
556 test_19a() {
557         touch $DIR/f19
558         ls -l $DIR
559         rm $DIR/f19
560         $CHECKSTAT -a $DIR/f19 || error
561 }
562 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
563
564 test_19b() {
565         ls -l $DIR/f19 && error || true
566 }
567 run_test 19b "ls -l .../f19 (should return error) =============="
568
569 test_19c() {
570         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
571         $RUNAS touch $DIR/f19 && error || true
572 }
573 run_test 19c "$RUNAS touch .../f19 (should return error) =="
574
575 test_19d() {
576         cat $DIR/f19 && error || true
577 }
578 run_test 19d "cat .../f19 (should return error) =============="
579
580 test_20() {
581         touch $DIR/f
582         rm $DIR/f
583         log "1 done"
584         touch $DIR/f
585         rm $DIR/f
586         log "2 done"
587         touch $DIR/f
588         rm $DIR/f
589         log "3 done"
590         $CHECKSTAT -a $DIR/f || error
591 }
592 run_test 20 "touch .../f ; ls -l ... ==========================="
593
594 test_21() {
595         mkdir $DIR/d21
596         [ -f $DIR/d21/dangle ] && rm -f $DIR/d21/dangle
597         ln -s dangle $DIR/d21/link
598         echo foo >> $DIR/d21/link
599         cat $DIR/d21/dangle
600         $CHECKSTAT -t link $DIR/d21/link || error
601         $CHECKSTAT -f -t file $DIR/d21/link || error
602 }
603 run_test 21 "write to dangling link ============================"
604
605 test_22() {
606         mkdir $DIR/d22
607         chown $RUNAS_ID $DIR/d22
608         # Tar gets pissy if it can't access $PWD *sigh*
609         (cd $TMP;
610         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
611         $RUNAS tar xfC - $DIR/d22)
612         ls -lR $DIR/d22/etc
613         $CHECKSTAT -t dir $DIR/d22/etc || error
614         $CHECKSTAT -u \#$RUNAS_ID $DIR/d22/etc || error
615 }
616 run_test 22 "unpack tar archive as non-root user ==============="
617
618 test_23() {
619         mkdir $DIR/d23
620         $TOEXCL $DIR/d23/f23
621         $TOEXCL -e $DIR/d23/f23 || error
622 }
623 run_test 23 "O_CREAT|O_EXCL in subdir =========================="
624
625 test_24a() {
626         echo '== rename sanity =============================================='
627         echo '-- same directory rename'
628         mkdir $DIR/R1
629         touch $DIR/R1/f
630         mv $DIR/R1/f $DIR/R1/g
631         $CHECKSTAT -t file $DIR/R1/g || error
632 }
633 run_test 24a "touch .../R1/f; rename .../R1/f .../R1/g ========="
634
635 test_24b() {
636         mkdir $DIR/R2
637         touch $DIR/R2/{f,g}
638         mv $DIR/R2/f $DIR/R2/g
639         $CHECKSTAT -a $DIR/R2/f || error
640         $CHECKSTAT -t file $DIR/R2/g || error
641 }
642 run_test 24b "touch .../R2/{f,g}; rename .../R2/f .../R2/g ====="
643
644 test_24c() {
645         mkdir $DIR/R3
646         mkdir $DIR/R3/f
647         mv $DIR/R3/f $DIR/R3/g
648         $CHECKSTAT -a $DIR/R3/f || error
649         $CHECKSTAT -t dir $DIR/R3/g || error
650 }
651 run_test 24c "mkdir .../R3/f; rename .../R3/f .../R3/g ========="
652
653 test_24d() {
654         mkdir $DIR/R4
655         mkdir $DIR/R4/{f,g}
656         mrename $DIR/R4/f $DIR/R4/g
657         $CHECKSTAT -a $DIR/R4/f || error
658         $CHECKSTAT -t dir $DIR/R4/g || error
659 }
660 run_test 24d "mkdir .../R4/{f,g}; rename .../R4/f .../R4/g ====="
661
662 test_24e() {
663         echo '-- cross directory renames --' 
664         mkdir $DIR/R5{a,b}
665         touch $DIR/R5a/f
666         mv $DIR/R5a/f $DIR/R5b/g
667         $CHECKSTAT -a $DIR/R5a/f || error
668         $CHECKSTAT -t file $DIR/R5b/g || error
669 }
670 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
671
672 test_24f() {
673         mkdir $DIR/R6{a,b}
674         touch $DIR/R6a/f $DIR/R6b/g
675         mv $DIR/R6a/f $DIR/R6b/g
676         $CHECKSTAT -a $DIR/R6a/f || error
677         $CHECKSTAT -t file $DIR/R6b/g || error
678 }
679 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
680
681 test_24g() {
682         mkdir $DIR/R7{a,b}
683         mkdir $DIR/R7a/d
684         mv $DIR/R7a/d $DIR/R7b/e
685         $CHECKSTAT -a $DIR/R7a/d || error
686         $CHECKSTAT -t dir $DIR/R7b/e || error
687 }
688 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R5b/e ======"
689
690 test_24h() {
691         mkdir $DIR/R8{a,b}
692         mkdir $DIR/R8a/d $DIR/R8b/e
693         mrename $DIR/R8a/d $DIR/R8b/e
694         $CHECKSTAT -a $DIR/R8a/d || error
695         $CHECKSTAT -t dir $DIR/R8b/e || error
696 }
697 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
698
699 test_24i() {
700         echo "-- rename error cases"
701         mkdir $DIR/R9
702         mkdir $DIR/R9/a
703         touch $DIR/R9/f
704         mrename $DIR/R9/f $DIR/R9/a
705         $CHECKSTAT -t file $DIR/R9/f || error
706         $CHECKSTAT -t dir  $DIR/R9/a || error
707         $CHECKSTAT -a file $DIR/R9/a/f || error
708 }
709 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
710
711 test_24j() {
712         mkdir $DIR/R10
713         mrename $DIR/R10/f $DIR/R10/g
714         $CHECKSTAT -t dir $DIR/R10 || error
715         $CHECKSTAT -a $DIR/R10/f || error
716         $CHECKSTAT -a $DIR/R10/g || error
717 }
718 run_test 24j "source does not exist ============================" 
719
720 test_24k() {
721         mkdir $DIR/R11a $DIR/R11a/d
722         touch $DIR/R11a/f
723         mv $DIR/R11a/f $DIR/R11a/d
724         $CHECKSTAT -a $DIR/R11a/f || error
725         $CHECKSTAT -t file $DIR/R11a/d/f || error
726 }
727 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
728
729 # bug 2429 - rename foo foo foo creates invalid file
730 test_24l() {
731         f="$DIR/f24l"
732         multiop $f OcNs || error
733 }
734 run_test 24l "Renaming a file to itself ========================"
735
736 test_24m() {
737         f="$DIR/f24m"
738         multiop $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
739         # on ext3 this does not remove either the source or target files
740         # though the "expected" operation would be to remove the source
741         $CHECKSTAT -t file ${f} || error "${f} missing"
742         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
743 }
744 run_test 24m "Renaming a file to a hard link to itself ========="
745
746 test_24n() {
747     f="$DIR/f24n"
748     # this stats the old file after it was renamed, so it should fail
749     touch ${f}
750     $CHECKSTAT ${f}
751     mv ${f} ${f}.rename
752     $CHECKSTAT ${f}.rename
753     $CHECKSTAT -a ${f}
754 }
755 run_test 24n "Statting the old file after renaming (Posix rename 2)"
756
757 test_24o() {
758         check_kernel_version 37 || return 0
759         mkdir -p $DIR/d24o
760         rename_many -s random -v -n 10 $DIR/d24o
761 }
762 run_test 24o "rename of files during htree split ==============="
763
764 test_24p() {
765         mkdir $DIR/R12{a,b}
766         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
767         mrename $DIR/R12a $DIR/R12b
768         $CHECKSTAT -a $DIR/R12a || error
769         $CHECKSTAT -t dir $DIR/R12b || error
770         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
771         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
772 }
773 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
774
775 test_24q() {
776         mkdir $DIR/R13{a,b}
777         DIRINO=`ls -lid $DIR/R13a | awk '{ print $1 }'`
778         multiop $DIR/R13b D_c &
779         MULTIPID=$!
780         usleep 500
781
782         mrename $DIR/R13a $DIR/R13b
783         $CHECKSTAT -a $DIR/R13a || error
784         $CHECKSTAT -t dir $DIR/R13b || error
785         DIRINO2=`ls -lid $DIR/R13b | awk '{ print $1 }'`
786         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
787         kill -USR1 $MULTIPID
788         wait $MULTIPID || error "multiop close failed"
789 }
790 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
791
792 test_24r() { #bug 3789
793         mkdir $DIR/R14a $DIR/R14a/b
794         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
795         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
796         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
797 }
798 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
799
800 test_24s() {
801         mkdir $DIR/R15a $DIR/R15a/b $DIR/R15a/b/c
802         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
803         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
804         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
805 }
806 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
807 test_24t() {
808         mkdir $DIR/R16a $DIR/R16a/b $DIR/R16a/b/c
809         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
810         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
811         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
812 }
813 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
814
815 test_25a() {
816         echo '== symlink sanity ============================================='
817
818         mkdir $DIR/d25
819         ln -s d25 $DIR/s25
820         touch $DIR/s25/foo || error
821 }
822 run_test 25a "create file in symlinked directory ==============="
823
824 test_25b() {
825         [ ! -d $DIR/d25 ] && test_25a
826         $CHECKSTAT -t file $DIR/s25/foo || error
827 }
828 run_test 25b "lookup file in symlinked directory ==============="
829
830 test_26a() {
831         mkdir $DIR/d26
832         mkdir $DIR/d26/d26-2
833         ln -s d26/d26-2 $DIR/s26
834         touch $DIR/s26/foo || error
835 }
836 run_test 26a "multiple component symlink ======================="
837
838 test_26b() {
839         mkdir -p $DIR/d26b/d26-2
840         ln -s d26b/d26-2/foo $DIR/s26-2
841         touch $DIR/s26-2 || error
842 }
843 run_test 26b "multiple component symlink at end of lookup ======"
844
845 test_26c() {
846         mkdir $DIR/d26.2
847         touch $DIR/d26.2/foo
848         ln -s d26.2 $DIR/s26.2-1
849         ln -s s26.2-1 $DIR/s26.2-2
850         ln -s s26.2-2 $DIR/s26.2-3
851         chmod 0666 $DIR/s26.2-3/foo
852 }
853 run_test 26c "chain of symlinks ================================"
854
855 # recursive symlinks (bug 439)
856 test_26d() {
857         ln -s d26-3/foo $DIR/d26-3
858 }
859 run_test 26d "create multiple component recursive symlink ======"
860
861 test_26e() {
862         [ ! -h $DIR/d26-3 ] && test_26d
863         rm $DIR/d26-3
864 }
865 run_test 26e "unlink multiple component recursive symlink ======"
866
867 # recursive symlinks (bug 7022)
868 test_26f() {
869         mkdir $DIR/$tfile        || error "mkdir $DIR/$tfile failed"
870         cd $DIR/$tfile           || error "cd $DIR/$tfile failed"
871         mkdir -p $tdir/bar1      || error "mkdir $tdir/bar1 failed"
872         mkdir $tfile             || error "mkdir $tfile failed"
873         cd $tfile                || error "cd $tfile failed"
874         ln -s .. dotdot          || error "ln dotdot failed"
875         ln -s dotdot/$tdir $tdir || error "ln $tdir failed"
876         cd ../..                 || error "cd ../.. failed"
877         output=`ls $tfile/$tfile/$tdir/bar1`
878         [ "$output" = bar1 ] && error "unexpected output"
879         rm -r $tfile             || error "rm $tfile failed"
880         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
881 }
882 run_test 26f "rm -r of a directory which has recursive symlink ="
883
884 test_27a() {
885         echo '== stripe sanity =============================================='
886         mkdir $DIR/d27
887         $SETSTRIPE $DIR/d27/f0 65536 0 1 || error "lstripe failed"
888         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
889         pass
890         log "== test_27a: write to one stripe file ========================="
891         cp /etc/hosts $DIR/d27/f0 || error
892 }
893 run_test 27a "one stripe file =================================="
894
895 test_27c() {
896         [ "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
897         mkdir -p $DIR/d27
898         $SETSTRIPE $DIR/d27/f01 65536 0 2 || error "lstripe failed"
899         [ `$GETSTRIPE $DIR/d27/f01 | grep -A 10 obdidx | wc -l` -eq 4 ] ||
900                 error "two-stripe file doesn't have two stripes"
901         pass
902         log "== test_27d: write to two stripe file file f01 ================"
903         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
904 }
905 run_test 27c "create two stripe file f01 ======================="
906
907 test_27d() {
908         mkdir -p $DIR/d27
909         $SETSTRIPE $DIR/d27/fdef 0 -1 0 || error "lstripe failed"
910         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
911         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
912 }
913 run_test 27d "create file with default settings ================"
914
915 test_27e() {
916         mkdir -p $DIR/d27
917         $SETSTRIPE $DIR/d27/f12 65536 0 2 || error "lstripe failed"
918         $SETSTRIPE $DIR/d27/f12 65536 0 2 && error "lstripe succeeded twice"
919         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
920 }
921 run_test 27e "lstripe existing file (should return error) ======"
922
923 test_27f() {
924         mkdir -p $DIR/d27
925         $SETSTRIPE $DIR/d27/fbad 100 0 1 && error "lstripe failed"
926         dd if=/dev/zero of=$DIR/d27/f12 bs=4k count=4 || error "dd failed"
927         $GETSTRIPE $DIR/d27/fbad || error "lfs getstripe failed"
928 }
929 run_test 27f "lstripe with bad stripe size (should return error)"
930
931 test_27g() {
932         mkdir -p $DIR/d27
933         $MCREATE $DIR/d27/fnone || error "mcreate failed"
934         pass
935         log "== test 27h: lfs getstripe with no objects ===================="
936         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" || error "has object"
937         pass
938         log "== test 27i: lfs getstripe with some objects =================="
939         touch $DIR/d27/fsome || error "touch failed"
940         $GETSTRIPE $DIR/d27/fsome | grep obdidx || error "missing objects"
941 }
942 run_test 27g "test lfs getstripe ==========================================="
943
944 test_27j() {
945         mkdir -p $DIR/d27
946         $SETSTRIPE $DIR/d27/f27j 65536 $OSTCOUNT 1 && error "lstripe failed"||true
947 }
948 run_test 27j "lstripe with bad stripe offset (should return error)"
949
950 test_27k() { # bug 2844
951         mkdir -p $DIR/d27
952         FILE=$DIR/d27/f27k
953         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
954         [ ! -d $DIR/d27 ] && mkdir -p $DIR/d27
955         $SETSTRIPE $FILE 67108864 -1 0 || error "lstripe failed"
956         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
957         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
958         dd if=/dev/zero of=$FILE bs=4k count=1
959         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
960         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
961 }
962 run_test 27k "limit i_blksize for broken user apps ============="
963
964 test_27l() {
965         mkdir -p $DIR/d27
966         mcreate $DIR/f27l || error "creating file"
967         $RUNAS $SETSTRIPE $DIR/f27l 65536 -1 1 && \
968                 error "lstripe should have failed" || true
969 }
970 run_test 27l "check setstripe permissions (should return error)"
971
972 test_27m() {
973         [ "$OSTCOUNT" -lt "2" ] && echo "skipping out-of-space test on OST0" && return
974         if [ $ORIGFREE -gt $MAXFREE ]; then
975                 echo "skipping out-of-space test on OST0"
976                 return
977         fi
978         mkdir -p $DIR/d27
979         $SETSTRIPE $DIR/d27/f27m_1 0 0 1
980         dd if=/dev/zero of=$DIR/d27/f27m_1 bs=1024 count=$MAXFREE && \
981                 error "dd should fill OST0"
982         i=2
983         while $SETSTRIPE $DIR/d27/f27m_$i 0 0 1 ; do
984                 i=`expr $i + 1`
985                 [ $i -gt 256 ] && break
986         done
987         i=`expr $i + 1`
988         touch $DIR/d27/f27m_$i
989         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
990                 error "OST0 was full but new created file still use it"
991         i=`expr $i + 1`
992         touch $DIR/d27/f27m_$i
993         [ `$GETSTRIPE $DIR/d27/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] && \
994                 error "OST0 was full but new created file still use it"
995         rm -r $DIR/d27
996 }
997 run_test 27m "create file while OST0 was full =================="
998
999 # osc's keep a NOSPC stick flag that gets unset with rmdir
1000 reset_enospc() {
1001         [ "$1" ] && FAIL_LOC=$1 || FAIL_LOC=0
1002         mkdir -p $DIR/d27/nospc
1003         rmdir $DIR/d27/nospc
1004         sysctl -w lustre.fail_loc=$FAIL_LOC
1005 }
1006
1007 exhaust_precreations() {
1008         OSTIDX=$1
1009         OST=$(grep ${OSTIDX}": " $LPROC/lov/${LOVNAME}/target_obd | \
1010             awk '{print $2}' | sed -e 's/_UUID$//')
1011         # on the mdt's osc
1012         OSC=$(ls $LPROC/osc | grep "mdtlov-osc000${OSTIDX}")
1013         last_id=$(cat $LPROC/osc/${OSC}/prealloc_last_id)
1014         next_id=$(cat $LPROC/osc/${OSC}/prealloc_next_id)
1015         
1016         mkdir -p $DIR/d27/${OST}
1017         $SETSTRIPE $DIR/d27/${OST} 0 $OSTIDX 1
1018 #define OBD_FAIL_OST_ENOSPC              0x215
1019         sysctl -w lustre.fail_loc=0x215
1020         echo "Creating to objid $last_id on ost $OST..."
1021         createmany -o $DIR/d27/${OST}/f $next_id $((last_id - next_id + 2))
1022         grep '[0-9]' $LPROC/osc/${OSC}/prealloc*
1023         reset_enospc $2
1024 }
1025
1026 exhaust_all_precreations() {
1027         local i
1028         for (( i=0; i < OSTCOUNT; i++ )) ; do
1029                 exhaust_precreations $i 0x215
1030         done
1031         reset_enospc $1
1032 }
1033
1034 test_27n() {
1035         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1036
1037         reset_enospc
1038         rm -f $DIR/d27/f27n
1039         exhaust_precreations 0 0x80000215
1040
1041         touch $DIR/d27/f27n || error
1042
1043         reset_enospc
1044 }
1045 run_test 27n "create file with some full OSTs =================="
1046
1047 test_27o() {
1048         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1049
1050         reset_enospc
1051         rm -f $DIR/d27/f27o
1052         exhaust_all_precreations 0x215
1053         sleep 5
1054
1055         touch $DIR/d27/f27o && error "able to create $DIR/d27/f27o"
1056
1057         reset_enospc
1058 }
1059 run_test 27o "create file with all full OSTs (should error) ===="
1060
1061 test_27p() {
1062         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1063
1064         reset_enospc
1065         rm -f $DIR/d27/f27p
1066
1067         $MCREATE $DIR/d27/f27p || error
1068         $TRUNCATE $DIR/d27/f27p 80000000 || error
1069         $CHECKSTAT -s 80000000 $DIR/d27/f27p || error
1070
1071         exhaust_precreations 0 0x80000215
1072         echo foo >> $DIR/d27/f27p || error
1073         $CHECKSTAT -s 80000004 $DIR/d27/f27p || error
1074
1075         reset_enospc
1076 }
1077 run_test 27p "append to a truncated file with some full OSTs ==="
1078
1079 test_27q() {
1080         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1081
1082         reset_enospc
1083         rm -f $DIR/d27/f27q
1084
1085         $MCREATE $DIR/d27/f27q || error
1086         $TRUNCATE $DIR/d27/f27q 80000000 || error
1087         $CHECKSTAT -s 80000000 $DIR/d27/f27q || error
1088
1089         exhaust_all_precreations 0x215
1090
1091         echo foo >> $DIR/d27/f27q && error
1092         $CHECKSTAT -s 80000000 $DIR/d27/f27q || error
1093
1094         reset_enospc
1095 }
1096 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1097
1098 test_27r() {
1099         [ "$OSTCOUNT" -lt "2" -o -z "$MDS" ] && echo "skipping $TESTNAME" && return
1100
1101         reset_enospc
1102         rm -f $DIR/d27/f27r
1103         exhaust_precreations 0 0x80000215
1104
1105         $SETSTRIPE $DIR/d27/f27r 0 0 2 # && error
1106
1107         reset_enospc
1108 }
1109 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1110
1111 test_27s() {
1112        mkdir -p $DIR/$tdir
1113        $LSTRIPE $DIR/$tdir $((2048 * 1024 * 1024)) -1 2 && \
1114                error "stripe width >= 2^32 succeeded" || true
1115 }
1116 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1117
1118 test_27t() { # bug 10864
1119         WDIR=`pwd`
1120         WLFS=`which lfs`
1121         cd $DIR
1122         touch $tfile
1123         $WLFS getstripe $tfile
1124         cd $WDIR
1125 }
1126 run_test 27t "check that utils parse path correctly"
1127
1128
1129 test_28() {
1130         mkdir $DIR/d28
1131         $CREATETEST $DIR/d28/ct || error
1132 }
1133 run_test 28 "create/mknod/mkdir with bad file types ============"
1134
1135 test_29() {
1136         cancel_lru_locks mdc
1137         mkdir $DIR/d29
1138         touch $DIR/d29/foo
1139         log 'first d29'
1140         ls -l $DIR/d29
1141         MDCDIR=${MDCDIR:-$LPROC/ldlm/namespaces/*-mdc-*}
1142         LOCKCOUNTORIG=`cat $MDCDIR/lock_count`
1143         LOCKUNUSEDCOUNTORIG=`cat $MDCDIR/lock_unused_count`
1144         log 'second d29'
1145         ls -l $DIR/d29
1146         log 'done'
1147         LOCKCOUNTCURRENT=`cat $MDCDIR/lock_count`
1148         LOCKUNUSEDCOUNTCURRENT=`cat $MDCDIR/lock_unused_count`
1149         if [ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]; then
1150                 echo > $LPROC/ldlm/dump_namespaces
1151                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1152                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1153                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1154         fi
1155         if [ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]; then
1156                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1157                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1158                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1159         fi
1160 }
1161 run_test 29 "IT_GETATTR regression  ============================"
1162
1163 test_30() {
1164         cp `which ls` $DIR || cp /bin/ls $DIR
1165         $DIR/ls /
1166         rm $DIR/ls
1167 }
1168 run_test 30 "run binary from Lustre (execve) ==================="
1169
1170 test_31a() {
1171         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1172         $CHECKSTAT -a $DIR/f31 || error
1173 }
1174 run_test 31a "open-unlink file =================================="
1175
1176 test_31b() {
1177         touch $DIR/f31 || error
1178         ln $DIR/f31 $DIR/f31b || error
1179         multiop $DIR/f31b Ouc || error
1180         $CHECKSTAT -t file $DIR/f31 || error
1181 }
1182 run_test 31b "unlink file with multiple links while open ======="
1183
1184 test_31c() {
1185         touch $DIR/f31 || error
1186         ln $DIR/f31 $DIR/f31c || error
1187         multiop $DIR/f31 O_uc &
1188         MULTIPID=$!
1189         multiop $DIR/f31c Ouc
1190         usleep 500
1191         kill -USR1 $MULTIPID
1192         wait $MULTIPID
1193 }
1194 run_test 31c "open-unlink file with multiple links ============="
1195
1196 test_31d() {
1197         opendirunlink $DIR/d31d $DIR/d31d || error
1198         $CHECKSTAT -a $DIR/d31d || error
1199 }
1200 run_test 31d "remove of open directory ========================="
1201
1202 test_31e() { # bug 2904
1203         check_kernel_version 34 || return 0
1204         openfilleddirunlink $DIR/d31e || error
1205 }
1206 run_test 31e "remove of open non-empty directory ==============="
1207
1208 test_31f() { # bug 4554
1209         set -vx
1210         mkdir $DIR/d31f
1211         lfs setstripe $DIR/d31f 1048576 -1 1
1212         cp /etc/hosts $DIR/d31f
1213         ls -l $DIR/d31f
1214         lfs getstripe $DIR/d31f/hosts
1215         multiop $DIR/d31f D_c &
1216         MULTIPID=$!
1217
1218         sleep 1
1219
1220         rm -rv $DIR/d31f || error "first of $DIR/d31f"
1221         mkdir $DIR/d31f
1222         lfs setstripe $DIR/d31f 1048576 -1 1
1223         cp /etc/hosts $DIR/d31f
1224         ls -l $DIR/d31f
1225         lfs getstripe $DIR/d31f/hosts
1226         multiop $DIR/d31f D_c &
1227         MULTIPID2=$!
1228
1229         sleep 6
1230
1231         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
1232         wait $MULTIPID || error "first opendir $MULTIPID failed"
1233
1234         sleep 6
1235
1236         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
1237         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
1238         set +vx
1239 }
1240 run_test 31f "remove of open directory with open-unlink file ==="
1241
1242 test_32a() {
1243         echo "== more mountpoints and symlinks ================="
1244         [ -e $DIR/d32a ] && rm -fr $DIR/d32a
1245         mkdir -p $DIR/d32a/ext2-mountpoint 
1246         mount -t ext2 -o loop $EXT2_DEV $DIR/d32a/ext2-mountpoint || error
1247         $CHECKSTAT -t dir $DIR/d32a/ext2-mountpoint/.. || error  
1248         $UMOUNT $DIR/d32a/ext2-mountpoint || error
1249 }
1250 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
1251
1252 test_32b() {
1253         [ -e $DIR/d32b ] && rm -fr $DIR/d32b
1254         mkdir -p $DIR/d32b/ext2-mountpoint 
1255         mount -t ext2 -o loop $EXT2_DEV $DIR/d32b/ext2-mountpoint || error
1256         ls -al $DIR/d32b/ext2-mountpoint/.. || error
1257         $UMOUNT $DIR/d32b/ext2-mountpoint || error
1258 }
1259 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
1260  
1261 test_32c() {
1262         [ -e $DIR/d32c ] && rm -fr $DIR/d32c
1263         mkdir -p $DIR/d32c/ext2-mountpoint 
1264         mount -t ext2 -o loop $EXT2_DEV $DIR/d32c/ext2-mountpoint || error
1265         mkdir -p $DIR/d32c/d2/test_dir    
1266         $CHECKSTAT -t dir $DIR/d32c/ext2-mountpoint/../d2/test_dir || error
1267         $UMOUNT $DIR/d32c/ext2-mountpoint || error
1268 }
1269 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
1270
1271 test_32d() {
1272         [ -e $DIR/d32d ] && rm -fr $DIR/d32d
1273         mkdir -p $DIR/d32d/ext2-mountpoint 
1274         mount -t ext2 -o loop $EXT2_DEV $DIR/d32d/ext2-mountpoint || error
1275         mkdir -p $DIR/d32d/d2/test_dir    
1276         ls -al $DIR/d32d/ext2-mountpoint/../d2/test_dir || error
1277         $UMOUNT $DIR/d32d/ext2-mountpoint || error
1278 }
1279 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
1280
1281 test_32e() {
1282         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
1283         mkdir -p $DIR/d32e/tmp    
1284         TMP_DIR=$DIR/d32e/tmp       
1285         ln -s $DIR/d32e $TMP_DIR/symlink11 
1286         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1287         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
1288         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
1289 }
1290 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
1291
1292 test_32f() {
1293         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
1294         mkdir -p $DIR/d32f/tmp    
1295         TMP_DIR=$DIR/d32f/tmp       
1296         ln -s $DIR/d32f $TMP_DIR/symlink11 
1297         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1298         ls $DIR/d32f/tmp/symlink11  || error
1299         ls $DIR/d32f/symlink01 || error
1300 }
1301 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
1302
1303 test_32g() {
1304         TMP_DIR=$DIR/$tdir/tmp       
1305         mkdir -p $TMP_DIR $DIR/${tdir}2
1306         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12 
1307         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1308         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
1309         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
1310         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
1311         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
1312 }
1313 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1314
1315 test_32h() {
1316         rm -fr $DIR/$tdir $DIR/${tdir}2
1317         TMP_DIR=$DIR/$tdir/tmp       
1318         mkdir -p $TMP_DIR $DIR/${tdir}2 
1319         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12 
1320         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1321         ls $TMP_DIR/symlink12 || error
1322         ls $DIR/$tdir/symlink02  || error
1323 }
1324 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
1325
1326 test_32i() {
1327         [ -e $DIR/d32i ] && rm -fr $DIR/d32i
1328         mkdir -p $DIR/d32i/ext2-mountpoint 
1329         mount -t ext2 -o loop $EXT2_DEV $DIR/d32i/ext2-mountpoint || error
1330         touch $DIR/d32i/test_file
1331         $CHECKSTAT -t file $DIR/d32i/ext2-mountpoint/../test_file || error  
1332         $UMOUNT $DIR/d32i/ext2-mountpoint || error
1333 }
1334 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
1335
1336 test_32j() {
1337         [ -e $DIR/d32j ] && rm -fr $DIR/d32j
1338         mkdir -p $DIR/d32j/ext2-mountpoint 
1339         mount -t ext2 -o loop $EXT2_DEV $DIR/d32j/ext2-mountpoint || error
1340         touch $DIR/d32j/test_file
1341         cat $DIR/d32j/ext2-mountpoint/../test_file || error
1342         $UMOUNT $DIR/d32j/ext2-mountpoint || error
1343 }
1344 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
1345
1346 test_32k() {
1347         rm -fr $DIR/d32k
1348         mkdir -p $DIR/d32k/ext2-mountpoint 
1349         mount -t ext2 -o loop $EXT2_DEV $DIR/d32k/ext2-mountpoint  
1350         mkdir -p $DIR/d32k/d2
1351         touch $DIR/d32k/d2/test_file || error
1352         $CHECKSTAT -t file $DIR/d32k/ext2-mountpoint/../d2/test_file || error
1353         $UMOUNT $DIR/d32k/ext2-mountpoint || error
1354 }
1355 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
1356
1357 test_32l() {
1358         rm -fr $DIR/d32l
1359         mkdir -p $DIR/d32l/ext2-mountpoint 
1360         mount -t ext2 -o loop $EXT2_DEV $DIR/d32l/ext2-mountpoint || error
1361         mkdir -p $DIR/d32l/d2
1362         touch $DIR/d32l/d2/test_file
1363         cat  $DIR/d32l/ext2-mountpoint/../d2/test_file || error
1364         $UMOUNT $DIR/d32l/ext2-mountpoint || error
1365 }
1366 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
1367
1368 test_32m() {
1369         rm -fr $DIR/d32m
1370         mkdir -p $DIR/d32m/tmp    
1371         TMP_DIR=$DIR/d32m/tmp       
1372         ln -s $DIR $TMP_DIR/symlink11 
1373         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1374         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
1375         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
1376 }
1377 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
1378
1379 test_32n() {
1380         rm -fr $DIR/d32n
1381         mkdir -p $DIR/d32n/tmp    
1382         TMP_DIR=$DIR/d32n/tmp       
1383         ln -s $DIR $TMP_DIR/symlink11 
1384         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01 
1385         ls -l $DIR/d32n/tmp/symlink11  || error
1386         ls -l $DIR/d32n/symlink01 || error
1387 }
1388 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
1389
1390 test_32o() {
1391         rm -fr $DIR/d32o $DIR/$tfile
1392         touch $DIR/$tfile 
1393         mkdir -p $DIR/d32o/tmp    
1394         TMP_DIR=$DIR/d32o/tmp       
1395         ln -s $DIR/$tfile $TMP_DIR/symlink12 
1396         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1397         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
1398         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
1399         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
1400         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
1401 }
1402 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
1403
1404 test_32p() {
1405     log 32p_1
1406         rm -fr $DIR/d32p
1407     log 32p_2
1408         rm -f $DIR/$tfile
1409     log 32p_3
1410         touch $DIR/$tfile 
1411     log 32p_4
1412         mkdir -p $DIR/d32p/tmp    
1413     log 32p_5
1414         TMP_DIR=$DIR/d32p/tmp       
1415     log 32p_6
1416         ln -s $DIR/$tfile $TMP_DIR/symlink12 
1417     log 32p_7
1418         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02 
1419     log 32p_8
1420         cat $DIR/d32p/tmp/symlink12 || error
1421     log 32p_9
1422         cat $DIR/d32p/symlink02 || error
1423     log 32p_10
1424 }
1425 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
1426
1427 test_32q() {
1428         [ -e $DIR/d32q ] && rm -fr $DIR/d32q
1429         mkdir -p $DIR/d32q
1430         touch $DIR/d32q/under_the_mount
1431         mount -t ext2 -o loop $EXT2_DEV $DIR/d32q
1432         ls $DIR/d32q/under_the_mount && error || true
1433         $UMOUNT $DIR/d32q || error
1434 }
1435 run_test 32q "stat follows mountpoints in Lustre (should return error)"
1436
1437 test_32r() {
1438         [ -e $DIR/d32r ] && rm -fr $DIR/d32r
1439         mkdir -p $DIR/d32r
1440         touch $DIR/d32r/under_the_mount
1441         mount -t ext2 -o loop $EXT2_DEV $DIR/d32r
1442         ls $DIR/d32r | grep -q under_the_mount && error || true
1443         $UMOUNT $DIR/d32r || error
1444 }
1445 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
1446
1447 test_33() {
1448         rm -f $DIR/$tfile
1449         touch $DIR/$tfile
1450         chmod 444 $DIR/$tfile
1451         chown $RUNAS_ID $DIR/$tfile
1452         log 33_1
1453         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
1454         log 33_2
1455 }
1456 run_test 33 "write file with mode 444 (should return error) ===="
1457
1458 test_33a() {
1459         rm -fr $DIR/d33
1460         mkdir -p $DIR/d33
1461         chown $RUNAS_ID $DIR/d33
1462         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
1463         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
1464                 error "open RDWR" || true
1465 }
1466 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
1467
1468 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
1469 test_34a() {
1470         rm -f $DIR/f34
1471         $MCREATE $DIR/f34 || error
1472         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1473         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
1474         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1475         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1476 }
1477 run_test 34a "truncate file that has not been opened ==========="
1478
1479 test_34b() {
1480         [ ! -f $DIR/f34 ] && test_34a
1481         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1482         $OPENFILE -f O_RDONLY $DIR/f34
1483         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
1484         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1485 }
1486 run_test 34b "O_RDONLY opening file doesn't create objects ====="
1487
1488 test_34c() {
1489         [ ! -f $DIR/f34 ] && test_34a 
1490         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1491         $OPENFILE -f O_RDWR $DIR/f34
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 34c "O_RDWR opening file-with-size works =============="
1496
1497 test_34d() {
1498         [ ! -f $DIR/f34 ] && test_34a 
1499         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
1500         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
1501         rm $DIR/f34
1502 }
1503 run_test 34d "write to sparse file ============================="
1504
1505 test_34e() {
1506         rm -f $DIR/f34e
1507         $MCREATE $DIR/f34e || error
1508         $TRUNCATE $DIR/f34e 1000 || error
1509         $CHECKSTAT -s 1000 $DIR/f34e || error
1510         $OPENFILE -f O_RDWR $DIR/f34e
1511         $CHECKSTAT -s 1000 $DIR/f34e || error
1512 }
1513 run_test 34e "create objects, some with size and some without =="
1514
1515 test_34f() { # bug 6242, 6243
1516         SIZE34F=48000
1517         rm -f $DIR/f34f
1518         $MCREATE $DIR/f34f || error
1519         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
1520         dd if=$DIR/f34f of=$TMP/f34f
1521         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
1522         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
1523         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
1524         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
1525         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
1526 }
1527 run_test 34f "read from a file with no objects until EOF ======="
1528
1529 test_35a() {
1530         cp /bin/sh $DIR/f35a
1531         chmod 444 $DIR/f35a
1532         chown $RUNAS_ID $DIR/f35a
1533         $RUNAS $DIR/f35a && error || true
1534         rm $DIR/f35a
1535 }
1536 run_test 35a "exec file with mode 444 (should return and not leak) ====="
1537
1538 test_36a() {
1539         rm -f $DIR/f36
1540         utime $DIR/f36 || error
1541 }
1542 run_test 36a "MDS utime check (mknod, utime) ==================="
1543
1544 test_36b() {
1545         echo "" > $DIR/f36
1546         utime $DIR/f36 || error
1547 }
1548 run_test 36b "OST utime check (open, utime) ===================="
1549
1550 test_36c() {
1551         rm -f $DIR/d36/f36
1552         mkdir $DIR/d36
1553         chown $RUNAS_ID $DIR/d36
1554         $RUNAS utime $DIR/d36/f36 || error
1555 }
1556 run_test 36c "non-root MDS utime check (mknod, utime) =========="
1557
1558 test_36d() {
1559         [ ! -d $DIR/d36 ] && test_36c
1560         echo "" > $DIR/d36/f36
1561         $RUNAS utime $DIR/d36/f36 || error
1562 }
1563 run_test 36d "non-root OST utime check (open, utime) ==========="
1564
1565 test_36e() {
1566         [ $RUNAS_ID -eq $UID ] && echo "skipping $TESTNAME" && return
1567         mkdir -p $DIR/$tdir
1568         touch $DIR/$tdir/$tfile
1569         $RUNAS utime $DIR/$tdir/$tfile && \
1570                 error "utime worked, expected failure" || true
1571 }
1572 run_test 36e "utime on non-owned file (should return error) ===="
1573
1574 test_36f() {
1575         export LANG=C LC_LANG=C # for date language
1576
1577         DATESTR="Dec 20  2000"
1578         mkdir -p $DIR/$tdir
1579         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
1580         sysctl -w lustre.fail_loc=0x80000214
1581         date; date +%s
1582         cp /etc/hosts $DIR/$tdir/$tfile
1583         sync & # write RPC generated with "current" inode timestamp, but delayed
1584         sleep 1
1585         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
1586         LS_BEFORE="`ls -l $DIR/d36/$tfile`" # "old" timestamp from client cache
1587         cancel_lru_locks osc
1588         LS_AFTER="`ls -l $DIR/d36/$tfile`"  # timestamp from OST object
1589         date; date +%s
1590         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
1591                 echo "BEFORE: $LS_BEFORE" && \
1592                 echo "AFTER : $LS_AFTER" && \
1593                 echo "WANT  : $DATESTR" && \
1594                 error "$DIR/d36/$tfile timestamps changed" || true
1595 }
1596 run_test 36f "utime on file racing with OST BRW write =========="
1597
1598 if [ -d $LPROC/obdfilter ]; then
1599 export FMD_MAX_AGE=`cat $LPROC/obdfilter/*/client_cache_seconds | head -n 1`
1600
1601 test_36g() {
1602         FMD_BEFORE="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1603         touch $DIR/d36/$tfile
1604         sleep $((FMD_MAX_AGE + 12))
1605         FMD_AFTER="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
1606         [ "$FMD_AFTER" -gt "$FMD_BEFORE" ] && \
1607                 echo "AFTER : $FMD_AFTER > BEFORE $FMD_BEFORE" && \
1608                 error "fmd didn't expire after ping" || true
1609 }
1610 run_test 36g "filter mod data cache expiry ====================="
1611 else
1612         log "skipping test_36g because of non-local OST"
1613 fi # [ -d $LPROC/obdfilter ]
1614
1615 test_37() {
1616         mkdir -p $DIR/dextra
1617         echo f > $DIR/dextra/fbugfile
1618         mount -t ext2 -o loop $EXT2_DEV $DIR/dextra
1619         ls $DIR/dextra | grep "\<fbugfile\>" && error
1620         $UMOUNT $DIR/dextra || error
1621         rm -f $DIR/dextra/fbugfile || error
1622 }
1623 run_test 37 "ls a mounted file system to check old content ====="
1624
1625 test_38() {
1626         o_directory $DIR/$tfile
1627 }
1628 run_test 38 "open a regular file with O_DIRECTORY =============="
1629
1630 test_39() {
1631         touch $DIR/$tfile
1632         touch $DIR/${tfile}2
1633 #       ls -l  $DIR/$tfile $DIR/${tfile}2
1634 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
1635 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
1636         sleep 2
1637         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
1638         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
1639                 echo "mtime"
1640                 ls -l  $DIR/$tfile $DIR/${tfile}2
1641                 echo "atime"
1642                 ls -lu  $DIR/$tfile $DIR/${tfile}2
1643                 echo "ctime"
1644                 ls -lc  $DIR/$tfile $DIR/${tfile}2
1645                 error "O_TRUNC didn't change timestamps"
1646         fi
1647 }
1648 run_test 39 "mtime changed on create ==========================="
1649
1650 test_40() {
1651         dd if=/dev/zero of=$DIR/f40 bs=4096 count=1
1652         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/f40 && error
1653         $CHECKSTAT -t file -s 4096 $DIR/f40 || error
1654 }
1655 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
1656
1657 test_41() {
1658         # bug 1553
1659         small_write $DIR/f41 18
1660 }
1661 run_test 41 "test small file write + fstat ====================="
1662
1663 count_ost_writes() {
1664         cat $LPROC/osc/*/stats |
1665             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
1666 }
1667
1668 # decent default
1669 WRITEBACK_SAVE=500
1670
1671 start_writeback() {
1672         trap 0
1673         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs
1674         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1675                 echo $WRITEBACK_SAVE > /proc/sys/vm/dirty_writeback_centisecs
1676         else
1677                 # if file not here, we are a 2.4 kernel
1678                 kill -CONT `pidof kupdated`
1679         fi
1680 }
1681 stop_writeback() {
1682         # setup the trap first, so someone cannot exit the test at the
1683         # exact wrong time and mess up a machine
1684         trap start_writeback EXIT
1685         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
1686         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
1687                 WRITEBACK_SAVE=`cat /proc/sys/vm/dirty_writeback_centisecs`
1688                 echo 0 > /proc/sys/vm/dirty_writeback_centisecs
1689         else
1690                 # if file not here, we are a 2.4 kernel
1691                 kill -STOP `pidof kupdated`
1692         fi
1693 }
1694
1695 # ensure that all stripes have some grant before we test client-side cache
1696 setup_test42() {
1697         [ "$SETUP_TEST42" ] && return
1698         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
1699                 dd if=/dev/zero of=$i bs=4k count=1
1700                 rm $i
1701         done
1702         SETUP_TEST42=DONE
1703 }
1704
1705 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
1706 # file truncation, and file removal.
1707 test_42a() {
1708         setup_test42
1709         cancel_lru_locks osc
1710         stop_writeback
1711         sync; sleep 1; sync # just to be safe
1712         BEFOREWRITES=`count_ost_writes`
1713         grep "[0-9]" $LPROC/osc/*-osc-*/cur_grant_bytes
1714         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
1715         AFTERWRITES=`count_ost_writes`
1716         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1717                 error "$BEFOREWRITES < $AFTERWRITES"
1718         start_writeback
1719 }
1720 run_test 42a "ensure that we don't flush on close =============="
1721
1722 test_42b() {
1723         setup_test42
1724         cancel_lru_locks osc
1725         stop_writeback
1726         sync
1727         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
1728         BEFOREWRITES=`count_ost_writes`
1729         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
1730         AFTERWRITES=`count_ost_writes`
1731         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1732                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
1733         fi
1734         BEFOREWRITES=`count_ost_writes`
1735         sync || error "sync: $?"
1736         AFTERWRITES=`count_ost_writes`
1737         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
1738                 error "$BEFOREWRITES < $AFTERWRITES on sync"
1739         fi
1740         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
1741         start_writeback
1742         return 0
1743 }
1744 run_test 42b "test destroy of file with cached dirty data ======"
1745
1746 # if these tests just want to test the effect of truncation,
1747 # they have to be very careful.  consider:
1748 # - the first open gets a {0,EOF}PR lock
1749 # - the first write conflicts and gets a {0, count-1}PW
1750 # - the rest of the writes are under {count,EOF}PW
1751 # - the open for truncate tries to match a {0,EOF}PR
1752 #   for the filesize and cancels the PWs.
1753 # any number of fixes (don't get {0,EOF} on open, match
1754 # composite locks, do smarter file size management) fix
1755 # this, but for now we want these tests to verify that
1756 # the cancellation with truncate intent works, so we
1757 # start the file with a full-file pw lock to match against
1758 # until the truncate.
1759 trunc_test() {
1760         test=$1
1761         file=$DIR/$test
1762         offset=$2
1763         cancel_lru_locks osc
1764         stop_writeback
1765         # prime the file with 0,EOF PW to match
1766         touch $file
1767         $TRUNCATE $file 0
1768         sync; sync
1769         # now the real test..
1770         dd if=/dev/zero of=$file bs=1024 count=100
1771         BEFOREWRITES=`count_ost_writes`
1772         $TRUNCATE $file $offset
1773         cancel_lru_locks osc
1774         AFTERWRITES=`count_ost_writes`
1775         start_writeback
1776 }
1777
1778 test_42c() {
1779         trunc_test 42c 1024
1780         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
1781             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
1782         rm $file
1783 }
1784 run_test 42c "test partial truncate of file with cached dirty data"
1785
1786 test_42d() {
1787         trunc_test 42d 0
1788         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
1789             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
1790         rm $file
1791 }
1792 run_test 42d "test complete truncate of file with cached dirty data"
1793
1794 test_43() {
1795         mkdir $DIR/$tdir
1796         cp -p /bin/ls $DIR/$tdir/$tfile
1797         exec 100>> $DIR/$tdir/$tfile
1798         $DIR/$tdir/$tfile && error || true
1799         exec 100<&-
1800 }
1801 run_test 43 "execution of file opened for write should return -ETXTBSY"
1802
1803 test_43a() {
1804         mkdir -p $DIR/d43
1805         cp -p `which multiop` $DIR/d43/multiop || cp -p multiop $DIR/d43/multiop
1806         $DIR/d43/multiop $TMP/test43.junk O_c &
1807         MULTIPID=$!
1808         sleep 1
1809         multiop $DIR/d43/multiop Oc && error "expected error, got success"
1810         kill -USR1 $MULTIPID || return 2
1811         wait $MULTIPID || return 3
1812         rm $TMP/test43.junk
1813 }
1814 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
1815
1816 test_43b() {
1817         mkdir -p $DIR/d43
1818         cp -p `which multiop` $DIR/d43/multiop || cp -p multiop $DIR/d43/multiop
1819         $DIR/d43/multiop $TMP/test43.junk O_c &
1820         MULTIPID=$!
1821         sleep 1
1822         truncate $DIR/d43/multiop 0 && error "expected error, got success"
1823         kill -USR1 $MULTIPID || return 2
1824         wait $MULTIPID || return 3
1825         rm $TMP/test43.junk
1826 }
1827 run_test 43b "truncate of file being executed should return -ETXTBSY"
1828
1829 test_43c() {
1830         local testdir="$DIR/d43c"
1831         mkdir -p $testdir
1832         cp $SHELL $testdir/
1833         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
1834                 ( cd $testdir && md5sum -c)
1835 }
1836 run_test 43c "md5sum of copy into lustre========================"
1837
1838 test_44() {
1839         [  "$OSTCOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
1840         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
1841         dd if=$DIR/f1 bs=4k count=1
1842 }
1843 run_test 44 "zero length read from a sparse stripe ============="
1844
1845 test_44a() {
1846     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
1847                          awk '{print $2}'`
1848     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
1849                       awk '{print $2}'`
1850     if [ $nstripe -eq 0 ] ; then
1851         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
1852     fi
1853
1854     OFFSETS="0 $((stride/2)) $((stride-1))"
1855     for offset in $OFFSETS ; do
1856       for i in `seq 0 $((nstripe-1))`; do
1857         local GLOBALOFFSETS=""
1858         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
1859         local myfn=$DIR/d44a-$size
1860         echo "--------writing $myfn at $size"
1861         ll_sparseness_write $myfn $size  || error "ll_sparseness_write"
1862         GLOBALOFFSETS="$GLOBALOFFSETS $size"
1863         ll_sparseness_verify $myfn $GLOBALOFFSETS \
1864                             || error "ll_sparseness_verify $GLOBALOFFSETS"
1865
1866         for j in `seq 0 $((nstripe-1))`; do
1867             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
1868             ll_sparseness_write $myfn $size || error "ll_sparseness_write"
1869             GLOBALOFFSETS="$GLOBALOFFSETS $size"
1870         done
1871         ll_sparseness_verify $myfn $GLOBALOFFSETS \
1872                             || error "ll_sparseness_verify $GLOBALOFFSETS"
1873         rm -f $myfn
1874       done
1875     done
1876 }
1877 run_test 44a "test sparse pwrite ==============================="
1878
1879 dirty_osc_total() {
1880         tot=0
1881         for d in $LPROC/osc/*/cur_dirty_bytes; do
1882                 tot=$(($tot + `cat $d`))
1883         done
1884         echo $tot
1885 }
1886 do_dirty_record() {
1887         before=`dirty_osc_total`
1888         echo executing "\"$*\""
1889         eval $*
1890         after=`dirty_osc_total`
1891         echo before $before, after $after
1892 }
1893 test_45() {
1894         f="$DIR/f45"
1895         # Obtain grants from OST if it supports it
1896         echo blah > ${f}_grant
1897         stop_writeback
1898         sync
1899         do_dirty_record "echo blah > $f"
1900         [ $before -eq $after ] && error "write wasn't cached"
1901         do_dirty_record "> $f"
1902         [ $before -gt $after ] || error "truncate didn't lower dirty count"
1903         do_dirty_record "echo blah > $f"
1904         [ $before -eq $after ] && error "write wasn't cached"
1905         do_dirty_record "sync"
1906         [ $before -gt $after ] || error "writeback didn't lower dirty count"
1907         do_dirty_record "echo blah > $f"
1908         [ $before -eq $after ] && error "write wasn't cached"
1909         do_dirty_record "cancel_lru_locks osc"
1910         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
1911         start_writeback
1912 }
1913 run_test 45 "osc io page accounting ============================"
1914
1915 page_size() {
1916         getconf PAGE_SIZE
1917 }
1918
1919 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
1920 # test tickles a bug where re-dirtying a page was failing to be mapped to the
1921 # objects offset and an assert hit when an rpc was built with 1023's mapped 
1922 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
1923 test_46() {
1924         f="$DIR/f46"
1925         stop_writeback
1926         sync
1927         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
1928         sync
1929         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
1930         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
1931         sync
1932         start_writeback
1933 }
1934 run_test 46 "dirtying a previously written page ================"
1935
1936 # Check that device nodes are created and then visible correctly (#2091)
1937 test_47() {
1938         cmknod $DIR/test_47_node || error
1939 }
1940 run_test 47 "Device nodes check ================================"
1941
1942 test_48a() { # bug 2399
1943         check_kernel_version 34 || return 0
1944         mkdir -p $DIR/d48a
1945         cd $DIR/d48a
1946         mv $DIR/d48a $DIR/d48.new || error "move directory failed"
1947         mkdir $DIR/d48a || error "recreate directory failed"
1948         touch foo || error "'touch foo' failed after recreating cwd"
1949         mkdir bar || error "'mkdir foo' failed after recreating cwd"
1950         if check_kernel_version 44; then
1951                 touch .foo || error "'touch .foo' failed after recreating cwd"
1952                 mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
1953         fi
1954         ls . || error "'ls .' failed after recreating cwd"
1955         ls .. || error "'ls ..' failed after removing cwd"
1956         cd . || error "'cd .' failed after recreating cwd"
1957         mkdir . && error "'mkdir .' worked after recreating cwd"
1958         rmdir . && error "'rmdir .' worked after recreating cwd"
1959         ln -s . baz || error "'ln -s .' failed after recreating cwd"
1960         cd .. || error "'cd ..' failed after recreating cwd"
1961 }
1962 run_test 48a "Access renamed working dir (should return errors)="
1963
1964 test_48b() { # bug 2399
1965         check_kernel_version 34 || return 0
1966         mkdir -p $DIR/d48b
1967         cd $DIR/d48b
1968         rmdir $DIR/d48b || error "remove cwd $DIR/d48b failed"
1969         touch foo && error "'touch foo' worked after removing cwd"
1970         mkdir foo && error "'mkdir foo' worked after removing cwd"
1971         if check_kernel_version 44; then
1972                 touch .foo && error "'touch .foo' worked after removing cwd"
1973                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
1974         fi
1975         ls . && error "'ls .' worked after removing cwd"
1976         ls .. || error "'ls ..' failed after removing cwd"
1977         cd . && error "'cd .' worked after removing cwd"
1978         mkdir . && error "'mkdir .' worked after removing cwd"
1979         rmdir . && error "'rmdir .' worked after removing cwd"
1980         ln -s . foo && error "'ln -s .' worked after removing cwd"
1981         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
1982 }
1983 run_test 48b "Access removed working dir (should return errors)="
1984
1985 test_48c() { # bug 2350
1986         check_kernel_version 36 || return 0
1987         #sysctl -w lnet.debug=-1
1988         #set -vx
1989         mkdir -p $DIR/d48c/dir
1990         cd $DIR/d48c/dir
1991         $TRACE rmdir $DIR/d48c/dir || error "remove cwd $DIR/d48c/dir failed"
1992         $TRACE touch foo && error "'touch foo' worked after removing cwd"
1993         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
1994         if check_kernel_version 44; then
1995                 touch .foo && error "'touch .foo' worked after removing cwd"
1996                 mkdir .foo && error "'mkdir .foo' worked after removing cwd"
1997         fi
1998         $TRACE ls . && error "'ls .' worked after removing cwd"
1999         $TRACE ls .. || error "'ls ..' failed after removing cwd"
2000         $TRACE cd . && error "'cd .' worked after removing cwd"
2001         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
2002         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
2003         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
2004         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
2005 }
2006 run_test 48c "Access removed working subdir (should return errors)"
2007
2008 test_48d() { # bug 2350
2009         check_kernel_version 36 || return 0
2010         #sysctl -w lnet.debug=-1
2011         #set -vx
2012         mkdir -p $DIR/d48d/dir
2013         cd $DIR/d48d/dir
2014         $TRACE rmdir $DIR/d48d/dir || error "remove cwd $DIR/d48d/dir failed"
2015         $TRACE rmdir $DIR/d48d || error "remove parent $DIR/d48d failed"
2016         $TRACE touch foo && error "'touch foo' worked after removing parent"
2017         $TRACE mkdir foo && error "'mkdir foo' worked after removing parent"
2018         if check_kernel_version 44; then
2019                 touch .foo && error "'touch .foo' worked after removing parent"
2020                 mkdir .foo && error "'mkdir .foo' worked after removing parent"
2021         fi
2022         $TRACE ls . && error "'ls .' worked after removing parent"
2023         $TRACE ls .. && error "'ls ..' worked after removing parent"
2024         $TRACE cd . && error "'cd .' worked after recreate parent"
2025         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
2026         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
2027         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
2028         $TRACE cd .. && error "'cd ..' worked after removing parent" || true
2029 }
2030 run_test 48d "Access removed parent subdir (should return errors)"
2031
2032 test_48e() { # bug 4134
2033         check_kernel_version 41 || return 0
2034         #sysctl -w lnet.debug=-1
2035         #set -vx
2036         mkdir -p $DIR/d48e/dir
2037         cd $DIR/d48e/dir
2038         $TRACE rmdir $DIR/d48e/dir || error "remove cwd $DIR/d48e/dir failed"
2039         $TRACE rmdir $DIR/d48e || error "remove parent $DIR/d48e failed"
2040         $TRACE touch $DIR/d48e || error "'touch $DIR/d48e' failed"
2041         $TRACE chmod +x $DIR/d48e || error "'chmod +x $DIR/d48e' failed"
2042         # On a buggy kernel addition of "touch foo" after cd .. will
2043         # produce kernel oops in lookup_hash_it
2044         cd -P .. && error "'cd ..' worked after recreate parent"
2045         touch foo
2046         cd $DIR
2047         $TRACE rm $DIR/d48e || error "rm '$DIR/d48e' failed"
2048 }
2049 run_test 48e "Access to recreated parent subdir (should return errors)"
2050
2051 test_50() {
2052         # bug 1485
2053         mkdir $DIR/d50
2054         cd $DIR/d50
2055         ls /proc/$$/cwd || error
2056 }
2057 run_test 50 "special situations: /proc symlinks  ==============="
2058
2059 test_51() {
2060         # bug 1516 - create an empty entry right after ".." then split dir
2061         mkdir $DIR/d51
2062         touch $DIR/d51/foo
2063         $MCREATE $DIR/d51/bar
2064         rm $DIR/d51/foo
2065         createmany -m $DIR/d51/longfile 201
2066         FNUM=202
2067         while [ `ls -sd $DIR/d51 | awk '{ print $1 }'` -eq 4 ]; do
2068                 $MCREATE $DIR/d51/longfile$FNUM
2069                 FNUM=$(($FNUM + 1))
2070                 echo -n "+"
2071         done
2072         ls -l $DIR/d51 > /dev/null || error
2073 }
2074 run_test 51 "special situations: split htree with empty entry =="
2075
2076 #export NUMTEST=70000
2077 # I select a relatively small number to do basic test. --huanghua
2078 # large number may give panic(). debugging on this is going on.
2079 export NUMTEST=70
2080 test_51b() {
2081         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
2082         [ $NUMFREE -lt 21000 ] && \
2083                 echo "skipping $TESTNAME, not enough free inodes ($NUMFREE)" && \
2084                 return
2085
2086         check_kernel_version 40 || NUMTEST=31000
2087         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 50))
2088
2089         mkdir -p $DIR/d51b
2090         createmany -d $DIR/d51b/t- $NUMTEST
2091 }
2092 run_test 51b "mkdir .../t-0 --- .../t-$NUMTEST ===================="
2093
2094 test_51c() {
2095         [ ! -d $DIR/d51b ] && echo "skipping $TESTNAME: $DIR/51b missing" && \
2096                 return
2097
2098         unlinkmany -d $DIR/d51b/t- $NUMTEST
2099 }
2100 run_test 51c "rmdir .../t-0 --- .../t-$NUMTEST ===================="
2101
2102 test_51d() {
2103         [  "$OSTCOUNT" -lt "3" ] && echo "skipping test with few OSTs" && return
2104         mkdir -p $DIR/d51d
2105         createmany -o $DIR/d51d/t- 1000
2106         $LFS getstripe $DIR/d51d > $TMP/files
2107         for N in `seq 0 $((OSTCOUNT - 1))`; do
2108             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
2109             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
2110             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
2111         done
2112         unlinkmany $DIR/d51d/t- 1000
2113
2114         NLAST=0
2115         for N in `seq 1 $((OSTCOUNT - 1))`; do
2116             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
2117                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2118             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
2119                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
2120             
2121             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
2122                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2123             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
2124                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
2125             NLAST=$N
2126         done
2127 }
2128 run_test 51d "check object distribution ===================="
2129
2130 test_52a() {
2131         [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
2132         mkdir -p $DIR/d52a
2133         touch $DIR/d52a/foo
2134         chattr =a $DIR/d52a/foo || error "chattr =a failed"
2135         echo bar >> $DIR/d52a/foo || error "append bar failed"
2136         cp /etc/hosts $DIR/d52a/foo && error "cp worked"
2137         rm -f $DIR/d52a/foo 2>/dev/null && error "rm worked"
2138         link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error "link worked"
2139         echo foo >> $DIR/d52a/foo || error "append foo failed"
2140         mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error "rename worked"
2141         lsattr $DIR/d52a/foo | egrep -q "^-+a-+ $DIR/d52a/foo" || error "lsattr"
2142         chattr -a $DIR/d52a/foo || error "chattr -a failed"
2143
2144         rm -fr $DIR/d52a || error "cleanup rm failed"
2145 }
2146 run_test 52a "append-only flag test (should return errors) ====="
2147
2148 test_52b() {
2149         [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
2150         mkdir -p $DIR/d52b
2151         touch $DIR/d52b/foo
2152         chattr =i $DIR/d52b/foo || error
2153         cat test > $DIR/d52b/foo && error
2154         cp /etc/hosts $DIR/d52b/foo && error
2155         rm -f $DIR/d52b/foo 2>/dev/null && error
2156         link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error
2157         echo foo >> $DIR/d52b/foo && error
2158         mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error
2159         [ -f $DIR/d52b/foo ] || error
2160         [ -f $DIR/d52b/foo_ren ] && error
2161         lsattr $DIR/d52b/foo | egrep -q "^-+i-+ $DIR/d52b/foo" || error
2162         chattr -i $DIR/d52b/foo || error
2163
2164         rm -fr $DIR/d52b || error
2165 }
2166 run_test 52b "immutable flag test (should return errors) ======="
2167
2168 test_53() {
2169         for i in `ls -d $LPROC/osc/*-osc 2> /dev/null` ; do
2170                 ostname=`basename $i | cut -d - -f 1-2`
2171                 ost_last=`cat $LPROC/obdfilter/$ostname/last_id`
2172                 mds_last=`cat $i/prealloc_last_id`
2173                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2174                 if [ $ost_last != $mds_last ]; then
2175                     error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
2176                 fi
2177         done
2178 }
2179 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
2180
2181 test_54a() {
2182         $SOCKETSERVER $DIR/socket
2183         $SOCKETCLIENT $DIR/socket || error
2184         $MUNLINK $DIR/socket
2185 }
2186 run_test 54a "unix domain socket test =========================="
2187
2188 test_54b() {
2189         f="$DIR/f54b"
2190         mknod $f c 1 3
2191         chmod 0666 $f
2192         dd if=/dev/zero of=$f bs=`page_size` count=1 
2193 }
2194 run_test 54b "char device works in lustre ======================"
2195
2196 find_loop_dev() {
2197         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
2198         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
2199         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
2200
2201         for i in `seq 3 7`; do
2202                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
2203                 LOOPDEV=$LOOPBASE$i
2204                 LOOPNUM=$i
2205                 break
2206         done
2207 }
2208
2209 test_54c() {
2210         tfile="$DIR/f54c"
2211         tdir="$DIR/d54c"
2212         loopdev="$DIR/loop54c"
2213
2214         find_loop_dev 
2215         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
2216         mknod $loopdev b 7 $LOOPNUM
2217         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
2218         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
2219         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
2220         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
2221         mkdir -p $tdir
2222         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
2223         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
2224         df $tdir
2225         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
2226         $UMOUNT $tdir
2227         losetup -d $loopdev
2228         rm $loopdev
2229 }
2230 run_test 54c "block device works in lustre ====================="
2231
2232 test_54d() {
2233         f="$DIR/f54d"
2234         string="aaaaaa"
2235         mknod $f p
2236         [ "$string" = `echo $string > $f | cat $f` ] || error
2237 }
2238 run_test 54d "fifo device works in lustre ======================"
2239
2240 test_54e() {
2241         check_kernel_version 46 || return 0
2242         f="$DIR/f54e"
2243         string="aaaaaa"
2244         mknod $f c 4 0
2245         echo $string > $f || error
2246 }
2247 run_test 54e "console/tty device works in lustre ======================"
2248
2249 check_fstype() {
2250         grep -q $FSTYPE /proc/filesystems && return 1
2251         modprobe $FSTYPE
2252         grep -q $FSTYPE /proc/filesystems && return 1
2253         insmod ../$FSTYPE/$FSTYPE.o
2254         grep -q $FSTYPE /proc/filesystems && return 1
2255         insmod ../$FSTYPE/$FSTYPE.ko
2256         grep -q $FSTYPE /proc/filesystems && return 1
2257         return 0
2258 }
2259
2260 test_55() {
2261         rm -rf $DIR/d55
2262         mkdir $DIR/d55
2263         check_fstype && echo "can't find fs $FSTYPE, skipping $TESTNAME" && return
2264         mount -t $FSTYPE -o loop,iopen $EXT2_DEV $DIR/d55 || error "mounting"
2265         touch $DIR/d55/foo
2266         $IOPENTEST1 $DIR/d55/foo $DIR/d55 || error "running $IOPENTEST1"
2267         $IOPENTEST2 $DIR/d55 || error "running $IOPENTEST2"
2268         echo "check for $EXT2_DEV. Please wait..."
2269         rm -rf $DIR/d55/*
2270         $UMOUNT $DIR/d55 || error "unmounting"
2271 }
2272 run_test 55 "check iopen_connect_dentry() ======================"
2273
2274 test_56() {
2275         rm -rf $DIR/d56
2276         $SETSTRIPE -d $DIR
2277         mkdir $DIR/d56
2278         mkdir $DIR/d56/dir
2279         NUMFILES=3
2280         NUMFILESx2=$(($NUMFILES * 2))
2281         for i in `seq 1 $NUMFILES` ; do
2282                 touch $DIR/d56/file$i
2283                 touch $DIR/d56/dir/file$i
2284         done
2285
2286         # test lfs getstripe with --recursive
2287         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | grep -c obdidx`
2288         [ $FILENUM -eq $NUMFILESx2 ] || error \
2289                 "lfs getstripe --recursive $DIR/d56 wrong: found $FILENUM, expected $NUMFILESx2"
2290         FILENUM=`$GETSTRIPE $DIR/d56 | grep -c obdidx`
2291         [ $FILENUM -eq $NUMFILES ] || error \
2292                 "lfs getstripe $DIR/d56 without --recursive wrong: found $FILENUM, expected $NUMFILES"
2293         echo "lfs getstripe --recursive passed."
2294
2295         # test lfs getstripe with file instead of dir
2296         FILENUM=`$GETSTRIPE $DIR/d56/file1 | grep -c obdidx`
2297         [ $FILENUM  -eq 1 ] || error \
2298                  "lfs getstripe $DIR/d56/file1 wrong:found $FILENUM, expected 1"
2299         echo "lfs getstripe file passed."
2300
2301         #test lfs getstripe with --verbose
2302         [ `$GETSTRIPE --verbose $DIR/d56 | grep -c lmm_magic` -eq $NUMFILES ] ||\
2303                 error "lfs getstripe --verbose $DIR/d56 wrong: should find $NUMFILES lmm_magic info"
2304         [ `$GETSTRIPE $DIR/d56 | grep -c lmm_magic` -eq 0 ] || error \
2305                 "lfs getstripe $DIR/d56 without --verbose wrong: should not show lmm_magic info"
2306         echo "lfs getstripe --verbose passed."
2307
2308         #test lfs getstripe with --obd
2309         $GETSTRIPE --obd wrong_uuid $DIR/d56 2>&1 | grep -q "unknown obduuid" || \
2310                 error "lfs getstripe --obd wrong_uuid should return error message"
2311
2312         [  "$OSTCOUNT" -lt 2 ] && \
2313                 echo "skipping other lfs getstripe --obd test" && return
2314         FILENUM=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1[    ]/p' | wc -l`
2315         OBDUUID=`$GETSTRIPE --recursive $DIR/d56 | sed -n '/^[   ]*1:/p' | awk '{print $2}'`
2316         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/d56 | wc -l`
2317         [ $FOUND -eq $FILENUM ] || \
2318                 error "lfs getstripe --obd wrong: found $FOUND, expected $FILENUM"
2319         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/d56 | sed '/^[   ]*1[    ]/d' |\
2320                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] || \
2321                 error "lfs getstripe --obd wrong: should not show file on other obd"
2322         echo "lfs getstripe --obd passed."
2323 }
2324 run_test 56 "check lfs getstripe ===================================="
2325
2326 test_57a() {
2327         # note test will not do anything if MDS is not local
2328         for DEV in `cat $LPROC/mds/*/mntdev`; do
2329                 dumpe2fs -h $DEV > $TMP/t57a.dump || error "can't access $DEV"
2330                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
2331                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
2332                 rm $TMP/t57a.dump
2333         done
2334 }
2335 run_test 57a "verify MDS filesystem created with large inodes =="
2336
2337 test_57b() {
2338 #       now we do not support large directory. I change this from 100 to 10
2339 #       restore it when ready -- huanghua
2340         FILECOUNT=100
2341         FILE1=$DIR/d57b/f1
2342         FILEN=$DIR/d57b/f$FILECOUNT
2343         rm -rf $DIR/d57b || error "removing $DIR/d57b"
2344         mkdir -p $DIR/d57b || error "creating $DIR/d57b"
2345         echo "mcreating $FILECOUNT files"
2346         createmany -m $DIR/d57b/f 1 $FILECOUNT || \
2347                 error "creating files in $DIR/d57b"
2348
2349         # verify that files do not have EAs yet
2350         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
2351         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
2352
2353         MDSFREE="`cat $LPROC/mds/*/kbytesfree`"
2354         MDCFREE="`cat $LPROC/mdc/*/kbytesfree`"
2355         echo "opening files to create objects/EAs"
2356         for FILE in `seq -f $DIR/d57b/f%g 1 $FILECOUNT`; do
2357                 $OPENFILE -f O_RDWR $FILE > /dev/null || error "opening $FILE"
2358         done
2359
2360         # verify that files have EAs now
2361         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
2362         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
2363
2364         sleep 1 # make sure we get new statfs data
2365 #       MDSFREE2="`cat $LPROC/mds/*/kbytesfree`"
2366 #       MDCFREE2="`cat $LPROC/mdc/*/kbytesfree`"
2367 #       if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
2368 #               if [ "$MDSFREE" != "$MDSFREE2" ]; then
2369 #                       error "MDC before $MDCFREE != after $MDCFREE2"
2370 #               else
2371 #                       echo "MDC before $MDCFREE != after $MDCFREE2"
2372 #                       echo "unable to confirm if MDS has large inodes"
2373 #               fi
2374 #       fi
2375         rm -rf $DIR/d57b
2376 }
2377 run_test 57b "default LOV EAs are stored inside large inodes ==="
2378
2379 test_58() {
2380     [ -z "$(which wiretest 2>/dev/null)" ] && echo "skipping $TESTNAME (could not find wiretest)" && return
2381     wiretest
2382 }
2383 run_test 58 "verify cross-platform wire constants =============="
2384
2385 test_59() {
2386         echo "touch 130 files"
2387         createmany -o $DIR/f59- 130
2388         echo "rm 130 files"
2389         unlinkmany $DIR/f59- 130
2390         sync
2391         sleep 2
2392         # wait for commitment of removal
2393 }
2394 run_test 59 "verify cancellation of llog records async ========="
2395
2396 test_60() {
2397         echo 60 "llog tests run from kernel mode"
2398         sh run-llog.sh
2399 }
2400 run_test 60 "llog sanity tests run from kernel module =========="
2401
2402 test_60b() { # bug 6411
2403         dmesg > $DIR/dmesg
2404         LLOG_COUNT=`dmesg | grep -c llog_test`
2405         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages"|| true
2406 }
2407 run_test 60b "limit repeated messages from CERROR/CWARN ========"
2408
2409 test_61() {
2410         f="$DIR/f61"
2411         dd if=/dev/zero of=$f bs=`page_size` count=1
2412         cancel_lru_locks osc
2413         multiop $f OSMWUc || error
2414         sync
2415 }
2416 run_test 61 "mmap() writes don't make sync hang ================"
2417
2418 # bug 2330 - insufficient obd_match error checking causes LBUG
2419 test_62() {
2420         f="$DIR/f62"
2421         echo foo > $f
2422         cancel_lru_locks osc
2423         sysctl -w lustre.fail_loc=0x405
2424         cat $f && error "cat succeeded, expect -EIO"
2425         sysctl -w lustre.fail_loc=0
2426 }
2427 run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
2428
2429 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
2430 test_63() {
2431         MAX_DIRTY_MB=`cat $LPROC/osc/*/max_dirty_mb | head -n 1`
2432         for i in $LPROC/osc/*/max_dirty_mb ; do
2433                 echo 0 > $i
2434         done
2435         for i in `seq 10` ; do
2436                 dd if=/dev/zero of=$DIR/f63 bs=8k &
2437                 sleep 5
2438                 kill $!
2439                 sleep 1
2440         done
2441
2442         for i in $LPROC/osc/*/max_dirty_mb ; do
2443                 echo $MAX_DIRTY_MB > $i
2444         done
2445         rm -f $DIR/f63 || true
2446 }
2447 run_test 63 "Verify oig_wait interruption does not crash ======="
2448
2449 # bug 2248 - async write errors didn't return to application on sync
2450 # bug 3677 - async write errors left page locked
2451 test_63b() {
2452         DBG_SAVE=`sysctl -n lnet.debug`
2453         sysctl -w lnet.debug=-1
2454
2455         # ensure we have a grant to do async writes
2456         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
2457         rm $DIR/$tfile
2458
2459         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
2460         sysctl -w lustre.fail_loc=0x80000406
2461         multiop $DIR/$tfile Owy && \
2462                 $LCTL dk /tmp/test63b.debug && \
2463                 sysctl -w lnet.debug=$DBG_SAVE && \
2464                 error "sync didn't return ENOMEM"
2465         grep -q locked $LPROC/llite/*/dump_page_cache && \
2466                 $LCTL dk /tmp/test63b.debug && \
2467                 sysctl -w lnet.debug=$DBG_SAVE && \
2468                 error "locked page left in cache after async error" || true
2469         sysctl -w lnet.debug=$DBG_SAVE
2470 }
2471 run_test 63b "async write errors should be returned to fsync ==="
2472
2473 test_64a () {
2474         df $DIR
2475         grep "[0-9]" $LPROC/osc/*-osc-*/cur*
2476 }
2477 run_test 64a "verify filter grant calculations (in kernel) ====="
2478
2479 test_64b () {
2480         sh oos.sh $MOUNT
2481 }
2482 run_test 64b "check out-of-space detection on client ==========="
2483
2484 # bug 1414 - set/get directories' stripe info
2485 test_65a() {
2486         mkdir -p $DIR/d65
2487         touch $DIR/d65/f1
2488         $LVERIFY $DIR/d65 $DIR/d65/f1 || error "lverify failed"
2489 }
2490 run_test 65a "directory with no stripe info ===================="
2491
2492 test_65b() {
2493         mkdir -p $DIR/d65
2494         $SETSTRIPE $DIR/d65 $(($STRIPESIZE * 2)) 0 1 || error "setstripe"
2495         touch $DIR/d65/f2
2496         $LVERIFY $DIR/d65 $DIR/d65/f2 || error "lverify failed"
2497 }
2498 run_test 65b "directory setstripe $(($STRIPESIZE * 2)) 0 1 ==============="
2499
2500 test_65c() {
2501         if [ $OSTCOUNT -gt 1 ]; then
2502                 mkdir -p $DIR/d65
2503                 $SETSTRIPE $DIR/d65 $(($STRIPESIZE * 4)) 1 \
2504                         $(($OSTCOUNT - 1)) || error "setstripe"
2505                 touch $DIR/d65/f3
2506                 $LVERIFY $DIR/d65 $DIR/d65/f3 || error "lverify failed"
2507         fi
2508 }
2509 run_test 65c "directory setstripe $(($STRIPESIZE * 4)) 1 $(($OSTCOUNT - 1))"
2510
2511 [ $STRIPECOUNT -eq 0 ] && sc=1 || sc=$(($STRIPECOUNT - 1))
2512
2513 test_65d() {
2514         mkdir -p $DIR/d65
2515         $SETSTRIPE $DIR/d65 $STRIPESIZE -1 $sc || error "setstripe"
2516         touch $DIR/d65/f4 $DIR/d65/f5
2517         $LVERIFY $DIR/d65 $DIR/d65/f4 $DIR/d65/f5 || error "lverify failed"
2518 }
2519 run_test 65d "directory setstripe $STRIPESIZE -1 $sc =============="
2520
2521 test_65e() {
2522         mkdir -p $DIR/d65
2523
2524         $SETSTRIPE $DIR/d65 0 -1 0 || error "setstripe"
2525         $GETSTRIPE -v $DIR/d65 | grep "has no stripe info" || error "no stripe info failed"
2526         touch $DIR/d65/f6
2527         $LVERIFY $DIR/d65 $DIR/d65/f6 || error "lverify failed"
2528 }
2529 run_test 65e "directory setstripe 0 -1 0 ======================="
2530
2531 test_65f() {
2532         mkdir -p $DIR/d65f
2533         $RUNAS $SETSTRIPE $DIR/d65f 0 -1 0 && error "setstripe succeeded" || true
2534 }
2535 run_test 65f "dir setstripe permission (should return error) ==="
2536
2537 test_65g() {
2538         mkdir -p $DIR/d65
2539         $SETSTRIPE $DIR/d65 $(($STRIPESIZE * 2)) 0 1 || error "setstripe"
2540         $SETSTRIPE -d $DIR/d65 || error "setstripe"
2541         $GETSTRIPE -v $DIR/d65 | grep "has no stripe info" || \
2542                 error "delete default stripe failed"
2543 }
2544 run_test 65g "directory setstripe -d ==========================="
2545
2546 test_65h() {
2547         mkdir -p $DIR/d65
2548         $SETSTRIPE $DIR/d65 $(($STRIPESIZE * 2)) 0 1 || error "setstripe"
2549         mkdir -p $DIR/d65/dd1
2550         [ "`$GETSTRIPE -v $DIR/d65 | grep "^count"`" == \
2551           "`$GETSTRIPE -v $DIR/d65/dd1 | grep "^count"`" ] || error "stripe info inherit failed"
2552 }
2553 run_test 65h "directory stripe info inherit ===================="
2554  
2555 test_65i() { # bug6367
2556         $SETSTRIPE $MOUNT 65536 -1 -1
2557 }
2558 run_test 65i "set non-default striping on root directory (bug 6367)="
2559
2560 test_65j() { # bug6367
2561         return
2562         # if we aren't already remounting for each test, do so for this test
2563         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
2564                 cleanup -f || error "failed to unmount"
2565                 setup
2566         fi
2567         $SETSTRIPE -d $MOUNT
2568 }
2569 run_test 65j "set default striping on root directory (bug 6367)="
2570
2571 # bug 2543 - update blocks count on client
2572 test_66() {
2573         COUNT=${COUNT:-8}
2574         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
2575         sync
2576         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
2577         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
2578 }
2579 run_test 66 "update inode blocks count on client ==============="
2580
2581 test_67() { # bug 3285 - supplementary group fails on MDS, passes on client
2582         [ "$RUNAS_ID" = "$UID" ] && echo "skipping $TESTNAME" && return
2583         check_kernel_version 35 || return 0
2584         mkdir $DIR/d67
2585         chmod 771 $DIR/d67
2586         chgrp $RUNAS_ID $DIR/d67
2587         $RUNAS -u $RUNAS_ID -g $(($RUNAS_ID + 1)) -G1,2,$RUNAS_ID ls $DIR/d67
2588         RC=$?
2589         if [ "$MDS" ]; then
2590                 # can't tell which is correct otherwise
2591                 GROUP_UPCALL=`cat $LPROC/mds/$MDS/group_upcall`
2592                 [ "$GROUP_UPCALL" = "NONE" -a $RC -eq 0 ] && \
2593                         error "no-upcall passed" || true
2594                 [ "$GROUP_UPCALL" != "NONE" -a $RC -ne 0 ] && \
2595                         error "upcall failed" || true
2596         fi
2597 }
2598 run_test 67 "supplementary group failure (should return error) ="
2599
2600 cleanup_68() {
2601         trap 0
2602         if [ "$LOOPDEV" ]; then
2603                 swapoff $LOOPDEV || error "swapoff failed"
2604                 losetup -d $LOOPDEV || error "losetup -d failed"
2605                 unset LOOPDEV LOOPNUM
2606         fi
2607         rm -f $DIR/f68
2608 }
2609
2610 meminfo() {
2611         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
2612 }
2613
2614 swap_used() {
2615         swapon -s | awk '($1 == "'$1'") { print $4 }'
2616 }
2617
2618 # excercise swapping to lustre by adding a high priority swapfile entry
2619 # and then consuming memory until it is used.
2620 test_68() {
2621 #       my UML is out of memory, so I skip it -- huanghua
2622         return
2623         [ "$UID" != 0 ] && echo "skipping $TESTNAME (must run as root)" && return
2624         [ "`lsmod|grep obdfilter`" ] && echo "skipping $TESTNAME (local OST)" && \
2625                 return
2626
2627         find_loop_dev
2628         dd if=/dev/zero of=$DIR/f68 bs=64k count=1024
2629
2630         trap cleanup_68 EXIT
2631
2632         losetup $LOOPDEV $DIR/f68 || error "losetup $LOOPDEV failed"
2633         mkswap $LOOPDEV
2634         swapon -p 32767 $LOOPDEV || error "swapon $LOOPDEV failed"
2635
2636         echo "before: `swapon -s | grep $LOOPDEV`"
2637         KBFREE=`meminfo MemTotal`
2638         $MEMHOG $KBFREE || error "error allocating $KBFREE kB"
2639         echo "after: `swapon -s | grep $LOOPDEV`"
2640         SWAPUSED=`swap_used $LOOPDEV`
2641
2642         cleanup_68
2643
2644         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
2645 }
2646 run_test 68 "support swapping to Lustre ========================"
2647
2648 # bug5265, obdfilter oa2dentry return -ENOENT
2649 # #define OBD_FAIL_OST_ENOENT 0x217
2650 test_69() {
2651         [ -z "`lsmod|grep obdfilter`" ] &&
2652                 echo "skipping $TESTNAME (remote OST)" && return
2653         [ ! -z "$USING_KRB5" ] &&
2654                 echo "skipping $TESTNAME (gss with bulk security will triger oops. re-enable this after b10091 get fixed)" && return
2655
2656         f="$DIR/$tfile"
2657         touch $f
2658
2659         if ! $DIRECTIO write ${f}.2 0 1; then
2660                 echo "skipping $TESTNAME - O_DIRECT not implemented"
2661                 return 0
2662         fi
2663
2664         sysctl -w lustre.fail_loc=0x217
2665         truncate $f 1 # vmtruncate() will ignore truncate() error.
2666         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
2667
2668         sysctl -w lustre.fail_loc=0
2669         $DIRECTIO write $f 0 2 || error "write error"
2670
2671         cancel_lru_locks osc
2672         $DIRECTIO read $f 0 1 || error "read error"
2673
2674         sysctl -w lustre.fail_loc=0x217
2675         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
2676
2677         sysctl -w lustre.fail_loc=0
2678         rm -f $f
2679 }
2680 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
2681
2682 test_71() {
2683         DBENCH_LIB=${DBENCH_LIB:-/usr/lib/dbench}
2684         PATH=${DBENCH_LIB}:${PATH}
2685         cp `which dbench` $DIR
2686
2687         [ ! -f $DIR/dbench ] && echo "dbench not installed, skip this test" && return 0
2688
2689         TGT=$DIR/client.txt
2690         SRC=${SRC:-$DBENCH_LIB/client.txt}
2691         [ ! -e $TGT -a -e $SRC ] && echo "copying $SRC to $TGT" && cp $SRC $TGT
2692         SRC=$DBENCH_LIB/client_plain.txt
2693         [ ! -e $TGT -a -e $SRC ] && echo "copying $SRC to $TGT" && cp $SRC $TGT
2694
2695         echo "copying necessary lib to $DIR"
2696         [ -d /lib64 ] && LIB71=/lib64 || LIB71=/lib
2697         mkdir -p $DIR$LIB71 || error "can't create $DIR$LIB71"
2698         cp $LIB71/libc* $DIR$LIB71 || error "can't copy $LIB71/libc*"
2699         cp $LIB71/ld-* $DIR$LIB71 || error "can't create $LIB71/ld-*"
2700
2701         echo "chroot $DIR /dbench -c client.txt 2"
2702         chroot $DIR /dbench -c client.txt 2
2703         RC=$?
2704
2705         rm -rf $DIR/dbench $TGT $DIR$LIB71
2706
2707         return $RC
2708 }
2709 run_test 71 "Running dbench on lustre (don't segment fault) ===="
2710
2711 test_72() { # bug 5695 - Test that on 2.6 remove_suid works properly
2712         check_kernel_version 43 || return 0
2713         [ "$RUNAS_ID" = "$UID" ] && echo "skipping $TESTNAME" && return
2714         # We had better clear the $DIR to get enough space for dd
2715         rm -rf $DIR/*
2716         touch $DIR/f72
2717         chmod 777 $DIR/f72
2718         chmod ug+s $DIR/f72
2719         $RUNAS -u $(($RUNAS_ID + 1)) dd if=/dev/zero of=$DIR/f72 bs=512 count=1 || error
2720         # See if we are still setuid/sgid
2721         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on write"
2722         # Now test that MDS is updated too
2723         cancel_lru_locks mdc
2724         test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on MDS"
2725         true
2726 }
2727 run_test 72 "Test that remove suid works properly (bug5695) ===="
2728
2729 # bug 3462 - multiple simultaneous MDC requests
2730 test_73() {
2731         mkdir $DIR/d73-1 
2732         mkdir $DIR/d73-2
2733         multiop $DIR/d73-1/f73-1 O_c &
2734         pid1=$!
2735         #give multiop a chance to open
2736         usleep 500
2737
2738         echo 0x80000129 > /proc/sys/lustre/fail_loc
2739         multiop $DIR/d73-1/f73-2 Oc &
2740         sleep 1
2741         echo 0 > /proc/sys/lustre/fail_loc
2742
2743         multiop $DIR/d73-2/f73-3 Oc &
2744         pid3=$!
2745
2746         kill -USR1 $pid1
2747         wait $pid1 || return 1
2748
2749         sleep 25
2750
2751         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
2752         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5 
2753         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6 
2754
2755         rm -rf $DIR/d73-*
2756 }
2757 run_test 73 "multiple MDC requests (should not deadlock)"
2758
2759 test_74() { # bug 6149, 6184
2760         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
2761         #
2762         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
2763         # will spin in a tight reconnection loop
2764         sysctl -w lustre.fail_loc=0x8000030e
2765         # get any lock
2766         touch $DIR/f74
2767         sysctl -w lustre.fail_loc=0
2768         true
2769 }
2770 run_test 74 "ldlm_enqueue freed-export error path (shouldn't LBUG)"
2771
2772 JOIN=${JOIN:-"lfs join"}
2773 F75=$DIR/f75
2774 F128k=${F75}_128k
2775 FHEAD=${F75}_head
2776 FTAIL=${F75}_tail
2777 export T75_PREP=no
2778 test75_prep() {
2779         [ $T75_PREP = "yes" ] && return
2780         echo "using F75=$F75, F128k=$F128k, FHEAD=$FHEAD, FTAIL=$FTAIL"
2781  
2782         dd if=/dev/urandom of=${F75}_128k bs=128k count=1 || error "dd failed"
2783         log "finished dd"
2784         chmod 777 ${F128k}
2785         T75_PREP=yes
2786 }
2787  
2788 test_75a() {
2789 #       skipped temporarily: we do not have join file currently
2790 #       please remove this when ready - huanghua
2791         return
2792         test75_prep
2793  
2794         cp -p ${F128k} ${FHEAD}
2795         log "finished cp to $FHEAD"
2796         cp -p ${F128k} ${FTAIL}
2797         log "finished cp to $FTAIL"
2798         cat ${F128k} ${F128k} > ${F75}_sim_sim
2799  
2800         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
2801         log "finished join $FHEAD to ${F75}_sim_sim"
2802         cmp ${FHEAD} ${F75}_sim_sim || error "${FHEAD} ${F75}_sim_sim differ"
2803         log "finished cmp $FHEAD to ${F75}_sim_sim"
2804         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} still exist after join"
2805 }
2806 run_test 75a "TEST join file ===================================="
2807  
2808 test_75b() {
2809 #       skipped temporarily: we do not have join file currently
2810 #       please remove this when ready - huanghua
2811         return
2812         test75_prep
2813  
2814         cp -p ${F128k} ${FTAIL}
2815         cat ${F75}_sim_sim >> ${F75}_join_sim
2816         cat ${F128k} >> ${F75}_join_sim
2817         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
2818         cmp ${FHEAD} ${F75}_join_sim || \
2819                 error "${FHEAD} ${F75}_join_sim are different"
2820         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join"
2821 }
2822 run_test 75b "TEST join file 2 =================================="
2823  
2824 test_75c() {
2825 #       skipped temporarily: we do not have join file currently
2826 #       please remove this when ready - huanghua
2827         return
2828         test75_prep
2829  
2830         cp -p ${F128k} ${FTAIL}
2831         cat ${F128k} >> ${F75}_sim_join
2832         cat ${F75}_join_sim >> ${F75}_sim_join
2833         $JOIN ${FTAIL} ${FHEAD} || error "join error"
2834         cmp ${FTAIL} ${F75}_sim_join || \
2835                 error "${FTAIL} ${F75}_sim_join are different"
2836         $CHECKSTAT -a ${FHEAD} || error "tail ${FHEAD} exist after join"
2837 }
2838 run_test 75c "TEST join file 3 =================================="
2839  
2840 test_75d() {
2841 #       skipped temporarily: we do not have join file currently
2842 #       please remove this when ready - huanghua
2843         return
2844         test75_prep
2845  
2846         cp -p ${F128k} ${FHEAD}
2847         cp -p ${F128k} ${FHEAD}_tmp
2848         cat ${F75}_sim_sim >> ${F75}_join_join
2849         cat ${F75}_sim_join >> ${F75}_join_join
2850         $JOIN ${FHEAD} ${FHEAD}_tmp || error "join ${FHEAD} ${FHEAD}_tmp error"
2851         $JOIN ${FHEAD} ${FTAIL} || error "join ${FHEAD} ${FTAIL} error"
2852         cmp ${FHEAD} ${F75}_join_join ||error "${FHEAD} ${F75}_join_join differ"        $CHECKSTAT -a ${FHEAD}_tmp || error "${FHEAD}_tmp exist after join"
2853         $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join (2)"
2854 }
2855 run_test 75d "TEST join file 4 =================================="
2856  
2857 test_75e() {
2858 #       skipped temporarily: we do not have join file currently
2859 #       please remove this when ready - huanghua
2860         return
2861         test75_prep
2862  
2863         rm -rf ${FHEAD} || "delete join file error"
2864 }
2865 run_test 75e "TEST join file 5 (remove joined file) ============="
2866  
2867 test_75f() {
2868 #       skipped temporarily: we do not have join file currently
2869 #       please remove this when ready - huanghua
2870         return
2871         test75_prep
2872  
2873         cp -p ${F128k} ${F75}_join_10_compare
2874         cp -p ${F128k} ${F75}_join_10
2875         for ((i = 0; i < 10; i++)); do
2876                 cat ${F128k} >> ${F75}_join_10_compare
2877                 cp -p ${F128k} ${FTAIL}
2878                 $JOIN ${F75}_join_10 ${FTAIL} || \
2879                         error "join ${F75}_join_10 ${FTAIL} error"
2880                 $CHECKSTAT -a ${FTAIL} || error "tail file exist after join"
2881         done
2882         cmp ${F75}_join_10 ${F75}_join_10_compare || \
2883                 error "files ${F75}_join_10 ${F75}_join_10_compare differ"
2884 }
2885 run_test 75f "TEST join file 6 (join 10 files) =================="
2886  
2887 test_75g() {
2888 #       skipped temporarily: we do not have join file currently
2889 #       please remove this when ready - huanghua
2890         return
2891         [ ! -f ${F75}_join_10 ] && echo "${F75}_join_10 missing" && return
2892         $LFS getstripe ${F75}_join_10
2893  
2894         $OPENUNLINK ${F75}_join_10 ${F75}_join_10 || error "files unlink open"
2895  
2896         ls -l $F75*
2897 }
2898 run_test 75g "TEST join file 7 (open unlink) ===================="
2899
2900 num_inodes() {
2901         awk '/lustre_inode_cache|^inode_cache/ {print $2; exit}' /proc/slabinfo
2902 }
2903
2904 test_76() { # bug 1443
2905         BEFORE_INODES=`num_inodes`
2906         echo "before inodes: $BEFORE_INODES"
2907         for i in `seq 1000`; do
2908                 touch $DIR/$tfile
2909                 rm -f $DIR/$tfile
2910         done
2911         AFTER_INODES=`num_inodes`
2912         echo "after inodes: $AFTER_INODES"
2913         [ $AFTER_INODES -gt $((BEFORE_INODES + 32)) ] && \
2914                 error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
2915         true
2916 }
2917 run_test 76 "destroy duplicate inodes in client inode cache ===="
2918
2919 test_77() {
2920        sh qos.sh
2921 }
2922 run_test 77 "qos test ============================================"
2923
2924 # on the LLNL clusters, runas will still pick up root's $TMP settings,
2925 # which will not be writable for the runas user, and then you get a CVS
2926 # error message with a corrupt path string (CVS bug) and panic.
2927 # We're not using much space, so just stick it in /tmp, which is safe.
2928 OLDTMPDIR=$TMPDIR
2929 OLDTMP=$TMP
2930 TMPDIR=/tmp
2931 TMP=/tmp
2932 OLDHOME=$HOME
2933 [ $RUNAS_ID -ne $UID ] && HOME=/tmp
2934
2935 test_99a() {
2936         mkdir -p $DIR/d99cvsroot
2937         chown $RUNAS_ID $DIR/d99cvsroot
2938         $RUNAS cvs -d $DIR/d99cvsroot init || error
2939 }
2940 run_test 99a "cvs init ========================================="
2941
2942 # For test_99b, we will get the same error on local filesystem--ext3.
2943 test_99b() {
2944         [ ! -d $DIR/d99cvsroot ] && test_99a
2945         cd /etc/init.d
2946         # some versions of cvs import exit(1) when asked to import links or
2947         # files they can't read.  ignore those files.
2948         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
2949                         ! -perm +4 -printf '-I %f\n')
2950         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
2951                 d99reposname vtag rtag
2952 }
2953 run_test 99b "cvs import ======================================="
2954
2955 test_99c() {
2956         [ ! -d $DIR/d99cvsroot ] && test_99b
2957         cd $DIR
2958         mkdir -p $DIR/d99reposname
2959         chown $RUNAS_ID $DIR/d99reposname
2960         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
2961 }
2962 run_test 99c "cvs checkout ====================================="
2963
2964 test_99d() {
2965         [ ! -d $DIR/d99cvsroot ] && test_99c
2966         cd $DIR/d99reposname
2967         $RUNAS touch foo99
2968         $RUNAS cvs add -m 'addmsg' foo99
2969 }
2970 run_test 99d "cvs add =========================================="
2971
2972 test_99e() {
2973         [ ! -d $DIR/d99cvsroot ] && test_99c
2974         cd $DIR/d99reposname
2975         $RUNAS cvs update
2976 }
2977 run_test 99e "cvs update ======================================="
2978
2979 test_99f() {
2980         [ ! -d $DIR/d99cvsroot ] && test_99d
2981         cd $DIR/d99reposname
2982         $RUNAS cvs commit -m 'nomsg' foo99
2983 }
2984 run_test 99f "cvs commit ======================================="
2985
2986 test_100() {
2987         netstat -tna | while read PROT SND RCV LOCAL REMOTE STAT; do
2988                 [ "$PROT" != "tcp" ] && continue
2989                 RPORT=`echo $REMOTE | cut -d: -f2`
2990                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
2991                 LPORT=`echo $LOCAL | cut -d: -f2`
2992                 if [ $LPORT -ge 1024 ]; then
2993                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
2994                         netstat -tna
2995                         error "local: $LPORT > 1024, remote: $RPORT"
2996                 fi
2997         done
2998         true
2999 }
3000 run_test 100 "check local port using privileged port ==========="
3001
3002 function get_named_value()
3003 {
3004     local tag
3005
3006     tag=$1
3007     while read ;do
3008         line=$REPLY
3009         case $line in
3010         $tag*)
3011             echo $line | sed "s/^$tag//"
3012             break
3013             ;;
3014         esac
3015     done
3016 }
3017
3018 export CACHE_MAX=`cat /proc/fs/lustre/llite/*/max_cached_mb | head -n 1`
3019 cleanup_101() {
3020         for s in $LPROC/llite/*/max_cached_mb; do
3021                 echo $CACHE_MAX > $s
3022         done
3023         trap 0
3024 }
3025
3026 test_101() {
3027         local s
3028         local discard
3029         local nreads=10000
3030         [ "$CPU" = "UML" ] && nreads=1000
3031         local cache_limit=32
3032
3033         for s in $LPROC/osc/*-osc*/rpc_stats; do
3034                 echo 0 > $s
3035         done
3036         trap cleanup_101 EXIT
3037         for s in $LPROC/llite/*; do
3038                 echo 0 > $s/read_ahead_stats
3039                 echo $cache_limit > $s/max_cached_mb
3040         done
3041
3042         #
3043         # randomly read 10000 of 64K chunks from file 3x 32MB in size
3044         #
3045         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
3046         $RANDOM_READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
3047
3048         discard=0
3049         for s in $LPROC/llite/*; do
3050                 discard=$(($discard + $(cat $s/read_ahead_stats | get_named_value 'read but discarded')))
3051         done
3052         cleanup_101
3053
3054         if [ $(($discard * 10)) -gt $nreads ] ;then
3055                 cat $LPROC/osc/*-osc*/rpc_stats
3056                 cat $LPROC/llite/*/read_ahead_stats
3057                 error "too many ($discard) discarded pages" 
3058         fi
3059         rm -f $DIR/$tfile || true
3060 }
3061 run_test 101 "check read-ahead for random reads ================"
3062
3063 test_102() {
3064         local testfile=$DIR/xattr_testfile
3065
3066         rm -f $testfile
3067         touch $testfile
3068
3069         [ "$UID" != 0 ] && echo "skipping $TESTNAME (must run as root)" && return
3070         [ -z "`grep xattr $LPROC/mdc/*-mdc-*/connect_flags`" ] && echo "skipping $TESTNAME (must have user_xattr)" && return
3071         [ -z "$(which setfattr 2>/dev/null)" ] && echo "skipping $TESTNAME (could not find setfattr)" && return
3072
3073         echo "set/get xattr..."
3074         setfattr -n trusted.name1 -v value1 $testfile || error
3075         [ "`getfattr -n trusted.name1 $testfile 2> /dev/null | \
3076         grep "trusted.name1"`" == "trusted.name1=\"value1\"" ] || error
3077  
3078         setfattr -n user.author1 -v author1 $testfile || error
3079         [ "`getfattr -n user.author1 $testfile 2> /dev/null | \
3080         grep "user.author1"`" == "user.author1=\"author1\"" ] || error
3081
3082         echo "listxattr..."
3083         setfattr -n trusted.name2 -v value2 $testfile || error
3084         setfattr -n trusted.name3 -v value3 $testfile || error
3085         [ `getfattr -d -m "^trusted" $testfile 2> /dev/null | \
3086         grep "trusted.name" | wc -l` -eq 3 ] || error
3087
3088  
3089         setfattr -n user.author2 -v author2 $testfile || error
3090         setfattr -n user.author3 -v author3 $testfile || error
3091         [ `getfattr -d -m "^user" $testfile 2> /dev/null | \
3092         grep "user" | wc -l` -eq 3 ] || error
3093
3094         echo "remove xattr..."
3095         setfattr -x trusted.name1 $testfile || error
3096         getfattr -d -m trusted $testfile 2> /dev/null | \
3097         grep "trusted.name1" && error || true
3098
3099         setfattr -x user.author1 $testfile || error
3100         getfattr -d -m user $testfile 2> /dev/null | \
3101         grep "user.author1" && error || true
3102
3103         # b10667: setting lustre special xattr be silently discarded
3104         echo "set lustre special xattr ..."
3105         setfattr -n "trusted.lov" -v "invalid value" $testfile || error
3106
3107         rm -f $testfile
3108 }
3109 run_test 102 "user xattr test =================================="
3110
3111 run_acl_subtest()
3112 {
3113     $SAVE_PWD/acl/run $SAVE_PWD/acl/$1.test
3114     return $?
3115 }
3116
3117 test_103 () {
3118     [ "$UID" != 0 ] && echo "skipping $TESTNAME (must run as root)" && return
3119     [ -z "$(grep acl $LPROC/mdc/*-mdc-*/connect_flags)" ] && echo "skipping $TESTNAME (must have acl enabled)" && return
3120     [ -z "$(which setfacl 2>/dev/null)" ] && echo "skipping $TESTNAME (could not find setfacl)" && return
3121     [ ! -z "$USING_KRB5" ] && echo "skipping $TESTNAME (could not run under gss)" && return
3122
3123     SAVE_UMASK=`umask`
3124     umask 0022
3125     cd $DIR
3126
3127     echo "performing cp ..."
3128     run_acl_subtest cp || error
3129     echo "performing getfacl-noacl..."
3130     run_acl_subtest getfacl-noacl || error
3131     echo "performing misc..."
3132     run_acl_subtest misc || error
3133 #    XXX add back permission test when we support supplementary groups.
3134 #    echo "performing permissions..."
3135 #    run_acl_subtest permissions || error
3136     echo "performing setfacl..."
3137     run_acl_subtest setfacl || error
3138
3139     # inheritance test got from HP
3140     echo "performing inheritance..."
3141     cp $SAVE_PWD/acl/make-tree . || error
3142     chmod +x make-tree || error
3143     run_acl_subtest inheritance || error
3144     rm -f make-tree
3145
3146     cd $SAVE_PWD
3147     umask $SAVE_UMASK
3148 }
3149 run_test 103 "acl test ========================================="
3150
3151 test_104() {
3152         touch $DIR/$tfile
3153         lfs df || error "lfs df failed"
3154         lfs df -ih || error "lfs df -ih failed"
3155         lfs df -h $DIR || error "lfs df -h $DIR failed"
3156         lfs df -i $DIR || error "lfs df -i $DIR failed"
3157         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
3158         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
3159         
3160         OSC=`awk '/-osc-/ {print $4}' $LPROC/devices | head -n 1`
3161         lctl --device %$OSC deactivate
3162         lfs df || error "lfs df with deactivated OSC failed"
3163         lctl --device %$OSC recover
3164         lfs df || error "lfs df with reactivated OSC failed"
3165 }
3166 run_test 104 "lfs df [-ih] [path] test ========================="
3167
3168 TMPDIR=$OLDTMPDIR
3169 TMP=$OLDTMP
3170 HOME=$OLDHOME
3171
3172 log "cleanup: ======================================================"
3173 if [ "`mount | grep ^$NAME`" ]; then
3174     rm -rf $DIR/[Rdfs][1-9]*
3175 fi
3176 if [ "$I_MOUNTED" = "yes" ]; then
3177     cleanupall -f || error "cleanup failed"
3178 fi
3179
3180
3181 echo '=========================== finished ==============================='
3182 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true