-
Notifications
You must be signed in to change notification settings - Fork 1.9k
FreeBSD: Add zfs jail property #17768
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2095,6 +2095,16 @@ for more information. | |
Jails are a | ||
.Fx | ||
feature and this property is not available on other platforms. | ||
.It Sy jail | ||
This read-only property reports name of the jail that mounted the jailed | ||
dataset. | ||
The "0" name is used for datasets that are not mounted or not jailed. | ||
This differs from the normal ZFS convention to print dash ('-') for unset | ||
values, since it can be a valid jail name. | ||
If the jail is renamed, the property will still report its old name from | ||
the time the dataset was mounted. | ||
Comment on lines
+2104
to
+2105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes me wonder if reporting jail ID would be more predictable. |
||
The reported jail may no longer exist, while the dataset remains mounted. | ||
The property is not revealed to jails themselves, the "0" is reported instead. | ||
.It Sy zoned Ns = Ns Sy off Ns | Ns Sy on | ||
Controls whether the dataset is managed from a non-global zone or namespace. | ||
See | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1310,6 +1310,18 @@ zfs_domount(vfs_t *vfsp, char *osname) | |
|
||
if (!zfsvfs->z_issnap) | ||
zfsctl_create(zfsvfs); | ||
|
||
#ifdef __FreeBSD__ | ||
if (error == 0) { | ||
/* zone dataset visiblity was checked before in zfs_mount() */ | ||
struct prison *pr = curthread->td_ucred->cr_prison; | ||
if (pr != &prison0) { | ||
zfsvfs->z_os->os_dsl_dataset->ds_jailname = | ||
kmem_strdup(pr->pr_name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I am not closely familiar with the zone/jail code in ZFS, but I am not sure the delegation should necessarily be tied to a mounting. I suppose some dataset may not be mounted, but be controlled by the jail. Am I wrong? |
||
} | ||
} | ||
#endif | ||
|
||
out: | ||
if (error) { | ||
dmu_objset_disown(zfsvfs->z_os, B_TRUE, zfsvfs); | ||
|
@@ -1783,6 +1795,12 @@ zfs_umount(vfs_t *vfsp, int fflag) | |
dmu_objset_set_user(os, NULL); | ||
mutex_exit(&os->os_user_ptr_lock); | ||
|
||
#ifdef __FreeBSD__ | ||
if (os->os_dsl_dataset->ds_jailname) | ||
kmem_strfree(os->os_dsl_dataset->ds_jailname); | ||
os->os_dsl_dataset->ds_jailname = NULL; | ||
#endif | ||
|
||
/* | ||
* Finally release the objset | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/bin/ksh -p | ||
# SPDX-License-Identifier: CDDL-1.0 | ||
# | ||
# 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 https://opensource.org/licenses/CDDL-1.0. | ||
# 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 2025 SkunkWerks, GmbH | ||
# | ||
|
||
. $STF_SUITE/include/libtest.shlib | ||
|
||
# | ||
# DESCRIPTION: | ||
# Test basic use cases of "jail" zfs dataset property. | ||
# | ||
# STRATEGY: | ||
# 1. Create a dataset. Verify. | ||
# 2. Create a jail. Verify. | ||
# 3. Jail the dataset. Verify. | ||
# 4. Mount the dataset by the jail. Verify. | ||
# 5. Unmount the dataset. Verify. | ||
# | ||
|
||
verify_runnable "global" | ||
|
||
JAIL="testjail" | ||
JAIL_CONF="$STF_SUITE/tests/functional/cli_root/zfs_jail/jail.conf" | ||
DATASET="$TESTPOOL/dataset1" | ||
DATASET_JAILED_MOUNTPOINT="/jailed" | ||
|
||
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 basic use cases of jail zfs property." | ||
|
||
# Root dataset has default value | ||
log_must test "0" = "$(zfs get -o value -H jail $TESTPOOL)" | ||
|
||
# Create the dataset | ||
log_must zfs create -o jailed=on -o mountpoint=$DATASET_JAILED_MOUNTPOINT $DATASET | ||
log_must test "0" = "$(zfs get -o value -H jail $DATASET)" | ||
|
||
# Create the jail | ||
log_must jail -c -f $JAIL_CONF $JAIL | ||
log_mustnot jexec $JAIL zfs list $DATASET | ||
log_must test "0" = "$(zfs get -o value -H jail $DATASET)" | ||
|
||
# Jail the dataset | ||
log_must zfs jail $JAIL $DATASET | ||
log_must jexec $JAIL zfs list $DATASET | ||
log_must test "0" = "$(zfs get -o value -H jail $DATASET)" | ||
log_must test "0" = "$(jexec $JAIL zfs get -o value -H jail $DATASET)" | ||
|
||
# Mount the dataset by the jail | ||
log_must jexec $JAIL zfs mount $DATASET | ||
# Now we see who mounted it | ||
log_must test "$JAIL" = "$(zfs get -o value -H jail $DATASET)" | ||
# But it is hidden from the jail itself | ||
log_must test "0" = "$(jexec $JAIL zfs get -o value -H jail $DATASET)" | ||
|
||
# Unmount the dataset by the jail | ||
log_must jexec $JAIL zfs unmount $DATASET | ||
log_must test "0" = "$(zfs get -o value -H jail $DATASET)" | ||
log_must test "0" = "$(jexec $JAIL zfs get -o value -H jail $DATASET)" | ||
|
||
log_pass "Verify basic use cases of jail zfs property." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not familiar with zones, but wouldn't this functionality apply there too? Would some
ds_zonename
without theifdef
be more universal?