1*809a8352SAlan Somers# SPDX-License-Identifier: BSD-2-Clause-FreeBSD 2*809a8352SAlan 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# $FreeBSD$ 2783406320SAlan Somers 2883406320SAlan SomersMD_DEVS="md.devs" 2983406320SAlan Somers 3083406320SAlan Somersatf_test_case blank_physpath cleanup 3183406320SAlan Somersblank_physpath_head() 3283406320SAlan Somers{ 3383406320SAlan Somers atf_set "descr" "gpart shouldn't add physical paths to underlying providers that have none" 3483406320SAlan Somers atf_set "require.user" "root" 3583406320SAlan Somers} 3683406320SAlan Somersblank_physpath_body() 3783406320SAlan Somers{ 3883406320SAlan Somers load_gnop 3983406320SAlan Somers load_gpart 4083406320SAlan Somers md=$(alloc_md) 4183406320SAlan Somers atf_check -o empty -e ignore diskinfo -p ${md} 4283406320SAlan Somers atf_check -s exit:0 -o ignore gpart create -s bsd ${md} 4383406320SAlan Somers atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md} 4483406320SAlan Somers atf_check -o empty -e ignore diskinfo -p ${md}a 4583406320SAlan Somers} 4683406320SAlan Somersblank_physpath_cleanup() 4783406320SAlan Somers{ 4883406320SAlan Somers common_cleanup 4983406320SAlan Somers} 5083406320SAlan Somers 5183406320SAlan Somers 5283406320SAlan Somersatf_test_case bsd_physpath cleanup 5383406320SAlan Somersbsd_physpath_head() 5483406320SAlan Somers{ 5583406320SAlan Somers atf_set "descr" "BSD partitions should append /X to the underlying device's physical path" 5683406320SAlan Somers atf_set "require.user" "root" 5783406320SAlan Somers} 5883406320SAlan Somersbsd_physpath_body() 5983406320SAlan Somers{ 6083406320SAlan Somers load_gnop 6183406320SAlan Somers load_gpart 6283406320SAlan Somers md=$(alloc_md) 6383406320SAlan Somers physpath="some/physical/path" 6483406320SAlan Somers atf_check gnop create -z $physpath /dev/${md} 6583406320SAlan Somers atf_check -s exit:0 -o ignore gpart create -s bsd ${md}.nop 6683406320SAlan Somers atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}.nop 6783406320SAlan Somers gpart_physpath=$(diskinfo -p ${md}.nopa) 6883406320SAlan Somers atf_check_equal "${physpath}/a" "$gpart_physpath" 6983406320SAlan Somers} 7083406320SAlan Somersbsd_physpath_cleanup() 7183406320SAlan Somers{ 7283406320SAlan Somers common_cleanup 7383406320SAlan Somers} 7483406320SAlan Somers 7583406320SAlan Somersatf_test_case gpt_physpath cleanup 7683406320SAlan Somersgpt_physpath_head() 7783406320SAlan Somers{ 7883406320SAlan Somers atf_set "descr" "GPT partitions should append /pX to the underlying device's physical path" 7983406320SAlan Somers atf_set "require.user" "root" 8083406320SAlan Somers} 8183406320SAlan Somersgpt_physpath_body() 8283406320SAlan Somers{ 8383406320SAlan Somers load_gnop 8483406320SAlan Somers load_gpart 8583406320SAlan Somers md=$(alloc_md) 8683406320SAlan Somers physpath="some/physical/path" 8783406320SAlan Somers atf_check gnop create -z $physpath /dev/${md} 8883406320SAlan Somers atf_check -s exit:0 -o ignore gpart create -s gpt ${md}.nop 8983406320SAlan Somers atf_check -s exit:0 -o ignore gpart add -t efi ${md}.nop 9083406320SAlan Somers gpart_physpath=$(diskinfo -p ${md}.nopp1) 9183406320SAlan Somers atf_check_equal "${physpath}/p1" "$gpart_physpath" 9283406320SAlan Somers} 9383406320SAlan Somersgpt_physpath_cleanup() 9483406320SAlan Somers{ 9583406320SAlan Somers common_cleanup 9683406320SAlan Somers} 9783406320SAlan Somers 9883406320SAlan Somersatf_test_case mbr_physpath cleanup 9983406320SAlan Somersmbr_physpath_head() 10083406320SAlan Somers{ 10183406320SAlan Somers atf_set "descr" "MBR partitions should append /sX to the underlying device's physical path" 10283406320SAlan Somers atf_set "require.user" "root" 10383406320SAlan Somers} 10483406320SAlan Somersmbr_physpath_body() 10583406320SAlan Somers{ 10683406320SAlan Somers load_gnop 10783406320SAlan Somers load_gpart 10883406320SAlan Somers md=$(alloc_md) 10983406320SAlan Somers physpath="some/physical/path" 11083406320SAlan Somers atf_check gnop create -z $physpath /dev/${md} 11183406320SAlan Somers atf_check -s exit:0 -o ignore gpart create -s mbr ${md}.nop 11283406320SAlan Somers atf_check -s exit:0 -o ignore gpart add -t freebsd ${md}.nop 11383406320SAlan Somers gpart_physpath=$(diskinfo -p ${md}.nops1) 11483406320SAlan Somers atf_check_equal "${physpath}/s1" "$gpart_physpath" 11583406320SAlan Somers} 11683406320SAlan Somersmbr_physpath_cleanup() 11783406320SAlan Somers{ 11883406320SAlan Somers common_cleanup 11983406320SAlan Somers} 12083406320SAlan Somers 12183406320SAlan Somersatf_test_case mbr_bsd_physpath cleanup 12283406320SAlan Somersmbr_bsd_physpath_head() 12383406320SAlan Somers{ 12483406320SAlan Somers atf_set "descr" "BSD partitions nested within MBR partitions should append /sX/Y to the underlying device's physical path" 12583406320SAlan Somers atf_set "require.user" "root" 12683406320SAlan Somers} 12783406320SAlan Somersmbr_bsd_physpath_body() 12883406320SAlan Somers{ 12983406320SAlan Somers load_gnop 13083406320SAlan Somers load_gpart 13183406320SAlan Somers md=$(alloc_md) 13283406320SAlan Somers physpath="some/physical/path" 13383406320SAlan Somers atf_check gnop create -z $physpath /dev/${md} 13483406320SAlan Somers atf_check -s exit:0 -o ignore gpart create -s mbr ${md}.nop 13583406320SAlan Somers atf_check -s exit:0 -o ignore gpart add -t freebsd ${md}.nop 13683406320SAlan Somers atf_check -s exit:0 -o ignore gpart create -s bsd ${md}.nops1 13783406320SAlan Somers atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}.nops1 13883406320SAlan Somers gpart_physpath=$(diskinfo -p ${md}.nops1a) 13983406320SAlan Somers atf_check_equal "${physpath}/s1/a" "$gpart_physpath" 14083406320SAlan Somers} 14183406320SAlan Somersmbr_bsd_physpath_cleanup() 14283406320SAlan Somers{ 14383406320SAlan Somers common_cleanup 14483406320SAlan Somers} 14583406320SAlan Somers 14683406320SAlan Somersatf_init_test_cases() 14783406320SAlan Somers{ 14883406320SAlan Somers atf_add_test_case blank_physpath 14983406320SAlan Somers atf_add_test_case bsd_physpath 15083406320SAlan Somers atf_add_test_case gpt_physpath 15183406320SAlan Somers atf_add_test_case mbr_physpath 15283406320SAlan Somers atf_add_test_case mbr_bsd_physpath 15383406320SAlan Somers} 15483406320SAlan Somers 15583406320SAlan Somersalloc_md() 15683406320SAlan Somers{ 15783406320SAlan Somers local md 15883406320SAlan Somers 15983406320SAlan Somers md=$(mdconfig -a -t swap -s 1M) || atf_fail "mdconfig -a failed" 16083406320SAlan Somers echo ${md} >> $MD_DEVS 16183406320SAlan Somers echo ${md} 16283406320SAlan Somers} 16383406320SAlan Somers 16483406320SAlan Somerscommon_cleanup() 16583406320SAlan Somers{ 16683406320SAlan Somers if [ -f "$MD_DEVS" ]; then 16783406320SAlan Somers while read test_md; do 16883406320SAlan Somers gnop destroy -f ${test_md}.nop 2>/dev/null 16983406320SAlan Somers mdconfig -d -u $test_md 2>/dev/null 17083406320SAlan Somers done < $MD_DEVS 17183406320SAlan Somers rm $MD_DEVS 17283406320SAlan Somers fi 17383406320SAlan Somers true 17483406320SAlan Somers} 17583406320SAlan Somers 17683406320SAlan Somersload_gpart() 17783406320SAlan Somers{ 17883406320SAlan Somers if ! kldstat -q -m g_part; then 17983406320SAlan Somers geom part load || atf_skip "could not load module for geom part" 18083406320SAlan Somers fi 18183406320SAlan Somers} 18283406320SAlan Somers 18383406320SAlan Somersload_gnop() 18483406320SAlan Somers{ 18583406320SAlan Somers if ! kldstat -q -m g_nop; then 18683406320SAlan Somers geom nop load || atf_skip "could not load module for geom nop" 18783406320SAlan Somers fi 18883406320SAlan Somers} 189