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
43 zconf_umount `hostname` $MOUNT
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
65 zconf_mount `hostname` $MOUNT
66 echo 0x3f0410 > /proc/sys/portals/debug
71 if [ "$ONLY" == "setup" ]; then
81 run_test 0 "empty replay"
87 $CHECKSTAT -t file $DIR/$tfile || return 1
90 run_test 1 "simple create"
96 $CHECKSTAT -t file $DIR/$tfile || return 1
102 ./mcreate $DIR/$tfile
106 $CHECKSTAT -t file $DIR/$tfile || return 1
114 o_directory $DIR/$tfile
116 $CHECKSTAT -t file $DIR/$tfile || return 2
119 run_test 3a "replay failed open(O_DIRECTORY)"
123 #define OBD_FAIL_MDS_OPEN_PACK | OBD_FAIL_ONCE
124 do_facet mds "sysctl -w lustre.fail_loc=0x80000114"
126 do_facet mds "sysctl -w lustre.fail_loc=0"
128 $CHECKSTAT -t file $DIR/$tfile && return 2
131 run_test 3b "replay failed open -ENOMEM"
135 #define OBD_FAIL_MDS_ALLOC_OBDO | OBD_FAIL_ONCE
136 do_facet mds "sysctl -w lustre.fail_loc=0x80000128"
138 do_facet mds "sysctl -w lustre.fail_loc=0"
141 $CHECKSTAT -t file $DIR/$tfile && return 2
144 run_test 3c "replay failed open -ENOMEM"
148 for i in `seq 10`; do
149 echo "tag-$i" > $DIR/$tfile-$i
152 for i in `seq 10`; do
153 grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
156 run_test 4 "|x| 10 open(O_CREAT)s"
162 $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
164 run_test 4b "|x| rm 10 files"
166 # The idea is to get past the first block of precreated files on both
167 # osts, and then replay.
170 for i in `seq 220`; do
171 echo "tag-$i" > $DIR/$tfile-$i
174 for i in `seq 220`; do
175 grep -q "tag-$i" $DIR/$tfile-$i || error "f1c-$i"
179 # waiting for commitment of removal
181 run_test 5 "|x| 220 open(O_CREAT)"
187 mcreate $DIR/$tdir/$tfile
189 $CHECKSTAT -t dir $DIR/$tdir || return 1
190 $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
192 # waiting for log process thread
194 run_test 6 "mkdir + contained create"
200 $CHECKSTAT -t dir $DIR/$tdir && return 1 || true
202 run_test 6b "|X| rmdir"
207 mcreate $DIR/$tdir/$tfile
209 $CHECKSTAT -t dir $DIR/$tdir || return 1
210 $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
213 run_test 7 "mkdir |X| contained create"
217 multiop $DIR/$tfile mo_c &
222 $CHECKSTAT -t file $DIR/$tfile || return 1
223 kill -USR1 $MULTIPID || return 2
224 wait $MULTIPID || return 3
227 run_test 8 "creat open |X| close"
232 local old_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
234 local new_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
236 echo " old_inum == $old_inum, new_inum == $new_inum"
237 if [ $old_inum -eq $new_inum ] ;
239 echo " old_inum and new_inum match"
241 echo "!!!! old_inum and new_inum NOT match"
246 run_test 9 "|X| create (same inum/gen)"
251 mv $DIR/$tfile $DIR/$tfile-2
254 $CHECKSTAT $DIR/$tfile && return 1
255 $CHECKSTAT $DIR/$tfile-2 ||return 2
259 run_test 10 "create |X| rename unlink"
263 echo "old" > $DIR/$tfile
264 mv $DIR/$tfile $DIR/$tfile-2
266 echo "new" > $DIR/$tfile
268 grep old $DIR/$tfile-2
270 grep new $DIR/$tfile || return 1
271 grep old $DIR/$tfile-2 || return 2
273 run_test 11 "create open write rename |X| create-old-name read"
277 multiop $DIR/$tfile o_tSc &
279 # give multiop a chance to open
284 wait $pid || return 1
287 [ -e $DIR/$tfile ] && return 2
290 run_test 12 "open, unlink |X| close"
293 # 1777 - replay open after committed chmod that would make
294 # a regular open a failure
297 multiop $DIR/$tfile O_wc &
299 # give multiop a chance to open
302 $CHECKSTAT -p 0 $DIR/$tfile
306 wait $pid || return 1
308 $CHECKSTAT -s 1 -p 0 $DIR/$tfile || return 2
311 run_test 13 "open chmod 0 |x| write close"
314 multiop $DIR/$tfile O_tSc &
316 # give multiop a chance to open
320 kill -USR1 $pid || return 1
321 wait $pid || return 2
324 [ -e $DIR/$tfile ] && return 3
327 run_test 14 "open(O_CREAT), unlink |X| close"
330 multiop $DIR/$tfile O_tSc &
332 # give multiop a chance to open
336 touch $DIR/g11 || return 1
338 wait $pid || return 2
341 [ -e $DIR/$tfile ] && return 3
342 touch $DIR/h11 || return 4
345 run_test 15 "open(O_CREAT), unlink |X| touch new, close"
352 mcreate $DIR/$tfile-2
354 [ -e $DIR/$tfile ] && return 1
355 [ -e $DIR/$tfile-2 ] || return 2
356 munlink $DIR/$tfile-2 || return 3
358 run_test 16 "|X| open(O_CREAT), unlink, touch new, unlink new"
362 multiop $DIR/$tfile O_c &
364 # give multiop a chance to open
367 kill -USR1 $pid || return 1
368 wait $pid || return 2
369 $CHECKSTAT -t file $DIR/$tfile || return 3
372 run_test 17 "|X| open(O_CREAT), |replay| close"
376 multiop $DIR/$tfile O_tSc &
378 # give multiop a chance to open
381 touch $DIR/$tfile-2 || return 1
382 echo "pid: $pid will close"
384 wait $pid || return 2
387 [ -e $DIR/$tfile ] && return 3
388 [ -e $DIR/$tfile-2 ] || return 4
389 # this touch frequently fails
390 touch $DIR/$tfile-3 || return 5
391 munlink $DIR/$tfile-2 || return 6
392 munlink $DIR/$tfile-3 || return 7
395 run_test 18 "|X| open(O_CREAT), unlink, touch new, close, touch, unlink"
397 # bug 1855 (a simpler form of test_11 above)
401 echo "old" > $DIR/$tfile
402 mv $DIR/$tfile $DIR/$tfile-2
403 grep old $DIR/$tfile-2
405 grep old $DIR/$tfile-2 || return 2
407 run_test 19 "|X| mcreate, open, write, rename "
411 multiop $DIR/$tfile O_tSc &
413 # give multiop a chance to open
419 wait $pid || return 1
420 [ -e $DIR/$tfile ] && return 2
423 run_test 20 "|X| open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
427 multiop $DIR/$tfile O_tSc &
429 # give multiop a chance to open
432 touch $DIR/g11 || return 1
436 wait $pid || return 2
437 [ -e $DIR/$tfile ] && return 3
438 touch $DIR/h11 || return 4
441 run_test 21 "|X| open(O_CREAT), unlink touch new, replay, close (test mds_cleanup_orphans)"
444 multiop $DIR/$tfile O_tSc &
446 # give multiop a chance to open
454 wait $pid || return 1
455 [ -e $DIR/$tfile ] && return 2
458 run_test 22 "open(O_CREAT), |X| unlink, replay, close (test mds_cleanup_orphans)"
461 multiop $DIR/$tfile O_tSc &
463 # give multiop a chance to open
468 touch $DIR/g11 || return 1
472 wait $pid || return 2
473 [ -e $DIR/$tfile ] && return 3
474 touch $DIR/h11 || return 4
477 run_test 23 "open(O_CREAT), |X| unlink touch new, replay, close (test mds_cleanup_orphans)"
480 multiop $DIR/$tfile O_tSc &
482 # give multiop a chance to open
489 wait $pid || return 1
490 [ -e $DIR/$tfile ] && return 2
493 run_test 24 "open(O_CREAT), replay, unlink, close (test mds_cleanup_orphans)"
496 multiop $DIR/$tfile O_tSc &
498 # give multiop a chance to open
505 wait $pid || return 1
506 [ -e $DIR/$tfile ] && return 2
509 run_test 25 "open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
513 multiop $DIR/$tfile-1 O_tSc &
515 multiop $DIR/$tfile-2 O_tSc &
517 # give multiop a chance to open
522 wait $pid2 || return 1
526 wait $pid1 || return 2
527 [ -e $DIR/$tfile-1 ] && return 3
528 [ -e $DIR/$tfile-2 ] && return 4
531 run_test 26 "|X| open(O_CREAT), unlink two, close one, replay, close one (test mds_cleanup_orphans)"
535 multiop $DIR/$tfile-1 O_tSc &
537 multiop $DIR/$tfile-2 O_tSc &
539 # give multiop a chance to open
546 wait $pid1 || return 1
548 wait $pid2 || return 2
549 [ -e $DIR/$tfile-1 ] && return 3
550 [ -e $DIR/$tfile-2 ] && return 4
553 run_test 27 "|X| open(O_CREAT), unlink two, replay, close two (test mds_cleanup_orphans)"
556 multiop $DIR/$tfile-1 O_tSc &
558 multiop $DIR/$tfile-2 O_tSc &
560 # give multiop a chance to open
566 wait $pid2 || return 1
570 wait $pid1 || return 2
571 [ -e $DIR/$tfile-1 ] && return 3
572 [ -e $DIR/$tfile-2 ] && return 4
575 run_test 28 "open(O_CREAT), |X| unlink two, close one, replay, close one (test mds_cleanup_orphans)"
578 multiop $DIR/$tfile-1 O_tSc &
580 multiop $DIR/$tfile-2 O_tSc &
582 # give multiop a chance to open
590 wait $pid1 || return 1
592 wait $pid2 || return 2
593 [ -e $DIR/$tfile-1 ] && return 3
594 [ -e $DIR/$tfile-2 ] && return 4
597 run_test 29 "open(O_CREAT), |X| unlink two, replay, close two (test mds_cleanup_orphans)"
600 multiop $DIR/$tfile-1 O_tSc &
602 multiop $DIR/$tfile-2 O_tSc &
604 # give multiop a chance to open
612 wait $pid1 || return 1
614 wait $pid2 || return 2
615 [ -e $DIR/$tfile-1 ] && return 3
616 [ -e $DIR/$tfile-2 ] && return 4
619 run_test 30 "open(O_CREAT) two, unlink two, replay, close two (test mds_cleanup_orphans)"
622 multiop $DIR/$tfile-1 O_tSc &
624 multiop $DIR/$tfile-2 O_tSc &
626 # give multiop a chance to open
634 wait $pid1 || return 1
636 wait $pid2 || return 2
637 [ -e $DIR/$tfile-1 ] && return 3
638 [ -e $DIR/$tfile-2 ] && return 4
641 run_test 31 "open(O_CREAT) two, unlink one, |X| unlink one, close two (test mds_cleanup_orphans)"
643 # tests for bug 2104; completion without crashing is success. The close is
644 # stale, but we always return 0 for close, so the app never sees it.
646 multiop $DIR/$tfile O_c &
648 multiop $DIR/$tfile O_c &
650 # give multiop a chance to open
653 df $MOUNT || df $MOUNT || return 1
659 run_test 32 "close() notices client eviction; close() after client eviction"
661 # Abort recovery before client complete
666 # this file should be gone, because the replay was aborted
667 $CHECKSTAT -t file $DIR/$tfile && return 1
670 run_test 33 "abort recovery before client does replay"
673 multiop $DIR/$tfile O_c &
675 # give multiop a chance to open
682 [ -e $DIR/$tfile ] && return 1
686 run_test 34 "abort recovery before client does replay (test mds_cleanup_orphans)"
688 # bug 2278 - generate one orphan on OST, then destroy it during recovery from llog
692 #define OBD_FAIL_MDS_REINT_NET_REP 0x119
693 do_facet mds "sysctl -w lustre.fail_loc=0x80000119"
698 # give a chance to remove from MDS
700 $CHECKSTAT -t file $DIR/$tfile && return 1 || true
702 run_test 35 "test recovery from llog for unlink op"
704 # b=2432 resent cancel after replay uses wrong cookie,
705 # so don't resend cancels
709 checkstat $DIR/$tfile
712 if dmesg | grep "unknown lock cookie"; then
713 echo "cancel after replay failed"
717 run_test 36 "don't resend cancel"
720 # directory orphans can't be unlinked from PENDING directory
722 rmdir $DIR/$tfile 2>/dev/null
723 multiop $DIR/$tfile dD_c &
725 # give multiop a chance to open
730 # clear the dmesg buffer so we only see errors from this recovery
734 dmesg | grep "mds_unlink_orphan.*error .* unlinking orphan" && return 1
738 run_test 37 "abort recovery before client does replay (test mds_cleanup_orphans for directories)"
741 createmany -o $DIR/$tfile-%d 800
742 unlinkmany $DIR/$tfile-%d 0 400
745 unlinkmany $DIR/$tfile-%d 400 400
747 $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
749 run_test 38 "test recovery from unlink llog (test llog_gen_rec) "
752 createmany -o $DIR/$tfile-%d 800
754 unlinkmany $DIR/$tfile-%d 0 400
756 unlinkmany $DIR/$tfile-%d 400 400
758 $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
760 run_test 39 "test recovery from unlink llog (test llog_gen_rec) "
763 cat /proc/fs/lustre/osc/*/stats |
764 awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
769 $LCTL mark multiop $MOUNT/$tfile OS_c
770 multiop $MOUNT/$tfile OS_c &
772 writeme -s $MOUNT/${tfile}-2 &
776 #define OBD_FAIL_MDS_CONNECT_NET 0x117
777 do_facet mds "sysctl -w lustre.fail_loc=0x80000117"
779 stat1=`count_ost_writes`
781 stat2=`count_ost_writes`
782 echo "$stat1, $stat2"
783 if [ $stat1 -lt $stat2 ]; then
784 echo "writes continuing during recovery"
787 echo "writes not continuing during recovery, bug 2477"
790 echo "waiting for writeme $WRITE_PID"
794 echo "waiting for multiop $PID"
795 wait $PID || return 2
796 do_facet client munlink $MOUNT/$tfile || return 3
797 do_facet client munlink $MOUNT/${tfile}-2 || return 3
800 run_test 40 "cause recovery in ptlrpc, ensure IO continues"
804 # make sure that a read to one osc doesn't try to double-unlock its page just
805 # because another osc is invalid. trigger_group_io used to mistakenly return
806 # an error if any oscs were invalid even after having successfully put rpcs
807 # on valid oscs. This was fatal if the caller was ll_readpage who unlocked
808 # the page, guarnateeing that the unlock from the RPC completion would
809 # assert on trying to unlock the unlocked page.
811 local f=$MOUNT/$tfile
812 # make sure the start of the file is ost1
813 lfs setstripe $f $((128 * 1024)) 0 0
814 do_facet client dd if=/dev/zero of=$f bs=4k count=1 || return 3
816 # fail ost2 and read from ost1
817 local osc2_dev=`$LCTL device_list | \
818 awk '(/ost2.*client_facet/){print $4}' `
819 $LCTL --device %$osc2_dev deactivate
820 do_facet client dd if=$f of=/dev/null bs=4k count=1 || return 3
821 $LCTL --device %$osc2_dev activate
824 run_test 41 "read from a valid osc while other oscs are invalid"
826 # test MDS recovery after ost failure
828 blocks=`df $MOUNT | tail -1 | awk '{ print $1 }'`
829 createmany -o $DIR/$tfile-%d 800
831 unlinkmany $DIR/$tfile-%d 0 400
834 # osc is evicted, fs is smaller
835 blocks_after=`df $MOUNT | tail -1 | awk '{ print $1 }'`
836 [ $blocks_after -lt $blocks ] || return 1
837 echo wait for MDS to timeout and recover
838 sleep $((TIMEOUT * 2))
839 unlinkmany $DIR/$tfile-%d 400 400
840 $CHECKSTAT -t file $DIR/$tfile-* && return 2 || true
842 run_test 42 "recovery after ost failure"
845 # directory orphans can't be unlinked from PENDING directory
849 # OBD_FAIL_OST_CREATE_NET 0x204
850 do_facet ost "sysctl -w lustre.fail_loc=0x80000204"
852 df $MOUNT || return 1
854 do_facet ost "sysctl -w lustre.fail_loc=0"
858 run_test 43 "mds osc import failure during recovery; don't LBUG"
861 mdcdev=`awk '/mds_svc_MNT/ {print $1}' < /proc/fs/lustre/devices`
862 do_facet mds "sysctl -w lustre.fail_loc=0x80000701"
863 $LCTL --device $mdcdev recover
865 do_facet mds "sysctl -w lustre.fail_loc=0"
868 run_test 44 "race in target handle connect"
870 # Handle failed close
872 mdcdev=`awk '/mds_svc_MNT/ {print $1}' < /proc/fs/lustre/devices`
873 $LCTL --device $mdcdev recover
875 multiop $DIR/$tfile O_c &
879 # This will cause the CLOSE to fail before even
880 # allocating a reply buffer
881 $LCTL --device $mdcdev deactivate
885 wait $pid || return 1
887 $LCTL --device $mdcdev activate
889 $CHECKSTAT -t file $DIR/$tfile || return 2
892 run_test 45 "Handle failed close"
894 equals_msg test complete, cleaning up