Whamcloud - gitweb
64dfdcd95313190664e60fb5b5614a1945b02af7
[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 # It will be ported soon.
17 EXCEPT="$EXCEPT 22"
18
19 SRCDIR=`dirname $0`
20 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
21
22 SIZE=${SIZE:-40960}
23 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
24 GETSTRIPE=${GETSTRIPE:-lfs getstripe}
25 SETSTRIPE=${SETSTRIPE:-lstripe}
26 MCREATE=${MCREATE:-mcreate}
27 OPENFILE=${OPENFILE:-openfile}
28 OPENUNLINK=${OPENUNLINK:-openunlink}
29 TRUNCATE=${TRUNCATE:-truncate}
30 export TMP=${TMP:-/tmp}
31 MOUNT_2=${MOUNT_2:-"yes"}
32 CHECK_GRANT=${CHECK_GRANT:-"yes"}
33 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
34
35 SAVE_PWD=$PWD
36
37 export NAME=${NAME:-local}
38
39 LUSTRE=${LUSTRE:-`dirname $0`/..}
40 . $LUSTRE/tests/test-framework.sh
41 CLEANUP=${CLEANUP:-:}
42 SETUP=${SETUP:-:}
43 init_test_env $@
44 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
45
46 [ "$SLOW" = "no" ] && EXCEPT_SLOW="12 16 23 33a"
47
48 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
49 FAIL_ON_ERROR=false
50
51 SETUP=${SETUP:-:}
52 TRACE=${TRACE:-""}
53
54 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
55
56 check_and_setup_lustre
57
58 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
59 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
60
61 assert_DIR
62 rm -rf $DIR1/[df][0-9]* $DIR1/lnk
63
64 # $RUNAS_ID may get set incorrectly somewhere else
65 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
66
67 check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
68
69 build_test_filter
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         grant_error=`dmesg | grep "> available"`
323         [ -z "$grant_error" ] || error "$grant_error"
324 }
325 run_test 15 "test out-of-space with multiple writers ==========="
326
327 test_16() {
328         rm -f $MOUNT1/fsxfile
329         lfs setstripe $MOUNT1/fsxfile -c -1 # b=10919
330         fsx -c 50 -p 100 -N 2500 -l $((SIZE * 256)) -S 0 $MOUNT1/fsxfile $MOUNT2/fsxfile
331 }
332 run_test 16 "2500 iterations of dual-mount fsx ================="
333
334 test_17() { # bug 3513, 3667
335         remote_ost_nodsh && skip "remote OST with nodsh" && return
336
337         lfs setstripe $DIR1/$tfile -i 0 -c 1
338         cp /etc/termcap $DIR1/$tfile
339         cancel_lru_locks osc > /dev/null
340         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
341         do_facet ost1 lctl set_param fail_loc=0x8000030a
342         ls -ls $DIR1/$tfile | awk '{ print $1,$6 }' > $DIR1/$tfile-1 & \
343         ls -ls $DIR2/$tfile | awk '{ print $1,$6 }' > $DIR2/$tfile-2
344         wait
345         diff -u $DIR1/$tfile-1 $DIR2/$tfile-2 || error "files are different"
346 }
347 run_test 17 "resource creation/LVB creation race ==============="
348
349 test_18() {
350         $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2
351         sync; sleep 1; sync
352 }
353 run_test 18 "mmap sanity check ================================="
354
355 test_19() { # bug3811
356         [ -d /proc/fs/lustre/obdfilter ] || return 0
357
358         MAX=`lctl get_param -n obdfilter.*.readcache_max_filesize | head -n 1`
359         lctl set_param -n obdfilter.*OST*.readcache_max_filesize=4096
360         dd if=/dev/urandom of=$TMP/f19b bs=512k count=32
361         SUM=`cksum $TMP/f19b | cut -d" " -f 1,2`
362         cp $TMP/f19b $DIR1/f19b
363         for i in `seq 1 20`; do
364                 [ $((i % 5)) -eq 0 ] && log "test_18 loop $i"
365                 cancel_lru_locks osc > /dev/null
366                 cksum $DIR1/f19b | cut -d" " -f 1,2 > $TMP/sum1 & \
367                 cksum $DIR2/f19b | cut -d" " -f 1,2 > $TMP/sum2
368                 wait
369                 [ "`cat $TMP/sum1`" = "$SUM" ] || \
370                         error "$DIR1/f19b `cat $TMP/sum1` != $SUM"
371                 [ "`cat $TMP/sum2`" = "$SUM" ] || \
372                         error "$DIR2/f19b `cat $TMP/sum2` != $SUM"
373         done
374         lctl set_param -n obdfilter.*OST*.readcache_max_filesize=$MAX
375         rm $DIR1/f19b
376 }
377 run_test 19 "test concurrent uncached read races ==============="
378
379 test_20() {
380         mkdir $DIR1/d20
381         cancel_lru_locks osc
382         CNT=$((`lctl get_param -n llite.*.dump_page_cache | wc -l`))
383         multiop $DIR1/f20 Ow8190c
384         multiop $DIR2/f20 Oz8194w8190c
385         multiop $DIR1/f20 Oz0r8190c
386         cancel_lru_locks osc
387         CNTD=$((`lctl get_param -n llite.*.dump_page_cache | wc -l` - $CNT))
388         [ $CNTD -gt 0 ] && \
389             error $CNTD" page left in cache after lock cancel" || true
390 }
391 run_test 20 "test extra readahead page left in cache ===="
392
393 cleanup_21() {
394         trap 0
395         umount $DIR1/d21
396 }
397
398 test_21() { # Bug 5907
399         mkdir $DIR1/d21
400         mount /etc $DIR1/d21 --bind || error "mount failed" # Poor man's mount.
401         trap cleanup_21 EXIT
402         rmdir -v $DIR1/d21 && error "Removed mounted directory"
403         rmdir -v $DIR2/d21 && echo "Removed mounted directory from another mountpoint, needs to be fixed"
404         test -d $DIR1/d21 || error "Mounted directory disappeared"
405         cleanup_21
406         test -d $DIR2/d21 || test -d $DIR1/d21 && error "Removed dir still visible after umount"
407         true
408 }
409 run_test 21 " Try to remove mountpoint on another dir ===="
410
411 test_23() { # Bug 5972
412         echo "others should see updated atime while another read" > $DIR1/f23
413         
414         # clear the lock(mode: LCK_PW) gotten from creating operation
415         cancel_lru_locks osc
416         
417         time1=`date +%s`        
418         #MAX_ATIME_DIFF 60, we update atime only if older than 60 seconds
419         sleep 61
420         
421         multiop_bg_pause $DIR1/f23 or20_c || return 1
422         # with SOM and opencache enabled, we need to close a file and cancel
423         # open lock to get atime propogated to MDS
424         kill -USR1 $!
425         cancel_lru_locks mdc
426
427         time2=`stat -c "%X" $DIR2/f23`
428
429         if (( $time2 <= $time1 )); then
430                 error "atime doesn't update among nodes"
431         fi
432
433         rm -f $DIR1/f23 || error "rm -f $DIR1/f23 failed"
434         true
435 }
436 run_test 23 " others should see updated atime while another read===="
437
438 test_24() {
439         touch $DIR1/$tfile
440         lfs df || error "lfs df failed"
441         lfs df -ih || error "lfs df -ih failed"
442         lfs df -h $DIR1 || error "lfs df -h $DIR1 failed"
443         lfs df -i $DIR2 || error "lfs df -i $DIR2 failed"
444         lfs df $DIR1/$tfile || error "lfs df $DIR1/$tfile failed"
445         lfs df -ih $DIR2/$tfile || error "lfs df -ih $DIR2/$tfile failed"
446         
447         OSC=`lctl dl | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
448 #       OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
449         lctl --device %$OSC deactivate
450         lfs df -i || error "lfs df -i with deactivated OSC failed"
451         lctl --device %$OSC recover
452         lfs df || error "lfs df with reactivated OSC failed"
453 }
454 run_test 24 "lfs df [-ih] [path] test ========================="
455
456 test_25() {
457         [ `lctl get_param -n mdc.*-mdc-*.connect_flags | grep -c acl` -lt 2 ] && \
458             skip "must have acl, skipping" && return
459
460         mkdir -p $DIR1/$tdir
461         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
462         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
463
464         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
465         setfacl -m u:$RUNAS_ID:--- $DIR1/$tdir || error "setfacl $DIR2/$tdir #1"
466         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
467         setfacl -m u:$RUNAS_ID:r-x $DIR1/$tdir || error "setfacl $DIR2/$tdir #2"
468         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
469         setfacl -m u:$RUNAS_ID:--- $DIR1/$tdir || error "setfacl $DIR2/$tdir #3"
470         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
471         setfacl -x u:$RUNAS_ID: $DIR1/$tdir || error "setfacl $DIR2/$tdir #4"
472         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
473
474         rm -rf $DIR1/$tdir
475 }
476 run_test 25 "change ACL on one mountpoint be seen on another ==="
477
478 test_26a() {
479         utime $DIR1/f26a -s $DIR2/f26a || error
480 }
481 run_test 26a "allow mtime to get older"
482
483 test_26b() {
484         touch $DIR1/$tfile
485         sleep 1
486         echo "aaa" >> $DIR1/$tfile
487         sleep 1
488         chmod a+x $DIR2/$tfile
489         mt1=`stat -c %Y $DIR1/$tfile`
490         mt2=`stat -c %Y $DIR2/$tfile`
491
492         if [ x"$mt1" != x"$mt2" ]; then
493                 error "not equal mtime, client1: "$mt1", client2: "$mt2"."
494         fi
495 }
496 run_test 26b "sync mtime between ost and mds"
497
498 test_27() {
499         cancel_lru_locks osc
500         lctl clear
501         dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
502         DD2_PID=$!
503         usleep 50
504         log "dd 1 started"
505         
506         dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
507         DD1_PID=$!
508         log "dd 2 started"
509         
510         sleep 1
511         dd if=/dev/zero of=$DIR1/$tfile bs=8k conv=notrunc count=1 seek=0
512         log "dd 3 finished"
513         lctl set_param -n ldlm.dump_namespaces ""
514         wait $DD1_PID $DD2_PID
515         [ $? -ne 0 ] && lctl dk $TMP/debug || true
516 }
517 run_test 27 "align non-overlapping extent locks from request ==="
518
519 test_28() { # bug 9977
520         ECHO_UUID="ECHO_osc1_UUID"
521         tOST=`$LCTL dl | | awk '/-osc-|OSC.*MNT/ { print $4 }' | head -1`
522
523         lfs setstripe $DIR1/$tfile -s 1048576 -i 0 -c 2
524         tOBJID=`lfs getstripe $DIR1/$tfile |grep "^[[:space:]]\+1" |awk '{print $2}'`
525         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
526
527         $LCTL <<-EOF
528                 newdev
529                 attach echo_client ECHO_osc1 $ECHO_UUID
530                 setup $tOST
531         EOF
532
533         tECHOID=`$LCTL dl | grep $ECHO_UUID | awk '{print $1}'`
534         $LCTL --device $tECHOID destroy "${tOBJID}:0"
535
536         $LCTL <<-EOF
537                 cfg_device ECHO_osc1
538                 cleanup
539                 detach
540         EOF
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         usleep 500
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         # cleanup: reconnect the client back
607         df $DIR2
608 }
609 run_test 31b "voluntary OST cancel / blocking ast race=============="
610
611 # enable/disable lockless truncate feature, depending on the arg 0/1
612 enable_lockless_truncate() {
613         lctl set_param -n osc.*.lockless_truncate $1
614 }
615
616 test_32a() { # bug 11270
617         local p="$TMP/sanityN-$TESTNAME.parameters"
618         save_lustre_params $HOSTNAME osc.*.lockless_truncate > $p
619         cancel_lru_locks osc
620         enable_lockless_truncate 1
621         rm -f $DIR1/$tfile
622         lfs setstripe -c -1 $DIR1/$tfile
623         dd if=/dev/zero of=$DIR1/$tfile count=10 bs=1M > /dev/null 2>&1
624         clear_osc_stats
625
626         log "checking cached lockless truncate"
627         $TRUNCATE $DIR1/$tfile 8000000
628         $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
629         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
630                 error "lockless truncate doesn't use cached locks"
631
632         log "checking not cached lockless truncate"
633         $TRUNCATE $DIR2/$tfile 5000000
634         $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
635         [ $(calc_osc_stats lockless_truncate) -ne 0 ] ||
636                 error "not cached trancate isn't lockless"
637
638         log "disabled lockless truncate"
639         enable_lockless_truncate 0
640         clear_osc_stats
641         $TRUNCATE $DIR2/$tfile 3000000
642         $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
643         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
644                 error "lockless truncate disabling failed"
645         rm $DIR1/$tfile
646         # restore lockless_truncate default values
647         restore_lustre_params < $p
648         rm -f $p
649 }
650 run_test 32a "lockless truncate"
651
652 test_32b() { # bug 11270
653         remote_ost_nodsh && skip "remote OST with nodsh" && return
654
655         local node
656         local p="$TMP/sanityN-$TESTNAME.parameters"
657         save_lustre_params $HOSTNAME "osc.*.contention_seconds" > $p
658         for node in $(osts_nodes); do
659                 save_lustre_params $node "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
660                 save_lustre_params $node "ldlm.namespaces.filter-*.contended_locks" >> $p
661                 save_lustre_params $node "ldlm.namespaces.filter-*.contention_seconds" >> $p
662         done
663         clear_osc_stats
664         # agressive lockless i/o settings
665         for node in $(osts_nodes); do
666                 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'
667         done
668         lctl set_param -n osc.*.contention_seconds 60
669         for i in $(seq 5); do
670                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
671                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
672         done
673         [ $(calc_osc_stats lockless_write_bytes) -ne 0 ] || error "lockless i/o was not triggered"
674         # disable lockless i/o (it is disabled by default)
675         for node in $(osts_nodes); do
676                 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'
677         done
678         # set contention_seconds to 0 at client too, otherwise Lustre still
679         # remembers lock contention
680         lctl set_param -n osc.*.contention_seconds 0
681         clear_osc_stats
682         for i in $(seq 1); do
683                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
684                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
685         done
686         [ $(calc_osc_stats lockless_write_bytes) -eq 0 ] ||
687                 error "lockless i/o works when disabled"
688         rm -f $DIR1/$tfile
689         restore_lustre_params <$p
690         rm -f $p
691 }
692 run_test 32b "lockless i/o"
693
694 print_jbd_stat () {
695     local dev
696     local mdts=$(get_facets MDS)
697     local varcvs
698     local mds
699
700     local stat=0
701     for mds in ${mdts//,/ }; do
702         varsvc=${mds}_svc
703         dev=$(basename $(do_facet $mds lctl get_param -n osd.${!varsvc}.mntdev))
704         val=$(do_facet $mds cat /proc/fs/jbd/$dev/info | head -1 | cut -d" " -f1)
705         stat=$(( stat + val))
706     done
707     echo $stat
708 }
709
710 # commit on sharing tests
711 test_33a() {
712     remote_mds_nodsh && skip "remote MDS with nodsh" && return
713
714     [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
715     [ $CLIENTCOUNT -ge 2 ] || \
716         { skip "Need two or more clients, have $CLIENTCOUNT" && return 0; }
717
718     zconf_mount_clients $CLIENT1,$CLIENT2 $DIR1
719     zconf_mount_clients $CLIENT1,$CLIENT2 $DIR2
720
721     local nfiles=${TEST33_NFILES:-10000}
722     local param_file=$TMP/$tfile-params
723
724     save_lustre_params $(comma_list $(mdts_nodes)) "mdt.*.commit_on_sharing" > $param_file
725
726     local COS
727     local jbdold
728     local jbdnew
729     local jbd
730
731     for COS in 0 1; do
732         do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
733         avgjbd=0
734         avgtime=0
735         for i in 1 2 3; do
736             do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
737
738             jbdold=$(print_jbd_stat)
739             echo "=== START createmany old: $jbdold transaction"
740             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")
741             jbdnew=$(print_jbd_stat)
742             jbd=$(( jbdnew - jbdold ))
743             echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
744             avgjbd=$(( avgjbd + jbd ))
745             avgtime=$(( avgtime + elapsed ))
746         done
747         eval cos${COS}_jbd=$((avgjbd / 3))
748         eval cos${COS}_time=$((avgtime / 3))
749     done
750
751     echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
752     echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
753     [ "$cos0_jbd" != 0 ] && echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
754     [ "$cos0_time" != 0 ] && echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
755
756     restore_lustre_params < $param_file
757     rm -f $param_file
758     return 0
759 }
760 run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
761
762 # End commit on sharing tests
763
764 test_34() { #16129
765         local OPER
766         local lock_in
767         local lock_out
768         for OPER in notimeout timeout ; do
769                 rm $DIR1/$tfile 2>/dev/null
770                 lock_in=$(do_nodes $(osts_nodes) "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
771                 if [ $OPER == "timeout" ] ; then
772                         for j in `seq $OSTCOUNT`; do
773                                 #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT    0x511
774                                 do_facet ost$j lctl set_param fail_loc=0x511
775                         done
776                         echo lock should expire
777                 else
778                         for j in `seq $OSTCOUNT`; do
779                                 #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT  0x512
780                                 do_facet ost$j lctl set_param fail_loc=0x512
781                         done
782                         echo lock should not expire
783                 fi
784                 echo writing on client1
785                 dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
786                 sync &
787                 echo reading on client2
788                 dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
789                 # wait for a lock timeout
790                 sleep 4
791                 lock_out=$(do_nodes $(osts_nodes) "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
792                 if [ $OPER == "timeout" ] ; then
793                         if [ $lock_in == $lock_out ]; then
794                                 error "no lock timeout happened"
795                         else
796                                 echo "success"
797                         fi
798                 else
799                         if [ $lock_in != $lock_out ]; then
800                                 error "lock timeout happened"
801                         else
802                                 echo "success"
803                         fi
804                 fi
805         done
806 }
807 run_test 34 "no lock timeout under IO"
808
809 test_35() { # bug 17645
810         local generation=[]
811         local count=0
812         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
813             g=$(awk '/generation/{print $2}' $imp/import)
814             generation[count]=$g
815             let count=count+1
816         done
817
818         mkdir -p $MOUNT1/$tfile
819         cancel_lru_locks mdc
820
821         # Let's initiate -EINTR situation by setting fail_loc and take
822         # write lock on same file from same client. This will not cause
823         # bl_ast yet as lock is already in local cache.
824 #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
825         do_facet client "lctl set_param fail_loc=0x80000317"
826         local timeout=`do_facet $SINGLEMDS lctl get_param  -n timeout`
827         let timeout=timeout*3
828         local nr=0
829         while test $nr -lt 10; do
830                 log "Race attempt $nr"
831                 local blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
832                 test "x$blk1" = "x" && blk1=0
833                 createmany -o $MOUNT2/$tfile/a 4000 &
834                 pid1=$!
835                 sleep 1
836
837                 # Let's make conflict and bl_ast
838                 ls -la $MOUNT1/$tfile > /dev/null &
839                 pid2=$!
840
841                 log "Wait for $pid1 $pid2 for $timeout sec..."
842                 sleep $timeout
843                 kill -9 $pid1 $pid2 > /dev/null 2>&1
844                 wait
845                 local blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
846                 test "x$blk2" = "x" && blk2=0
847                 test $blk2 -gt $blk1 && break
848                 rm -fr $MOUNT1/$tfile/*
849                 cancel_lru_locks mdc
850                 let nr=nr+1
851         done
852         do_facet client "lctl set_param fail_loc=0x0"
853         df -h $MOUNT1 $MOUNT2
854         count=0
855         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
856             g=$(awk '/generation/{print $2}' $imp/import)
857             if ! test "$g" -eq "${generation[count]}"; then
858                 error "Eviction happened on import $(basename $imp)"
859             fi
860             let count=count+1
861         done
862 }
863 run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
864
865 test_36() { #bug 16417
866     local SIZE
867     local SIZE_B
868     local i
869
870     mkdir -p $DIR1/$tdir
871     $LFS setstripe -c -1 $DIR1/$tdir
872     i=0
873     SIZE=50
874     let SIZE_B=SIZE*1024*1024
875
876     while [ $i -le 10 ]; do
877         lctl mark "start test"
878         local before=$($LFS df | awk '{if ($1 ~/^filesystem/) {print $5; exit} }')
879         dd if=/dev/zero of=$DIR1/$tdir/file000 bs=1M count=$SIZE
880         sync
881         sleep 1
882         local after_dd=$($LFS df | awk '{if ($1 ~/^filesystem/) {print $5; exit} }')
883         multiop_bg_pause $DIR2/$tdir/file000 O_r${SIZE_B}c || return 3
884         read_pid=$!
885         rm -f $DIR1/$tdir/file000
886         kill -USR1 $read_pid
887         wait $read_pid
888         sleep 1
889         local after=$($LFS df | awk '{if ($1 ~/^filesystem/) {print $5; exit} }')
890         echo "*** cycle($i) *** before($before):after_dd($after_dd):after($after)"
891         # this free space! not used
892         if [ $after_dd -ge $after ]; then
893             error "space leaked"
894             return 1;
895         fi
896         let i=i+1
897             done
898 }
899 run_test 36 "handle ESTALE/open-unlink corectly"
900
901 test_37() { # bug 18695
902         mkdir -p $DIR1/$tdir
903         multiop_bg_pause $DIR1/$tdir D_c || return 1
904         MULTIPID=$!
905         # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
906         createmany -m $DIR2/$tdir/f 10000
907         # set mtime/atime backward
908         touch -t 198001010000 $DIR2/$tdir
909         kill -USR1 $MULTIPID
910         nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
911         [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
912
913 }
914 run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
915
916 log "cleanup: ======================================================"
917
918 check_and_cleanup_lustre
919
920 echo '=========================== finished ==============================='
921 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 || true
922 echo "$0: completed"