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