4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>.
24 * All rights reserved.
25 * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
26 * Copyright (c) 2014 Integros [integros.com]
27 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
30 /* Portions Copyright 2010 Robert Milkowski */
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/sysmacros.h>
39 #include <sys/vnode.h>
41 #include <sys/mntent.h>
42 #include <sys/mount.h>
43 #include <sys/cmn_err.h>
44 #include <sys/zfs_znode.h>
45 #include <sys/zfs_dir.h>
47 #include <sys/fs/zfs.h>
49 #include <sys/dsl_prop.h>
50 #include <sys/dsl_dataset.h>
51 #include <sys/dsl_deleg.h>
55 #include <sys/sa_impl.h>
56 #include <sys/policy.h>
57 #include <sys/atomic.h>
58 #include <sys/zfs_ioctl.h>
59 #include <sys/zfs_ctldir.h>
60 #include <sys/zfs_fuid.h>
61 #include <sys/sunddi.h>
62 #include <sys/dmu_objset.h>
63 #include <sys/dsl_dir.h>
64 #include <sys/spa_boot.h>
66 #include <ufs/ufs/quota.h>
67 #include <sys/zfs_quota.h>
69 #include "zfs_comutil.h"
71 #ifndef MNTK_VMSETSIZE_BUG
72 #define MNTK_VMSETSIZE_BUG 0
75 #define MNTK_NOMSYNC 8
79 struct mtx zfs_debug_mtx;
80 MTX_SYSINIT(zfs_debug_mtx, &zfs_debug_mtx, "zfs_debug", MTX_DEF);
82 SYSCTL_NODE(_vfs, OID_AUTO, zfs, CTLFLAG_RW, 0, "ZFS file system");
85 SYSCTL_INT(_vfs_zfs, OID_AUTO, super_owner, CTLFLAG_RW, &zfs_super_owner, 0,
86 "File system owner can perform privileged operation on his file systems");
89 SYSCTL_INT(_vfs_zfs, OID_AUTO, debug, CTLFLAG_RWTUN, &zfs_debug_level, 0,
92 SYSCTL_NODE(_vfs_zfs, OID_AUTO, version, CTLFLAG_RD, 0, "ZFS versions");
93 static int zfs_version_acl = ZFS_ACL_VERSION;
94 SYSCTL_INT(_vfs_zfs_version, OID_AUTO, acl, CTLFLAG_RD, &zfs_version_acl, 0,
96 static int zfs_version_spa = SPA_VERSION;
97 SYSCTL_INT(_vfs_zfs_version, OID_AUTO, spa, CTLFLAG_RD, &zfs_version_spa, 0,
99 static int zfs_version_zpl = ZPL_VERSION;
100 SYSCTL_INT(_vfs_zfs_version, OID_AUTO, zpl, CTLFLAG_RD, &zfs_version_zpl, 0,
104 static int zfs_quotactl(vfs_t *vfsp, int cmds, uid_t id, void *arg);
105 static int zfs_mount(vfs_t *vfsp);
106 static int zfs_umount(vfs_t *vfsp, int fflag);
107 static int zfs_root(vfs_t *vfsp, int flags, vnode_t **vpp);
108 static int zfs_statfs(vfs_t *vfsp, struct statfs *statp);
109 static int zfs_vget(vfs_t *vfsp, ino_t ino, int flags, vnode_t **vpp);
110 static int zfs_sync(vfs_t *vfsp, int waitfor);
111 #if __FreeBSD_version >= 1300098
112 static int zfs_checkexp(vfs_t *vfsp, struct sockaddr *nam, uint64_t *extflagsp,
113 struct ucred **credanonp, int *numsecflavors, int *secflavors);
115 static int zfs_checkexp(vfs_t *vfsp, struct sockaddr *nam, int *extflagsp,
116 struct ucred **credanonp, int *numsecflavors, int **secflavors);
118 static int zfs_fhtovp(vfs_t *vfsp, fid_t *fidp, int flags, vnode_t **vpp);
119 static void zfs_freevfs(vfs_t *vfsp);
121 struct vfsops zfs_vfsops = {
122 .vfs_mount = zfs_mount,
123 .vfs_unmount = zfs_umount,
124 #if __FreeBSD_version >= 1300049
125 .vfs_root = vfs_cache_root,
126 .vfs_cachedroot = zfs_root,
128 .vfs_root = zfs_root,
130 .vfs_statfs = zfs_statfs,
131 .vfs_vget = zfs_vget,
132 .vfs_sync = zfs_sync,
133 .vfs_checkexp = zfs_checkexp,
134 .vfs_fhtovp = zfs_fhtovp,
135 .vfs_quotactl = zfs_quotactl,
138 VFS_SET(zfs_vfsops, zfs, VFCF_JAIL | VFCF_DELEGADMIN);
141 * We need to keep a count of active fs's.
142 * This is necessary to prevent our module
143 * from being unloaded after a umount -f
145 static uint32_t zfs_active_fs_count = 0;
148 zfs_get_temporary_prop(dsl_dataset_t *ds, zfs_prop_t zfs_prop, uint64_t *val,
157 error = dmu_objset_from_ds(ds, &os);
161 error = getzfsvfs_impl(os, &zfvp);
169 if (vfs_optionisset(vfsp, MNTOPT_NOATIME, NULL))
171 if (vfs_optionisset(vfsp, MNTOPT_ATIME, NULL))
174 case ZFS_PROP_DEVICES:
175 if (vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL))
177 if (vfs_optionisset(vfsp, MNTOPT_DEVICES, NULL))
181 if (vfs_optionisset(vfsp, MNTOPT_NOEXEC, NULL))
183 if (vfs_optionisset(vfsp, MNTOPT_EXEC, NULL))
186 case ZFS_PROP_SETUID:
187 if (vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL))
189 if (vfs_optionisset(vfsp, MNTOPT_SETUID, NULL))
192 case ZFS_PROP_READONLY:
193 if (vfs_optionisset(vfsp, MNTOPT_RW, NULL))
195 if (vfs_optionisset(vfsp, MNTOPT_RO, NULL))
199 if (zfvp->z_flags & ZSB_XATTR)
202 case ZFS_PROP_NBMAND:
203 if (vfs_optionisset(vfsp, MNTOPT_NONBMAND, NULL))
205 if (vfs_optionisset(vfsp, MNTOPT_NBMAND, NULL))
215 (void) strcpy(setpoint, "temporary");
222 zfs_getquota(zfsvfs_t *zfsvfs, uid_t id, int isgroup, struct dqblk64 *dqp)
226 uint64_t usedobj, quotaobj;
227 uint64_t quota, used = 0;
230 usedobj = isgroup ? DMU_GROUPUSED_OBJECT : DMU_USERUSED_OBJECT;
231 quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj;
233 if (quotaobj == 0 || zfsvfs->z_replay) {
237 (void) sprintf(buf, "%llx", (longlong_t)id);
238 if ((error = zap_lookup(zfsvfs->z_os, quotaobj,
239 buf, sizeof (quota), 1, "a)) != 0) {
240 dprintf("%s(%d): quotaobj lookup failed\n",
241 __FUNCTION__, __LINE__);
245 * quota(8) uses bsoftlimit as "quoota", and hardlimit as "limit".
246 * So we set them to be the same.
248 dqp->dqb_bsoftlimit = dqp->dqb_bhardlimit = btodb(quota);
249 error = zap_lookup(zfsvfs->z_os, usedobj, buf, sizeof (used), 1, &used);
250 if (error && error != ENOENT) {
251 dprintf("%s(%d): usedobj failed; %d\n",
252 __FUNCTION__, __LINE__, error);
255 dqp->dqb_curblocks = btodb(used);
256 dqp->dqb_ihardlimit = dqp->dqb_isoftlimit = 0;
259 * Setting this to 0 causes FreeBSD quota(8) to print
260 * the number of days since the epoch, which isn't
261 * particularly useful.
263 dqp->dqb_btime = dqp->dqb_itime = now.tv_sec;
269 zfs_quotactl(vfs_t *vfsp, int cmds, uid_t id, void *arg)
271 zfsvfs_t *zfsvfs = vfsp->vfs_data;
273 int cmd, type, error = 0;
275 zfs_userquota_prop_t quota_type;
276 struct dqblk64 dqblk = { 0 };
279 cmd = cmds >> SUBCMDSHIFT;
280 type = cmds & SUBCMDMASK;
286 id = td->td_ucred->cr_ruid;
289 id = td->td_ucred->cr_rgid;
293 if (cmd == Q_QUOTAON || cmd == Q_QUOTAOFF)
301 * ZFS_PROP_USERQUOTA,
302 * ZFS_PROP_GROUPUSED,
303 * ZFS_PROP_GROUPQUOTA
308 if (type == USRQUOTA)
309 quota_type = ZFS_PROP_USERQUOTA;
310 else if (type == GRPQUOTA)
311 quota_type = ZFS_PROP_GROUPQUOTA;
317 if (type == USRQUOTA)
318 quota_type = ZFS_PROP_USERUSED;
319 else if (type == GRPQUOTA)
320 quota_type = ZFS_PROP_GROUPUSED;
327 * Depending on the cmd, we may need to get
328 * the ruid and domain (see fuidstr_to_sid?),
329 * the fuid (how?), or other information.
330 * Create fuid using zfs_fuid_create(zfsvfs, id,
331 * ZFS_OWNER or ZFS_GROUP, cr, &fuidp)?
332 * I think I can use just the id?
334 * Look at zfs_id_overquota() to look up a quota.
335 * zap_lookup(something, quotaobj, fuidstring,
336 * sizeof (long long), 1, "a)
338 * See zfs_set_userquota() to set a quota.
340 if ((uint32_t)type >= MAXQUOTAS) {
348 error = copyout(&bitsize, arg, sizeof (int));
351 // As far as I can tell, you can't turn quotas on or off on zfs
360 error = copyin(arg, &dqblk, sizeof (dqblk));
362 error = zfs_set_userquota(zfsvfs, quota_type,
363 "", id, dbtob(dqblk.dqb_bhardlimit));
366 error = zfs_getquota(zfsvfs, id, type == GRPQUOTA, &dqblk);
368 error = copyout(&dqblk, arg, sizeof (dqblk));
381 zfs_is_readonly(zfsvfs_t *zfsvfs)
383 return (!!(zfsvfs->z_vfs->vfs_flag & VFS_RDONLY));
388 zfs_sync(vfs_t *vfsp, int waitfor)
392 * Data integrity is job one. We don't want a compromised kernel
393 * writing to the storage pool, so we never sync during panic.
399 * Ignore the system syncher. ZFS already commits async data
400 * at zfs_txg_timeout intervals.
402 if (waitfor == MNT_LAZY)
407 * Sync a specific filesystem.
409 zfsvfs_t *zfsvfs = vfsp->vfs_data;
413 error = vfs_stdsync(vfsp, waitfor);
418 dp = dmu_objset_pool(zfsvfs->z_os);
421 * If the system is shutting down, then skip any
422 * filesystems which may exist on a suspended pool.
424 if (rebooting && spa_suspended(dp->dp_spa)) {
429 if (zfsvfs->z_log != NULL)
430 zil_commit(zfsvfs->z_log, 0);
435 * Sync all ZFS filesystems. This is what happens when you
436 * run sync(1M). Unlike other filesystems, ZFS honors the
437 * request by waiting for all pools to commit all dirty data.
446 atime_changed_cb(void *arg, uint64_t newval)
448 zfsvfs_t *zfsvfs = arg;
450 if (newval == TRUE) {
451 zfsvfs->z_atime = TRUE;
452 zfsvfs->z_vfs->vfs_flag &= ~MNT_NOATIME;
453 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME);
454 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_ATIME, NULL, 0);
456 zfsvfs->z_atime = FALSE;
457 zfsvfs->z_vfs->vfs_flag |= MNT_NOATIME;
458 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_ATIME);
459 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME, NULL, 0);
464 xattr_changed_cb(void *arg, uint64_t newval)
466 zfsvfs_t *zfsvfs = arg;
468 if (newval == ZFS_XATTR_OFF) {
469 zfsvfs->z_flags &= ~ZSB_XATTR;
471 zfsvfs->z_flags |= ZSB_XATTR;
473 if (newval == ZFS_XATTR_SA)
474 zfsvfs->z_xattr_sa = B_TRUE;
476 zfsvfs->z_xattr_sa = B_FALSE;
481 blksz_changed_cb(void *arg, uint64_t newval)
483 zfsvfs_t *zfsvfs = arg;
484 ASSERT3U(newval, <=, spa_maxblocksize(dmu_objset_spa(zfsvfs->z_os)));
485 ASSERT3U(newval, >=, SPA_MINBLOCKSIZE);
486 ASSERT(ISP2(newval));
488 zfsvfs->z_max_blksz = newval;
489 zfsvfs->z_vfs->mnt_stat.f_iosize = newval;
493 readonly_changed_cb(void *arg, uint64_t newval)
495 zfsvfs_t *zfsvfs = arg;
498 /* XXX locking on vfs_flag? */
499 zfsvfs->z_vfs->vfs_flag |= VFS_RDONLY;
500 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RW);
501 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RO, NULL, 0);
503 /* XXX locking on vfs_flag? */
504 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
505 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RO);
506 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RW, NULL, 0);
511 setuid_changed_cb(void *arg, uint64_t newval)
513 zfsvfs_t *zfsvfs = arg;
515 if (newval == FALSE) {
516 zfsvfs->z_vfs->vfs_flag |= VFS_NOSETUID;
517 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_SETUID);
518 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID, NULL, 0);
520 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOSETUID;
521 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID);
522 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_SETUID, NULL, 0);
527 exec_changed_cb(void *arg, uint64_t newval)
529 zfsvfs_t *zfsvfs = arg;
531 if (newval == FALSE) {
532 zfsvfs->z_vfs->vfs_flag |= VFS_NOEXEC;
533 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_EXEC);
534 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC, NULL, 0);
536 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOEXEC;
537 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC);
538 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_EXEC, NULL, 0);
543 * The nbmand mount option can be changed at mount time.
544 * We can't allow it to be toggled on live file systems or incorrect
545 * behavior may be seen from cifs clients
547 * This property isn't registered via dsl_prop_register(), but this callback
548 * will be called when a file system is first mounted
551 nbmand_changed_cb(void *arg, uint64_t newval)
553 zfsvfs_t *zfsvfs = arg;
554 if (newval == FALSE) {
555 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND);
556 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND, NULL, 0);
558 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND);
559 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND, NULL, 0);
564 snapdir_changed_cb(void *arg, uint64_t newval)
566 zfsvfs_t *zfsvfs = arg;
568 zfsvfs->z_show_ctldir = newval;
572 vscan_changed_cb(void *arg, uint64_t newval)
574 zfsvfs_t *zfsvfs = arg;
576 zfsvfs->z_vscan = newval;
580 acl_mode_changed_cb(void *arg, uint64_t newval)
582 zfsvfs_t *zfsvfs = arg;
584 zfsvfs->z_acl_mode = newval;
588 acl_inherit_changed_cb(void *arg, uint64_t newval)
590 zfsvfs_t *zfsvfs = arg;
592 zfsvfs->z_acl_inherit = newval;
596 zfs_register_callbacks(vfs_t *vfsp)
598 struct dsl_dataset *ds = NULL;
600 zfsvfs_t *zfsvfs = NULL;
602 boolean_t readonly = B_FALSE;
603 boolean_t do_readonly = B_FALSE;
604 boolean_t setuid = B_FALSE;
605 boolean_t do_setuid = B_FALSE;
606 boolean_t exec = B_FALSE;
607 boolean_t do_exec = B_FALSE;
608 boolean_t xattr = B_FALSE;
609 boolean_t atime = B_FALSE;
610 boolean_t do_atime = B_FALSE;
611 boolean_t do_xattr = B_FALSE;
615 zfsvfs = vfsp->vfs_data;
620 * This function can be called for a snapshot when we update snapshot's
621 * mount point, which isn't really supported.
623 if (dmu_objset_is_snapshot(os))
627 * The act of registering our callbacks will destroy any mount
628 * options we may have. In order to enable temporary overrides
629 * of mount options, we stash away the current values and
630 * restore them after we register the callbacks.
632 if (vfs_optionisset(vfsp, MNTOPT_RO, NULL) ||
633 !spa_writeable(dmu_objset_spa(os))) {
635 do_readonly = B_TRUE;
636 } else if (vfs_optionisset(vfsp, MNTOPT_RW, NULL)) {
638 do_readonly = B_TRUE;
640 if (vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL)) {
643 } else if (vfs_optionisset(vfsp, MNTOPT_SETUID, NULL)) {
647 if (vfs_optionisset(vfsp, MNTOPT_NOEXEC, NULL)) {
650 } else if (vfs_optionisset(vfsp, MNTOPT_EXEC, NULL)) {
654 if (vfs_optionisset(vfsp, MNTOPT_NOXATTR, NULL)) {
655 zfsvfs->z_xattr = xattr = ZFS_XATTR_OFF;
657 } else if (vfs_optionisset(vfsp, MNTOPT_XATTR, NULL)) {
658 zfsvfs->z_xattr = xattr = ZFS_XATTR_DIR;
660 } else if (vfs_optionisset(vfsp, MNTOPT_DIRXATTR, NULL)) {
661 zfsvfs->z_xattr = xattr = ZFS_XATTR_DIR;
663 } else if (vfs_optionisset(vfsp, MNTOPT_SAXATTR, NULL)) {
664 zfsvfs->z_xattr = xattr = ZFS_XATTR_SA;
667 if (vfs_optionisset(vfsp, MNTOPT_NOATIME, NULL)) {
670 } else if (vfs_optionisset(vfsp, MNTOPT_ATIME, NULL)) {
676 * We need to enter pool configuration here, so that we can use
677 * dsl_prop_get_int_ds() to handle the special nbmand property below.
678 * dsl_prop_get_integer() can not be used, because it has to acquire
679 * spa_namespace_lock and we can not do that because we already hold
680 * z_teardown_lock. The problem is that spa_write_cachefile() is called
681 * with spa_namespace_lock held and the function calls ZFS vnode
682 * operations to write the cache file and thus z_teardown_lock is
683 * acquired after spa_namespace_lock.
685 ds = dmu_objset_ds(os);
686 dsl_pool_config_enter(dmu_objset_pool(os), FTAG);
689 * nbmand is a special property. It can only be changed at
692 * This is weird, but it is documented to only be changeable
695 if (vfs_optionisset(vfsp, MNTOPT_NONBMAND, NULL)) {
697 } else if (vfs_optionisset(vfsp, MNTOPT_NBMAND, NULL)) {
699 } else if ((error = dsl_prop_get_int_ds(ds, "nbmand", &nbmand) != 0)) {
700 dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
705 * Register property callbacks.
707 * It would probably be fine to just check for i/o error from
708 * the first prop_register(), but I guess I like to go
711 error = dsl_prop_register(ds,
712 zfs_prop_to_name(ZFS_PROP_ATIME), atime_changed_cb, zfsvfs);
713 error = error ? error : dsl_prop_register(ds,
714 zfs_prop_to_name(ZFS_PROP_XATTR), xattr_changed_cb, zfsvfs);
715 error = error ? error : dsl_prop_register(ds,
716 zfs_prop_to_name(ZFS_PROP_RECORDSIZE), blksz_changed_cb, zfsvfs);
717 error = error ? error : dsl_prop_register(ds,
718 zfs_prop_to_name(ZFS_PROP_READONLY), readonly_changed_cb, zfsvfs);
719 error = error ? error : dsl_prop_register(ds,
720 zfs_prop_to_name(ZFS_PROP_SETUID), setuid_changed_cb, zfsvfs);
721 error = error ? error : dsl_prop_register(ds,
722 zfs_prop_to_name(ZFS_PROP_EXEC), exec_changed_cb, zfsvfs);
723 error = error ? error : dsl_prop_register(ds,
724 zfs_prop_to_name(ZFS_PROP_SNAPDIR), snapdir_changed_cb, zfsvfs);
725 error = error ? error : dsl_prop_register(ds,
726 zfs_prop_to_name(ZFS_PROP_ACLMODE), acl_mode_changed_cb, zfsvfs);
727 error = error ? error : dsl_prop_register(ds,
728 zfs_prop_to_name(ZFS_PROP_ACLINHERIT), acl_inherit_changed_cb,
730 error = error ? error : dsl_prop_register(ds,
731 zfs_prop_to_name(ZFS_PROP_VSCAN), vscan_changed_cb, zfsvfs);
732 dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
737 * Invoke our callbacks to restore temporary mount options.
740 readonly_changed_cb(zfsvfs, readonly);
742 setuid_changed_cb(zfsvfs, setuid);
744 exec_changed_cb(zfsvfs, exec);
746 xattr_changed_cb(zfsvfs, xattr);
748 atime_changed_cb(zfsvfs, atime);
750 nbmand_changed_cb(zfsvfs, nbmand);
755 dsl_prop_unregister_all(ds, zfsvfs);
760 * Associate this zfsvfs with the given objset, which must be owned.
761 * This will cache a bunch of on-disk state from the objset in the
765 zfsvfs_init(zfsvfs_t *zfsvfs, objset_t *os)
770 zfsvfs->z_max_blksz = SPA_OLD_MAXBLOCKSIZE;
771 zfsvfs->z_show_ctldir = ZFS_SNAPDIR_VISIBLE;
774 error = zfs_get_zplprop(os, ZFS_PROP_VERSION, &zfsvfs->z_version);
777 if (zfsvfs->z_version >
778 zfs_zpl_version_map(spa_version(dmu_objset_spa(os)))) {
779 (void) printf("Can't mount a version %lld file system "
780 "on a version %lld pool\n. Pool must be upgraded to mount "
781 "this file system.", (u_longlong_t)zfsvfs->z_version,
782 (u_longlong_t)spa_version(dmu_objset_spa(os)));
783 return (SET_ERROR(ENOTSUP));
785 error = zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &val);
788 zfsvfs->z_norm = (int)val;
790 error = zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &val);
793 zfsvfs->z_utf8 = (val != 0);
795 error = zfs_get_zplprop(os, ZFS_PROP_CASE, &val);
798 zfsvfs->z_case = (uint_t)val;
801 * Fold case on file systems that are always or sometimes case
804 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
805 zfsvfs->z_case == ZFS_CASE_MIXED)
806 zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER;
808 zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
809 zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
812 if (zfsvfs->z_use_sa) {
813 /* should either have both of these objects or none */
814 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SA_ATTRS, 8, 1,
820 error = sa_setup(os, sa_obj, zfs_attr_table, ZPL_END,
821 &zfsvfs->z_attr_table);
825 if (zfsvfs->z_version >= ZPL_VERSION_SA)
826 sa_register_update_callback(os, zfs_sa_upgrade);
828 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1,
832 ASSERT(zfsvfs->z_root != 0);
834 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_UNLINKED_SET, 8, 1,
835 &zfsvfs->z_unlinkedobj);
839 error = zap_lookup(os, MASTER_NODE_OBJ,
840 zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA],
841 8, 1, &zfsvfs->z_userquota_obj);
843 zfsvfs->z_userquota_obj = 0;
847 error = zap_lookup(os, MASTER_NODE_OBJ,
848 zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA],
849 8, 1, &zfsvfs->z_groupquota_obj);
851 zfsvfs->z_groupquota_obj = 0;
855 error = zap_lookup(os, MASTER_NODE_OBJ,
856 zfs_userquota_prop_prefixes[ZFS_PROP_PROJECTQUOTA],
857 8, 1, &zfsvfs->z_projectquota_obj);
859 zfsvfs->z_projectquota_obj = 0;
863 error = zap_lookup(os, MASTER_NODE_OBJ,
864 zfs_userquota_prop_prefixes[ZFS_PROP_USEROBJQUOTA],
865 8, 1, &zfsvfs->z_userobjquota_obj);
867 zfsvfs->z_userobjquota_obj = 0;
871 error = zap_lookup(os, MASTER_NODE_OBJ,
872 zfs_userquota_prop_prefixes[ZFS_PROP_GROUPOBJQUOTA],
873 8, 1, &zfsvfs->z_groupobjquota_obj);
875 zfsvfs->z_groupobjquota_obj = 0;
879 error = zap_lookup(os, MASTER_NODE_OBJ,
880 zfs_userquota_prop_prefixes[ZFS_PROP_PROJECTOBJQUOTA],
881 8, 1, &zfsvfs->z_projectobjquota_obj);
883 zfsvfs->z_projectobjquota_obj = 0;
887 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES, 8, 1,
888 &zfsvfs->z_fuid_obj);
890 zfsvfs->z_fuid_obj = 0;
894 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SHARES_DIR, 8, 1,
895 &zfsvfs->z_shares_dir);
897 zfsvfs->z_shares_dir = 0;
902 * Only use the name cache if we are looking for a
903 * name on a file system that does not require normalization
904 * or case folding. We can also look there if we happen to be
905 * on a non-normalizing, mixed sensitivity file system IF we
906 * are looking for the exact name (which is always the case on
909 zfsvfs->z_use_namecache = !zfsvfs->z_norm ||
910 ((zfsvfs->z_case == ZFS_CASE_MIXED) &&
911 !(zfsvfs->z_norm & ~U8_TEXTPREP_TOUPPER));
916 taskq_t *zfsvfs_taskq;
919 zfsvfs_task_unlinked_drain(void *context, int pending __unused)
922 zfs_unlinked_drain((zfsvfs_t *)context);
926 zfsvfs_create(const char *osname, boolean_t readonly, zfsvfs_t **zfvp)
931 boolean_t ro = (readonly || (strchr(osname, '@') != NULL));
934 * XXX: Fix struct statfs so this isn't necessary!
936 * The 'osname' is used as the filesystem's special node, which means
937 * it must fit in statfs.f_mntfromname, or else it can't be
938 * enumerated, so libzfs_mnttab_find() returns NULL, which causes
939 * 'zfs unmount' to think it's not mounted when it is.
941 if (strlen(osname) >= MNAMELEN)
942 return (SET_ERROR(ENAMETOOLONG));
944 zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP);
946 error = dmu_objset_own(osname, DMU_OST_ZFS, ro, B_TRUE, zfsvfs,
949 kmem_free(zfsvfs, sizeof (zfsvfs_t));
953 error = zfsvfs_create_impl(zfvp, zfsvfs, os);
960 zfsvfs_create_impl(zfsvfs_t **zfvp, zfsvfs_t *zfsvfs, objset_t *os)
964 zfsvfs->z_vfs = NULL;
965 zfsvfs->z_parent = zfsvfs;
967 mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
968 mutex_init(&zfsvfs->z_lock, NULL, MUTEX_DEFAULT, NULL);
969 list_create(&zfsvfs->z_all_znodes, sizeof (znode_t),
970 offsetof(znode_t, z_link_node));
971 TASK_INIT(&zfsvfs->z_unlinked_drain_task, 0,
972 zfsvfs_task_unlinked_drain, zfsvfs);
974 rrm_init(&zfsvfs->z_teardown_lock, B_TRUE);
976 rrm_init(&zfsvfs->z_teardown_lock, B_FALSE);
978 rw_init(&zfsvfs->z_teardown_inactive_lock, NULL, RW_DEFAULT, NULL);
979 rw_init(&zfsvfs->z_fuid_lock, NULL, RW_DEFAULT, NULL);
980 for (int i = 0; i != ZFS_OBJ_MTX_SZ; i++)
981 mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
983 error = zfsvfs_init(zfsvfs, os);
985 dmu_objset_disown(os, B_TRUE, zfsvfs);
987 kmem_free(zfsvfs, sizeof (zfsvfs_t));
996 zfsvfs_setup(zfsvfs_t *zfsvfs, boolean_t mounting)
1001 * Check for a bad on-disk format version now since we
1002 * lied about owning the dataset readonly before.
1004 if (!(zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) &&
1005 dmu_objset_incompatible_encryption_version(zfsvfs->z_os))
1006 return (SET_ERROR(EROFS));
1008 error = zfs_register_callbacks(zfsvfs->z_vfs);
1012 zfsvfs->z_log = zil_open(zfsvfs->z_os, zfs_get_data);
1015 * If we are not mounting (ie: online recv), then we don't
1016 * have to worry about replaying the log as we blocked all
1017 * operations out since we closed the ZIL.
1022 ASSERT3P(zfsvfs->z_kstat.dk_kstats, ==, NULL);
1023 dataset_kstats_create(&zfsvfs->z_kstat, zfsvfs->z_os);
1026 * During replay we remove the read only flag to
1027 * allow replays to succeed.
1029 readonly = zfsvfs->z_vfs->vfs_flag & VFS_RDONLY;
1030 if (readonly != 0) {
1031 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
1036 if (zap_get_stats(zfsvfs->z_os, zfsvfs->z_unlinkedobj,
1038 dataset_kstats_update_nunlinks_kstat(
1039 &zfsvfs->z_kstat, zs.zs_num_entries);
1040 dprintf_ds(zfsvfs->z_os->os_dsl_dataset,
1041 "num_entries in unlinked set: %llu",
1045 zfs_unlinked_drain(zfsvfs);
1046 dd = zfsvfs->z_os->os_dsl_dataset->ds_dir;
1047 dd->dd_activity_cancelled = B_FALSE;
1051 * Parse and replay the intent log.
1053 * Because of ziltest, this must be done after
1054 * zfs_unlinked_drain(). (Further note: ziltest
1055 * doesn't use readonly mounts, where
1056 * zfs_unlinked_drain() isn't called.) This is because
1057 * ziltest causes spa_sync() to think it's committed,
1058 * but actually it is not, so the intent log contains
1059 * many txg's worth of changes.
1061 * In particular, if object N is in the unlinked set in
1062 * the last txg to actually sync, then it could be
1063 * actually freed in a later txg and then reallocated
1064 * in a yet later txg. This would write a "create
1065 * object N" record to the intent log. Normally, this
1066 * would be fine because the spa_sync() would have
1067 * written out the fact that object N is free, before
1068 * we could write the "create object N" intent log
1071 * But when we are in ziltest mode, we advance the "open
1072 * txg" without actually spa_sync()-ing the changes to
1073 * disk. So we would see that object N is still
1074 * allocated and in the unlinked set, and there is an
1075 * intent log record saying to allocate it.
1077 if (spa_writeable(dmu_objset_spa(zfsvfs->z_os))) {
1078 if (zil_replay_disable) {
1079 zil_destroy(zfsvfs->z_log, B_FALSE);
1081 boolean_t use_nc = zfsvfs->z_use_namecache;
1082 zfsvfs->z_use_namecache = B_FALSE;
1083 zfsvfs->z_replay = B_TRUE;
1084 zil_replay(zfsvfs->z_os, zfsvfs,
1086 zfsvfs->z_replay = B_FALSE;
1087 zfsvfs->z_use_namecache = use_nc;
1091 /* restore readonly bit */
1093 zfsvfs->z_vfs->vfs_flag |= VFS_RDONLY;
1097 * Set the objset user_ptr to track its zfsvfs.
1099 mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
1100 dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
1101 mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
1106 extern krwlock_t zfsvfs_lock; /* in zfs_znode.c */
1109 zfsvfs_free(zfsvfs_t *zfsvfs)
1114 * This is a barrier to prevent the filesystem from going away in
1115 * zfs_znode_move() until we can safely ensure that the filesystem is
1116 * not unmounted. We consider the filesystem valid before the barrier
1117 * and invalid after the barrier.
1119 rw_enter(&zfsvfs_lock, RW_READER);
1120 rw_exit(&zfsvfs_lock);
1122 zfs_fuid_destroy(zfsvfs);
1124 mutex_destroy(&zfsvfs->z_znodes_lock);
1125 mutex_destroy(&zfsvfs->z_lock);
1126 ASSERT(zfsvfs->z_nr_znodes == 0);
1127 list_destroy(&zfsvfs->z_all_znodes);
1128 rrm_destroy(&zfsvfs->z_teardown_lock);
1129 rw_destroy(&zfsvfs->z_teardown_inactive_lock);
1130 rw_destroy(&zfsvfs->z_fuid_lock);
1131 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
1132 mutex_destroy(&zfsvfs->z_hold_mtx[i]);
1133 dataset_kstats_destroy(&zfsvfs->z_kstat);
1134 kmem_free(zfsvfs, sizeof (zfsvfs_t));
1138 zfs_set_fuid_feature(zfsvfs_t *zfsvfs)
1140 zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
1141 if (zfsvfs->z_vfs) {
1142 if (zfsvfs->z_use_fuids) {
1143 vfs_set_feature(zfsvfs->z_vfs, VFSFT_XVATTR);
1144 vfs_set_feature(zfsvfs->z_vfs, VFSFT_SYSATTR_VIEWS);
1145 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACEMASKONACCESS);
1146 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACLONCREATE);
1147 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACCESS_FILTER);
1148 vfs_set_feature(zfsvfs->z_vfs, VFSFT_REPARSE);
1150 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_XVATTR);
1151 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_SYSATTR_VIEWS);
1152 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_ACEMASKONACCESS);
1153 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_ACLONCREATE);
1154 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_ACCESS_FILTER);
1155 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_REPARSE);
1158 zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
1162 zfs_domount(vfs_t *vfsp, char *osname)
1164 uint64_t recordsize, fsid_guid;
1171 error = zfsvfs_create(osname, vfsp->mnt_flag & MNT_RDONLY, &zfsvfs);
1174 zfsvfs->z_vfs = vfsp;
1176 if ((error = dsl_prop_get_integer(osname,
1177 "recordsize", &recordsize, NULL)))
1179 zfsvfs->z_vfs->vfs_bsize = SPA_MINBLOCKSIZE;
1180 zfsvfs->z_vfs->mnt_stat.f_iosize = recordsize;
1182 vfsp->vfs_data = zfsvfs;
1183 vfsp->mnt_flag |= MNT_LOCAL;
1184 vfsp->mnt_kern_flag |= MNTK_LOOKUP_SHARED;
1185 vfsp->mnt_kern_flag |= MNTK_SHARED_WRITES;
1186 vfsp->mnt_kern_flag |= MNTK_EXTENDED_SHARED;
1188 * This can cause a loss of coherence between ARC and page cache
1189 * on ZoF - unclear if the problem is in FreeBSD or ZoF
1191 vfsp->mnt_kern_flag |= MNTK_NO_IOPF; /* vn_io_fault can be used */
1192 vfsp->mnt_kern_flag |= MNTK_NOMSYNC;
1193 vfsp->mnt_kern_flag |= MNTK_VMSETSIZE_BUG;
1195 #if defined(_KERNEL) && !defined(KMEM_DEBUG)
1196 vfsp->mnt_kern_flag |= MNTK_FPLOOKUP;
1199 * The fsid is 64 bits, composed of an 8-bit fs type, which
1200 * separates our fsid from any other filesystem types, and a
1201 * 56-bit objset unique ID. The objset unique ID is unique to
1202 * all objsets open on this system, provided by unique_create().
1203 * The 8-bit fs type must be put in the low bits of fsid[1]
1204 * because that's where other Solaris filesystems put it.
1206 fsid_guid = dmu_objset_fsid_guid(zfsvfs->z_os);
1207 ASSERT((fsid_guid & ~((1ULL<<56)-1)) == 0);
1208 vfsp->vfs_fsid.val[0] = fsid_guid;
1209 vfsp->vfs_fsid.val[1] = ((fsid_guid>>32) << 8) |
1210 (vfsp->mnt_vfc->vfc_typenum & 0xFF);
1213 * Set features for file system.
1215 zfs_set_fuid_feature(zfsvfs);
1216 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE) {
1217 vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS);
1218 vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE);
1219 vfs_set_feature(vfsp, VFSFT_NOCASESENSITIVE);
1220 } else if (zfsvfs->z_case == ZFS_CASE_MIXED) {
1221 vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS);
1222 vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE);
1224 vfs_set_feature(vfsp, VFSFT_ZEROCOPY_SUPPORTED);
1226 if (dmu_objset_is_snapshot(zfsvfs->z_os)) {
1229 atime_changed_cb(zfsvfs, B_FALSE);
1230 readonly_changed_cb(zfsvfs, B_TRUE);
1231 if ((error = dsl_prop_get_integer(osname,
1232 "xattr", &pval, NULL)))
1234 xattr_changed_cb(zfsvfs, pval);
1235 zfsvfs->z_issnap = B_TRUE;
1236 zfsvfs->z_os->os_sync = ZFS_SYNC_DISABLED;
1238 mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
1239 dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
1240 mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
1242 if ((error = zfsvfs_setup(zfsvfs, B_TRUE)))
1246 vfs_mountedfrom(vfsp, osname);
1248 if (!zfsvfs->z_issnap)
1249 zfsctl_create(zfsvfs);
1252 dmu_objset_disown(zfsvfs->z_os, B_TRUE, zfsvfs);
1253 zfsvfs_free(zfsvfs);
1255 atomic_inc_32(&zfs_active_fs_count);
1262 zfs_unregister_callbacks(zfsvfs_t *zfsvfs)
1264 objset_t *os = zfsvfs->z_os;
1266 if (!dmu_objset_is_snapshot(os))
1267 dsl_prop_unregister_all(dmu_objset_ds(os), zfsvfs);
1272 * Convert a decimal digit string to a uint64_t integer.
1275 str_to_uint64(char *str, uint64_t *objnum)
1280 if (*str < '0' || *str > '9')
1281 return (SET_ERROR(EINVAL));
1283 num = num*10 + *str++ - '0';
1291 * The boot path passed from the boot loader is in the form of
1292 * "rootpool-name/root-filesystem-object-number'. Convert this
1293 * string to a dataset name: "rootpool-name/root-filesystem-name".
1296 zfs_parse_bootfs(char *bpath, char *outpath)
1302 if (*bpath == 0 || *bpath == '/')
1303 return (SET_ERROR(EINVAL));
1305 (void) strcpy(outpath, bpath);
1307 slashp = strchr(bpath, '/');
1309 /* if no '/', just return the pool name */
1310 if (slashp == NULL) {
1314 /* if not a number, just return the root dataset name */
1315 if (str_to_uint64(slashp+1, &objnum)) {
1320 error = dsl_dsobj_to_dsname(bpath, objnum, outpath);
1327 * Check that the hex label string is appropriate for the dataset being
1328 * mounted into the global_zone proper.
1330 * Return an error if the hex label string is not default or
1331 * admin_low/admin_high. For admin_low labels, the corresponding
1332 * dataset must be readonly.
1335 zfs_check_global_label(const char *dsname, const char *hexsl)
1337 if (strcasecmp(hexsl, ZFS_MLSLABEL_DEFAULT) == 0)
1339 if (strcasecmp(hexsl, ADMIN_HIGH) == 0)
1341 if (strcasecmp(hexsl, ADMIN_LOW) == 0) {
1342 /* must be readonly */
1345 if (dsl_prop_get_integer(dsname,
1346 zfs_prop_to_name(ZFS_PROP_READONLY), &rdonly, NULL))
1347 return (SET_ERROR(EACCES));
1348 return (rdonly ? 0 : EACCES);
1350 return (SET_ERROR(EACCES));
1354 * Determine whether the mount is allowed according to MAC check.
1355 * by comparing (where appropriate) label of the dataset against
1356 * the label of the zone being mounted into. If the dataset has
1357 * no label, create one.
1359 * Returns 0 if access allowed, error otherwise (e.g. EACCES)
1362 zfs_mount_label_policy(vfs_t *vfsp, char *osname)
1365 zone_t *mntzone = NULL;
1366 ts_label_t *mnt_tsl;
1369 char ds_hexsl[MAXNAMELEN];
1371 retv = EACCES; /* assume the worst */
1374 * Start by getting the dataset label if it exists.
1376 error = dsl_prop_get(osname, zfs_prop_to_name(ZFS_PROP_MLSLABEL),
1377 1, sizeof (ds_hexsl), &ds_hexsl, NULL);
1379 return (SET_ERROR(EACCES));
1382 * If labeling is NOT enabled, then disallow the mount of datasets
1383 * which have a non-default label already. No other label checks
1386 if (!is_system_labeled()) {
1387 if (strcasecmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) == 0)
1389 return (SET_ERROR(EACCES));
1393 * Get the label of the mountpoint. If mounting into the global
1394 * zone (i.e. mountpoint is not within an active zone and the
1395 * zoned property is off), the label must be default or
1396 * admin_low/admin_high only; no other checks are needed.
1398 mntzone = zone_find_by_any_path(vfsp->vfs_mntpt, B_FALSE);
1399 if (mntzone->zone_id == GLOBAL_ZONEID) {
1404 if (dsl_prop_get_integer(osname,
1405 zfs_prop_to_name(ZFS_PROP_ZONED), &zoned, NULL))
1406 return (SET_ERROR(EACCES));
1408 return (zfs_check_global_label(osname, ds_hexsl));
1411 * This is the case of a zone dataset being mounted
1412 * initially, before the zone has been fully created;
1413 * allow this mount into global zone.
1418 mnt_tsl = mntzone->zone_slabel;
1419 ASSERT(mnt_tsl != NULL);
1420 label_hold(mnt_tsl);
1421 mnt_sl = label2bslabel(mnt_tsl);
1423 if (strcasecmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) == 0) {
1425 * The dataset doesn't have a real label, so fabricate one.
1429 if (l_to_str_internal(mnt_sl, &str) == 0 &&
1430 dsl_prop_set_string(osname,
1431 zfs_prop_to_name(ZFS_PROP_MLSLABEL),
1432 ZPROP_SRC_LOCAL, str) == 0)
1435 kmem_free(str, strlen(str) + 1);
1436 } else if (hexstr_to_label(ds_hexsl, &ds_sl) == 0) {
1438 * Now compare labels to complete the MAC check. If the
1439 * labels are equal then allow access. If the mountpoint
1440 * label dominates the dataset label, allow readonly access.
1441 * Otherwise, access is denied.
1443 if (blequal(mnt_sl, &ds_sl))
1445 else if (bldominates(mnt_sl, &ds_sl)) {
1446 vfs_setmntopt(vfsp, MNTOPT_RO, NULL, 0);
1451 label_rele(mnt_tsl);
1455 #endif /* SECLABEL */
1458 getpoolname(const char *osname, char *poolname)
1462 p = strchr(osname, '/');
1464 if (strlen(osname) >= MAXNAMELEN)
1465 return (ENAMETOOLONG);
1466 (void) strcpy(poolname, osname);
1468 if (p - osname >= MAXNAMELEN)
1469 return (ENAMETOOLONG);
1470 (void) strncpy(poolname, osname, p - osname);
1471 poolname[p - osname] = '\0';
1478 zfs_mount(vfs_t *vfsp)
1480 kthread_t *td = curthread;
1481 vnode_t *mvp = vfsp->mnt_vnodecovered;
1482 cred_t *cr = td->td_ucred;
1487 if (vfs_getopt(vfsp->mnt_optnew, "from", (void **)&osname, NULL))
1488 return (SET_ERROR(EINVAL));
1491 * If full-owner-access is enabled and delegated administration is
1492 * turned on, we must set nosuid.
1494 if (zfs_super_owner &&
1495 dsl_deleg_access(osname, ZFS_DELEG_PERM_MOUNT, cr) != ECANCELED) {
1496 secpolicy_fs_mount_clearopts(cr, vfsp);
1500 * Check for mount privilege?
1502 * If we don't have privilege then see if
1503 * we have local permission to allow it
1505 error = secpolicy_fs_mount(cr, mvp, vfsp);
1507 if (dsl_deleg_access(osname, ZFS_DELEG_PERM_MOUNT, cr) != 0)
1510 if (!(vfsp->vfs_flag & MS_REMOUNT)) {
1514 * Make sure user is the owner of the mount point
1515 * or has sufficient privileges.
1518 vattr.va_mask = AT_UID;
1520 vn_lock(mvp, LK_SHARED | LK_RETRY);
1521 if (VOP_GETATTR(mvp, &vattr, cr)) {
1526 if (secpolicy_vnode_owner(mvp, cr, vattr.va_uid) != 0 &&
1527 VOP_ACCESS(mvp, VWRITE, cr, td) != 0) {
1534 secpolicy_fs_mount_clearopts(cr, vfsp);
1538 * Refuse to mount a filesystem if we are in a local zone and the
1539 * dataset is not visible.
1541 if (!INGLOBALZONE(curproc) &&
1542 (!zone_dataset_visible(osname, &canwrite) || !canwrite)) {
1543 error = SET_ERROR(EPERM);
1548 error = zfs_mount_label_policy(vfsp, osname);
1553 vfsp->vfs_flag |= MNT_NFS4ACLS;
1556 * When doing a remount, we simply refresh our temporary properties
1557 * according to those options set in the current VFS options.
1559 if (vfsp->vfs_flag & MS_REMOUNT) {
1560 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1563 * Refresh mount options with z_teardown_lock blocking I/O while
1564 * the filesystem is in an inconsistent state.
1565 * The lock also serializes this code with filesystem
1566 * manipulations between entry to zfs_suspend_fs() and return
1567 * from zfs_resume_fs().
1569 rrm_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG);
1570 zfs_unregister_callbacks(zfsvfs);
1571 error = zfs_register_callbacks(vfsp);
1572 rrm_exit(&zfsvfs->z_teardown_lock, FTAG);
1576 /* Initial root mount: try hard to import the requested root pool. */
1577 if ((vfsp->vfs_flag & MNT_ROOTFS) != 0 &&
1578 (vfsp->vfs_flag & MNT_UPDATE) == 0) {
1579 char pname[MAXNAMELEN];
1581 error = getpoolname(osname, pname);
1583 error = spa_import_rootpool(pname, false);
1588 error = zfs_domount(vfsp, osname);
1596 zfs_statfs(vfs_t *vfsp, struct statfs *statp)
1598 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1599 uint64_t refdbytes, availbytes, usedobjs, availobjs;
1601 statp->f_version = STATFS_VERSION;
1605 dmu_objset_space(zfsvfs->z_os,
1606 &refdbytes, &availbytes, &usedobjs, &availobjs);
1609 * The underlying storage pool actually uses multiple block sizes.
1610 * We report the fragsize as the smallest block size we support,
1611 * and we report our blocksize as the filesystem's maximum blocksize.
1613 statp->f_bsize = SPA_MINBLOCKSIZE;
1614 statp->f_iosize = zfsvfs->z_vfs->mnt_stat.f_iosize;
1617 * The following report "total" blocks of various kinds in the
1618 * file system, but reported in terms of f_frsize - the
1622 statp->f_blocks = (refdbytes + availbytes) >> SPA_MINBLOCKSHIFT;
1623 statp->f_bfree = availbytes / statp->f_bsize;
1624 statp->f_bavail = statp->f_bfree; /* no root reservation */
1627 * statvfs() should really be called statufs(), because it assumes
1628 * static metadata. ZFS doesn't preallocate files, so the best
1629 * we can do is report the max that could possibly fit in f_files,
1630 * and that minus the number actually used in f_ffree.
1631 * For f_ffree, report the smaller of the number of object available
1632 * and the number of blocks (each object will take at least a block).
1634 statp->f_ffree = MIN(availobjs, statp->f_bfree);
1635 statp->f_files = statp->f_ffree + usedobjs;
1638 * We're a zfs filesystem.
1640 strlcpy(statp->f_fstypename, "zfs",
1641 sizeof (statp->f_fstypename));
1643 strlcpy(statp->f_mntfromname, vfsp->mnt_stat.f_mntfromname,
1644 sizeof (statp->f_mntfromname));
1645 strlcpy(statp->f_mntonname, vfsp->mnt_stat.f_mntonname,
1646 sizeof (statp->f_mntonname));
1648 statp->f_namemax = MAXNAMELEN - 1;
1655 zfs_root(vfs_t *vfsp, int flags, vnode_t **vpp)
1657 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1663 error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp);
1665 *vpp = ZTOV(rootzp);
1670 error = vn_lock(*vpp, flags);
1680 * Teardown the zfsvfs::z_os.
1682 * Note, if 'unmounting' is FALSE, we return with the 'z_teardown_lock'
1683 * and 'z_teardown_inactive_lock' held.
1686 zfsvfs_teardown(zfsvfs_t *zfsvfs, boolean_t unmounting)
1692 * If someone has not already unmounted this file system,
1693 * drain the zrele_taskq to ensure all active references to the
1694 * zfsvfs_t have been handled only then can it be safely destroyed.
1698 * If we're unmounting we have to wait for the list to
1701 * If we're not unmounting there's no guarantee the list
1702 * will drain completely, but zreles run from the taskq
1703 * may add the parents of dir-based xattrs to the taskq
1704 * so we want to wait for these.
1706 * We can safely read z_nr_znodes without locking because the
1707 * VFS has already blocked operations which add to the
1708 * z_all_znodes list and thus increment z_nr_znodes.
1711 while (zfsvfs->z_nr_znodes > 0) {
1712 taskq_wait_outstanding(dsl_pool_zrele_taskq(
1713 dmu_objset_pool(zfsvfs->z_os)), 0);
1714 if (++round > 1 && !unmounting)
1718 rrm_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG);
1722 * We purge the parent filesystem's vfsp as the parent
1723 * filesystem and all of its snapshots have their vnode's
1724 * v_vfsp set to the parent's filesystem's vfsp. Note,
1725 * 'z_parent' is self referential for non-snapshots.
1727 #ifdef FREEBSD_NAMECACHE
1728 cache_purgevfs(zfsvfs->z_parent->z_vfs, true);
1733 * Close the zil. NB: Can't close the zil while zfs_inactive
1734 * threads are blocked as zil_close can call zfs_inactive.
1736 if (zfsvfs->z_log) {
1737 zil_close(zfsvfs->z_log);
1738 zfsvfs->z_log = NULL;
1741 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_WRITER);
1744 * If we are not unmounting (ie: online recv) and someone already
1745 * unmounted this file system while we were doing the switcheroo,
1746 * or a reopen of z_os failed then just bail out now.
1748 if (!unmounting && (zfsvfs->z_unmounted || zfsvfs->z_os == NULL)) {
1749 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1750 rrm_exit(&zfsvfs->z_teardown_lock, FTAG);
1751 return (SET_ERROR(EIO));
1755 * At this point there are no vops active, and any new vops will
1756 * fail with EIO since we have z_teardown_lock for writer (only
1757 * relevant for forced unmount).
1759 * Release all holds on dbufs.
1761 mutex_enter(&zfsvfs->z_znodes_lock);
1762 for (zp = list_head(&zfsvfs->z_all_znodes); zp != NULL;
1763 zp = list_next(&zfsvfs->z_all_znodes, zp))
1765 ASSERT(ZTOV(zp)->v_count >= 0);
1766 zfs_znode_dmu_fini(zp);
1768 mutex_exit(&zfsvfs->z_znodes_lock);
1771 * If we are unmounting, set the unmounted flag and let new vops
1772 * unblock. zfs_inactive will have the unmounted behavior, and all
1773 * other vops will fail with EIO.
1776 zfsvfs->z_unmounted = B_TRUE;
1777 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1778 rrm_exit(&zfsvfs->z_teardown_lock, FTAG);
1782 * z_os will be NULL if there was an error in attempting to reopen
1783 * zfsvfs, so just return as the properties had already been
1784 * unregistered and cached data had been evicted before.
1786 if (zfsvfs->z_os == NULL)
1790 * Unregister properties.
1792 zfs_unregister_callbacks(zfsvfs);
1797 if (!zfs_is_readonly(zfsvfs))
1798 txg_wait_synced(dmu_objset_pool(zfsvfs->z_os), 0);
1799 dmu_objset_evict_dbufs(zfsvfs->z_os);
1800 dd = zfsvfs->z_os->os_dsl_dataset->ds_dir;
1801 dsl_dir_cancel_waiters(dd);
1808 zfs_umount(vfs_t *vfsp, int fflag)
1810 kthread_t *td = curthread;
1811 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1813 cred_t *cr = td->td_ucred;
1816 ret = secpolicy_fs_unmount(cr, vfsp);
1818 if (dsl_deleg_access((char *)vfsp->vfs_resource,
1819 ZFS_DELEG_PERM_MOUNT, cr))
1824 * Unmount any snapshots mounted under .zfs before unmounting the
1827 if (zfsvfs->z_ctldir != NULL) {
1828 if ((ret = zfsctl_umount_snapshots(vfsp, fflag, cr)) != 0)
1832 if (fflag & MS_FORCE) {
1834 * Mark file system as unmounted before calling
1835 * vflush(FORCECLOSE). This way we ensure no future vnops
1836 * will be called and risk operating on DOOMED vnodes.
1838 rrm_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG);
1839 zfsvfs->z_unmounted = B_TRUE;
1840 rrm_exit(&zfsvfs->z_teardown_lock, FTAG);
1844 * Flush all the files.
1846 ret = vflush(vfsp, 0, (fflag & MS_FORCE) ? FORCECLOSE : 0, td);
1849 while (taskqueue_cancel(zfsvfs_taskq->tq_queue,
1850 &zfsvfs->z_unlinked_drain_task, NULL) != 0)
1851 taskqueue_drain(zfsvfs_taskq->tq_queue,
1852 &zfsvfs->z_unlinked_drain_task);
1854 VERIFY(zfsvfs_teardown(zfsvfs, B_TRUE) == 0);
1858 * z_os will be NULL if there was an error in
1859 * attempting to reopen zfsvfs.
1863 * Unset the objset user_ptr.
1865 mutex_enter(&os->os_user_ptr_lock);
1866 dmu_objset_set_user(os, NULL);
1867 mutex_exit(&os->os_user_ptr_lock);
1870 * Finally release the objset
1872 dmu_objset_disown(os, B_TRUE, zfsvfs);
1876 * We can now safely destroy the '.zfs' directory node.
1878 if (zfsvfs->z_ctldir != NULL)
1879 zfsctl_destroy(zfsvfs);
1886 zfs_vget(vfs_t *vfsp, ino_t ino, int flags, vnode_t **vpp)
1888 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1893 * zfs_zget() can't operate on virtual entries like .zfs/ or
1894 * .zfs/snapshot/ directories, that's why we return EOPNOTSUPP.
1895 * This will make NFS to switch to LOOKUP instead of using VGET.
1897 if (ino == ZFSCTL_INO_ROOT || ino == ZFSCTL_INO_SNAPDIR ||
1898 (zfsvfs->z_shares_dir != 0 && ino == zfsvfs->z_shares_dir))
1899 return (EOPNOTSUPP);
1902 err = zfs_zget(zfsvfs, ino, &zp);
1903 if (err == 0 && zp->z_unlinked) {
1911 err = vn_lock(*vpp, flags);
1921 #if __FreeBSD_version >= 1300098
1922 zfs_checkexp(vfs_t *vfsp, struct sockaddr *nam, uint64_t *extflagsp,
1923 struct ucred **credanonp, int *numsecflavors, int *secflavors)
1925 zfs_checkexp(vfs_t *vfsp, struct sockaddr *nam, int *extflagsp,
1926 struct ucred **credanonp, int *numsecflavors, int **secflavors)
1929 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1932 * If this is regular file system vfsp is the same as
1933 * zfsvfs->z_parent->z_vfs, but if it is snapshot,
1934 * zfsvfs->z_parent->z_vfs represents parent file system
1935 * which we have to use here, because only this file system
1936 * has mnt_export configured.
1938 return (vfs_stdcheckexp(zfsvfs->z_parent->z_vfs, nam, extflagsp,
1939 credanonp, numsecflavors, secflavors));
1942 CTASSERT(SHORT_FID_LEN <= sizeof (struct fid));
1943 CTASSERT(LONG_FID_LEN <= sizeof (struct fid));
1946 zfs_fhtovp(vfs_t *vfsp, fid_t *fidp, int flags, vnode_t **vpp)
1948 struct componentname cn;
1949 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1952 uint64_t object = 0;
1953 uint64_t fid_gen = 0;
1963 * On FreeBSD we can get snapshot's mount point or its parent file
1964 * system mount point depending if snapshot is already mounted or not.
1966 if (zfsvfs->z_parent == zfsvfs && fidp->fid_len == LONG_FID_LEN) {
1967 zfid_long_t *zlfid = (zfid_long_t *)fidp;
1968 uint64_t objsetid = 0;
1969 uint64_t setgen = 0;
1971 for (i = 0; i < sizeof (zlfid->zf_setid); i++)
1972 objsetid |= ((uint64_t)zlfid->zf_setid[i]) << (8 * i);
1974 for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
1975 setgen |= ((uint64_t)zlfid->zf_setgen[i]) << (8 * i);
1979 err = zfsctl_lookup_objset(vfsp, objsetid, &zfsvfs);
1981 return (SET_ERROR(EINVAL));
1985 if (fidp->fid_len == SHORT_FID_LEN || fidp->fid_len == LONG_FID_LEN) {
1986 zfid_short_t *zfid = (zfid_short_t *)fidp;
1988 for (i = 0; i < sizeof (zfid->zf_object); i++)
1989 object |= ((uint64_t)zfid->zf_object[i]) << (8 * i);
1991 for (i = 0; i < sizeof (zfid->zf_gen); i++)
1992 fid_gen |= ((uint64_t)zfid->zf_gen[i]) << (8 * i);
1995 return (SET_ERROR(EINVAL));
1999 * A zero fid_gen means we are in .zfs or the .zfs/snapshot
2000 * directory tree. If the object == zfsvfs->z_shares_dir, then
2001 * we are in the .zfs/shares directory tree.
2003 if ((fid_gen == 0 &&
2004 (object == ZFSCTL_INO_ROOT || object == ZFSCTL_INO_SNAPDIR)) ||
2005 (zfsvfs->z_shares_dir != 0 && object == zfsvfs->z_shares_dir)) {
2007 VERIFY0(zfsctl_root(zfsvfs, LK_SHARED, &dvp));
2008 if (object == ZFSCTL_INO_SNAPDIR) {
2009 cn.cn_nameptr = "snapshot";
2010 cn.cn_namelen = strlen(cn.cn_nameptr);
2011 cn.cn_nameiop = LOOKUP;
2012 cn.cn_flags = ISLASTCN | LOCKLEAF;
2013 cn.cn_lkflags = flags;
2014 VERIFY0(VOP_LOOKUP(dvp, vpp, &cn));
2016 } else if (object == zfsvfs->z_shares_dir) {
2018 * XXX This branch must not be taken,
2019 * if it is, then the lookup below will
2022 cn.cn_nameptr = "shares";
2023 cn.cn_namelen = strlen(cn.cn_nameptr);
2024 cn.cn_nameiop = LOOKUP;
2025 cn.cn_flags = ISLASTCN;
2026 cn.cn_lkflags = flags;
2027 VERIFY0(VOP_LOOKUP(dvp, vpp, &cn));
2035 gen_mask = -1ULL >> (64 - 8 * i);
2037 dprintf("getting %llu [%u mask %llx]\n", object, fid_gen, gen_mask);
2038 if ((err = zfs_zget(zfsvfs, object, &zp))) {
2042 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zfsvfs), &zp_gen,
2044 zp_gen = zp_gen & gen_mask;
2047 if (zp->z_unlinked || zp_gen != fid_gen) {
2048 dprintf("znode gen (%u) != fid gen (%u)\n", zp_gen, fid_gen);
2051 return (SET_ERROR(EINVAL));
2056 err = vn_lock(*vpp, flags);
2058 vnode_create_vobject(*vpp, zp->z_size, curthread);
2065 * Block out VOPs and close zfsvfs_t::z_os
2067 * Note, if successful, then we return with the 'z_teardown_lock' and
2068 * 'z_teardown_inactive_lock' write held. We leave ownership of the underlying
2069 * dataset and objset intact so that they can be atomically handed off during
2070 * a subsequent rollback or recv operation and the resume thereafter.
2073 zfs_suspend_fs(zfsvfs_t *zfsvfs)
2077 if ((error = zfsvfs_teardown(zfsvfs, B_FALSE)) != 0)
2084 * Rebuild SA and release VOPs. Note that ownership of the underlying dataset
2085 * is an invariant across any of the operations that can be performed while the
2086 * filesystem was suspended. Whether it succeeded or failed, the preconditions
2087 * are the same: the relevant objset and associated dataset are owned by
2088 * zfsvfs, held, and long held on entry.
2091 zfs_resume_fs(zfsvfs_t *zfsvfs, dsl_dataset_t *ds)
2096 ASSERT(RRM_WRITE_HELD(&zfsvfs->z_teardown_lock));
2097 ASSERT(RW_WRITE_HELD(&zfsvfs->z_teardown_inactive_lock));
2100 * We already own this, so just update the objset_t, as the one we
2101 * had before may have been evicted.
2104 VERIFY3P(ds->ds_owner, ==, zfsvfs);
2105 VERIFY(dsl_dataset_long_held(ds));
2106 dsl_pool_t *dp = spa_get_dsl(dsl_dataset_get_spa(ds));
2107 dsl_pool_config_enter(dp, FTAG);
2108 VERIFY0(dmu_objset_from_ds(ds, &os));
2109 dsl_pool_config_exit(dp, FTAG);
2111 err = zfsvfs_init(zfsvfs, os);
2115 ds->ds_dir->dd_activity_cancelled = B_FALSE;
2116 VERIFY(zfsvfs_setup(zfsvfs, B_FALSE) == 0);
2118 zfs_set_fuid_feature(zfsvfs);
2121 * Attempt to re-establish all the active znodes with
2122 * their dbufs. If a zfs_rezget() fails, then we'll let
2123 * any potential callers discover that via ZFS_ENTER_VERIFY_VP
2124 * when they try to use their znode.
2126 mutex_enter(&zfsvfs->z_znodes_lock);
2127 for (zp = list_head(&zfsvfs->z_all_znodes); zp;
2128 zp = list_next(&zfsvfs->z_all_znodes, zp)) {
2129 (void) zfs_rezget(zp);
2131 mutex_exit(&zfsvfs->z_znodes_lock);
2134 /* release the VOPs */
2135 rw_exit(&zfsvfs->z_teardown_inactive_lock);
2136 rrm_exit(&zfsvfs->z_teardown_lock, FTAG);
2140 * Since we couldn't setup the sa framework, try to force
2141 * unmount this file system.
2143 if (vn_vfswlock(zfsvfs->z_vfs->vfs_vnodecovered) == 0) {
2144 vfs_ref(zfsvfs->z_vfs);
2145 (void) dounmount(zfsvfs->z_vfs, MS_FORCE, curthread);
2152 zfs_freevfs(vfs_t *vfsp)
2154 zfsvfs_t *zfsvfs = vfsp->vfs_data;
2156 zfsvfs_free(zfsvfs);
2158 atomic_dec_32(&zfs_active_fs_count);
2162 static int desiredvnodes_backup;
2163 #include <sys/vmmeter.h>
2166 #include <vm/vm_page.h>
2167 #include <vm/vm_object.h>
2168 #include <vm/vm_kern.h>
2169 #include <vm/vm_map.h>
2173 zfs_vnodes_adjust(void)
2176 int newdesiredvnodes;
2178 desiredvnodes_backup = desiredvnodes;
2181 * We calculate newdesiredvnodes the same way it is done in
2182 * vntblinit(). If it is equal to desiredvnodes, it means that
2183 * it wasn't tuned by the administrator and we can tune it down.
2185 newdesiredvnodes = min(maxproc + vm_cnt.v_page_count / 4, 2 *
2186 vm_kmem_size / (5 * (sizeof (struct vm_object) +
2187 sizeof (struct vnode))));
2188 if (newdesiredvnodes == desiredvnodes)
2189 desiredvnodes = (3 * newdesiredvnodes) / 4;
2194 zfs_vnodes_adjust_back(void)
2198 desiredvnodes = desiredvnodes_backup;
2206 printf("ZFS filesystem version: " ZPL_VERSION_STRING "\n");
2209 * Initialize .zfs directory structures
2214 * Initialize znode cache, vnode ops, etc...
2219 * Reduce number of vnodes. Originally number of vnodes is calculated
2220 * with UFS inode in mind. We reduce it here, because it's too big for
2223 zfs_vnodes_adjust();
2225 dmu_objset_register_type(DMU_OST_ZFS, zpl_get_file_info);
2227 zfsvfs_taskq = taskq_create("zfsvfs", 1, minclsyspri, 0, 0, 0);
2233 taskq_destroy(zfsvfs_taskq);
2236 zfs_vnodes_adjust_back();
2242 return (zfs_active_fs_count != 0);
2246 * Release VOPs and unmount a suspended filesystem.
2249 zfs_end_fs(zfsvfs_t *zfsvfs, dsl_dataset_t *ds)
2251 ASSERT(RRM_WRITE_HELD(&zfsvfs->z_teardown_lock));
2252 ASSERT(RW_WRITE_HELD(&zfsvfs->z_teardown_inactive_lock));
2255 * We already own this, so just hold and rele it to update the
2256 * objset_t, as the one we had before may have been evicted.
2259 VERIFY3P(ds->ds_owner, ==, zfsvfs);
2260 VERIFY(dsl_dataset_long_held(ds));
2261 dsl_pool_t *dp = spa_get_dsl(dsl_dataset_get_spa(ds));
2262 dsl_pool_config_enter(dp, FTAG);
2263 VERIFY0(dmu_objset_from_ds(ds, &os));
2264 dsl_pool_config_exit(dp, FTAG);
2267 /* release the VOPs */
2268 rw_exit(&zfsvfs->z_teardown_inactive_lock);
2269 rrm_exit(&zfsvfs->z_teardown_lock, FTAG);
2272 * Try to force unmount this file system.
2274 (void) zfs_umount(zfsvfs->z_vfs, 0);
2275 zfsvfs->z_unmounted = B_TRUE;
2280 zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers)
2283 objset_t *os = zfsvfs->z_os;
2286 if (newvers < ZPL_VERSION_INITIAL || newvers > ZPL_VERSION)
2287 return (SET_ERROR(EINVAL));
2289 if (newvers < zfsvfs->z_version)
2290 return (SET_ERROR(EINVAL));
2292 if (zfs_spa_version_map(newvers) >
2293 spa_version(dmu_objset_spa(zfsvfs->z_os)))
2294 return (SET_ERROR(ENOTSUP));
2296 tx = dmu_tx_create(os);
2297 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_FALSE, ZPL_VERSION_STR);
2298 if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
2299 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE,
2301 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
2303 error = dmu_tx_assign(tx, TXG_WAIT);
2309 error = zap_update(os, MASTER_NODE_OBJ, ZPL_VERSION_STR,
2310 8, 1, &newvers, tx);
2317 if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
2320 ASSERT3U(spa_version(dmu_objset_spa(zfsvfs->z_os)), >=,
2322 sa_obj = zap_create(os, DMU_OT_SA_MASTER_NODE,
2323 DMU_OT_NONE, 0, tx);
2325 error = zap_add(os, MASTER_NODE_OBJ,
2326 ZFS_SA_ATTRS, 8, 1, &sa_obj, tx);
2329 VERIFY(0 == sa_set_sa_object(os, sa_obj));
2330 sa_register_update_callback(os, zfs_sa_upgrade);
2333 spa_history_log_internal_ds(dmu_objset_ds(os), "upgrade", tx,
2334 "from %ju to %ju", (uintmax_t)zfsvfs->z_version,
2335 (uintmax_t)newvers);
2338 zfsvfs->z_version = newvers;
2339 os->os_version = newvers;
2341 zfs_set_fuid_feature(zfsvfs);
2347 * Read a property stored within the master node.
2350 zfs_get_zplprop(objset_t *os, zfs_prop_t prop, uint64_t *value)
2352 uint64_t *cached_copy = NULL;
2355 * Figure out where in the objset_t the cached copy would live, if it
2356 * is available for the requested property.
2360 case ZFS_PROP_VERSION:
2361 cached_copy = &os->os_version;
2363 case ZFS_PROP_NORMALIZE:
2364 cached_copy = &os->os_normalization;
2366 case ZFS_PROP_UTF8ONLY:
2367 cached_copy = &os->os_utf8only;
2370 cached_copy = &os->os_casesensitivity;
2376 if (cached_copy != NULL && *cached_copy != OBJSET_PROP_UNINITIALIZED) {
2377 *value = *cached_copy;
2382 * If the property wasn't cached, look up the file system's value for
2383 * the property. For the version property, we look up a slightly
2388 if (prop == ZFS_PROP_VERSION) {
2389 pname = ZPL_VERSION_STR;
2391 pname = zfs_prop_to_name(prop);
2395 ASSERT3U(os->os_phys->os_type, ==, DMU_OST_ZFS);
2396 error = zap_lookup(os, MASTER_NODE_OBJ, pname, 8, 1, value);
2399 if (error == ENOENT) {
2400 /* No value set, use the default value */
2402 case ZFS_PROP_VERSION:
2403 *value = ZPL_VERSION;
2405 case ZFS_PROP_NORMALIZE:
2406 case ZFS_PROP_UTF8ONLY:
2410 *value = ZFS_CASE_SENSITIVE;
2419 * If one of the methods for getting the property value above worked,
2420 * copy it into the objset_t's cache.
2422 if (error == 0 && cached_copy != NULL) {
2423 *cached_copy = *value;
2430 * Return true if the corresponding vfs's unmounted flag is set.
2431 * Otherwise return false.
2432 * If this function returns true we know VFS unmount has been initiated.
2435 zfs_get_vfs_flag_unmounted(objset_t *os)
2438 boolean_t unmounted = B_FALSE;
2440 ASSERT(dmu_objset_type(os) == DMU_OST_ZFS);
2442 mutex_enter(&os->os_user_ptr_lock);
2443 zfvp = dmu_objset_get_user(os);
2444 if (zfvp != NULL && zfvp->z_vfs != NULL &&
2445 (zfvp->z_vfs->mnt_kern_flag & MNTK_UNMOUNT))
2447 mutex_exit(&os->os_user_ptr_lock);
2454 zfsvfs_update_fromname(const char *oldname, const char *newname)
2456 char tmpbuf[MAXPATHLEN];
2461 oldlen = strlen(oldname);
2463 mtx_lock(&mountlist_mtx);
2464 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
2465 fromname = mp->mnt_stat.f_mntfromname;
2466 if (strcmp(fromname, oldname) == 0) {
2467 (void) strlcpy(fromname, newname,
2468 sizeof (mp->mnt_stat.f_mntfromname));
2471 if (strncmp(fromname, oldname, oldlen) == 0 &&
2472 (fromname[oldlen] == '/' || fromname[oldlen] == '@')) {
2473 (void) snprintf(tmpbuf, sizeof (tmpbuf), "%s%s",
2474 newname, fromname + oldlen);
2475 (void) strlcpy(fromname, tmpbuf,
2476 sizeof (mp->mnt_stat.f_mntfromname));
2480 mtx_unlock(&mountlist_mtx);