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