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 at the expected intervals.
23#
24# STRATEGY:
25#	1. Set zfs_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#
32
33. $STF_SUITE/include/libtest.shlib
34. $STF_SUITE/tests/functional/mmp/mmp.cfg
35. $STF_SUITE/tests/functional/mmp/mmp.kshlib
36
37verify_runnable "both"
38
39UBER_CHANGES=0
40EXPECTED=$(($(echo $DISKS | wc -w) * 10))
41FUDGE=$((EXPECTED * 20 / 100))
42MIN=$((EXPECTED - FUDGE))
43MAX=$((EXPECTED + FUDGE))
44
45function cleanup
46{
47	default_cleanup_noexit
48	set_tunable64 zfs_txg_timeout $TXG_TIMEOUT_DEFAULT
49	log_must mmp_clear_hostid
50}
51
52log_assert "Ensure MMP uberblocks update at the correct interval"
53log_onexit cleanup
54
55log_must set_tunable64 zfs_txg_timeout $TXG_TIMEOUT_LONG
56log_must mmp_set_hostid $HOSTID1
57
58default_setup_noexit "$DISKS"
59log_must zpool set multihost=on $TESTPOOL
60clear_mmp_history
61UBER_CHANGES=$(count_mmp_writes $TESTPOOL 10)
62
63log_note "Uberblock changed $UBER_CHANGES times"
64
65if [ $UBER_CHANGES -lt $MIN ]; then
66	log_fail "Fewer uberblock writes occured than expected ($EXPECTED)"
67fi
68
69if [ $UBER_CHANGES -gt $MAX ]; then
70	log_fail "More uberblock writes occured than expected ($EXPECTED)"
71fi
72
73log_pass "Ensure MMP uberblocks update at the correct interval passed"
74