]>
Commit | Line | Data |
---|---|---|
379ca9cf OF |
1 | # |
2 | # CDDL HEADER START | |
3 | # | |
4 | # The contents of this file are subject to the terms of the | |
5 | # Common Development and Distribution License (the "License"). | |
6 | # You may not use this file except in compliance with the License. | |
7 | # | |
8 | # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 | # or http://www.opensolaris.org/os/licensing. | |
10 | # See the License for the specific language governing permissions | |
11 | # and limitations under the License. | |
12 | # | |
13 | # When distributing Covered Code, include this CDDL HEADER in each | |
14 | # file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 | # If applicable, add the following below this CDDL HEADER, with the | |
16 | # fields enclosed by brackets "[]" replaced with your own identifying | |
17 | # information: Portions Copyright [yyyy] [name of copyright owner] | |
18 | # | |
19 | # CDDL HEADER END | |
20 | # | |
21 | ||
22 | # | |
23 | # Copyright (c) 2017 by Lawrence Livermore National Security, LLC. | |
24 | # Use is subject to license terms. | |
25 | # | |
26 | ||
27 | . $STF_SUITE/include/libtest.shlib | |
28 | . $STF_SUITE/tests/functional/mmp/mmp.cfg | |
29 | ||
30 | ||
31 | function check_pool_import # pool opts token keyword | |
32 | { | |
33 | typeset pool=${1:-$MMP_POOL} | |
34 | typeset opts=$2 | |
35 | typeset token=$3 | |
36 | typeset keyword=$4 | |
37 | ||
38 | zpool import $opts 2>&1 | \ | |
39 | nawk -v token="$token:" '($1==token) {print $0}' | \ | |
40 | grep -i "$keyword" > /dev/null 2>&1 | |
41 | ||
42 | return $? | |
43 | } | |
44 | ||
45 | function is_pool_imported # pool opts | |
46 | { | |
47 | typeset pool=${1:-$MMP_POOL} | |
48 | typeset opts=$2 | |
49 | ||
50 | check_pool_import "$pool" "$opts" "status" \ | |
51 | "The pool is currently imported" | |
52 | return $? | |
53 | } | |
54 | ||
55 | function wait_pool_imported # pool opts | |
56 | { | |
57 | typeset pool=${1:-$MMP_POOL} | |
58 | typeset opts=$2 | |
59 | ||
60 | while is_pool_imported "$pool" "$opts"; do | |
61 | log_must sleep 5 | |
62 | done | |
63 | ||
64 | return 0 | |
65 | } | |
66 | ||
67 | function try_pool_import # pool opts message | |
68 | { | |
69 | typeset pool=${1:-$MMP_POOL} | |
70 | typeset opts=$2 | |
71 | typeset msg=$3 | |
72 | ||
73 | zpool import $opts $pool 2>&1 | grep -i "$msg" | |
74 | ||
75 | return $? | |
76 | } | |
77 | ||
78 | function mmp_set_hostid | |
79 | { | |
80 | typeset hostid=$1 | |
81 | ||
b9373170 | 82 | zgenhostid $1 |
379ca9cf OF |
83 | |
84 | if [ $(hostid) != "$hostid" ]; then | |
85 | return 1 | |
86 | fi | |
87 | ||
88 | return 0 | |
89 | } | |
90 | ||
91 | function mmp_clear_hostid | |
92 | { | |
93 | rm -f $HOSTID_FILE | |
94 | } | |
95 | ||
96 | function mmp_pool_create # pool dir | |
97 | { | |
98 | typeset pool=${1:-$MMP_POOL} | |
99 | typeset dir=${2:-$MMP_DIR} | |
100 | typeset opts="-T120 -M -k0 -f $dir -E -p $pool" | |
101 | ||
102 | log_must mkdir -p $dir | |
103 | log_must truncate -s $MINVDEVSIZE $dir/vdev1 $dir/vdev2 | |
104 | ||
b9373170 | 105 | log_must mmp_clear_hostid |
379ca9cf OF |
106 | log_must mmp_set_hostid $HOSTID1 |
107 | log_must zpool create -f $pool mirror $dir/vdev1 $dir/vdev2 | |
108 | log_must zpool set multihost=on $pool | |
109 | log_must zpool export $pool | |
b9373170 | 110 | log_must mmp_clear_hostid |
379ca9cf OF |
111 | log_must mmp_set_hostid $HOSTID2 |
112 | ||
113 | log_note "Starting ztest in the background as hostid $HOSTID1" | |
114 | log_must eval "ZFS_HOSTID=$HOSTID1 ztest $opts >/dev/null 2>&1 &" | |
115 | ||
116 | while ! is_pool_imported "$pool" "-d $dir"; do | |
117 | log_must pgrep ztest | |
118 | log_must sleep 5 | |
119 | done | |
120 | } | |
121 | ||
122 | function mmp_pool_destroy # pool dir | |
123 | { | |
124 | typeset pool=${1:-$MMP_POOL} | |
125 | typeset dir=${2:-$MMP_DIR} | |
126 | ||
127 | ZTESTPID=$(pgrep ztest) | |
128 | if [ -n "$ZTESTPID" ]; then | |
129 | log_must kill $ZTESTPID | |
130 | wait $ZTESTPID | |
131 | fi | |
132 | ||
133 | if poolexists $pool; then | |
134 | destroy_pool $pool | |
135 | fi | |
136 | ||
137 | rm -Rf $dir | |
138 | mmp_clear_hostid | |
139 | } | |
140 | ||
141 | function mmp_pool_set_hostid # pool hostid | |
142 | { | |
143 | typeset pool=$1 | |
144 | typeset hostid=$2 | |
145 | ||
b9373170 | 146 | log_must mmp_clear_hostid |
379ca9cf OF |
147 | log_must mmp_set_hostid $hostid |
148 | log_must zpool export $pool | |
149 | log_must zpool import $pool | |
150 | ||
151 | return 0 | |
152 | } | |
153 | ||
154 | function import_no_activity_check # pool opts | |
155 | { | |
156 | typeset pool=$1 | |
157 | typeset opts=$2 | |
158 | ||
159 | SECONDS=0 | |
160 | zpool import $opts $pool | |
161 | typeset rc=$? | |
162 | ||
163 | if [[ $SECONDS -gt $ZPOOL_IMPORT_DURATION ]]; then | |
164 | log_fail "unexpected activity check (${SECONDS}s)" | |
165 | fi | |
166 | ||
167 | return $rc | |
168 | } | |
169 | ||
170 | function import_activity_check # pool opts | |
171 | { | |
172 | typeset pool=$1 | |
173 | typeset opts=$2 | |
174 | ||
175 | SECONDS=0 | |
176 | zpool import $opts $pool | |
177 | typeset rc=$? | |
178 | ||
179 | if [[ $SECONDS -le $ZPOOL_IMPORT_DURATION ]]; then | |
180 | log_fail "expected activity check (${SECONDS}s)" | |
181 | fi | |
182 | ||
183 | return $rc | |
184 | } | |
af0f8428 GDN |
185 | |
186 | function clear_mmp_history | |
187 | { | |
188 | log_must set_tunable64 zfs_multihost_history $MMP_HISTORY_OFF | |
189 | log_must set_tunable64 zfs_multihost_history $MMP_HISTORY | |
190 | } | |
191 | ||
192 | function count_uberblocks # pool duration | |
193 | { | |
194 | typeset pool=$1 | |
195 | typeset -i duration=$2 | |
196 | typeset hist_path="/proc/spl/kstat/zfs/$pool/multihost" | |
197 | ||
198 | log_must sleep $duration | |
199 | echo $(cat "$hist_path" | sed '1,2d' | wc -l) | |
200 | } |