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