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