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