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