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