Skip to content

Commit 9a8e5cb

Browse files
committed
FreeBSD: Add zfs jail property
A read-only property to report name of the jail that mounted the dataset. Sponsored-by: SkunkWerks, GmbH Signed-off-by: Igor Ostapenko <[email protected]>
1 parent 6ba51da commit 9a8e5cb

File tree

6 files changed

+49
-0
lines changed

6 files changed

+49
-0
lines changed

include/sys/dsl_dataset.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ typedef struct dsl_dataset {
268268

269269
/* Protected by ds_lock; keep at end of struct for better locality */
270270
char ds_snapname[ZFS_MAX_DATASET_NAME_LEN];
271+
272+
#ifdef __FreeBSD__
273+
char *ds_jailname;
274+
#endif
271275
} dsl_dataset_t;
272276

273277
static inline dsl_dataset_phys_t *

include/sys/fs/zfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ typedef enum {
203203
ZFS_PROP_DEFAULTUSEROBJQUOTA,
204204
ZFS_PROP_DEFAULTGROUPOBJQUOTA,
205205
ZFS_PROP_DEFAULTPROJECTOBJQUOTA,
206+
ZFS_PROP_ZONE,
206207
ZFS_NUM_PROPS
207208
} zfs_prop_t;
208209

man/man7/zfsprops.7

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,14 @@ for more information.
20952095
Jails are a
20962096
.Fx
20972097
feature and this property is not available on other platforms.
2098+
.It Sy jail
2099+
This read-only property reports the name of the jail that mounted the jailed
2100+
dataset.
2101+
The "0" name is used for datasets that are not mounted or not jailed.
2102+
If a jail is renamed, the property will still report its old name from
2103+
the time the dataset was mounted.
2104+
The reported jail may no longer exist, while the dataset remains mounted.
2105+
The property is not revealed to jails, the "0" is reported instead.
20982106
.It Sy zoned Ns = Ns Sy off Ns | Ns Sy on
20992107
Controls whether the dataset is managed from a non-global zone or namespace.
21002108
See

module/os/freebsd/zfs/zfs_vfsops.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,20 @@ zfs_domount(vfs_t *vfsp, char *osname)
13101310

13111311
if (!zfsvfs->z_issnap)
13121312
zfsctl_create(zfsvfs);
1313+
1314+
#ifdef __FreeBSD__
1315+
if (error == 0) {
1316+
/* zone dataset visiblity was checked before in zfs_mount() */
1317+
struct prison *pr = curthread->td_ucred->cr_prison;
1318+
if (pr != &prison0) {
1319+
zfsvfs->z_os->os_dsl_dataset->ds_jailname =
1320+
kmem_zalloc(strlen(pr->pr_name) + 1, KM_SLEEP);
1321+
strcpy(zfsvfs->z_os->os_dsl_dataset->ds_jailname,
1322+
pr->pr_name);
1323+
}
1324+
}
1325+
#endif
1326+
13131327
out:
13141328
if (error) {
13151329
dmu_objset_disown(zfsvfs->z_os, B_TRUE, zfsvfs);
@@ -1783,6 +1797,12 @@ zfs_umount(vfs_t *vfsp, int fflag)
17831797
dmu_objset_set_user(os, NULL);
17841798
mutex_exit(&os->os_user_ptr_lock);
17851799

1800+
#ifdef __FreeBSD__
1801+
if (os->os_dsl_dataset->ds_jailname)
1802+
kmem_strfree(os->os_dsl_dataset->ds_jailname);
1803+
os->os_dsl_dataset->ds_jailname = NULL;
1804+
#endif
1805+
17861806
/*
17871807
* Finally release the objset
17881808
*/

module/zcommon/zfs_prop.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,13 @@ zfs_prop_init(void)
516516
zprop_register_index(ZFS_PROP_ZONED, "jailed", 0, PROP_INHERIT,
517517
ZFS_TYPE_FILESYSTEM, "on | off", "JAILED", boolean_table,
518518
sfeatures);
519+
zprop_register_string(ZFS_PROP_ZONE, "jail", NULL, PROP_READONLY,
520+
ZFS_TYPE_FILESYSTEM, "<jailname> | 0", "JAIL", sfeatures);
519521
#else
520522
zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
521523
ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table, sfeatures);
524+
zprop_register_string(ZFS_PROP_ZONE, "zone", NULL, PROP_READONLY,
525+
ZFS_TYPE_FILESYSTEM, "<zonename>", "ZONE", sfeatures);
522526
#endif
523527
zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
524528
ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", boolean_table, sfeatures);

module/zfs/dsl_prop.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,18 @@ dsl_prop_get_all_ds(dsl_dataset_t *ds, nvlist_t **nvp,
12301230
goto out;
12311231
}
12321232

1233+
#ifdef __FreeBSD__
1234+
nvlist_t *propval;
1235+
dsl_dataset_name(ds, setpoint);
1236+
VERIFY0(nvlist_alloc(&propval, NV_UNIQUE_NAME, KM_SLEEP));
1237+
VERIFY0(nvlist_add_string(propval, ZPROP_VALUE,
1238+
(ds->ds_jailname && INGLOBALZONE(curproc)) ?
1239+
ds->ds_jailname : "0"));
1240+
VERIFY0(nvlist_add_string(propval, ZPROP_SOURCE, setpoint));
1241+
VERIFY0(nvlist_add_nvlist(*nvp, "jail", propval));
1242+
nvlist_free(propval);
1243+
#endif
1244+
12331245
for (; dd != NULL; dd = dd->dd_parent) {
12341246
if (dd != ds->ds_dir || (flags & DSL_PROP_GET_SNAPSHOT)) {
12351247
if (flags & (DSL_PROP_GET_LOCAL |

0 commit comments

Comments
 (0)