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