Skip to content

FreeBSD: Fix zfs jail and add a test #10658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ AC_CONFIG_FILES([
tests/zfs-tests/tests/functional/cli_root/zfs_get/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_inherit/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_jail/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_load-key/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_program/Makefile
Expand Down
2 changes: 1 addition & 1 deletion lib/libzfs/os/freebsd/libzfs_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ zfs_jail(zfs_handle_t *zhp, int jailid, int attach)
zc.zc_zoneid = jailid;

cmd = attach ? ZFS_IOC_JAIL : ZFS_IOC_UNJAIL;
if ((ret = ioctl(hdl->libzfs_fd, cmd, &zc)) != 0)
if ((ret = zfs_ioctl(hdl, cmd, &zc)) != 0)
zfs_standard_error(hdl, errno, errbuf);

return (ret);
Expand Down
28 changes: 27 additions & 1 deletion tests/runfiles/freebsd.run
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
# don't delete this file
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

[DEFAULT]
pre = setup
quiet = False
pre_user = root
user = root
timeout = 600
post_user = root
post = cleanup
failsafe_user = root
failsafe = callbacks/zfs_failsafe
outputdir = /var/tmp/test_results
tags = ['functional']

[tests/functional/cli_root/zfs_jail:FreeBSD]
tests = ['zfs_jail_001_pos']
tags = ['functional', 'cli_root', 'zfs_jail']
3 changes: 3 additions & 0 deletions tests/zfs-tests/include/commands.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export SYSTEM_FILES_FREEBSD='chflags
fsck
getextattr
gpart
jail
jexec
jls
lsextattr
md5
mdconfig
Expand Down
1 change: 1 addition & 0 deletions tests/zfs-tests/tests/functional/cli_root/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SUBDIRS = \
zfs_get \
zfs_ids_to_path \
zfs_inherit \
zfs_jail \
zfs_load-key \
zfs_mount \
zfs_program \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_jail
dist_pkgdata_SCRIPTS = \
setup.ksh \
cleanup.ksh \
jail.conf \
zfs_jail_001_pos.ksh
30 changes: 30 additions & 0 deletions tests/zfs-tests/tests/functional/cli_root/zfs_jail/cleanup.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#

. $STF_SUITE/include/libtest.shlib

default_cleanup
9 changes: 9 additions & 0 deletions tests/zfs-tests/tests/functional/cli_root/zfs_jail/jail.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
testjail {
allow.mount.zfs;
allow.mount;
devfs_ruleset = 4;
enforce_statfs = 0;
mount.devfs;
path = "/";
persist;
}
32 changes: 32 additions & 0 deletions tests/zfs-tests/tests/functional/cli_root/zfs_jail/setup.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#

. $STF_SUITE/include/libtest.shlib

DISK=${DISKS%% *}

default_setup $DISK
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2020 iXsystems, Inc.
#

. $STF_SUITE/include/libtest.shlib

#
# DESCRIPTION:
# Test basic functionality of `zfs jail` and `zfs unjail`.
#
# STRATEGY:
# 1. Create a jail.
# 2. Perform some basic ZFS operations on a dataset both in the host and
# in the jail to confirm the dataset is functional in the host
# and hidden in in the jail.
# 3. Run `zfs jail` to expose the dataset in the jail.
# 4. Perform some basic ZFS operations on the dataset both in the host and
# in the jail to confirm the dataset is functional in the jail and host.
# 5. Run `zfs unjail` to return the dataset to the host.
# 6. Perform some basic ZFS operations on the dataset both in the host and
# in the jail to confirm the dataset is functional in the host
# and hidden in in the jail.
#

verify_runnable "global"

JAIL="testjail"
JAIL_CONF="$STF_SUITE/tests/functional/cli_root/zfs_jail/jail.conf"

function cleanup
{
if jls -j $JAIL name >/dev/null 2>&1; then
jail -r -f $JAIL_CONF $JAIL
fi
}

log_onexit cleanup

log_assert "Verify that a dataset can be jailed and unjailed."

# 1. Create a jail.
log_must jail -c -f $JAIL_CONF $JAIL

# 2. Try some basic ZFS operations.
log_must zfs list $TESTPOOL
log_mustnot jexec $JAIL zfs list $TESTPOOL

# 3. Jail the dataset.
log_must zfs jail $JAIL $TESTPOOL

# 4. Try some basic ZFS operations.
log_must zfs list $TESTPOOL
log_must jexec $JAIL zfs list $TESTPOOL

# 5. Unjail the dataset.
log_must zfs unjail $JAIL $TESTPOOL

# 6. Try some basic ZFS operations.
log_must zfs list $TESTPOOL
log_mustnot jexec $JAIL zfs list $TESTPOOL

log_pass "Datasets can be jailed and unjailed."