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