xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/mmp/mmp_on_uberblocks.ksh (revision eb00b1c8a31c2253a353644606388dff5b0e0275)
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# Copyright 2019 Joyent, Inc.
20#
21
22# DESCRIPTION:
23#	Ensure that MMP updates uberblocks with MMP info at expected intervals.
24#
25# STRATEGY:
26#	1. Set zfs_txg_timeout to large value
27#	2. Create a zpool
28#	3. Clear multihost history
29#	4. Sleep, then collect count of uberblocks written
30#	5. If number of changes seen is less than min threshold, then fail
31#	6. If number of changes seen is more than max threshold, then fail
32#	7. Sequence number increments when no TXGs are syncing
33#
34
35. $STF_SUITE/include/libtest.shlib
36. $STF_SUITE/tests/functional/mmp/mmp.cfg
37. $STF_SUITE/tests/functional/mmp/mmp.kshlib
38
39verify_runnable "both"
40
41UBER_CHANGES=0
42EXPECTED=$(($(echo $DISKS | wc -w) * 10))
43FUDGE=$((EXPECTED * 20 / 100))
44MIN_UB_WRITES=$((EXPECTED - FUDGE))
45MAX_UB_WRITES=$((EXPECTED + FUDGE))
46MIN_SEQ_VALUES=7
47
48function cleanup
49{
50	default_cleanup_noexit
51	log_must set_tunable64 zfs_multihost_interval $MMP_INTERVAL_DEFAULT
52	set_tunable32 zfs_txg_timeout $TXG_TIMEOUT_DEFAULT
53	log_must mmp_clear_hostid
54}
55
56log_assert "Ensure MMP uberblocks update at the correct interval"
57log_onexit cleanup
58
59log_must set_tunable32 zfs_txg_timeout $TXG_TIMEOUT_LONG
60log_must mmp_set_hostid $HOSTID1
61
62default_setup_noexit "$DISKS"
63log_must zpool set multihost=on $TESTPOOL
64clear_mmp_history
65UBER_CHANGES=$(count_mmp_writes $TESTPOOL 10)
66
67log_note "Uberblock changed $UBER_CHANGES times"
68
69if [ $UBER_CHANGES -lt $MIN_UB_WRITES ]; then
70	log_fail "Fewer uberblock writes occured than expected ($EXPECTED)"
71fi
72
73if [ $UBER_CHANGES -gt $MAX_UB_WRITES ]; then
74	log_fail "More uberblock writes occured than expected ($EXPECTED)"
75fi
76
77log_must set_tunable64 zfs_multihost_interval $MMP_INTERVAL_MIN
78SEQ_BEFORE=$(zdb -luuuu ${DISK[0]} | awk '/mmp_seq/ {if ($NF>max) max=$NF}; END {print max}')
79sleep 1
80SEQ_AFTER=$(zdb  -luuuu ${DISK[0]} | awk '/mmp_seq/ {if ($NF>max) max=$NF}; END {print max}')
81if [ $((SEQ_AFTER - SEQ_BEFORE)) -lt $MIN_SEQ_VALUES ]; then
82	zdb -luuuu ${DISK[0]}
83	log_fail "ERROR: mmp_seq did not increase by $MIN_SEQ_VALUES; before $SEQ_BEFORE after $SEQ_AFTER"
84fi
85
86log_pass "Ensure MMP uberblocks update at the correct interval passed"
87