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="-VVVVV -T120 -M -k0 -f $dir -E -p $pool"
102 log_must mkdir -p $dir
103 log_must rm -f $dir/*
104 log_must truncate -s $MINVDEVSIZE $dir/vdev1 $dir/vdev2
106 log_must mmp_clear_hostid
107 log_must mmp_set_hostid $HOSTID1
108 log_must zpool create -f -o cachefile=$MMP_CACHE $pool \
109 mirror $dir/vdev1 $dir/vdev2
110 log_must zpool set multihost=on $pool
111 log_must mv $MMP_CACHE ${MMP_CACHE}.stale
112 log_must zpool export $pool
113 log_must mmp_clear_hostid
114 log_must mmp_set_hostid $HOSTID2
116 log_note "Starting ztest in the background as hostid $HOSTID1"
117 log_must eval "ZFS_HOSTID=$HOSTID1 ztest $opts >$MMP_ZTEST_LOG 2>&1 &"
119 while ! is_pool_imported "$pool" "-d $dir"; do
125 function mmp_pool_destroy # pool dir
127 typeset pool=${1:-$MMP_POOL}
128 typeset dir=${2:-$MMP_DIR}
130 ZTESTPID=$(pgrep ztest)
131 if [ -n "$ZTESTPID" ]; then
132 log_must kill $ZTESTPID
136 if poolexists $pool; then
140 log_must rm -f $dir/*
144 function mmp_pool_set_hostid # pool hostid
149 log_must mmp_clear_hostid
150 log_must mmp_set_hostid $hostid
151 log_must zpool export $pool
152 log_must zpool import $pool
157 function import_no_activity_check # pool opts
163 zpool import $opts $pool
166 if [[ $SECONDS -gt $ZPOOL_IMPORT_DURATION ]]; then
167 log_fail "unexpected activity check (${SECONDS}s)"
173 function import_activity_check # pool opts
179 zpool import $opts $pool
182 if [[ $SECONDS -le $ZPOOL_IMPORT_DURATION ]]; then
183 log_fail "expected activity check (${SECONDS}s)"
189 function clear_mmp_history
191 log_must set_tunable64 zfs_multihost_history $MMP_HISTORY_OFF
192 log_must set_tunable64 zfs_multihost_history $MMP_HISTORY
195 function count_uberblocks # pool duration
198 typeset -i duration=$2
199 typeset hist_path="/proc/spl/kstat/zfs/$pool/multihost"
201 log_must sleep $duration
202 echo $(cat "$hist_path" | sed '1,2d' | wc -l)