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_vnops.h>
46 #include <sys/zfs_dir.h>
48 #include <sys/fs/zfs.h>
50 #include <sys/dsl_prop.h>
51 #include <sys/dsl_dataset.h>
52 #include <sys/dsl_deleg.h>
56 #include <sys/sa_impl.h>
57 #include <sys/policy.h>
58 #include <sys/atomic.h>
59 #include <sys/zfs_ioctl.h>
60 #include <sys/zfs_ctldir.h>
61 #include <sys/zfs_fuid.h>
62 #include <sys/sunddi.h>
63 #include <sys/dmu_objset.h>
64 #include <sys/dsl_dir.h>
65 #include <sys/spa_boot.h>
67 #include <ufs/ufs/quota.h>
68 #include <sys/zfs_quota.h>
70 #include "zfs_comutil.h"
72 #ifndef MNTK_VMSETSIZE_BUG
73 #define MNTK_VMSETSIZE_BUG 0
76 #define MNTK_NOMSYNC 8
80 struct mtx zfs_debug_mtx;
81 MTX_SYSINIT(zfs_debug_mtx, &zfs_debug_mtx, "zfs_debug", MTX_DEF);
83 SYSCTL_NODE(_vfs, OID_AUTO, zfs, CTLFLAG_RW, 0, "ZFS file system");
86 SYSCTL_INT(_vfs_zfs, OID_AUTO, super_owner, CTLFLAG_RW, &zfs_super_owner, 0,
87 "File system owner can perform privileged operation on his file systems");
90 SYSCTL_INT(_vfs_zfs, OID_AUTO, debug, CTLFLAG_RWTUN, &zfs_debug_level, 0,
93 SYSCTL_NODE(_vfs_zfs, OID_AUTO, version, CTLFLAG_RD, 0, "ZFS versions");
94 static int zfs_version_acl = ZFS_ACL_VERSION;
95 SYSCTL_INT(_vfs_zfs_version, OID_AUTO, acl, CTLFLAG_RD, &zfs_version_acl, 0,
97 static int zfs_version_spa = SPA_VERSION;
98 SYSCTL_INT(_vfs_zfs_version, OID_AUTO, spa, CTLFLAG_RD, &zfs_version_spa, 0,
100 static int zfs_version_zpl = ZPL_VERSION;
101 SYSCTL_INT(_vfs_zfs_version, OID_AUTO, zpl, CTLFLAG_RD, &zfs_version_zpl, 0,
105 #if __FreeBSD_version >= 1400018
106 static int zfs_quotactl(vfs_t *vfsp, int cmds, uid_t id, void *arg,
109 static int zfs_quotactl(vfs_t *vfsp, int cmds, uid_t id, void *arg);
111 static int zfs_mount(vfs_t *vfsp);
112 static int zfs_umount(vfs_t *vfsp, int fflag);
113 static int zfs_root(vfs_t *vfsp, int flags, vnode_t **vpp);
114 static int zfs_statfs(vfs_t *vfsp, struct statfs *statp);
115 static int zfs_vget(vfs_t *vfsp, ino_t ino, int flags, vnode_t **vpp);
116 static int zfs_sync(vfs_t *vfsp, int waitfor);
117 #if __FreeBSD_version >= 1300098
118 static int zfs_checkexp(vfs_t *vfsp, struct sockaddr *nam, uint64_t *extflagsp,
119 struct ucred **credanonp, int *numsecflavors, int *secflavors);
121 static int zfs_checkexp(vfs_t *vfsp, struct sockaddr *nam, int *extflagsp,
122 struct ucred **credanonp, int *numsecflavors, int **secflavors);
124 static int zfs_fhtovp(vfs_t *vfsp, fid_t *fidp, int flags, vnode_t **vpp);
125 static void zfs_freevfs(vfs_t *vfsp);
127 struct vfsops zfs_vfsops = {
128 .vfs_mount = zfs_mount,
129 .vfs_unmount = zfs_umount,
130 #if __FreeBSD_version >= 1300049
131 .vfs_root = vfs_cache_root,
132 .vfs_cachedroot = zfs_root,
134 .vfs_root = zfs_root,
136 .vfs_statfs = zfs_statfs,
137 .vfs_vget = zfs_vget,
138 .vfs_sync = zfs_sync,
139 .vfs_checkexp = zfs_checkexp,
140 .vfs_fhtovp = zfs_fhtovp,
141 .vfs_quotactl = zfs_quotactl,
144 VFS_SET(zfs_vfsops, zfs, VFCF_JAIL | VFCF_DELEGADMIN);
147 * We need to keep a count of active fs's.
148 * This is necessary to prevent our module
149 * from being unloaded after a umount -f
151 static uint32_t zfs_active_fs_count = 0;
154 zfs_get_temporary_prop(dsl_dataset_t *ds, zfs_prop_t zfs_prop, uint64_t *val,
163 error = dmu_objset_from_ds(ds, &os);
167 error = getzfsvfs_impl(os, &zfvp);
175 if (vfs_optionisset(vfsp, MNTOPT_NOATIME, NULL))
177 if (vfs_optionisset(vfsp, MNTOPT_ATIME, NULL))
180 case ZFS_PROP_DEVICES:
181 if (vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL))
183 if (vfs_optionisset(vfsp, MNTOPT_DEVICES, NULL))
187 if (vfs_optionisset(vfsp, MNTOPT_NOEXEC, NULL))
189 if (vfs_optionisset(vfsp, MNTOPT_EXEC, NULL))
192 case ZFS_PROP_SETUID:
193 if (vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL))
195 if (vfs_optionisset(vfsp, MNTOPT_SETUID, NULL))
198 case ZFS_PROP_READONLY:
199 if (vfs_optionisset(vfsp, MNTOPT_RW, NULL))
201 if (vfs_optionisset(vfsp, MNTOPT_RO, NULL))
205 if (zfvp->z_flags & ZSB_XATTR)
208 case ZFS_PROP_NBMAND:
209 if (vfs_optionisset(vfsp, MNTOPT_NONBMAND, NULL))
211 if (vfs_optionisset(vfsp, MNTOPT_NBMAND, NULL))
221 (void) strcpy(setpoint, "temporary");
228 zfs_getquota(zfsvfs_t *zfsvfs, uid_t id, int isgroup, struct dqblk64 *dqp)
232 uint64_t usedobj, quotaobj;
233 uint64_t quota, used = 0;
236 usedobj = isgroup ? DMU_GROUPUSED_OBJECT : DMU_USERUSED_OBJECT;
237 quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj;
239 if (quotaobj == 0 || zfsvfs->z_replay) {
243 (void) sprintf(buf, "%llx", (longlong_t)id);
244 if ((error = zap_lookup(zfsvfs->z_os, quotaobj,
245 buf, sizeof (quota), 1, "a)) != 0) {
246 dprintf("%s(%d): quotaobj lookup failed\n",
247 __FUNCTION__, __LINE__);
251 * quota(8) uses bsoftlimit as "quoota", and hardlimit as "limit".
252 * So we set them to be the same.
254 dqp->dqb_bsoftlimit = dqp->dqb_bhardlimit = btodb(quota);
255 error = zap_lookup(zfsvfs->z_os, usedobj, buf, sizeof (used), 1, &used);
256 if (error && error != ENOENT) {
257 dprintf("%s(%d): usedobj failed; %d\n",
258 __FUNCTION__, __LINE__, error);
261 dqp->dqb_curblocks = btodb(used);
262 dqp->dqb_ihardlimit = dqp->dqb_isoftlimit = 0;
265 * Setting this to 0 causes FreeBSD quota(8) to print
266 * the number of days since the epoch, which isn't
267 * particularly useful.
269 dqp->dqb_btime = dqp->dqb_itime = now.tv_sec;
275 #if __FreeBSD_version >= 1400018
276 zfs_quotactl(vfs_t *vfsp, int cmds, uid_t id, void *arg, bool *mp_busy)
278 zfs_quotactl(vfs_t *vfsp, int cmds, uid_t id, void *arg)
281 zfsvfs_t *zfsvfs = vfsp->vfs_data;
283 int cmd, type, error = 0;
285 zfs_userquota_prop_t quota_type;
286 struct dqblk64 dqblk = { 0 };
289 cmd = cmds >> SUBCMDSHIFT;
290 type = cmds & SUBCMDMASK;
296 id = td->td_ucred->cr_ruid;
299 id = td->td_ucred->cr_rgid;
303 #if __FreeBSD_version < 1400018
304 if (cmd == Q_QUOTAON || cmd == Q_QUOTAOFF)
313 * ZFS_PROP_USERQUOTA,
314 * ZFS_PROP_GROUPUSED,
315 * ZFS_PROP_GROUPQUOTA
320 if (type == USRQUOTA)
321 quota_type = ZFS_PROP_USERQUOTA;
322 else if (type == GRPQUOTA)
323 quota_type = ZFS_PROP_GROUPQUOTA;
329 if (type == USRQUOTA)
330 quota_type = ZFS_PROP_USERUSED;
331 else if (type == GRPQUOTA)
332 quota_type = ZFS_PROP_GROUPUSED;
339 * Depending on the cmd, we may need to get
340 * the ruid and domain (see fuidstr_to_sid?),
341 * the fuid (how?), or other information.
342 * Create fuid using zfs_fuid_create(zfsvfs, id,
343 * ZFS_OWNER or ZFS_GROUP, cr, &fuidp)?
344 * I think I can use just the id?
346 * Look at zfs_id_overquota() to look up a quota.
347 * zap_lookup(something, quotaobj, fuidstring,
348 * sizeof (long long), 1, "a)
350 * See zfs_set_userquota() to set a quota.
352 if ((uint32_t)type >= MAXQUOTAS) {
360 error = copyout(&bitsize, arg, sizeof (int));
363 // As far as I can tell, you can't turn quotas on or off on zfs
365 #if __FreeBSD_version < 1400018
371 #if __FreeBSD_version < 1400018
376 error = copyin(arg, &dqblk, sizeof (dqblk));
378 error = zfs_set_userquota(zfsvfs, quota_type,
379 "", id, dbtob(dqblk.dqb_bhardlimit));
382 error = zfs_getquota(zfsvfs, id, type == GRPQUOTA, &dqblk);
384 error = copyout(&dqblk, arg, sizeof (dqblk));
397 zfs_is_readonly(zfsvfs_t *zfsvfs)
399 return (!!(zfsvfs->z_vfs->vfs_flag & VFS_RDONLY));
404 zfs_sync(vfs_t *vfsp, int waitfor)
408 * Data integrity is job one. We don't want a compromised kernel
409 * writing to the storage pool, so we never sync during panic.
415 * Ignore the system syncher. ZFS already commits async data
416 * at zfs_txg_timeout intervals.
418 if (waitfor == MNT_LAZY)
423 * Sync a specific filesystem.
425 zfsvfs_t *zfsvfs = vfsp->vfs_data;
429 error = vfs_stdsync(vfsp, waitfor);
434 dp = dmu_objset_pool(zfsvfs->z_os);
437 * If the system is shutting down, then skip any
438 * filesystems which may exist on a suspended pool.
440 if (rebooting && spa_suspended(dp->dp_spa)) {
445 if (zfsvfs->z_log != NULL)
446 zil_commit(zfsvfs->z_log, 0);
451 * Sync all ZFS filesystems. This is what happens when you
452 * run sync(8). Unlike other filesystems, ZFS honors the
453 * request by waiting for all pools to commit all dirty data.
462 atime_changed_cb(void *arg, uint64_t newval)
464 zfsvfs_t *zfsvfs = arg;
466 if (newval == TRUE) {
467 zfsvfs->z_atime = TRUE;
468 zfsvfs->z_vfs->vfs_flag &= ~MNT_NOATIME;
469 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME);
470 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_ATIME, NULL, 0);
472 zfsvfs->z_atime = FALSE;
473 zfsvfs->z_vfs->vfs_flag |= MNT_NOATIME;
474 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_ATIME);
475 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME, NULL, 0);
480 xattr_changed_cb(void *arg, uint64_t newval)
482 zfsvfs_t *zfsvfs = arg;
484 if (newval == ZFS_XATTR_OFF) {
485 zfsvfs->z_flags &= ~ZSB_XATTR;
487 zfsvfs->z_flags |= ZSB_XATTR;
489 if (newval == ZFS_XATTR_SA)
490 zfsvfs->z_xattr_sa = B_TRUE;
492 zfsvfs->z_xattr_sa = B_FALSE;
497 blksz_changed_cb(void *arg, uint64_t newval)
499 zfsvfs_t *zfsvfs = arg;
500 ASSERT3U(newval, <=, spa_maxblocksize(dmu_objset_spa(zfsvfs->z_os)));
501 ASSERT3U(newval, >=, SPA_MINBLOCKSIZE);
502 ASSERT(ISP2(newval));
504 zfsvfs->z_max_blksz = newval;
505 zfsvfs->z_vfs->mnt_stat.f_iosize = newval;
509 readonly_changed_cb(void *arg, uint64_t newval)
511 zfsvfs_t *zfsvfs = arg;
514 /* XXX locking on vfs_flag? */
515 zfsvfs->z_vfs->vfs_flag |= VFS_RDONLY;
516 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RW);
517 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RO, NULL, 0);
519 /* XXX locking on vfs_flag? */
520 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
521 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RO);
522 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RW, NULL, 0);
527 setuid_changed_cb(void *arg, uint64_t newval)
529 zfsvfs_t *zfsvfs = arg;
531 if (newval == FALSE) {
532 zfsvfs->z_vfs->vfs_flag |= VFS_NOSETUID;
533 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_SETUID);
534 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID, NULL, 0);
536 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOSETUID;
537 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID);
538 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_SETUID, NULL, 0);
543 exec_changed_cb(void *arg, uint64_t newval)
545 zfsvfs_t *zfsvfs = arg;
547 if (newval == FALSE) {
548 zfsvfs->z_vfs->vfs_flag |= VFS_NOEXEC;
549 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_EXEC);
550 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC, NULL, 0);
552 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOEXEC;
553 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC);
554 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_EXEC, NULL, 0);
559 * The nbmand mount option can be changed at mount time.
560 * We can't allow it to be toggled on live file systems or incorrect
561 * behavior may be seen from cifs clients
563 * This property isn't registered via dsl_prop_register(), but this callback
564 * will be called when a file system is first mounted
567 nbmand_changed_cb(void *arg, uint64_t newval)
569 zfsvfs_t *zfsvfs = arg;
570 if (newval == FALSE) {
571 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND);
572 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND, NULL, 0);
574 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND);
575 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND, NULL, 0);
580 snapdir_changed_cb(void *arg, uint64_t newval)
582 zfsvfs_t *zfsvfs = arg;
584 zfsvfs->z_show_ctldir = newval;
588 vscan_changed_cb(void *arg, uint64_t newval)
590 zfsvfs_t *zfsvfs = arg;
592 zfsvfs->z_vscan = newval;
596 acl_mode_changed_cb(void *arg, uint64_t newval)
598 zfsvfs_t *zfsvfs = arg;
600 zfsvfs->z_acl_mode = newval;
604 acl_inherit_changed_cb(void *arg, uint64_t newval)
606 zfsvfs_t *zfsvfs = arg;
608 zfsvfs->z_acl_inherit = newval;
612 acl_type_changed_cb(void *arg, uint64_t newval)
614 zfsvfs_t *zfsvfs = arg;
616 zfsvfs->z_acl_type = newval;
620 zfs_register_callbacks(vfs_t *vfsp)
622 struct dsl_dataset *ds = NULL;
624 zfsvfs_t *zfsvfs = NULL;
626 boolean_t readonly = B_FALSE;
627 boolean_t do_readonly = B_FALSE;
628 boolean_t setuid = B_FALSE;
629 boolean_t do_setuid = B_FALSE;
630 boolean_t exec = B_FALSE;
631 boolean_t do_exec = B_FALSE;
632 boolean_t xattr = B_FALSE;
633 boolean_t atime = B_FALSE;
634 boolean_t do_atime = B_FALSE;
635 boolean_t do_xattr = B_FALSE;
638 ASSERT3P(vfsp, !=, NULL);
639 zfsvfs = vfsp->vfs_data;
640 ASSERT3P(zfsvfs, !=, NULL);
644 * This function can be called for a snapshot when we update snapshot's
645 * mount point, which isn't really supported.
647 if (dmu_objset_is_snapshot(os))
651 * The act of registering our callbacks will destroy any mount
652 * options we may have. In order to enable temporary overrides
653 * of mount options, we stash away the current values and
654 * restore them after we register the callbacks.
656 if (vfs_optionisset(vfsp, MNTOPT_RO, NULL) ||
657 !spa_writeable(dmu_objset_spa(os))) {
659 do_readonly = B_TRUE;
660 } else if (vfs_optionisset(vfsp, MNTOPT_RW, NULL)) {
662 do_readonly = B_TRUE;
664 if (vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL)) {
667 } else if (vfs_optionisset(vfsp, MNTOPT_SETUID, NULL)) {
671 if (vfs_optionisset(vfsp, MNTOPT_NOEXEC, NULL)) {
674 } else if (vfs_optionisset(vfsp, MNTOPT_EXEC, NULL)) {
678 if (vfs_optionisset(vfsp, MNTOPT_NOXATTR, NULL)) {
679 zfsvfs->z_xattr = xattr = ZFS_XATTR_OFF;
681 } else if (vfs_optionisset(vfsp, MNTOPT_XATTR, NULL)) {
682 zfsvfs->z_xattr = xattr = ZFS_XATTR_DIR;
684 } else if (vfs_optionisset(vfsp, MNTOPT_DIRXATTR, NULL)) {
685 zfsvfs->z_xattr = xattr = ZFS_XATTR_DIR;
687 } else if (vfs_optionisset(vfsp, MNTOPT_SAXATTR, NULL)) {
688 zfsvfs->z_xattr = xattr = ZFS_XATTR_SA;
691 if (vfs_optionisset(vfsp, MNTOPT_NOATIME, NULL)) {
694 } else if (vfs_optionisset(vfsp, MNTOPT_ATIME, NULL)) {
700 * We need to enter pool configuration here, so that we can use
701 * dsl_prop_get_int_ds() to handle the special nbmand property below.
702 * dsl_prop_get_integer() can not be used, because it has to acquire
703 * spa_namespace_lock and we can not do that because we already hold
704 * z_teardown_lock. The problem is that spa_write_cachefile() is called
705 * with spa_namespace_lock held and the function calls ZFS vnode
706 * operations to write the cache file and thus z_teardown_lock is
707 * acquired after spa_namespace_lock.
709 ds = dmu_objset_ds(os);
710 dsl_pool_config_enter(dmu_objset_pool(os), FTAG);
713 * nbmand is a special property. It can only be changed at
716 * This is weird, but it is documented to only be changeable
719 if (vfs_optionisset(vfsp, MNTOPT_NONBMAND, NULL)) {
721 } else if (vfs_optionisset(vfsp, MNTOPT_NBMAND, NULL)) {
723 } else if ((error = dsl_prop_get_int_ds(ds, "nbmand", &nbmand) != 0)) {
724 dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
729 * Register property callbacks.
731 * It would probably be fine to just check for i/o error from
732 * the first prop_register(), but I guess I like to go
735 error = dsl_prop_register(ds,
736 zfs_prop_to_name(ZFS_PROP_ATIME), atime_changed_cb, zfsvfs);
737 error = error ? error : dsl_prop_register(ds,
738 zfs_prop_to_name(ZFS_PROP_XATTR), xattr_changed_cb, zfsvfs);
739 error = error ? error : dsl_prop_register(ds,
740 zfs_prop_to_name(ZFS_PROP_RECORDSIZE), blksz_changed_cb, zfsvfs);
741 error = error ? error : dsl_prop_register(ds,
742 zfs_prop_to_name(ZFS_PROP_READONLY), readonly_changed_cb, zfsvfs);
743 error = error ? error : dsl_prop_register(ds,
744 zfs_prop_to_name(ZFS_PROP_SETUID), setuid_changed_cb, zfsvfs);
745 error = error ? error : dsl_prop_register(ds,
746 zfs_prop_to_name(ZFS_PROP_EXEC), exec_changed_cb, zfsvfs);
747 error = error ? error : dsl_prop_register(ds,
748 zfs_prop_to_name(ZFS_PROP_SNAPDIR), snapdir_changed_cb, zfsvfs);
749 error = error ? error : dsl_prop_register(ds,
750 zfs_prop_to_name(ZFS_PROP_ACLTYPE), acl_type_changed_cb, zfsvfs);
751 error = error ? error : dsl_prop_register(ds,
752 zfs_prop_to_name(ZFS_PROP_ACLMODE), acl_mode_changed_cb, zfsvfs);
753 error = error ? error : dsl_prop_register(ds,
754 zfs_prop_to_name(ZFS_PROP_ACLINHERIT), acl_inherit_changed_cb,
756 error = error ? error : dsl_prop_register(ds,
757 zfs_prop_to_name(ZFS_PROP_VSCAN), vscan_changed_cb, zfsvfs);
758 dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
763 * Invoke our callbacks to restore temporary mount options.
766 readonly_changed_cb(zfsvfs, readonly);
768 setuid_changed_cb(zfsvfs, setuid);
770 exec_changed_cb(zfsvfs, exec);
772 xattr_changed_cb(zfsvfs, xattr);
774 atime_changed_cb(zfsvfs, atime);
776 nbmand_changed_cb(zfsvfs, nbmand);
781 dsl_prop_unregister_all(ds, zfsvfs);
786 * Associate this zfsvfs with the given objset, which must be owned.
787 * This will cache a bunch of on-disk state from the objset in the
791 zfsvfs_init(zfsvfs_t *zfsvfs, objset_t *os)
796 zfsvfs->z_max_blksz = SPA_OLD_MAXBLOCKSIZE;
797 zfsvfs->z_show_ctldir = ZFS_SNAPDIR_VISIBLE;
800 error = zfs_get_zplprop(os, ZFS_PROP_VERSION, &zfsvfs->z_version);
803 if (zfsvfs->z_version >
804 zfs_zpl_version_map(spa_version(dmu_objset_spa(os)))) {
805 (void) printf("Can't mount a version %lld file system "
806 "on a version %lld pool\n. Pool must be upgraded to mount "
807 "this file system.", (u_longlong_t)zfsvfs->z_version,
808 (u_longlong_t)spa_version(dmu_objset_spa(os)));
809 return (SET_ERROR(ENOTSUP));
811 error = zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &val);
814 zfsvfs->z_norm = (int)val;
816 error = zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &val);
819 zfsvfs->z_utf8 = (val != 0);
821 error = zfs_get_zplprop(os, ZFS_PROP_CASE, &val);
824 zfsvfs->z_case = (uint_t)val;
826 error = zfs_get_zplprop(os, ZFS_PROP_ACLTYPE, &val);
829 zfsvfs->z_acl_type = (uint_t)val;
832 * Fold case on file systems that are always or sometimes case
835 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
836 zfsvfs->z_case == ZFS_CASE_MIXED)
837 zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER;
839 zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
840 zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
843 if (zfsvfs->z_use_sa) {
844 /* should either have both of these objects or none */
845 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SA_ATTRS, 8, 1,
850 error = zfs_get_zplprop(os, ZFS_PROP_XATTR, &val);
851 if (error == 0 && val == ZFS_XATTR_SA)
852 zfsvfs->z_xattr_sa = B_TRUE;
855 error = sa_setup(os, sa_obj, zfs_attr_table, ZPL_END,
856 &zfsvfs->z_attr_table);
860 if (zfsvfs->z_version >= ZPL_VERSION_SA)
861 sa_register_update_callback(os, zfs_sa_upgrade);
863 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1,
867 ASSERT3U(zfsvfs->z_root, !=, 0);
869 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_UNLINKED_SET, 8, 1,
870 &zfsvfs->z_unlinkedobj);
874 error = zap_lookup(os, MASTER_NODE_OBJ,
875 zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA],
876 8, 1, &zfsvfs->z_userquota_obj);
878 zfsvfs->z_userquota_obj = 0;
882 error = zap_lookup(os, MASTER_NODE_OBJ,
883 zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA],
884 8, 1, &zfsvfs->z_groupquota_obj);
886 zfsvfs->z_groupquota_obj = 0;
890 error = zap_lookup(os, MASTER_NODE_OBJ,
891 zfs_userquota_prop_prefixes[ZFS_PROP_PROJECTQUOTA],
892 8, 1, &zfsvfs->z_projectquota_obj);
894 zfsvfs->z_projectquota_obj = 0;
898 error = zap_lookup(os, MASTER_NODE_OBJ,
899 zfs_userquota_prop_prefixes[ZFS_PROP_USEROBJQUOTA],
900 8, 1, &zfsvfs->z_userobjquota_obj);
902 zfsvfs->z_userobjquota_obj = 0;
906 error = zap_lookup(os, MASTER_NODE_OBJ,
907 zfs_userquota_prop_prefixes[ZFS_PROP_GROUPOBJQUOTA],
908 8, 1, &zfsvfs->z_groupobjquota_obj);
910 zfsvfs->z_groupobjquota_obj = 0;
914 error = zap_lookup(os, MASTER_NODE_OBJ,
915 zfs_userquota_prop_prefixes[ZFS_PROP_PROJECTOBJQUOTA],
916 8, 1, &zfsvfs->z_projectobjquota_obj);
918 zfsvfs->z_projectobjquota_obj = 0;
922 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES, 8, 1,
923 &zfsvfs->z_fuid_obj);
925 zfsvfs->z_fuid_obj = 0;
929 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SHARES_DIR, 8, 1,
930 &zfsvfs->z_shares_dir);
932 zfsvfs->z_shares_dir = 0;
937 * Only use the name cache if we are looking for a
938 * name on a file system that does not require normalization
939 * or case folding. We can also look there if we happen to be
940 * on a non-normalizing, mixed sensitivity file system IF we
941 * are looking for the exact name (which is always the case on
944 zfsvfs->z_use_namecache = !zfsvfs->z_norm ||
945 ((zfsvfs->z_case == ZFS_CASE_MIXED) &&
946 !(zfsvfs->z_norm & ~U8_TEXTPREP_TOUPPER));
951 taskq_t *zfsvfs_taskq;
954 zfsvfs_task_unlinked_drain(void *context, int pending __unused)
957 zfs_unlinked_drain((zfsvfs_t *)context);
961 zfsvfs_create(const char *osname, boolean_t readonly, zfsvfs_t **zfvp)
966 boolean_t ro = (readonly || (strchr(osname, '@') != NULL));
969 * XXX: Fix struct statfs so this isn't necessary!
971 * The 'osname' is used as the filesystem's special node, which means
972 * it must fit in statfs.f_mntfromname, or else it can't be
973 * enumerated, so libzfs_mnttab_find() returns NULL, which causes
974 * 'zfs unmount' to think it's not mounted when it is.
976 if (strlen(osname) >= MNAMELEN)
977 return (SET_ERROR(ENAMETOOLONG));
979 zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP);
981 error = dmu_objset_own(osname, DMU_OST_ZFS, ro, B_TRUE, zfsvfs,
984 kmem_free(zfsvfs, sizeof (zfsvfs_t));
988 error = zfsvfs_create_impl(zfvp, zfsvfs, os);
995 zfsvfs_create_impl(zfsvfs_t **zfvp, zfsvfs_t *zfsvfs, objset_t *os)
999 zfsvfs->z_vfs = NULL;
1000 zfsvfs->z_parent = zfsvfs;
1002 mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
1003 mutex_init(&zfsvfs->z_lock, NULL, MUTEX_DEFAULT, NULL);
1004 list_create(&zfsvfs->z_all_znodes, sizeof (znode_t),
1005 offsetof(znode_t, z_link_node));
1006 TASK_INIT(&zfsvfs->z_unlinked_drain_task, 0,
1007 zfsvfs_task_unlinked_drain, zfsvfs);
1008 ZFS_TEARDOWN_INIT(zfsvfs);
1009 ZFS_TEARDOWN_INACTIVE_INIT(zfsvfs);
1010 rw_init(&zfsvfs->z_fuid_lock, NULL, RW_DEFAULT, NULL);
1011 for (int i = 0; i != ZFS_OBJ_MTX_SZ; i++)
1012 mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
1014 error = zfsvfs_init(zfsvfs, os);
1016 dmu_objset_disown(os, B_TRUE, zfsvfs);
1018 kmem_free(zfsvfs, sizeof (zfsvfs_t));
1027 zfsvfs_setup(zfsvfs_t *zfsvfs, boolean_t mounting)
1032 * Check for a bad on-disk format version now since we
1033 * lied about owning the dataset readonly before.
1035 if (!(zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) &&
1036 dmu_objset_incompatible_encryption_version(zfsvfs->z_os))
1037 return (SET_ERROR(EROFS));
1039 error = zfs_register_callbacks(zfsvfs->z_vfs);
1043 zfsvfs->z_log = zil_open(zfsvfs->z_os, zfs_get_data);
1046 * If we are not mounting (ie: online recv), then we don't
1047 * have to worry about replaying the log as we blocked all
1048 * operations out since we closed the ZIL.
1053 ASSERT3P(zfsvfs->z_kstat.dk_kstats, ==, NULL);
1054 dataset_kstats_create(&zfsvfs->z_kstat, zfsvfs->z_os);
1057 * During replay we remove the read only flag to
1058 * allow replays to succeed.
1060 readonly = zfsvfs->z_vfs->vfs_flag & VFS_RDONLY;
1061 if (readonly != 0) {
1062 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
1067 if (zap_get_stats(zfsvfs->z_os, zfsvfs->z_unlinkedobj,
1069 dataset_kstats_update_nunlinks_kstat(
1070 &zfsvfs->z_kstat, zs.zs_num_entries);
1071 dprintf_ds(zfsvfs->z_os->os_dsl_dataset,
1072 "num_entries in unlinked set: %llu",
1073 (u_longlong_t)zs.zs_num_entries);
1076 zfs_unlinked_drain(zfsvfs);
1077 dd = zfsvfs->z_os->os_dsl_dataset->ds_dir;
1078 dd->dd_activity_cancelled = B_FALSE;
1082 * Parse and replay the intent log.
1084 * Because of ziltest, this must be done after
1085 * zfs_unlinked_drain(). (Further note: ziltest
1086 * doesn't use readonly mounts, where
1087 * zfs_unlinked_drain() isn't called.) This is because
1088 * ziltest causes spa_sync() to think it's committed,
1089 * but actually it is not, so the intent log contains
1090 * many txg's worth of changes.
1092 * In particular, if object N is in the unlinked set in
1093 * the last txg to actually sync, then it could be
1094 * actually freed in a later txg and then reallocated
1095 * in a yet later txg. This would write a "create
1096 * object N" record to the intent log. Normally, this
1097 * would be fine because the spa_sync() would have
1098 * written out the fact that object N is free, before
1099 * we could write the "create object N" intent log
1102 * But when we are in ziltest mode, we advance the "open
1103 * txg" without actually spa_sync()-ing the changes to
1104 * disk. So we would see that object N is still
1105 * allocated and in the unlinked set, and there is an
1106 * intent log record saying to allocate it.
1108 if (spa_writeable(dmu_objset_spa(zfsvfs->z_os))) {
1109 if (zil_replay_disable) {
1110 zil_destroy(zfsvfs->z_log, B_FALSE);
1112 boolean_t use_nc = zfsvfs->z_use_namecache;
1113 zfsvfs->z_use_namecache = B_FALSE;
1114 zfsvfs->z_replay = B_TRUE;
1115 zil_replay(zfsvfs->z_os, zfsvfs,
1117 zfsvfs->z_replay = B_FALSE;
1118 zfsvfs->z_use_namecache = use_nc;
1122 /* restore readonly bit */
1124 zfsvfs->z_vfs->vfs_flag |= VFS_RDONLY;
1128 * Set the objset user_ptr to track its zfsvfs.
1130 mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
1131 dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
1132 mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
1138 zfsvfs_free(zfsvfs_t *zfsvfs)
1142 zfs_fuid_destroy(zfsvfs);
1144 mutex_destroy(&zfsvfs->z_znodes_lock);
1145 mutex_destroy(&zfsvfs->z_lock);
1146 ASSERT3U(zfsvfs->z_nr_znodes, ==, 0);
1147 list_destroy(&zfsvfs->z_all_znodes);
1148 ZFS_TEARDOWN_DESTROY(zfsvfs);
1149 ZFS_TEARDOWN_INACTIVE_DESTROY(zfsvfs);
1150 rw_destroy(&zfsvfs->z_fuid_lock);
1151 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
1152 mutex_destroy(&zfsvfs->z_hold_mtx[i]);
1153 dataset_kstats_destroy(&zfsvfs->z_kstat);
1154 kmem_free(zfsvfs, sizeof (zfsvfs_t));
1158 zfs_set_fuid_feature(zfsvfs_t *zfsvfs)
1160 zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
1161 if (zfsvfs->z_vfs) {
1162 if (zfsvfs->z_use_fuids) {
1163 vfs_set_feature(zfsvfs->z_vfs, VFSFT_XVATTR);
1164 vfs_set_feature(zfsvfs->z_vfs, VFSFT_SYSATTR_VIEWS);
1165 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACEMASKONACCESS);
1166 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACLONCREATE);
1167 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACCESS_FILTER);
1168 vfs_set_feature(zfsvfs->z_vfs, VFSFT_REPARSE);
1170 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_XVATTR);
1171 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_SYSATTR_VIEWS);
1172 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_ACEMASKONACCESS);
1173 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_ACLONCREATE);
1174 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_ACCESS_FILTER);
1175 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_REPARSE);
1178 zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
1182 zfs_domount(vfs_t *vfsp, char *osname)
1184 uint64_t recordsize, fsid_guid;
1188 ASSERT3P(vfsp, !=, NULL);
1189 ASSERT3P(osname, !=, NULL);
1191 error = zfsvfs_create(osname, vfsp->mnt_flag & MNT_RDONLY, &zfsvfs);
1194 zfsvfs->z_vfs = vfsp;
1196 if ((error = dsl_prop_get_integer(osname,
1197 "recordsize", &recordsize, NULL)))
1199 zfsvfs->z_vfs->vfs_bsize = SPA_MINBLOCKSIZE;
1200 zfsvfs->z_vfs->mnt_stat.f_iosize = recordsize;
1202 vfsp->vfs_data = zfsvfs;
1203 vfsp->mnt_flag |= MNT_LOCAL;
1204 vfsp->mnt_kern_flag |= MNTK_LOOKUP_SHARED;
1205 vfsp->mnt_kern_flag |= MNTK_SHARED_WRITES;
1206 vfsp->mnt_kern_flag |= MNTK_EXTENDED_SHARED;
1208 * This can cause a loss of coherence between ARC and page cache
1209 * on ZoF - unclear if the problem is in FreeBSD or ZoF
1211 vfsp->mnt_kern_flag |= MNTK_NO_IOPF; /* vn_io_fault can be used */
1212 vfsp->mnt_kern_flag |= MNTK_NOMSYNC;
1213 vfsp->mnt_kern_flag |= MNTK_VMSETSIZE_BUG;
1215 #if defined(_KERNEL) && !defined(KMEM_DEBUG)
1216 vfsp->mnt_kern_flag |= MNTK_FPLOOKUP;
1219 * The fsid is 64 bits, composed of an 8-bit fs type, which
1220 * separates our fsid from any other filesystem types, and a
1221 * 56-bit objset unique ID. The objset unique ID is unique to
1222 * all objsets open on this system, provided by unique_create().
1223 * The 8-bit fs type must be put in the low bits of fsid[1]
1224 * because that's where other Solaris filesystems put it.
1226 fsid_guid = dmu_objset_fsid_guid(zfsvfs->z_os);
1227 ASSERT3U((fsid_guid & ~((1ULL << 56) - 1)), ==, 0);
1228 vfsp->vfs_fsid.val[0] = fsid_guid;
1229 vfsp->vfs_fsid.val[1] = ((fsid_guid >> 32) << 8) |
1230 (vfsp->mnt_vfc->vfc_typenum & 0xFF);
1233 * Set features for file system.
1235 zfs_set_fuid_feature(zfsvfs);
1236 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE) {
1237 vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS);
1238 vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE);
1239 vfs_set_feature(vfsp, VFSFT_NOCASESENSITIVE);
1240 } else if (zfsvfs->z_case == ZFS_CASE_MIXED) {
1241 vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS);
1242 vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE);
1244 vfs_set_feature(vfsp, VFSFT_ZEROCOPY_SUPPORTED);
1246 if (dmu_objset_is_snapshot(zfsvfs->z_os)) {
1249 atime_changed_cb(zfsvfs, B_FALSE);
1250 readonly_changed_cb(zfsvfs, B_TRUE);
1251 if ((error = dsl_prop_get_integer(osname,
1252 "xattr", &pval, NULL)))
1254 xattr_changed_cb(zfsvfs, pval);
1255 if ((error = dsl_prop_get_integer(osname,
1256 "acltype", &pval, NULL)))
1258 acl_type_changed_cb(zfsvfs, pval);
1259 zfsvfs->z_issnap = B_TRUE;
1260 zfsvfs->z_os->os_sync = ZFS_SYNC_DISABLED;
1262 mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
1263 dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
1264 mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
1266 if ((error = zfsvfs_setup(zfsvfs, B_TRUE)))
1270 vfs_mountedfrom(vfsp, osname);
1272 if (!zfsvfs->z_issnap)
1273 zfsctl_create(zfsvfs);
1276 dmu_objset_disown(zfsvfs->z_os, B_TRUE, zfsvfs);
1277 zfsvfs_free(zfsvfs);
1279 atomic_inc_32(&zfs_active_fs_count);
1286 zfs_unregister_callbacks(zfsvfs_t *zfsvfs)
1288 objset_t *os = zfsvfs->z_os;
1290 if (!dmu_objset_is_snapshot(os))
1291 dsl_prop_unregister_all(dmu_objset_ds(os), zfsvfs);
1295 getpoolname(const char *osname, char *poolname)
1299 p = strchr(osname, '/');
1301 if (strlen(osname) >= MAXNAMELEN)
1302 return (ENAMETOOLONG);
1303 (void) strcpy(poolname, osname);
1305 if (p - osname >= MAXNAMELEN)
1306 return (ENAMETOOLONG);
1307 (void) strncpy(poolname, osname, p - osname);
1308 poolname[p - osname] = '\0';
1314 fetch_osname_options(char *name, bool *checkpointrewind)
1317 if (name[0] == '!') {
1318 *checkpointrewind = true;
1319 memmove(name, name + 1, strlen(name));
1321 *checkpointrewind = false;
1327 zfs_mount(vfs_t *vfsp)
1329 kthread_t *td = curthread;
1330 vnode_t *mvp = vfsp->mnt_vnodecovered;
1331 cred_t *cr = td->td_ucred;
1335 bool checkpointrewind;
1337 if (vfs_getopt(vfsp->mnt_optnew, "from", (void **)&osname, NULL))
1338 return (SET_ERROR(EINVAL));
1341 * If full-owner-access is enabled and delegated administration is
1342 * turned on, we must set nosuid.
1344 if (zfs_super_owner &&
1345 dsl_deleg_access(osname, ZFS_DELEG_PERM_MOUNT, cr) != ECANCELED) {
1346 secpolicy_fs_mount_clearopts(cr, vfsp);
1349 fetch_osname_options(osname, &checkpointrewind);
1352 * Check for mount privilege?
1354 * If we don't have privilege then see if
1355 * we have local permission to allow it
1357 error = secpolicy_fs_mount(cr, mvp, vfsp);
1359 if (dsl_deleg_access(osname, ZFS_DELEG_PERM_MOUNT, cr) != 0)
1362 if (!(vfsp->vfs_flag & MS_REMOUNT)) {
1366 * Make sure user is the owner of the mount point
1367 * or has sufficient privileges.
1370 vattr.va_mask = AT_UID;
1372 vn_lock(mvp, LK_SHARED | LK_RETRY);
1373 if (VOP_GETATTR(mvp, &vattr, cr)) {
1378 if (secpolicy_vnode_owner(mvp, cr, vattr.va_uid) != 0 &&
1379 VOP_ACCESS(mvp, VWRITE, cr, td) != 0) {
1386 secpolicy_fs_mount_clearopts(cr, vfsp);
1390 * Refuse to mount a filesystem if we are in a local zone and the
1391 * dataset is not visible.
1393 if (!INGLOBALZONE(curproc) &&
1394 (!zone_dataset_visible(osname, &canwrite) || !canwrite)) {
1395 error = SET_ERROR(EPERM);
1399 vfsp->vfs_flag |= MNT_NFS4ACLS;
1402 * When doing a remount, we simply refresh our temporary properties
1403 * according to those options set in the current VFS options.
1405 if (vfsp->vfs_flag & MS_REMOUNT) {
1406 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1409 * Refresh mount options with z_teardown_lock blocking I/O while
1410 * the filesystem is in an inconsistent state.
1411 * The lock also serializes this code with filesystem
1412 * manipulations between entry to zfs_suspend_fs() and return
1413 * from zfs_resume_fs().
1415 ZFS_TEARDOWN_ENTER_WRITE(zfsvfs, FTAG);
1416 zfs_unregister_callbacks(zfsvfs);
1417 error = zfs_register_callbacks(vfsp);
1418 ZFS_TEARDOWN_EXIT(zfsvfs, FTAG);
1422 /* Initial root mount: try hard to import the requested root pool. */
1423 if ((vfsp->vfs_flag & MNT_ROOTFS) != 0 &&
1424 (vfsp->vfs_flag & MNT_UPDATE) == 0) {
1425 char pname[MAXNAMELEN];
1427 error = getpoolname(osname, pname);
1429 error = spa_import_rootpool(pname, checkpointrewind);
1434 error = zfs_domount(vfsp, osname);
1442 zfs_statfs(vfs_t *vfsp, struct statfs *statp)
1444 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1445 uint64_t refdbytes, availbytes, usedobjs, availobjs;
1447 statp->f_version = STATFS_VERSION;
1451 dmu_objset_space(zfsvfs->z_os,
1452 &refdbytes, &availbytes, &usedobjs, &availobjs);
1455 * The underlying storage pool actually uses multiple block sizes.
1456 * We report the fragsize as the smallest block size we support,
1457 * and we report our blocksize as the filesystem's maximum blocksize.
1459 statp->f_bsize = SPA_MINBLOCKSIZE;
1460 statp->f_iosize = zfsvfs->z_vfs->mnt_stat.f_iosize;
1463 * The following report "total" blocks of various kinds in the
1464 * file system, but reported in terms of f_frsize - the
1468 statp->f_blocks = (refdbytes + availbytes) >> SPA_MINBLOCKSHIFT;
1469 statp->f_bfree = availbytes / statp->f_bsize;
1470 statp->f_bavail = statp->f_bfree; /* no root reservation */
1473 * statvfs() should really be called statufs(), because it assumes
1474 * static metadata. ZFS doesn't preallocate files, so the best
1475 * we can do is report the max that could possibly fit in f_files,
1476 * and that minus the number actually used in f_ffree.
1477 * For f_ffree, report the smaller of the number of object available
1478 * and the number of blocks (each object will take at least a block).
1480 statp->f_ffree = MIN(availobjs, statp->f_bfree);
1481 statp->f_files = statp->f_ffree + usedobjs;
1484 * We're a zfs filesystem.
1486 strlcpy(statp->f_fstypename, "zfs",
1487 sizeof (statp->f_fstypename));
1489 strlcpy(statp->f_mntfromname, vfsp->mnt_stat.f_mntfromname,
1490 sizeof (statp->f_mntfromname));
1491 strlcpy(statp->f_mntonname, vfsp->mnt_stat.f_mntonname,
1492 sizeof (statp->f_mntonname));
1494 statp->f_namemax = MAXNAMELEN - 1;
1501 zfs_root(vfs_t *vfsp, int flags, vnode_t **vpp)
1503 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1509 error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp);
1511 *vpp = ZTOV(rootzp);
1516 error = vn_lock(*vpp, flags);
1526 * Teardown the zfsvfs::z_os.
1528 * Note, if 'unmounting' is FALSE, we return with the 'z_teardown_lock'
1529 * and 'z_teardown_inactive_lock' held.
1532 zfsvfs_teardown(zfsvfs_t *zfsvfs, boolean_t unmounting)
1538 * If someone has not already unmounted this file system,
1539 * drain the zrele_taskq to ensure all active references to the
1540 * zfsvfs_t have been handled only then can it be safely destroyed.
1544 * If we're unmounting we have to wait for the list to
1547 * If we're not unmounting there's no guarantee the list
1548 * will drain completely, but zreles run from the taskq
1549 * may add the parents of dir-based xattrs to the taskq
1550 * so we want to wait for these.
1552 * We can safely read z_nr_znodes without locking because the
1553 * VFS has already blocked operations which add to the
1554 * z_all_znodes list and thus increment z_nr_znodes.
1557 while (zfsvfs->z_nr_znodes > 0) {
1558 taskq_wait_outstanding(dsl_pool_zrele_taskq(
1559 dmu_objset_pool(zfsvfs->z_os)), 0);
1560 if (++round > 1 && !unmounting)
1564 ZFS_TEARDOWN_ENTER_WRITE(zfsvfs, FTAG);
1568 * We purge the parent filesystem's vfsp as the parent
1569 * filesystem and all of its snapshots have their vnode's
1570 * v_vfsp set to the parent's filesystem's vfsp. Note,
1571 * 'z_parent' is self referential for non-snapshots.
1573 #ifdef FREEBSD_NAMECACHE
1574 #if __FreeBSD_version >= 1300117
1575 cache_purgevfs(zfsvfs->z_parent->z_vfs);
1577 cache_purgevfs(zfsvfs->z_parent->z_vfs, true);
1583 * Close the zil. NB: Can't close the zil while zfs_inactive
1584 * threads are blocked as zil_close can call zfs_inactive.
1586 if (zfsvfs->z_log) {
1587 zil_close(zfsvfs->z_log);
1588 zfsvfs->z_log = NULL;
1591 ZFS_TEARDOWN_INACTIVE_ENTER_WRITE(zfsvfs);
1594 * If we are not unmounting (ie: online recv) and someone already
1595 * unmounted this file system while we were doing the switcheroo,
1596 * or a reopen of z_os failed then just bail out now.
1598 if (!unmounting && (zfsvfs->z_unmounted || zfsvfs->z_os == NULL)) {
1599 ZFS_TEARDOWN_INACTIVE_EXIT_WRITE(zfsvfs);
1600 ZFS_TEARDOWN_EXIT(zfsvfs, FTAG);
1601 return (SET_ERROR(EIO));
1605 * At this point there are no vops active, and any new vops will
1606 * fail with EIO since we have z_teardown_lock for writer (only
1607 * relevant for forced unmount).
1609 * Release all holds on dbufs.
1611 mutex_enter(&zfsvfs->z_znodes_lock);
1612 for (zp = list_head(&zfsvfs->z_all_znodes); zp != NULL;
1613 zp = list_next(&zfsvfs->z_all_znodes, zp)) {
1614 if (zp->z_sa_hdl != NULL) {
1615 zfs_znode_dmu_fini(zp);
1618 mutex_exit(&zfsvfs->z_znodes_lock);
1621 * If we are unmounting, set the unmounted flag and let new vops
1622 * unblock. zfs_inactive will have the unmounted behavior, and all
1623 * other vops will fail with EIO.
1626 zfsvfs->z_unmounted = B_TRUE;
1627 ZFS_TEARDOWN_INACTIVE_EXIT_WRITE(zfsvfs);
1628 ZFS_TEARDOWN_EXIT(zfsvfs, FTAG);
1632 * z_os will be NULL if there was an error in attempting to reopen
1633 * zfsvfs, so just return as the properties had already been
1634 * unregistered and cached data had been evicted before.
1636 if (zfsvfs->z_os == NULL)
1640 * Unregister properties.
1642 zfs_unregister_callbacks(zfsvfs);
1647 if (!zfs_is_readonly(zfsvfs))
1648 txg_wait_synced(dmu_objset_pool(zfsvfs->z_os), 0);
1649 dmu_objset_evict_dbufs(zfsvfs->z_os);
1650 dd = zfsvfs->z_os->os_dsl_dataset->ds_dir;
1651 dsl_dir_cancel_waiters(dd);
1658 zfs_umount(vfs_t *vfsp, int fflag)
1660 kthread_t *td = curthread;
1661 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1663 cred_t *cr = td->td_ucred;
1666 ret = secpolicy_fs_unmount(cr, vfsp);
1668 if (dsl_deleg_access((char *)vfsp->vfs_resource,
1669 ZFS_DELEG_PERM_MOUNT, cr))
1674 * Unmount any snapshots mounted under .zfs before unmounting the
1677 if (zfsvfs->z_ctldir != NULL) {
1678 if ((ret = zfsctl_umount_snapshots(vfsp, fflag, cr)) != 0)
1682 if (fflag & MS_FORCE) {
1684 * Mark file system as unmounted before calling
1685 * vflush(FORCECLOSE). This way we ensure no future vnops
1686 * will be called and risk operating on DOOMED vnodes.
1688 ZFS_TEARDOWN_ENTER_WRITE(zfsvfs, FTAG);
1689 zfsvfs->z_unmounted = B_TRUE;
1690 ZFS_TEARDOWN_EXIT(zfsvfs, FTAG);
1694 * Flush all the files.
1696 ret = vflush(vfsp, 0, (fflag & MS_FORCE) ? FORCECLOSE : 0, td);
1699 while (taskqueue_cancel(zfsvfs_taskq->tq_queue,
1700 &zfsvfs->z_unlinked_drain_task, NULL) != 0)
1701 taskqueue_drain(zfsvfs_taskq->tq_queue,
1702 &zfsvfs->z_unlinked_drain_task);
1704 VERIFY0(zfsvfs_teardown(zfsvfs, B_TRUE));
1708 * z_os will be NULL if there was an error in
1709 * attempting to reopen zfsvfs.
1713 * Unset the objset user_ptr.
1715 mutex_enter(&os->os_user_ptr_lock);
1716 dmu_objset_set_user(os, NULL);
1717 mutex_exit(&os->os_user_ptr_lock);
1720 * Finally release the objset
1722 dmu_objset_disown(os, B_TRUE, zfsvfs);
1726 * We can now safely destroy the '.zfs' directory node.
1728 if (zfsvfs->z_ctldir != NULL)
1729 zfsctl_destroy(zfsvfs);
1736 zfs_vget(vfs_t *vfsp, ino_t ino, int flags, vnode_t **vpp)
1738 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1743 * zfs_zget() can't operate on virtual entries like .zfs/ or
1744 * .zfs/snapshot/ directories, that's why we return EOPNOTSUPP.
1745 * This will make NFS to switch to LOOKUP instead of using VGET.
1747 if (ino == ZFSCTL_INO_ROOT || ino == ZFSCTL_INO_SNAPDIR ||
1748 (zfsvfs->z_shares_dir != 0 && ino == zfsvfs->z_shares_dir))
1749 return (EOPNOTSUPP);
1752 err = zfs_zget(zfsvfs, ino, &zp);
1753 if (err == 0 && zp->z_unlinked) {
1761 err = vn_lock(*vpp, flags);
1771 #if __FreeBSD_version >= 1300098
1772 zfs_checkexp(vfs_t *vfsp, struct sockaddr *nam, uint64_t *extflagsp,
1773 struct ucred **credanonp, int *numsecflavors, int *secflavors)
1775 zfs_checkexp(vfs_t *vfsp, struct sockaddr *nam, int *extflagsp,
1776 struct ucred **credanonp, int *numsecflavors, int **secflavors)
1779 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1782 * If this is regular file system vfsp is the same as
1783 * zfsvfs->z_parent->z_vfs, but if it is snapshot,
1784 * zfsvfs->z_parent->z_vfs represents parent file system
1785 * which we have to use here, because only this file system
1786 * has mnt_export configured.
1788 return (vfs_stdcheckexp(zfsvfs->z_parent->z_vfs, nam, extflagsp,
1789 credanonp, numsecflavors, secflavors));
1792 CTASSERT(SHORT_FID_LEN <= sizeof (struct fid));
1793 CTASSERT(LONG_FID_LEN <= sizeof (struct fid));
1796 zfs_fhtovp(vfs_t *vfsp, fid_t *fidp, int flags, vnode_t **vpp)
1798 struct componentname cn;
1799 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1802 uint64_t object = 0;
1803 uint64_t fid_gen = 0;
1804 uint64_t setgen = 0;
1814 * On FreeBSD we can get snapshot's mount point or its parent file
1815 * system mount point depending if snapshot is already mounted or not.
1817 if (zfsvfs->z_parent == zfsvfs && fidp->fid_len == LONG_FID_LEN) {
1818 zfid_long_t *zlfid = (zfid_long_t *)fidp;
1819 uint64_t objsetid = 0;
1821 for (i = 0; i < sizeof (zlfid->zf_setid); i++)
1822 objsetid |= ((uint64_t)zlfid->zf_setid[i]) << (8 * i);
1824 for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
1825 setgen |= ((uint64_t)zlfid->zf_setgen[i]) << (8 * i);
1829 err = zfsctl_lookup_objset(vfsp, objsetid, &zfsvfs);
1831 return (SET_ERROR(EINVAL));
1835 if (fidp->fid_len == SHORT_FID_LEN || fidp->fid_len == LONG_FID_LEN) {
1836 zfid_short_t *zfid = (zfid_short_t *)fidp;
1838 for (i = 0; i < sizeof (zfid->zf_object); i++)
1839 object |= ((uint64_t)zfid->zf_object[i]) << (8 * i);
1841 for (i = 0; i < sizeof (zfid->zf_gen); i++)
1842 fid_gen |= ((uint64_t)zfid->zf_gen[i]) << (8 * i);
1845 return (SET_ERROR(EINVAL));
1848 if (fidp->fid_len == LONG_FID_LEN && setgen != 0) {
1850 dprintf("snapdir fid: fid_gen (%llu) and setgen (%llu)\n",
1851 (u_longlong_t)fid_gen, (u_longlong_t)setgen);
1852 return (SET_ERROR(EINVAL));
1856 * A zero fid_gen means we are in .zfs or the .zfs/snapshot
1857 * directory tree. If the object == zfsvfs->z_shares_dir, then
1858 * we are in the .zfs/shares directory tree.
1860 if ((fid_gen == 0 &&
1861 (object == ZFSCTL_INO_ROOT || object == ZFSCTL_INO_SNAPDIR)) ||
1862 (zfsvfs->z_shares_dir != 0 && object == zfsvfs->z_shares_dir)) {
1864 VERIFY0(zfsctl_root(zfsvfs, LK_SHARED, &dvp));
1865 if (object == ZFSCTL_INO_SNAPDIR) {
1866 cn.cn_nameptr = "snapshot";
1867 cn.cn_namelen = strlen(cn.cn_nameptr);
1868 cn.cn_nameiop = LOOKUP;
1869 cn.cn_flags = ISLASTCN | LOCKLEAF;
1870 cn.cn_lkflags = flags;
1871 VERIFY0(VOP_LOOKUP(dvp, vpp, &cn));
1873 } else if (object == zfsvfs->z_shares_dir) {
1875 * XXX This branch must not be taken,
1876 * if it is, then the lookup below will
1879 cn.cn_nameptr = "shares";
1880 cn.cn_namelen = strlen(cn.cn_nameptr);
1881 cn.cn_nameiop = LOOKUP;
1882 cn.cn_flags = ISLASTCN;
1883 cn.cn_lkflags = flags;
1884 VERIFY0(VOP_LOOKUP(dvp, vpp, &cn));
1892 gen_mask = -1ULL >> (64 - 8 * i);
1894 dprintf("getting %llu [%llu mask %llx]\n", (u_longlong_t)object,
1895 (u_longlong_t)fid_gen,
1896 (u_longlong_t)gen_mask);
1897 if ((err = zfs_zget(zfsvfs, object, &zp))) {
1901 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zfsvfs), &zp_gen,
1903 zp_gen = zp_gen & gen_mask;
1906 if (zp->z_unlinked || zp_gen != fid_gen) {
1907 dprintf("znode gen (%llu) != fid gen (%llu)\n",
1908 (u_longlong_t)zp_gen, (u_longlong_t)fid_gen);
1911 return (SET_ERROR(EINVAL));
1916 err = vn_lock(*vpp, flags);
1918 vnode_create_vobject(*vpp, zp->z_size, curthread);
1925 * Block out VOPs and close zfsvfs_t::z_os
1927 * Note, if successful, then we return with the 'z_teardown_lock' and
1928 * 'z_teardown_inactive_lock' write held. We leave ownership of the underlying
1929 * dataset and objset intact so that they can be atomically handed off during
1930 * a subsequent rollback or recv operation and the resume thereafter.
1933 zfs_suspend_fs(zfsvfs_t *zfsvfs)
1937 if ((error = zfsvfs_teardown(zfsvfs, B_FALSE)) != 0)
1944 * Rebuild SA and release VOPs. Note that ownership of the underlying dataset
1945 * is an invariant across any of the operations that can be performed while the
1946 * filesystem was suspended. Whether it succeeded or failed, the preconditions
1947 * are the same: the relevant objset and associated dataset are owned by
1948 * zfsvfs, held, and long held on entry.
1951 zfs_resume_fs(zfsvfs_t *zfsvfs, dsl_dataset_t *ds)
1956 ASSERT(ZFS_TEARDOWN_WRITE_HELD(zfsvfs));
1957 ASSERT(ZFS_TEARDOWN_INACTIVE_WRITE_HELD(zfsvfs));
1960 * We already own this, so just update the objset_t, as the one we
1961 * had before may have been evicted.
1964 VERIFY3P(ds->ds_owner, ==, zfsvfs);
1965 VERIFY(dsl_dataset_long_held(ds));
1966 dsl_pool_t *dp = spa_get_dsl(dsl_dataset_get_spa(ds));
1967 dsl_pool_config_enter(dp, FTAG);
1968 VERIFY0(dmu_objset_from_ds(ds, &os));
1969 dsl_pool_config_exit(dp, FTAG);
1971 err = zfsvfs_init(zfsvfs, os);
1975 ds->ds_dir->dd_activity_cancelled = B_FALSE;
1976 VERIFY0(zfsvfs_setup(zfsvfs, B_FALSE));
1978 zfs_set_fuid_feature(zfsvfs);
1981 * Attempt to re-establish all the active znodes with
1982 * their dbufs. If a zfs_rezget() fails, then we'll let
1983 * any potential callers discover that via ZFS_ENTER_VERIFY_VP
1984 * when they try to use their znode.
1986 mutex_enter(&zfsvfs->z_znodes_lock);
1987 for (zp = list_head(&zfsvfs->z_all_znodes); zp;
1988 zp = list_next(&zfsvfs->z_all_znodes, zp)) {
1989 (void) zfs_rezget(zp);
1991 mutex_exit(&zfsvfs->z_znodes_lock);
1994 /* release the VOPs */
1995 ZFS_TEARDOWN_INACTIVE_EXIT_WRITE(zfsvfs);
1996 ZFS_TEARDOWN_EXIT(zfsvfs, FTAG);
2000 * Since we couldn't setup the sa framework, try to force
2001 * unmount this file system.
2003 if (vn_vfswlock(zfsvfs->z_vfs->vfs_vnodecovered) == 0) {
2004 vfs_ref(zfsvfs->z_vfs);
2005 (void) dounmount(zfsvfs->z_vfs, MS_FORCE, curthread);
2012 zfs_freevfs(vfs_t *vfsp)
2014 zfsvfs_t *zfsvfs = vfsp->vfs_data;
2016 zfsvfs_free(zfsvfs);
2018 atomic_dec_32(&zfs_active_fs_count);
2022 static int desiredvnodes_backup;
2023 #include <sys/vmmeter.h>
2026 #include <vm/vm_page.h>
2027 #include <vm/vm_object.h>
2028 #include <vm/vm_kern.h>
2029 #include <vm/vm_map.h>
2033 zfs_vnodes_adjust(void)
2036 int newdesiredvnodes;
2038 desiredvnodes_backup = desiredvnodes;
2041 * We calculate newdesiredvnodes the same way it is done in
2042 * vntblinit(). If it is equal to desiredvnodes, it means that
2043 * it wasn't tuned by the administrator and we can tune it down.
2045 newdesiredvnodes = min(maxproc + vm_cnt.v_page_count / 4, 2 *
2046 vm_kmem_size / (5 * (sizeof (struct vm_object) +
2047 sizeof (struct vnode))));
2048 if (newdesiredvnodes == desiredvnodes)
2049 desiredvnodes = (3 * newdesiredvnodes) / 4;
2054 zfs_vnodes_adjust_back(void)
2058 desiredvnodes = desiredvnodes_backup;
2066 printf("ZFS filesystem version: " ZPL_VERSION_STRING "\n");
2069 * Initialize .zfs directory structures
2074 * Initialize znode cache, vnode ops, etc...
2079 * Reduce number of vnodes. Originally number of vnodes is calculated
2080 * with UFS inode in mind. We reduce it here, because it's too big for
2083 zfs_vnodes_adjust();
2085 dmu_objset_register_type(DMU_OST_ZFS, zpl_get_file_info);
2087 zfsvfs_taskq = taskq_create("zfsvfs", 1, minclsyspri, 0, 0, 0);
2093 taskq_destroy(zfsvfs_taskq);
2096 zfs_vnodes_adjust_back();
2102 return (zfs_active_fs_count != 0);
2106 * Release VOPs and unmount a suspended filesystem.
2109 zfs_end_fs(zfsvfs_t *zfsvfs, dsl_dataset_t *ds)
2111 ASSERT(ZFS_TEARDOWN_WRITE_HELD(zfsvfs));
2112 ASSERT(ZFS_TEARDOWN_INACTIVE_WRITE_HELD(zfsvfs));
2115 * We already own this, so just hold and rele it to update the
2116 * objset_t, as the one we had before may have been evicted.
2119 VERIFY3P(ds->ds_owner, ==, zfsvfs);
2120 VERIFY(dsl_dataset_long_held(ds));
2121 dsl_pool_t *dp = spa_get_dsl(dsl_dataset_get_spa(ds));
2122 dsl_pool_config_enter(dp, FTAG);
2123 VERIFY0(dmu_objset_from_ds(ds, &os));
2124 dsl_pool_config_exit(dp, FTAG);
2127 /* release the VOPs */
2128 ZFS_TEARDOWN_INACTIVE_EXIT_WRITE(zfsvfs);
2129 ZFS_TEARDOWN_EXIT(zfsvfs, FTAG);
2132 * Try to force unmount this file system.
2134 (void) zfs_umount(zfsvfs->z_vfs, 0);
2135 zfsvfs->z_unmounted = B_TRUE;
2140 zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers)
2143 objset_t *os = zfsvfs->z_os;
2146 if (newvers < ZPL_VERSION_INITIAL || newvers > ZPL_VERSION)
2147 return (SET_ERROR(EINVAL));
2149 if (newvers < zfsvfs->z_version)
2150 return (SET_ERROR(EINVAL));
2152 if (zfs_spa_version_map(newvers) >
2153 spa_version(dmu_objset_spa(zfsvfs->z_os)))
2154 return (SET_ERROR(ENOTSUP));
2156 tx = dmu_tx_create(os);
2157 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_FALSE, ZPL_VERSION_STR);
2158 if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
2159 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE,
2161 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
2163 error = dmu_tx_assign(tx, TXG_WAIT);
2169 error = zap_update(os, MASTER_NODE_OBJ, ZPL_VERSION_STR,
2170 8, 1, &newvers, tx);
2177 if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
2180 ASSERT3U(spa_version(dmu_objset_spa(zfsvfs->z_os)), >=,
2182 sa_obj = zap_create(os, DMU_OT_SA_MASTER_NODE,
2183 DMU_OT_NONE, 0, tx);
2185 error = zap_add(os, MASTER_NODE_OBJ,
2186 ZFS_SA_ATTRS, 8, 1, &sa_obj, tx);
2189 VERIFY0(sa_set_sa_object(os, sa_obj));
2190 sa_register_update_callback(os, zfs_sa_upgrade);
2193 spa_history_log_internal_ds(dmu_objset_ds(os), "upgrade", tx,
2194 "from %ju to %ju", (uintmax_t)zfsvfs->z_version,
2195 (uintmax_t)newvers);
2198 zfsvfs->z_version = newvers;
2199 os->os_version = newvers;
2201 zfs_set_fuid_feature(zfsvfs);
2207 * Read a property stored within the master node.
2210 zfs_get_zplprop(objset_t *os, zfs_prop_t prop, uint64_t *value)
2212 uint64_t *cached_copy = NULL;
2215 * Figure out where in the objset_t the cached copy would live, if it
2216 * is available for the requested property.
2220 case ZFS_PROP_VERSION:
2221 cached_copy = &os->os_version;
2223 case ZFS_PROP_NORMALIZE:
2224 cached_copy = &os->os_normalization;
2226 case ZFS_PROP_UTF8ONLY:
2227 cached_copy = &os->os_utf8only;
2230 cached_copy = &os->os_casesensitivity;
2236 if (cached_copy != NULL && *cached_copy != OBJSET_PROP_UNINITIALIZED) {
2237 *value = *cached_copy;
2242 * If the property wasn't cached, look up the file system's value for
2243 * the property. For the version property, we look up a slightly
2248 if (prop == ZFS_PROP_VERSION) {
2249 pname = ZPL_VERSION_STR;
2251 pname = zfs_prop_to_name(prop);
2255 ASSERT3U(os->os_phys->os_type, ==, DMU_OST_ZFS);
2256 error = zap_lookup(os, MASTER_NODE_OBJ, pname, 8, 1, value);
2259 if (error == ENOENT) {
2260 /* No value set, use the default value */
2262 case ZFS_PROP_VERSION:
2263 *value = ZPL_VERSION;
2265 case ZFS_PROP_NORMALIZE:
2266 case ZFS_PROP_UTF8ONLY:
2270 *value = ZFS_CASE_SENSITIVE;
2272 case ZFS_PROP_ACLTYPE:
2273 *value = ZFS_ACLTYPE_NFSV4;
2282 * If one of the methods for getting the property value above worked,
2283 * copy it into the objset_t's cache.
2285 if (error == 0 && cached_copy != NULL) {
2286 *cached_copy = *value;
2293 * Return true if the corresponding vfs's unmounted flag is set.
2294 * Otherwise return false.
2295 * If this function returns true we know VFS unmount has been initiated.
2298 zfs_get_vfs_flag_unmounted(objset_t *os)
2301 boolean_t unmounted = B_FALSE;
2303 ASSERT3U(dmu_objset_type(os), ==, DMU_OST_ZFS);
2305 mutex_enter(&os->os_user_ptr_lock);
2306 zfvp = dmu_objset_get_user(os);
2307 if (zfvp != NULL && zfvp->z_vfs != NULL &&
2308 (zfvp->z_vfs->mnt_kern_flag & MNTK_UNMOUNT))
2310 mutex_exit(&os->os_user_ptr_lock);
2317 zfsvfs_update_fromname(const char *oldname, const char *newname)
2319 char tmpbuf[MAXPATHLEN];
2324 oldlen = strlen(oldname);
2326 mtx_lock(&mountlist_mtx);
2327 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
2328 fromname = mp->mnt_stat.f_mntfromname;
2329 if (strcmp(fromname, oldname) == 0) {
2330 (void) strlcpy(fromname, newname,
2331 sizeof (mp->mnt_stat.f_mntfromname));
2334 if (strncmp(fromname, oldname, oldlen) == 0 &&
2335 (fromname[oldlen] == '/' || fromname[oldlen] == '@')) {
2336 (void) snprintf(tmpbuf, sizeof (tmpbuf), "%s%s",
2337 newname, fromname + oldlen);
2338 (void) strlcpy(fromname, tmpbuf,
2339 sizeof (mp->mnt_stat.f_mntfromname));
2343 mtx_unlock(&mountlist_mtx);