xref: /freebsd/tests/sys/geom/class/multipath/conf.sh (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
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# $FreeBSD$
26
27MD_DEVS="md.devs"
28MULTIPATH_DEVS="multipath.devs"
29
30alloc_md()
31{
32	local md
33
34	md=$(mdconfig -a -t swap -s 1M) || atf_fail "mdconfig -a failed"
35	echo ${md} >> $MD_DEVS
36	echo ${md}
37}
38
39# Verify expected state.
40# check_multipath_state <active_path> <geom_state> <prov0_state> <prov1_state> [prov2_state]
41check_multipath_state()
42{
43	local want_active_path=$1
44	local want_geom_state=$2
45	local want_prov0_state=$3
46	local want_prov1_state=$4
47	local want_prov2_state=$5
48	local geom_state
49	local prov0_state
50	local prov1_state
51	local prov2_state
52
53	geom_state=`gmultipath list "$name" | awk '/^State:/ {print $2}'`
54	atf_check_equal "$want_geom_state" "$geom_state"
55	prov0_state=`gmultipath list "$name" | awk '/1. Name: md[0-9]/ {trigger=1} /State:/ && trigger == 1 {print $2; trigger=0;}'`
56	prov1_state=`gmultipath list "$name" | awk '/2. Name: md[0-9]/ {trigger=1} /State:/ && trigger == 1 {print $2; trigger=0;}'`
57	prov2_state=`gmultipath list "$name" | awk '/3. Name: md[0-9]/ {trigger=1} /State:/ && trigger == 1 {print $2; trigger=0;}'`
58	atf_check_equal "$want_active_path" "`gmultipath getactive "$name"`"
59	atf_check_equal "$want_prov0_state" $prov0_state
60	atf_check_equal "$want_prov1_state" $prov1_state
61	if [ -n "$want_prov2_state" ]; then
62		atf_check_equal "$want_prov2_state" $prov2_state
63	fi
64}
65
66common_cleanup()
67{
68	name=$(cat $MULTIPATH_DEVS)
69	if [ -n "$name" -a -c "/dev/multipath/$name" ]; then
70		gmultipath destroy "$name"
71		rm $MULTIPATH_DEVS
72	fi
73	if [ -f "$MD_DEVS" ]; then
74		while read test_md; do
75			gnop destroy -f ${test_md}.nop 2>/dev/null
76			mdconfig -d -u $test_md 2>/dev/null
77		done < $MD_DEVS
78		rm $MD_DEVS
79	fi
80	true
81}
82
83load_dtrace()
84{
85	if ! kldstat -q -m sdt; then
86		kldload sdt || atf_skip "could not load module for dtrace SDT"
87	fi
88}
89
90load_gmultipath()
91{
92	if ! kldstat -q -m g_multipath; then
93		geom multipath load || atf_skip "could not load module for geom multipath"
94	fi
95}
96
97load_gnop()
98{
99	if ! kldstat -q -m g_nop; then
100		geom nop load || atf_skip "could not load module for geom nop"
101	fi
102}
103
104mkname()
105{
106	mktemp -u mp.XXXXXX | tee $MULTIPATH_DEVS
107}
108