]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/mmp/mmp_on_uberblocks.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / mmp / mmp_on_uberblocks.ksh
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
38 verify_runnable "both"
39
40 UBER_CHANGES=0
41 EXPECTED=$(($(echo $DISKS | wc -w) * 10))
42 FUDGE=$((EXPECTED * 20 / 100))
43 MIN_UB_WRITES=$((EXPECTED - FUDGE))
44 MAX_UB_WRITES=$((EXPECTED + FUDGE))
45 MIN_SEQ_VALUES=7
46
47 function 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
55 log_assert "Ensure MMP uberblocks update at the correct interval"
56 log_onexit cleanup
57
58 log_must set_tunable64 TXG_TIMEOUT $TXG_TIMEOUT_LONG
59 log_must mmp_set_hostid $HOSTID1
60
61 default_setup_noexit "$DISKS"
62 log_must zpool set multihost=on $TESTPOOL
63 clear_mmp_history
64 UBER_CHANGES=$(count_mmp_writes $TESTPOOL 10)
65
66 log_note "Uberblock changed $UBER_CHANGES times"
67
68 if [ $UBER_CHANGES -lt $MIN_UB_WRITES ]; then
69         log_fail "Fewer uberblock writes occurred than expected ($EXPECTED)"
70 fi
71
72 if [ $UBER_CHANGES -gt $MAX_UB_WRITES ]; then
73         log_fail "More uberblock writes occurred than expected ($EXPECTED)"
74 fi
75
76 log_must set_tunable64 MULTIHOST_INTERVAL $MMP_INTERVAL_MIN
77 SEQ_BEFORE=$(zdb -luuuu ${DISK[0]} | awk '/mmp_seq/ {if ($NF>max) max=$NF}; END {print max}')
78 sleep 1
79 SEQ_AFTER=$(zdb  -luuuu ${DISK[0]} | awk '/mmp_seq/ {if ($NF>max) max=$NF}; END {print max}')
80 if [ $((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"
83 fi
84
85 log_pass "Ensure MMP uberblocks update at the correct interval passed"