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.
27 /* Portions Copyright 2010 Robert Milkowski */
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/sysmacros.h>
36 #include <sys/vnode.h>
38 #include <sys/mntent.h>
39 #include <sys/mount.h>
40 #include <sys/cmn_err.h>
41 #include <sys/zfs_znode.h>
42 #include <sys/zfs_dir.h>
44 #include <sys/fs/zfs.h>
46 #include <sys/dsl_prop.h>
47 #include <sys/dsl_dataset.h>
48 #include <sys/dsl_deleg.h>
52 #include <sys/varargs.h>
53 #include <sys/policy.h>
54 #include <sys/atomic.h>
55 #include <sys/zfs_ioctl.h>
56 #include <sys/zfs_ctldir.h>
57 #include <sys/zfs_fuid.h>
58 #include <sys/sunddi.h>
60 #include <sys/dmu_objset.h>
61 #include <sys/spa_boot.h>
63 #include "zfs_comutil.h"
65 struct mtx zfs_debug_mtx;
66 MTX_SYSINIT(zfs_debug_mtx, &zfs_debug_mtx, "zfs_debug", MTX_DEF);
68 SYSCTL_NODE(_vfs, OID_AUTO, zfs, CTLFLAG_RW, 0, "ZFS file system");
71 SYSCTL_INT(_vfs_zfs, OID_AUTO, super_owner, CTLFLAG_RW, &zfs_super_owner, 0,
72 "File system owner can perform privileged operation on his file systems");
75 TUNABLE_INT("vfs.zfs.debug", &zfs_debug_level);
76 SYSCTL_INT(_vfs_zfs, OID_AUTO, debug, CTLFLAG_RW, &zfs_debug_level, 0,
79 SYSCTL_NODE(_vfs_zfs, OID_AUTO, version, CTLFLAG_RD, 0, "ZFS versions");
80 static int zfs_version_acl = ZFS_ACL_VERSION;
81 SYSCTL_INT(_vfs_zfs_version, OID_AUTO, acl, CTLFLAG_RD, &zfs_version_acl, 0,
83 static int zfs_version_spa = SPA_VERSION;
84 SYSCTL_INT(_vfs_zfs_version, OID_AUTO, spa, CTLFLAG_RD, &zfs_version_spa, 0,
86 static int zfs_version_zpl = ZPL_VERSION;
87 SYSCTL_INT(_vfs_zfs_version, OID_AUTO, zpl, CTLFLAG_RD, &zfs_version_zpl, 0,
90 static int zfs_mount(vfs_t *vfsp);
91 static int zfs_umount(vfs_t *vfsp, int fflag);
92 static int zfs_root(vfs_t *vfsp, int flags, vnode_t **vpp);
93 static int zfs_statfs(vfs_t *vfsp, struct statfs *statp);
94 static int zfs_vget(vfs_t *vfsp, ino_t ino, int flags, vnode_t **vpp);
95 static int zfs_sync(vfs_t *vfsp, int waitfor);
96 static int zfs_checkexp(vfs_t *vfsp, struct sockaddr *nam, int *extflagsp,
97 struct ucred **credanonp, int *numsecflavors, int **secflavors);
98 static int zfs_fhtovp(vfs_t *vfsp, fid_t *fidp, int flags, vnode_t **vpp);
99 static void zfs_objset_close(zfsvfs_t *zfsvfs);
100 static void zfs_freevfs(vfs_t *vfsp);
102 static struct vfsops zfs_vfsops = {
103 .vfs_mount = zfs_mount,
104 .vfs_unmount = zfs_umount,
105 .vfs_root = zfs_root,
106 .vfs_statfs = zfs_statfs,
107 .vfs_vget = zfs_vget,
108 .vfs_sync = zfs_sync,
109 .vfs_checkexp = zfs_checkexp,
110 .vfs_fhtovp = zfs_fhtovp,
113 VFS_SET(zfs_vfsops, zfs, VFCF_JAIL | VFCF_DELEGADMIN);
116 * We need to keep a count of active fs's.
117 * This is necessary to prevent our module
118 * from being unloaded after a umount -f
120 static uint32_t zfs_active_fs_count = 0;
124 zfs_sync(vfs_t *vfsp, int waitfor)
128 * Data integrity is job one. We don't want a compromised kernel
129 * writing to the storage pool, so we never sync during panic.
136 * Sync a specific filesystem.
138 zfsvfs_t *zfsvfs = vfsp->vfs_data;
142 error = vfs_stdsync(vfsp, waitfor);
147 dp = dmu_objset_pool(zfsvfs->z_os);
150 * If the system is shutting down, then skip any
151 * filesystems which may exist on a suspended pool.
153 if (sys_shutdown && spa_suspended(dp->dp_spa)) {
158 if (zfsvfs->z_log != NULL)
159 zil_commit(zfsvfs->z_log, 0);
164 * Sync all ZFS filesystems. This is what happens when you
165 * run sync(1M). Unlike other filesystems, ZFS honors the
166 * request by waiting for all pools to commit all dirty data.
176 zfs_create_unique_device(dev_t *dev)
181 ASSERT3U(zfs_minor, <=, MAXMIN32);
182 minor_t start = zfs_minor;
184 mutex_enter(&zfs_dev_mtx);
185 if (zfs_minor >= MAXMIN32) {
187 * If we're still using the real major
188 * keep out of /dev/zfs and /dev/zvol minor
189 * number space. If we're using a getudev()'ed
190 * major number, we can use all of its minors.
192 if (zfs_major == ddi_name_to_major(ZFS_DRIVER))
193 zfs_minor = ZFS_MIN_MINOR;
199 *dev = makedevice(zfs_major, zfs_minor);
200 mutex_exit(&zfs_dev_mtx);
201 } while (vfs_devismounted(*dev) && zfs_minor != start);
202 if (zfs_minor == start) {
204 * We are using all ~262,000 minor numbers for the
205 * current major number. Create a new major number.
207 if ((new_major = getudev()) == (major_t)-1) {
209 "zfs_mount: Can't get unique major "
213 mutex_enter(&zfs_dev_mtx);
214 zfs_major = new_major;
217 mutex_exit(&zfs_dev_mtx);
221 /* CONSTANTCONDITION */
226 #endif /* !__FreeBSD__ */
229 atime_changed_cb(void *arg, uint64_t newval)
231 zfsvfs_t *zfsvfs = arg;
233 if (newval == TRUE) {
234 zfsvfs->z_atime = TRUE;
235 zfsvfs->z_vfs->vfs_flag &= ~MNT_NOATIME;
236 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME);
237 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_ATIME, NULL, 0);
239 zfsvfs->z_atime = FALSE;
240 zfsvfs->z_vfs->vfs_flag |= MNT_NOATIME;
241 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_ATIME);
242 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME, NULL, 0);
247 xattr_changed_cb(void *arg, uint64_t newval)
249 zfsvfs_t *zfsvfs = arg;
251 if (newval == TRUE) {
252 /* XXX locking on vfs_flag? */
254 zfsvfs->z_vfs->vfs_flag |= VFS_XATTR;
256 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR);
257 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_XATTR, NULL, 0);
259 /* XXX locking on vfs_flag? */
261 zfsvfs->z_vfs->vfs_flag &= ~VFS_XATTR;
263 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_XATTR);
264 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR, NULL, 0);
269 blksz_changed_cb(void *arg, uint64_t newval)
271 zfsvfs_t *zfsvfs = arg;
273 if (newval < SPA_MINBLOCKSIZE ||
274 newval > SPA_MAXBLOCKSIZE || !ISP2(newval))
275 newval = SPA_MAXBLOCKSIZE;
277 zfsvfs->z_max_blksz = newval;
278 zfsvfs->z_vfs->mnt_stat.f_iosize = newval;
282 readonly_changed_cb(void *arg, uint64_t newval)
284 zfsvfs_t *zfsvfs = arg;
287 /* XXX locking on vfs_flag? */
288 zfsvfs->z_vfs->vfs_flag |= VFS_RDONLY;
289 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RW);
290 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RO, NULL, 0);
292 /* XXX locking on vfs_flag? */
293 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
294 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RO);
295 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RW, NULL, 0);
300 setuid_changed_cb(void *arg, uint64_t newval)
302 zfsvfs_t *zfsvfs = arg;
304 if (newval == FALSE) {
305 zfsvfs->z_vfs->vfs_flag |= VFS_NOSETUID;
306 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_SETUID);
307 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID, NULL, 0);
309 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOSETUID;
310 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID);
311 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_SETUID, NULL, 0);
316 exec_changed_cb(void *arg, uint64_t newval)
318 zfsvfs_t *zfsvfs = arg;
320 if (newval == FALSE) {
321 zfsvfs->z_vfs->vfs_flag |= VFS_NOEXEC;
322 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_EXEC);
323 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC, NULL, 0);
325 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOEXEC;
326 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC);
327 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_EXEC, NULL, 0);
332 * The nbmand mount option can be changed at mount time.
333 * We can't allow it to be toggled on live file systems or incorrect
334 * behavior may be seen from cifs clients
336 * This property isn't registered via dsl_prop_register(), but this callback
337 * will be called when a file system is first mounted
340 nbmand_changed_cb(void *arg, uint64_t newval)
342 zfsvfs_t *zfsvfs = arg;
343 if (newval == FALSE) {
344 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND);
345 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND, NULL, 0);
347 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND);
348 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND, NULL, 0);
353 snapdir_changed_cb(void *arg, uint64_t newval)
355 zfsvfs_t *zfsvfs = arg;
357 zfsvfs->z_show_ctldir = newval;
361 vscan_changed_cb(void *arg, uint64_t newval)
363 zfsvfs_t *zfsvfs = arg;
365 zfsvfs->z_vscan = newval;
369 acl_mode_changed_cb(void *arg, uint64_t newval)
371 zfsvfs_t *zfsvfs = arg;
373 zfsvfs->z_acl_mode = newval;
377 acl_inherit_changed_cb(void *arg, uint64_t newval)
379 zfsvfs_t *zfsvfs = arg;
381 zfsvfs->z_acl_inherit = newval;
385 zfs_register_callbacks(vfs_t *vfsp)
387 struct dsl_dataset *ds = NULL;
389 zfsvfs_t *zfsvfs = NULL;
391 int readonly, do_readonly = B_FALSE;
392 int setuid, do_setuid = B_FALSE;
393 int exec, do_exec = B_FALSE;
394 int xattr, do_xattr = B_FALSE;
395 int atime, do_atime = B_FALSE;
399 zfsvfs = vfsp->vfs_data;
404 * This function can be called for a snapshot when we update snapshot's
405 * mount point, which isn't really supported.
407 if (dmu_objset_is_snapshot(os))
411 * The act of registering our callbacks will destroy any mount
412 * options we may have. In order to enable temporary overrides
413 * of mount options, we stash away the current values and
414 * restore them after we register the callbacks.
416 if (vfs_optionisset(vfsp, MNTOPT_RO, NULL) ||
417 !spa_writeable(dmu_objset_spa(os))) {
419 do_readonly = B_TRUE;
420 } else if (vfs_optionisset(vfsp, MNTOPT_RW, NULL)) {
422 do_readonly = B_TRUE;
424 if (vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL)) {
428 if (vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL)) {
431 } else if (vfs_optionisset(vfsp, MNTOPT_SETUID, NULL)) {
436 if (vfs_optionisset(vfsp, MNTOPT_NOEXEC, NULL)) {
439 } else if (vfs_optionisset(vfsp, MNTOPT_EXEC, NULL)) {
443 if (vfs_optionisset(vfsp, MNTOPT_NOXATTR, NULL)) {
446 } else if (vfs_optionisset(vfsp, MNTOPT_XATTR, NULL)) {
450 if (vfs_optionisset(vfsp, MNTOPT_NOATIME, NULL)) {
453 } else if (vfs_optionisset(vfsp, MNTOPT_ATIME, NULL)) {
459 * nbmand is a special property. It can only be changed at
462 * This is weird, but it is documented to only be changeable
465 if (vfs_optionisset(vfsp, MNTOPT_NONBMAND, NULL)) {
467 } else if (vfs_optionisset(vfsp, MNTOPT_NBMAND, NULL)) {
470 char osname[MAXNAMELEN];
472 dmu_objset_name(os, osname);
473 if (error = dsl_prop_get_integer(osname, "nbmand", &nbmand,
480 * Register property callbacks.
482 * It would probably be fine to just check for i/o error from
483 * the first prop_register(), but I guess I like to go
486 ds = dmu_objset_ds(os);
487 error = dsl_prop_register(ds, "atime", atime_changed_cb, zfsvfs);
488 error = error ? error : dsl_prop_register(ds,
489 "xattr", xattr_changed_cb, zfsvfs);
490 error = error ? error : dsl_prop_register(ds,
491 "recordsize", blksz_changed_cb, zfsvfs);
492 error = error ? error : dsl_prop_register(ds,
493 "readonly", readonly_changed_cb, zfsvfs);
494 error = error ? error : dsl_prop_register(ds,
495 "setuid", setuid_changed_cb, zfsvfs);
496 error = error ? error : dsl_prop_register(ds,
497 "exec", exec_changed_cb, zfsvfs);
498 error = error ? error : dsl_prop_register(ds,
499 "snapdir", snapdir_changed_cb, zfsvfs);
500 error = error ? error : dsl_prop_register(ds,
501 "aclmode", acl_mode_changed_cb, zfsvfs);
502 error = error ? error : dsl_prop_register(ds,
503 "aclinherit", acl_inherit_changed_cb, zfsvfs);
504 error = error ? error : dsl_prop_register(ds,
505 "vscan", vscan_changed_cb, zfsvfs);
510 * Invoke our callbacks to restore temporary mount options.
513 readonly_changed_cb(zfsvfs, readonly);
515 setuid_changed_cb(zfsvfs, setuid);
517 exec_changed_cb(zfsvfs, exec);
519 xattr_changed_cb(zfsvfs, xattr);
521 atime_changed_cb(zfsvfs, atime);
523 nbmand_changed_cb(zfsvfs, nbmand);
529 * We may attempt to unregister some callbacks that are not
530 * registered, but this is OK; it will simply return ENOMSG,
531 * which we will ignore.
533 (void) dsl_prop_unregister(ds, "atime", atime_changed_cb, zfsvfs);
534 (void) dsl_prop_unregister(ds, "xattr", xattr_changed_cb, zfsvfs);
535 (void) dsl_prop_unregister(ds, "recordsize", blksz_changed_cb, zfsvfs);
536 (void) dsl_prop_unregister(ds, "readonly", readonly_changed_cb, zfsvfs);
537 (void) dsl_prop_unregister(ds, "setuid", setuid_changed_cb, zfsvfs);
538 (void) dsl_prop_unregister(ds, "exec", exec_changed_cb, zfsvfs);
539 (void) dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb, zfsvfs);
540 (void) dsl_prop_unregister(ds, "aclmode", acl_mode_changed_cb, zfsvfs);
541 (void) dsl_prop_unregister(ds, "aclinherit", acl_inherit_changed_cb,
543 (void) dsl_prop_unregister(ds, "vscan", vscan_changed_cb, zfsvfs);
549 zfs_space_delta_cb(dmu_object_type_t bonustype, void *data,
550 uint64_t *userp, uint64_t *groupp)
552 znode_phys_t *znp = data;
556 * Is it a valid type of object to track?
558 if (bonustype != DMU_OT_ZNODE && bonustype != DMU_OT_SA)
562 * If we have a NULL data pointer
563 * then assume the id's aren't changing and
564 * return EEXIST to the dmu to let it know to
570 if (bonustype == DMU_OT_ZNODE) {
571 *userp = znp->zp_uid;
572 *groupp = znp->zp_gid;
576 ASSERT(bonustype == DMU_OT_SA);
577 hdrsize = sa_hdrsize(data);
580 *userp = *((uint64_t *)((uintptr_t)data + hdrsize +
582 *groupp = *((uint64_t *)((uintptr_t)data + hdrsize +
586 * This should only happen for newly created
587 * files that haven't had the znode data filled
598 fuidstr_to_sid(zfsvfs_t *zfsvfs, const char *fuidstr,
599 char *domainbuf, int buflen, uid_t *ridp)
604 fuid = strtonum(fuidstr, NULL);
606 domain = zfs_fuid_find_by_idx(zfsvfs, FUID_INDEX(fuid));
608 (void) strlcpy(domainbuf, domain, buflen);
611 *ridp = FUID_RID(fuid);
615 zfs_userquota_prop_to_obj(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type)
618 case ZFS_PROP_USERUSED:
619 return (DMU_USERUSED_OBJECT);
620 case ZFS_PROP_GROUPUSED:
621 return (DMU_GROUPUSED_OBJECT);
622 case ZFS_PROP_USERQUOTA:
623 return (zfsvfs->z_userquota_obj);
624 case ZFS_PROP_GROUPQUOTA:
625 return (zfsvfs->z_groupquota_obj);
631 zfs_userspace_many(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
632 uint64_t *cookiep, void *vbuf, uint64_t *bufsizep)
637 zfs_useracct_t *buf = vbuf;
640 if (!dmu_objset_userspace_present(zfsvfs->z_os))
643 obj = zfs_userquota_prop_to_obj(zfsvfs, type);
649 for (zap_cursor_init_serialized(&zc, zfsvfs->z_os, obj, *cookiep);
650 (error = zap_cursor_retrieve(&zc, &za)) == 0;
651 zap_cursor_advance(&zc)) {
652 if ((uintptr_t)buf - (uintptr_t)vbuf + sizeof (zfs_useracct_t) >
656 fuidstr_to_sid(zfsvfs, za.za_name,
657 buf->zu_domain, sizeof (buf->zu_domain), &buf->zu_rid);
659 buf->zu_space = za.za_first_integer;
665 ASSERT3U((uintptr_t)buf - (uintptr_t)vbuf, <=, *bufsizep);
666 *bufsizep = (uintptr_t)buf - (uintptr_t)vbuf;
667 *cookiep = zap_cursor_serialize(&zc);
668 zap_cursor_fini(&zc);
673 * buf must be big enough (eg, 32 bytes)
676 id_to_fuidstr(zfsvfs_t *zfsvfs, const char *domain, uid_t rid,
677 char *buf, boolean_t addok)
682 if (domain && domain[0]) {
683 domainid = zfs_fuid_find_by_domain(zfsvfs, domain, NULL, addok);
687 fuid = FUID_ENCODE(domainid, rid);
688 (void) sprintf(buf, "%llx", (longlong_t)fuid);
693 zfs_userspace_one(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
694 const char *domain, uint64_t rid, uint64_t *valp)
702 if (!dmu_objset_userspace_present(zfsvfs->z_os))
705 obj = zfs_userquota_prop_to_obj(zfsvfs, type);
709 err = id_to_fuidstr(zfsvfs, domain, rid, buf, B_FALSE);
713 err = zap_lookup(zfsvfs->z_os, obj, buf, 8, 1, valp);
720 zfs_set_userquota(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
721 const char *domain, uint64_t rid, uint64_t quota)
727 boolean_t fuid_dirtied;
729 if (type != ZFS_PROP_USERQUOTA && type != ZFS_PROP_GROUPQUOTA)
732 if (zfsvfs->z_version < ZPL_VERSION_USERSPACE)
735 objp = (type == ZFS_PROP_USERQUOTA) ? &zfsvfs->z_userquota_obj :
736 &zfsvfs->z_groupquota_obj;
738 err = id_to_fuidstr(zfsvfs, domain, rid, buf, B_TRUE);
741 fuid_dirtied = zfsvfs->z_fuid_dirty;
743 tx = dmu_tx_create(zfsvfs->z_os);
744 dmu_tx_hold_zap(tx, *objp ? *objp : DMU_NEW_OBJECT, B_TRUE, NULL);
746 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE,
747 zfs_userquota_prop_prefixes[type]);
750 zfs_fuid_txhold(zfsvfs, tx);
751 err = dmu_tx_assign(tx, TXG_WAIT);
757 mutex_enter(&zfsvfs->z_lock);
759 *objp = zap_create(zfsvfs->z_os, DMU_OT_USERGROUP_QUOTA,
761 VERIFY(0 == zap_add(zfsvfs->z_os, MASTER_NODE_OBJ,
762 zfs_userquota_prop_prefixes[type], 8, 1, objp, tx));
764 mutex_exit(&zfsvfs->z_lock);
767 err = zap_remove(zfsvfs->z_os, *objp, buf, tx);
771 err = zap_update(zfsvfs->z_os, *objp, buf, 8, 1, "a, tx);
775 zfs_fuid_sync(zfsvfs, tx);
781 zfs_fuid_overquota(zfsvfs_t *zfsvfs, boolean_t isgroup, uint64_t fuid)
784 uint64_t used, quota, usedobj, quotaobj;
787 usedobj = isgroup ? DMU_GROUPUSED_OBJECT : DMU_USERUSED_OBJECT;
788 quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj;
790 if (quotaobj == 0 || zfsvfs->z_replay)
793 (void) sprintf(buf, "%llx", (longlong_t)fuid);
794 err = zap_lookup(zfsvfs->z_os, quotaobj, buf, 8, 1, "a);
798 err = zap_lookup(zfsvfs->z_os, usedobj, buf, 8, 1, &used);
801 return (used >= quota);
805 zfs_owner_overquota(zfsvfs_t *zfsvfs, znode_t *zp, boolean_t isgroup)
810 quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj;
812 fuid = isgroup ? zp->z_gid : zp->z_uid;
814 if (quotaobj == 0 || zfsvfs->z_replay)
817 return (zfs_fuid_overquota(zfsvfs, isgroup, fuid));
821 zfsvfs_create(const char *osname, zfsvfs_t **zfvp)
829 zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP);
832 * We claim to always be readonly so we can open snapshots;
833 * other ZPL code will prevent us from writing to snapshots.
835 error = dmu_objset_own(osname, DMU_OST_ZFS, B_TRUE, zfsvfs, &os);
837 kmem_free(zfsvfs, sizeof (zfsvfs_t));
842 * Initialize the zfs-specific filesystem structure.
843 * Should probably make this a kmem cache, shuffle fields,
844 * and just bzero up to z_hold_mtx[].
846 zfsvfs->z_vfs = NULL;
847 zfsvfs->z_parent = zfsvfs;
848 zfsvfs->z_max_blksz = SPA_MAXBLOCKSIZE;
849 zfsvfs->z_show_ctldir = ZFS_SNAPDIR_VISIBLE;
852 error = zfs_get_zplprop(os, ZFS_PROP_VERSION, &zfsvfs->z_version);
855 } else if (zfsvfs->z_version >
856 zfs_zpl_version_map(spa_version(dmu_objset_spa(os)))) {
857 (void) printf("Can't mount a version %lld file system "
858 "on a version %lld pool\n. Pool must be upgraded to mount "
859 "this file system.", (u_longlong_t)zfsvfs->z_version,
860 (u_longlong_t)spa_version(dmu_objset_spa(os)));
864 if ((error = zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &zval)) != 0)
866 zfsvfs->z_norm = (int)zval;
868 if ((error = zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &zval)) != 0)
870 zfsvfs->z_utf8 = (zval != 0);
872 if ((error = zfs_get_zplprop(os, ZFS_PROP_CASE, &zval)) != 0)
874 zfsvfs->z_case = (uint_t)zval;
877 * Fold case on file systems that are always or sometimes case
880 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
881 zfsvfs->z_case == ZFS_CASE_MIXED)
882 zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER;
884 zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
885 zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
887 if (zfsvfs->z_use_sa) {
888 /* should either have both of these objects or none */
889 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SA_ATTRS, 8, 1,
895 * Pre SA versions file systems should never touch
896 * either the attribute registration or layout objects.
901 error = sa_setup(os, sa_obj, zfs_attr_table, ZPL_END,
902 &zfsvfs->z_attr_table);
906 if (zfsvfs->z_version >= ZPL_VERSION_SA)
907 sa_register_update_callback(os, zfs_sa_upgrade);
909 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1,
913 ASSERT(zfsvfs->z_root != 0);
915 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_UNLINKED_SET, 8, 1,
916 &zfsvfs->z_unlinkedobj);
920 error = zap_lookup(os, MASTER_NODE_OBJ,
921 zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA],
922 8, 1, &zfsvfs->z_userquota_obj);
923 if (error && error != ENOENT)
926 error = zap_lookup(os, MASTER_NODE_OBJ,
927 zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA],
928 8, 1, &zfsvfs->z_groupquota_obj);
929 if (error && error != ENOENT)
932 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES, 8, 1,
933 &zfsvfs->z_fuid_obj);
934 if (error && error != ENOENT)
937 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SHARES_DIR, 8, 1,
938 &zfsvfs->z_shares_dir);
939 if (error && error != ENOENT)
942 mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
943 mutex_init(&zfsvfs->z_lock, NULL, MUTEX_DEFAULT, NULL);
944 list_create(&zfsvfs->z_all_znodes, sizeof (znode_t),
945 offsetof(znode_t, z_link_node));
946 rrw_init(&zfsvfs->z_teardown_lock);
947 rw_init(&zfsvfs->z_teardown_inactive_lock, NULL, RW_DEFAULT, NULL);
948 rw_init(&zfsvfs->z_fuid_lock, NULL, RW_DEFAULT, NULL);
949 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
950 mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
956 dmu_objset_disown(os, zfsvfs);
958 kmem_free(zfsvfs, sizeof (zfsvfs_t));
963 zfsvfs_setup(zfsvfs_t *zfsvfs, boolean_t mounting)
967 error = zfs_register_callbacks(zfsvfs->z_vfs);
972 * Set the objset user_ptr to track its zfsvfs.
974 mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
975 dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
976 mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
978 zfsvfs->z_log = zil_open(zfsvfs->z_os, zfs_get_data);
981 * If we are not mounting (ie: online recv), then we don't
982 * have to worry about replaying the log as we blocked all
983 * operations out since we closed the ZIL.
989 * During replay we remove the read only flag to
990 * allow replays to succeed.
992 readonly = zfsvfs->z_vfs->vfs_flag & VFS_RDONLY;
994 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
996 zfs_unlinked_drain(zfsvfs);
999 * Parse and replay the intent log.
1001 * Because of ziltest, this must be done after
1002 * zfs_unlinked_drain(). (Further note: ziltest
1003 * doesn't use readonly mounts, where
1004 * zfs_unlinked_drain() isn't called.) This is because
1005 * ziltest causes spa_sync() to think it's committed,
1006 * but actually it is not, so the intent log contains
1007 * many txg's worth of changes.
1009 * In particular, if object N is in the unlinked set in
1010 * the last txg to actually sync, then it could be
1011 * actually freed in a later txg and then reallocated
1012 * in a yet later txg. This would write a "create
1013 * object N" record to the intent log. Normally, this
1014 * would be fine because the spa_sync() would have
1015 * written out the fact that object N is free, before
1016 * we could write the "create object N" intent log
1019 * But when we are in ziltest mode, we advance the "open
1020 * txg" without actually spa_sync()-ing the changes to
1021 * disk. So we would see that object N is still
1022 * allocated and in the unlinked set, and there is an
1023 * intent log record saying to allocate it.
1025 if (spa_writeable(dmu_objset_spa(zfsvfs->z_os))) {
1026 if (zil_replay_disable) {
1027 zil_destroy(zfsvfs->z_log, B_FALSE);
1029 zfsvfs->z_replay = B_TRUE;
1030 zil_replay(zfsvfs->z_os, zfsvfs,
1032 zfsvfs->z_replay = B_FALSE;
1035 zfsvfs->z_vfs->vfs_flag |= readonly; /* restore readonly bit */
1041 extern krwlock_t zfsvfs_lock; /* in zfs_znode.c */
1044 zfsvfs_free(zfsvfs_t *zfsvfs)
1049 * This is a barrier to prevent the filesystem from going away in
1050 * zfs_znode_move() until we can safely ensure that the filesystem is
1051 * not unmounted. We consider the filesystem valid before the barrier
1052 * and invalid after the barrier.
1054 rw_enter(&zfsvfs_lock, RW_READER);
1055 rw_exit(&zfsvfs_lock);
1057 zfs_fuid_destroy(zfsvfs);
1059 mutex_destroy(&zfsvfs->z_znodes_lock);
1060 mutex_destroy(&zfsvfs->z_lock);
1061 list_destroy(&zfsvfs->z_all_znodes);
1062 rrw_destroy(&zfsvfs->z_teardown_lock);
1063 rw_destroy(&zfsvfs->z_teardown_inactive_lock);
1064 rw_destroy(&zfsvfs->z_fuid_lock);
1065 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
1066 mutex_destroy(&zfsvfs->z_hold_mtx[i]);
1067 kmem_free(zfsvfs, sizeof (zfsvfs_t));
1071 zfs_set_fuid_feature(zfsvfs_t *zfsvfs)
1073 zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
1074 if (zfsvfs->z_vfs) {
1075 if (zfsvfs->z_use_fuids) {
1076 vfs_set_feature(zfsvfs->z_vfs, VFSFT_XVATTR);
1077 vfs_set_feature(zfsvfs->z_vfs, VFSFT_SYSATTR_VIEWS);
1078 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACEMASKONACCESS);
1079 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACLONCREATE);
1080 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACCESS_FILTER);
1081 vfs_set_feature(zfsvfs->z_vfs, VFSFT_REPARSE);
1083 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_XVATTR);
1084 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_SYSATTR_VIEWS);
1085 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_ACEMASKONACCESS);
1086 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_ACLONCREATE);
1087 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_ACCESS_FILTER);
1088 vfs_clear_feature(zfsvfs->z_vfs, VFSFT_REPARSE);
1091 zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
1095 zfs_domount(vfs_t *vfsp, char *osname)
1097 uint64_t recordsize, fsid_guid;
1105 error = zfsvfs_create(osname, &zfsvfs);
1108 zfsvfs->z_vfs = vfsp;
1110 if (error = dsl_prop_get_integer(osname, "recordsize", &recordsize,
1113 zfsvfs->z_vfs->vfs_bsize = SPA_MINBLOCKSIZE;
1114 zfsvfs->z_vfs->mnt_stat.f_iosize = recordsize;
1116 vfsp->vfs_data = zfsvfs;
1117 vfsp->mnt_flag |= MNT_LOCAL;
1118 vfsp->mnt_kern_flag |= MNTK_MPSAFE;
1119 vfsp->mnt_kern_flag |= MNTK_LOOKUP_SHARED;
1120 vfsp->mnt_kern_flag |= MNTK_SHARED_WRITES;
1123 * The fsid is 64 bits, composed of an 8-bit fs type, which
1124 * separates our fsid from any other filesystem types, and a
1125 * 56-bit objset unique ID. The objset unique ID is unique to
1126 * all objsets open on this system, provided by unique_create().
1127 * The 8-bit fs type must be put in the low bits of fsid[1]
1128 * because that's where other Solaris filesystems put it.
1130 fsid_guid = dmu_objset_fsid_guid(zfsvfs->z_os);
1131 ASSERT((fsid_guid & ~((1ULL<<56)-1)) == 0);
1132 vfsp->vfs_fsid.val[0] = fsid_guid;
1133 vfsp->vfs_fsid.val[1] = ((fsid_guid>>32) << 8) |
1134 vfsp->mnt_vfc->vfc_typenum & 0xFF;
1137 * Set features for file system.
1139 zfs_set_fuid_feature(zfsvfs);
1140 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE) {
1141 vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS);
1142 vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE);
1143 vfs_set_feature(vfsp, VFSFT_NOCASESENSITIVE);
1144 } else if (zfsvfs->z_case == ZFS_CASE_MIXED) {
1145 vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS);
1146 vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE);
1148 vfs_set_feature(vfsp, VFSFT_ZEROCOPY_SUPPORTED);
1150 if (dmu_objset_is_snapshot(zfsvfs->z_os)) {
1153 atime_changed_cb(zfsvfs, B_FALSE);
1154 readonly_changed_cb(zfsvfs, B_TRUE);
1155 if (error = dsl_prop_get_integer(osname, "xattr", &pval, NULL))
1157 xattr_changed_cb(zfsvfs, pval);
1158 zfsvfs->z_issnap = B_TRUE;
1159 zfsvfs->z_os->os_sync = ZFS_SYNC_DISABLED;
1161 mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
1162 dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
1163 mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
1165 error = zfsvfs_setup(zfsvfs, B_TRUE);
1168 vfs_mountedfrom(vfsp, osname);
1169 /* Grab extra reference. */
1170 VERIFY(VFS_ROOT(vfsp, LK_EXCLUSIVE, &vp) == 0);
1173 if (!zfsvfs->z_issnap)
1174 zfsctl_create(zfsvfs);
1177 dmu_objset_disown(zfsvfs->z_os, zfsvfs);
1178 zfsvfs_free(zfsvfs);
1180 atomic_add_32(&zfs_active_fs_count, 1);
1187 zfs_unregister_callbacks(zfsvfs_t *zfsvfs)
1189 objset_t *os = zfsvfs->z_os;
1190 struct dsl_dataset *ds;
1193 * Unregister properties.
1195 if (!dmu_objset_is_snapshot(os)) {
1196 ds = dmu_objset_ds(os);
1197 VERIFY(dsl_prop_unregister(ds, "atime", atime_changed_cb,
1200 VERIFY(dsl_prop_unregister(ds, "xattr", xattr_changed_cb,
1203 VERIFY(dsl_prop_unregister(ds, "recordsize", blksz_changed_cb,
1206 VERIFY(dsl_prop_unregister(ds, "readonly", readonly_changed_cb,
1209 VERIFY(dsl_prop_unregister(ds, "setuid", setuid_changed_cb,
1212 VERIFY(dsl_prop_unregister(ds, "exec", exec_changed_cb,
1215 VERIFY(dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb,
1218 VERIFY(dsl_prop_unregister(ds, "aclmode", acl_mode_changed_cb,
1221 VERIFY(dsl_prop_unregister(ds, "aclinherit",
1222 acl_inherit_changed_cb, zfsvfs) == 0);
1224 VERIFY(dsl_prop_unregister(ds, "vscan",
1225 vscan_changed_cb, zfsvfs) == 0);
1231 * Convert a decimal digit string to a uint64_t integer.
1234 str_to_uint64(char *str, uint64_t *objnum)
1239 if (*str < '0' || *str > '9')
1242 num = num*10 + *str++ - '0';
1250 * The boot path passed from the boot loader is in the form of
1251 * "rootpool-name/root-filesystem-object-number'. Convert this
1252 * string to a dataset name: "rootpool-name/root-filesystem-name".
1255 zfs_parse_bootfs(char *bpath, char *outpath)
1261 if (*bpath == 0 || *bpath == '/')
1264 (void) strcpy(outpath, bpath);
1266 slashp = strchr(bpath, '/');
1268 /* if no '/', just return the pool name */
1269 if (slashp == NULL) {
1273 /* if not a number, just return the root dataset name */
1274 if (str_to_uint64(slashp+1, &objnum)) {
1279 error = dsl_dsobj_to_dsname(bpath, objnum, outpath);
1286 * zfs_check_global_label:
1287 * Check that the hex label string is appropriate for the dataset
1288 * being mounted into the global_zone proper.
1290 * Return an error if the hex label string is not default or
1291 * admin_low/admin_high. For admin_low labels, the corresponding
1292 * dataset must be readonly.
1295 zfs_check_global_label(const char *dsname, const char *hexsl)
1297 if (strcasecmp(hexsl, ZFS_MLSLABEL_DEFAULT) == 0)
1299 if (strcasecmp(hexsl, ADMIN_HIGH) == 0)
1301 if (strcasecmp(hexsl, ADMIN_LOW) == 0) {
1302 /* must be readonly */
1305 if (dsl_prop_get_integer(dsname,
1306 zfs_prop_to_name(ZFS_PROP_READONLY), &rdonly, NULL))
1308 return (rdonly ? 0 : EACCES);
1314 * zfs_mount_label_policy:
1315 * Determine whether the mount is allowed according to MAC check.
1316 * by comparing (where appropriate) label of the dataset against
1317 * the label of the zone being mounted into. If the dataset has
1318 * no label, create one.
1321 * 0 : access allowed
1322 * >0 : error code, such as EACCES
1325 zfs_mount_label_policy(vfs_t *vfsp, char *osname)
1328 zone_t *mntzone = NULL;
1329 ts_label_t *mnt_tsl;
1332 char ds_hexsl[MAXNAMELEN];
1334 retv = EACCES; /* assume the worst */
1337 * Start by getting the dataset label if it exists.
1339 error = dsl_prop_get(osname, zfs_prop_to_name(ZFS_PROP_MLSLABEL),
1340 1, sizeof (ds_hexsl), &ds_hexsl, NULL);
1345 * If labeling is NOT enabled, then disallow the mount of datasets
1346 * which have a non-default label already. No other label checks
1349 if (!is_system_labeled()) {
1350 if (strcasecmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) == 0)
1356 * Get the label of the mountpoint. If mounting into the global
1357 * zone (i.e. mountpoint is not within an active zone and the
1358 * zoned property is off), the label must be default or
1359 * admin_low/admin_high only; no other checks are needed.
1361 mntzone = zone_find_by_any_path(refstr_value(vfsp->vfs_mntpt), B_FALSE);
1362 if (mntzone->zone_id == GLOBAL_ZONEID) {
1367 if (dsl_prop_get_integer(osname,
1368 zfs_prop_to_name(ZFS_PROP_ZONED), &zoned, NULL))
1371 return (zfs_check_global_label(osname, ds_hexsl));
1374 * This is the case of a zone dataset being mounted
1375 * initially, before the zone has been fully created;
1376 * allow this mount into global zone.
1381 mnt_tsl = mntzone->zone_slabel;
1382 ASSERT(mnt_tsl != NULL);
1383 label_hold(mnt_tsl);
1384 mnt_sl = label2bslabel(mnt_tsl);
1386 if (strcasecmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) == 0) {
1388 * The dataset doesn't have a real label, so fabricate one.
1392 if (l_to_str_internal(mnt_sl, &str) == 0 &&
1393 dsl_prop_set(osname, zfs_prop_to_name(ZFS_PROP_MLSLABEL),
1394 ZPROP_SRC_LOCAL, 1, strlen(str) + 1, str) == 0)
1397 kmem_free(str, strlen(str) + 1);
1398 } else if (hexstr_to_label(ds_hexsl, &ds_sl) == 0) {
1400 * Now compare labels to complete the MAC check. If the
1401 * labels are equal then allow access. If the mountpoint
1402 * label dominates the dataset label, allow readonly access.
1403 * Otherwise, access is denied.
1405 if (blequal(mnt_sl, &ds_sl))
1407 else if (bldominates(mnt_sl, &ds_sl)) {
1408 vfs_setmntopt(vfsp, MNTOPT_RO, NULL, 0);
1413 label_rele(mnt_tsl);
1417 #endif /* SECLABEL */
1419 #ifdef OPENSOLARIS_MOUNTROOT
1421 zfs_mountroot(vfs_t *vfsp, enum whymountroot why)
1424 static int zfsrootdone = 0;
1425 zfsvfs_t *zfsvfs = NULL;
1434 * The filesystem that we mount as root is defined in the
1435 * boot property "zfs-bootfs" with a format of
1436 * "poolname/root-dataset-objnum".
1438 if (why == ROOT_INIT) {
1442 * the process of doing a spa_load will require the
1443 * clock to be set before we could (for example) do
1444 * something better by looking at the timestamp on
1445 * an uberblock, so just set it to -1.
1449 if ((zfs_bootfs = spa_get_bootprop("zfs-bootfs")) == NULL) {
1450 cmn_err(CE_NOTE, "spa_get_bootfs: can not get "
1454 zfs_devid = spa_get_bootprop("diskdevid");
1455 error = spa_import_rootpool(rootfs.bo_name, zfs_devid);
1457 spa_free_bootprop(zfs_devid);
1459 spa_free_bootprop(zfs_bootfs);
1460 cmn_err(CE_NOTE, "spa_import_rootpool: error %d",
1464 if (error = zfs_parse_bootfs(zfs_bootfs, rootfs.bo_name)) {
1465 spa_free_bootprop(zfs_bootfs);
1466 cmn_err(CE_NOTE, "zfs_parse_bootfs: error %d",
1471 spa_free_bootprop(zfs_bootfs);
1473 if (error = vfs_lock(vfsp))
1476 if (error = zfs_domount(vfsp, rootfs.bo_name)) {
1477 cmn_err(CE_NOTE, "zfs_domount: error %d", error);
1481 zfsvfs = (zfsvfs_t *)vfsp->vfs_data;
1483 if (error = zfs_zget(zfsvfs, zfsvfs->z_root, &zp)) {
1484 cmn_err(CE_NOTE, "zfs_zget: error %d", error);
1489 mutex_enter(&vp->v_lock);
1490 vp->v_flag |= VROOT;
1491 mutex_exit(&vp->v_lock);
1495 * Leave rootvp held. The root file system is never unmounted.
1498 vfs_add((struct vnode *)0, vfsp,
1499 (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0);
1503 } else if (why == ROOT_REMOUNT) {
1504 readonly_changed_cb(vfsp->vfs_data, B_FALSE);
1505 vfsp->vfs_flag |= VFS_REMOUNT;
1507 /* refresh mount options */
1508 zfs_unregister_callbacks(vfsp->vfs_data);
1509 return (zfs_register_callbacks(vfsp));
1511 } else if (why == ROOT_UNMOUNT) {
1512 zfs_unregister_callbacks((zfsvfs_t *)vfsp->vfs_data);
1513 (void) zfs_sync(vfsp, 0, 0);
1518 * if "why" is equal to anything else other than ROOT_INIT,
1519 * ROOT_REMOUNT, or ROOT_UNMOUNT, we do not support it.
1523 #endif /* OPENSOLARIS_MOUNTROOT */
1527 zfs_mount(vfs_t *vfsp)
1529 kthread_t *td = curthread;
1530 vnode_t *mvp = vfsp->mnt_vnodecovered;
1531 cred_t *cr = td->td_ucred;
1536 if (vfs_getopt(vfsp->mnt_optnew, "from", (void **)&osname, NULL))
1540 * If full-owner-access is enabled and delegated administration is
1541 * turned on, we must set nosuid.
1543 if (zfs_super_owner &&
1544 dsl_deleg_access(osname, ZFS_DELEG_PERM_MOUNT, cr) != ECANCELED) {
1545 secpolicy_fs_mount_clearopts(cr, vfsp);
1549 * Check for mount privilege?
1551 * If we don't have privilege then see if
1552 * we have local permission to allow it
1554 error = secpolicy_fs_mount(cr, mvp, vfsp);
1556 if (dsl_deleg_access(osname, ZFS_DELEG_PERM_MOUNT, cr) != 0)
1559 if (!(vfsp->vfs_flag & MS_REMOUNT)) {
1563 * Make sure user is the owner of the mount point
1564 * or has sufficient privileges.
1567 vattr.va_mask = AT_UID;
1569 vn_lock(mvp, LK_SHARED | LK_RETRY);
1570 if (VOP_GETATTR(mvp, &vattr, cr)) {
1575 if (secpolicy_vnode_owner(mvp, cr, vattr.va_uid) != 0 &&
1576 VOP_ACCESS(mvp, VWRITE, cr, td) != 0) {
1583 secpolicy_fs_mount_clearopts(cr, vfsp);
1587 * Refuse to mount a filesystem if we are in a local zone and the
1588 * dataset is not visible.
1590 if (!INGLOBALZONE(curthread) &&
1591 (!zone_dataset_visible(osname, &canwrite) || !canwrite)) {
1597 error = zfs_mount_label_policy(vfsp, osname);
1602 vfsp->vfs_flag |= MNT_NFS4ACLS;
1605 * When doing a remount, we simply refresh our temporary properties
1606 * according to those options set in the current VFS options.
1608 if (vfsp->vfs_flag & MS_REMOUNT) {
1609 /* refresh mount options */
1610 zfs_unregister_callbacks(vfsp->vfs_data);
1611 error = zfs_register_callbacks(vfsp);
1616 error = zfs_domount(vfsp, osname);
1621 * Add an extra VFS_HOLD on our parent vfs so that it can't
1622 * disappear due to a forced unmount.
1624 if (error == 0 && ((zfsvfs_t *)vfsp->vfs_data)->z_issnap)
1625 VFS_HOLD(mvp->v_vfsp);
1633 zfs_statfs(vfs_t *vfsp, struct statfs *statp)
1635 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1636 uint64_t refdbytes, availbytes, usedobjs, availobjs;
1638 statp->f_version = STATFS_VERSION;
1642 dmu_objset_space(zfsvfs->z_os,
1643 &refdbytes, &availbytes, &usedobjs, &availobjs);
1646 * The underlying storage pool actually uses multiple block sizes.
1647 * We report the fragsize as the smallest block size we support,
1648 * and we report our blocksize as the filesystem's maximum blocksize.
1650 statp->f_bsize = SPA_MINBLOCKSIZE;
1651 statp->f_iosize = zfsvfs->z_vfs->mnt_stat.f_iosize;
1654 * The following report "total" blocks of various kinds in the
1655 * file system, but reported in terms of f_frsize - the
1659 statp->f_blocks = (refdbytes + availbytes) >> SPA_MINBLOCKSHIFT;
1660 statp->f_bfree = availbytes / statp->f_bsize;
1661 statp->f_bavail = statp->f_bfree; /* no root reservation */
1664 * statvfs() should really be called statufs(), because it assumes
1665 * static metadata. ZFS doesn't preallocate files, so the best
1666 * we can do is report the max that could possibly fit in f_files,
1667 * and that minus the number actually used in f_ffree.
1668 * For f_ffree, report the smaller of the number of object available
1669 * and the number of blocks (each object will take at least a block).
1671 statp->f_ffree = MIN(availobjs, statp->f_bfree);
1672 statp->f_files = statp->f_ffree + usedobjs;
1675 * We're a zfs filesystem.
1677 (void) strlcpy(statp->f_fstypename, "zfs", sizeof(statp->f_fstypename));
1679 strlcpy(statp->f_mntfromname, vfsp->mnt_stat.f_mntfromname,
1680 sizeof(statp->f_mntfromname));
1681 strlcpy(statp->f_mntonname, vfsp->mnt_stat.f_mntonname,
1682 sizeof(statp->f_mntonname));
1684 statp->f_namemax = ZFS_MAXNAMELEN;
1691 zfs_vnode_lock(vnode_t *vp, int flags)
1698 * Check if the file system wasn't forcibly unmounted in the meantime.
1700 error = vn_lock(vp, flags);
1701 if (error == 0 && (vp->v_iflag & VI_DOOMED) != 0) {
1710 zfs_root(vfs_t *vfsp, int flags, vnode_t **vpp)
1712 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1716 ZFS_ENTER_NOERROR(zfsvfs);
1718 error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp);
1720 *vpp = ZTOV(rootzp);
1725 error = zfs_vnode_lock(*vpp, flags);
1727 (*vpp)->v_vflag |= VV_ROOT;
1736 * Teardown the zfsvfs::z_os.
1738 * Note, if 'unmounting' if FALSE, we return with the 'z_teardown_lock'
1739 * and 'z_teardown_inactive_lock' held.
1742 zfsvfs_teardown(zfsvfs_t *zfsvfs, boolean_t unmounting)
1746 rrw_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG);
1750 * We purge the parent filesystem's vfsp as the parent
1751 * filesystem and all of its snapshots have their vnode's
1752 * v_vfsp set to the parent's filesystem's vfsp. Note,
1753 * 'z_parent' is self referential for non-snapshots.
1755 (void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0);
1756 #ifdef FREEBSD_NAMECACHE
1757 cache_purgevfs(zfsvfs->z_parent->z_vfs);
1762 * Close the zil. NB: Can't close the zil while zfs_inactive
1763 * threads are blocked as zil_close can call zfs_inactive.
1765 if (zfsvfs->z_log) {
1766 zil_close(zfsvfs->z_log);
1767 zfsvfs->z_log = NULL;
1770 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_WRITER);
1773 * If we are not unmounting (ie: online recv) and someone already
1774 * unmounted this file system while we were doing the switcheroo,
1775 * or a reopen of z_os failed then just bail out now.
1777 if (!unmounting && (zfsvfs->z_unmounted || zfsvfs->z_os == NULL)) {
1778 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1779 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
1784 * At this point there are no vops active, and any new vops will
1785 * fail with EIO since we have z_teardown_lock for writer (only
1786 * relavent for forced unmount).
1788 * Release all holds on dbufs.
1790 mutex_enter(&zfsvfs->z_znodes_lock);
1791 for (zp = list_head(&zfsvfs->z_all_znodes); zp != NULL;
1792 zp = list_next(&zfsvfs->z_all_znodes, zp))
1794 ASSERT(ZTOV(zp)->v_count >= 0);
1795 zfs_znode_dmu_fini(zp);
1797 mutex_exit(&zfsvfs->z_znodes_lock);
1800 * If we are unmounting, set the unmounted flag and let new vops
1801 * unblock. zfs_inactive will have the unmounted behavior, and all
1802 * other vops will fail with EIO.
1805 zfsvfs->z_unmounted = B_TRUE;
1806 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
1807 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1811 * Some znodes might not be fully reclaimed, wait for them.
1813 mutex_enter(&zfsvfs->z_znodes_lock);
1814 while (list_head(&zfsvfs->z_all_znodes) != NULL) {
1815 msleep(zfsvfs, &zfsvfs->z_znodes_lock, 0,
1818 mutex_exit(&zfsvfs->z_znodes_lock);
1823 * z_os will be NULL if there was an error in attempting to reopen
1824 * zfsvfs, so just return as the properties had already been
1825 * unregistered and cached data had been evicted before.
1827 if (zfsvfs->z_os == NULL)
1831 * Unregister properties.
1833 zfs_unregister_callbacks(zfsvfs);
1838 if (dmu_objset_is_dirty_anywhere(zfsvfs->z_os))
1839 if (!(zfsvfs->z_vfs->vfs_flag & VFS_RDONLY))
1840 txg_wait_synced(dmu_objset_pool(zfsvfs->z_os), 0);
1841 (void) dmu_objset_evict_dbufs(zfsvfs->z_os);
1848 zfs_umount(vfs_t *vfsp, int fflag)
1850 kthread_t *td = curthread;
1851 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1853 cred_t *cr = td->td_ucred;
1856 ret = secpolicy_fs_unmount(cr, vfsp);
1858 if (dsl_deleg_access((char *)refstr_value(vfsp->vfs_resource),
1859 ZFS_DELEG_PERM_MOUNT, cr))
1864 * We purge the parent filesystem's vfsp as the parent filesystem
1865 * and all of its snapshots have their vnode's v_vfsp set to the
1866 * parent's filesystem's vfsp. Note, 'z_parent' is self
1867 * referential for non-snapshots.
1869 (void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0);
1872 * Unmount any snapshots mounted under .zfs before unmounting the
1875 if (zfsvfs->z_ctldir != NULL) {
1876 if ((ret = zfsctl_umount_snapshots(vfsp, fflag, cr)) != 0)
1878 ret = vflush(vfsp, 0, 0, td);
1879 ASSERT(ret == EBUSY);
1880 if (!(fflag & MS_FORCE)) {
1881 if (zfsvfs->z_ctldir->v_count > 1)
1883 ASSERT(zfsvfs->z_ctldir->v_count == 1);
1885 zfsctl_destroy(zfsvfs);
1886 ASSERT(zfsvfs->z_ctldir == NULL);
1889 if (fflag & MS_FORCE) {
1891 * Mark file system as unmounted before calling
1892 * vflush(FORCECLOSE). This way we ensure no future vnops
1893 * will be called and risk operating on DOOMED vnodes.
1895 rrw_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG);
1896 zfsvfs->z_unmounted = B_TRUE;
1897 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
1901 * Flush all the files.
1903 ret = vflush(vfsp, 1, (fflag & MS_FORCE) ? FORCECLOSE : 0, td);
1905 if (!zfsvfs->z_issnap) {
1906 zfsctl_create(zfsvfs);
1907 ASSERT(zfsvfs->z_ctldir != NULL);
1912 if (!(fflag & MS_FORCE)) {
1914 * Check the number of active vnodes in the file system.
1915 * Our count is maintained in the vfs structure, but the
1916 * number is off by 1 to indicate a hold on the vfs
1919 * The '.zfs' directory maintains a reference of its
1920 * own, and any active references underneath are
1921 * reflected in the vnode count.
1923 if (zfsvfs->z_ctldir == NULL) {
1924 if (vfsp->vfs_count > 1)
1927 if (vfsp->vfs_count > 2 ||
1928 zfsvfs->z_ctldir->v_count > 1)
1933 vfsp->mnt_kern_flag |= MNTK_UNMOUNTF;
1937 VERIFY(zfsvfs_teardown(zfsvfs, B_TRUE) == 0);
1941 * z_os will be NULL if there was an error in
1942 * attempting to reopen zfsvfs.
1946 * Unset the objset user_ptr.
1948 mutex_enter(&os->os_user_ptr_lock);
1949 dmu_objset_set_user(os, NULL);
1950 mutex_exit(&os->os_user_ptr_lock);
1953 * Finally release the objset
1955 dmu_objset_disown(os, zfsvfs);
1959 * We can now safely destroy the '.zfs' directory node.
1961 if (zfsvfs->z_ctldir != NULL)
1962 zfsctl_destroy(zfsvfs);
1963 if (zfsvfs->z_issnap) {
1964 vnode_t *svp = vfsp->mnt_vnodecovered;
1966 if (svp->v_count >= 2)
1975 zfs_vget(vfs_t *vfsp, ino_t ino, int flags, vnode_t **vpp)
1977 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1982 * zfs_zget() can't operate on virtual entries like .zfs/ or
1983 * .zfs/snapshot/ directories, that's why we return EOPNOTSUPP.
1984 * This will make NFS to switch to LOOKUP instead of using VGET.
1986 if (ino == ZFSCTL_INO_ROOT || ino == ZFSCTL_INO_SNAPDIR)
1987 return (EOPNOTSUPP);
1990 err = zfs_zget(zfsvfs, ino, &zp);
1991 if (err == 0 && zp->z_unlinked) {
1999 err = zfs_vnode_lock(*vpp, flags);
2006 zfs_checkexp(vfs_t *vfsp, struct sockaddr *nam, int *extflagsp,
2007 struct ucred **credanonp, int *numsecflavors, int **secflavors)
2009 zfsvfs_t *zfsvfs = vfsp->vfs_data;
2012 * If this is regular file system vfsp is the same as
2013 * zfsvfs->z_parent->z_vfs, but if it is snapshot,
2014 * zfsvfs->z_parent->z_vfs represents parent file system
2015 * which we have to use here, because only this file system
2016 * has mnt_export configured.
2018 return (vfs_stdcheckexp(zfsvfs->z_parent->z_vfs, nam, extflagsp,
2019 credanonp, numsecflavors, secflavors));
2022 CTASSERT(SHORT_FID_LEN <= sizeof(struct fid));
2023 CTASSERT(LONG_FID_LEN <= sizeof(struct fid));
2026 zfs_fhtovp(vfs_t *vfsp, fid_t *fidp, int flags, vnode_t **vpp)
2028 zfsvfs_t *zfsvfs = vfsp->vfs_data;
2030 uint64_t object = 0;
2031 uint64_t fid_gen = 0;
2041 * On FreeBSD we can get snapshot's mount point or its parent file
2042 * system mount point depending if snapshot is already mounted or not.
2044 if (zfsvfs->z_parent == zfsvfs && fidp->fid_len == LONG_FID_LEN) {
2045 zfid_long_t *zlfid = (zfid_long_t *)fidp;
2046 uint64_t objsetid = 0;
2047 uint64_t setgen = 0;
2049 for (i = 0; i < sizeof (zlfid->zf_setid); i++)
2050 objsetid |= ((uint64_t)zlfid->zf_setid[i]) << (8 * i);
2052 for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
2053 setgen |= ((uint64_t)zlfid->zf_setgen[i]) << (8 * i);
2057 err = zfsctl_lookup_objset(vfsp, objsetid, &zfsvfs);
2063 if (fidp->fid_len == SHORT_FID_LEN || fidp->fid_len == LONG_FID_LEN) {
2064 zfid_short_t *zfid = (zfid_short_t *)fidp;
2066 for (i = 0; i < sizeof (zfid->zf_object); i++)
2067 object |= ((uint64_t)zfid->zf_object[i]) << (8 * i);
2069 for (i = 0; i < sizeof (zfid->zf_gen); i++)
2070 fid_gen |= ((uint64_t)zfid->zf_gen[i]) << (8 * i);
2076 /* A zero fid_gen means we are in the .zfs control directories */
2078 (object == ZFSCTL_INO_ROOT || object == ZFSCTL_INO_SNAPDIR)) {
2079 *vpp = zfsvfs->z_ctldir;
2080 ASSERT(*vpp != NULL);
2081 if (object == ZFSCTL_INO_SNAPDIR) {
2082 VERIFY(zfsctl_root_lookup(*vpp, "snapshot", vpp, NULL,
2083 0, NULL, NULL, NULL, NULL, NULL) == 0);
2088 err = zfs_vnode_lock(*vpp, flags | LK_RETRY);
2094 gen_mask = -1ULL >> (64 - 8 * i);
2096 dprintf("getting %llu [%u mask %llx]\n", object, fid_gen, gen_mask);
2097 if (err = zfs_zget(zfsvfs, object, &zp)) {
2101 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zfsvfs), &zp_gen,
2103 zp_gen = zp_gen & gen_mask;
2106 if (zp->z_unlinked || zp_gen != fid_gen) {
2107 dprintf("znode gen (%u) != fid gen (%u)\n", zp_gen, fid_gen);
2115 err = zfs_vnode_lock(*vpp, flags | LK_RETRY);
2117 vnode_create_vobject(*vpp, zp->z_size, curthread);
2124 * Block out VOPs and close zfsvfs_t::z_os
2126 * Note, if successful, then we return with the 'z_teardown_lock' and
2127 * 'z_teardown_inactive_lock' write held.
2130 zfs_suspend_fs(zfsvfs_t *zfsvfs)
2134 if ((error = zfsvfs_teardown(zfsvfs, B_FALSE)) != 0)
2136 dmu_objset_disown(zfsvfs->z_os, zfsvfs);
2142 * Reopen zfsvfs_t::z_os and release VOPs.
2145 zfs_resume_fs(zfsvfs_t *zfsvfs, const char *osname)
2149 ASSERT(RRW_WRITE_HELD(&zfsvfs->z_teardown_lock));
2150 ASSERT(RW_WRITE_HELD(&zfsvfs->z_teardown_inactive_lock));
2152 err = dmu_objset_own(osname, DMU_OST_ZFS, B_FALSE, zfsvfs,
2155 zfsvfs->z_os = NULL;
2158 uint64_t sa_obj = 0;
2161 * Make sure version hasn't changed
2164 err = zfs_get_zplprop(zfsvfs->z_os, ZFS_PROP_VERSION,
2165 &zfsvfs->z_version);
2170 err = zap_lookup(zfsvfs->z_os, MASTER_NODE_OBJ,
2171 ZFS_SA_ATTRS, 8, 1, &sa_obj);
2173 if (err && zfsvfs->z_version >= ZPL_VERSION_SA)
2176 if ((err = sa_setup(zfsvfs->z_os, sa_obj,
2177 zfs_attr_table, ZPL_END, &zfsvfs->z_attr_table)) != 0)
2180 if (zfsvfs->z_version >= ZPL_VERSION_SA)
2181 sa_register_update_callback(zfsvfs->z_os,
2184 VERIFY(zfsvfs_setup(zfsvfs, B_FALSE) == 0);
2186 zfs_set_fuid_feature(zfsvfs);
2189 * Attempt to re-establish all the active znodes with
2190 * their dbufs. If a zfs_rezget() fails, then we'll let
2191 * any potential callers discover that via ZFS_ENTER_VERIFY_VP
2192 * when they try to use their znode.
2194 mutex_enter(&zfsvfs->z_znodes_lock);
2195 for (zp = list_head(&zfsvfs->z_all_znodes); zp;
2196 zp = list_next(&zfsvfs->z_all_znodes, zp)) {
2197 (void) zfs_rezget(zp);
2199 mutex_exit(&zfsvfs->z_znodes_lock);
2203 /* release the VOPs */
2204 rw_exit(&zfsvfs->z_teardown_inactive_lock);
2205 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
2209 * Since we couldn't reopen zfsvfs::z_os, or
2210 * setup the sa framework force unmount this file system.
2212 if (vn_vfswlock(zfsvfs->z_vfs->vfs_vnodecovered) == 0)
2213 (void) dounmount(zfsvfs->z_vfs, MS_FORCE, curthread);
2219 zfs_freevfs(vfs_t *vfsp)
2221 zfsvfs_t *zfsvfs = vfsp->vfs_data;
2225 * If this is a snapshot, we have an extra VFS_HOLD on our parent
2226 * from zfs_mount(). Release it here. If we came through
2227 * zfs_mountroot() instead, we didn't grab an extra hold, so
2228 * skip the VFS_RELE for rootvfs.
2230 if (zfsvfs->z_issnap && (vfsp != rootvfs))
2231 VFS_RELE(zfsvfs->z_parent->z_vfs);
2234 zfsvfs_free(zfsvfs);
2236 atomic_add_32(&zfs_active_fs_count, -1);
2240 static int desiredvnodes_backup;
2244 zfs_vnodes_adjust(void)
2247 int newdesiredvnodes;
2249 desiredvnodes_backup = desiredvnodes;
2252 * We calculate newdesiredvnodes the same way it is done in
2253 * vntblinit(). If it is equal to desiredvnodes, it means that
2254 * it wasn't tuned by the administrator and we can tune it down.
2256 newdesiredvnodes = min(maxproc + cnt.v_page_count / 4, 2 *
2257 vm_kmem_size / (5 * (sizeof(struct vm_object) +
2258 sizeof(struct vnode))));
2259 if (newdesiredvnodes == desiredvnodes)
2260 desiredvnodes = (3 * newdesiredvnodes) / 4;
2265 zfs_vnodes_adjust_back(void)
2269 desiredvnodes = desiredvnodes_backup;
2277 printf("ZFS filesystem version " ZPL_VERSION_STRING "\n");
2280 * Initialize .zfs directory structures
2285 * Initialize znode cache, vnode ops, etc...
2290 * Reduce number of vnodes. Originally number of vnodes is calculated
2291 * with UFS inode in mind. We reduce it here, because it's too big for
2294 zfs_vnodes_adjust();
2296 dmu_objset_register_type(DMU_OST_ZFS, zfs_space_delta_cb);
2304 zfs_vnodes_adjust_back();
2310 return (zfs_active_fs_count != 0);
2314 zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers)
2317 objset_t *os = zfsvfs->z_os;
2320 if (newvers < ZPL_VERSION_INITIAL || newvers > ZPL_VERSION)
2323 if (newvers < zfsvfs->z_version)
2326 if (zfs_spa_version_map(newvers) >
2327 spa_version(dmu_objset_spa(zfsvfs->z_os)))
2330 tx = dmu_tx_create(os);
2331 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_FALSE, ZPL_VERSION_STR);
2332 if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
2333 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE,
2335 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
2337 error = dmu_tx_assign(tx, TXG_WAIT);
2343 error = zap_update(os, MASTER_NODE_OBJ, ZPL_VERSION_STR,
2344 8, 1, &newvers, tx);
2351 if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
2354 ASSERT3U(spa_version(dmu_objset_spa(zfsvfs->z_os)), >=,
2356 sa_obj = zap_create(os, DMU_OT_SA_MASTER_NODE,
2357 DMU_OT_NONE, 0, tx);
2359 error = zap_add(os, MASTER_NODE_OBJ,
2360 ZFS_SA_ATTRS, 8, 1, &sa_obj, tx);
2361 ASSERT3U(error, ==, 0);
2363 VERIFY(0 == sa_set_sa_object(os, sa_obj));
2364 sa_register_update_callback(os, zfs_sa_upgrade);
2367 spa_history_log_internal(LOG_DS_UPGRADE,
2368 dmu_objset_spa(os), tx, "oldver=%llu newver=%llu dataset = %llu",
2369 zfsvfs->z_version, newvers, dmu_objset_id(os));
2373 zfsvfs->z_version = newvers;
2375 zfs_set_fuid_feature(zfsvfs);
2381 * Read a property stored within the master node.
2384 zfs_get_zplprop(objset_t *os, zfs_prop_t prop, uint64_t *value)
2390 * Look up the file system's value for the property. For the
2391 * version property, we look up a slightly different string.
2393 if (prop == ZFS_PROP_VERSION)
2394 pname = ZPL_VERSION_STR;
2396 pname = zfs_prop_to_name(prop);
2399 error = zap_lookup(os, MASTER_NODE_OBJ, pname, 8, 1, value);
2401 if (error == ENOENT) {
2402 /* No value set, use the default value */
2404 case ZFS_PROP_VERSION:
2405 *value = ZPL_VERSION;
2407 case ZFS_PROP_NORMALIZE:
2408 case ZFS_PROP_UTF8ONLY:
2412 *value = ZFS_CASE_SENSITIVE;
2424 zfsvfs_update_fromname(const char *oldname, const char *newname)
2426 char tmpbuf[MAXPATHLEN];
2431 oldlen = strlen(oldname);
2433 mtx_lock(&mountlist_mtx);
2434 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
2435 fromname = mp->mnt_stat.f_mntfromname;
2436 if (strcmp(fromname, oldname) == 0) {
2437 (void)strlcpy(fromname, newname,
2438 sizeof(mp->mnt_stat.f_mntfromname));
2441 if (strncmp(fromname, oldname, oldlen) == 0 &&
2442 (fromname[oldlen] == '/' || fromname[oldlen] == '@')) {
2443 (void)snprintf(tmpbuf, sizeof(tmpbuf), "%s%s",
2444 newname, fromname + oldlen);
2445 (void)strlcpy(fromname, tmpbuf,
2446 sizeof(mp->mnt_stat.f_mntfromname));
2450 mtx_unlock(&mountlist_mtx);