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