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