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"
69 extern int sys_shutdown;
72 * We need to keep a count of active fs's.
73 * This is necessary to prevent our module
74 * from being unloaded after a umount -f
76 static uint32_t zfs_active_fs_count = 0;
78 static char *noatime_cancel[] = { MNTOPT_ATIME, NULL };
79 static char *atime_cancel[] = { MNTOPT_NOATIME, NULL };
80 static char *noxattr_cancel[] = { MNTOPT_XATTR, NULL };
81 static char *xattr_cancel[] = { MNTOPT_NOXATTR, NULL };
84 * MO_DEFAULT is not used since the default value is determined
85 * by the equivalent property.
87 static mntopt_t mntopts[] = {
88 { MNTOPT_NOXATTR, noxattr_cancel, NULL, 0, NULL },
89 { MNTOPT_XATTR, xattr_cancel, NULL, 0, NULL },
90 { MNTOPT_NOATIME, noatime_cancel, NULL, 0, NULL },
91 { MNTOPT_ATIME, atime_cancel, NULL, 0, NULL }
94 static mntopts_t zfs_mntopts = {
95 sizeof (mntopts) / sizeof (mntopt_t),
101 zfs_sync(vfs_t *vfsp, short flag, cred_t *cr)
104 * Data integrity is job one. We don't want a compromised kernel
105 * writing to the storage pool, so we never sync during panic.
111 * SYNC_ATTR is used by fsflush() to force old filesystems like UFS
112 * to sync metadata, which they would otherwise cache indefinitely.
113 * Semantically, the only requirement is that the sync be initiated.
114 * The DMU syncs out txgs frequently, so there's nothing to do.
116 if (flag & SYNC_ATTR)
121 * Sync a specific filesystem.
123 zfsvfs_t *zfsvfs = vfsp->vfs_data;
127 dp = dmu_objset_pool(zfsvfs->z_os);
130 * If the system is shutting down, then skip any
131 * filesystems which may exist on a suspended pool.
133 if (sys_shutdown && spa_suspended(dp->dp_spa)) {
138 if (zfsvfs->z_log != NULL)
139 zil_commit(zfsvfs->z_log, 0);
144 * Sync all ZFS filesystems. This is what happens when you
145 * run sync(1M). Unlike other filesystems, ZFS honors the
146 * request by waiting for all pools to commit all dirty data.
153 EXPORT_SYMBOL(zfs_sync);
156 atime_changed_cb(void *arg, uint64_t newval)
158 zfsvfs_t *zfsvfs = arg;
160 if (newval == TRUE) {
161 zfsvfs->z_atime = TRUE;
162 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME);
163 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_ATIME, NULL, 0);
165 zfsvfs->z_atime = FALSE;
166 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_ATIME);
167 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME, NULL, 0);
172 xattr_changed_cb(void *arg, uint64_t newval)
174 zfsvfs_t *zfsvfs = arg;
176 if (newval == TRUE) {
177 /* XXX locking on vfs_flag? */
178 zfsvfs->z_vfs->vfs_flag |= VFS_XATTR;
179 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR);
180 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_XATTR, NULL, 0);
182 /* XXX locking on vfs_flag? */
183 zfsvfs->z_vfs->vfs_flag &= ~VFS_XATTR;
184 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_XATTR);
185 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR, NULL, 0);
190 blksz_changed_cb(void *arg, uint64_t newval)
192 zfsvfs_t *zfsvfs = arg;
194 if (newval < SPA_MINBLOCKSIZE ||
195 newval > SPA_MAXBLOCKSIZE || !ISP2(newval))
196 newval = SPA_MAXBLOCKSIZE;
198 zfsvfs->z_max_blksz = newval;
199 zfsvfs->z_vfs->vfs_bsize = newval;
203 readonly_changed_cb(void *arg, uint64_t newval)
205 zfsvfs_t *zfsvfs = arg;
208 /* XXX locking on vfs_flag? */
209 zfsvfs->z_vfs->vfs_flag |= VFS_RDONLY;
210 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RW);
211 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RO, NULL, 0);
213 /* XXX locking on vfs_flag? */
214 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
215 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RO);
216 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RW, NULL, 0);
221 devices_changed_cb(void *arg, uint64_t newval)
223 zfsvfs_t *zfsvfs = arg;
225 if (newval == FALSE) {
226 zfsvfs->z_vfs->vfs_flag |= VFS_NODEVICES;
227 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES);
228 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES, NULL, 0);
230 zfsvfs->z_vfs->vfs_flag &= ~VFS_NODEVICES;
231 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES);
232 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES, NULL, 0);
237 setuid_changed_cb(void *arg, uint64_t newval)
239 zfsvfs_t *zfsvfs = arg;
241 if (newval == FALSE) {
242 zfsvfs->z_vfs->vfs_flag |= VFS_NOSETUID;
243 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_SETUID);
244 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID, NULL, 0);
246 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOSETUID;
247 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID);
248 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_SETUID, NULL, 0);
253 exec_changed_cb(void *arg, uint64_t newval)
255 zfsvfs_t *zfsvfs = arg;
257 if (newval == FALSE) {
258 zfsvfs->z_vfs->vfs_flag |= VFS_NOEXEC;
259 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_EXEC);
260 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC, NULL, 0);
262 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOEXEC;
263 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC);
264 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_EXEC, NULL, 0);
269 * The nbmand mount option can be changed at mount time.
270 * We can't allow it to be toggled on live file systems or incorrect
271 * behavior may be seen from cifs clients
273 * This property isn't registered via dsl_prop_register(), but this callback
274 * will be called when a file system is first mounted
277 nbmand_changed_cb(void *arg, uint64_t newval)
279 zfsvfs_t *zfsvfs = arg;
280 if (newval == FALSE) {
281 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND);
282 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND, NULL, 0);
284 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND);
285 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND, NULL, 0);
290 snapdir_changed_cb(void *arg, uint64_t newval)
292 zfsvfs_t *zfsvfs = arg;
294 zfsvfs->z_show_ctldir = newval;
298 vscan_changed_cb(void *arg, uint64_t newval)
300 zfsvfs_t *zfsvfs = arg;
302 zfsvfs->z_vscan = newval;
306 acl_inherit_changed_cb(void *arg, uint64_t newval)
308 zfsvfs_t *zfsvfs = arg;
310 zfsvfs->z_acl_inherit = newval;
314 zfs_register_callbacks(vfs_t *vfsp)
316 struct dsl_dataset *ds = NULL;
318 zfsvfs_t *zfsvfs = NULL;
320 int readonly, do_readonly = B_FALSE;
321 int setuid, do_setuid = B_FALSE;
322 int exec, do_exec = B_FALSE;
323 int devices, do_devices = B_FALSE;
324 int xattr, do_xattr = B_FALSE;
325 int atime, do_atime = B_FALSE;
329 zfsvfs = vfsp->vfs_data;
334 * The act of registering our callbacks will destroy any mount
335 * options we may have. In order to enable temporary overrides
336 * of mount options, we stash away the current values and
337 * restore them after we register the callbacks.
339 if (vfs_optionisset(vfsp, MNTOPT_RO, NULL) ||
340 !spa_writeable(dmu_objset_spa(os))) {
342 do_readonly = B_TRUE;
343 } else if (vfs_optionisset(vfsp, MNTOPT_RW, NULL)) {
345 do_readonly = B_TRUE;
347 if (vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL)) {
353 if (vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL)) {
356 } else if (vfs_optionisset(vfsp, MNTOPT_DEVICES, NULL)) {
361 if (vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL)) {
364 } else if (vfs_optionisset(vfsp, MNTOPT_SETUID, NULL)) {
369 if (vfs_optionisset(vfsp, MNTOPT_NOEXEC, NULL)) {
372 } else if (vfs_optionisset(vfsp, MNTOPT_EXEC, NULL)) {
376 if (vfs_optionisset(vfsp, MNTOPT_NOXATTR, NULL)) {
379 } else if (vfs_optionisset(vfsp, MNTOPT_XATTR, NULL)) {
383 if (vfs_optionisset(vfsp, MNTOPT_NOATIME, NULL)) {
386 } else if (vfs_optionisset(vfsp, MNTOPT_ATIME, NULL)) {
392 * nbmand is a special property. It can only be changed at
395 * This is weird, but it is documented to only be changeable
398 if (vfs_optionisset(vfsp, MNTOPT_NONBMAND, NULL)) {
400 } else if (vfs_optionisset(vfsp, MNTOPT_NBMAND, NULL)) {
403 char osname[MAXNAMELEN];
405 dmu_objset_name(os, osname);
406 if ((error = dsl_prop_get_integer(osname, "nbmand", &nbmand,
413 * Register property callbacks.
415 * It would probably be fine to just check for i/o error from
416 * the first prop_register(), but I guess I like to go
419 ds = dmu_objset_ds(os);
420 error = dsl_prop_register(ds, "atime", atime_changed_cb, zfsvfs);
421 error = error ? error : dsl_prop_register(ds,
422 "xattr", xattr_changed_cb, zfsvfs);
423 error = error ? error : dsl_prop_register(ds,
424 "recordsize", blksz_changed_cb, zfsvfs);
425 error = error ? error : dsl_prop_register(ds,
426 "readonly", readonly_changed_cb, zfsvfs);
427 error = error ? error : dsl_prop_register(ds,
428 "devices", devices_changed_cb, zfsvfs);
429 error = error ? error : dsl_prop_register(ds,
430 "setuid", setuid_changed_cb, zfsvfs);
431 error = error ? error : dsl_prop_register(ds,
432 "exec", exec_changed_cb, zfsvfs);
433 error = error ? error : dsl_prop_register(ds,
434 "snapdir", snapdir_changed_cb, zfsvfs);
435 error = error ? error : dsl_prop_register(ds,
436 "aclinherit", acl_inherit_changed_cb, zfsvfs);
437 error = error ? error : dsl_prop_register(ds,
438 "vscan", vscan_changed_cb, zfsvfs);
443 * Invoke our callbacks to restore temporary mount options.
446 readonly_changed_cb(zfsvfs, readonly);
448 setuid_changed_cb(zfsvfs, setuid);
450 exec_changed_cb(zfsvfs, exec);
452 devices_changed_cb(zfsvfs, devices);
454 xattr_changed_cb(zfsvfs, xattr);
456 atime_changed_cb(zfsvfs, atime);
458 nbmand_changed_cb(zfsvfs, nbmand);
464 * We may attempt to unregister some callbacks that are not
465 * registered, but this is OK; it will simply return ENOMSG,
466 * which we will ignore.
468 (void) dsl_prop_unregister(ds, "atime", atime_changed_cb, zfsvfs);
469 (void) dsl_prop_unregister(ds, "xattr", xattr_changed_cb, zfsvfs);
470 (void) dsl_prop_unregister(ds, "recordsize", blksz_changed_cb, zfsvfs);
471 (void) dsl_prop_unregister(ds, "readonly", readonly_changed_cb, zfsvfs);
472 (void) dsl_prop_unregister(ds, "devices", devices_changed_cb, zfsvfs);
473 (void) dsl_prop_unregister(ds, "setuid", setuid_changed_cb, zfsvfs);
474 (void) dsl_prop_unregister(ds, "exec", exec_changed_cb, zfsvfs);
475 (void) dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb, zfsvfs);
476 (void) dsl_prop_unregister(ds, "aclinherit", acl_inherit_changed_cb,
478 (void) dsl_prop_unregister(ds, "vscan", vscan_changed_cb, zfsvfs);
482 EXPORT_SYMBOL(zfs_register_callbacks);
483 #endif /* HAVE_ZPL */
486 zfs_space_delta_cb(dmu_object_type_t bonustype, void *data,
487 uint64_t *userp, uint64_t *groupp)
489 znode_phys_t *znp = data;
493 * Is it a valid type of object to track?
495 if (bonustype != DMU_OT_ZNODE && bonustype != DMU_OT_SA)
499 * If we have a NULL data pointer
500 * then assume the id's aren't changing and
501 * return EEXIST to the dmu to let it know to
507 if (bonustype == DMU_OT_ZNODE) {
508 *userp = znp->zp_uid;
509 *groupp = znp->zp_gid;
513 ASSERT(bonustype == DMU_OT_SA);
514 hdrsize = sa_hdrsize(data);
517 *userp = *((uint64_t *)((uintptr_t)data + hdrsize +
519 *groupp = *((uint64_t *)((uintptr_t)data + hdrsize +
523 * This should only happen for newly created
524 * files that haven't had the znode data filled
536 fuidstr_to_sid(zfsvfs_t *zfsvfs, const char *fuidstr,
537 char *domainbuf, int buflen, uid_t *ridp)
542 fuid = strtonum(fuidstr, NULL);
544 domain = zfs_fuid_find_by_idx(zfsvfs, FUID_INDEX(fuid));
546 (void) strlcpy(domainbuf, domain, buflen);
549 *ridp = FUID_RID(fuid);
553 zfs_userquota_prop_to_obj(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type)
556 case ZFS_PROP_USERUSED:
557 return (DMU_USERUSED_OBJECT);
558 case ZFS_PROP_GROUPUSED:
559 return (DMU_GROUPUSED_OBJECT);
560 case ZFS_PROP_USERQUOTA:
561 return (zfsvfs->z_userquota_obj);
562 case ZFS_PROP_GROUPQUOTA:
563 return (zfsvfs->z_groupquota_obj);
571 zfs_userspace_many(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
572 uint64_t *cookiep, void *vbuf, uint64_t *bufsizep)
577 zfs_useracct_t *buf = vbuf;
580 if (!dmu_objset_userspace_present(zfsvfs->z_os))
583 obj = zfs_userquota_prop_to_obj(zfsvfs, type);
589 for (zap_cursor_init_serialized(&zc, zfsvfs->z_os, obj, *cookiep);
590 (error = zap_cursor_retrieve(&zc, &za)) == 0;
591 zap_cursor_advance(&zc)) {
592 if ((uintptr_t)buf - (uintptr_t)vbuf + sizeof (zfs_useracct_t) >
596 fuidstr_to_sid(zfsvfs, za.za_name,
597 buf->zu_domain, sizeof (buf->zu_domain), &buf->zu_rid);
599 buf->zu_space = za.za_first_integer;
605 ASSERT3U((uintptr_t)buf - (uintptr_t)vbuf, <=, *bufsizep);
606 *bufsizep = (uintptr_t)buf - (uintptr_t)vbuf;
607 *cookiep = zap_cursor_serialize(&zc);
608 zap_cursor_fini(&zc);
611 EXPORT_SYMBOL(zfs_userspace_many);
614 * buf must be big enough (eg, 32 bytes)
617 id_to_fuidstr(zfsvfs_t *zfsvfs, const char *domain, uid_t rid,
618 char *buf, boolean_t addok)
623 if (domain && domain[0]) {
624 domainid = zfs_fuid_find_by_domain(zfsvfs, domain, NULL, addok);
628 fuid = FUID_ENCODE(domainid, rid);
629 (void) sprintf(buf, "%llx", (longlong_t)fuid);
634 zfs_userspace_one(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
635 const char *domain, uint64_t rid, uint64_t *valp)
643 if (!dmu_objset_userspace_present(zfsvfs->z_os))
646 obj = zfs_userquota_prop_to_obj(zfsvfs, type);
650 err = id_to_fuidstr(zfsvfs, domain, rid, buf, B_FALSE);
654 err = zap_lookup(zfsvfs->z_os, obj, buf, 8, 1, valp);
659 EXPORT_SYMBOL(zfs_userspace_one);
662 zfs_set_userquota(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
663 const char *domain, uint64_t rid, uint64_t quota)
669 boolean_t fuid_dirtied;
671 if (type != ZFS_PROP_USERQUOTA && type != ZFS_PROP_GROUPQUOTA)
674 if (zfsvfs->z_version < ZPL_VERSION_USERSPACE)
677 objp = (type == ZFS_PROP_USERQUOTA) ? &zfsvfs->z_userquota_obj :
678 &zfsvfs->z_groupquota_obj;
680 err = id_to_fuidstr(zfsvfs, domain, rid, buf, B_TRUE);
683 fuid_dirtied = zfsvfs->z_fuid_dirty;
685 tx = dmu_tx_create(zfsvfs->z_os);
686 dmu_tx_hold_zap(tx, *objp ? *objp : DMU_NEW_OBJECT, B_TRUE, NULL);
688 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE,
689 zfs_userquota_prop_prefixes[type]);
692 zfs_fuid_txhold(zfsvfs, tx);
693 err = dmu_tx_assign(tx, TXG_WAIT);
699 mutex_enter(&zfsvfs->z_lock);
701 *objp = zap_create(zfsvfs->z_os, DMU_OT_USERGROUP_QUOTA,
703 VERIFY(0 == zap_add(zfsvfs->z_os, MASTER_NODE_OBJ,
704 zfs_userquota_prop_prefixes[type], 8, 1, objp, tx));
706 mutex_exit(&zfsvfs->z_lock);
709 err = zap_remove(zfsvfs->z_os, *objp, buf, tx);
713 err = zap_update(zfsvfs->z_os, *objp, buf, 8, 1, "a, tx);
717 zfs_fuid_sync(zfsvfs, tx);
721 EXPORT_SYMBOL(zfs_set_userquota);
724 zfs_fuid_overquota(zfsvfs_t *zfsvfs, boolean_t isgroup, uint64_t fuid)
727 uint64_t used, quota, usedobj, quotaobj;
730 usedobj = isgroup ? DMU_GROUPUSED_OBJECT : DMU_USERUSED_OBJECT;
731 quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj;
733 if (quotaobj == 0 || zfsvfs->z_replay)
736 (void) sprintf(buf, "%llx", (longlong_t)fuid);
737 err = zap_lookup(zfsvfs->z_os, quotaobj, buf, 8, 1, "a);
741 err = zap_lookup(zfsvfs->z_os, usedobj, buf, 8, 1, &used);
744 return (used >= quota);
746 EXPORT_SYMBOL(zfs_fuid_overquota);
749 zfs_owner_overquota(zfsvfs_t *zfsvfs, znode_t *zp, boolean_t isgroup)
754 quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj;
756 fuid = isgroup ? zp->z_gid : zp->z_uid;
758 if (quotaobj == 0 || zfsvfs->z_replay)
761 return (zfs_fuid_overquota(zfsvfs, isgroup, fuid));
763 EXPORT_SYMBOL(zfs_owner_overquota);
766 zfsvfs_create(const char *osname, zfsvfs_t **zfvp)
774 zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP);
777 * We claim to always be readonly so we can open snapshots;
778 * other ZPL code will prevent us from writing to snapshots.
780 error = dmu_objset_own(osname, DMU_OST_ZFS, B_TRUE, zfsvfs, &os);
782 kmem_free(zfsvfs, sizeof (zfsvfs_t));
787 * Initialize the zfs-specific filesystem structure.
788 * Should probably make this a kmem cache, shuffle fields,
789 * and just bzero up to z_hold_mtx[].
791 zfsvfs->z_vfs = NULL;
792 zfsvfs->z_parent = zfsvfs;
793 zfsvfs->z_max_blksz = SPA_MAXBLOCKSIZE;
794 zfsvfs->z_show_ctldir = ZFS_SNAPDIR_VISIBLE;
797 error = zfs_get_zplprop(os, ZFS_PROP_VERSION, &zfsvfs->z_version);
800 } else if (zfsvfs->z_version >
801 zfs_zpl_version_map(spa_version(dmu_objset_spa(os)))) {
802 (void) printk("Can't mount a version %lld file system "
803 "on a version %lld pool\n. Pool must be upgraded to mount "
804 "this file system.", (u_longlong_t)zfsvfs->z_version,
805 (u_longlong_t)spa_version(dmu_objset_spa(os)));
809 if ((error = zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &zval)) != 0)
811 zfsvfs->z_norm = (int)zval;
813 if ((error = zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &zval)) != 0)
815 zfsvfs->z_utf8 = (zval != 0);
817 if ((error = zfs_get_zplprop(os, ZFS_PROP_CASE, &zval)) != 0)
819 zfsvfs->z_case = (uint_t)zval;
822 * Fold case on file systems that are always or sometimes case
825 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
826 zfsvfs->z_case == ZFS_CASE_MIXED)
827 zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER;
829 zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
830 zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
832 if (zfsvfs->z_use_sa) {
833 /* should either have both of these objects or none */
834 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SA_ATTRS, 8, 1,
840 * Pre SA versions file systems should never touch
841 * either the attribute registration or layout objects.
846 error = sa_setup(os, sa_obj, zfs_attr_table, ZPL_END,
847 &zfsvfs->z_attr_table);
851 if (zfsvfs->z_version >= ZPL_VERSION_SA)
852 sa_register_update_callback(os, zfs_sa_upgrade);
854 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1,
858 ASSERT(zfsvfs->z_root != 0);
860 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_UNLINKED_SET, 8, 1,
861 &zfsvfs->z_unlinkedobj);
865 error = zap_lookup(os, MASTER_NODE_OBJ,
866 zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA],
867 8, 1, &zfsvfs->z_userquota_obj);
868 if (error && error != ENOENT)
871 error = zap_lookup(os, MASTER_NODE_OBJ,
872 zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA],
873 8, 1, &zfsvfs->z_groupquota_obj);
874 if (error && error != ENOENT)
877 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES, 8, 1,
878 &zfsvfs->z_fuid_obj);
879 if (error && error != ENOENT)
882 error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SHARES_DIR, 8, 1,
883 &zfsvfs->z_shares_dir);
884 if (error && error != ENOENT)
887 mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
888 mutex_init(&zfsvfs->z_lock, NULL, MUTEX_DEFAULT, NULL);
889 list_create(&zfsvfs->z_all_znodes, sizeof (znode_t),
890 offsetof(znode_t, z_link_node));
891 rrw_init(&zfsvfs->z_teardown_lock);
892 rw_init(&zfsvfs->z_teardown_inactive_lock, NULL, RW_DEFAULT, NULL);
893 rw_init(&zfsvfs->z_fuid_lock, NULL, RW_DEFAULT, NULL);
894 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
895 mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
901 dmu_objset_disown(os, zfsvfs);
903 kmem_free(zfsvfs, sizeof (zfsvfs_t));
908 zfsvfs_setup(zfsvfs_t *zfsvfs, boolean_t mounting)
912 error = zfs_register_callbacks(zfsvfs->z_vfs);
917 * Set the objset user_ptr to track its zfsvfs.
919 mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
920 dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
921 mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
923 zfsvfs->z_log = zil_open(zfsvfs->z_os, zfs_get_data);
926 * If we are not mounting (ie: online recv), then we don't
927 * have to worry about replaying the log as we blocked all
928 * operations out since we closed the ZIL.
934 * During replay we remove the read only flag to
935 * allow replays to succeed.
937 readonly = zfsvfs->z_vfs->vfs_flag & VFS_RDONLY;
939 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
941 zfs_unlinked_drain(zfsvfs);
944 * Parse and replay the intent log.
946 * Because of ziltest, this must be done after
947 * zfs_unlinked_drain(). (Further note: ziltest
948 * doesn't use readonly mounts, where
949 * zfs_unlinked_drain() isn't called.) This is because
950 * ziltest causes spa_sync() to think it's committed,
951 * but actually it is not, so the intent log contains
952 * many txg's worth of changes.
954 * In particular, if object N is in the unlinked set in
955 * the last txg to actually sync, then it could be
956 * actually freed in a later txg and then reallocated
957 * in a yet later txg. This would write a "create
958 * object N" record to the intent log. Normally, this
959 * would be fine because the spa_sync() would have
960 * written out the fact that object N is free, before
961 * we could write the "create object N" intent log
964 * But when we are in ziltest mode, we advance the "open
965 * txg" without actually spa_sync()-ing the changes to
966 * disk. So we would see that object N is still
967 * allocated and in the unlinked set, and there is an
968 * intent log record saying to allocate it.
970 if (spa_writeable(dmu_objset_spa(zfsvfs->z_os))) {
971 if (zil_replay_disable) {
972 zil_destroy(zfsvfs->z_log, B_FALSE);
974 zfsvfs->z_replay = B_TRUE;
975 zil_replay(zfsvfs->z_os, zfsvfs,
977 zfsvfs->z_replay = B_FALSE;
980 zfsvfs->z_vfs->vfs_flag |= readonly; /* restore readonly bit */
987 zfsvfs_free(zfsvfs_t *zfsvfs)
990 extern krwlock_t zfsvfs_lock; /* in zfs_znode.c */
993 * This is a barrier to prevent the filesystem from going away in
994 * zfs_znode_move() until we can safely ensure that the filesystem is
995 * not unmounted. We consider the filesystem valid before the barrier
996 * and invalid after the barrier.
998 rw_enter(&zfsvfs_lock, RW_READER);
999 rw_exit(&zfsvfs_lock);
1001 zfs_fuid_destroy(zfsvfs);
1003 mutex_destroy(&zfsvfs->z_znodes_lock);
1004 mutex_destroy(&zfsvfs->z_lock);
1005 list_destroy(&zfsvfs->z_all_znodes);
1006 rrw_destroy(&zfsvfs->z_teardown_lock);
1007 rw_destroy(&zfsvfs->z_teardown_inactive_lock);
1008 rw_destroy(&zfsvfs->z_fuid_lock);
1009 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
1010 mutex_destroy(&zfsvfs->z_hold_mtx[i]);
1011 kmem_free(zfsvfs, sizeof (zfsvfs_t));
1015 zfs_set_fuid_feature(zfsvfs_t *zfsvfs)
1017 zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
1018 if (zfsvfs->z_use_fuids && zfsvfs->z_vfs) {
1019 vfs_set_feature(zfsvfs->z_vfs, VFSFT_XVATTR);
1020 vfs_set_feature(zfsvfs->z_vfs, VFSFT_SYSATTR_VIEWS);
1021 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACEMASKONACCESS);
1022 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACLONCREATE);
1023 vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACCESS_FILTER);
1024 vfs_set_feature(zfsvfs->z_vfs, VFSFT_REPARSE);
1026 zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
1030 zfs_domount(vfs_t *vfsp, char *osname)
1032 uint64_t recordsize, fsid_guid;
1039 error = zfsvfs_create(osname, &zfsvfs);
1042 zfsvfs->z_vfs = vfsp;
1044 /* Initialize the generic filesystem structure. */
1045 vfsp->vfs_bcount = 0;
1046 vfsp->vfs_data = NULL;
1048 if ((error = dsl_prop_get_integer(osname, "recordsize",
1049 &recordsize, NULL)))
1052 vfsp->vfs_bsize = recordsize;
1053 vfsp->vfs_flag |= VFS_NOTRUNC;
1054 vfsp->vfs_data = zfsvfs;
1057 * The fsid is 64 bits, composed of an 8-bit fs type, which
1058 * separates our fsid from any other filesystem types, and a
1059 * 56-bit objset unique ID. The objset unique ID is unique to
1060 * all objsets open on this system, provided by unique_create().
1061 * The 8-bit fs type must be put in the low bits of fsid[1]
1062 * because that's where other Solaris filesystems put it.
1064 fsid_guid = dmu_objset_fsid_guid(zfsvfs->z_os);
1065 ASSERT((fsid_guid & ~((1ULL<<56)-1)) == 0);
1066 vfsp->vfs_fsid.val[0] = fsid_guid;
1067 vfsp->vfs_fsid.val[1] = ((fsid_guid>>32) << 8);
1070 * Set features for file system.
1072 zfs_set_fuid_feature(zfsvfs);
1073 if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE) {
1074 vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS);
1075 vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE);
1076 vfs_set_feature(vfsp, VFSFT_NOCASESENSITIVE);
1077 } else if (zfsvfs->z_case == ZFS_CASE_MIXED) {
1078 vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS);
1079 vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE);
1081 vfs_set_feature(vfsp, VFSFT_ZEROCOPY_SUPPORTED);
1083 if (dmu_objset_is_snapshot(zfsvfs->z_os)) {
1086 atime_changed_cb(zfsvfs, B_FALSE);
1087 readonly_changed_cb(zfsvfs, B_TRUE);
1088 if ((error = dsl_prop_get_integer(osname,"xattr",&pval,NULL)))
1090 xattr_changed_cb(zfsvfs, pval);
1091 zfsvfs->z_issnap = B_TRUE;
1092 zfsvfs->z_os->os_sync = ZFS_SYNC_DISABLED;
1094 mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
1095 dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
1096 mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
1098 error = zfsvfs_setup(zfsvfs, B_TRUE);
1101 if (!zfsvfs->z_issnap)
1102 zfsctl_create(zfsvfs);
1105 dmu_objset_disown(zfsvfs->z_os, zfsvfs);
1106 zfsvfs_free(zfsvfs);
1108 atomic_add_32(&zfs_active_fs_count, 1);
1113 EXPORT_SYMBOL(zfs_domount);
1116 zfs_unregister_callbacks(zfsvfs_t *zfsvfs)
1118 objset_t *os = zfsvfs->z_os;
1119 struct dsl_dataset *ds;
1122 * Unregister properties.
1124 if (!dmu_objset_is_snapshot(os)) {
1125 ds = dmu_objset_ds(os);
1126 VERIFY(dsl_prop_unregister(ds, "atime", atime_changed_cb,
1129 VERIFY(dsl_prop_unregister(ds, "xattr", xattr_changed_cb,
1132 VERIFY(dsl_prop_unregister(ds, "recordsize", blksz_changed_cb,
1135 VERIFY(dsl_prop_unregister(ds, "readonly", readonly_changed_cb,
1138 VERIFY(dsl_prop_unregister(ds, "devices", devices_changed_cb,
1141 VERIFY(dsl_prop_unregister(ds, "setuid", setuid_changed_cb,
1144 VERIFY(dsl_prop_unregister(ds, "exec", exec_changed_cb,
1147 VERIFY(dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb,
1150 VERIFY(dsl_prop_unregister(ds, "aclinherit",
1151 acl_inherit_changed_cb, zfsvfs) == 0);
1153 VERIFY(dsl_prop_unregister(ds, "vscan",
1154 vscan_changed_cb, zfsvfs) == 0);
1157 EXPORT_SYMBOL(zfs_unregister_callbacks);
1159 #ifdef HAVE_MLSLABEL
1161 * zfs_check_global_label:
1162 * Check that the hex label string is appropriate for the dataset
1163 * being mounted into the global_zone proper.
1165 * Return an error if the hex label string is not default or
1166 * admin_low/admin_high. For admin_low labels, the corresponding
1167 * dataset must be readonly.
1170 zfs_check_global_label(const char *dsname, const char *hexsl)
1172 if (strcasecmp(hexsl, ZFS_MLSLABEL_DEFAULT) == 0)
1174 if (strcasecmp(hexsl, ADMIN_HIGH) == 0)
1176 if (strcasecmp(hexsl, ADMIN_LOW) == 0) {
1177 /* must be readonly */
1180 if (dsl_prop_get_integer(dsname,
1181 zfs_prop_to_name(ZFS_PROP_READONLY), &rdonly, NULL))
1183 return (rdonly ? 0 : EACCES);
1187 #endif /* HAVE_MLSLABEL */
1190 zfs_statvfs(vfs_t *vfsp, struct statvfs64 *statp)
1192 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1194 uint64_t refdbytes, availbytes, usedobjs, availobjs;
1198 dmu_objset_space(zfsvfs->z_os,
1199 &refdbytes, &availbytes, &usedobjs, &availobjs);
1202 * The underlying storage pool actually uses multiple block sizes.
1203 * We report the fragsize as the smallest block size we support,
1204 * and we report our blocksize as the filesystem's maximum blocksize.
1206 statp->f_frsize = 1UL << SPA_MINBLOCKSHIFT;
1207 statp->f_bsize = zfsvfs->z_max_blksz;
1210 * The following report "total" blocks of various kinds in the
1211 * file system, but reported in terms of f_frsize - the
1215 statp->f_blocks = (refdbytes + availbytes) >> SPA_MINBLOCKSHIFT;
1216 statp->f_bfree = availbytes >> SPA_MINBLOCKSHIFT;
1217 statp->f_bavail = statp->f_bfree; /* no root reservation */
1220 * statvfs() should really be called statufs(), because it assumes
1221 * static metadata. ZFS doesn't preallocate files, so the best
1222 * we can do is report the max that could possibly fit in f_files,
1223 * and that minus the number actually used in f_ffree.
1224 * For f_ffree, report the smaller of the number of object available
1225 * and the number of blocks (each object will take at least a block).
1227 statp->f_ffree = MIN(availobjs, statp->f_bfree);
1228 statp->f_favail = statp->f_ffree; /* no "root reservation" */
1229 statp->f_files = statp->f_ffree + usedobjs;
1231 (void) cmpldev(&d32, vfsp->vfs_dev);
1232 statp->f_fsid = d32;
1235 * We're a zfs filesystem.
1237 (void) strcpy(statp->f_basetype, MNTTYPE_ZFS);
1239 statp->f_flag = vf_to_stf(vfsp->vfs_flag);
1241 statp->f_namemax = ZFS_MAXNAMELEN;
1244 * We have all of 32 characters to stuff a string here.
1245 * Is there anything useful we could/should provide?
1247 bzero(statp->f_fstr, sizeof (statp->f_fstr));
1252 EXPORT_SYMBOL(zfs_statvfs);
1255 zfs_root(vfs_t *vfsp, vnode_t **vpp)
1257 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1263 error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp);
1265 *vpp = ZTOV(rootzp);
1270 EXPORT_SYMBOL(zfs_root);
1273 * Teardown the zfsvfs::z_os.
1275 * Note, if 'unmounting' if FALSE, we return with the 'z_teardown_lock'
1276 * and 'z_teardown_inactive_lock' held.
1279 zfsvfs_teardown(zfsvfs_t *zfsvfs, boolean_t unmounting)
1283 rrw_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG);
1287 * We purge the parent filesystem's vfsp as the parent
1288 * filesystem and all of its snapshots have their vnode's
1289 * v_vfsp set to the parent's filesystem's vfsp. Note,
1290 * 'z_parent' is self referential for non-snapshots.
1292 (void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0);
1296 * Close the zil. NB: Can't close the zil while zfs_inactive
1297 * threads are blocked as zil_close can call zfs_inactive.
1299 if (zfsvfs->z_log) {
1300 zil_close(zfsvfs->z_log);
1301 zfsvfs->z_log = NULL;
1304 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_WRITER);
1307 * If we are not unmounting (ie: online recv) and someone already
1308 * unmounted this file system while we were doing the switcheroo,
1309 * or a reopen of z_os failed then just bail out now.
1311 if (!unmounting && (zfsvfs->z_unmounted || zfsvfs->z_os == NULL)) {
1312 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1313 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
1318 * At this point there are no vops active, and any new vops will
1319 * fail with EIO since we have z_teardown_lock for writer (only
1320 * relavent for forced unmount).
1322 * Release all holds on dbufs.
1324 mutex_enter(&zfsvfs->z_znodes_lock);
1325 for (zp = list_head(&zfsvfs->z_all_znodes); zp != NULL;
1326 zp = list_next(&zfsvfs->z_all_znodes, zp))
1328 ASSERT(ZTOV(zp)->v_count > 0);
1329 zfs_znode_dmu_fini(zp);
1331 mutex_exit(&zfsvfs->z_znodes_lock);
1334 * If we are unmounting, set the unmounted flag and let new vops
1335 * unblock. zfs_inactive will have the unmounted behavior, and all
1336 * other vops will fail with EIO.
1339 zfsvfs->z_unmounted = B_TRUE;
1340 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
1341 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1345 * z_os will be NULL if there was an error in attempting to reopen
1346 * zfsvfs, so just return as the properties had already been
1347 * unregistered and cached data had been evicted before.
1349 if (zfsvfs->z_os == NULL)
1353 * Unregister properties.
1355 zfs_unregister_callbacks(zfsvfs);
1360 if (dmu_objset_is_dirty_anywhere(zfsvfs->z_os))
1361 if (!(zfsvfs->z_vfs->vfs_flag & VFS_RDONLY))
1362 txg_wait_synced(dmu_objset_pool(zfsvfs->z_os), 0);
1363 (void) dmu_objset_evict_dbufs(zfsvfs->z_os);
1370 zfs_umount(vfs_t *vfsp, int fflag, cred_t *cr)
1372 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1376 ret = secpolicy_fs_unmount(cr, vfsp);
1378 if (dsl_deleg_access((char *)refstr_value(vfsp->vfs_resource),
1379 ZFS_DELEG_PERM_MOUNT, cr))
1384 * We purge the parent filesystem's vfsp as the parent filesystem
1385 * and all of its snapshots have their vnode's v_vfsp set to the
1386 * parent's filesystem's vfsp. Note, 'z_parent' is self
1387 * referential for non-snapshots.
1389 (void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0);
1392 * Unmount any snapshots mounted under .zfs before unmounting the
1395 if (zfsvfs->z_ctldir != NULL &&
1396 (ret = zfsctl_umount_snapshots(vfsp, fflag, cr)) != 0) {
1400 if (!(fflag & MS_FORCE)) {
1402 * Check the number of active vnodes in the file system.
1403 * Our count is maintained in the vfs structure, but the
1404 * number is off by 1 to indicate a hold on the vfs
1407 * The '.zfs' directory maintains a reference of its
1408 * own, and any active references underneath are
1409 * reflected in the vnode count.
1411 if (zfsvfs->z_ctldir == NULL) {
1412 if (vfsp->vfs_count > 1)
1415 if (vfsp->vfs_count > 2 ||
1416 zfsvfs->z_ctldir->v_count > 1)
1421 vfsp->vfs_flag |= VFS_UNMOUNTED;
1423 VERIFY(zfsvfs_teardown(zfsvfs, B_TRUE) == 0);
1427 * z_os will be NULL if there was an error in
1428 * attempting to reopen zfsvfs.
1432 * Unset the objset user_ptr.
1434 mutex_enter(&os->os_user_ptr_lock);
1435 dmu_objset_set_user(os, NULL);
1436 mutex_exit(&os->os_user_ptr_lock);
1439 * Finally release the objset
1441 dmu_objset_disown(os, zfsvfs);
1445 * We can now safely destroy the '.zfs' directory node.
1447 if (zfsvfs->z_ctldir != NULL)
1448 zfsctl_destroy(zfsvfs);
1452 EXPORT_SYMBOL(zfs_umount);
1455 zfs_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp)
1457 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1459 uint64_t object = 0;
1460 uint64_t fid_gen = 0;
1469 if (fidp->fid_len == LONG_FID_LEN) {
1470 zfid_long_t *zlfid = (zfid_long_t *)fidp;
1471 uint64_t objsetid = 0;
1472 uint64_t setgen = 0;
1474 for (i = 0; i < sizeof (zlfid->zf_setid); i++)
1475 objsetid |= ((uint64_t)zlfid->zf_setid[i]) << (8 * i);
1477 for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
1478 setgen |= ((uint64_t)zlfid->zf_setgen[i]) << (8 * i);
1482 err = zfsctl_lookup_objset(vfsp, objsetid, &zfsvfs);
1488 if (fidp->fid_len == SHORT_FID_LEN || fidp->fid_len == LONG_FID_LEN) {
1489 zfid_short_t *zfid = (zfid_short_t *)fidp;
1491 for (i = 0; i < sizeof (zfid->zf_object); i++)
1492 object |= ((uint64_t)zfid->zf_object[i]) << (8 * i);
1494 for (i = 0; i < sizeof (zfid->zf_gen); i++)
1495 fid_gen |= ((uint64_t)zfid->zf_gen[i]) << (8 * i);
1501 /* A zero fid_gen means we are in the .zfs control directories */
1503 (object == ZFSCTL_INO_ROOT || object == ZFSCTL_INO_SNAPDIR)) {
1504 *vpp = zfsvfs->z_ctldir;
1505 ASSERT(*vpp != NULL);
1506 if (object == ZFSCTL_INO_SNAPDIR) {
1507 VERIFY(zfsctl_root_lookup(*vpp, "snapshot", vpp, NULL,
1508 0, NULL, NULL, NULL, NULL, NULL) == 0);
1516 gen_mask = -1ULL >> (64 - 8 * i);
1518 dprintf("getting %llu [%u mask %llx]\n", object, fid_gen, gen_mask);
1519 if ((err = zfs_zget(zfsvfs, object, &zp))) {
1523 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zfsvfs), &zp_gen,
1525 zp_gen = zp_gen & gen_mask;
1528 if (zp->z_unlinked || zp_gen != fid_gen) {
1529 dprintf("znode gen (%u) != fid gen (%u)\n", zp_gen, fid_gen);
1537 zfs_inode_update(VTOZ(*vpp));
1542 EXPORT_SYMBOL(zfs_vget);
1545 * Block out VOPs and close zfsvfs_t::z_os
1547 * Note, if successful, then we return with the 'z_teardown_lock' and
1548 * 'z_teardown_inactive_lock' write held.
1551 zfs_suspend_fs(zfsvfs_t *zfsvfs)
1555 if ((error = zfsvfs_teardown(zfsvfs, B_FALSE)) != 0)
1557 dmu_objset_disown(zfsvfs->z_os, zfsvfs);
1561 EXPORT_SYMBOL(zfs_suspend_fs);
1564 * Reopen zfsvfs_t::z_os and release VOPs.
1567 zfs_resume_fs(zfsvfs_t *zfsvfs, const char *osname)
1571 ASSERT(RRW_WRITE_HELD(&zfsvfs->z_teardown_lock));
1572 ASSERT(RW_WRITE_HELD(&zfsvfs->z_teardown_inactive_lock));
1574 err = dmu_objset_own(osname, DMU_OST_ZFS, B_FALSE, zfsvfs,
1577 zfsvfs->z_os = NULL;
1580 uint64_t sa_obj = 0;
1582 err2 = zap_lookup(zfsvfs->z_os, MASTER_NODE_OBJ,
1583 ZFS_SA_ATTRS, 8, 1, &sa_obj);
1585 if ((err || err2) && zfsvfs->z_version >= ZPL_VERSION_SA)
1589 if ((err = sa_setup(zfsvfs->z_os, sa_obj,
1590 zfs_attr_table, ZPL_END, &zfsvfs->z_attr_table)) != 0)
1593 VERIFY(zfsvfs_setup(zfsvfs, B_FALSE) == 0);
1596 * Attempt to re-establish all the active znodes with
1597 * their dbufs. If a zfs_rezget() fails, then we'll let
1598 * any potential callers discover that via ZFS_ENTER_VERIFY_VP
1599 * when they try to use their znode.
1601 mutex_enter(&zfsvfs->z_znodes_lock);
1602 for (zp = list_head(&zfsvfs->z_all_znodes); zp;
1603 zp = list_next(&zfsvfs->z_all_znodes, zp)) {
1604 (void) zfs_rezget(zp);
1606 mutex_exit(&zfsvfs->z_znodes_lock);
1611 /* release the VOPs */
1612 rw_exit(&zfsvfs->z_teardown_inactive_lock);
1613 rrw_exit(&zfsvfs->z_teardown_lock, FTAG);
1617 * Since we couldn't reopen zfsvfs::z_os, force
1618 * unmount this file system.
1620 if (vn_vfswlock(zfsvfs->z_vfs->vfs_vnodecovered) == 0)
1621 (void) dounmount(zfsvfs->z_vfs, MS_FORCE, CRED());
1625 EXPORT_SYMBOL(zfs_resume_fs);
1628 zfs_freevfs(vfs_t *vfsp)
1630 zfsvfs_t *zfsvfs = vfsp->vfs_data;
1632 zfsvfs_free(zfsvfs);
1634 atomic_add_32(&zfs_active_fs_count, -1);
1636 #endif /* HAVE_ZPL */
1644 dmu_objset_register_type(DMU_OST_ZFS, zfs_space_delta_cb);
1656 zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers)
1659 objset_t *os = zfsvfs->z_os;
1662 if (newvers < ZPL_VERSION_INITIAL || newvers > ZPL_VERSION)
1665 if (newvers < zfsvfs->z_version)
1668 if (zfs_spa_version_map(newvers) >
1669 spa_version(dmu_objset_spa(zfsvfs->z_os)))
1672 tx = dmu_tx_create(os);
1673 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_FALSE, ZPL_VERSION_STR);
1674 if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
1675 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE,
1677 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
1679 error = dmu_tx_assign(tx, TXG_WAIT);
1685 error = zap_update(os, MASTER_NODE_OBJ, ZPL_VERSION_STR,
1686 8, 1, &newvers, tx);
1693 if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
1696 ASSERT3U(spa_version(dmu_objset_spa(zfsvfs->z_os)), >=,
1698 sa_obj = zap_create(os, DMU_OT_SA_MASTER_NODE,
1699 DMU_OT_NONE, 0, tx);
1701 error = zap_add(os, MASTER_NODE_OBJ,
1702 ZFS_SA_ATTRS, 8, 1, &sa_obj, tx);
1703 ASSERT3U(error, ==, 0);
1705 VERIFY(0 == sa_set_sa_object(os, sa_obj));
1706 sa_register_update_callback(os, zfs_sa_upgrade);
1709 spa_history_log_internal(LOG_DS_UPGRADE,
1710 dmu_objset_spa(os), tx, "oldver=%llu newver=%llu dataset = %llu",
1711 zfsvfs->z_version, newvers, dmu_objset_id(os));
1715 zfsvfs->z_version = newvers;
1717 if (zfsvfs->z_version >= ZPL_VERSION_FUID)
1718 zfs_set_fuid_feature(zfsvfs);
1722 EXPORT_SYMBOL(zfs_set_version);
1723 #endif /* HAVE_ZPL */
1726 * Read a property stored within the master node.
1729 zfs_get_zplprop(objset_t *os, zfs_prop_t prop, uint64_t *value)
1735 * Look up the file system's value for the property. For the
1736 * version property, we look up a slightly different string.
1738 if (prop == ZFS_PROP_VERSION)
1739 pname = ZPL_VERSION_STR;
1741 pname = zfs_prop_to_name(prop);
1744 error = zap_lookup(os, MASTER_NODE_OBJ, pname, 8, 1, value);
1746 if (error == ENOENT) {
1747 /* No value set, use the default value */
1749 case ZFS_PROP_VERSION:
1750 *value = ZPL_VERSION;
1752 case ZFS_PROP_NORMALIZE:
1753 case ZFS_PROP_UTF8ONLY:
1757 *value = ZFS_CASE_SENSITIVE;