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.
25 /* Portions Copyright 2010 Robert Milkowski */
27 #include <sys/types.h>
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/sysmacros.h>
32 #include <sys/pathname.h>
33 #include <sys/vnode.h>
35 #include <sys/vfs_opreg.h>
36 #include <sys/mntent.h>
37 #include <sys/mount.h>
38 #include <sys/cmn_err.h>
39 #include "fs/fs_subr.h"
40 #include <sys/zfs_znode.h>
41 #include <sys/zfs_dir.h>
43 #include <sys/fs/zfs.h>
45 #include <sys/dsl_prop.h>
46 #include <sys/dsl_dataset.h>
47 #include <sys/dsl_deleg.h>
51 #include <sys/varargs.h>
52 #include <sys/policy.h>
53 #include <sys/atomic.h>
54 #include <sys/mkdev.h>
55 #include <sys/modctl.h>
56 #include <sys/refstr.h>
57 #include <sys/zfs_ioctl.h>
58 #include <sys/zfs_fuid.h>
59 #include <sys/bootconf.h>
60 #include <sys/sunddi.h>
62 #include <sys/dmu_objset.h>
63 #include <sys/spa_boot.h>
65 #include "zfs_comutil.h"
71 zfs_sync(vfs_t *vfsp, short flag, cred_t *cr)
74 * Data integrity is job one. We don't want a compromised kernel
75 * writing to the storage pool, so we never sync during panic.
77 if (unlikely(oops_in_progress))
82 * Sync a specific filesystem.
84 zfsvfs_t *zfsvfs = vfsp->vfs_data;
88 dp = dmu_objset_pool(zfsvfs->z_os);
92 * If the system is shutting down, then skip any
93 * filesystems which may exist on a suspended pool.
95 * XXX: This can be implemented using the Linux reboot
96 * notifiers: {un}register_reboot_notifier().
98 if (sys_shutdown && spa_suspended(dp->dp_spa)) {
102 #endif /* HAVE_SHUTDOWN */
104 if (zfsvfs->z_log != NULL)
105 zil_commit(zfsvfs->z_log, 0);
110 * Sync all ZFS filesystems. This is what happens when you
111 * run sync(1M). Unlike other filesystems, ZFS honors the
112 * request by waiting for all pools to commit all dirty data.
119 EXPORT_SYMBOL(zfs_sync);
122 atime_changed_cb(void *arg, uint64_t newval)
124 zfsvfs_t *zfsvfs = arg;
126 if (newval == TRUE) {
127 zfsvfs->z_atime = TRUE;
128 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME);
129 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_ATIME, NULL, 0);
131 zfsvfs->z_atime = FALSE;
132 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_ATIME);
133 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME, NULL, 0);
138 xattr_changed_cb(void *arg, uint64_t newval)
140 zfsvfs_t *zfsvfs = arg;
142 if (newval == TRUE) {
143 /* XXX locking on vfs_flag? */
144 zfsvfs->z_vfs->vfs_flag |= VFS_XATTR;
145 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR);
146 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_XATTR, NULL, 0);
148 /* XXX locking on vfs_flag? */
149 zfsvfs->z_vfs->vfs_flag &= ~VFS_XATTR;
150 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_XATTR);
151 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR, NULL, 0);
156 blksz_changed_cb(void *arg, uint64_t newval)
158 zfsvfs_t *zfsvfs = arg;
160 if (newval < SPA_MINBLOCKSIZE ||
161 newval > SPA_MAXBLOCKSIZE || !ISP2(newval))
162 newval = SPA_MAXBLOCKSIZE;
164 zfsvfs->z_max_blksz = newval;
165 zfsvfs->z_vfs->vfs_bsize = newval;
169 readonly_changed_cb(void *arg, uint64_t newval)
171 zfsvfs_t *zfsvfs = arg;
174 /* XXX locking on vfs_flag? */
175 zfsvfs->z_vfs->vfs_flag |= VFS_RDONLY;
176 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RW);
177 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RO, NULL, 0);
179 /* XXX locking on vfs_flag? */
180 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
181 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RO);
182 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RW, NULL, 0);
187 devices_changed_cb(void *arg, uint64_t newval)
189 zfsvfs_t *zfsvfs = arg;
191 if (newval == FALSE) {
192 zfsvfs->z_vfs->vfs_flag |= VFS_NODEVICES;
193 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES);
194 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES, NULL, 0);
196 zfsvfs->z_vfs->vfs_flag &= ~VFS_NODEVICES;
197 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES);
198 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES, NULL, 0);
203 setuid_changed_cb(void *arg, uint64_t newval)
205 zfsvfs_t *zfsvfs = arg;
207 if (newval == FALSE) {
208 zfsvfs->z_vfs->vfs_flag |= VFS_NOSETUID;
209 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_SETUID);
210 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID, NULL, 0);
212 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOSETUID;
213 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID);
214 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_SETUID, NULL, 0);
219 exec_changed_cb(void *arg, uint64_t newval)
221 zfsvfs_t *zfsvfs = arg;
223 if (newval == FALSE) {
224 zfsvfs->z_vfs->vfs_flag |= VFS_NOEXEC;
225 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_EXEC);
226 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC, NULL, 0);
228 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOEXEC;
229 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC);
230 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_EXEC, NULL, 0);
235 * The nbmand mount option can be changed at mount time.
236 * We can't allow it to be toggled on live file systems or incorrect
237 * behavior may be seen from cifs clients
239 * This property isn't registered via dsl_prop_register(), but this callback
240 * will be called when a file system is first mounted
243 nbmand_changed_cb(void *arg, uint64_t newval)
245 zfsvfs_t *zfsvfs = arg;
246 if (newval == FALSE) {
247 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND);
248 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND, NULL, 0);
250 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND);
251 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND, NULL, 0);
256 snapdir_changed_cb(void *arg, uint64_t newval)
258 zfsvfs_t *zfsvfs = arg;
260 zfsvfs->z_show_ctldir = newval;
264 vscan_changed_cb(void *arg, uint64_t newval)
266 zfsvfs_t *zfsvfs = arg;
268 zfsvfs->z_vscan = newval;
272 acl_inherit_changed_cb(void *arg, uint64_t newval)
274 zfsvfs_t *zfsvfs = arg;
276 zfsvfs->z_acl_inherit = newval;
280 zfs_register_callbacks(vfs_t *vfsp)
282 struct dsl_dataset *ds = NULL;
284 zfsvfs_t *zfsvfs = NULL;
286 int readonly, do_readonly = B_FALSE;
287 int setuid, do_setuid = B_FALSE;
288 int exec, do_exec = B_FALSE;
289 int devices, do_devices = B_FALSE;
290 int xattr, do_xattr = B_FALSE;
291 int atime, do_atime = B_FALSE;
295 zfsvfs = vfsp->vfs_data;
300 * The act of registering our callbacks will destroy any mount
301 * options we may have. In order to enable temporary overrides
302 * of mount options, we stash away the current values and
303 * restore them after we register the callbacks.
305 if (vfs_optionisset(vfsp, MNTOPT_RO, NULL) ||
306 !spa_writeable(dmu_objset_spa(os))) {
308 do_readonly = B_TRUE;
309 } else if (vfs_optionisset(vfsp, MNTOPT_RW, NULL)) {
311 do_readonly = B_TRUE;
313 if (vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL)) {
319 if (vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL)) {
322 } else if (vfs_optionisset(vfsp, MNTOPT_DEVICES, NULL)) {
327 if (vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL)) {
330 } else if (vfs_optionisset(vfsp, MNTOPT_SETUID, NULL)) {
335 if (vfs_optionisset(vfsp, MNTOPT_NOEXEC, NULL)) {
338 } else if (vfs_optionisset(vfsp, MNTOPT_EXEC, NULL)) {
342 if (vfs_optionisset(vfsp, MNTOPT_NOXATTR, NULL)) {
345 } else if (vfs_optionisset(vfsp, MNTOPT_XATTR, NULL)) {
349 if (vfs_optionisset(vfsp, MNTOPT_NOATIME, NULL)) {
352 } else if (vfs_optionisset(vfsp, MNTOPT_ATIME, NULL)) {
358 * nbmand is a special property. It can only be changed at
361 * This is weird, but it is documented to only be changeable
364 if (vfs_optionisset(vfsp, MNTOPT_NONBMAND, NULL)) {
366 } else if (vfs_optionisset(vfsp, MNTOPT_NBMAND, NULL)) {
369 char osname[MAXNAMELEN];
371 dmu_objset_name(os, osname);
372 if ((error = dsl_prop_get_integer(osname, "nbmand", &nbmand,
379 * Register property callbacks.
381 * It would probably be fine to just check for i/o error from
382 * the first prop_register(), but I guess I like to go
385 ds = dmu_objset_ds(os);
386 error = dsl_prop_register(ds, "atime", atime_changed_cb, zfsvfs);
387 error = error ? error : dsl_prop_register(ds,
388 "xattr", xattr_changed_cb, zfsvfs);
389 error = error ? error : dsl_prop_register(ds,
390 "recordsize", blksz_changed_cb, zfsvfs);
391 error = error ? error : dsl_prop_register(ds,
392 "readonly", readonly_changed_cb, zfsvfs);
393 error = error ? error : dsl_prop_register(ds,
394 "devices", devices_changed_cb, zfsvfs);
395 error = error ? error : dsl_prop_register(ds,
396 "setuid", setuid_changed_cb, zfsvfs);
397 error = error ? error : dsl_prop_register(ds,
398 "exec", exec_changed_cb, zfsvfs);
399 error = error ? error : dsl_prop_register(ds,
400 "snapdir", snapdir_changed_cb, zfsvfs);
401 error = error ? error : dsl_prop_register(ds,
402 "aclinherit", acl_inherit_changed_cb, zfsvfs);
403 error = error ? error : dsl_prop_register(ds,
404 "vscan", vscan_changed_cb, zfsvfs);
409 * Invoke our callbacks to restore temporary mount options.
412 readonly_changed_cb(zfsvfs, readonly);
414 setuid_changed_cb(zfsvfs, setuid);
416 exec_changed_cb(zfsvfs, exec);
418 devices_changed_cb(zfsvfs, devices);
420 xattr_changed_cb(zfsvfs, xattr);
422 atime_changed_cb(zfsvfs, atime);
424 nbmand_changed_cb(zfsvfs, nbmand);
430 * We may attempt to unregister some callbacks that are not
431 * registered, but this is OK; it will simply return ENOMSG,
432 * which we will ignore.
434 (void) dsl_prop_unregister(ds, "atime", atime_changed_cb, zfsvfs);
435 (void) dsl_prop_unregister(ds, "xattr", xattr_changed_cb, zfsvfs);
436 (void) dsl_prop_unregister(ds, "recordsize", blksz_changed_cb, zfsvfs);
437 (void) dsl_prop_unregister(ds, "readonly", readonly_changed_cb, zfsvfs);
438 (void) dsl_prop_unregister(ds, "devices", devices_changed_cb, zfsvfs);
439 (void) dsl_prop_unregister(ds, "setuid", setuid_changed_cb, zfsvfs);
440 (void) dsl_prop_unregister(ds, "exec", exec_changed_cb, zfsvfs);
441 (void) dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb, zfsvfs);
442 (void) dsl_prop_unregister(ds, "aclinherit", acl_inherit_changed_cb,
444 (void) dsl_prop_unregister(ds, "vscan", vscan_changed_cb, zfsvfs);
448 EXPORT_SYMBOL(zfs_register_callbacks);
449 #endif /* HAVE_ZPL */
452 zfs_space_delta_cb(dmu_object_type_t bonustype, void *data,
453 uint64_t *userp, uint64_t *groupp)
455 znode_phys_t *znp = data;
459 * Is it a valid type of object to track?
461 if (bonustype != DMU_OT_ZNODE && bonustype != DMU_OT_SA)
465 * If we have a NULL data pointer
466 * then assume the id's aren't changing and
467 * return EEXIST to the dmu to let it know to
473 if (bonustype == DMU_OT_ZNODE) {
474 *userp = znp->zp_uid;
475 *groupp = znp->zp_gid;
479 ASSERT(bonustype == DMU_OT_SA);
480 hdrsize = sa_hdrsize(data);
483 *userp = *((uint64_t *)((uintptr_t)data + hdrsize +
485 *groupp = *((uint64_t *)((uintptr_t)data + hdrsize +
489 * This should only happen for newly created
490 * files that haven't had the znode data filled
502 fuidstr_to_sid(zfsvfs_t *zfsvfs, const char *fuidstr,
503 char *domainbuf, int buflen, uid_t *ridp)
508 fuid = strtonum(fuidstr, NULL);
510 domain = zfs_fuid_find_by_idx(zfsvfs, FUID_INDEX(fuid));
512 (void) strlcpy(domainbuf, domain, buflen);
515 *ridp = FUID_RID(fuid);
519 zfs_userquota_prop_to_obj(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type)
522 case ZFS_PROP_USERUSED:
523 return (DMU_USERUSED_OBJECT);
524 case ZFS_PROP_GROUPUSED:
525 return (DMU_GROUPUSED_OBJECT);
526 case ZFS_PROP_USERQUOTA:
527 return (zfsvfs->z_userquota_obj);
528 case ZFS_PROP_GROUPQUOTA:
529 return (zfsvfs->z_groupquota_obj);
537 zfs_userspace_many(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
538 uint64_t *cookiep, void *vbuf, uint64_t *bufsizep)
543 zfs_useracct_t *buf = vbuf;
546 if (!dmu_objset_userspace_present(zfsvfs->z_os))
549 obj = zfs_userquota_prop_to_obj(zfsvfs, type);
555 for (zap_cursor_init_serialized(&zc, zfsvfs->z_os, obj, *cookiep);
556 (error = zap_cursor_retrieve(&zc, &za)) == 0;
557 zap_cursor_advance(&zc)) {
558 if ((uintptr_t)buf - (uintptr_t)vbuf + sizeof (zfs_useracct_t) >
562 fuidstr_to_sid(zfsvfs, za.za_name,
563 buf->zu_domain, sizeof (buf->zu_domain), &buf->zu_rid);
565 buf->zu_space = za.za_first_integer;
571 ASSERT3U((uintptr_t)buf - (uintptr_t)vbuf, <=, *bufsizep);
572 *bufsizep = (uintptr_t)buf - (uintptr_t)vbuf;
573 *cookiep = zap_cursor_serialize(&zc);
574 zap_cursor_fini(&zc);
577 EXPORT_SYMBOL(zfs_userspace_many);
580 * buf must be big enough (eg, 32 bytes)
583 id_to_fuidstr(zfsvfs_t *zfsvfs, const char *domain, uid_t rid,
584 char *buf, boolean_t addok)
589 if (domain && domain[0]) {
590 domainid = zfs_fuid_find_by_domain(zfsvfs, domain, NULL, addok);
594 fuid = FUID_ENCODE(domainid, rid);
595 (void) sprintf(buf, "%llx", (longlong_t)fuid);
600 zfs_userspace_one(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
601 const char *domain, uint64_t rid, uint64_t *valp)
609 if (!dmu_objset_userspace_present(zfsvfs->z_os))
612 obj = zfs_userquota_prop_to_obj(zfsvfs, type);
616 err = id_to_fuidstr(zfsvfs, domain, rid, buf, B_FALSE);
620 err = zap_lookup(zfsvfs->z_os, obj, buf, 8, 1, valp);
625 EXPORT_SYMBOL(zfs_userspace_one);
628 zfs_set_userquota(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
629 const char *domain, uint64_t rid, uint64_t quota)
635 boolean_t fuid_dirtied;
637 if (type != ZFS_PROP_USERQUOTA && type != ZFS_PROP_GROUPQUOTA)
640 if (zfsvfs->z_version < ZPL_VERSION_USERSPACE)
643 objp = (type == ZFS_PROP_USERQUOTA) ? &zfsvfs->z_userquota_obj :
644 &zfsvfs->z_groupquota_obj;
646 err = id_to_fuidstr(zfsvfs, domain, rid, buf, B_TRUE);
649 fuid_dirtied = zfsvfs->z_fuid_dirty;
651 tx = dmu_tx_create(zfsvfs->z_os);
652 dmu_tx_hold_zap(tx, *objp ? *objp : DMU_NEW_OBJECT, B_TRUE, NULL);
654 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE,
655 zfs_userquota_prop_prefixes[type]);
658 zfs_fuid_txhold(zfsvfs, tx);
659 err = dmu_tx_assign(tx, TXG_WAIT);
665 mutex_enter(&zfsvfs->z_lock);
667 *objp = zap_create(zfsvfs->z_os, DMU_OT_USERGROUP_QUOTA,
669 VERIFY(0 == zap_add(zfsvfs->z_os, MASTER_NODE_OBJ,
670 zfs_userquota_prop_prefixes[type], 8, 1, objp, tx));
672 mutex_exit(&zfsvfs->z_lock);
675 err = zap_remove(zfsvfs->z_os, *objp, buf, tx);
679 err = zap_update(zfsvfs->z_os, *objp, buf, 8, 1, "a, tx);
683 zfs_fuid_sync(zfsvfs, tx);
687 EXPORT_SYMBOL(zfs_set_userquota);
690 zfs_fuid_overquota(zfsvfs_t *zfsvfs, boolean_t isgroup, uint64_t fuid)
693 uint64_t used, quota, usedobj, quotaobj;
696 usedobj = isgroup ? DMU_GROUPUSED_OBJECT : DMU_USERUSED_OBJECT;
697 quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj;
699 if (quotaobj == 0 || zfsvfs->z_replay)
702 (void) sprintf(buf, "%llx", (longlong_t)fuid);
703 err = zap_lookup(zfsvfs->z_os, quotaobj, buf, 8, 1, "a);
707 err = zap_lookup(zfsvfs->z_os, usedobj, buf, 8, 1, &used);
710 return (used >= quota);
712 EXPORT_SYMBOL(zfs_fuid_overquota);
715 zfs_owner_overquota(zfsvfs_t *zfsvfs, znode_t *zp, boolean_t isgroup)
720 quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj;
722 fuid = isgroup ? zp->z_gid : zp->z_uid;
724 if (quotaobj == 0 || zfsvfs->z_replay)
727 return (zfs_fuid_overquota(zfsvfs, isgroup, fuid));
729 EXPORT_SYMBOL(zfs_owner_overquota);
732 zfsvfs_create(const char *osname, zfsvfs_t **zfvp)
740 zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP);
743 * We claim to always be readonly so we can open snapshots;
744 * other ZPL code will prevent us from writing to snapshots.
746 error = dmu_objset_own(osname, DMU_OST_ZFS, B_TRUE, zfsvfs, &os);
748 kmem_free(zfsvfs, sizeof (zfsvfs_t));
753 * Initialize the zfs-specific filesystem structure.
754 * Should probably make this a kmem cache, shuffle fields,
755 * and just bzero up to z_hold_mtx[].
757 zfsvfs->z_vfs = NULL;
758 zfsvfs->z_parent = zfsvfs;
759 zfsvfs->z_max_blksz = SPA_MAXBLOCKSIZE;
760 zfsvfs->z_show_ctldir = ZFS_SNAPDIR_VISIBLE;
763 error = zfs_get_zplprop(os, ZFS_PROP_VERSION, &zfsvfs->z_version);
766 } else if (zfsvfs->z_version >
767 zfs_zpl_version_map(spa_version(dmu_objset_spa(os)))) {
768 (void) printk("Can't mount a version %lld file system "
769 "on a version %lld pool\n. Pool must be upgraded to mount "
770 "this file system.", (u_longlong_t)zfsvfs->z_version,
771 (u_longlong_t)spa_version(dmu_objset_spa(os)));
775 if ((error = zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &zval)) != 0)
777 zfsvfs->z_norm = (int)zval;
779 if ((error = zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &zval)) != 0)
781 zfsvfs->z_utf8 = (zval != 0);
783 if ((error = zfs_get_zplprop(os, ZFS_PROP_CASE, &zval)) != 0)
785 zfsvfs->z_case = (uint_t)zval;
788 * Fold case on file systems that are always or sometimes case
791 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
792 zfsvfs->z_case == ZFS_CASE_MIXED)
793 zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER;
795 zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
796 zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
798 if (zfsvfs->z_use_sa) {
799 /* should either have both of these objects or none */
800 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SA_ATTRS, 8, 1,
806 * Pre SA versions file systems should never touch
807 * either the attribute registration or layout objects.
812 error = sa_setup(os, sa_obj, zfs_attr_table, ZPL_END,
813 &zfsvfs->z_attr_table);
817 if (zfsvfs->z_version >= ZPL_VERSION_SA)
818 sa_register_update_callback(os, zfs_sa_upgrade);
820 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1,
824 ASSERT(zfsvfs->z_root != 0);
826 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_UNLINKED_SET, 8, 1,
827 &zfsvfs->z_unlinkedobj);
831 error = zap_lookup(os, MASTER_NODE_OBJ,
832 zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA],
833 8, 1, &zfsvfs->z_userquota_obj);
834 if (error && error != ENOENT)
837 error = zap_lookup(os, MASTER_NODE_OBJ,
838 zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA],
839 8, 1, &zfsvfs->z_groupquota_obj);
840 if (error && error != ENOENT)
843 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES, 8, 1,
844 &zfsvfs->z_fuid_obj);
845 if (error && error != ENOENT)
848 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SHARES_DIR, 8, 1,
849 &zfsvfs->z_shares_dir);
850 if (error && error != ENOENT)
853 mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
854 mutex_init(&zfsvfs->z_lock, NULL, MUTEX_DEFAULT, NULL);
855 list_create(&zfsvfs->z_all_znodes, sizeof (znode_t),
856 offsetof(znode_t, z_link_node));
857 rrw_init(&zfsvfs->z_teardown_lock);
858 rw_init(&zfsvfs->z_teardown_inactive_lock, NULL, RW_DEFAULT, NULL);
859 rw_init(&zfsvfs->z_fuid_lock, NULL, RW_DEFAULT, NULL);
860 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
861 mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
867 dmu_objset_disown(os, zfsvfs);
869 kmem_free(zfsvfs, sizeof (zfsvfs_t));
874 zfsvfs_setup(zfsvfs_t *zfsvfs, boolean_t mounting)
878 error = zfs_register_callbacks(zfsvfs->z_vfs);
883 * Set the objset user_ptr to track its zfsvfs.
885 mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
886 dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
887 mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
889 zfsvfs->z_log = zil_open(zfsvfs->z_os, zfs_get_data);
892 * If we are not mounting (ie: online recv), then we don't
893 * have to worry about replaying the log as we blocked all
894 * operations out since we closed the ZIL.
900 * During replay we remove the read only flag to
901 * allow replays to succeed.
903 readonly = zfsvfs->z_vfs->vfs_flag & VFS_RDONLY;
905 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
907 zfs_unlinked_drain(zfsvfs);
910 * Parse and replay the intent log.
912 * Because of ziltest, this must be done after
913 * zfs_unlinked_drain(). (Further note: ziltest
914 * doesn't use readonly mounts, where
915 * zfs_unlinked_drain() isn't called.) This is because
916 * ziltest causes spa_sync() to think it's committed,
917 * but actually it is not, so the intent log contains
918 * many txg's worth of changes.
920 * In particular, if object N is in the unlinked set in
921 * the last txg to actually sync, then it could be
922 * actually freed in a later txg and then reallocated
923 * in a yet later txg. This would write a "create
924 * object N" record to the intent log. Normally, this
925 * would be fine because the spa_sync() would have
926 * written out the fact that object N is free, before
927 * we could write the "create object N" intent log
930 * But when we are in ziltest mode, we advance the "open
931 * txg" without actually spa_sync()-ing the changes to
932 * disk. So we would see that object N is still
933 * allocated and in the unlinked set, and there is an
934 * intent log record saying to allocate it.
936 if (spa_writeable(dmu_objset_spa(zfsvfs->z_os))) {
937 if (zil_replay_disable) {
938 zil_destroy(zfsvfs->z_log, B_FALSE);
940 zfsvfs->z_replay = B_TRUE;
941 zil_replay(zfsvfs->z_os, zfsvfs,
943 zfsvfs->z_replay = B_FALSE;
946 zfsvfs->z_vfs->vfs_flag |= readonly; /* restore readonly bit */
953 zfsvfs_free(zfsvfs_t *zfsvfs)
956 extern krwlock_t zfsvfs_lock; /* in zfs_znode.c */
959 * This is a barrier to prevent the filesystem from going away in
960 * zfs_znode_move() until we can safely ensure that the filesystem is
961 * not unmounted. We consider the filesystem valid before the barrier
962 * and invalid after the barrier.
964 rw_enter(&zfsvfs_lock, RW_READER);
965 rw_exit(&zfsvfs_lock);
967 zfs_fuid_destroy(zfsvfs);
969 mutex_destroy(&zfsvfs->z_znodes_lock);
970 mutex_destroy(&zfsvfs->z_lock);
971 list_destroy(&zfsvfs->z_all_znodes);
972 rrw_destroy(&zfsvfs->z_teardown_lock);
973 rw_destroy(&zfsvfs->z_teardown_inactive_lock);
974 rw_destroy(&zfsvfs->z_fuid_lock);
975 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
976 mutex_destroy(&zfsvfs->z_hold_mtx[i]);
977 kmem_free(zfsvfs, sizeof (zfsvfs_t));
980 #ifdef HAVE_FUID_FEATURES
982 zfs_set_fuid_feature(zfsvfs_t *zfsvfs)
984 zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
985 if (zfsvfs->z_use_fuids && zfsvfs->z_vfs) {
986 vfs_set_feature(zfsvfs->z_vfs, VFSFT_XVATTR);
987 vfs_set_feature(zfsvfs->z_vfs, VFSFT_SYSATTR_VIEWS);
988 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACEMASKONACCESS);
989 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACLONCREATE);
990 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACCESS_FILTER);
991 vfs_set_feature(zfsvfs->z_vfs, VFSFT_REPARSE);
993 zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
995 #endif /* HAVE_FUID_FEATURES */
998 zfs_domount(vfs_t *vfsp, char *osname)
1000 uint64_t recordsize, fsid_guid;
1007 error = zfsvfs_create(osname, &zfsvfs);
1010 zfsvfs->z_vfs = vfsp;
1012 /* Initialize the generic filesystem structure. */
1013 vfsp->vfs_bcount = 0;
1014 vfsp->vfs_data = NULL;
1016 if ((error = dsl_prop_get_integer(osname, "recordsize",
1017 &recordsize, NULL)))
1020 vfsp->vfs_bsize = recordsize;
1021 vfsp->vfs_flag |= VFS_NOTRUNC;
1022 vfsp->vfs_data = zfsvfs;
1025 * The fsid is 64 bits, composed of an 8-bit fs type, which
1026 * separates our fsid from any other filesystem types, and a
1027 * 56-bit objset unique ID. The objset unique ID is unique to
1028 * all objsets open on this system, provided by unique_create().
1029 * The 8-bit fs type must be put in the low bits of fsid[1]
1030 * because that's where other Solaris filesystems put it.
1032 fsid_guid = dmu_objset_fsid_guid(zfsvfs->z_os);
1033 ASSERT((fsid_guid & ~((1ULL<<56)-1)) == 0);
1034 vfsp->vfs_fsid.val[0] = fsid_guid;
1035 vfsp->vfs_fsid.val[1] = ((fsid_guid>>32) << 8);
1037 #ifdef HAVE_FUID_FEATURES
1039 * Set features for file system.
1041 zfs_set_fuid_feature(zfsvfs);
1042 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE) {
1043 vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS);
1044 vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE);
1045 vfs_set_feature(vfsp, VFSFT_NOCASESENSITIVE);
1046 } else if (zfsvfs->z_case == ZFS_CASE_MIXED) {
1047 vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS);
1048 vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE);
1050 vfs_set_feature(vfsp, VFSFT_ZEROCOPY_SUPPORTED);
1051 #endif /* HAVE_FUID_FEATURES */
1053 if (dmu_objset_is_snapshot(zfsvfs->z_os)) {
1056 atime_changed_cb(zfsvfs, B_FALSE);
1057 readonly_changed_cb(zfsvfs, B_TRUE);
1058 if ((error = dsl_prop_get_integer(osname,"xattr",&pval,NULL)))
1060 xattr_changed_cb(zfsvfs, pval);
1061 zfsvfs->z_issnap = B_TRUE;
1062 zfsvfs->z_os->os_sync = ZFS_SYNC_DISABLED;
1064 mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
1065 dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
1066 mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
1068 error = zfsvfs_setup(zfsvfs, B_TRUE);
1071 if (!zfsvfs->z_issnap)
1072 zfsctl_create(zfsvfs);
1075 dmu_objset_disown(zfsvfs->z_os, zfsvfs);
1076 zfsvfs_free(zfsvfs);
1081 EXPORT_SYMBOL(zfs_domount);
1084 zfs_unregister_callbacks(zfsvfs_t *zfsvfs)
1086 objset_t *os = zfsvfs->z_os;
1087 struct dsl_dataset *ds;
1090 * Unregister properties.
1092 if (!dmu_objset_is_snapshot(os)) {
1093 ds = dmu_objset_ds(os);
1094 VERIFY(dsl_prop_unregister(ds, "atime", atime_changed_cb,
1097 VERIFY(dsl_prop_unregister(ds, "xattr", xattr_changed_cb,
1100 VERIFY(dsl_prop_unregister(ds, "recordsize", blksz_changed_cb,
1103 VERIFY(dsl_prop_unregister(ds, "readonly", readonly_changed_cb,
1106 VERIFY(dsl_prop_unregister(ds, "devices", devices_changed_cb,
1109 VERIFY(dsl_prop_unregister(ds, "setuid", setuid_changed_cb,
1112 VERIFY(dsl_prop_unregister(ds, "exec", exec_changed_cb,
1115 VERIFY(dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb,
1118 VERIFY(dsl_prop_unregister(ds, "aclinherit",
1119 acl_inherit_changed_cb, zfsvfs) == 0);
1121 VERIFY(dsl_prop_unregister(ds, "vscan",
1122 vscan_changed_cb, zfsvfs) == 0);
1125 EXPORT_SYMBOL(zfs_unregister_callbacks);
1127 #ifdef HAVE_MLSLABEL
1129 * zfs_check_global_label:
1130 * Check that the hex label string is appropriate for the dataset
1131 * being mounted into the global_zone proper.
1133 * Return an error if the hex label string is not default or
1134 * admin_low/admin_high. For admin_low labels, the corresponding
1135 * dataset must be readonly.
1138 zfs_check_global_label(const char *dsname, const char *hexsl)
1140 if (strcasecmp(hexsl, ZFS_MLSLABEL_DEFAULT) == 0)
1142 if (strcasecmp(hexsl, ADMIN_HIGH) == 0)
1144 if (strcasecmp(hexsl, ADMIN_LOW) == 0) {
1145 /* must be readonly */
1148 if (dsl_prop_get_integer(dsname,
1149 zfs_prop_to_name(ZFS_PROP_READONLY), &rdonly, NULL))
1151 return (rdonly ? 0 : EACCES);
1155 #endif /* HAVE_MLSLABEL */
1158 zfs_statvfs(vfs_t *vfsp, struct statvfs64 *statp)
1160 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1162 uint64_t refdbytes, availbytes, usedobjs, availobjs;
1166 dmu_objset_space(zfsvfs->z_os,
1167 &refdbytes, &availbytes, &usedobjs, &availobjs);
1170 * The underlying storage pool actually uses multiple block sizes.
1171 * We report the fragsize as the smallest block size we support,
1172 * and we report our blocksize as the filesystem's maximum blocksize.
1174 statp->f_frsize = 1UL << SPA_MINBLOCKSHIFT;
1175 statp->f_bsize = zfsvfs->z_max_blksz;
1178 * The following report "total" blocks of various kinds in the
1179 * file system, but reported in terms of f_frsize - the
1183 statp->f_blocks = (refdbytes + availbytes) >> SPA_MINBLOCKSHIFT;
1184 statp->f_bfree = availbytes >> SPA_MINBLOCKSHIFT;
1185 statp->f_bavail = statp->f_bfree; /* no root reservation */
1188 * statvfs() should really be called statufs(), because it assumes
1189 * static metadata. ZFS doesn't preallocate files, so the best
1190 * we can do is report the max that could possibly fit in f_files,
1191 * and that minus the number actually used in f_ffree.
1192 * For f_ffree, report the smaller of the number of object available
1193 * and the number of blocks (each object will take at least a block).
1195 statp->f_ffree = MIN(availobjs, statp->f_bfree);
1196 statp->f_favail = statp->f_ffree; /* no "root reservation" */
1197 statp->f_files = statp->f_ffree + usedobjs;
1199 (void) cmpldev(&d32, vfsp->vfs_dev);
1200 statp->f_fsid = d32;
1203 * We're a zfs filesystem.
1205 (void) strcpy(statp->f_basetype, MNTTYPE_ZFS);
1207 statp->f_flag = vf_to_stf(vfsp->vfs_flag);
1209 statp->f_namemax = ZFS_MAXNAMELEN;
1212 * We have all of 32 characters to stuff a string here.
1213 * Is there anything useful we could/should provide?
1215 bzero(statp->f_fstr, sizeof (statp->f_fstr));
1220 EXPORT_SYMBOL(zfs_statvfs);
1223 zfs_root(vfs_t *vfsp, vnode_t **vpp)
1225 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1231 error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp);
1233 *vpp = ZTOV(rootzp);
1238 EXPORT_SYMBOL(zfs_root);
1241 * Teardown the zfsvfs::z_os.
1243 * Note, if 'unmounting' if FALSE, we return with the 'z_teardown_lock'
1244 * and 'z_teardown_inactive_lock' held.
1247 zfsvfs_teardown(zfsvfs_t *zfsvfs, boolean_t unmounting)
1251 rrw_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG);
1255 * We purge the parent filesystem's vfsp as the parent
1256 * filesystem and all of its snapshots have their vnode's
1257 * v_vfsp set to the parent's filesystem's vfsp. Note,
1258 * 'z_parent' is self referential for non-snapshots.
1260 (void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0);
1264 * Close the zil. NB: Can't close the zil while zfs_inactive
1265 * threads are blocked as zil_close can call zfs_inactive.
1267 if (zfsvfs->z_log) {
1268 zil_close(zfsvfs->z_log);
1269 zfsvfs->z_log = NULL;
1272 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_WRITER);
1275 * If we are not unmounting (ie: online recv) and someone already
1276 * unmounted this file system while we were doing the switcheroo,
1277 * or a reopen of z_os failed then just bail out now.
1279 if (!unmounting && (zfsvfs->z_unmounted || zfsvfs->z_os == NULL)) {
1280 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1281 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
1286 * At this point there are no vops active, and any new vops will
1287 * fail with EIO since we have z_teardown_lock for writer (only
1288 * relavent for forced unmount).
1290 * Release all holds on dbufs.
1292 mutex_enter(&zfsvfs->z_znodes_lock);
1293 for (zp = list_head(&zfsvfs->z_all_znodes); zp != NULL;
1294 zp = list_next(&zfsvfs->z_all_znodes, zp))
1296 ASSERT(ZTOV(zp)->v_count > 0);
1297 zfs_znode_dmu_fini(zp);
1299 mutex_exit(&zfsvfs->z_znodes_lock);
1302 * If we are unmounting, set the unmounted flag and let new vops
1303 * unblock. zfs_inactive will have the unmounted behavior, and all
1304 * other vops will fail with EIO.
1307 zfsvfs->z_unmounted = B_TRUE;
1308 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
1309 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1313 * z_os will be NULL if there was an error in attempting to reopen
1314 * zfsvfs, so just return as the properties had already been
1315 * unregistered and cached data had been evicted before.
1317 if (zfsvfs->z_os == NULL)
1321 * Unregister properties.
1323 zfs_unregister_callbacks(zfsvfs);
1328 if (dmu_objset_is_dirty_anywhere(zfsvfs->z_os))
1329 if (!(zfsvfs->z_vfs->vfs_flag & VFS_RDONLY))
1330 txg_wait_synced(dmu_objset_pool(zfsvfs->z_os), 0);
1331 (void) dmu_objset_evict_dbufs(zfsvfs->z_os);
1338 zfs_umount(vfs_t *vfsp, int fflag, cred_t *cr)
1340 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1344 ret = secpolicy_fs_unmount(cr, vfsp);
1346 if (dsl_deleg_access((char *)refstr_value(vfsp->vfs_resource),
1347 ZFS_DELEG_PERM_MOUNT, cr))
1352 * We purge the parent filesystem's vfsp as the parent filesystem
1353 * and all of its snapshots have their vnode's v_vfsp set to the
1354 * parent's filesystem's vfsp. Note, 'z_parent' is self
1355 * referential for non-snapshots.
1357 (void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0);
1360 * Unmount any snapshots mounted under .zfs before unmounting the
1363 if (zfsvfs->z_ctldir != NULL &&
1364 (ret = zfsctl_umount_snapshots(vfsp, fflag, cr)) != 0) {
1368 if (!(fflag & MS_FORCE)) {
1370 * Check the number of active vnodes in the file system.
1371 * Our count is maintained in the vfs structure, but the
1372 * number is off by 1 to indicate a hold on the vfs
1375 * The '.zfs' directory maintains a reference of its
1376 * own, and any active references underneath are
1377 * reflected in the vnode count.
1379 if (zfsvfs->z_ctldir == NULL) {
1380 if (vfsp->vfs_count > 1)
1383 if (vfsp->vfs_count > 2 ||
1384 zfsvfs->z_ctldir->v_count > 1)
1389 vfsp->vfs_flag |= VFS_UNMOUNTED;
1391 VERIFY(zfsvfs_teardown(zfsvfs, B_TRUE) == 0);
1395 * z_os will be NULL if there was an error in
1396 * attempting to reopen zfsvfs.
1400 * Unset the objset user_ptr.
1402 mutex_enter(&os->os_user_ptr_lock);
1403 dmu_objset_set_user(os, NULL);
1404 mutex_exit(&os->os_user_ptr_lock);
1407 * Finally release the objset
1409 dmu_objset_disown(os, zfsvfs);
1413 * We can now safely destroy the '.zfs' directory node.
1415 if (zfsvfs->z_ctldir != NULL)
1416 zfsctl_destroy(zfsvfs);
1420 EXPORT_SYMBOL(zfs_umount);
1423 zfs_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp)
1425 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1427 uint64_t object = 0;
1428 uint64_t fid_gen = 0;
1437 if (fidp->fid_len == LONG_FID_LEN) {
1438 zfid_long_t *zlfid = (zfid_long_t *)fidp;
1439 uint64_t objsetid = 0;
1440 uint64_t setgen = 0;
1442 for (i = 0; i < sizeof (zlfid->zf_setid); i++)
1443 objsetid |= ((uint64_t)zlfid->zf_setid[i]) << (8 * i);
1445 for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
1446 setgen |= ((uint64_t)zlfid->zf_setgen[i]) << (8 * i);
1450 err = zfsctl_lookup_objset(vfsp, objsetid, &zfsvfs);
1456 if (fidp->fid_len == SHORT_FID_LEN || fidp->fid_len == LONG_FID_LEN) {
1457 zfid_short_t *zfid = (zfid_short_t *)fidp;
1459 for (i = 0; i < sizeof (zfid->zf_object); i++)
1460 object |= ((uint64_t)zfid->zf_object[i]) << (8 * i);
1462 for (i = 0; i < sizeof (zfid->zf_gen); i++)
1463 fid_gen |= ((uint64_t)zfid->zf_gen[i]) << (8 * i);
1469 /* A zero fid_gen means we are in the .zfs control directories */
1471 (object == ZFSCTL_INO_ROOT || object == ZFSCTL_INO_SNAPDIR)) {
1472 *vpp = zfsvfs->z_ctldir;
1473 ASSERT(*vpp != NULL);
1474 if (object == ZFSCTL_INO_SNAPDIR) {
1475 VERIFY(zfsctl_root_lookup(*vpp, "snapshot", vpp, NULL,
1476 0, NULL, NULL, NULL, NULL, NULL) == 0);
1484 gen_mask = -1ULL >> (64 - 8 * i);
1486 dprintf("getting %llu [%u mask %llx]\n", object, fid_gen, gen_mask);
1487 if ((err = zfs_zget(zfsvfs, object, &zp))) {
1491 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zfsvfs), &zp_gen,
1493 zp_gen = zp_gen & gen_mask;
1496 if (zp->z_unlinked || zp_gen != fid_gen) {
1497 dprintf("znode gen (%u) != fid gen (%u)\n", zp_gen, fid_gen);
1505 zfs_inode_update(VTOZ(*vpp));
1510 EXPORT_SYMBOL(zfs_vget);
1513 * Block out VOPs and close zfsvfs_t::z_os
1515 * Note, if successful, then we return with the 'z_teardown_lock' and
1516 * 'z_teardown_inactive_lock' write held.
1519 zfs_suspend_fs(zfsvfs_t *zfsvfs)
1523 if ((error = zfsvfs_teardown(zfsvfs, B_FALSE)) != 0)
1525 dmu_objset_disown(zfsvfs->z_os, zfsvfs);
1529 EXPORT_SYMBOL(zfs_suspend_fs);
1532 * Reopen zfsvfs_t::z_os and release VOPs.
1535 zfs_resume_fs(zfsvfs_t *zfsvfs, const char *osname)
1539 ASSERT(RRW_WRITE_HELD(&zfsvfs->z_teardown_lock));
1540 ASSERT(RW_WRITE_HELD(&zfsvfs->z_teardown_inactive_lock));
1542 err = dmu_objset_own(osname, DMU_OST_ZFS, B_FALSE, zfsvfs,
1545 zfsvfs->z_os = NULL;
1548 uint64_t sa_obj = 0;
1550 err2 = zap_lookup(zfsvfs->z_os, MASTER_NODE_OBJ,
1551 ZFS_SA_ATTRS, 8, 1, &sa_obj);
1553 if ((err || err2) && zfsvfs->z_version >= ZPL_VERSION_SA)
1557 if ((err = sa_setup(zfsvfs->z_os, sa_obj,
1558 zfs_attr_table, ZPL_END, &zfsvfs->z_attr_table)) != 0)
1561 VERIFY(zfsvfs_setup(zfsvfs, B_FALSE) == 0);
1564 * Attempt to re-establish all the active znodes with
1565 * their dbufs. If a zfs_rezget() fails, then we'll let
1566 * any potential callers discover that via ZFS_ENTER_VERIFY_VP
1567 * when they try to use their znode.
1569 mutex_enter(&zfsvfs->z_znodes_lock);
1570 for (zp = list_head(&zfsvfs->z_all_znodes); zp;
1571 zp = list_next(&zfsvfs->z_all_znodes, zp)) {
1572 (void) zfs_rezget(zp);
1574 mutex_exit(&zfsvfs->z_znodes_lock);
1579 /* release the VOPs */
1580 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1581 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
1585 * Since we couldn't reopen zfsvfs::z_os, force
1586 * unmount this file system.
1588 if (vn_vfswlock(zfsvfs->z_vfs->vfs_vnodecovered) == 0)
1589 (void) dounmount(zfsvfs->z_vfs, MS_FORCE, CRED());
1593 EXPORT_SYMBOL(zfs_resume_fs);
1596 zfs_freevfs(vfs_t *vfsp)
1598 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1600 zfsvfs_free(zfsvfs);
1602 #endif /* HAVE_ZPL */
1610 dmu_objset_register_type(DMU_OST_ZFS, zfs_space_delta_cb);
1622 zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers)
1625 objset_t *os = zfsvfs->z_os;
1628 if (newvers < ZPL_VERSION_INITIAL || newvers > ZPL_VERSION)
1631 if (newvers < zfsvfs->z_version)
1634 if (zfs_spa_version_map(newvers) >
1635 spa_version(dmu_objset_spa(zfsvfs->z_os)))
1638 tx = dmu_tx_create(os);
1639 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_FALSE, ZPL_VERSION_STR);
1640 if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
1641 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE,
1643 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
1645 error = dmu_tx_assign(tx, TXG_WAIT);
1651 error = zap_update(os, MASTER_NODE_OBJ, ZPL_VERSION_STR,
1652 8, 1, &newvers, tx);
1659 if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
1662 ASSERT3U(spa_version(dmu_objset_spa(zfsvfs->z_os)), >=,
1664 sa_obj = zap_create(os, DMU_OT_SA_MASTER_NODE,
1665 DMU_OT_NONE, 0, tx);
1667 error = zap_add(os, MASTER_NODE_OBJ,
1668 ZFS_SA_ATTRS, 8, 1, &sa_obj, tx);
1669 ASSERT3U(error, ==, 0);
1671 VERIFY(0 == sa_set_sa_object(os, sa_obj));
1672 sa_register_update_callback(os, zfs_sa_upgrade);
1675 spa_history_log_internal(LOG_DS_UPGRADE,
1676 dmu_objset_spa(os), tx, "oldver=%llu newver=%llu dataset = %llu",
1677 zfsvfs->z_version, newvers, dmu_objset_id(os));
1681 zfsvfs->z_version = newvers;
1683 #ifdef HAVE_FUID_FEATURES
1684 if (zfsvfs->z_version >= ZPL_VERSION_FUID)
1685 zfs_set_fuid_feature(zfsvfs);
1686 #endif /* HAVE_FUID_FEATURES */
1690 EXPORT_SYMBOL(zfs_set_version);
1691 #endif /* HAVE_ZPL */
1694 * Read a property stored within the master node.
1697 zfs_get_zplprop(objset_t *os, zfs_prop_t prop, uint64_t *value)
1703 * Look up the file system's value for the property. For the
1704 * version property, we look up a slightly different string.
1706 if (prop == ZFS_PROP_VERSION)
1707 pname = ZPL_VERSION_STR;
1709 pname = zfs_prop_to_name(prop);
1712 error = zap_lookup(os, MASTER_NODE_OBJ, pname, 8, 1, value);
1714 if (error == ENOENT) {
1715 /* No value set, use the default value */
1717 case ZFS_PROP_VERSION:
1718 *value = ZPL_VERSION;
1720 case ZFS_PROP_NORMALIZE:
1721 case ZFS_PROP_UTF8ONLY:
1725 *value = ZFS_CASE_SENSITIVE;