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