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