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