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