xref: /freebsd/tests/sys/geom/class/multipath/conf.sh (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1#!/bin/sh
2# Copyright (c) 2019 Axcient
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8#    notice, this list of conditions and the following disclaimer.
9# 2. Redistributions in binary form must reproduce the above copyright
10#    notice, this list of conditions and the following disclaimer in the
11#    documentation and/or other materials provided with the distribution.
12#
13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23# SUCH DAMAGE.
24#
25
26MD_DEVS="md.devs"
27MULTIPATH_DEVS="multipath.devs"
28
29alloc_md()
30{
31	local md
32
33	md=$(mdconfig -a -t swap -s 1M) || atf_fail "mdconfig -a failed"
34	echo ${md} >> $MD_DEVS
35	echo ${md}
36}
37
38# Verify expected state.
39# check_multipath_state <active_path> <geom_state> <prov0_state> <prov1_state> [prov2_state]
40check_multipath_state()
41{
42	local want_active_path=$1
43	local want_geom_state=$2
44	local want_prov0_state=$3
45	local want_prov1_state=$4
46	local want_prov2_state=$5
47	local geom_state
48	local prov0_state
49	local prov1_state
50	local prov2_state
51
52	geom_state=`gmultipath list "$name" | awk '/^State:/ {print $2}'`
53	atf_check_equal "$want_geom_state" "$geom_state"
54	prov0_state=`gmultipath list "$name" | awk '/1. Name: md[0-9]/ {trigger=1} /State:/ && trigger == 1 {print $2; trigger=0;}'`
55	prov1_state=`gmultipath list "$name" | awk '/2. Name: md[0-9]/ {trigger=1} /State:/ && trigger == 1 {print $2; trigger=0;}'`
56	prov2_state=`gmultipath list "$name" | awk '/3. Name: md[0-9]/ {trigger=1} /State:/ && trigger == 1 {print $2; trigger=0;}'`
57	atf_check_equal "$want_active_path" "`gmultipath getactive "$name"`"
58	atf_check_equal "$want_prov0_state" $prov0_state
59	atf_check_equal "$want_prov1_state" $prov1_state
60	if [ -n "$want_prov2_state" ]; then
61		atf_check_equal "$want_prov2_state" $prov2_state
62	fi
63}
64
65common_cleanup()
66{
67	name=$(cat $MULTIPATH_DEVS)
68	if [ -n "$name" -a -c "/dev/multipath/$name" ]; then
69		gmultipath destroy "$name"
70		rm $MULTIPATH_DEVS
71	fi
72	if [ -f "$MD_DEVS" ]; then
73		while read test_md; do
74			gnop destroy -f ${test_md}.nop 2>/dev/null
75			mdconfig -d -u $test_md 2>/dev/null
76		done < $MD_DEVS
77		rm $MD_DEVS
78	fi
79	true
80}
81
82load_dtrace()
83{
84	if ! kldstat -q -m sdt; then
85		kldload sdt || atf_skip "could not load module for dtrace SDT"
86	fi
87}
88
89load_gmultipath()
90{
91	if ! kldstat -q -m g_multipath; then
92		geom multipath load || atf_skip "could not load module for geom multipath"
93	fi
94}
95
96load_gnop()
97{
98	if ! kldstat -q -m g_nop; then
99		geom nop load || atf_skip "could not load module for geom nop"
100	fi
101}
102
103mkname()
104{
105	mktemp -u mp.XXXXXX | tee $MULTIPATH_DEVS
106}
107