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