1*4d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause 2809a8352SAlan Somers# 383406320SAlan Somers# Copyright (c) 2018 Alan Somers 483406320SAlan Somers# 583406320SAlan Somers# Redistribution and use in source and binary forms, with or without 683406320SAlan Somers# modification, are permitted provided that the following conditions 783406320SAlan Somers# are met: 883406320SAlan Somers# 1. Redistributions of source code must retain the above copyright 983406320SAlan Somers# notice, this list of conditions and the following disclaimer. 1083406320SAlan Somers# 2. Redistributions in binary form must reproduce the above copyright 1183406320SAlan Somers# notice, this list of conditions and the following disclaimer in the 1283406320SAlan Somers# documentation and/or other materials provided with the distribution. 1383406320SAlan Somers# 1483406320SAlan Somers# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1583406320SAlan Somers# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1683406320SAlan Somers# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1783406320SAlan Somers# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1883406320SAlan Somers# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1983406320SAlan Somers# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2083406320SAlan Somers# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2183406320SAlan Somers# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2283406320SAlan Somers# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2383406320SAlan Somers# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2483406320SAlan Somers# SUCH DAMAGE. 2583406320SAlan Somers# 2683406320SAlan Somers 2783406320SAlan SomersMD_DEVS="md.devs" 2883406320SAlan Somers 2983406320SAlan Somersatf_test_case blank_physpath cleanup 3083406320SAlan Somersblank_physpath_head() 3183406320SAlan Somers{ 3283406320SAlan Somers atf_set "descr" "gpart shouldn't add physical paths to underlying providers that have none" 3383406320SAlan Somers atf_set "require.user" "root" 3483406320SAlan Somers} 3583406320SAlan Somersblank_physpath_body() 3683406320SAlan Somers{ 3783406320SAlan Somers load_gnop 3883406320SAlan Somers load_gpart 3983406320SAlan Somers md=$(alloc_md) 4083406320SAlan Somers atf_check -o empty -e ignore diskinfo -p ${md} 4183406320SAlan Somers atf_check -s exit:0 -o ignore gpart create -s bsd ${md} 4283406320SAlan Somers atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md} 4383406320SAlan Somers atf_check -o empty -e ignore diskinfo -p ${md}a 4483406320SAlan Somers} 4583406320SAlan Somersblank_physpath_cleanup() 4683406320SAlan Somers{ 4783406320SAlan Somers common_cleanup 4883406320SAlan Somers} 4983406320SAlan Somers 5083406320SAlan Somers 5183406320SAlan Somersatf_test_case bsd_physpath cleanup 5283406320SAlan Somersbsd_physpath_head() 5383406320SAlan Somers{ 5483406320SAlan Somers atf_set "descr" "BSD partitions should append /X to the underlying device's physical path" 5583406320SAlan Somers atf_set "require.user" "root" 5683406320SAlan Somers} 5783406320SAlan Somersbsd_physpath_body() 5883406320SAlan Somers{ 5983406320SAlan Somers load_gnop 6083406320SAlan Somers load_gpart 6183406320SAlan Somers md=$(alloc_md) 6283406320SAlan Somers physpath="some/physical/path" 6383406320SAlan Somers atf_check gnop create -z $physpath /dev/${md} 6483406320SAlan Somers atf_check -s exit:0 -o ignore gpart create -s bsd ${md}.nop 6583406320SAlan Somers atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}.nop 6683406320SAlan Somers gpart_physpath=$(diskinfo -p ${md}.nopa) 6783406320SAlan Somers atf_check_equal "${physpath}/a" "$gpart_physpath" 6883406320SAlan Somers} 6983406320SAlan Somersbsd_physpath_cleanup() 7083406320SAlan Somers{ 7183406320SAlan Somers common_cleanup 7283406320SAlan Somers} 7383406320SAlan Somers 7483406320SAlan Somersatf_test_case gpt_physpath cleanup 7583406320SAlan Somersgpt_physpath_head() 7683406320SAlan Somers{ 7783406320SAlan Somers atf_set "descr" "GPT partitions should append /pX to the underlying device's physical path" 7883406320SAlan Somers atf_set "require.user" "root" 7983406320SAlan Somers} 8083406320SAlan Somersgpt_physpath_body() 8183406320SAlan Somers{ 8283406320SAlan Somers load_gnop 8383406320SAlan Somers load_gpart 8483406320SAlan Somers md=$(alloc_md) 8583406320SAlan Somers physpath="some/physical/path" 8683406320SAlan Somers atf_check gnop create -z $physpath /dev/${md} 8783406320SAlan Somers atf_check -s exit:0 -o ignore gpart create -s gpt ${md}.nop 8883406320SAlan Somers atf_check -s exit:0 -o ignore gpart add -t efi ${md}.nop 8983406320SAlan Somers gpart_physpath=$(diskinfo -p ${md}.nopp1) 9083406320SAlan Somers atf_check_equal "${physpath}/p1" "$gpart_physpath" 9183406320SAlan Somers} 9283406320SAlan Somersgpt_physpath_cleanup() 9383406320SAlan Somers{ 9483406320SAlan Somers common_cleanup 9583406320SAlan Somers} 9683406320SAlan Somers 9783406320SAlan Somersatf_test_case mbr_physpath cleanup 9883406320SAlan Somersmbr_physpath_head() 9983406320SAlan Somers{ 10083406320SAlan Somers atf_set "descr" "MBR partitions should append /sX to the underlying device's physical path" 10183406320SAlan Somers atf_set "require.user" "root" 10283406320SAlan Somers} 10383406320SAlan Somersmbr_physpath_body() 10483406320SAlan Somers{ 10583406320SAlan Somers load_gnop 10683406320SAlan Somers load_gpart 10783406320SAlan Somers md=$(alloc_md) 10883406320SAlan Somers physpath="some/physical/path" 10983406320SAlan Somers atf_check gnop create -z $physpath /dev/${md} 11083406320SAlan Somers atf_check -s exit:0 -o ignore gpart create -s mbr ${md}.nop 11183406320SAlan Somers atf_check -s exit:0 -o ignore gpart add -t freebsd ${md}.nop 11283406320SAlan Somers gpart_physpath=$(diskinfo -p ${md}.nops1) 11383406320SAlan Somers atf_check_equal "${physpath}/s1" "$gpart_physpath" 11483406320SAlan Somers} 11583406320SAlan Somersmbr_physpath_cleanup() 11683406320SAlan Somers{ 11783406320SAlan Somers common_cleanup 11883406320SAlan Somers} 11983406320SAlan Somers 12083406320SAlan Somersatf_test_case mbr_bsd_physpath cleanup 12183406320SAlan Somersmbr_bsd_physpath_head() 12283406320SAlan Somers{ 12383406320SAlan Somers atf_set "descr" "BSD partitions nested within MBR partitions should append /sX/Y to the underlying device's physical path" 12483406320SAlan Somers atf_set "require.user" "root" 12583406320SAlan Somers} 12683406320SAlan Somersmbr_bsd_physpath_body() 12783406320SAlan Somers{ 12883406320SAlan Somers load_gnop 12983406320SAlan Somers load_gpart 13083406320SAlan Somers md=$(alloc_md) 13183406320SAlan Somers physpath="some/physical/path" 13283406320SAlan Somers atf_check gnop create -z $physpath /dev/${md} 13383406320SAlan Somers atf_check -s exit:0 -o ignore gpart create -s mbr ${md}.nop 13483406320SAlan Somers atf_check -s exit:0 -o ignore gpart add -t freebsd ${md}.nop 13583406320SAlan Somers atf_check -s exit:0 -o ignore gpart create -s bsd ${md}.nops1 13683406320SAlan Somers atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}.nops1 13783406320SAlan Somers gpart_physpath=$(diskinfo -p ${md}.nops1a) 13883406320SAlan Somers atf_check_equal "${physpath}/s1/a" "$gpart_physpath" 13983406320SAlan Somers} 14083406320SAlan Somersmbr_bsd_physpath_cleanup() 14183406320SAlan Somers{ 14283406320SAlan Somers common_cleanup 14383406320SAlan Somers} 14483406320SAlan Somers 14583406320SAlan Somersatf_init_test_cases() 14683406320SAlan Somers{ 14783406320SAlan Somers atf_add_test_case blank_physpath 14883406320SAlan Somers atf_add_test_case bsd_physpath 14983406320SAlan Somers atf_add_test_case gpt_physpath 15083406320SAlan Somers atf_add_test_case mbr_physpath 15183406320SAlan Somers atf_add_test_case mbr_bsd_physpath 15283406320SAlan Somers} 15383406320SAlan Somers 15483406320SAlan Somersalloc_md() 15583406320SAlan Somers{ 15683406320SAlan Somers local md 15783406320SAlan Somers 15883406320SAlan Somers md=$(mdconfig -a -t swap -s 1M) || atf_fail "mdconfig -a failed" 15983406320SAlan Somers echo ${md} >> $MD_DEVS 16083406320SAlan Somers echo ${md} 16183406320SAlan Somers} 16283406320SAlan Somers 16383406320SAlan Somerscommon_cleanup() 16483406320SAlan Somers{ 16583406320SAlan Somers if [ -f "$MD_DEVS" ]; then 16683406320SAlan Somers while read test_md; do 16783406320SAlan Somers gnop destroy -f ${test_md}.nop 2>/dev/null 16883406320SAlan Somers mdconfig -d -u $test_md 2>/dev/null 16983406320SAlan Somers done < $MD_DEVS 17083406320SAlan Somers rm $MD_DEVS 17183406320SAlan Somers fi 17283406320SAlan Somers true 17383406320SAlan Somers} 17483406320SAlan Somers 17583406320SAlan Somersload_gpart() 17683406320SAlan Somers{ 17783406320SAlan Somers if ! kldstat -q -m g_part; then 17883406320SAlan Somers geom part load || atf_skip "could not load module for geom part" 17983406320SAlan Somers fi 18083406320SAlan Somers} 18183406320SAlan Somers 18283406320SAlan Somersload_gnop() 18383406320SAlan Somers{ 18483406320SAlan Somers if ! kldstat -q -m g_nop; then 18583406320SAlan Somers geom nop load || atf_skip "could not load module for geom nop" 18683406320SAlan Somers fi 18783406320SAlan Somers} 188