Skip to content

Commit b673719

Browse files
author
Ryan Moeller
authored
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
1 parent fe628bc commit b673719

File tree

10 files changed

+194
-2
lines changed

10 files changed

+194
-2
lines changed

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ AC_CONFIG_FILES([
258258
tests/zfs-tests/tests/functional/cli_root/zfs_get/Makefile
259259
tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/Makefile
260260
tests/zfs-tests/tests/functional/cli_root/zfs_inherit/Makefile
261+
tests/zfs-tests/tests/functional/cli_root/zfs_jail/Makefile
261262
tests/zfs-tests/tests/functional/cli_root/zfs_load-key/Makefile
262263
tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile
263264
tests/zfs-tests/tests/functional/cli_root/zfs_program/Makefile

lib/libzfs/os/freebsd/libzfs_compat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ zfs_jail(zfs_handle_t *zhp, int jailid, int attach)
268268
zc.zc_zoneid = jailid;
269269

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

274274
return (ret);

tests/runfiles/freebsd.run

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1-
# don't delete this file
1+
#
2+
# This file and its contents are supplied under the terms of the
3+
# Common Development and Distribution License ("CDDL"), version 1.0.
4+
# You may only use this file in accordance with the terms of version
5+
# 1.0 of the CDDL.
6+
#
7+
# A full copy of the text of the CDDL should have accompanied this
8+
# source. A copy of the CDDL is also available via the Internet at
9+
# http://www.illumos.org/license/CDDL.
10+
#
11+
12+
[DEFAULT]
13+
pre = setup
14+
quiet = False
15+
pre_user = root
16+
user = root
17+
timeout = 600
18+
post_user = root
19+
post = cleanup
20+
failsafe_user = root
21+
failsafe = callbacks/zfs_failsafe
22+
outputdir = /var/tmp/test_results
23+
tags = ['functional']
24+
25+
[tests/functional/cli_root/zfs_jail:FreeBSD]
26+
tests = ['zfs_jail_001_pos']
27+
tags = ['functional', 'cli_root', 'zfs_jail']

tests/zfs-tests/include/commands.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ export SYSTEM_FILES_FREEBSD='chflags
120120
fsck
121121
getextattr
122122
gpart
123+
jail
124+
jexec
125+
jls
123126
lsextattr
124127
md5
125128
mdconfig

tests/zfs-tests/tests/functional/cli_root/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SUBDIRS = \
1515
zfs_get \
1616
zfs_ids_to_path \
1717
zfs_inherit \
18+
zfs_jail \
1819
zfs_load-key \
1920
zfs_mount \
2021
zfs_program \
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_jail
2+
dist_pkgdata_SCRIPTS = \
3+
setup.ksh \
4+
cleanup.ksh \
5+
jail.conf \
6+
zfs_jail_001_pos.ksh
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/ksh -p
2+
#
3+
# CDDL HEADER START
4+
#
5+
# The contents of this file are subject to the terms of the
6+
# Common Development and Distribution License (the "License").
7+
# You may not use this file except in compliance with the License.
8+
#
9+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
# or http://www.opensolaris.org/os/licensing.
11+
# See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
# When distributing Covered Code, include this CDDL HEADER in each
15+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
# If applicable, add the following below this CDDL HEADER, with the
17+
# fields enclosed by brackets "[]" replaced with your own identifying
18+
# information: Portions Copyright [yyyy] [name of copyright owner]
19+
#
20+
# CDDL HEADER END
21+
#
22+
23+
#
24+
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25+
# Use is subject to license terms.
26+
#
27+
28+
. $STF_SUITE/include/libtest.shlib
29+
30+
default_cleanup
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
testjail {
2+
allow.mount.zfs;
3+
allow.mount;
4+
devfs_ruleset = 4;
5+
enforce_statfs = 0;
6+
mount.devfs;
7+
path = "/";
8+
persist;
9+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/ksh -p
2+
#
3+
# CDDL HEADER START
4+
#
5+
# The contents of this file are subject to the terms of the
6+
# Common Development and Distribution License (the "License").
7+
# You may not use this file except in compliance with the License.
8+
#
9+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
# or http://www.opensolaris.org/os/licensing.
11+
# See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
# When distributing Covered Code, include this CDDL HEADER in each
15+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
# If applicable, add the following below this CDDL HEADER, with the
17+
# fields enclosed by brackets "[]" replaced with your own identifying
18+
# information: Portions Copyright [yyyy] [name of copyright owner]
19+
#
20+
# CDDL HEADER END
21+
#
22+
23+
#
24+
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25+
# Use is subject to license terms.
26+
#
27+
28+
. $STF_SUITE/include/libtest.shlib
29+
30+
DISK=${DISKS%% *}
31+
32+
default_setup $DISK
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/ksh -p
2+
#
3+
# CDDL HEADER START
4+
#
5+
# The contents of this file are subject to the terms of the
6+
# Common Development and Distribution License (the "License").
7+
# You may not use this file except in compliance with the License.
8+
#
9+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
# or http://www.opensolaris.org/os/licensing.
11+
# See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
# When distributing Covered Code, include this CDDL HEADER in each
15+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
# If applicable, add the following below this CDDL HEADER, with the
17+
# fields enclosed by brackets "[]" replaced with your own identifying
18+
# information: Portions Copyright [yyyy] [name of copyright owner]
19+
#
20+
# CDDL HEADER END
21+
#
22+
23+
#
24+
# Copyright 2020 iXsystems, Inc.
25+
#
26+
27+
. $STF_SUITE/include/libtest.shlib
28+
29+
#
30+
# DESCRIPTION:
31+
# Test basic functionality of `zfs jail` and `zfs unjail`.
32+
#
33+
# STRATEGY:
34+
# 1. Create a jail.
35+
# 2. Perform some basic ZFS operations on a dataset both in the host and
36+
# in the jail to confirm the dataset is functional in the host
37+
# and hidden in in the jail.
38+
# 3. Run `zfs jail` to expose the dataset in the jail.
39+
# 4. Perform some basic ZFS operations on the dataset both in the host and
40+
# in the jail to confirm the dataset is functional in the jail and host.
41+
# 5. Run `zfs unjail` to return the dataset to the host.
42+
# 6. Perform some basic ZFS operations on the dataset both in the host and
43+
# in the jail to confirm the dataset is functional in the host
44+
# and hidden in in the jail.
45+
#
46+
47+
verify_runnable "global"
48+
49+
JAIL="testjail"
50+
JAIL_CONF="$STF_SUITE/tests/functional/cli_root/zfs_jail/jail.conf"
51+
52+
function cleanup
53+
{
54+
if jls -j $JAIL name >/dev/null 2>&1; then
55+
jail -r -f $JAIL_CONF $JAIL
56+
fi
57+
}
58+
59+
log_onexit cleanup
60+
61+
log_assert "Verify that a dataset can be jailed and unjailed."
62+
63+
# 1. Create a jail.
64+
log_must jail -c -f $JAIL_CONF $JAIL
65+
66+
# 2. Try some basic ZFS operations.
67+
log_must zfs list $TESTPOOL
68+
log_mustnot jexec $JAIL zfs list $TESTPOOL
69+
70+
# 3. Jail the dataset.
71+
log_must zfs jail $JAIL $TESTPOOL
72+
73+
# 4. Try some basic ZFS operations.
74+
log_must zfs list $TESTPOOL
75+
log_must jexec $JAIL zfs list $TESTPOOL
76+
77+
# 5. Unjail the dataset.
78+
log_must zfs unjail $JAIL $TESTPOOL
79+
80+
# 6. Try some basic ZFS operations.
81+
log_must zfs list $TESTPOOL
82+
log_mustnot jexec $JAIL zfs list $TESTPOOL
83+
84+
log_pass "Datasets can be jailed and unjailed."

0 commit comments

Comments
 (0)