1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright (c) 2017 by Lawrence Livermore National Security, LLC.
19#
20
21# DESCRIPTION:
22#	Ensure that MMP updates uberblocks with MMP info at expected intervals.
23#
24# STRATEGY:
25#	1. Set TXG_TIMEOUT to large value
26#	2. Create a zpool
27#	3. Clear multihost history
28#	4. Sleep, then collect count of uberblocks written
29#	5. If number of changes seen is less than min threshold, then fail
30#	6. If number of changes seen is more than max threshold, then fail
31#	7. Sequence number increments when no TXGs are syncing
32#
33
34. $STF_SUITE/include/libtest.shlib
35. $STF_SUITE/tests/functional/mmp/mmp.cfg
36. $STF_SUITE/tests/functional/mmp/mmp.kshlib
37
38verify_runnable "both"
39
40UBER_CHANGES=0
41EXPECTED=$(($(echo $DISKS | wc -w) * 10))
42FUDGE=$((EXPECTED * 20 / 100))
43MIN_UB_WRITES=$((EXPECTED - FUDGE))
44MAX_UB_WRITES=$((EXPECTED + FUDGE))
45MIN_SEQ_VALUES=7
46
47function cleanup
48{
49	default_cleanup_noexit
50	log_must set_tunable64 MULTIHOST_INTERVAL $MMP_INTERVAL_DEFAULT
51	set_tunable64 TXG_TIMEOUT $TXG_TIMEOUT_DEFAULT
52	log_must mmp_clear_hostid
53}
54
55log_assert "Ensure MMP uberblocks update at the correct interval"
56log_onexit cleanup
57
58log_must set_tunable64 TXG_TIMEOUT $TXG_TIMEOUT_LONG
59log_must mmp_set_hostid $HOSTID1
60
61default_setup_noexit "$DISKS"
62log_must zpool set multihost=on $TESTPOOL
63clear_mmp_history
64UBER_CHANGES=$(count_mmp_writes $TESTPOOL 10)
65
66log_note "Uberblock changed $UBER_CHANGES times"
67
68if [ $UBER_CHANGES -lt $MIN_UB_WRITES ]; then
69	log_fail "Fewer uberblock writes occurred than expected ($EXPECTED)"
70fi
71
72if [ $UBER_CHANGES -gt $MAX_UB_WRITES ]; then
73	log_fail "More uberblock writes occurred than expected ($EXPECTED)"
74fi
75
76log_must set_tunable64 MULTIHOST_INTERVAL $MMP_INTERVAL_MIN
77SEQ_BEFORE=$(zdb -luuuu ${DISK[0]} | awk '/mmp_seq/ {if ($NF>max) max=$NF}; END {print max}')
78sleep 1
79SEQ_AFTER=$(zdb  -luuuu ${DISK[0]} | awk '/mmp_seq/ {if ($NF>max) max=$NF}; END {print max}')
80if [ $((SEQ_AFTER - SEQ_BEFORE)) -lt $MIN_SEQ_VALUES ]; then
81	zdb -luuuu ${DISK[0]}
82	log_fail "ERROR: mmp_seq did not increase by $MIN_SEQ_VALUES; before $SEQ_BEFORE after $SEQ_AFTER"
83fi
84
85log_pass "Ensure MMP uberblocks update at the correct interval passed"
86