From owner-svn-src-head@freebsd.org Wed Feb 14 20:26:10 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A4921F1D868; Wed, 14 Feb 2018 20:26:10 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 552A66B82F; Wed, 14 Feb 2018 20:26:10 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4FFC414AE4; Wed, 14 Feb 2018 20:26:10 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1EKQArD006029; Wed, 14 Feb 2018 20:26:10 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1EKQ9g8006025; Wed, 14 Feb 2018 20:26:09 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201802142026.w1EKQ9g8006025@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Wed, 14 Feb 2018 20:26:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329275 - in head: sys/geom/part tests/sys/geom/class tests/sys/geom/class/part X-SVN-Group: head X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: in head: sys/geom/part tests/sys/geom/class tests/sys/geom/class/part X-SVN-Commit-Revision: 329275 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Feb 2018 20:26:10 -0000 Author: asomers Date: Wed Feb 14 20:26:09 2018 New Revision: 329275 URL: https://svnweb.freebsd.org/changeset/base/329275 Log: gpart: append partition name to the underlying provider's physical path If the underlying provider's physical path is null, then the gpart device's physical path will be, too. Otherwise, it will append the partition name, such as "/p1" or "/s1/a". This will make gpart work better with zfsd(8). PR: 224965 MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D14010 Added: head/tests/sys/geom/class/part/ head/tests/sys/geom/class/part/Makefile (contents, props changed) head/tests/sys/geom/class/part/misc.sh (contents, props changed) Modified: head/sys/geom/part/g_part.c head/tests/sys/geom/class/Makefile Modified: head/sys/geom/part/g_part.c ============================================================================== --- head/sys/geom/part/g_part.c Wed Feb 14 20:18:23 2018 (r329274) +++ head/sys/geom/part/g_part.c Wed Feb 14 20:26:09 2018 (r329275) @@ -275,6 +275,35 @@ g_part_geometry(struct g_part_table *table, struct g_c } } +static void +g_part_get_physpath_done(struct bio *bp) +{ + struct g_geom *gp; + struct g_part_entry *entry; + struct g_part_table *table; + struct g_provider *pp; + struct bio *pbp; + + pbp = bp->bio_parent; + pp = pbp->bio_to; + gp = pp->geom; + table = gp->softc; + entry = pp->private; + + if (bp->bio_error == 0) { + char *end; + size_t len, remainder; + len = strlcat(bp->bio_data, "/", bp->bio_length); + if (len < bp->bio_length) { + end = bp->bio_data + len; + remainder = bp->bio_length - len; + G_PART_NAME(table, entry, end, remainder); + } + } + g_std_done(bp); +} + + #define DPRINTF(...) if (bootverbose) { \ printf("GEOM_PART: " __VA_ARGS__); \ } @@ -2189,6 +2218,7 @@ g_part_start(struct bio *bp) struct g_part_table *table; struct g_kerneldump *gkd; struct g_provider *pp; + void (*done_func)(struct bio *) = g_std_done; char buf[64]; biotrack(bp, __func__); @@ -2243,6 +2273,10 @@ g_part_start(struct bio *bp) if (g_handleattr_str(bp, "PART::type", G_PART_TYPE(table, entry, buf, sizeof(buf)))) return; + if (!strcmp("GEOM::physpath", bp->bio_attribute)) { + done_func = g_part_get_physpath_done; + break; + } if (!strcmp("GEOM::kerneldump", bp->bio_attribute)) { /* * Check that the partition is suitable for kernel @@ -2279,7 +2313,7 @@ g_part_start(struct bio *bp) g_io_deliver(bp, ENOMEM); return; } - bp2->bio_done = g_std_done; + bp2->bio_done = done_func; g_io_request(bp2, cp); } Modified: head/tests/sys/geom/class/Makefile ============================================================================== --- head/tests/sys/geom/class/Makefile Wed Feb 14 20:18:23 2018 (r329274) +++ head/tests/sys/geom/class/Makefile Wed Feb 14 20:26:09 2018 (r329275) @@ -7,10 +7,9 @@ TESTSDIR= ${TESTSBASE}/sys/geom/class TESTS_SUBDIRS+= concat TESTS_SUBDIRS+= eli TESTS_SUBDIRS+= gate -# XXX: might not work due to geom(4) changes; more investigation's needed -#TESTS_SUBDIRS+= gpt TESTS_SUBDIRS+= mirror TESTS_SUBDIRS+= nop +TESTS_SUBDIRS+= part TESTS_SUBDIRS+= raid3 TESTS_SUBDIRS+= shsec TESTS_SUBDIRS+= stripe Added: head/tests/sys/geom/class/part/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/geom/class/part/Makefile Wed Feb 14 20:26:09 2018 (r329275) @@ -0,0 +1,10 @@ +# $FreeBSD$ + +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/sys/geom/class/${.CURDIR:T} + +# TODO: port the perl tests in tools/regression/geom_gpt +ATF_TESTS_SH+= misc + +.include Added: head/tests/sys/geom/class/part/misc.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/geom/class/part/misc.sh Wed Feb 14 20:26:09 2018 (r329275) @@ -0,0 +1,187 @@ +# Copyright (c) 2018 Alan Somers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +MD_DEVS="md.devs" + +atf_test_case blank_physpath cleanup +blank_physpath_head() +{ + atf_set "descr" "gpart shouldn't add physical paths to underlying providers that have none" + atf_set "require.user" "root" +} +blank_physpath_body() +{ + load_gnop + load_gpart + md=$(alloc_md) + atf_check -o empty -e ignore diskinfo -p ${md} + atf_check -s exit:0 -o ignore gpart create -s bsd ${md} + atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md} + atf_check -o empty -e ignore diskinfo -p ${md}a +} +blank_physpath_cleanup() +{ + common_cleanup +} + + +atf_test_case bsd_physpath cleanup +bsd_physpath_head() +{ + atf_set "descr" "BSD partitions should append /X to the underlying device's physical path" + atf_set "require.user" "root" +} +bsd_physpath_body() +{ + load_gnop + load_gpart + md=$(alloc_md) + physpath="some/physical/path" + atf_check gnop create -z $physpath /dev/${md} + atf_check -s exit:0 -o ignore gpart create -s bsd ${md}.nop + atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}.nop + gpart_physpath=$(diskinfo -p ${md}.nopa) + atf_check_equal "${physpath}/a" "$gpart_physpath" +} +bsd_physpath_cleanup() +{ + common_cleanup +} + +atf_test_case gpt_physpath cleanup +gpt_physpath_head() +{ + atf_set "descr" "GPT partitions should append /pX to the underlying device's physical path" + atf_set "require.user" "root" +} +gpt_physpath_body() +{ + load_gnop + load_gpart + md=$(alloc_md) + physpath="some/physical/path" + atf_check gnop create -z $physpath /dev/${md} + atf_check -s exit:0 -o ignore gpart create -s gpt ${md}.nop + atf_check -s exit:0 -o ignore gpart add -t efi ${md}.nop + gpart_physpath=$(diskinfo -p ${md}.nopp1) + atf_check_equal "${physpath}/p1" "$gpart_physpath" +} +gpt_physpath_cleanup() +{ + common_cleanup +} + +atf_test_case mbr_physpath cleanup +mbr_physpath_head() +{ + atf_set "descr" "MBR partitions should append /sX to the underlying device's physical path" + atf_set "require.user" "root" +} +mbr_physpath_body() +{ + load_gnop + load_gpart + md=$(alloc_md) + physpath="some/physical/path" + atf_check gnop create -z $physpath /dev/${md} + atf_check -s exit:0 -o ignore gpart create -s mbr ${md}.nop + atf_check -s exit:0 -o ignore gpart add -t freebsd ${md}.nop + gpart_physpath=$(diskinfo -p ${md}.nops1) + atf_check_equal "${physpath}/s1" "$gpart_physpath" +} +mbr_physpath_cleanup() +{ + common_cleanup +} + +atf_test_case mbr_bsd_physpath cleanup +mbr_bsd_physpath_head() +{ + atf_set "descr" "BSD partitions nested within MBR partitions should append /sX/Y to the underlying device's physical path" + atf_set "require.user" "root" +} +mbr_bsd_physpath_body() +{ + load_gnop + load_gpart + md=$(alloc_md) + physpath="some/physical/path" + atf_check gnop create -z $physpath /dev/${md} + atf_check -s exit:0 -o ignore gpart create -s mbr ${md}.nop + atf_check -s exit:0 -o ignore gpart add -t freebsd ${md}.nop + atf_check -s exit:0 -o ignore gpart create -s bsd ${md}.nops1 + atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}.nops1 + gpart_physpath=$(diskinfo -p ${md}.nops1a) + atf_check_equal "${physpath}/s1/a" "$gpart_physpath" +} +mbr_bsd_physpath_cleanup() +{ + common_cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case blank_physpath + atf_add_test_case bsd_physpath + atf_add_test_case gpt_physpath + atf_add_test_case mbr_physpath + atf_add_test_case mbr_bsd_physpath +} + +alloc_md() +{ + local md + + md=$(mdconfig -a -t swap -s 1M) || atf_fail "mdconfig -a failed" + echo ${md} >> $MD_DEVS + echo ${md} +} + +common_cleanup() +{ + if [ -f "$MD_DEVS" ]; then + while read test_md; do + gnop destroy -f ${test_md}.nop 2>/dev/null + mdconfig -d -u $test_md 2>/dev/null + done < $MD_DEVS + rm $MD_DEVS + fi + true +} + +load_gpart() +{ + if ! kldstat -q -m g_part; then + geom part load || atf_skip "could not load module for geom part" + fi +} + +load_gnop() +{ + if ! kldstat -q -m g_nop; then + geom nop load || atf_skip "could not load module for geom nop" + fi +}