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