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