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
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 3a "replay failed open(O_DIRECTORY)"
122 #define OBD_FAIL_MDS_OPEN_PACK | OBD_FAIL_ONCE
123 do_facet mds "sysctl -w lustre.fail_loc=0x80000114"
125 do_facet mds "sysctl -w lustre.fail_loc=0"
127 $CHECKSTAT -t file $DIR/$tfile && return 2
130 run_test 3b "replay failed open -ENOMEM"
134 #define OBD_FAIL_MDS_ALLOC_OBDO | OBD_FAIL_ONCE
135 do_facet mds "sysctl -w lustre.fail_loc=0x80000128"
137 do_facet mds "sysctl -w lustre.fail_loc=0"
140 $CHECKSTAT -t file $DIR/$tfile && return 2
143 run_test 3c "replay failed open -ENOMEM"
147 for i in `seq 10`; do
148 echo "tag-$i" > $DIR/$tfile-$i
151 for i in `seq 10`; do
152 grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
155 run_test 4 "|x| 10 open(O_CREAT)s"
161 $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
163 run_test 4b "|x| rm 10 files"
165 # The idea is to get past the first block of precreated files on both
166 # osts, and then replay.
169 for i in `seq 220`; do
170 echo "tag-$i" > $DIR/$tfile-$i
173 for i in `seq 220`; do
174 grep -q "tag-$i" $DIR/$tfile-$i || error "f1c-$i"
178 # waiting for commitment of removal
180 run_test 5 "|x| 220 open(O_CREAT)"
186 mcreate $DIR/$tdir/$tfile
188 $CHECKSTAT -t dir $DIR/$tdir || return 1
189 $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
191 # waiting for log process thread
193 run_test 6 "mkdir + contained create"
199 $CHECKSTAT -t dir $DIR/$tdir && return 1 || true
201 run_test 6b "|X| rmdir"
206 mcreate $DIR/$tdir/$tfile
208 $CHECKSTAT -t dir $DIR/$tdir || return 1
209 $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
212 run_test 7 "mkdir |X| contained create"
216 multiop $DIR/$tfile mo_c &
221 $CHECKSTAT -t file $DIR/$tfile || return 1
222 kill -USR1 $MULTIPID || return 2
223 wait $MULTIPID || return 3
226 run_test 8 "creat open |X| close"
231 local old_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
233 local new_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
235 echo " old_inum == $old_inum, new_inum == $new_inum"
236 if [ $old_inum -eq $new_inum ] ;
238 echo " old_inum and new_inum match"
240 echo "!!!! old_inum and new_inum NOT match"
245 run_test 9 "|X| create (same inum/gen)"
250 mv $DIR/$tfile $DIR/$tfile-2
253 $CHECKSTAT $DIR/$tfile && return 1
254 $CHECKSTAT $DIR/$tfile-2 ||return 2
258 run_test 10 "create |X| rename unlink"
262 echo "old" > $DIR/$tfile
263 mv $DIR/$tfile $DIR/$tfile-2
265 echo "new" > $DIR/$tfile
267 grep old $DIR/$tfile-2
269 grep new $DIR/$tfile || return 1
270 grep old $DIR/$tfile-2 || return 2
272 run_test 11 "create open write rename |X| create-old-name read"
276 multiop $DIR/$tfile o_tSc &
278 # give multiop a chance to open
283 wait $pid || return 1
286 [ -e $DIR/$tfile ] && return 2
289 run_test 12 "open, unlink |X| close"
292 # 1777 - replay open after committed chmod that would make
293 # a regular open a failure
296 multiop $DIR/$tfile O_wc &
298 # give multiop a chance to open
301 $CHECKSTAT -p 0 $DIR/$tfile
305 wait $pid || return 1
307 $CHECKSTAT -s 1 -p 0 $DIR/$tfile || return 2
310 run_test 13 "open chmod 0 |x| write close"
313 multiop $DIR/$tfile O_tSc &
315 # give multiop a chance to open
319 kill -USR1 $pid || return 1
320 wait $pid || return 2
323 [ -e $DIR/$tfile ] && return 3
326 run_test 14 "open(O_CREAT), unlink |X| close"
329 multiop $DIR/$tfile O_tSc &
331 # give multiop a chance to open
335 touch $DIR/g11 || return 1
337 wait $pid || return 2
340 [ -e $DIR/$tfile ] && return 3
341 touch $DIR/h11 || return 4
344 run_test 15 "open(O_CREAT), unlink |X| touch new, close"
351 mcreate $DIR/$tfile-2
353 [ -e $DIR/$tfile ] && return 1
354 [ -e $DIR/$tfile-2 ] || return 2
355 munlink $DIR/$tfile-2 || return 3
357 run_test 16 "|X| open(O_CREAT), unlink, touch new, unlink new"
361 multiop $DIR/$tfile O_c &
363 # give multiop a chance to open
366 kill -USR1 $pid || return 1
367 wait $pid || return 2
368 $CHECKSTAT -t file $DIR/$tfile || return 3
371 run_test 17 "|X| open(O_CREAT), |replay| close"
375 multiop $DIR/$tfile O_tSc &
377 # give multiop a chance to open
380 touch $DIR/$tfile-2 || return 1
381 echo "pid: $pid will close"
383 wait $pid || return 2
386 [ -e $DIR/$tfile ] && return 3
387 [ -e $DIR/$tfile-2 ] || return 4
388 # this touch frequently fails
389 touch $DIR/$tfile-3 || return 5
390 munlink $DIR/$tfile-2 || return 6
391 munlink $DIR/$tfile-3 || return 7
394 run_test 18 "|X| open(O_CREAT), unlink, touch new, close, touch, unlink"
396 # bug 1855 (a simpler form of test_11 above)
400 echo "old" > $DIR/$tfile
401 mv $DIR/$tfile $DIR/$tfile-2
402 grep old $DIR/$tfile-2
404 grep old $DIR/$tfile-2 || return 2
406 run_test 19 "|X| mcreate, open, write, rename "
410 multiop $DIR/$tfile O_tSc &
412 # give multiop a chance to open
418 wait $pid || return 1
419 [ -e $DIR/$tfile ] && return 2
422 run_test 20 "|X| open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
426 multiop $DIR/$tfile O_tSc &
428 # give multiop a chance to open
431 touch $DIR/g11 || return 1
435 wait $pid || return 2
436 [ -e $DIR/$tfile ] && return 3
437 touch $DIR/h11 || return 4
440 run_test 21 "|X| open(O_CREAT), unlink touch new, replay, close (test mds_cleanup_orphans)"
443 multiop $DIR/$tfile O_tSc &
445 # give multiop a chance to open
453 wait $pid || return 1
454 [ -e $DIR/$tfile ] && return 2
457 run_test 22 "open(O_CREAT), |X| unlink, replay, close (test mds_cleanup_orphans)"
460 multiop $DIR/$tfile O_tSc &
462 # give multiop a chance to open
467 touch $DIR/g11 || return 1
471 wait $pid || return 2
472 [ -e $DIR/$tfile ] && return 3
473 touch $DIR/h11 || return 4
476 run_test 23 "open(O_CREAT), |X| unlink touch new, replay, close (test mds_cleanup_orphans)"
479 multiop $DIR/$tfile O_tSc &
481 # give multiop a chance to open
488 wait $pid || return 1
489 [ -e $DIR/$tfile ] && return 2
492 run_test 24 "open(O_CREAT), replay, unlink, close (test mds_cleanup_orphans)"
495 multiop $DIR/$tfile O_tSc &
497 # give multiop a chance to open
504 wait $pid || return 1
505 [ -e $DIR/$tfile ] && return 2
508 run_test 25 "open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
512 multiop $DIR/$tfile-1 O_tSc &
514 multiop $DIR/$tfile-2 O_tSc &
516 # give multiop a chance to open
521 wait $pid2 || return 1
525 wait $pid1 || return 2
526 [ -e $DIR/$tfile-1 ] && return 3
527 [ -e $DIR/$tfile-2 ] && return 4
530 run_test 26 "|X| open(O_CREAT), unlink two, close one, replay, close one (test mds_cleanup_orphans)"
534 multiop $DIR/$tfile-1 O_tSc &
536 multiop $DIR/$tfile-2 O_tSc &
538 # give multiop a chance to open
545 wait $pid1 || return 1
547 wait $pid2 || return 2
548 [ -e $DIR/$tfile-1 ] && return 3
549 [ -e $DIR/$tfile-2 ] && return 4
552 run_test 27 "|X| open(O_CREAT), unlink two, replay, close two (test mds_cleanup_orphans)"
555 multiop $DIR/$tfile-1 O_tSc &
557 multiop $DIR/$tfile-2 O_tSc &
559 # give multiop a chance to open
565 wait $pid2 || return 1
569 wait $pid1 || return 2
570 [ -e $DIR/$tfile-1 ] && return 3
571 [ -e $DIR/$tfile-2 ] && return 4
574 run_test 28 "open(O_CREAT), |X| unlink two, close one, replay, close one (test mds_cleanup_orphans)"
577 multiop $DIR/$tfile-1 O_tSc &
579 multiop $DIR/$tfile-2 O_tSc &
581 # give multiop a chance to open
589 wait $pid1 || return 1
591 wait $pid2 || return 2
592 [ -e $DIR/$tfile-1 ] && return 3
593 [ -e $DIR/$tfile-2 ] && return 4
596 run_test 29 "open(O_CREAT), |X| unlink two, replay, close two (test mds_cleanup_orphans)"
599 multiop $DIR/$tfile-1 O_tSc &
601 multiop $DIR/$tfile-2 O_tSc &
603 # give multiop a chance to open
611 wait $pid1 || return 1
613 wait $pid2 || return 2
614 [ -e $DIR/$tfile-1 ] && return 3
615 [ -e $DIR/$tfile-2 ] && return 4
618 run_test 30 "open(O_CREAT) two, unlink two, replay, close two (test mds_cleanup_orphans)"
621 multiop $DIR/$tfile-1 O_tSc &
623 multiop $DIR/$tfile-2 O_tSc &
625 # give multiop a chance to open
633 wait $pid1 || return 1
635 wait $pid2 || return 2
636 [ -e $DIR/$tfile-1 ] && return 3
637 [ -e $DIR/$tfile-2 ] && return 4
640 run_test 31 "open(O_CREAT) two, unlink one, |X| unlink one, close two (test mds_cleanup_orphans)"
642 # tests for bug 2104; completion without crashing is success. The close is
643 # stale, but we always return 0 for close, so the app never sees it.
645 multiop $DIR/$tfile O_c &
647 multiop $DIR/$tfile O_c &
649 # give multiop a chance to open
652 df $MOUNT || df $MOUNT || return 1
658 run_test 32 "close() notices client eviction; close() after client eviction"
660 # Abort recovery before client complete
665 # this file should be gone, because the replay was aborted
666 $CHECKSTAT -t file $DIR/$tfile && return 1
669 run_test 33 "abort recovery before client does replay"
672 multiop $DIR/$tfile O_c &
674 # give multiop a chance to open
681 [ -e $DIR/$tfile ] && return 1
685 run_test 34 "abort recovery before client does replay (test mds_cleanup_orphans)"
687 # bug 2278 - generate one orphan on OST, then destroy it during recovery from llog
691 #define OBD_FAIL_MDS_REINT_NET_REP 0x119
692 do_facet mds "sysctl -w lustre.fail_loc=0x80000119"
697 # give a chance to remove from MDS
699 $CHECKSTAT -t file $DIR/$tfile && return 1 || true
701 run_test 35 "test recovery from llog for unlink op"
703 # b=2432 resent cancel after replay uses wrong cookie,
704 # so don't resend cancels
708 checkstat $DIR/$tfile
711 if dmesg | grep "unknown lock cookie"; then
712 echo "cancel after replay failed"
716 run_test 36 "don't resend cancel"
719 # directory orphans can't be unlinked from PENDING directory
721 rmdir $DIR/$tfile 2>/dev/null
722 multiop $DIR/$tfile dD_c &
724 # give multiop a chance to open
729 # clear the dmesg buffer so we only see errors from this recovery
733 dmesg | grep "mds_unlink_orphan.*error .* unlinking orphan" && return 1
737 run_test 37 "abort recovery before client does replay (test mds_cleanup_orphans for directories)"
740 createmany -o $DIR/$tfile-%d 800
741 unlinkmany $DIR/$tfile-%d 0 400
744 unlinkmany $DIR/$tfile-%d 400 400
746 $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
748 run_test 38 "test recovery from unlink llog (test llog_gen_rec) "
751 createmany -o $DIR/$tfile-%d 800
753 unlinkmany $DIR/$tfile-%d 0 400
755 unlinkmany $DIR/$tfile-%d 400 400
757 $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
759 run_test 39 "test recovery from unlink llog (test llog_gen_rec) "
762 cat /proc/fs/lustre/osc/*/stats |
763 awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
768 $LCTL mark multiop $MOUNT/$tfile OS_c
769 multiop $MOUNT/$tfile OS_c &
771 writeme -s $MOUNT/${tfile}-2 &
775 #define OBD_FAIL_MDS_CONNECT_NET 0x117
776 do_facet mds "sysctl -w lustre.fail_loc=0x80000117"
778 stat1=`count_ost_writes`
780 stat2=`count_ost_writes`
781 echo "$stat1, $stat2"
782 if [ $stat1 -lt $stat2 ]; then
783 echo "writes continuing during recovery"
786 echo "writes not continuing during recovery, bug 2477"
789 echo "waiting for writeme $WRITE_PID"
793 echo "waiting for multiop $PID"
794 wait $PID || return 2
795 do_facet client munlink $MOUNT/$tfile || return 3
796 do_facet client munlink $MOUNT/${tfile}-2 || return 3
799 run_test 40 "cause recovery in ptlrpc, ensure IO continues"
803 # make sure that a read to one osc doesn't try to double-unlock its page just
804 # because another osc is invalid. trigger_group_io used to mistakenly return
805 # an error if any oscs were invalid even after having successfully put rpcs
806 # on valid oscs. This was fatal if the caller was ll_readpage who unlocked
807 # the page, guarnateeing that the unlock from the RPC completion would
808 # assert on trying to unlock the unlocked page.
810 local f=$MOUNT/$tfile
811 # make sure the start of the file is ost1
812 lfs setstripe $f $((128 * 1024)) 0 0
813 do_facet client dd if=/dev/zero of=$f bs=4k count=1 || return 3
815 # fail ost2 and read from ost1
816 local osc2_dev=`$LCTL device_list | \
817 awk '(/ost2.*client_facet/){print $4}' `
818 $LCTL --device %$osc2_dev deactivate
819 do_facet client dd if=$f of=/dev/null bs=4k count=1 || return 3
820 $LCTL --device %$osc2_dev activate
823 run_test 41 "read from a valid osc while other oscs are invalid"
825 # test MDS recovery after ost failure
827 blocks=`df $MOUNT | tail -1 | awk '{ print $1 }'`
828 createmany -o $DIR/$tfile-%d 800
830 unlinkmany $DIR/$tfile-%d 0 400
833 # osc is evicted, fs is smaller
834 blocks_after=`df $MOUNT | tail -1 | awk '{ print $1 }'`
835 [ $blocks_after -lt $blocks ] || return 1
836 echo wait for MDS to timeout and recover
837 sleep $((TIMEOUT * 2))
838 unlinkmany $DIR/$tfile-%d 400 400
839 $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
841 run_test 42 "recovery after ost failure"
844 # directory orphans can't be unlinked from PENDING directory
848 # OBD_FAIL_OST_CREATE_NET 0x204
849 do_facet ost "sysctl -w lustre.fail_loc=0x80000204"
851 df $MOUNT || return 1
853 do_facet ost "sysctl -w lustre.fail_loc=0"
857 run_test 43 "mds osc import failure during recovery; don't LBUG"
860 mdcdev=`awk '/mds_svc_MNT/ {print $1}' < /proc/fs/lustre/devices`
861 do_facet mds "sysctl -w lustre.fail_loc=0x80000701"
862 $LCTL --device $mdcdev recover
864 do_facet mds "sysctl -w lustre.fail_loc=0"
867 run_test 44 "race in target handle connect"
869 # Handle failed close
871 mdcdev=`awk '/mds_svc_MNT/ {print $1}' < /proc/fs/lustre/devices`
872 $LCTL --device $mdcdev recover
874 multiop $DIR/$tfile O_c &
877 # This will cause the CLOSE to fail before even
878 # allocating a reply buffer
879 $LCTL --device $mdcdev deactivate
883 wait $pid || return 1
885 $LCTL --device $mdcdev activate
887 $CHECKSTAT -t file $DIR/$tfile || return 2
890 run_test 45 "Handle failed close"
892 equals_msg test complete, cleaning up