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