Path: blob/main/tests/sys/geom/class/multipath/conf.sh
39636 views
#!/bin/sh1# Copyright (c) 2019 Axcient2#3# Redistribution and use in source and binary forms, with or without4# modification, are permitted provided that the following conditions5# are met:6# 1. Redistributions of source code must retain the above copyright7# notice, this list of conditions and the following disclaimer.8# 2. Redistributions in binary form must reproduce the above copyright9# notice, this list of conditions and the following disclaimer in the10# documentation and/or other materials provided with the distribution.11#12# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND13# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE14# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE15# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE16# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL17# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS18# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)19# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT20# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY21# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF22# SUCH DAMAGE.23#2425MD_DEVS="md.devs"26MULTIPATH_DEVS="multipath.devs"2728alloc_md()29{30local md3132md=$(mdconfig -a -t swap -s 1M) || atf_fail "mdconfig -a failed"33echo ${md} >> $MD_DEVS34echo ${md}35}3637# Verify expected state.38# check_multipath_state <active_path> <geom_state> <prov0_state> <prov1_state> [prov2_state]39check_multipath_state()40{41local want_active_path=$142local want_geom_state=$243local want_prov0_state=$344local want_prov1_state=$445local want_prov2_state=$546local geom_state47local prov0_state48local prov1_state49local prov2_state5051geom_state=`gmultipath list "$name" | awk '/^State:/ {print $2}'`52atf_check_equal "$want_geom_state" "$geom_state"53prov0_state=`gmultipath list "$name" | awk '/1. Name: md[0-9]/ {trigger=1} /State:/ && trigger == 1 {print $2; trigger=0;}'`54prov1_state=`gmultipath list "$name" | awk '/2. Name: md[0-9]/ {trigger=1} /State:/ && trigger == 1 {print $2; trigger=0;}'`55prov2_state=`gmultipath list "$name" | awk '/3. Name: md[0-9]/ {trigger=1} /State:/ && trigger == 1 {print $2; trigger=0;}'`56atf_check_equal "$want_active_path" "`gmultipath getactive "$name"`"57atf_check_equal "$want_prov0_state" $prov0_state58atf_check_equal "$want_prov1_state" $prov1_state59if [ -n "$want_prov2_state" ]; then60atf_check_equal "$want_prov2_state" $prov2_state61fi62}6364common_cleanup()65{66name=$(cat $MULTIPATH_DEVS)67if [ -n "$name" -a -c "/dev/multipath/$name" ]; then68gmultipath destroy "$name"69rm $MULTIPATH_DEVS70fi71if [ -f "$MD_DEVS" ]; then72while read test_md; do73gnop destroy -f ${test_md}.nop 2>/dev/null74mdconfig -d -u $test_md 2>/dev/null75done < $MD_DEVS76rm $MD_DEVS77fi78true79}8081load_dtrace()82{83if ! kldstat -q -m sdt; then84kldload sdt || atf_skip "could not load module for dtrace SDT"85fi86}8788load_gmultipath()89{90if ! kldstat -q -m g_multipath; then91geom multipath load || atf_skip "could not load module for geom multipath"92fi93}9495load_gnop()96{97if ! kldstat -q -m g_nop; then98geom nop load || atf_skip "could not load module for geom nop"99fi100}101102mkname()103{104mktemp -u mp.XXXXXX | tee $MULTIPATH_DEVS105}106107108