diff options
author | Ryan Moeller <[email protected]> | 2020-08-01 11:44:54 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2020-08-01 08:44:54 -0700 |
commit | b6737193ee601cc213d3630e4603f9883b6002ad (patch) | |
tree | bb46c43abb7bd2a3c4841664ee3e0b5a3cbc8587 /tests | |
parent | fe628bc21d360336307d1da09bc9260a46dde444 (diff) |
FreeBSD: Fix `zfs jail` and add a test
zfs_jail was not using zfs_ioctl so failed to map the IOC number
correctly. Use zfs_ioctl to perform the jail ioctl and add a test
case for FreeBSD.
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes #10658
Diffstat (limited to 'tests')
8 files changed, 192 insertions, 1 deletions
diff --git a/tests/runfiles/freebsd.run b/tests/runfiles/freebsd.run index 447463699..c7ca1d769 100644 --- a/tests/runfiles/freebsd.run +++ b/tests/runfiles/freebsd.run @@ -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'] diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg index 21fe0df9e..bf8b67e75 100644 --- a/tests/zfs-tests/include/commands.cfg +++ b/tests/zfs-tests/include/commands.cfg @@ -120,6 +120,9 @@ export SYSTEM_FILES_FREEBSD='chflags fsck getextattr gpart + jail + jexec + jls lsextattr md5 mdconfig diff --git a/tests/zfs-tests/tests/functional/cli_root/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/Makefile.am index 2595ed8c1..c01ecee89 100644 --- a/tests/zfs-tests/tests/functional/cli_root/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/Makefile.am @@ -15,6 +15,7 @@ SUBDIRS = \ zfs_get \ zfs_ids_to_path \ zfs_inherit \ + zfs_jail \ zfs_load-key \ zfs_mount \ zfs_program \ diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_jail/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_jail/Makefile.am new file mode 100644 index 000000000..b6dd7721e --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_jail/Makefile.am @@ -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 diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_jail/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_jail/cleanup.ksh new file mode 100755 index 000000000..79cd6e9f9 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_jail/cleanup.ksh @@ -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 diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_jail/jail.conf b/tests/zfs-tests/tests/functional/cli_root/zfs_jail/jail.conf new file mode 100644 index 000000000..23a9dabeb --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_jail/jail.conf @@ -0,0 +1,9 @@ +testjail { + allow.mount.zfs; + allow.mount; + devfs_ruleset = 4; + enforce_statfs = 0; + mount.devfs; + path = "/"; + persist; +} diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_jail/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_jail/setup.ksh new file mode 100755 index 000000000..6a9af3bc2 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_jail/setup.ksh @@ -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 diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_jail/zfs_jail_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_jail/zfs_jail_001_pos.ksh new file mode 100755 index 000000000..2c0808110 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_jail/zfs_jail_001_pos.ksh @@ -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." |