Whamcloud - gitweb
b=19415
[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_24() {
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 24 "lfs df [-ih] [path] test ========================="
469
470 test_25() {
471         [ `lctl get_param -n mdc.*-mdc-*.connect_flags | grep -c acl` -lt 2 ] && \
472             skip "must have acl, skipping" && return
473
474         mkdir -p $DIR1/$tdir
475         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
476         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
477
478         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
479         setfacl -m u:$RUNAS_ID:--- $DIR1/$tdir || error "setfacl $DIR2/$tdir #1"
480         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
481         setfacl -m u:$RUNAS_ID:r-x $DIR1/$tdir || error "setfacl $DIR2/$tdir #2"
482         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
483         setfacl -m u:$RUNAS_ID:--- $DIR1/$tdir || error "setfacl $DIR2/$tdir #3"
484         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
485         setfacl -x u:$RUNAS_ID: $DIR1/$tdir || error "setfacl $DIR2/$tdir #4"
486         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
487
488         rm -rf $DIR1/$tdir
489 }
490 run_test 25 "change ACL on one mountpoint be seen on another ==="
491
492 test_26a() {
493         utime $DIR1/f26a -s $DIR2/f26a || error
494 }
495 run_test 26a "allow mtime to get older"
496
497 test_26b() {
498         touch $DIR1/$tfile
499         sleep 1
500         echo "aaa" >> $DIR1/$tfile
501         sleep 1
502         chmod a+x $DIR2/$tfile
503         mt1=`stat -c %Y $DIR1/$tfile`
504         mt2=`stat -c %Y $DIR2/$tfile`
505
506         if [ x"$mt1" != x"$mt2" ]; then
507                 error "not equal mtime, client1: "$mt1", client2: "$mt2"."
508         fi
509 }
510 run_test 26b "sync mtime between ost and mds"
511
512 test_27() {
513         cancel_lru_locks osc
514         lctl clear
515         dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
516         DD2_PID=$!
517         sleep 0.050s
518         log "dd 1 started"
519
520         dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
521         DD1_PID=$!
522         log "dd 2 started"
523
524         sleep 1
525         dd if=/dev/zero of=$DIR1/$tfile bs=8k conv=notrunc count=1 seek=0
526         log "dd 3 finished"
527         lctl set_param -n ldlm.dump_namespaces ""
528         wait $DD1_PID $DD2_PID
529         [ $? -ne 0 ] && lctl dk $TMP/debug || true
530 }
531 run_test 27 "align non-overlapping extent locks from request ==="
532
533 test_28() { # bug 9977
534         ostID=`$LCTL dl | awk '/-osc-|OSC.*MNT/ { ost++; if (ost == 2) { print $1 } }'`
535
536         lfs setstripe $DIR1/$tfile -s 1048576 -i 0 -c 2
537         tOBJID=`lfs getstripe $DIR1/$tfile | awk '/^[[:space:]]+1/ {print $2}'`
538         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
539
540         $LCTL --device $ostID destroy "${tOBJID}"
541
542         # reading of 1st stripe should pass
543         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
544         # reading of 2nd stripe should fail (this stripe was destroyed)
545         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 && error
546
547         # now, recreating test file
548         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error
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 pass
552         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 || error
553 }
554 run_test 28 "read/write/truncate file with lost stripes"
555
556 test_29() { # bug 10999
557         touch $DIR1/$tfile
558         #define OBD_FAIL_LDLM_GLIMPSE  0x30f
559         lctl set_param fail_loc=0x8000030f
560         ls -l $DIR2/$tfile &
561         sleep 0.500s
562         dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1
563         wait
564 }
565 #bug 11549 - permanently turn test off in b1_5
566 run_test 29 "lock put race between glimpse and enqueue ========="
567
568 test_30() { #bug #11110
569     mkdir -p $DIR1/$tdir
570     cp -f /bin/bash $DIR1/$tdir/bash
571     /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash; cp /bin/bash $DIR2/$tdir' &
572     err=$($DIR1/$tdir/bash -c 'sleep 2; openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?')
573     wait
574     [ $err -ne 116 ] && error_ignore 12900 "return code ($err) != -ESTALE" && return
575     true
576 }
577
578 run_test 30 "recreate file race ========="
579
580 test_31a() {
581         mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
582         writes=`LANG=C dd if=/dev/zero of=$DIR/$tdir/$tfile count=1 2>&1 |
583                 awk 'BEGIN { FS="+" } /out/ {print $1}'`
584         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
585         lctl set_param fail_loc=0x314
586         reads=`LANG=C dd if=$DIR2/$tdir/$tfile of=/dev/null 2>&1 |
587                awk 'BEGIN { FS="+" } /in/ {print $1}'`
588         [ $reads -eq $writes ] || error "read" $reads "blocks, must be" $writes
589 }
590 run_test 31a "voluntary cancel / blocking ast race=============="
591
592 test_31b() {
593         remote_ost || { skip "local OST" && return 0; }
594         remote_ost_nodsh && skip "remote OST w/o dsh" && return 0
595         mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
596         lfs setstripe $DIR/$tdir/$tfile -i 0 -c 1
597         cp /etc/hosts $DIR/$tdir/$tfile
598         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
599         lctl set_param fail_loc=0x314
600         #define OBD_FAIL_LDLM_OST_FAIL_RACE      0x316
601         do_facet ost1 lctl set_param fail_loc=0x316
602         # Don't crash kernel
603         cat $DIR2/$tdir/$tfile > /dev/null 2>&1
604         lctl set_param fail_loc=0
605         do_facet ost1 lctl set_param fail_loc=0
606 }
607 run_test 31b "voluntary OST cancel / blocking ast race=============="
608
609 # enable/disable lockless truncate feature, depending on the arg 0/1
610 enable_lockless_truncate() {
611         lctl set_param -n llite.*.lockless_truncate $1
612 }
613
614 test_32a() { # bug 11270
615         local p="$TMP/sanityN-$TESTNAME.parameters"
616         save_lustre_params $HOSTNAME llite.*.lockless_truncate > $p
617         rm -f $DIR1/$tfile
618         cancel_lru_locks osc
619         enable_lockless_truncate 1
620         lfs setstripe -c -1 -s 1m $DIR1/$tfile
621         dd if=/dev/zero of=$DIR1/$tfile count=10 bs=1M > /dev/null 2>&1
622         clear_llite_stats
623
624         log "checking cached lockless truncate"
625         $TRUNCATE $DIR1/$tfile 8000000
626         $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
627         [ $(calc_llite_stats lockless_truncate) -eq 0 ] ||
628                 error "lockless truncate doesn't use cached locks"
629
630         log "checking not cached lockless truncate"
631         $TRUNCATE $DIR2/$tfile 5000000
632         $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
633         [ $(calc_llite_stats lockless_truncate) -ne 0 ] ||
634                 error "not cached trancate isn't lockless"
635
636         log "disabled lockless truncate"
637         enable_lockless_truncate 0
638         clear_llite_stats
639         $TRUNCATE $DIR2/$tfile 3000000
640         $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
641         [ $(calc_llite_stats lockless_truncate) -eq 0 ] ||
642                 error "lockless truncate disabling failed"
643         rm $DIR1/$tfile
644         # restore lockless_truncate default values
645         restore_lustre_params < $p
646         rm -f $p
647 }
648 run_test 32a "lockless truncate"
649
650 test_32b() { # bug 11270
651         remote_ost_nodsh && skip "remote OST with nodsh" && return
652
653         local node
654         local p="$TMP/sanityN-$TESTNAME.parameters"
655         save_lustre_params $HOSTNAME "llite.*.contention_seconds" > $p
656         for node in $(osts_nodes); do
657                 save_lustre_params $node "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
658                 save_lustre_params $node "ldlm.namespaces.filter-*.contended_locks" >> $p
659                 save_lustre_params $node "ldlm.namespaces.filter-*.contention_seconds" >> $p
660         done
661         clear_llite_stats
662         # agressive lockless i/o settings
663         for node in $(osts_nodes); do
664                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 2000000; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 0; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 60'
665         done
666         lctl set_param -n llite.*.contention_seconds 60
667         for i in $(seq 5); do
668                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
669                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
670         done
671         [ $(calc_llite_stats lockless_write_bytes) -ne 0 ] || error "lockless i/o was not triggered"
672         # disable lockless i/o (it is disabled by default)
673         for node in $(osts_nodes); do
674                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 0; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 32; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 0'
675         done
676         # set contention_seconds to 0 at client too, otherwise Lustre still
677         # remembers lock contention
678         lctl set_param -n llite.*.contention_seconds 0
679         clear_llite_stats
680         for i in $(seq 5); do
681                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
682                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
683         done
684         [ $(calc_llite_stats lockless_write_bytes) -eq 0 ] ||
685                 error "lockless i/o works when disabled"
686         rm -f $DIR1/$tfile
687         restore_lustre_params <$p
688         rm -f $p
689 }
690 run_test 32b "lockless i/o"
691
692 test_33() { #16129
693         local OPER
694         local lock_in
695         local lock_out
696         for OPER in notimeout timeout ; do
697                 rm $DIR1/$tfile 2>/dev/null
698                 lock_in=$(do_nodes $(osts_nodes) "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
699                 if [ $OPER == "timeout" ] ; then
700                         for j in `seq $OSTCOUNT`; do
701                                 #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT    0x511
702                                 do_facet ost$j lctl set_param fail_loc=0x511
703                         done
704                         echo lock should expire
705                 else
706                         for j in `seq $OSTCOUNT`; do
707                                 #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT  0x512
708                                 do_facet ost$j lctl set_param fail_loc=0x512
709                         done
710                         echo lock should not expire
711                 fi
712                 echo writing on client1
713                 dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
714                 sync &
715                 echo reading on client2
716                 dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
717                 # wait for a lock timeout
718                 sleep 4
719                 lock_out=$(do_nodes $(osts_nodes) "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
720                 if [ $OPER == "timeout" ] ; then
721                         if [ $lock_in == $lock_out ]; then
722                                 error "no lock timeout happened"
723                         else
724                                 echo "success"
725                         fi
726                 else
727                         if [ $lock_in != $lock_out ]; then
728                                 error "lock timeout happened"
729                         else
730                                 echo "success"
731                         fi
732                 fi
733         done
734 }
735 run_test 33 "no lock timeout under IO"
736
737 test_35() { # bug 17645
738         local generation=[]
739         local count=0
740         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
741             g=$(awk '/generation/{print $2}' $imp/import)
742             generation[count]=$g
743             let count=count+1
744         done
745
746         mkdir -p $MOUNT1/$tfile
747         cancel_lru_locks mdc
748
749         # Let's initiate -EINTR situation by setting fail_loc and take
750         # write lock on same file from same client. This will not cause
751         # bl_ast yet as lock is already in local cache.
752 #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
753         do_facet client "lctl set_param fail_loc=0x80000317"
754         local timeout=`do_facet mds lctl get_param  -n timeout`
755         let timeout=timeout*3
756         local nr=0
757         while test $nr -lt 10; do
758                 log "Race attempt $nr"
759                 local blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
760                 test "x$blk1" = "x" && blk1=0
761                 createmany -o $MOUNT2/$tfile/a 4000 &
762                 pid1=$!
763                 sleep 1
764
765                 # Let's make conflict and bl_ast
766                 ls -la $MOUNT1/$tfile > /dev/null &
767                 pid2=$!
768
769                 log "Wait for $pid1 $pid2 for $timeout sec..."
770                 sleep $timeout
771                 kill -9 $pid1 $pid2 > /dev/null 2>&1
772                 wait
773                 local blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
774                 test "x$blk2" = "x" && blk2=0
775                 test $blk2 -gt $blk1 && break
776                 rm -fr $MOUNT1/$tfile/*
777                 cancel_lru_locks mdc
778                 let nr=nr+1
779         done
780         do_facet client "lctl set_param fail_loc=0x0"
781         df -h $MOUNT1 $MOUNT2
782         count=0
783         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
784             g=$(awk '/generation/{print $2}' $imp/import)
785             if ! test "$g" -eq "${generation[count]}"; then
786                 error "Eviction happened on import $(basename $imp)"
787             fi
788             let count=count+1
789         done
790 }
791 run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
792
793 test_36() { #bug 16417
794     local SIZE
795     local SIZE_B
796     local i
797
798     mkdir -p $DIR1/$tdir
799     $LFS setstripe -c -1 $DIR1/$tdir
800     i=0
801     SIZE=50
802     let SIZE_B=SIZE*1024*1024
803
804     while [ $i -le 10 ]; do
805         lctl mark "start test"
806         local before=$($LFS df | awk '{if ($1 ~/^filesystem/) {print $5; exit} }')
807         dd if=/dev/zero of=$DIR1/$tdir/file000 bs=1M count=$SIZE
808         sync
809         sleep 1
810         local after_dd=$($LFS df | awk '{if ($1 ~/^filesystem/) {print $5; exit} }')
811         multiop_bg_pause $DIR2/$tdir/file000 O_r${SIZE_B}c || return 3
812         read_pid=$!
813         rm -f $DIR1/$tdir/file000
814         kill -USR1 $read_pid
815         wait $read_pid
816         sleep 1
817         local after=$($LFS df | awk '{if ($1 ~/^filesystem/) {print $5; exit} }')
818         echo "*** cycle($i) *** before($before):after_dd($after_dd):after($after)"
819         # this free space! not used
820         if [ $after_dd -ge $after ]; then
821             error "space leaked"
822             return 1;
823         fi
824         let i=i+1
825     done
826 }
827 run_test 36 "handle ESTALE/open-unlink corectly"
828
829 test_37() { # bug 18695
830         mkdir -p $DIR1/$tdir
831         multiop_bg_pause $DIR1/$tdir D_c || return 1
832         MULTIPID=$!
833         # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
834         createmany -m $DIR2/$tdir/f 10000
835         # set mtime/atime backward
836         touch -t 198001010000 $DIR2/$tdir
837         kill -USR1 $MULTIPID
838         nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
839         [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
840 }
841 run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
842
843 test_38() { # bug 18801, based on the code of test_32b
844         remote_ost_nodsh && skip "remote OST with nodsh" && return
845
846         local node
847         local p="$TMP/sanityN-$TESTNAME.parameters"
848         local random="$TMP/sanityN-$TESTNAME.random"
849         # 1. locked unaligned non-DIRECT_IO write of 8192 bytes to file A
850         # 2a. locked unaligned DIRECT_IO write of 4000 bytes to file B
851         # 2b. locked unaligned DIRECT_IO write of 4000 bytes to file B
852         # 3. unaligned "lockless DIRECT_IO" write of 192 bytes in the end of file B
853         # 4. compare A and B
854         log "creating the initial file"
855         multiop $random Ob4000b4000b192c || error "failed creating random file"
856         log "creating a file with the same contents"
857         multiop $DIR1/$tfile oO_CREAT:O_DIRECT:O_RDWR:b4000c || error "first multiop failed"
858         multiop $DIR1/$tfile oO_CREAT:O_DIRECT:O_RDWR:z4000b4000c || error "second multiop failed"
859         save_lustre_params $HOSTNAME "llite.*.contention_seconds" > $p
860         for node in $(osts_nodes); do
861                 save_lustre_params $node "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
862                 save_lustre_params $node "ldlm.namespaces.filter-*.contended_locks" >> $p
863                 save_lustre_params $node "ldlm.namespaces.filter-*.contention_seconds" >> $p
864         done
865         log "enforcing lockless I/O"
866         clear_llite_stats
867         # agressive lockless i/o settings
868         for node in $(osts_nodes); do
869                 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'
870         done
871         lctl set_param -n llite.*.contention_seconds 60
872         multiop $DIR2/$tfile oO_DIRECT:O_RDWR:z8000b192c || error "the last multiop failed"
873         [ $(calc_llite_stats lockless_write_bytes) -ne 0 ] || error "lockless i/o was not triggered"
874         restore_lustre_params <$p
875         log "comparing"
876         cmp $DIR1/$tfile $random || error "O_DIRECT+lockless results do not match the original file"
877         rm -f $DIR1/$tfile
878         rm -f $p
879         rm -f $random
880 }
881 run_test 38 "lockless i/o with O_DIRECT and unaligned writes"
882
883 test_39() {
884         local originaltime
885         local updatedtime
886         local delay=3
887
888         touch $DIR1/$tfile
889         originaltime=$(stat -c %Y $DIR1/$tfile)
890         log "original modification time is $originaltime"
891         sleep $delay
892         multiop $DIR1/$tfile oO_DIRECT:O_WRONLY:w$((10*1048576))c || error "multiop has failed"
893         updatedtime=$(stat -c %Y $DIR2/$tfile)
894         log "updated modification time is $updatedtime"
895         [ $((updatedtime - originaltime)) -ge $delay ] || error "invalid modification time"
896         rm -rf $DIR/$tfile
897 }
898 run_test 39 "direct I/O writes should update mtime ========="
899
900 log "cleanup: ======================================================"
901
902 check_and_cleanup_lustre
903
904 echo '=========================== finished ==============================='
905 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 || true
906 echo "$0: completed"
907