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/lmv.sh}
23 if [ "$MDSCOUNT" -gt 1 ]; then
25 for num in `seq $MDSCOUNT`; do
26 MDSDEV=$TMP/mds${num}-`hostname`
27 add_mds mds$num --dev $MDSDEV --size $MDSSIZE --master --lmv lmv1
29 add_lov_to_lmv lov1 lmv1 --stripe_sz $STRIPE_BYTES \
30 --stripe_cnt $STRIPES_PER_OBJ --stripe_pattern 0
31 add_ost ost --lov lov1 --dev $OSTDEV --size $OSTSIZE
32 add_ost ost2 --lov lov1 --dev ${OSTDEV}-2 --size $OSTSIZE
33 add_client client --lmv lmv1 --lov lov1 --path $MOUNT
35 add_mds mds1 --dev $MDSDEV --size $MDSSIZE
36 if [ ! -z "$mdsfailover_HOST" ]; then
37 add_mdsfailover mds --dev $MDSDEV --size $MDSSIZE
40 add_lov lov1 mds1 --stripe_sz $STRIPE_BYTES \
41 --stripe_cnt $STRIPES_PER_OBJ --stripe_pattern 0
42 add_ost ost --lov lov1 --dev $OSTDEV --size $OSTSIZE
43 add_ost ost2 --lov lov1 --dev ${OSTDEV}-2 --size $OSTSIZE
44 add_client client --mds mds1_svc --lov lov1 --path $MOUNT
47 add_lov lov1 mds --stripe_sz $STRIPE_BYTES \
48 --stripe_cnt $STRIPES_PER_OBJ --stripe_pattern 0
49 add_ost ost --lov lov1 --dev $OSTDEV --size $OSTSIZE
50 add_ost ost2 --lov lov1 --dev ${OSTDEV}-2 --size $OSTSIZE
51 add_client client mds --lov lov1 --path $MOUNT
57 # make sure we are using the primary MDS, so the config log will
58 # be able to clean up properly.
59 activemds=`facet_active mds`
60 if [ $activemds != "mds" ]; then
63 zconf_umount `hostname` $MOUNT
64 if [ "$MDSCOUNT" -gt 1 ]; then
65 for num in `seq $MDSCOUNT`; do
66 stop mds$num ${FORCE} $MDSLCONFARGS
69 stop mds ${FORCE} $MDSLCONFARGS
71 stop ost2 ${FORCE} --dump cleanup.log
72 stop ost ${FORCE} --dump cleanup.log
75 if [ "$ONLY" == "cleanup" ]; then
76 sysctl -w portals.debug=0 || true
81 SETUP=${SETUP:-"setup"}
82 CLEANUP=${CLEANUP:-"cleanup"}
87 start ost --reformat $OSTLCONFARGS
88 start ost2 --reformat $OSTLCONFARGS
89 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
90 start mds $MDSLCONFARGS --reformat
91 grep " $MOUNT " /proc/mounts || zconf_mount `hostname` $MOUNT
96 if [ "$ONLY" == "setup" ]; then
106 run_test 0 "empty replay"
109 # this test attempts to trigger a race in the precreation code,
110 # and must run before any other objects are created on the filesystem
112 createmany -o $DIR/$tfile 20 || return 1
113 unlinkmany $DIR/$tfile 20 || return 2
115 run_test 0b "ensure object created after recover exists. (3284)"
121 $CHECKSTAT -t file $DIR/$tfile || return 1
124 run_test 1 "simple create"
130 $CHECKSTAT -t file $DIR/$tfile || return 1
136 ./mcreate $DIR/$tfile
140 $CHECKSTAT -t file $DIR/$tfile || return 1
148 o_directory $DIR/$tfile
150 $CHECKSTAT -t file $DIR/$tfile || return 2
153 run_test 3a "replay failed open(O_DIRECTORY)"
157 #define OBD_FAIL_MDS_OPEN_PACK | OBD_FAIL_ONCE
158 do_facet mds "sysctl -w lustre.fail_loc=0x80000114"
160 do_facet mds "sysctl -w lustre.fail_loc=0"
162 $CHECKSTAT -t file $DIR/$tfile && return 2
165 run_test 3b "replay failed open -ENOMEM"
169 #define OBD_FAIL_MDS_ALLOC_OBDO | OBD_FAIL_ONCE
170 do_facet mds "sysctl -w lustre.fail_loc=0x80000128"
172 do_facet mds "sysctl -w lustre.fail_loc=0"
175 $CHECKSTAT -t file $DIR/$tfile && return 2
178 run_test 3c "replay failed open -ENOMEM"
182 for i in `seq 10`; do
183 echo "tag-$i" > $DIR/$tfile-$i
186 for i in `seq 10`; do
187 grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
190 run_test 4 "|x| 10 open(O_CREAT)s"
196 $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
198 run_test 4b "|x| rm 10 files"
200 # The idea is to get past the first block of precreated files on both
201 # osts, and then replay.
204 for i in `seq 220`; do
205 echo "tag-$i" > $DIR/$tfile-$i
208 for i in `seq 220`; do
209 grep -q "tag-$i" $DIR/$tfile-$i || error "f1c-$i"
213 # waiting for commitment of removal
215 run_test 5 "|x| 220 open(O_CREAT)"
221 mcreate $DIR/$tdir/$tfile
223 $CHECKSTAT -t dir $DIR/$tdir || return 1
224 $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
226 # waiting for log process thread
228 run_test 6 "mkdir + contained create"
234 $CHECKSTAT -t dir $DIR/$tdir && return 1 || true
236 run_test 6b "|X| rmdir"
241 mcreate $DIR/$tdir/$tfile
243 $CHECKSTAT -t dir $DIR/$tdir || return 1
244 $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
247 run_test 7 "mkdir |X| contained create"
251 multiop $DIR/$tfile mo_c &
256 $CHECKSTAT -t file $DIR/$tfile || return 1
257 kill -USR1 $MULTIPID || return 2
258 wait $MULTIPID || return 3
261 run_test 8 "creat open |X| close"
266 local old_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
268 local new_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
270 echo " old_inum == $old_inum, new_inum == $new_inum"
271 if [ $old_inum -eq $new_inum ] ;
273 echo " old_inum and new_inum match"
275 echo "!!!! old_inum and new_inum NOT match"
280 run_test 9 "|X| create (same inum/gen)"
285 mv $DIR/$tfile $DIR/$tfile-2
288 $CHECKSTAT $DIR/$tfile && return 1
289 $CHECKSTAT $DIR/$tfile-2 ||return 2
293 run_test 10 "create |X| rename unlink"
297 echo "old" > $DIR/$tfile
298 mv $DIR/$tfile $DIR/$tfile-2
300 echo "new" > $DIR/$tfile
302 grep old $DIR/$tfile-2
304 grep new $DIR/$tfile || return 1
305 grep old $DIR/$tfile-2 || return 2
307 run_test 11 "create open write rename |X| create-old-name read"
311 multiop $DIR/$tfile o_tSc &
313 # give multiop a chance to open
318 wait $pid || return 1
321 [ -e $DIR/$tfile ] && return 2
324 run_test 12 "open, unlink |X| close"
327 # 1777 - replay open after committed chmod that would make
328 # a regular open a failure
331 multiop $DIR/$tfile O_wc &
333 # give multiop a chance to open
336 $CHECKSTAT -p 0 $DIR/$tfile
340 wait $pid || return 1
342 $CHECKSTAT -s 1 -p 0 $DIR/$tfile || return 2
345 run_test 13 "open chmod 0 |x| write close"
348 multiop $DIR/$tfile O_tSc &
350 # give multiop a chance to open
354 kill -USR1 $pid || return 1
355 wait $pid || return 2
358 [ -e $DIR/$tfile ] && return 3
361 run_test 14 "open(O_CREAT), unlink |X| close"
364 multiop $DIR/$tfile O_tSc &
366 # give multiop a chance to open
370 touch $DIR/g11 || return 1
372 wait $pid || return 2
375 [ -e $DIR/$tfile ] && return 3
376 touch $DIR/h11 || return 4
379 run_test 15 "open(O_CREAT), unlink |X| touch new, close"
386 mcreate $DIR/$tfile-2
388 [ -e $DIR/$tfile ] && return 1
389 [ -e $DIR/$tfile-2 ] || return 2
390 munlink $DIR/$tfile-2 || return 3
392 run_test 16 "|X| open(O_CREAT), unlink, touch new, unlink new"
396 multiop $DIR/$tfile O_c &
398 # give multiop a chance to open
401 kill -USR1 $pid || return 1
402 wait $pid || return 2
403 $CHECKSTAT -t file $DIR/$tfile || return 3
406 run_test 17 "|X| open(O_CREAT), |replay| close"
410 multiop $DIR/$tfile O_tSc &
412 # give multiop a chance to open
415 touch $DIR/$tfile-2 || return 1
416 echo "pid: $pid will close"
418 wait $pid || return 2
421 [ -e $DIR/$tfile ] && return 3
422 [ -e $DIR/$tfile-2 ] || return 4
423 # this touch frequently fails
424 touch $DIR/$tfile-3 || return 5
425 munlink $DIR/$tfile-2 || return 6
426 munlink $DIR/$tfile-3 || return 7
429 run_test 18 "|X| open(O_CREAT), unlink, touch new, close, touch, unlink"
431 # bug 1855 (a simpler form of test_11 above)
435 echo "old" > $DIR/$tfile
436 mv $DIR/$tfile $DIR/$tfile-2
437 grep old $DIR/$tfile-2
439 grep old $DIR/$tfile-2 || return 2
441 run_test 19 "|X| mcreate, open, write, rename "
445 multiop $DIR/$tfile O_tSc &
447 # give multiop a chance to open
453 wait $pid || return 1
454 [ -e $DIR/$tfile ] && return 2
457 run_test 20 "|X| open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
461 multiop $DIR/$tfile O_tSc &
463 # give multiop a chance to open
466 touch $DIR/g11 || return 1
470 wait $pid || return 2
471 [ -e $DIR/$tfile ] && return 3
472 touch $DIR/h11 || return 4
475 run_test 21 "|X| open(O_CREAT), unlink touch new, replay, close (test mds_cleanup_orphans)"
478 multiop $DIR/$tfile O_tSc &
480 # give multiop a chance to open
488 wait $pid || return 1
489 [ -e $DIR/$tfile ] && return 2
492 run_test 22 "open(O_CREAT), |X| unlink, replay, close (test mds_cleanup_orphans)"
495 multiop $DIR/$tfile O_tSc &
497 # give multiop a chance to open
502 touch $DIR/g11 || return 1
506 wait $pid || return 2
507 [ -e $DIR/$tfile ] && return 3
508 touch $DIR/h11 || return 4
511 run_test 23 "open(O_CREAT), |X| unlink touch new, replay, close (test mds_cleanup_orphans)"
514 multiop $DIR/$tfile O_tSc &
516 # give multiop a chance to open
523 wait $pid || return 1
524 [ -e $DIR/$tfile ] && return 2
527 run_test 24 "open(O_CREAT), replay, unlink, close (test mds_cleanup_orphans)"
530 multiop $DIR/$tfile O_tSc &
532 # give multiop a chance to open
539 wait $pid || return 1
540 [ -e $DIR/$tfile ] && return 2
543 run_test 25 "open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
547 multiop $DIR/$tfile-1 O_tSc &
549 multiop $DIR/$tfile-2 O_tSc &
551 # give multiop a chance to open
556 wait $pid2 || return 1
560 wait $pid1 || return 2
561 [ -e $DIR/$tfile-1 ] && return 3
562 [ -e $DIR/$tfile-2 ] && return 4
565 run_test 26 "|X| open(O_CREAT), unlink two, close one, replay, close one (test mds_cleanup_orphans)"
569 multiop $DIR/$tfile-1 O_tSc &
571 multiop $DIR/$tfile-2 O_tSc &
573 # give multiop a chance to open
580 wait $pid1 || return 1
582 wait $pid2 || return 2
583 [ -e $DIR/$tfile-1 ] && return 3
584 [ -e $DIR/$tfile-2 ] && return 4
587 run_test 27 "|X| open(O_CREAT), unlink two, replay, close two (test mds_cleanup_orphans)"
590 multiop $DIR/$tfile-1 O_tSc &
592 multiop $DIR/$tfile-2 O_tSc &
594 # give multiop a chance to open
600 wait $pid2 || return 1
604 wait $pid1 || return 2
605 [ -e $DIR/$tfile-1 ] && return 3
606 [ -e $DIR/$tfile-2 ] && return 4
609 run_test 28 "open(O_CREAT), |X| unlink two, close one, replay, close one (test mds_cleanup_orphans)"
612 multiop $DIR/$tfile-1 O_tSc &
614 multiop $DIR/$tfile-2 O_tSc &
616 # give multiop a chance to open
624 wait $pid1 || return 1
626 wait $pid2 || return 2
627 [ -e $DIR/$tfile-1 ] && return 3
628 [ -e $DIR/$tfile-2 ] && return 4
631 run_test 29 "open(O_CREAT), |X| unlink two, replay, close two (test mds_cleanup_orphans)"
634 multiop $DIR/$tfile-1 O_tSc &
636 multiop $DIR/$tfile-2 O_tSc &
638 # give multiop a chance to open
646 wait $pid1 || return 1
648 wait $pid2 || return 2
649 [ -e $DIR/$tfile-1 ] && return 3
650 [ -e $DIR/$tfile-2 ] && return 4
653 run_test 30 "open(O_CREAT) two, unlink two, replay, close two (test mds_cleanup_orphans)"
656 multiop $DIR/$tfile-1 O_tSc &
658 multiop $DIR/$tfile-2 O_tSc &
660 # give multiop a chance to open
668 wait $pid1 || return 1
670 wait $pid2 || return 2
671 [ -e $DIR/$tfile-1 ] && return 3
672 [ -e $DIR/$tfile-2 ] && return 4
675 run_test 31 "open(O_CREAT) two, unlink one, |X| unlink one, close two (test mds_cleanup_orphans)"
677 # tests for bug 2104; completion without crashing is success. The close is
678 # stale, but we always return 0 for close, so the app never sees it.
680 multiop $DIR/$tfile O_c &
682 multiop $DIR/$tfile O_c &
684 # give multiop a chance to open
687 df $MOUNT || df $MOUNT || return 1
693 run_test 32 "close() notices client eviction; close() after client eviction"
695 # Abort recovery before client complete
700 # this file should be gone, because the replay was aborted
701 $CHECKSTAT -t file $DIR/$tfile && return 1
704 run_test 33 "abort recovery before client does replay"
707 multiop $DIR/$tfile O_c &
709 # give multiop a chance to open
716 [ -e $DIR/$tfile ] && return 1
720 run_test 34 "abort recovery before client does replay (test mds_cleanup_orphans)"
722 # bug 2278 - generate one orphan on OST, then destroy it during recovery from llog
726 #define OBD_FAIL_MDS_REINT_NET_REP 0x119
727 do_facet mds "sysctl -w lustre.fail_loc=0x80000119"
732 # give a chance to remove from MDS
734 $CHECKSTAT -t file $DIR/$tfile && return 1 || true
736 run_test 35 "test recovery from llog for unlink op"
738 # b=2432 resent cancel after replay uses wrong cookie,
739 # so don't resend cancels
743 checkstat $DIR/$tfile
746 if dmesg | grep "unknown lock cookie"; then
747 echo "cancel after replay failed"
751 run_test 36 "don't resend cancel"
754 # directory orphans can't be unlinked from PENDING directory
756 rmdir $DIR/$tfile 2>/dev/null
757 multiop $DIR/$tfile dD_c &
759 # give multiop a chance to open
764 # clear the dmesg buffer so we only see errors from this recovery
768 dmesg | grep "mds_unlink_orphan.*error .* unlinking orphan" && return 1
772 run_test 37 "abort recovery before client does replay (test mds_cleanup_orphans for directories)"
775 createmany -o $DIR/$tfile-%d 800
776 unlinkmany $DIR/$tfile-%d 0 400
779 unlinkmany $DIR/$tfile-%d 400 400
781 $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
783 run_test 38 "test recovery from unlink llog (test llog_gen_rec) "
786 createmany -o $DIR/$tfile-%d 800
788 unlinkmany $DIR/$tfile-%d 0 400
790 unlinkmany $DIR/$tfile-%d 400 400
792 $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
794 run_test 39 "test recovery from unlink llog (test llog_gen_rec) "
797 cat /proc/fs/lustre/osc/*/stats |
798 awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
803 $LCTL mark multiop $MOUNT/$tfile OS_c
804 multiop $MOUNT/$tfile OS_c &
806 writeme -s $MOUNT/${tfile}-2 &
810 #define OBD_FAIL_MDS_CONNECT_NET 0x117
811 do_facet mds "sysctl -w lustre.fail_loc=0x80000117"
813 stat1=`count_ost_writes`
815 stat2=`count_ost_writes`
816 echo "$stat1, $stat2"
817 if [ $stat1 -lt $stat2 ]; then
818 echo "writes continuing during recovery"
821 echo "writes not continuing during recovery, bug 2477"
824 echo "waiting for writeme $WRITE_PID"
828 echo "waiting for multiop $PID"
829 wait $PID || return 2
830 do_facet client munlink $MOUNT/$tfile || return 3
831 do_facet client munlink $MOUNT/${tfile}-2 || return 3
834 run_test 40 "cause recovery in ptlrpc, ensure IO continues"
838 # make sure that a read to one osc doesn't try to double-unlock its page just
839 # because another osc is invalid. trigger_group_io used to mistakenly return
840 # an error if any oscs were invalid even after having successfully put rpcs
841 # on valid oscs. This was fatal if the caller was ll_readpage who unlocked
842 # the page, guarnateeing that the unlock from the RPC completion would
843 # assert on trying to unlock the unlocked page.
845 local f=$MOUNT/$tfile
846 # make sure the start of the file is ost1
847 lfs setstripe $f $((128 * 1024)) 0 0
848 do_facet client dd if=/dev/zero of=$f bs=4k count=1 || return 3
850 # fail ost2 and read from ost1
851 local osc2_dev=`$LCTL device_list | \
852 awk '(/ost2.*client_facet/){print $4}' `
853 $LCTL --device %$osc2_dev deactivate
854 do_facet client dd if=$f of=/dev/null bs=4k count=1 || return 3
855 $LCTL --device %$osc2_dev activate
858 run_test 41 "read from a valid osc while other oscs are invalid"
860 # test MDS recovery after ost failure
862 blocks=`df $MOUNT | tail -n 1 | awk '{ print $1 }'`
863 createmany -o $DIR/$tfile-%d 800
865 unlinkmany $DIR/$tfile-%d 0 400
868 # osc is evicted, fs is smaller
869 blocks_after=`df $MOUNT | tail -n 1 | awk '{ print $1 }'`
870 [ $blocks_after -lt $blocks ] || return 1
871 echo wait for MDS to timeout and recover
872 sleep $((TIMEOUT * 2))
873 unlinkmany $DIR/$tfile-%d 400 400
874 $CHECKSTAT -t file $DIR/$tfile-* && return 2 || true
876 run_test 42 "recovery after ost failure"
879 # timeout in MDS/OST recovery RPC will LBUG MDS
883 # OBD_FAIL_OST_CREATE_NET 0x204
884 do_facet ost "sysctl -w lustre.fail_loc=0x80000204"
886 df $MOUNT || return 1
888 do_facet ost "sysctl -w lustre.fail_loc=0"
892 run_test 43 "mds osc import failure during recovery; don't LBUG"
895 mdcdev=`awk '/mds_svc_MNT/ {print $1}' < /proc/fs/lustre/devices`
896 do_facet mds "sysctl -w lustre.fail_loc=0x80000701"
897 $LCTL --device $mdcdev recover
899 do_facet mds "sysctl -w lustre.fail_loc=0"
902 run_test 44 "race in target handle connect"
904 # Handle failed close
906 mdcdev=`awk '/mds_svc_MNT/ {print $1}' < /proc/fs/lustre/devices`
907 $LCTL --device $mdcdev recover
909 multiop $DIR/$tfile O_c &
913 # This will cause the CLOSE to fail before even
914 # allocating a reply buffer
915 $LCTL --device $mdcdev deactivate
919 wait $pid || return 1
921 $LCTL --device $mdcdev activate
923 $CHECKSTAT -t file $DIR/$tfile || return 2
926 run_test 45 "Handle failed close"
930 drop_reply "touch $DIR/$tfile"
932 # ironically, the previous test, 45, will cause a real forced close,
933 # so just look for one for this test
934 dmesg | grep -i "force closing client file handle for $tfile" && return 1
937 run_test 46 "Don't leak file handle after open resend (3325)"
942 # create some files to make sure precreate has been done on all
943 # OSTs. (just in case this test is run independently)
944 createmany -o $DIR/$tfile 20 || return 1
946 # OBD_FAIL_OST_CREATE_NET 0x204
948 do_facet ost "sysctl -w lustre.fail_loc=0x80000204"
949 df $MOUNT || return 2
951 # let the MDS discover the OST failure, attempt to recover, fail
953 sleep $((3 * TIMEOUT))
955 # Without 2824, this createmany would hang
956 createmany -o $DIR/$tfile 20 || return 3
957 unlinkmany $DIR/$tfile 20 || return 4
959 do_facet ost "sysctl -w lustre.fail_loc=0"
962 run_test 47 "MDS->OSC failure during precreate cleanup (2824)"
964 equals_msg test complete, cleaning up