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