Skip to content
Open
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
4 changes: 4 additions & 0 deletions include/sys/dsl_dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ typedef struct dsl_dataset {

/* Protected by ds_lock; keep at end of struct for better locality */
char ds_snapname[ZFS_MAX_DATASET_NAME_LEN];

#ifdef __FreeBSD__
char *ds_jailname;
#endif
} dsl_dataset_t;

static inline dsl_dataset_phys_t *
Expand Down
1 change: 1 addition & 0 deletions include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ typedef enum {
ZFS_PROP_DEFAULTUSEROBJQUOTA,
ZFS_PROP_DEFAULTGROUPOBJQUOTA,
ZFS_PROP_DEFAULTPROJECTOBJQUOTA,
ZFS_PROP_ZONE,
ZFS_NUM_PROPS
} zfs_prop_t;

Expand Down
3 changes: 2 additions & 1 deletion lib/libzfs/libzfs.abi
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,8 @@
<enumerator name='ZFS_PROP_DEFAULTUSEROBJQUOTA' value='103'/>
<enumerator name='ZFS_PROP_DEFAULTGROUPOBJQUOTA' value='104'/>
<enumerator name='ZFS_PROP_DEFAULTPROJECTOBJQUOTA' value='105'/>
<enumerator name='ZFS_NUM_PROPS' value='106'/>
<enumerator name='ZFS_PROP_ZONE' value='106'/>
<enumerator name='ZFS_NUM_PROPS' value='107'/>
</enum-decl>
<typedef-decl name='zfs_prop_t' type-id='4b000d60' id='58603c44'/>
<enum-decl name='zprop_source_t' naming-typedef-id='a2256d42' id='5903f80e'>
Expand Down
8 changes: 8 additions & 0 deletions man/man7/zfsprops.7
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,14 @@ 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 the name of the jail that mounted the jailed
dataset.
The "0" name is used for datasets that are not mounted or not jailed.
If a jail is renamed, the property will still report its old name from
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention the reasoning for "0". What do you think of?:

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 '-' can be a valid jail name.

the time the dataset was mounted.
The reported jail may no longer exist, while the dataset remains mounted.
The property is not revealed to jails, 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
Expand Down
20 changes: 20 additions & 0 deletions module/os/freebsd/zfs/zfs_vfsops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,20 @@ 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_zalloc(strlen(pr->pr_name) + 1, KM_SLEEP);
strcpy(zfsvfs->z_os->os_dsl_dataset->ds_jailname,
pr->pr_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use kmem_strdup(pr->pr_name); to simplify this.

}
}
#endif

out:
if (error) {
dmu_objset_disown(zfsvfs->z_os, B_TRUE, zfsvfs);
Expand Down Expand Up @@ -1783,6 +1797,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
*/
Expand Down
4 changes: 4 additions & 0 deletions module/zcommon/zfs_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,13 @@ zfs_prop_init(void)
zprop_register_index(ZFS_PROP_ZONED, "jailed", 0, PROP_INHERIT,
ZFS_TYPE_FILESYSTEM, "on | off", "JAILED", boolean_table,
sfeatures);
zprop_register_string(ZFS_PROP_ZONE, "jail", NULL, PROP_READONLY,
ZFS_TYPE_FILESYSTEM, "<jailname> | 0", "JAIL", sfeatures);
#else
zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table, sfeatures);
zprop_register_string(ZFS_PROP_ZONE, "zone", NULL, PROP_READONLY,
ZFS_TYPE_FILESYSTEM, "<zonename>", "ZONE", sfeatures);
#endif
zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", boolean_table, sfeatures);
Expand Down
12 changes: 12 additions & 0 deletions module/zfs/dsl_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,18 @@ dsl_prop_get_all_ds(dsl_dataset_t *ds, nvlist_t **nvp,
goto out;
}

#ifdef __FreeBSD__
nvlist_t *propval;
dsl_dataset_name(ds, setpoint);
VERIFY0(nvlist_alloc(&propval, NV_UNIQUE_NAME, KM_SLEEP));
VERIFY0(nvlist_add_string(propval, ZPROP_VALUE,
(ds->ds_jailname && INGLOBALZONE(curproc)) ?
ds->ds_jailname : "0"));
VERIFY0(nvlist_add_string(propval, ZPROP_SOURCE, setpoint));
VERIFY0(nvlist_add_nvlist(*nvp, "jail", propval));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fnvlist_* wrappers should be used here, or better yet add the required error handling even if they're almost certain never to fail.

nvlist_free(propval);
#endif

for (; dd != NULL; dd = dd->dd_parent) {
if (dd != ds->ds_dir || (flags & DSL_PROP_GET_SNAPSHOT)) {
if (flags & (DSL_PROP_GET_LOCAL |
Expand Down
Loading