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