2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
5 # Tests for multiple mount protection (MMP) feature.
7 # Run select tests by setting ONLY, or as arguments to the script.
8 # Skip specific tests by setting EXCEPT.
10 # e.g. ONLY="5 6" or ONLY="`seq 8 11`" or EXCEPT="7"
15 # bug number for skipped test:
16 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"$MMP_EXCEPT"}
17 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
19 SRCDIR=$(cd $(dirname $0); echo $PWD)
20 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH:/sbin
22 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
23 . $LUSTRE/tests/test-framework.sh
25 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
28 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
29 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
31 # unmount and cleanup the Lustre filesystem
32 MMP_RESTORE_MOUNT=false
33 if is_mounted $MOUNT || is_mounted $MOUNT2; then
35 MMP_RESTORE_MOUNT=true
38 SAVED_FAIL_ON_ERROR=$FAIL_ON_ERROR
43 # Get the failover facet.
44 get_failover_facet() {
46 local failover_facet=${facet}failover
48 local host=$(facet_host $facet)
49 local failover_host=$(facet_host $failover_facet)
51 [ -z "$failover_host" -o "$host" = "$failover_host" ] && \
57 # Initiate the variables for Lustre servers and targets.
59 MMP_MDS=${MMP_MDS:-$SINGLEMDS}
60 MMP_MDS_FAILOVER=$(get_failover_facet $MMP_MDS)
62 local mds_num=$(echo $MMP_MDS | tr -d "mds")
63 MMP_MDSDEV=$(mdsdevname $mds_num)
65 MMP_OSS=${MMP_OSS:-ost1}
66 MMP_OSS_FAILOVER=$(get_failover_facet $MMP_OSS)
68 local oss_num=$(echo $MMP_OSS | tr -d "ost")
69 MMP_OSTDEV=$(ostdevname $oss_num)
72 # Stop the MDS and OSS services on the primary or failover servers.
80 if [ "$flavor" = "failover" ]; then
81 mds_facet=$MMP_MDS_FAILOVER
82 oss_facet=$MMP_OSS_FAILOVER
88 stop $mds_facet $opts || return ${PIPESTATUS[0]}
89 stop $oss_facet $opts || return ${PIPESTATUS[0]}
92 # Enable the MMP feature.
97 do_facet $facet "$TUNE2FS -O mmp $device"
98 return ${PIPESTATUS[0]}
101 # Disable the MMP feature.
106 do_facet $facet "$TUNE2FS -O ^mmp $device"
107 return ${PIPESTATUS[0]}
110 # Set the MMP block to 'fsck' state
115 do_facet $facet "$LUSTRE/tests/mmp_mark.sh $device"
116 return ${PIPESTATUS[0]}
119 # Reset the MMP block (if any) back to the clean state.
124 do_facet $facet "$TUNE2FS -f -E clear-mmp $device"
125 return ${PIPESTATUS[0]}
128 # Check whether the MMP feature is enabled or not.
133 do_facet $facet "$DUMPE2FS -h $device | grep mmp"
134 return ${PIPESTATUS[0]}
137 # Get MMP update interval (in seconds) from the Lustre server target.
138 get_mmp_update_interval() {
143 interval=$(do_facet $facet \
144 "$DEBUGFS -c -R dump_mmp $device 2>$TMP/mmp.debugfs.msg" |
145 awk 'tolower($0) ~ /update.interval/ { print $NF }')
146 [ -z "$interval" ] && interval=5 &&
147 do_facet $facet cat $TMP/mmp.debugfs.msg &&
148 echo "$facet:$device: assume update interval=$interval" 1>&2 ||
149 echo "$facet:$device: got actual update interval=$interval" 1>&2
154 # Get MMP check interval (in seconds) from the Lustre server target.
155 get_mmp_check_interval() {
160 interval=$(do_facet $facet \
161 "$DEBUGFS -c -R dump_mmp $device 2>$TMP/mmp.debugfs.msg" |
162 awk 'tolower($0) ~ /check.interval/ { print $NF }')
163 [ -z "$interval" ] && interval=5 &&
164 do_facet $facet cat $TMP/mmp.debugfs.msg &&
165 echo "$facet:$device: assume check interval=$interval" 1>&2 ||
166 echo "$facet:$device: got actual check interval=$interval" 1>&2
171 # Adjust the MMP update interval (in seconds) on the Lustre server target.
172 # Specifying an interval of 0 means to use the default interval.
173 set_mmp_update_interval() {
176 local interval=${3:-0}
178 do_facet $facet "$TUNE2FS -E mmp_update_interval=$interval $device"
179 return ${PIPESTATUS[0]}
185 # Enable the MMP feature on the Lustre server targets.
189 if [ $(facet_fstype $MMP_MDS) != ldiskfs ]; then
190 skip "ldiskfs only test"
194 if [ $(facet_fstype $MMP_OSS) != ldiskfs ]; then
195 skip "ldiskfs only test"
199 mmp_is_enabled $MMP_MDS $MMP_MDSDEV ||
201 log "MMP is not enabled on MDS, enabling it manually..."
202 enable_mmp $MMP_MDS $MMP_MDSDEV ||
203 error "failed to enable MMP on $MMP_MDSDEV on $MMP_MDS"
207 mmp_is_enabled $MMP_OSS $MMP_OSTDEV ||
209 log "MMP is not enabled on OSS, enabling it manually..."
210 enable_mmp $MMP_OSS $MMP_OSTDEV ||
211 error "failed to enable MMP on $MMP_OSTDEV on $MMP_OSS"
215 # check whether the MMP feature is enabled or not
216 mmp_is_enabled $MMP_MDS $MMP_MDSDEV ||
217 error "MMP was not enabled on $MMP_MDSDEV on $MMP_MDS"
219 mmp_is_enabled $MMP_OSS $MMP_OSTDEV ||
220 error "MMP was not enabled on $MMP_OSTDEV on $MMP_OSS"
223 # Disable the MMP feature on the Lustre server targets
226 if [ $I_ENABLED_MDS -eq 1 ]; then
227 log "Disabling MMP on $MMP_MDSDEV on $MMP_MDS manually..."
228 disable_mmp $MMP_MDS $MMP_MDSDEV ||
229 error "failed to disable MMP on $MMP_MDSDEV on $MMP_MDS"
230 mmp_is_enabled $MMP_MDS $MMP_MDSDEV &&
231 error "MMP was not disabled on $MMP_MDSDEV on $MMP_MDS"
234 if [ $I_ENABLED_OSS -eq 1 ]; then
235 log "Disabling MMP on $MMP_OSTDEV on $MMP_OSS manually..."
236 disable_mmp $MMP_OSS $MMP_OSTDEV ||
237 error "failed to disable MMP on $MMP_OSTDEV on $MMP_OSS"
238 mmp_is_enabled $MMP_OSS $MMP_OSTDEV &&
239 error "MMP was not disabled on $MMP_OSTDEV on $MMP_OSS"
245 # Mount the shared target on the failover server after some interval it's
246 # mounted on the primary server.
247 mount_after_interval_sub() {
255 local failover_facet=$(get_failover_facet $facet)
258 local first_mount_rc=0
259 local second_mount_rc=0
261 log "Mounting $device on $facet..."
262 start $facet $device $opts &
265 if [ $interval -ne 0 ]; then
266 log "sleep $interval..."
270 log "Mounting $device on $failover_facet..."
271 start $failover_facet $device $opts
272 second_mount_rc=${PIPESTATUS[0]}
275 first_mount_rc=${PIPESTATUS[0]}
277 if [ $second_mount_rc -eq 0 -a $first_mount_rc -eq 0 ]; then
278 error_noexit "one mount delayed by mmp interval $interval should fail"
279 stop $facet || return ${PIPESTATUS[0]}
280 [ "$failover_facet" != "$facet" ] && stop $failover_facet || \
281 return ${PIPESTATUS[0]}
283 elif [ $second_mount_rc -ne 0 -a $first_mount_rc -ne 0 ]; then
284 error_noexit "mount failure on failover pair $facet,$failover_facet"
285 return $first_mount_rc
291 mount_after_interval() {
292 local mdt_interval=$1
293 local ost_interval=$2
296 mount_after_interval_sub $mdt_interval $MMP_MDSDEV $MMP_MDS \
297 $MDS_MOUNT_OPTS || return ${PIPESTATUS[0]}
300 mount_after_interval_sub $ost_interval $MMP_OSTDEV $MMP_OSS $OST_MOUNT_OPTS
302 if [ $rc -ne 0 ]; then
310 # Mount the shared target on the failover server
311 # during unmounting it on the primary server.
312 mount_during_unmount() {
318 local failover_facet=$(get_failover_facet $facet)
324 log "Mounting $device on $facet..."
325 start $facet $device $mnt_opts || return ${PIPESTATUS[0]}
327 log "Unmounting $device on $facet..."
331 log "Mounting $device on $failover_facet..."
332 start $failover_facet $device $mnt_opts
333 mount_rc=${PIPESTATUS[0]}
336 unmount_rc=${PIPESTATUS[0]}
338 if [ $mount_rc -eq 0 ]; then
339 error_noexit "mount during unmount of the first filesystem should fail"
340 stop $failover_facet || return ${PIPESTATUS[0]}
344 if [ $unmount_rc -ne 0 ]; then
345 error_noexit "unmount the $device on $facet should succeed"
352 # Mount the shared target on the failover server
353 # after clean unmounting it on the primary server.
354 mount_after_unmount() {
360 local failover_facet=$(get_failover_facet $facet)
362 log "Mounting $device on $facet..."
363 start $facet $device $mnt_opts || return ${PIPESTATUS[0]}
365 log "Unmounting $device on $facet..."
366 stop $facet || return ${PIPESTATUS[0]}
368 log "Mounting $device on $failover_facet..."
369 start $failover_facet $device $mnt_opts || return ${PIPESTATUS[0]}
374 # Mount the shared target on the failover server after rebooting
375 # the primary server.
376 mount_after_reboot() {
382 local failover_facet=$(get_failover_facet $facet)
385 log "Mounting $device on $facet..."
386 start $facet $device $mnt_opts || return ${PIPESTATUS[0]}
388 if [ "$FAILURE_MODE" = "HARD" ]; then
389 shutdown_facet $facet
391 wait_for_facet $facet
393 replay_barrier_nodf $facet
396 log "Mounting $device on $failover_facet..."
397 start $failover_facet $device $mnt_opts
399 if [ $rc -ne 0 ]; then
400 error_noexit "mount $device on $failover_facet should succeed"
401 stop $facet || return ${PIPESTATUS[0]}
408 # Run e2fsck on the Lustre server target.
416 echo "Running e2fsck on the device $device on $facet..."
417 do_facet $facet "$E2FSCK $opts $device"
418 return ${PIPESTATUS[0]}
421 # Check whether there are failover pairs for MDS and OSS servers.
422 check_failover_pair() {
423 [ "$MMP_MDS" = "$MMP_MDS_FAILOVER" -o "$MMP_OSS" = "$MMP_OSS_FAILOVER" ] \
424 && { skip_env "failover pair is needed" && return 1; }
430 # Test 1 - two mounts at the same time.
432 check_failover_pair || return 0
434 mount_after_interval 0 0 || return ${PIPESTATUS[0]}
435 stop_services primary || return ${PIPESTATUS[0]}
436 stop_services failover || return ${PIPESTATUS[0]}
438 run_test 1 "two mounts at the same time"
440 # Test 2 - one mount delayed by mmp update interval.
442 check_failover_pair || return 0
444 local mdt_interval=$(get_mmp_update_interval $MMP_MDS $MMP_MDSDEV)
445 local ost_interval=$(get_mmp_update_interval $MMP_OSS $MMP_OSTDEV)
447 mount_after_interval $mdt_interval $ost_interval || return ${PIPESTATUS[0]}
448 stop_services primary || return ${PIPESTATUS[0]}
450 run_test 2 "one mount delayed by mmp update interval"
452 # Test 3 - one mount delayed by 2x mmp check interval.
454 check_failover_pair || return 0
456 local mdt_interval=$(get_mmp_check_interval $MMP_MDS $MMP_MDSDEV)
457 local ost_interval=$(get_mmp_check_interval $MMP_OSS $MMP_OSTDEV)
459 mdt_interval=$((2 * $mdt_interval + 1))
460 ost_interval=$((2 * $ost_interval + 1))
462 mount_after_interval $mdt_interval $ost_interval || return ${PIPESTATUS[0]}
463 stop_services primary || return ${PIPESTATUS[0]}
465 run_test 3 "one mount delayed by 2x mmp check interval"
467 # Test 4 - one mount delayed by > 2x mmp check interval.
469 check_failover_pair || return 0
471 local mdt_interval=$(get_mmp_check_interval $MMP_MDS $MMP_MDSDEV)
472 local ost_interval=$(get_mmp_check_interval $MMP_OSS $MMP_OSTDEV)
474 mdt_interval=$((4 * $mdt_interval))
475 ost_interval=$((4 * $ost_interval))
477 mount_after_interval $mdt_interval $ost_interval || return ${PIPESTATUS[0]}
478 stop_services primary || return ${PIPESTATUS[0]}
480 run_test 4 "one mount delayed by > 2x mmp check interval"
482 # Test 5 - mount during unmount of the first filesystem.
485 check_failover_pair || return 0
487 mount_during_unmount $MMP_MDSDEV $MMP_MDS $MDS_MOUNT_OPTS || \
488 return ${PIPESTATUS[0]}
491 start $MMP_MDS $MMP_MDSDEV $MDS_MOUNT_OPTS || return ${PIPESTATUS[0]}
492 mount_during_unmount $MMP_OSTDEV $MMP_OSS $OST_MOUNT_OPTS
494 if [ $rc -ne 0 ]; then
495 stop $MMP_MDS || return ${PIPESTATUS[0]}
499 stop $MMP_MDS || return ${PIPESTATUS[0]}
501 run_test 5 "mount during unmount of the first filesystem"
503 # Test 6 - mount after clean unmount.
506 check_failover_pair || return 0
508 mount_after_unmount $MMP_MDSDEV $MMP_MDS $MDS_MOUNT_OPTS || \
509 return ${PIPESTATUS[0]}
512 mount_after_unmount $MMP_OSTDEV $MMP_OSS $OST_MOUNT_OPTS
514 if [ $rc -ne 0 ]; then
515 stop $MMP_MDS_FAILOVER || return ${PIPESTATUS[0]}
519 stop_services failover || return ${PIPESTATUS[0]}
521 run_test 6 "mount after clean unmount"
523 # Test 7 - mount after reboot.
526 check_failover_pair || return 0
528 mount_after_reboot $MMP_MDSDEV $MMP_MDS $MDS_MOUNT_OPTS || \
529 return ${PIPESTATUS[0]}
532 mount_after_reboot $MMP_OSTDEV $MMP_OSS $OST_MOUNT_OPTS
534 if [ $rc -ne 0 ]; then
535 stop $MMP_MDS || return ${PIPESTATUS[0]}
536 stop $MMP_MDS_FAILOVER || return ${PIPESTATUS[0]}
540 stop_services failover || return ${PIPESTATUS[0]}
541 stop_services primary || return ${PIPESTATUS[0]}
543 run_test 7 "mount after reboot"
545 # Test 8 - mount during e2fsck (should never succeed).
551 # After writing a new sequence number into the MMP block, e2fsck will
552 # sleep at least (2 * new_interval + 1) seconds before it goes into
557 saved_interval=$(get_mmp_update_interval $MMP_MDS $MMP_MDSDEV)
558 set_mmp_update_interval $MMP_MDS $MMP_MDSDEV $new_interval
560 run_e2fsck $MMP_MDS $MMP_MDSDEV "-fy" &
564 if start $MMP_MDS_FAILOVER $MMP_MDSDEV $MDS_MOUNT_OPTS; then
566 "mount $MMP_MDSDEV on $MMP_MDS_FAILOVER should fail"
567 stop $MMP_MDS_FAILOVER || return ${PIPESTATUS[0]}
568 set_mmp_update_interval $MMP_MDS $MMP_MDSDEV $saved_interval
573 set_mmp_update_interval $MMP_MDS $MMP_MDSDEV $saved_interval
577 saved_interval=$(get_mmp_update_interval $MMP_OSS $MMP_OSTDEV)
578 set_mmp_update_interval $MMP_OSS $MMP_OSTDEV $new_interval
580 run_e2fsck $MMP_OSS $MMP_OSTDEV "-fy" &
584 if start $MMP_OSS_FAILOVER $MMP_OSTDEV $OST_MOUNT_OPTS; then
586 "mount $MMP_OSTDEV on $MMP_OSS_FAILOVER should fail"
587 stop $MMP_OSS_FAILOVER || return ${PIPESTATUS[0]}
588 set_mmp_update_interval $MMP_OSS $MMP_OSTDEV $saved_interval
593 set_mmp_update_interval $MMP_OSS $MMP_OSTDEV $saved_interval
596 run_test 8 "mount during e2fsck"
598 # Test 9 - mount after aborted e2fsck (should never succeed).
600 start $MMP_MDS $MMP_MDSDEV $MDS_MOUNT_OPTS || return ${PIPESTATUS[0]}
601 if ! start $MMP_OSS $MMP_OSTDEV $OST_MOUNT_OPTS; then
602 local rc=${PIPESTATUS[0]}
603 stop $MMP_MDS || return ${PIPESTATUS[0]}
606 stop_services primary || return ${PIPESTATUS[0]}
608 mark_mmp_block $MMP_MDS $MMP_MDSDEV || return ${PIPESTATUS[0]}
610 log "Mounting $MMP_MDSDEV on $MMP_MDS..."
611 if start $MMP_MDS $MMP_MDSDEV $MDS_MOUNT_OPTS; then
612 error_noexit "mount $MMP_MDSDEV on $MMP_MDS should fail"
613 stop $MMP_MDS || return ${PIPESTATUS[0]}
617 reset_mmp_block $MMP_MDS $MMP_MDSDEV || return ${PIPESTATUS[0]}
619 mark_mmp_block $MMP_OSS $MMP_OSTDEV || return ${PIPESTATUS[0]}
621 log "Mounting $MMP_OSTDEV on $MMP_OSS..."
622 if start $MMP_OSS $MMP_OSTDEV $OST_MOUNT_OPTS; then
623 error_noexit "mount $MMP_OSTDEV on $MMP_OSS should fail"
624 stop $MMP_OSS || return ${PIPESTATUS[0]}
628 reset_mmp_block $MMP_OSS $MMP_OSTDEV || return ${PIPESTATUS[0]}
631 run_test 9 "mount after aborted e2fsck"
633 # Test 10 - e2fsck with mounted filesystem.
637 log "Mounting $MMP_MDSDEV on $MMP_MDS..."
638 start $MMP_MDS $MMP_MDSDEV $MDS_MOUNT_OPTS || return ${PIPESTATUS[0]}
640 run_e2fsck $MMP_MDS_FAILOVER $MMP_MDSDEV "-fn"
643 # e2fsck is called with -n option (Open the filesystem read-only), so
644 # 0 (No errors) and 4 (File system errors left uncorrected) are the only
645 # acceptable exit codes in this case
646 if [ $rc -ne 0 ] && [ $rc -ne 4 ]; then
647 error_noexit "e2fsck $MMP_MDSDEV on $MMP_MDS_FAILOVER returned $rc"
648 stop $MMP_MDS || return ${PIPESTATUS[0]}
652 log "Mounting $MMP_OSTDEV on $MMP_OSS..."
653 start $MMP_OSS $MMP_OSTDEV $OST_MOUNT_OPTS
655 if [ $rc -ne 0 ]; then
656 stop $MMP_MDS || return ${PIPESTATUS[0]}
660 run_e2fsck $MMP_OSS_FAILOVER $MMP_OSTDEV "-fn"
662 if [ $rc -ne 0 ] && [ $rc -ne 4 ]; then
663 error_noexit "e2fsck $MMP_OSTDEV on $MMP_OSS_FAILOVER returned $rc"
666 stop_services primary || return ${PIPESTATUS[0]}
669 run_test 10 "e2fsck with mounted filesystem"
672 FAIL_ON_ERROR=$SAVED_FAIL_ON_ERROR
675 $MMP_RESTORE_MOUNT && setupall