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