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_ctldir.h>
59 #include <sys/zfs_fuid.h>
60 #include <sys/bootconf.h>
61 #include <sys/sunddi.h>
63 #include <sys/dmu_objset.h>
64 #include <sys/spa_boot.h>
66 #include "zfs_comutil.h"
72 zfs_sync(vfs_t *vfsp, short flag, cred_t *cr)
75 * Data integrity is job one. We don't want a compromised kernel
76 * writing to the storage pool, so we never sync during panic.
83 * Sync a specific filesystem.
85 zfsvfs_t *zfsvfs = vfsp->vfs_data;
89 dp = dmu_objset_pool(zfsvfs->z_os);
93 * If the system is shutting down, then skip any
94 * filesystems which may exist on a suspended pool.
96 * XXX: This can be implemented using the Linux reboot
97 * notifiers: {un}register_reboot_notifier().
99 if (sys_shutdown && spa_suspended(dp->dp_spa)) {
103 #endif /* HAVE_SHUTDOWN */
105 if (zfsvfs->z_log != NULL)
106 zil_commit(zfsvfs->z_log, 0);
111 * Sync all ZFS filesystems. This is what happens when you
112 * run sync(1M). Unlike other filesystems, ZFS honors the
113 * request by waiting for all pools to commit all dirty data.
120 EXPORT_SYMBOL(zfs_sync);
123 atime_changed_cb(void *arg, uint64_t newval)
125 zfsvfs_t *zfsvfs = arg;
127 if (newval == TRUE) {
128 zfsvfs->z_atime = TRUE;
129 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME);
130 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_ATIME, NULL, 0);
132 zfsvfs->z_atime = FALSE;
133 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_ATIME);
134 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME, NULL, 0);
139 xattr_changed_cb(void *arg, uint64_t newval)
141 zfsvfs_t *zfsvfs = arg;
143 if (newval == TRUE) {
144 /* XXX locking on vfs_flag? */
145 zfsvfs->z_vfs->vfs_flag |= VFS_XATTR;
146 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR);
147 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_XATTR, NULL, 0);
149 /* XXX locking on vfs_flag? */
150 zfsvfs->z_vfs->vfs_flag &= ~VFS_XATTR;
151 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_XATTR);
152 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR, NULL, 0);
157 blksz_changed_cb(void *arg, uint64_t newval)
159 zfsvfs_t *zfsvfs = arg;
161 if (newval < SPA_MINBLOCKSIZE ||
162 newval > SPA_MAXBLOCKSIZE || !ISP2(newval))
163 newval = SPA_MAXBLOCKSIZE;
165 zfsvfs->z_max_blksz = newval;
166 zfsvfs->z_vfs->vfs_bsize = newval;
170 readonly_changed_cb(void *arg, uint64_t newval)
172 zfsvfs_t *zfsvfs = arg;
175 /* XXX locking on vfs_flag? */
176 zfsvfs->z_vfs->vfs_flag |= VFS_RDONLY;
177 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RW);
178 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RO, NULL, 0);
180 /* XXX locking on vfs_flag? */
181 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
182 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RO);
183 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RW, NULL, 0);
188 devices_changed_cb(void *arg, uint64_t newval)
190 zfsvfs_t *zfsvfs = arg;
192 if (newval == FALSE) {
193 zfsvfs->z_vfs->vfs_flag |= VFS_NODEVICES;
194 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES);
195 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES, NULL, 0);
197 zfsvfs->z_vfs->vfs_flag &= ~VFS_NODEVICES;
198 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES);
199 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES, NULL, 0);
204 setuid_changed_cb(void *arg, uint64_t newval)
206 zfsvfs_t *zfsvfs = arg;
208 if (newval == FALSE) {
209 zfsvfs->z_vfs->vfs_flag |= VFS_NOSETUID;
210 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_SETUID);
211 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID, NULL, 0);
213 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOSETUID;
214 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID);
215 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_SETUID, NULL, 0);
220 exec_changed_cb(void *arg, uint64_t newval)
222 zfsvfs_t *zfsvfs = arg;
224 if (newval == FALSE) {
225 zfsvfs->z_vfs->vfs_flag |= VFS_NOEXEC;
226 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_EXEC);
227 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC, NULL, 0);
229 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOEXEC;
230 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC);
231 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_EXEC, NULL, 0);
236 * The nbmand mount option can be changed at mount time.
237 * We can't allow it to be toggled on live file systems or incorrect
238 * behavior may be seen from cifs clients
240 * This property isn't registered via dsl_prop_register(), but this callback
241 * will be called when a file system is first mounted
244 nbmand_changed_cb(void *arg, uint64_t newval)
246 zfsvfs_t *zfsvfs = arg;
247 if (newval == FALSE) {
248 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND);
249 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND, NULL, 0);
251 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND);
252 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND, NULL, 0);
257 snapdir_changed_cb(void *arg, uint64_t newval)
259 zfsvfs_t *zfsvfs = arg;
261 zfsvfs->z_show_ctldir = newval;
265 vscan_changed_cb(void *arg, uint64_t newval)
267 zfsvfs_t *zfsvfs = arg;
269 zfsvfs->z_vscan = newval;
273 acl_inherit_changed_cb(void *arg, uint64_t newval)
275 zfsvfs_t *zfsvfs = arg;
277 zfsvfs->z_acl_inherit = newval;
281 zfs_register_callbacks(vfs_t *vfsp)
283 struct dsl_dataset *ds = NULL;
285 zfsvfs_t *zfsvfs = NULL;
287 int readonly, do_readonly = B_FALSE;
288 int setuid, do_setuid = B_FALSE;
289 int exec, do_exec = B_FALSE;
290 int devices, do_devices = B_FALSE;
291 int xattr, do_xattr = B_FALSE;
292 int atime, do_atime = B_FALSE;
296 zfsvfs = vfsp->vfs_data;
301 * The act of registering our callbacks will destroy any mount
302 * options we may have. In order to enable temporary overrides
303 * of mount options, we stash away the current values and
304 * restore them after we register the callbacks.
306 if (vfs_optionisset(vfsp, MNTOPT_RO, NULL) ||
307 !spa_writeable(dmu_objset_spa(os))) {
309 do_readonly = B_TRUE;
310 } else if (vfs_optionisset(vfsp, MNTOPT_RW, NULL)) {
312 do_readonly = B_TRUE;
314 if (vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL)) {
320 if (vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL)) {
323 } else if (vfs_optionisset(vfsp, MNTOPT_DEVICES, NULL)) {
328 if (vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL)) {
331 } else if (vfs_optionisset(vfsp, MNTOPT_SETUID, NULL)) {
336 if (vfs_optionisset(vfsp, MNTOPT_NOEXEC, NULL)) {
339 } else if (vfs_optionisset(vfsp, MNTOPT_EXEC, NULL)) {
343 if (vfs_optionisset(vfsp, MNTOPT_NOXATTR, NULL)) {
346 } else if (vfs_optionisset(vfsp, MNTOPT_XATTR, NULL)) {
350 if (vfs_optionisset(vfsp, MNTOPT_NOATIME, NULL)) {
353 } else if (vfs_optionisset(vfsp, MNTOPT_ATIME, NULL)) {
359 * nbmand is a special property. It can only be changed at
362 * This is weird, but it is documented to only be changeable
365 if (vfs_optionisset(vfsp, MNTOPT_NONBMAND, NULL)) {
367 } else if (vfs_optionisset(vfsp, MNTOPT_NBMAND, NULL)) {
370 char osname[MAXNAMELEN];
372 dmu_objset_name(os, osname);
373 if ((error = dsl_prop_get_integer(osname, "nbmand", &nbmand,
380 * Register property callbacks.
382 * It would probably be fine to just check for i/o error from
383 * the first prop_register(), but I guess I like to go
386 ds = dmu_objset_ds(os);
387 error = dsl_prop_register(ds, "atime", atime_changed_cb, zfsvfs);
388 error = error ? error : dsl_prop_register(ds,
389 "xattr", xattr_changed_cb, zfsvfs);
390 error = error ? error : dsl_prop_register(ds,
391 "recordsize", blksz_changed_cb, zfsvfs);
392 error = error ? error : dsl_prop_register(ds,
393 "readonly", readonly_changed_cb, zfsvfs);
394 error = error ? error : dsl_prop_register(ds,
395 "devices", devices_changed_cb, zfsvfs);
396 error = error ? error : dsl_prop_register(ds,
397 "setuid", setuid_changed_cb, zfsvfs);
398 error = error ? error : dsl_prop_register(ds,
399 "exec", exec_changed_cb, zfsvfs);
400 error = error ? error : dsl_prop_register(ds,
401 "snapdir", snapdir_changed_cb, zfsvfs);
402 error = error ? error : dsl_prop_register(ds,
403 "aclinherit", acl_inherit_changed_cb, zfsvfs);
404 error = error ? error : dsl_prop_register(ds,
405 "vscan", vscan_changed_cb, zfsvfs);
410 * Invoke our callbacks to restore temporary mount options.
413 readonly_changed_cb(zfsvfs, readonly);
415 setuid_changed_cb(zfsvfs, setuid);
417 exec_changed_cb(zfsvfs, exec);
419 devices_changed_cb(zfsvfs, devices);
421 xattr_changed_cb(zfsvfs, xattr);
423 atime_changed_cb(zfsvfs, atime);
425 nbmand_changed_cb(zfsvfs, nbmand);
431 * We may attempt to unregister some callbacks that are not
432 * registered, but this is OK; it will simply return ENOMSG,
433 * which we will ignore.
435 (void) dsl_prop_unregister(ds, "atime", atime_changed_cb, zfsvfs);
436 (void) dsl_prop_unregister(ds, "xattr", xattr_changed_cb, zfsvfs);
437 (void) dsl_prop_unregister(ds, "recordsize", blksz_changed_cb, zfsvfs);
438 (void) dsl_prop_unregister(ds, "readonly", readonly_changed_cb, zfsvfs);
439 (void) dsl_prop_unregister(ds, "devices", devices_changed_cb, zfsvfs);
440 (void) dsl_prop_unregister(ds, "setuid", setuid_changed_cb, zfsvfs);
441 (void) dsl_prop_unregister(ds, "exec", exec_changed_cb, zfsvfs);
442 (void) dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb, zfsvfs);
443 (void) dsl_prop_unregister(ds, "aclinherit", acl_inherit_changed_cb,
445 (void) dsl_prop_unregister(ds, "vscan", vscan_changed_cb, zfsvfs);
449 EXPORT_SYMBOL(zfs_register_callbacks);
450 #endif /* HAVE_ZPL */
453 zfs_space_delta_cb(dmu_object_type_t bonustype, void *data,
454 uint64_t *userp, uint64_t *groupp)
456 znode_phys_t *znp = data;
460 * Is it a valid type of object to track?
462 if (bonustype != DMU_OT_ZNODE && bonustype != DMU_OT_SA)
466 * If we have a NULL data pointer
467 * then assume the id's aren't changing and
468 * return EEXIST to the dmu to let it know to
474 if (bonustype == DMU_OT_ZNODE) {
475 *userp = znp->zp_uid;
476 *groupp = znp->zp_gid;
480 ASSERT(bonustype == DMU_OT_SA);
481 hdrsize = sa_hdrsize(data);
484 *userp = *((uint64_t *)((uintptr_t)data + hdrsize +
486 *groupp = *((uint64_t *)((uintptr_t)data + hdrsize +
490 * This should only happen for newly created
491 * files that haven't had the znode data filled
503 fuidstr_to_sid(zfsvfs_t *zfsvfs, const char *fuidstr,
504 char *domainbuf, int buflen, uid_t *ridp)
509 fuid = strtonum(fuidstr, NULL);
511 domain = zfs_fuid_find_by_idx(zfsvfs, FUID_INDEX(fuid));
513 (void) strlcpy(domainbuf, domain, buflen);
516 *ridp = FUID_RID(fuid);
520 zfs_userquota_prop_to_obj(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type)
523 case ZFS_PROP_USERUSED:
524 return (DMU_USERUSED_OBJECT);
525 case ZFS_PROP_GROUPUSED:
526 return (DMU_GROUPUSED_OBJECT);
527 case ZFS_PROP_USERQUOTA:
528 return (zfsvfs->z_userquota_obj);
529 case ZFS_PROP_GROUPQUOTA:
530 return (zfsvfs->z_groupquota_obj);
538 zfs_userspace_many(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
539 uint64_t *cookiep, void *vbuf, uint64_t *bufsizep)
544 zfs_useracct_t *buf = vbuf;
547 if (!dmu_objset_userspace_present(zfsvfs->z_os))
550 obj = zfs_userquota_prop_to_obj(zfsvfs, type);
556 for (zap_cursor_init_serialized(&zc, zfsvfs->z_os, obj, *cookiep);
557 (error = zap_cursor_retrieve(&zc, &za)) == 0;
558 zap_cursor_advance(&zc)) {
559 if ((uintptr_t)buf - (uintptr_t)vbuf + sizeof (zfs_useracct_t) >
563 fuidstr_to_sid(zfsvfs, za.za_name,
564 buf->zu_domain, sizeof (buf->zu_domain), &buf->zu_rid);
566 buf->zu_space = za.za_first_integer;
572 ASSERT3U((uintptr_t)buf - (uintptr_t)vbuf, <=, *bufsizep);
573 *bufsizep = (uintptr_t)buf - (uintptr_t)vbuf;
574 *cookiep = zap_cursor_serialize(&zc);
575 zap_cursor_fini(&zc);
578 EXPORT_SYMBOL(zfs_userspace_many);
581 * buf must be big enough (eg, 32 bytes)
584 id_to_fuidstr(zfsvfs_t *zfsvfs, const char *domain, uid_t rid,
585 char *buf, boolean_t addok)
590 if (domain && domain[0]) {
591 domainid = zfs_fuid_find_by_domain(zfsvfs, domain, NULL, addok);
595 fuid = FUID_ENCODE(domainid, rid);
596 (void) sprintf(buf, "%llx", (longlong_t)fuid);
601 zfs_userspace_one(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
602 const char *domain, uint64_t rid, uint64_t *valp)
610 if (!dmu_objset_userspace_present(zfsvfs->z_os))
613 obj = zfs_userquota_prop_to_obj(zfsvfs, type);
617 err = id_to_fuidstr(zfsvfs, domain, rid, buf, B_FALSE);
621 err = zap_lookup(zfsvfs->z_os, obj, buf, 8, 1, valp);
626 EXPORT_SYMBOL(zfs_userspace_one);
629 zfs_set_userquota(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
630 const char *domain, uint64_t rid, uint64_t quota)
636 boolean_t fuid_dirtied;
638 if (type != ZFS_PROP_USERQUOTA && type != ZFS_PROP_GROUPQUOTA)
641 if (zfsvfs->z_version < ZPL_VERSION_USERSPACE)
644 objp = (type == ZFS_PROP_USERQUOTA) ? &zfsvfs->z_userquota_obj :
645 &zfsvfs->z_groupquota_obj;
647 err = id_to_fuidstr(zfsvfs, domain, rid, buf, B_TRUE);
650 fuid_dirtied = zfsvfs->z_fuid_dirty;
652 tx = dmu_tx_create(zfsvfs->z_os);
653 dmu_tx_hold_zap(tx, *objp ? *objp : DMU_NEW_OBJECT, B_TRUE, NULL);
655 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE,
656 zfs_userquota_prop_prefixes[type]);
659 zfs_fuid_txhold(zfsvfs, tx);
660 err = dmu_tx_assign(tx, TXG_WAIT);
666 mutex_enter(&zfsvfs->z_lock);
668 *objp = zap_create(zfsvfs->z_os, DMU_OT_USERGROUP_QUOTA,
670 VERIFY(0 == zap_add(zfsvfs->z_os, MASTER_NODE_OBJ,
671 zfs_userquota_prop_prefixes[type], 8, 1, objp, tx));
673 mutex_exit(&zfsvfs->z_lock);
676 err = zap_remove(zfsvfs->z_os, *objp, buf, tx);
680 err = zap_update(zfsvfs->z_os, *objp, buf, 8, 1, "a, tx);
684 zfs_fuid_sync(zfsvfs, tx);
688 EXPORT_SYMBOL(zfs_set_userquota);
691 zfs_fuid_overquota(zfsvfs_t *zfsvfs, boolean_t isgroup, uint64_t fuid)
694 uint64_t used, quota, usedobj, quotaobj;
697 usedobj = isgroup ? DMU_GROUPUSED_OBJECT : DMU_USERUSED_OBJECT;
698 quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj;
700 if (quotaobj == 0 || zfsvfs->z_replay)
703 (void) sprintf(buf, "%llx", (longlong_t)fuid);
704 err = zap_lookup(zfsvfs->z_os, quotaobj, buf, 8, 1, "a);
708 err = zap_lookup(zfsvfs->z_os, usedobj, buf, 8, 1, &used);
711 return (used >= quota);
713 EXPORT_SYMBOL(zfs_fuid_overquota);
716 zfs_owner_overquota(zfsvfs_t *zfsvfs, znode_t *zp, boolean_t isgroup)
721 quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj;
723 fuid = isgroup ? zp->z_gid : zp->z_uid;
725 if (quotaobj == 0 || zfsvfs->z_replay)
728 return (zfs_fuid_overquota(zfsvfs, isgroup, fuid));
730 EXPORT_SYMBOL(zfs_owner_overquota);
733 zfsvfs_create(const char *osname, zfsvfs_t **zfvp)
741 zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP);
744 * We claim to always be readonly so we can open snapshots;
745 * other ZPL code will prevent us from writing to snapshots.
747 error = dmu_objset_own(osname, DMU_OST_ZFS, B_TRUE, zfsvfs, &os);
749 kmem_free(zfsvfs, sizeof (zfsvfs_t));
754 * Initialize the zfs-specific filesystem structure.
755 * Should probably make this a kmem cache, shuffle fields,
756 * and just bzero up to z_hold_mtx[].
758 zfsvfs->z_vfs = NULL;
759 zfsvfs->z_parent = zfsvfs;
760 zfsvfs->z_max_blksz = SPA_MAXBLOCKSIZE;
761 zfsvfs->z_show_ctldir = ZFS_SNAPDIR_VISIBLE;
764 error = zfs_get_zplprop(os, ZFS_PROP_VERSION, &zfsvfs->z_version);
767 } else if (zfsvfs->z_version >
768 zfs_zpl_version_map(spa_version(dmu_objset_spa(os)))) {
769 (void) printk("Can't mount a version %lld file system "
770 "on a version %lld pool\n. Pool must be upgraded to mount "
771 "this file system.", (u_longlong_t)zfsvfs->z_version,
772 (u_longlong_t)spa_version(dmu_objset_spa(os)));
776 if ((error = zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &zval)) != 0)
778 zfsvfs->z_norm = (int)zval;
780 if ((error = zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &zval)) != 0)
782 zfsvfs->z_utf8 = (zval != 0);
784 if ((error = zfs_get_zplprop(os, ZFS_PROP_CASE, &zval)) != 0)
786 zfsvfs->z_case = (uint_t)zval;
789 * Fold case on file systems that are always or sometimes case
792 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
793 zfsvfs->z_case == ZFS_CASE_MIXED)
794 zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER;
796 zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
797 zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
799 if (zfsvfs->z_use_sa) {
800 /* should either have both of these objects or none */
801 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SA_ATTRS, 8, 1,
807 * Pre SA versions file systems should never touch
808 * either the attribute registration or layout objects.
813 error = sa_setup(os, sa_obj, zfs_attr_table, ZPL_END,
814 &zfsvfs->z_attr_table);
818 if (zfsvfs->z_version >= ZPL_VERSION_SA)
819 sa_register_update_callback(os, zfs_sa_upgrade);
821 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1,
825 ASSERT(zfsvfs->z_root != 0);
827 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_UNLINKED_SET, 8, 1,
828 &zfsvfs->z_unlinkedobj);
832 error = zap_lookup(os, MASTER_NODE_OBJ,
833 zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA],
834 8, 1, &zfsvfs->z_userquota_obj);
835 if (error && error != ENOENT)
838 error = zap_lookup(os, MASTER_NODE_OBJ,
839 zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA],
840 8, 1, &zfsvfs->z_groupquota_obj);
841 if (error && error != ENOENT)
844 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES, 8, 1,
845 &zfsvfs->z_fuid_obj);
846 if (error && error != ENOENT)
849 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SHARES_DIR, 8, 1,
850 &zfsvfs->z_shares_dir);
851 if (error && error != ENOENT)
854 mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
855 mutex_init(&zfsvfs->z_lock, NULL, MUTEX_DEFAULT, NULL);
856 list_create(&zfsvfs->z_all_znodes, sizeof (znode_t),
857 offsetof(znode_t, z_link_node));
858 rrw_init(&zfsvfs->z_teardown_lock);
859 rw_init(&zfsvfs->z_teardown_inactive_lock, NULL, RW_DEFAULT, NULL);
860 rw_init(&zfsvfs->z_fuid_lock, NULL, RW_DEFAULT, NULL);
861 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
862 mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
868 dmu_objset_disown(os, zfsvfs);
870 kmem_free(zfsvfs, sizeof (zfsvfs_t));
875 zfsvfs_setup(zfsvfs_t *zfsvfs, boolean_t mounting)
879 error = zfs_register_callbacks(zfsvfs->z_vfs);
884 * Set the objset user_ptr to track its zfsvfs.
886 mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
887 dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
888 mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
890 zfsvfs->z_log = zil_open(zfsvfs->z_os, zfs_get_data);
893 * If we are not mounting (ie: online recv), then we don't
894 * have to worry about replaying the log as we blocked all
895 * operations out since we closed the ZIL.
901 * During replay we remove the read only flag to
902 * allow replays to succeed.
904 readonly = zfsvfs->z_vfs->vfs_flag & VFS_RDONLY;
906 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
908 zfs_unlinked_drain(zfsvfs);
911 * Parse and replay the intent log.
913 * Because of ziltest, this must be done after
914 * zfs_unlinked_drain(). (Further note: ziltest
915 * doesn't use readonly mounts, where
916 * zfs_unlinked_drain() isn't called.) This is because
917 * ziltest causes spa_sync() to think it's committed,
918 * but actually it is not, so the intent log contains
919 * many txg's worth of changes.
921 * In particular, if object N is in the unlinked set in
922 * the last txg to actually sync, then it could be
923 * actually freed in a later txg and then reallocated
924 * in a yet later txg. This would write a "create
925 * object N" record to the intent log. Normally, this
926 * would be fine because the spa_sync() would have
927 * written out the fact that object N is free, before
928 * we could write the "create object N" intent log
931 * But when we are in ziltest mode, we advance the "open
932 * txg" without actually spa_sync()-ing the changes to
933 * disk. So we would see that object N is still
934 * allocated and in the unlinked set, and there is an
935 * intent log record saying to allocate it.
937 if (spa_writeable(dmu_objset_spa(zfsvfs->z_os))) {
938 if (zil_replay_disable) {
939 zil_destroy(zfsvfs->z_log, B_FALSE);
941 zfsvfs->z_replay = B_TRUE;
942 zil_replay(zfsvfs->z_os, zfsvfs,
944 zfsvfs->z_replay = B_FALSE;
947 zfsvfs->z_vfs->vfs_flag |= readonly; /* restore readonly bit */
954 zfsvfs_free(zfsvfs_t *zfsvfs)
957 extern krwlock_t zfsvfs_lock; /* in zfs_znode.c */
960 * This is a barrier to prevent the filesystem from going away in
961 * zfs_znode_move() until we can safely ensure that the filesystem is
962 * not unmounted. We consider the filesystem valid before the barrier
963 * and invalid after the barrier.
965 rw_enter(&zfsvfs_lock, RW_READER);
966 rw_exit(&zfsvfs_lock);
968 zfs_fuid_destroy(zfsvfs);
970 mutex_destroy(&zfsvfs->z_znodes_lock);
971 mutex_destroy(&zfsvfs->z_lock);
972 list_destroy(&zfsvfs->z_all_znodes);
973 rrw_destroy(&zfsvfs->z_teardown_lock);
974 rw_destroy(&zfsvfs->z_teardown_inactive_lock);
975 rw_destroy(&zfsvfs->z_fuid_lock);
976 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
977 mutex_destroy(&zfsvfs->z_hold_mtx[i]);
978 kmem_free(zfsvfs, sizeof (zfsvfs_t));
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);
997 zfs_domount(vfs_t *vfsp, char *osname)
999 uint64_t recordsize, fsid_guid;
1006 error = zfsvfs_create(osname, &zfsvfs);
1009 zfsvfs->z_vfs = vfsp;
1011 /* Initialize the generic filesystem structure. */
1012 vfsp->vfs_bcount = 0;
1013 vfsp->vfs_data = NULL;
1015 if ((error = dsl_prop_get_integer(osname, "recordsize",
1016 &recordsize, NULL)))
1019 vfsp->vfs_bsize = recordsize;
1020 vfsp->vfs_flag |= VFS_NOTRUNC;
1021 vfsp->vfs_data = zfsvfs;
1024 * The fsid is 64 bits, composed of an 8-bit fs type, which
1025 * separates our fsid from any other filesystem types, and a
1026 * 56-bit objset unique ID. The objset unique ID is unique to
1027 * all objsets open on this system, provided by unique_create().
1028 * The 8-bit fs type must be put in the low bits of fsid[1]
1029 * because that's where other Solaris filesystems put it.
1031 fsid_guid = dmu_objset_fsid_guid(zfsvfs->z_os);
1032 ASSERT((fsid_guid & ~((1ULL<<56)-1)) == 0);
1033 vfsp->vfs_fsid.val[0] = fsid_guid;
1034 vfsp->vfs_fsid.val[1] = ((fsid_guid>>32) << 8);
1037 * Set features for file system.
1039 zfs_set_fuid_feature(zfsvfs);
1040 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE) {
1041 vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS);
1042 vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE);
1043 vfs_set_feature(vfsp, VFSFT_NOCASESENSITIVE);
1044 } else if (zfsvfs->z_case == ZFS_CASE_MIXED) {
1045 vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS);
1046 vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE);
1048 vfs_set_feature(vfsp, VFSFT_ZEROCOPY_SUPPORTED);
1050 if (dmu_objset_is_snapshot(zfsvfs->z_os)) {
1053 atime_changed_cb(zfsvfs, B_FALSE);
1054 readonly_changed_cb(zfsvfs, B_TRUE);
1055 if ((error = dsl_prop_get_integer(osname,"xattr",&pval,NULL)))
1057 xattr_changed_cb(zfsvfs, pval);
1058 zfsvfs->z_issnap = B_TRUE;
1059 zfsvfs->z_os->os_sync = ZFS_SYNC_DISABLED;
1061 mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
1062 dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
1063 mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
1065 error = zfsvfs_setup(zfsvfs, B_TRUE);
1068 if (!zfsvfs->z_issnap)
1069 zfsctl_create(zfsvfs);
1072 dmu_objset_disown(zfsvfs->z_os, zfsvfs);
1073 zfsvfs_free(zfsvfs);
1078 EXPORT_SYMBOL(zfs_domount);
1081 zfs_unregister_callbacks(zfsvfs_t *zfsvfs)
1083 objset_t *os = zfsvfs->z_os;
1084 struct dsl_dataset *ds;
1087 * Unregister properties.
1089 if (!dmu_objset_is_snapshot(os)) {
1090 ds = dmu_objset_ds(os);
1091 VERIFY(dsl_prop_unregister(ds, "atime", atime_changed_cb,
1094 VERIFY(dsl_prop_unregister(ds, "xattr", xattr_changed_cb,
1097 VERIFY(dsl_prop_unregister(ds, "recordsize", blksz_changed_cb,
1100 VERIFY(dsl_prop_unregister(ds, "readonly", readonly_changed_cb,
1103 VERIFY(dsl_prop_unregister(ds, "devices", devices_changed_cb,
1106 VERIFY(dsl_prop_unregister(ds, "setuid", setuid_changed_cb,
1109 VERIFY(dsl_prop_unregister(ds, "exec", exec_changed_cb,
1112 VERIFY(dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb,
1115 VERIFY(dsl_prop_unregister(ds, "aclinherit",
1116 acl_inherit_changed_cb, zfsvfs) == 0);
1118 VERIFY(dsl_prop_unregister(ds, "vscan",
1119 vscan_changed_cb, zfsvfs) == 0);
1122 EXPORT_SYMBOL(zfs_unregister_callbacks);
1124 #ifdef HAVE_MLSLABEL
1126 * zfs_check_global_label:
1127 * Check that the hex label string is appropriate for the dataset
1128 * being mounted into the global_zone proper.
1130 * Return an error if the hex label string is not default or
1131 * admin_low/admin_high. For admin_low labels, the corresponding
1132 * dataset must be readonly.
1135 zfs_check_global_label(const char *dsname, const char *hexsl)
1137 if (strcasecmp(hexsl, ZFS_MLSLABEL_DEFAULT) == 0)
1139 if (strcasecmp(hexsl, ADMIN_HIGH) == 0)
1141 if (strcasecmp(hexsl, ADMIN_LOW) == 0) {
1142 /* must be readonly */
1145 if (dsl_prop_get_integer(dsname,
1146 zfs_prop_to_name(ZFS_PROP_READONLY), &rdonly, NULL))
1148 return (rdonly ? 0 : EACCES);
1152 #endif /* HAVE_MLSLABEL */
1155 zfs_statvfs(vfs_t *vfsp, struct statvfs64 *statp)
1157 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1159 uint64_t refdbytes, availbytes, usedobjs, availobjs;
1163 dmu_objset_space(zfsvfs->z_os,
1164 &refdbytes, &availbytes, &usedobjs, &availobjs);
1167 * The underlying storage pool actually uses multiple block sizes.
1168 * We report the fragsize as the smallest block size we support,
1169 * and we report our blocksize as the filesystem's maximum blocksize.
1171 statp->f_frsize = 1UL << SPA_MINBLOCKSHIFT;
1172 statp->f_bsize = zfsvfs->z_max_blksz;
1175 * The following report "total" blocks of various kinds in the
1176 * file system, but reported in terms of f_frsize - the
1180 statp->f_blocks = (refdbytes + availbytes) >> SPA_MINBLOCKSHIFT;
1181 statp->f_bfree = availbytes >> SPA_MINBLOCKSHIFT;
1182 statp->f_bavail = statp->f_bfree; /* no root reservation */
1185 * statvfs() should really be called statufs(), because it assumes
1186 * static metadata. ZFS doesn't preallocate files, so the best
1187 * we can do is report the max that could possibly fit in f_files,
1188 * and that minus the number actually used in f_ffree.
1189 * For f_ffree, report the smaller of the number of object available
1190 * and the number of blocks (each object will take at least a block).
1192 statp->f_ffree = MIN(availobjs, statp->f_bfree);
1193 statp->f_favail = statp->f_ffree; /* no "root reservation" */
1194 statp->f_files = statp->f_ffree + usedobjs;
1196 (void) cmpldev(&d32, vfsp->vfs_dev);
1197 statp->f_fsid = d32;
1200 * We're a zfs filesystem.
1202 (void) strcpy(statp->f_basetype, MNTTYPE_ZFS);
1204 statp->f_flag = vf_to_stf(vfsp->vfs_flag);
1206 statp->f_namemax = ZFS_MAXNAMELEN;
1209 * We have all of 32 characters to stuff a string here.
1210 * Is there anything useful we could/should provide?
1212 bzero(statp->f_fstr, sizeof (statp->f_fstr));
1217 EXPORT_SYMBOL(zfs_statvfs);
1220 zfs_root(vfs_t *vfsp, vnode_t **vpp)
1222 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1228 error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp);
1230 *vpp = ZTOV(rootzp);
1235 EXPORT_SYMBOL(zfs_root);
1238 * Teardown the zfsvfs::z_os.
1240 * Note, if 'unmounting' if FALSE, we return with the 'z_teardown_lock'
1241 * and 'z_teardown_inactive_lock' held.
1244 zfsvfs_teardown(zfsvfs_t *zfsvfs, boolean_t unmounting)
1248 rrw_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG);
1252 * We purge the parent filesystem's vfsp as the parent
1253 * filesystem and all of its snapshots have their vnode's
1254 * v_vfsp set to the parent's filesystem's vfsp. Note,
1255 * 'z_parent' is self referential for non-snapshots.
1257 (void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0);
1261 * Close the zil. NB: Can't close the zil while zfs_inactive
1262 * threads are blocked as zil_close can call zfs_inactive.
1264 if (zfsvfs->z_log) {
1265 zil_close(zfsvfs->z_log);
1266 zfsvfs->z_log = NULL;
1269 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_WRITER);
1272 * If we are not unmounting (ie: online recv) and someone already
1273 * unmounted this file system while we were doing the switcheroo,
1274 * or a reopen of z_os failed then just bail out now.
1276 if (!unmounting && (zfsvfs->z_unmounted || zfsvfs->z_os == NULL)) {
1277 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1278 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
1283 * At this point there are no vops active, and any new vops will
1284 * fail with EIO since we have z_teardown_lock for writer (only
1285 * relavent for forced unmount).
1287 * Release all holds on dbufs.
1289 mutex_enter(&zfsvfs->z_znodes_lock);
1290 for (zp = list_head(&zfsvfs->z_all_znodes); zp != NULL;
1291 zp = list_next(&zfsvfs->z_all_znodes, zp))
1293 ASSERT(ZTOV(zp)->v_count > 0);
1294 zfs_znode_dmu_fini(zp);
1296 mutex_exit(&zfsvfs->z_znodes_lock);
1299 * If we are unmounting, set the unmounted flag and let new vops
1300 * unblock. zfs_inactive will have the unmounted behavior, and all
1301 * other vops will fail with EIO.
1304 zfsvfs->z_unmounted = B_TRUE;
1305 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
1306 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1310 * z_os will be NULL if there was an error in attempting to reopen
1311 * zfsvfs, so just return as the properties had already been
1312 * unregistered and cached data had been evicted before.
1314 if (zfsvfs->z_os == NULL)
1318 * Unregister properties.
1320 zfs_unregister_callbacks(zfsvfs);
1325 if (dmu_objset_is_dirty_anywhere(zfsvfs->z_os))
1326 if (!(zfsvfs->z_vfs->vfs_flag & VFS_RDONLY))
1327 txg_wait_synced(dmu_objset_pool(zfsvfs->z_os), 0);
1328 (void) dmu_objset_evict_dbufs(zfsvfs->z_os);
1335 zfs_umount(vfs_t *vfsp, int fflag, cred_t *cr)
1337 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1341 ret = secpolicy_fs_unmount(cr, vfsp);
1343 if (dsl_deleg_access((char *)refstr_value(vfsp->vfs_resource),
1344 ZFS_DELEG_PERM_MOUNT, cr))
1349 * We purge the parent filesystem's vfsp as the parent filesystem
1350 * and all of its snapshots have their vnode's v_vfsp set to the
1351 * parent's filesystem's vfsp. Note, 'z_parent' is self
1352 * referential for non-snapshots.
1354 (void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0);
1357 * Unmount any snapshots mounted under .zfs before unmounting the
1360 if (zfsvfs->z_ctldir != NULL &&
1361 (ret = zfsctl_umount_snapshots(vfsp, fflag, cr)) != 0) {
1365 if (!(fflag & MS_FORCE)) {
1367 * Check the number of active vnodes in the file system.
1368 * Our count is maintained in the vfs structure, but the
1369 * number is off by 1 to indicate a hold on the vfs
1372 * The '.zfs' directory maintains a reference of its
1373 * own, and any active references underneath are
1374 * reflected in the vnode count.
1376 if (zfsvfs->z_ctldir == NULL) {
1377 if (vfsp->vfs_count > 1)
1380 if (vfsp->vfs_count > 2 ||
1381 zfsvfs->z_ctldir->v_count > 1)
1386 vfsp->vfs_flag |= VFS_UNMOUNTED;
1388 VERIFY(zfsvfs_teardown(zfsvfs, B_TRUE) == 0);
1392 * z_os will be NULL if there was an error in
1393 * attempting to reopen zfsvfs.
1397 * Unset the objset user_ptr.
1399 mutex_enter(&os->os_user_ptr_lock);
1400 dmu_objset_set_user(os, NULL);
1401 mutex_exit(&os->os_user_ptr_lock);
1404 * Finally release the objset
1406 dmu_objset_disown(os, zfsvfs);
1410 * We can now safely destroy the '.zfs' directory node.
1412 if (zfsvfs->z_ctldir != NULL)
1413 zfsctl_destroy(zfsvfs);
1417 EXPORT_SYMBOL(zfs_umount);
1420 zfs_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp)
1422 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1424 uint64_t object = 0;
1425 uint64_t fid_gen = 0;
1434 if (fidp->fid_len == LONG_FID_LEN) {
1435 zfid_long_t *zlfid = (zfid_long_t *)fidp;
1436 uint64_t objsetid = 0;
1437 uint64_t setgen = 0;
1439 for (i = 0; i < sizeof (zlfid->zf_setid); i++)
1440 objsetid |= ((uint64_t)zlfid->zf_setid[i]) << (8 * i);
1442 for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
1443 setgen |= ((uint64_t)zlfid->zf_setgen[i]) << (8 * i);
1447 err = zfsctl_lookup_objset(vfsp, objsetid, &zfsvfs);
1453 if (fidp->fid_len == SHORT_FID_LEN || fidp->fid_len == LONG_FID_LEN) {
1454 zfid_short_t *zfid = (zfid_short_t *)fidp;
1456 for (i = 0; i < sizeof (zfid->zf_object); i++)
1457 object |= ((uint64_t)zfid->zf_object[i]) << (8 * i);
1459 for (i = 0; i < sizeof (zfid->zf_gen); i++)
1460 fid_gen |= ((uint64_t)zfid->zf_gen[i]) << (8 * i);
1466 /* A zero fid_gen means we are in the .zfs control directories */
1468 (object == ZFSCTL_INO_ROOT || object == ZFSCTL_INO_SNAPDIR)) {
1469 *vpp = zfsvfs->z_ctldir;
1470 ASSERT(*vpp != NULL);
1471 if (object == ZFSCTL_INO_SNAPDIR) {
1472 VERIFY(zfsctl_root_lookup(*vpp, "snapshot", vpp, NULL,
1473 0, NULL, NULL, NULL, NULL, NULL) == 0);
1481 gen_mask = -1ULL >> (64 - 8 * i);
1483 dprintf("getting %llu [%u mask %llx]\n", object, fid_gen, gen_mask);
1484 if ((err = zfs_zget(zfsvfs, object, &zp))) {
1488 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zfsvfs), &zp_gen,
1490 zp_gen = zp_gen & gen_mask;
1493 if (zp->z_unlinked || zp_gen != fid_gen) {
1494 dprintf("znode gen (%u) != fid gen (%u)\n", zp_gen, fid_gen);
1502 zfs_inode_update(VTOZ(*vpp));
1507 EXPORT_SYMBOL(zfs_vget);
1510 * Block out VOPs and close zfsvfs_t::z_os
1512 * Note, if successful, then we return with the 'z_teardown_lock' and
1513 * 'z_teardown_inactive_lock' write held.
1516 zfs_suspend_fs(zfsvfs_t *zfsvfs)
1520 if ((error = zfsvfs_teardown(zfsvfs, B_FALSE)) != 0)
1522 dmu_objset_disown(zfsvfs->z_os, zfsvfs);
1526 EXPORT_SYMBOL(zfs_suspend_fs);
1529 * Reopen zfsvfs_t::z_os and release VOPs.
1532 zfs_resume_fs(zfsvfs_t *zfsvfs, const char *osname)
1536 ASSERT(RRW_WRITE_HELD(&zfsvfs->z_teardown_lock));
1537 ASSERT(RW_WRITE_HELD(&zfsvfs->z_teardown_inactive_lock));
1539 err = dmu_objset_own(osname, DMU_OST_ZFS, B_FALSE, zfsvfs,
1542 zfsvfs->z_os = NULL;
1545 uint64_t sa_obj = 0;
1547 err2 = zap_lookup(zfsvfs->z_os, MASTER_NODE_OBJ,
1548 ZFS_SA_ATTRS, 8, 1, &sa_obj);
1550 if ((err || err2) && zfsvfs->z_version >= ZPL_VERSION_SA)
1554 if ((err = sa_setup(zfsvfs->z_os, sa_obj,
1555 zfs_attr_table, ZPL_END, &zfsvfs->z_attr_table)) != 0)
1558 VERIFY(zfsvfs_setup(zfsvfs, B_FALSE) == 0);
1561 * Attempt to re-establish all the active znodes with
1562 * their dbufs. If a zfs_rezget() fails, then we'll let
1563 * any potential callers discover that via ZFS_ENTER_VERIFY_VP
1564 * when they try to use their znode.
1566 mutex_enter(&zfsvfs->z_znodes_lock);
1567 for (zp = list_head(&zfsvfs->z_all_znodes); zp;
1568 zp = list_next(&zfsvfs->z_all_znodes, zp)) {
1569 (void) zfs_rezget(zp);
1571 mutex_exit(&zfsvfs->z_znodes_lock);
1576 /* release the VOPs */
1577 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1578 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
1582 * Since we couldn't reopen zfsvfs::z_os, force
1583 * unmount this file system.
1585 if (vn_vfswlock(zfsvfs->z_vfs->vfs_vnodecovered) == 0)
1586 (void) dounmount(zfsvfs->z_vfs, MS_FORCE, CRED());
1590 EXPORT_SYMBOL(zfs_resume_fs);
1593 zfs_freevfs(vfs_t *vfsp)
1595 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1597 zfsvfs_free(zfsvfs);
1599 #endif /* HAVE_ZPL */
1607 dmu_objset_register_type(DMU_OST_ZFS, zfs_space_delta_cb);
1619 zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers)
1622 objset_t *os = zfsvfs->z_os;
1625 if (newvers < ZPL_VERSION_INITIAL || newvers > ZPL_VERSION)
1628 if (newvers < zfsvfs->z_version)
1631 if (zfs_spa_version_map(newvers) >
1632 spa_version(dmu_objset_spa(zfsvfs->z_os)))
1635 tx = dmu_tx_create(os);
1636 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_FALSE, ZPL_VERSION_STR);
1637 if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
1638 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE,
1640 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
1642 error = dmu_tx_assign(tx, TXG_WAIT);
1648 error = zap_update(os, MASTER_NODE_OBJ, ZPL_VERSION_STR,
1649 8, 1, &newvers, tx);
1656 if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
1659 ASSERT3U(spa_version(dmu_objset_spa(zfsvfs->z_os)), >=,
1661 sa_obj = zap_create(os, DMU_OT_SA_MASTER_NODE,
1662 DMU_OT_NONE, 0, tx);
1664 error = zap_add(os, MASTER_NODE_OBJ,
1665 ZFS_SA_ATTRS, 8, 1, &sa_obj, tx);
1666 ASSERT3U(error, ==, 0);
1668 VERIFY(0 == sa_set_sa_object(os, sa_obj));
1669 sa_register_update_callback(os, zfs_sa_upgrade);
1672 spa_history_log_internal(LOG_DS_UPGRADE,
1673 dmu_objset_spa(os), tx, "oldver=%llu newver=%llu dataset = %llu",
1674 zfsvfs->z_version, newvers, dmu_objset_id(os));
1678 zfsvfs->z_version = newvers;
1680 if (zfsvfs->z_version >= ZPL_VERSION_FUID)
1681 zfs_set_fuid_feature(zfsvfs);
1685 EXPORT_SYMBOL(zfs_set_version);
1686 #endif /* HAVE_ZPL */
1689 * Read a property stored within the master node.
1692 zfs_get_zplprop(objset_t *os, zfs_prop_t prop, uint64_t *value)
1698 * Look up the file system's value for the property. For the
1699 * version property, we look up a slightly different string.
1701 if (prop == ZFS_PROP_VERSION)
1702 pname = ZPL_VERSION_STR;
1704 pname = zfs_prop_to_name(prop);
1707 error = zap_lookup(os, MASTER_NODE_OBJ, pname, 8, 1, value);
1709 if (error == ENOENT) {
1710 /* No value set, use the default value */
1712 case ZFS_PROP_VERSION:
1713 *value = ZPL_VERSION;
1715 case ZFS_PROP_NORMALIZE:
1716 case ZFS_PROP_UTF8ONLY:
1720 *value = ZFS_CASE_SENSITIVE;