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