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