Whamcloud - gitweb
b=12560
[fs/lustre-release.git] / lustre / tests / sanityN.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6 # bug number for skipped test:  3192 9977
7 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"14b  28"}
8 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
9
10 [ "$SLOW" = "no" ] && EXCEPT="$EXCEPT 16"
11
12 # Tests that fail on uml
13 [ "$UML" = "true" ] && EXCEPT="$EXCEPT 7"
14
15 # Join file feature is not supported currently.
16 # It will be ported soon.
17 EXCEPT="$EXCEPT 22"
18
19 SRCDIR=`dirname $0`
20 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
21
22 SIZE=${SIZE:-40960}
23 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
24 CREATETEST=${CREATETEST:-createtest}
25 GETSTRIPE=${GETSTRIPE:-lfs getstripe}
26 SETSTRIPE=${SETSTRIPE:-lstripe}
27 LFS=${LFS:-lfs}
28 LCTL=${LCTL:-lctl}
29 MCREATE=${MCREATE:-mcreate}
30 OPENFILE=${OPENFILE:-openfile}
31 OPENUNLINK=${OPENUNLINK:-openunlink}
32 TOEXCL=${TOEXCL:-toexcl}
33 TRUNCATE=${TRUNCATE:-truncate}
34 export TMP=${TMP:-/tmp}
35 CHECK_GRANT=${CHECK_GRANT:-"no"}
36
37
38 if [ $UID -ne 0 ]; then
39         RUNAS_ID="$UID"
40         RUNAS=""
41 else
42         RUNAS_ID=${RUNAS_ID:-500}
43         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
44 fi
45
46 SAVE_PWD=$PWD
47
48 export NAME=${NAME:-local}
49
50 LUSTRE=${LUSTRE:-`dirname $0`/..}
51 . $LUSTRE/tests/test-framework.sh
52 init_test_env $@
53 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
54
55 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
56 FAIL_ON_ERROR=false
57
58 if [ ! -z "$USING_KRB5" ]; then
59     $RUNAS krb5_login.sh || exit 1
60 fi
61
62 cleanup() {
63         echo -n "cln.."
64         grep " $MOUNT2 " /proc/mounts && zconf_umount `hostname` $MOUNT2 ${FORCE}
65         cleanupall ${FORCE} > /dev/null || { echo "FAILed to clean up"; exit 20; }
66 }
67 CLEANUP=${CLEANUP:-:}
68
69 setup() {
70         echo -n "mnt.."
71         setupall || exit 10
72         echo "done"
73 }
74 SETUP=${SETUP:-:}
75
76 log() {
77         echo "$*"
78         lctl mark "$*" 2> /dev/null || true
79 }
80
81 trace() {
82         log "STARTING: $*"
83         strace -o $TMP/$1.strace -ttt $*
84         RC=$?
85         log "FINISHED: $*: rc $RC"
86         return 1
87 }
88 TRACE=${TRACE:-""}
89
90 LPROC=/proc/fs/lustre
91
92 run_one() {
93         if ! grep -q $DIR /proc/mounts; then
94                 $SETUP
95         fi
96         testnum=$1
97         message=$2
98         BEFORE=`date +%s`
99         log "== test $testnum: $message= `date +%H:%M:%S` ($BEFORE)"
100         export TESTNAME=test_$testnum
101         export tfile=f${testnum}
102         export tdir=d${base}
103         test_$1 || error "exit with rc=$?"
104         check_grant || error "check grant fail"
105         unset TESTNAME
106         pass "($((`date +%s` - $BEFORE))s)"
107         cd $SAVE_PWD
108         $CLEANUP
109 }
110
111 build_test_filter() {
112         [ "$ALWAYS_EXCEPT$EXCEPT$SANITYN_EXCEPT" ] && \
113             echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT $SANITYN_EXCEPT`"
114
115         for O in $ONLY; do
116             eval ONLY_${O}=true
117         done
118         for E in $EXCEPT $ALWAYS_EXCEPT $SANITY_EXCEPT; do
119             eval EXCEPT_${E}=true
120         done
121 }
122
123 _basetest() {
124     echo $*
125 }
126
127 basetest() {
128     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
129 }
130
131 build_test_filter() {
132         [ "$ALWAYS_EXCEPT$EXCEPT$SANITYN_EXCEPT" ] && \
133             echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT $SANITYN_EXCEPT`"
134
135         for O in $ONLY; do
136             eval ONLY_${O}=true
137         done
138         for E in $EXCEPT $ALWAYS_EXCEPT $SANITYN_EXCEPT; do
139             eval EXCEPT_${E}=true
140         done
141 }
142
143 _basetest() {
144     echo $*
145 }
146
147 basetest() {
148     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
149 }
150
151 sync_clients() {
152         cd $DIR1
153         sync; sleep 1; sync
154         cd $DIR2
155         sync; sleep 1; sync
156
157         cd $SAVE_PWD
158 }
159
160 check_grant() {
161         [ "$CHECK_GRANT" == "no" ] && return 0
162
163         echo -n "checking grant......"
164         cd $SAVE_PWD
165         # write some data to sync client lost_grant
166         rm -f $DIR1/${tfile}_check_grant_* 2>&1
167         for i in `seq $OSTCOUNT`; do
168                 $LFS setstripe $DIR1/${tfile}_check_grant_$i 0 $(($i -1)) 1
169                 dd if=/dev/zero of=$DIR1/${tfile}_check_grant_$i bs=4k \
170                                               count=1 > /dev/null 2>&1 
171         done
172         # sync all the data and make sure no pending data on server
173         sync_clients
174         
175         #get client grant and server grant 
176         client_grant=0
177         for d in /proc/fs/lustre/osc/*/cur_grant_bytes; do 
178                 client_grant=$(($client_grant + `cat $d`))
179         done
180         server_grant=0
181         for d in /proc/fs/lustre/obdfilter/*/tot_granted; do
182                 server_grant=$(($server_grant + `cat $d`))
183         done
184
185         # cleanup the check_grant file
186         for i in `seq $OSTCOUNT`; do
187                 rm $DIR1/${tfile}_check_grant_$i
188         done
189
190         #check whether client grant == server grant 
191         if [ $client_grant != $server_grant ]; then
192                 echo "failed: client:${client_grant} server: ${server_grant}"
193                 return 1
194         else
195                 echo "pass"
196         fi
197 }
198
199 run_test() {
200          export base=`basetest $1`
201          if [ "$ONLY" ]; then
202                  testname=ONLY_$1
203                  if [ ${!testname}x != x ]; then
204                         run_one $1 "$2"
205                         return $?
206                  fi
207                  testname=ONLY_$base
208                  if [ ${!testname}x != x ]; then
209                          run_one $1 "$2"
210                          return $?
211                  fi
212                  echo -n "."
213                  return 0
214         fi
215         testname=EXCEPT_$1
216         if [ ${!testname}x != x ]; then
217                  echo "skipping excluded test $1"
218                  return 0
219         fi
220         testname=EXCEPT_$base
221         if [ ${!testname}x != x ]; then
222                  echo "skipping excluded test $1 (base $base)"
223                  return 0
224         fi
225         run_one $1 "$2"
226         return $?
227 }
228
229 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
230
231 error () {
232         sysctl -w lustre.fail_loc=0 2> /dev/null || true
233         log "$0: FAIL: $TESTNAME $@"
234         $LCTL dk $TMP/lustre-log-$TESTNAME.log
235         if [ "$SANITYLOG" ]; then
236                 echo "$0: FAIL: $TESTNAME $@" >> $SANITYLOG
237         else
238                 exit 1
239         fi
240 }
241
242 pass() {
243         echo PASS $@
244 }
245
246 mounted_lustre_filesystems() {
247         awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
248 }
249 MOUNTED="`mounted_lustre_filesystems`"
250 if [ -z "$MOUNTED" ]; then
251     formatall
252     setupall
253     mount_client $MOUNT2
254     MOUNTED="`mounted_lustre_filesystems`"
255     [ -z "$MOUNTED" ] && error "NAME=$NAME not mounted"
256     I_MOUNTED=yes
257 fi
258 export MOUNT1=`mounted_lustre_filesystems | head -n 1`
259 [ -z "$MOUNT1" ] && error "NAME=$NAME not mounted once"
260 export MOUNT2=`mounted_lustre_filesystems | tail -n 1`
261 [ "$MOUNT1" = "$MOUNT2" ] && error "NAME=$NAME not mounted twice"
262 [ `mounted_lustre_filesystems | wc -l` -ne 2 ] && \
263         error "NAME=$NAME mounted more than twice"
264
265 export DIR1=${DIR1:-$MOUNT1}
266 export DIR2=${DIR2:-$MOUNT2}
267 [ -z "`echo $DIR1 | grep $MOUNT1`" ] && echo "$DIR1 not in $MOUNT1" && exit 96
268 [ -z "`echo $DIR2 | grep $MOUNT2`" ] && echo "$DIR2 not in $MOUNT2" && exit 95
269
270 LPROC=/proc/fs/lustre
271 LOVNAME=`cat $LPROC/llite/*/lov/common_name | tail -n 1`
272 OSTCOUNT=`cat $LPROC/lov/$LOVNAME/numobd`
273
274 rm -rf $DIR1/[df][0-9]* $DIR1/lnk
275
276 build_test_filter
277
278 test_1a() {
279         touch $DIR1/f1
280         [ -f $DIR2/f1 ] || error
281 }
282 run_test 1a "check create on 2 mtpt's =========================="
283
284 test_1b() {
285         chmod 777 $DIR2/f1
286         $CHECKSTAT -t file -p 0777 $DIR1/f1 || error
287         chmod a-x $DIR2/f1
288 }
289 run_test 1b "check attribute updates on 2 mtpt's ==============="
290
291 test_1c() {
292         $CHECKSTAT -t file -p 0666 $DIR1/f1 || error
293 }
294 run_test 1c "check after remount attribute updates on 2 mtpt's ="
295
296 test_1d() {
297         rm $DIR2/f1
298         $CHECKSTAT -a $DIR1/f1 || error
299 }
300 run_test 1d "unlink on one mountpoint removes file on other ===="
301
302 test_2a() {
303         touch $DIR1/f2a
304         ls -l $DIR2/f2a
305         chmod 777 $DIR2/f2a
306         $CHECKSTAT -t file -p 0777 $DIR1/f2a || error
307 }
308 run_test 2a "check cached attribute updates on 2 mtpt's ========"
309
310 test_2b() {
311         touch $DIR1/f2b
312         ls -l $DIR2/f2b
313         chmod 777 $DIR1/f2b
314         $CHECKSTAT -t file -p 0777 $DIR2/f2b || error
315 }
316 run_test 2b "check cached attribute updates on 2 mtpt's ========"
317
318 # NEED TO SAVE ROOT DIR MODE
319 test_2c() {
320         chmod 777 $DIR1
321         $CHECKSTAT -t dir -p 0777 $DIR2 || error
322 }
323 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
324
325 test_2d() {
326         chmod 755 $DIR1
327         $CHECKSTAT -t dir -p 0755 $DIR2 || error
328 }
329 run_test 2d "check cached attribute updates on 2 mtpt's root ==="
330
331 test_2e() {
332         chmod 755 $DIR1
333         ls -l $DIR1
334         ls -l $DIR2
335         chmod 777 $DIR1
336         $RUNAS dd if=/dev/zero of=$DIR2/$tfile count=1 || error
337 }
338 run_test 2e "check chmod on root is propagated to others"
339
340 test_3() {
341         ( cd $DIR1 ; ln -s this/is/good lnk )
342         [ "this/is/good" = "`perl -e 'print readlink("'$DIR2/lnk'");'`" ] || \
343                 error
344 }
345 run_test 3 "symlink on one mtpt, readlink on another ==========="
346
347 test_4() {
348         multifstat $DIR1/f4 $DIR2/f4
349 }
350 run_test 4 "fstat validation on multiple mount points =========="
351
352 test_5() {
353         mcreate $DIR1/f5
354         truncate $DIR2/f5 100
355         $CHECKSTAT -t file -s 100 $DIR1/f5 || error
356         rm $DIR1/f5
357 }
358 run_test 5 "create a file on one mount, truncate it on the other"
359
360 test_6() {
361         openunlink $DIR1/$tfile $DIR2/$tfile || \
362                 error "openunlink $DIR1/$tfile $DIR2/$tfile"
363 }
364 run_test 6 "remove of open file on other node =================="
365
366 test_7() {
367         opendirunlink $DIR1/$tdir $DIR2/$tdir || \
368                 error "opendirunlink $DIR1/$tdir $DIR2/$tdir"
369 }
370 run_test 7 "remove of open directory on other node ============="
371
372 test_8() {
373         opendevunlink $DIR1/$tfile $DIR2/$tfile || \
374                 error "opendevunlink $DIR1/$tfile $DIR2/$tfile"
375 }
376 run_test 8 "remove of open special file on other node =========="
377
378 test_9() {
379         MTPT=1
380         > $DIR2/f9
381         for C in a b c d e f g h i j k l; do
382                 DIR=`eval echo \\$DIR$MTPT`
383                 echo -n $C >> $DIR/f9
384                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
385         done
386         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
387                 error "`od -a $DIR1/f9` != abcdefghijkl"
388 }
389 run_test 9 "append of file with sub-page size on multiple mounts"
390
391 test_10a() {
392         MTPT=1
393         OFFSET=0
394         > $DIR2/f10
395         for C in a b c d e f g h i j k l; do
396                 DIR=`eval echo \\$DIR$MTPT`
397                 echo -n $C | dd of=$DIR/f10 bs=1 seek=$OFFSET count=1
398                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
399                 OFFSET=`expr $OFFSET + 1`
400         done
401         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
402                 error "`od -a $DIR1/f10` != abcdefghijkl"
403 }
404 run_test 10a "write of file with sub-page size on multiple mounts "
405
406 test_10b() {
407         yes "R" | dd of=$DIR1/f10b bs=3k count=1 || error "dd $DIR1"
408
409         truncate $DIR1/f10b 4096 || error "truncate 4096"
410
411         dd if=$DIR2/f10b of=$TMP/f10b-lustre bs=4k count=1 || error "dd $DIR2"
412
413         # create a test file locally to compare
414         yes "R" | dd of=$TMP/f10b bs=3k count=1 || error "dd random"
415         truncate $TMP/f10b 4096 || error "truncate 4096"
416         cmp $TMP/f10b $TMP/f10b-lustre || error "file miscompare"
417         rm $TMP/f10b $TMP/f10b-lustre
418 }
419 run_test 10b "write of file with sub-page size on multiple mounts "
420
421 test_11() {
422         mkdir $DIR1/d11
423         multiop $DIR1/d11/f O_c &
424         MULTIPID=$!
425         usleep 200
426         cp -p /bin/ls $DIR1/d11/f
427         $DIR2/d11/f
428         RC=$?
429         kill -USR1 $MULTIPID
430         wait $MULTIPID || error
431         [ $RC -eq 0 ] && error || true
432 }
433 run_test 11 "execution of file opened for write should return error ===="
434
435 test_12() {
436        sh lockorder.sh
437 }
438 run_test 12 "test lock ordering (link, stat, unlink) ==========="
439
440 test_13() {     # bug 2451 - directory coherency
441        rm -rf $DIR1/d13
442        mkdir $DIR1/d13 || error
443        cd $DIR1/d13 || error
444        ls
445        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
446        ls
447        rm -f $DIR2/d13/f13 || error
448        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
449        # need to run it twice
450        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
451        ls
452        rm -f $DIR2/d13/f13 || error
453        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
454 }
455 run_test 13 "test directory page revocation ===================="
456
457 test_14() {
458         mkdir $DIR1/d14
459         cp -p /bin/ls $DIR1/d14/ls
460         exec 100>> $DIR1/d14/ls
461         $DIR2/d14/ls && error || true
462         exec 100<&-
463 }
464 run_test 14 "execution of file open for write returns -ETXTBSY ="
465
466 test_14a() {
467         mkdir -p $DIR1/d14
468         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
469         $DIR1/d14/multiop $TMP/test14.junk O_c &
470         MULTIPID=$!
471         sleep 1
472         multiop $DIR2/d14/multiop Oc && error "expected error, got success"
473         kill -USR1 $MULTIPID || return 2
474         wait $MULTIPID || return 3
475         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
476 }
477 run_test 14a "open(RDWR) of executing file returns -ETXTBSY ===="
478
479 test_14b() { # bug 3192, 7040
480         mkdir -p $DIR1/d14
481         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
482         $DIR1/d14/multiop $TMP/test14.junk O_c &
483         MULTIPID=$!
484         sleep 1
485         truncate $DIR2/d14/multiop 0 && kill -9 $MULTIPID && \
486                 error "expected truncate error, got success"
487         kill -USR1 $MULTIPID || return 2
488         wait $MULTIPID || return 3
489         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
490         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
491 }
492 run_test 14b "truncate of executing file returns -ETXTBSY ======"
493
494 test_14c() { # bug 3430, 7040
495         mkdir -p $DIR1/d14
496         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
497         $DIR1/d14/multiop $TMP/test14.junk O_c &
498         MULTIPID=$!
499         sleep 1
500         cp /etc/hosts $DIR2/d14/multiop && error "expected error, got success"
501         kill -USR1 $MULTIPID || return 2
502         wait $MULTIPID || return 3
503         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
504         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
505 }
506 run_test 14c "open(O_TRUNC) of executing file return -ETXTBSY =="
507
508 test_14d() { # bug 10921
509         mkdir -p $DIR1/d14
510         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
511         $DIR1/d14/multiop $TMP/test14.junk O_c &
512         MULTIPID=$!
513         sleep 1
514         log chmod
515         chmod 600 $DIR1/d14/multiop || error "chmod failed"
516         kill -USR1 $MULTIPID || return 2
517         wait $MULTIPID || return 3
518         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
519         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
520 }
521 run_test 14d "chmod of executing file is still possible ========"
522
523 test_15() {     # bug 974 - ENOSPC
524         echo "PATH=$PATH"
525         sh oos2.sh $MOUNT1 $MOUNT2
526         grant_error=`dmesg | grep "> available"`
527         [ -z "$grant_error" ] || error "$grant_error"
528 }
529 run_test 15 "test out-of-space with multiple writers ==========="
530
531 test_16() {
532         rm -f $MOUNT1/fsxfile
533         lfs setstripe $MOUNT1/fsxfile 0 -1 -1 # b=10919
534         fsx -c 50 -p 100 -N 2500 -l $((SIZE * 256)) -S 0 $MOUNT1/fsxfile $MOUNT2/fsxfile
535 }
536 run_test 16 "2500 iterations of dual-mount fsx ================="
537
538 test_17() { # bug 3513, 3667
539         [ ! -d /proc/fs/lustre/ost ] && skip "remote OST, skipping OST-only test" && return
540
541         cp /etc/termcap $DIR1/f17
542         cancel_lru_locks osc > /dev/null
543         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
544         sysctl -w lustre.fail_loc=0x8000030a
545         ls -ls $DIR1/f17 | awk '{ print $1,$6 }' > $DIR1/f17-1 & \
546         ls -ls $DIR2/f17 | awk '{ print $1,$6 }' > $DIR2/f17-2
547         wait
548         diff -u $DIR1/f17-1 $DIR2/f17-2 || error "files are different"
549 }
550 run_test 17 "resource creation/LVB creation race ==============="
551
552 test_18() {
553         ./mmap_sanity -d $MOUNT1 -m $MOUNT2
554         sync; sleep 1; sync
555 }
556 run_test 18 "mmap sanity check ================================="
557
558 test_19() { # bug3811
559         [ -d /proc/fs/lustre/obdfilter ] || return 0
560
561         MAX=`cat /proc/fs/lustre/obdfilter/*/readcache_max_filesize | head -n 1`
562         for O in /proc/fs/lustre/obdfilter/*OST*; do
563                 echo 4096 > $O/readcache_max_filesize
564         done
565         dd if=/dev/urandom of=$TMP/f19b bs=512k count=32
566         SUM=`cksum $TMP/f19b | cut -d" " -f 1,2`
567         cp $TMP/f19b $DIR1/f19b
568         for i in `seq 1 20`; do
569                 [ $((i % 5)) -eq 0 ] && log "test_18 loop $i"
570                 cancel_lru_locks osc > /dev/null
571                 cksum $DIR1/f19b | cut -d" " -f 1,2 > $TMP/sum1 & \
572                 cksum $DIR2/f19b | cut -d" " -f 1,2 > $TMP/sum2
573                 wait
574                 [ "`cat $TMP/sum1`" = "$SUM" ] || \
575                         error "$DIR1/f19b `cat $TMP/sum1` != $SUM"
576                 [ "`cat $TMP/sum2`" = "$SUM" ] || \
577                         error "$DIR2/f19b `cat $TMP/sum2` != $SUM"
578         done
579         for O in /proc/fs/lustre/obdfilter/*OST*; do
580                 echo $MAX > $O/readcache_max_filesize
581         done
582         rm $DIR1/f19b
583 }
584 #run_test 19 "test concurrent uncached read races ==============="
585
586 test_20() {
587         mkdir $DIR1/d20
588         cancel_lru_locks osc
589         CNT=$((`cat /proc/fs/lustre/llite/*/dump_page_cache | wc -l`))
590         multiop $DIR1/f20 Ow8190c
591         multiop $DIR2/f20 Oz8194w8190c
592         multiop $DIR1/f20 Oz0r8190c
593         cancel_lru_locks osc
594         CNTD=$((`cat /proc/fs/lustre/llite/*/dump_page_cache | wc -l` - $CNT))
595         [ $CNTD -gt 0 ] && \
596             error $CNTD" page left in cache after lock cancel" || true
597 }
598 run_test 20 "test extra readahead page left in cache ===="
599
600 cleanup_21() {
601         trap 0
602         umount $DIR1/d21
603 }
604
605 test_21() { # Bug 5907
606         mkdir $DIR1/d21
607         mount /etc $DIR1/d21 --bind || error "mount failed" # Poor man's mount.
608         trap cleanup_21 EXIT
609         rmdir -v $DIR1/d21 && error "Removed mounted directory"
610         rmdir -v $DIR2/d21 && echo "Removed mounted directory from another mountpoint, needs to be fixed"
611         test -d $DIR1/d21 || error "Mounted directory disappeared"
612         cleanup_21
613         test -d $DIR2/d21 || test -d $DIR1/d21 && error "Removed dir still visible after umount"
614         true
615 }
616 run_test 21 " Try to remove mountpoint on another dir ===="
617
618 JOIN=${JOIN:-"lfs join"}
619
620 test_22() { # Bug 9926
621         mkdir $DIR1/d21
622         dd if=/dev/urandom of=$DIR1/d21/128k bs=1024 count=128
623         cp -p $DIR1/d21/128k $DIR1/d21/f_head
624         for ((i=0;i<10;i++)); do
625                 cp -p $DIR1/d21/128k $DIR1/d21/f_tail
626                 $JOIN $DIR1/d21/f_head $DIR1/d21/f_tail || error "join error"
627                 $CHECKSTAT -a $DIR1/d21/f_tail || error "tail file exist after join"
628         done
629         echo aaaaaaaaaaa >> $DIR1/d21/no_joined
630
631         mv $DIR2/d21/f_head $DIR2/
632         munlink $DIR2/f_head || error "unlink joined file error"
633         cat $DIR2/d21/no_joined || error "cat error"
634         rm -rf $DIR2/d21/no_joined || error "unlink normal file error"
635 }
636 run_test 22 " After joining in one dir,  open/close unlink file in anther dir" 
637
638 test_23() { # Bug 5972
639         echo "others should see updated atime while another read" > $DIR1/f23
640         
641         # clear the lock(mode: LCK_PW) gotten from creating operation
642         cancel_lru_locks osc
643         
644         time1=`date +%s`        
645         sleep 2
646         
647         multiop $DIR1/f23 or20_c &
648         MULTIPID=$!
649
650         sleep 2
651         time2=`stat -c "%X" $DIR2/f23`
652
653         if (( $time2 <= $time1 )); then
654                 kill -USR1 $MULTIPID
655                 error "atime doesn't update among nodes"
656         fi
657
658         kill -USR1 $MULTIPID || return 1
659         rm -f $DIR1/f23 || error "rm -f $DIR1/f23 failed"
660         true
661 }
662 run_test 23 " others should see updated atime while another read===="
663
664 test_24() {
665         touch $DIR1/$tfile
666         lfs df || error "lfs df failed"
667         lfs df -ih || error "lfs df -ih failed"
668         lfs df -h $DIR1 || error "lfs df -h $DIR1 failed"
669         lfs df -i $DIR2 || error "lfs df -i $DIR2 failed"
670         lfs df $DIR1/$tfile || error "lfs df $DIR1/$tfile failed"
671         lfs df -ih $DIR2/$tfile || error "lfs df -ih $DIR2/$tfile failed"
672         
673         OSC=`lctl dl | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
674 #       OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
675         lctl --device %$OSC deactivate
676         lfs df -i || error "lfs df -i with deactivated OSC failed"
677         lctl --device %$OSC recover
678         lfs df || error "lfs df with reactivated OSC failed"
679 }
680 run_test 24 "lfs df [-ih] [path] test ========================="
681
682 test_25() {
683         [ `cat $LPROC/mdc/*-mdc-*/connect_flags | grep -c acl` -lt 2 ] && \
684             skip "must have acl, skipping" && return
685
686         mkdir $DIR1/$tdir || error "mkdir $DIR1/$tdir"
687         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
688         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
689
690         $RUNAS checkstat $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
691         setfacl -m u:$RUNAS_ID:--- $DIR1/$tdir || error "setfacl $DIR2/$tdir #1"
692         $RUNAS checkstat $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
693         setfacl -m u:$RUNAS_ID:r-x $DIR1/$tdir || error "setfacl $DIR2/$tdir #2"
694         $RUNAS checkstat $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
695         setfacl -m u:$RUNAS_ID:--- $DIR1/$tdir || error "setfacl $DIR2/$tdir #3"
696         $RUNAS checkstat $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
697         setfacl -x u:$RUNAS_ID: $DIR1/$tdir || error "setfacl $DIR2/$tdir #4"
698         $RUNAS checkstat $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
699
700         rm -rf $DIR1/$tdir
701 }
702 run_test 25 "change ACL on one mountpoint be seen on another ==="
703
704 test_26a() {
705         utime $DIR1/f26a -s $DIR2/f26a || error
706 }
707 run_test 26a "allow mtime to get older"
708
709 test_26b() {
710         touch $DIR1/$tfile
711         sleep 1
712         echo "aaa" >> $DIR1/$tfile
713         sleep 1
714         chmod a+x $DIR2/$tfile
715         mt1=`stat -c %Y $DIR1/$tfile`
716         mt2=`stat -c %Y $DIR2/$tfile`
717         
718         if [ x"$mt1" != x"$mt2" ]; then 
719                 error "not equal mtime, client1: "$mt1", client2: "$mt2"."
720         fi
721 }
722 run_test 26b "sync mtime between ost and mds"
723
724 test_27() {
725         cancel_lru_locks osc
726         lctl clear
727         dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
728         DD2_PID=$!
729         usleep 50
730         log "dd 1 started"
731         
732         dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
733         DD1_PID=$!
734         log "dd 2 started"
735         
736         sleep 1
737         dd if=/dev/zero of=$DIR1/$tfile bs=8k conv=notrunc count=1 seek=0
738         log "dd 3 finished"
739         echo > $LPROC/ldlm/dump_namespaces
740         wait $DD1_PID $DD2_PID
741         [ $? -ne 0 ] && lctl dk $TMP/debug || true
742 }
743 run_test 27 "align non-overlapping extent locks from request ==="
744
745 test_28() { # bug 9977
746         ECHO_UUID="ECHO_osc1_UUID"
747         tOST=`$LCTL dl | | awk '/-osc-|OSC.*MNT/ { print $4 }' | head -1`
748
749         lfs setstripe $DIR1/$tfile 1048576 0 2
750         tOBJID=`lfs getstripe $DIR1/$tfile |grep "^[[:space:]]\+1" |awk '{print $2}'`
751         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
752
753         $LCTL <<-EOF
754                 newdev
755                 attach echo_client ECHO_osc1 $ECHO_UUID
756                 setup $tOST
757         EOF
758
759         tECHOID=`$LCTL dl | grep $ECHO_UUID | awk '{print $1}'`
760         $LCTL --device $tECHOID destroy "${tOBJID}:0"
761     
762         $LCTL <<-EOF
763                 cfg_device ECHO_osc1
764                 cleanup
765                 detach
766         EOF
767
768         # reading of 1st stripe should pass
769         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
770         # reading of 2nd stripe should fail (this stripe was destroyed)
771         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 && error
772
773         # now, recreating test file
774         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error
775         # reading of 1st stripe should pass
776         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
777         # reading of 2nd stripe should pass
778         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 || error
779 }
780 run_test 28 "read/write/truncate file with lost stripes"
781
782 test_29() { # bug 10999
783         touch $DIR1/$tfile
784         #define OBD_FAIL_LDLM_GLIMPSE  0x30f
785         sysctl -w lustre.fail_loc=0x8000030f
786         ls -l $DIR2/$tfile &
787         usleep 500
788         dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1
789         wait
790 }
791 #bug 11549 - permanently turn test off in b1_5
792 #run_test 29 "lock put race between glimpse and enqueue ========="
793
794 test_30() { #bug #11110
795     rm -rf $DIR1/$tdir
796     mkdir -p $DIR1/$tdir
797     cp -f /bin/bash $DIR1/$tdir/bash
798     /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash; cp /bin/bash $DIR2/$tdir' &
799     err=$($DIR1/$tdir/bash -c 'sleep 2; openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?')
800     wait
801     [ $err -ne 116 ] && error "return code ($err) != -ESTALE" && return
802     true
803 }
804
805 run_test 30 "recreate file race ========="
806
807 log "cleanup: ======================================================"
808 rm -rf $DIR1/[df][0-9]* $DIR1/lnk || true
809 if [ "$I_MOUNTED" = "yes" ]; then
810     cleanup
811 fi
812
813 echo '=========================== finished ==============================='
814 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 || true
815 echo "$0: completed"