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.
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.
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]
23 # Copyright (c) 2017 by Lawrence Livermore National Security, LLC.
24 # Use is subject to license terms.
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/tests/functional/mmp/mmp.cfg
31 function check_pool_import # pool opts token keyword
33 typeset pool=${1:-$MMP_POOL}
38 zpool import $opts 2>&1 | \
39 nawk -v token="$token:" '($1==token) {print $0}' | \
40 grep -i "$keyword" > /dev/null 2>&1
45 function is_pool_imported # pool opts
47 typeset pool=${1:-$MMP_POOL}
50 check_pool_import "$pool" "$opts" "status" \
51 "The pool is currently imported"
55 function wait_pool_imported # pool opts
57 typeset pool=${1:-$MMP_POOL}
60 while is_pool_imported "$pool" "$opts"; do
67 function try_pool_import # pool opts message
69 typeset pool=${1:-$MMP_POOL}
73 zpool import $opts $pool 2>&1 | grep -i "$msg"
78 function mmp_set_hostid
84 if [ $(hostid) != "$hostid" ]; then
91 function mmp_clear_hostid
96 function mmp_pool_create # pool dir
98 typeset pool=${1:-$MMP_POOL}
99 typeset dir=${2:-$MMP_DIR}
100 typeset opts="-T120 -M -k0 -f $dir -E -p $pool"
102 log_must mkdir -p $dir
103 log_must truncate -s $MINVDEVSIZE $dir/vdev1 $dir/vdev2
105 log_must mmp_clear_hostid
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
110 log_must mmp_clear_hostid
111 log_must mmp_set_hostid $HOSTID2
113 log_note "Starting ztest in the background as hostid $HOSTID1"
114 log_must eval "ZFS_HOSTID=$HOSTID1 ztest $opts >/dev/null 2>&1 &"
116 while ! is_pool_imported "$pool" "-d $dir"; do
122 function mmp_pool_destroy # pool dir
124 typeset pool=${1:-$MMP_POOL}
125 typeset dir=${2:-$MMP_DIR}
127 ZTESTPID=$(pgrep ztest)
128 if [ -n "$ZTESTPID" ]; then
129 log_must kill $ZTESTPID
133 if poolexists $pool; then
141 function mmp_pool_set_hostid # pool hostid
146 log_must mmp_clear_hostid
147 log_must mmp_set_hostid $hostid
148 log_must zpool export $pool
149 log_must zpool import $pool
154 function import_no_activity_check # pool opts
160 zpool import $opts $pool
163 if [[ $SECONDS -gt $ZPOOL_IMPORT_DURATION ]]; then
164 log_fail "unexpected activity check (${SECONDS}s)"
170 function import_activity_check # pool opts
176 zpool import $opts $pool
179 if [[ $SECONDS -le $ZPOOL_IMPORT_DURATION ]]; then
180 log_fail "expected activity check (${SECONDS}s)"
186 function clear_mmp_history
188 log_must set_tunable64 zfs_multihost_history $MMP_HISTORY_OFF
189 log_must set_tunable64 zfs_multihost_history $MMP_HISTORY
192 function count_uberblocks # pool duration
195 typeset -i duration=$2
196 typeset hist_path="/proc/spl/kstat/zfs/$pool/multihost"
198 log_must sleep $duration
199 echo $(cat "$hist_path" | sed '1,2d' | wc -l)