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