6 # This test needs to be run on the client
9 LUSTRE=${LUSTRE:-`dirname $0`/..}
10 . $LUSTRE/tests/test-framework.sh
14 . ${CONFIG:=$LUSTRE/tests/cfg/local.sh}
22 add_mds mds --dev $MDSDEV --size $MDSSIZE
23 if [ ! -z "$mdsfailover_HOST" ]; then
24 add_mdsfailover mds --dev $MDSDEV --size $MDSSIZE
27 add_lov lov1 mds --stripe_sz $STRIPE_BYTES\
28 --stripe_cnt $STRIPES_PER_OBJ --stripe_pattern 0
29 add_ost ost --lov lov1 --dev $OSTDEV --size $OSTSIZE
30 add_ost ost2 --lov lov1 --dev ${OSTDEV}-2 --size $OSTSIZE
31 add_client client mds --lov lov1 --path $MOUNT
37 # make sure we are using the primary MDS, so the config log will
38 # be able to clean up properly.
39 activemds=`facet_active mds`
40 if [ $activemds != "mds" ]; then
44 stop mds ${FORCE} $MDSLCONFARGS
45 stop ost2 ${FORCE} --dump cleanup.log
46 stop ost ${FORCE} --dump cleanup.log
49 if [ "$ONLY" == "cleanup" ]; then
50 sysctl -w portals.debug=0 || true
55 SETUP=${SETUP:-"setup"}
56 CLEANUP=${CLEANUP:-"cleanup"}
61 start ost --reformat $OSTLCONFARGS
62 start ost2 --reformat $OSTLCONFARGS
63 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
64 start mds $MDSLCONFARGS --reformat
70 if [ "$ONLY" == "setup" ]; then
80 run_test 0 "empty replay"
86 $CHECKSTAT -t file $DIR/$tfile || return 1
89 run_test 1 "simple create"
95 $CHECKSTAT -t file $DIR/$tfile || return 1
101 ./mcreate $DIR/$tfile
105 $CHECKSTAT -t file $DIR/$tfile || return 1
113 o_directory $DIR/$tfile
115 $CHECKSTAT -t file $DIR/$tfile || return 2
118 run_test 3 "replay failed open"
122 for i in `seq 10`; do
123 echo "tag-$i" > $DIR/$tfile-$i
126 for i in `seq 10`; do
127 grep -q "tag-$i" $DIR/$tfile-$i || error "f1c-$i"
130 run_test 4 "|x| 10 open(O_CREAT)s"
136 $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
138 run_test 4b "|x| rm 10 files"
140 # The idea is to get past the first block of precreated files on both
141 # osts, and then replay.
144 for i in `seq 220`; do
145 echo "tag-$i" > $DIR/$tfile-$i
148 for i in `seq 220`; do
149 grep -q "tag-$i" $DIR/$tfile-$i || error "f1c-$i"
153 # waiting for commitment of removal
155 run_test 5 "|x| 220 open(O_CREAT)"
161 mcreate $DIR/$tdir/$tfile
163 $CHECKSTAT -t dir $DIR/$tdir || return 1
164 $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
166 # waiting for log process thread
168 run_test 6 "mkdir + contained create"
174 $CHECKSTAT -t dir $DIR/$tdir && return 1 || true
176 run_test 6b "|X| rmdir"
181 mcreate $DIR/$tdir/$tfile
183 $CHECKSTAT -t dir $DIR/$tdir || return 1
184 $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
187 run_test 7 "mkdir |X| contained create"
191 multiop $DIR/$tfile mo_c &
196 $CHECKSTAT -t file $DIR/$tfile || return 1
197 kill -USR1 $MULTIPID || return 2
198 wait $MULTIPID || return 3
201 run_test 8 "creat open |X| close"
206 local old_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
208 local new_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
210 echo " old_inum == $old_inum, new_inum == $new_inum"
211 if [ $old_inum -eq $new_inum ] ;
213 echo " old_inum and new_inum match"
215 echo "!!!! old_inum and new_inum NOT match"
220 run_test 9 "|X| create (same inum/gen)"
225 mv $DIR/$tfile $DIR/$tfile-2
228 $CHECKSTAT $DIR/$tfile && return 1
229 $CHECKSTAT $DIR/$tfile-2 ||return 2
233 run_test 10 "create |X| rename unlink"
237 echo "old" > $DIR/$tfile
238 mv $DIR/$tfile $DIR/$tfile-2
240 echo "new" > $DIR/$tfile
242 grep old $DIR/$tfile-2
244 grep new $DIR/$tfile || return 1
245 grep old $DIR/$tfile-2 || return 2
247 run_test 11 "create open write rename |X| create-old-name read"
251 multiop $DIR/$tfile o_tSc &
253 # give multiop a chance to open
258 wait $pid || return 1
261 [ -e $DIR/$tfile ] && return 2
264 run_test 12 "open, unlink |X| close"
267 # 1777 - replay open after committed chmod that would make
268 # a regular open a failure
271 multiop $DIR/$tfile O_wc &
273 # give multiop a chance to open
276 $CHECKSTAT -p 0 $DIR/$tfile
280 wait $pid || return 1
282 $CHECKSTAT -s 1 -p 0 $DIR/$tfile || return 2
285 run_test 13 "open chmod 0 |x| write close"
288 multiop $DIR/$tfile O_tSc &
290 # give multiop a chance to open
294 kill -USR1 $pid || return 1
295 wait $pid || return 2
298 [ -e $DIR/$tfile ] && return 3
301 run_test 14 "open(O_CREAT), unlink |X| close"
304 multiop $DIR/$tfile O_tSc &
306 # give multiop a chance to open
310 touch $DIR/g11 || return 1
312 wait $pid || return 2
315 [ -e $DIR/$tfile ] && return 3
316 touch $DIR/h11 || return 4
319 run_test 15 "open(O_CREAT), unlink |X| touch new, close"
326 mcreate $DIR/$tfile-2
328 [ -e $DIR/$tfile ] && return 1
329 [ -e $DIR/$tfile-2 ] || return 2
330 munlink $DIR/$tfile-2 || return 3
332 run_test 16 "|X| open(O_CREAT), unlink, touch new, unlink new"
336 multiop $DIR/$tfile O_c &
338 # give multiop a chance to open
341 kill -USR1 $pid || return 1
342 wait $pid || return 2
343 $CHECKSTAT -t file $DIR/$tfile || return 3
346 run_test 17 "|X| open(O_CREAT), |replay| close"
350 multiop $DIR/$tfile O_tSc &
352 # give multiop a chance to open
355 touch $DIR/$tfile-2 || return 1
357 wait $pid || return 2
360 [ -e $DIR/$tfile ] && return 3
361 [ -e $DIR/$tfile-2 ] || return 4
362 # this touch frequently fails
363 touch $DIR/$tfile-3 || return 5
364 munlink $DIR/$tfile-2 || return 6
365 munlink $DIR/$tfile-3 || return 7
368 run_test 18 "|X| open(O_CREAT), unlink, touch new, close, touch, unlink"
370 # bug 1855 (a simpler form of test_11 above)
374 echo "old" > $DIR/$tfile
375 mv $DIR/$tfile $DIR/$tfile-2
376 grep old $DIR/$tfile-2
378 grep old $DIR/$tfile-2 || return 2
380 run_test 19 "|X| mcreate, open, write, rename "
384 multiop $DIR/$tfile O_tSc &
386 # give multiop a chance to open
392 wait $pid || return 1
393 [ -e $DIR/$tfile ] && return 2
396 run_test 20 "|X| open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
400 multiop $DIR/$tfile O_tSc &
402 # give multiop a chance to open
405 touch $DIR/g11 || return 1
409 wait $pid || return 2
410 [ -e $DIR/$tfile ] && return 3
411 touch $DIR/h11 || return 4
414 run_test 21 "|X| open(O_CREAT), unlink touch new, replay, close (test mds_cleanup_orphans)"
417 multiop $DIR/$tfile O_tSc &
419 # give multiop a chance to open
427 wait $pid || return 1
428 [ -e $DIR/$tfile ] && return 2
431 run_test 22 "open(O_CREAT), |X| unlink, replay, close (test mds_cleanup_orphans)"
434 multiop $DIR/$tfile O_tSc &
436 # give multiop a chance to open
441 touch $DIR/g11 || return 1
445 wait $pid || return 2
446 [ -e $DIR/$tfile ] && return 3
447 touch $DIR/h11 || return 4
450 run_test 23 "open(O_CREAT), |X| unlink touch new, replay, close (test mds_cleanup_orphans)"
453 multiop $DIR/$tfile O_tSc &
455 # give multiop a chance to open
462 wait $pid || return 1
463 [ -e $DIR/$tfile ] && return 2
466 run_test 24 "open(O_CREAT), replay, unlink, close (test mds_cleanup_orphans)"
469 multiop $DIR/$tfile O_tSc &
471 # give multiop a chance to open
478 wait $pid || return 1
479 [ -e $DIR/$tfile ] && return 2
482 run_test 25 "open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
486 multiop $DIR/$tfile-1 O_tSc &
488 multiop $DIR/$tfile-2 O_tSc &
490 # give multiop a chance to open
495 wait $pid2 || return 1
499 wait $pid1 || return 2
500 [ -e $DIR/$tfile-1 ] && return 3
501 [ -e $DIR/$tfile-2 ] && return 4
504 run_test 26 "|X| open(O_CREAT), unlink two, close one, replay, close one (test mds_cleanup_orphans)"
508 multiop $DIR/$tfile-1 O_tSc &
510 multiop $DIR/$tfile-2 O_tSc &
512 # give multiop a chance to open
519 wait $pid1 || return 1
521 wait $pid2 || return 2
522 [ -e $DIR/$tfile-1 ] && return 3
523 [ -e $DIR/$tfile-2 ] && return 4
526 run_test 27 "|X| open(O_CREAT), unlink two, replay, close two (test mds_cleanup_orphans)"
529 multiop $DIR/$tfile-1 O_tSc &
531 multiop $DIR/$tfile-2 O_tSc &
533 # give multiop a chance to open
539 wait $pid2 || return 1
543 wait $pid1 || return 2
544 [ -e $DIR/$tfile-1 ] && return 3
545 [ -e $DIR/$tfile-2 ] && return 4
548 run_test 28 "open(O_CREAT), |X| unlink two, close one, replay, close one (test mds_cleanup_orphans)"
551 multiop $DIR/$tfile-1 O_tSc &
553 multiop $DIR/$tfile-2 O_tSc &
555 # give multiop a chance to open
563 wait $pid1 || return 1
565 wait $pid2 || return 2
566 [ -e $DIR/$tfile-1 ] && return 3
567 [ -e $DIR/$tfile-2 ] && return 4
570 run_test 29 "open(O_CREAT), |X| unlink two, replay, close two (test mds_cleanup_orphans)"
573 multiop $DIR/$tfile-1 O_tSc &
575 multiop $DIR/$tfile-2 O_tSc &
577 # give multiop a chance to open
585 wait $pid1 || return 1
587 wait $pid2 || return 2
588 [ -e $DIR/$tfile-1 ] && return 3
589 [ -e $DIR/$tfile-2 ] && return 4
592 run_test 30 "open(O_CREAT) two, unlink two, replay, close two (test mds_cleanup_orphans)"
595 multiop $DIR/$tfile-1 O_tSc &
597 multiop $DIR/$tfile-2 O_tSc &
599 # give multiop a chance to open
607 wait $pid1 || return 1
609 wait $pid2 || return 2
610 [ -e $DIR/$tfile-1 ] && return 3
611 [ -e $DIR/$tfile-2 ] && return 4
614 run_test 31 "open(O_CREAT) two, unlink one, |X| unlink one, close two (test mds_cleanup_orphans)"
616 # tests for bug 2104; completion without crashing is success. The close is
617 # stale, but we always return 0 for close, so the app never sees it.
619 multiop $DIR/$tfile O_c &
621 multiop $DIR/$tfile O_c &
623 # give multiop a chance to open
626 df $MOUNT || df $MOUNT || return 1
632 run_test 32 "close() notices client eviction; close() after client eviction"
634 # Abort recovery before client complete
639 # this file should be gone, because the replay was aborted
640 $CHECKSTAT -t file $DIR/$tfile && return 1
643 run_test 33 "abort recovery before client does replay"
646 multiop $DIR/$tfile O_c &
648 # give multiop a chance to open
655 [ -e $DIR/$tfile ] && return 1
659 run_test 34 "abort recovery before client does replay (test mds_cleanup_orphans)"
661 # bug 2278 - generate one orphan on OST, then destroy it during recovery from llog
665 echo 0x80000119 > /proc/sys/lustre/fail_loc
668 # give a chance to remove from MDS
670 $CHECKSTAT -t file $DIR/$tfile && return 1 || true
672 run_test 35 "test recovery from llog for unlink op"
674 # b=2432 resent cancel after replay uses wrong cookie,
675 # so don't resend cancels
679 checkstat $DIR/$tfile
682 if dmesg | grep "unknown lock cookie"; then
683 echo "cancel after replay failed"
687 run_test 36 "don't resend cancel"
690 # directory orphans can't be unlinked from PENDING directory
692 rmdir $DIR/$tfile 2>/dev/null
693 multiop $DIR/$tfile dD_c &
695 # give multiop a chance to open
700 # clear the dmesg buffer so we only see errors from this recovery
704 dmesg | grep "mds_unlink_orphan.*error .* unlinking orphan" && return 1
708 run_test 37 "abort recovery before client does replay (test mds_cleanup_orphans for directories)"
710 equals_msg test complete, cleaning up