geli: append "/eli" to the underlying provider's physical path

If the underlying provider's physical path is null, then the geli device's
physical path will be, too. Otherwise, it will append "/eli".  This will make
geli work better with zfsd(8).

PR:		224962
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D13979
This commit is contained in:
Alan Somers 2018-02-14 20:15:32 +00:00
parent 70c144dc78
commit 0bab7fa8a7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329273
3 changed files with 192 additions and 1 deletions

View File

@ -212,6 +212,16 @@ g_eli_crypto_rerun(struct cryptop *crp)
return (error);
}
static void
g_eli_getattr_done(struct bio *bp)
{
if (bp->bio_error == 0 &&
!strcmp(bp->bio_attribute, "GEOM::physpath")) {
strlcat(bp->bio_data, "/eli", bp->bio_length);
}
g_std_done(bp);
}
/*
* The function is called afer reading encrypted data from the provider.
*
@ -380,7 +390,10 @@ g_eli_start(struct bio *bp)
case BIO_FLUSH:
case BIO_DELETE:
case BIO_ZONE:
cbp->bio_done = g_std_done;
if (bp->bio_cmd == BIO_GETATTR)
cbp->bio_done = g_eli_getattr_done;
else
cbp->bio_done = g_std_done;
cp = LIST_FIRST(&sc->sc_geom->consumer);
cbp->bio_to = cp->provider;
G_ELI_LOGREQ(2, cbp, "Sending request.");

View File

@ -14,6 +14,7 @@ ATF_TESTS_SH+= detach_test
ATF_TESTS_SH+= init_test
ATF_TESTS_SH+= integrity_test
ATF_TESTS_SH+= kill_test
ATF_TESTS_SH+= misc_test
ATF_TESTS_SH+= onetime_test
ATF_TESTS_SH+= resize_test
ATF_TESTS_SH+= setkey_test

View File

@ -0,0 +1,177 @@
# 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$
atf_test_case preserve_props cleanup
preserve_props_head()
{
atf_set "descr" "geli should preserve basic GEOM properties"
atf_set "require.user" "root"
atf_set "timeout" 15
}
preserve_props_body()
{
. $(atf_get_srcdir)/conf.sh
md=$(attach_md -s1m)
atf_check geli onetime /dev/${md}
md_secsize=$(diskinfo ${md} | cut -wf 2)
md_stripesize=$(diskinfo ${md} | cut -wf 5)
eli_secsize=$(diskinfo ${md}.eli | cut -wf 2)
eli_stripesize=$(diskinfo ${md}.eli | cut -wf 5)
atf_check_equal "$md_secsize" "$eli_secsize"
atf_check_equal "$md_stripesize" "$eli_stripesize"
}
preserve_props_cleanup()
{
. $(atf_get_srcdir)/conf.sh
geli_test_cleanup
}
atf_test_case preserve_disk_props cleanup
preserve_disk_props_head()
{
atf_set "descr" "geli should preserve properties for disks"
atf_set "require.user" "root"
atf_set "require.config" "disks"
atf_set "timeout" 15
}
preserve_disk_props_body()
{
. $(atf_get_srcdir)/conf.sh
disks=`atf_config_get disks`
disk=${disks%% *}
if [ -z "$disk" ]; then
atf_skip "Must define disks (see tests(7))"
fi
atf_check geli onetime ${disk}
disk_ident=$(diskinfo -s ${disk})
disk_descr=$(diskinfo -v ${disk} | awk '/Disk descr/ {print $1}')
disk_rotrate=$(diskinfo -v ${disk} | awk '/Rotation rate/ {print $1}')
disk_zonemode=$(diskinfo -v ${disk} | awk '/Zone Mode/ {print $1}')
eli_ident=$(diskinfo -s ${disk}.eli)
eli_descr=$(diskinfo -v ${disk}.eli | awk '/Disk descr/ {print $1}')
eli_rotrate=$(diskinfo -v ${disk}.eli | awk '/Rotation/ {print $1}')
eli_zonemode=$(diskinfo -v ${disk}.eli | awk '/Zone Mode/ {print $1}')
atf_check_equal "$disk_ident" "$eli_ident"
atf_check_equal "$disk_descr" "$eli_descr"
atf_check_equal "$disk_rotrate" "$eli_rotrate"
atf_check_equal "$disk_zonemode" "$eli_zonemode"
}
preserve_disk_props_cleanup()
{
. $(atf_get_srcdir)/conf.sh
disk_cleanup
geli_test_cleanup
}
atf_test_case physpath cleanup
physpath_head()
{
atf_set "descr" "geli should append /eli to the underlying device's physical path"
atf_set "require.user" "root"
atf_set "timeout" 15
}
physpath_body()
{
. $(atf_get_srcdir)/conf.sh
load_gnop
md=$(attach_md -s1m)
# If the underlying device has no physical path, then geli should not
# create one.
atf_check -o empty -e ignore diskinfo -p $md
atf_check -s exit:0 geli onetime $md
atf_check -o empty -e ignore diskinfo -p $md.eli
atf_check -s exit:0 geli kill $md
# If the underlying device does have a physical path, then geli should
# append "/eli"
physpath="some/physical/path"
atf_check gnop create -z $physpath ${md}
atf_check -s exit:0 geli onetime $md.nop
atf_check -o match:"^${physpath}/eli$" diskinfo -p $md.nop.eli
}
physpath_cleanup()
{
. $(atf_get_srcdir)/conf.sh
if [ -f "$TEST_MDS_FILE" ]; then
while read md; do
[ -c /dev/${md}.nop.eli ] && \
geli detach $md.nop.eli 2>/dev/null
[ -c /dev/${md}.nop ] && \
gnop destroy -f $md.nop 2>/dev/null
[ -c /dev/${md}.eli ] && \
geli detach $md.eli 2>/dev/null
mdconfig -d -u $md 2>/dev/null
done < $TEST_MDS_FILE
fi
true
}
atf_init_test_cases()
{
atf_add_test_case physpath
atf_add_test_case preserve_props
atf_add_test_case preserve_disk_props
}
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
if [ -f "$PLAINFILES" ]; then
while read f; do
rm -f ${f}
done < ${PLAINFILES}
rm ${PLAINFILES}
fi
true
}
disk_cleanup()
{
disks=`atf_config_get disks`
disk=${disks%% *}
if [ -n "$disk" ]; then
geli kill ${disk} 2>/dev/null
fi
}
load_gnop()
{
if ! kldstat -q -m g_nop; then
geom nop load || atf_skip "could not load module for geom nop"
fi
}