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