xref: /illumos-gate/usr/src/uts/common/fs/zfs/zfs_vfsops.c (revision a39df08c)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5033f9833Sek  * Common Development and Distribution License (the "License").
6033f9833Sek  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
22dc7cd546SMark Shellenbaum  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
231fdcbd00SMatthew Ahrens  * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
24c3d26abcSMatthew Ahrens  * Copyright (c) 2014 Integros [integros.com]
25eb721827SAlek Pinchuk  * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
26f67950b2SNasf-Fan  * Copyright 2019 Joyent, Inc.
2730c304d9SJoshua M. Clulow  * Copyright 2020 Joshua M. Clulow <josh@sysmgr.org>
28b39b008fSAndy Fiddaman  * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
29fa9e4066Sahrens  */
30fa9e4066Sahrens 
3155da60b9SMark J Musante /* Portions Copyright 2010 Robert Milkowski */
3255da60b9SMark J Musante 
33fa9e4066Sahrens #include <sys/types.h>
34fa9e4066Sahrens #include <sys/param.h>
35fa9e4066Sahrens #include <sys/systm.h>
36fa9e4066Sahrens #include <sys/sysmacros.h>
37fa9e4066Sahrens #include <sys/kmem.h>
38fa9e4066Sahrens #include <sys/pathname.h>
39fa9e4066Sahrens #include <sys/vnode.h>
40fa9e4066Sahrens #include <sys/vfs.h>
41aa59c4cbSrsb #include <sys/vfs_opreg.h>
42fa9e4066Sahrens #include <sys/mntent.h>
43fa9e4066Sahrens #include <sys/mount.h>
44fa9e4066Sahrens #include <sys/cmn_err.h>
45fa9e4066Sahrens #include "fs/fs_subr.h"
46fa9e4066Sahrens #include <sys/zfs_znode.h>
47893a6d32Sahrens #include <sys/zfs_dir.h>
48fa9e4066Sahrens #include <sys/zil.h>
49fa9e4066Sahrens #include <sys/fs/zfs.h>
50fa9e4066Sahrens #include <sys/dmu.h>
51fa9e4066Sahrens #include <sys/dsl_prop.h>
52b1b8ab34Slling #include <sys/dsl_dataset.h>
53ecd6cf80Smarks #include <sys/dsl_deleg.h>
54fa9e4066Sahrens #include <sys/spa.h>
55fa9e4066Sahrens #include <sys/zap.h>
560a586ceaSMark Shellenbaum #include <sys/sa.h>
57e828a46dSMatthew Ahrens #include <sys/sa_impl.h>
58fa9e4066Sahrens #include <sys/varargs.h>
59fa9e4066Sahrens #include <sys/policy.h>
60fa9e4066Sahrens #include <sys/atomic.h>
61fa9e4066Sahrens #include <sys/mkdev.h>
62fa9e4066Sahrens #include <sys/modctl.h>
63ecd6cf80Smarks #include <sys/refstr.h>
64fa9e4066Sahrens #include <sys/zfs_ioctl.h>
65fa9e4066Sahrens #include <sys/zfs_ctldir.h>
66da6c28aaSamw #include <sys/zfs_fuid.h>
67ea8dc4b6Seschrock #include <sys/bootconf.h>
6830c304d9SJoshua M. Clulow #include <sys/ddi.h>
69a0965f35Sbonwick #include <sys/sunddi.h>
70033f9833Sek #include <sys/dnlc.h>
71f18faf3fSek #include <sys/dmu_objset.h>
72e7cbe64fSgw #include <sys/spa_boot.h>
7330c304d9SJoshua M. Clulow #include <sys/vdev_impl.h>
740a586ceaSMark Shellenbaum #include "zfs_comutil.h"
75fa9e4066Sahrens 
76fa9e4066Sahrens int zfsfstype;
77fa9e4066Sahrens vfsops_t *zfs_vfsops = NULL;
78a0965f35Sbonwick static major_t zfs_major;
79fa9e4066Sahrens static minor_t zfs_minor;
80fa9e4066Sahrens static kmutex_t	zfs_dev_mtx;
81fa9e4066Sahrens 
8254d692b7SGeorge Wilson extern int sys_shutdown;
8354d692b7SGeorge Wilson 
84fa9e4066Sahrens static int zfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr);
85fa9e4066Sahrens static int zfs_umount(vfs_t *vfsp, int fflag, cred_t *cr);
86ea8dc4b6Seschrock static int zfs_mountroot(vfs_t *vfsp, enum whymountroot);
87fa9e4066Sahrens static int zfs_root(vfs_t *vfsp, vnode_t **vpp);
88fa9e4066Sahrens static int zfs_statvfs(vfs_t *vfsp, struct statvfs64 *statp);
89fa9e4066Sahrens static int zfs_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp);
90fa9e4066Sahrens static void zfs_freevfs(vfs_t *vfsp);
91fa9e4066Sahrens 
92fa9e4066Sahrens static const fs_operation_def_t zfs_vfsops_template[] = {
93aa59c4cbSrsb 	VFSNAME_MOUNT,		{ .vfs_mount = zfs_mount },
94aa59c4cbSrsb 	VFSNAME_MOUNTROOT,	{ .vfs_mountroot = zfs_mountroot },
95aa59c4cbSrsb 	VFSNAME_UNMOUNT,	{ .vfs_unmount = zfs_umount },
96aa59c4cbSrsb 	VFSNAME_ROOT,		{ .vfs_root = zfs_root },
97aa59c4cbSrsb 	VFSNAME_STATVFS,	{ .vfs_statvfs = zfs_statvfs },
98aa59c4cbSrsb 	VFSNAME_SYNC,		{ .vfs_sync = zfs_sync },
99aa59c4cbSrsb 	VFSNAME_VGET,		{ .vfs_vget = zfs_vget },
100aa59c4cbSrsb 	VFSNAME_FREEVFS,	{ .vfs_freevfs = zfs_freevfs },
101aa59c4cbSrsb 	NULL,			NULL
102fa9e4066Sahrens };
103fa9e4066Sahrens 
104fa9e4066Sahrens /*
105fa9e4066Sahrens  * We need to keep a count of active fs's.
106fa9e4066Sahrens  * This is necessary to prevent our module
107fa9e4066Sahrens  * from being unloaded after a umount -f
108fa9e4066Sahrens  */
109fa9e4066Sahrens static uint32_t	zfs_active_fs_count = 0;
110fa9e4066Sahrens 
111fa9e4066Sahrens static char *noatime_cancel[] = { MNTOPT_ATIME, NULL };
112fa9e4066Sahrens static char *atime_cancel[] = { MNTOPT_NOATIME, NULL };
1137b55fa8eSck static char *noxattr_cancel[] = { MNTOPT_XATTR, NULL };
1147b55fa8eSck static char *xattr_cancel[] = { MNTOPT_NOXATTR, NULL };
115fa9e4066Sahrens 
1167b55fa8eSck /*
117b510d378Slling  * MO_DEFAULT is not used since the default value is determined
118b510d378Slling  * by the equivalent property.
1197b55fa8eSck  */
120fa9e4066Sahrens static mntopt_t mntopts[] = {
1217b55fa8eSck 	{ MNTOPT_NOXATTR, noxattr_cancel, NULL, 0, NULL },
1227b55fa8eSck 	{ MNTOPT_XATTR, xattr_cancel, NULL, 0, NULL },
123b510d378Slling 	{ MNTOPT_NOATIME, noatime_cancel, NULL, 0, NULL },
124fa9e4066Sahrens 	{ MNTOPT_ATIME, atime_cancel, NULL, 0, NULL }
125fa9e4066Sahrens };
126fa9e4066Sahrens 
127fa9e4066Sahrens static mntopts_t zfs_mntopts = {
128fa9e4066Sahrens 	sizeof (mntopts) / sizeof (mntopt_t),
129fa9e4066Sahrens 	mntopts
130fa9e4066Sahrens };
131fa9e4066Sahrens 
132fa9e4066Sahrens /*ARGSUSED*/
133fa9e4066Sahrens int
zfs_sync(vfs_t * vfsp,short flag,cred_t * cr)134fa9e4066Sahrens zfs_sync(vfs_t *vfsp, short flag, cred_t *cr)
135fa9e4066Sahrens {
136fa9e4066Sahrens 	/*
137fa9e4066Sahrens 	 * Data integrity is job one.  We don't want a compromised kernel
138fa9e4066Sahrens 	 * writing to the storage pool, so we never sync during panic.
139fa9e4066Sahrens 	 */
140fa9e4066Sahrens 	if (panicstr)
141fa9e4066Sahrens 		return (0);
142fa9e4066Sahrens 
143fa9e4066Sahrens 	/*
144fa9e4066Sahrens 	 * SYNC_ATTR is used by fsflush() to force old filesystems like UFS
145fa9e4066Sahrens 	 * to sync metadata, which they would otherwise cache indefinitely.
146fa9e4066Sahrens 	 * Semantically, the only requirement is that the sync be initiated.
147fa9e4066Sahrens 	 * The DMU syncs out txgs frequently, so there's nothing to do.
148fa9e4066Sahrens 	 */
149fa9e4066Sahrens 	if (flag & SYNC_ATTR)
150fa9e4066Sahrens 		return (0);
151fa9e4066Sahrens 
152fa9e4066Sahrens 	if (vfsp != NULL) {
153fa9e4066Sahrens 		/*
154fa9e4066Sahrens 		 * Sync a specific filesystem.
155fa9e4066Sahrens 		 */
156fa9e4066Sahrens 		zfsvfs_t *zfsvfs = vfsp->vfs_data;
15754d692b7SGeorge Wilson 		dsl_pool_t *dp;
158fa9e4066Sahrens 
159fa9e4066Sahrens 		ZFS_ENTER(zfsvfs);
16054d692b7SGeorge Wilson 		dp = dmu_objset_pool(zfsvfs->z_os);
16154d692b7SGeorge Wilson 
16254d692b7SGeorge Wilson 		/*
16354d692b7SGeorge Wilson 		 * If the system is shutting down, then skip any
16454d692b7SGeorge Wilson 		 * filesystems which may exist on a suspended pool.
16554d692b7SGeorge Wilson 		 */
16654d692b7SGeorge Wilson 		if (sys_shutdown && spa_suspended(dp->dp_spa)) {
16754d692b7SGeorge Wilson 			ZFS_EXIT(zfsvfs);
16854d692b7SGeorge Wilson 			return (0);
16954d692b7SGeorge Wilson 		}
17054d692b7SGeorge Wilson 
171fa9e4066Sahrens 		if (zfsvfs->z_log != NULL)
1725002558fSNeil Perrin 			zil_commit(zfsvfs->z_log, 0);
17355da60b9SMark J Musante 
174fa9e4066Sahrens 		ZFS_EXIT(zfsvfs);
175fa9e4066Sahrens 	} else {
176fa9e4066Sahrens 		/*
177fa9e4066Sahrens 		 * Sync all ZFS filesystems.  This is what happens when you
178fa9e4066Sahrens 		 * run sync(1M).  Unlike other filesystems, ZFS honors the
179fa9e4066Sahrens 		 * request by waiting for all pools to commit all dirty data.
180fa9e4066Sahrens 		 */
181fa9e4066Sahrens 		spa_sync_allpools();
182fa9e4066Sahrens 	}
183fa9e4066Sahrens 
184fa9e4066Sahrens 	return (0);
185fa9e4066Sahrens }
186fa9e4066Sahrens 
187ea8dc4b6Seschrock static int
zfs_create_unique_device(dev_t * dev)188ea8dc4b6Seschrock zfs_create_unique_device(dev_t *dev)
189ea8dc4b6Seschrock {
190ea8dc4b6Seschrock 	major_t new_major;
191ea8dc4b6Seschrock 
192ea8dc4b6Seschrock 	do {
193ea8dc4b6Seschrock 		ASSERT3U(zfs_minor, <=, MAXMIN32);
194ea8dc4b6Seschrock 		minor_t start = zfs_minor;
195ea8dc4b6Seschrock 		do {
196ea8dc4b6Seschrock 			mutex_enter(&zfs_dev_mtx);
197ea8dc4b6Seschrock 			if (zfs_minor >= MAXMIN32) {
198ea8dc4b6Seschrock 				/*
199ea8dc4b6Seschrock 				 * If we're still using the real major
200ea8dc4b6Seschrock 				 * keep out of /dev/zfs and /dev/zvol minor
201ea8dc4b6Seschrock 				 * number space.  If we're using a getudev()'ed
202ea8dc4b6Seschrock 				 * major number, we can use all of its minors.
203ea8dc4b6Seschrock 				 */
204ea8dc4b6Seschrock 				if (zfs_major == ddi_name_to_major(ZFS_DRIVER))
205ea8dc4b6Seschrock 					zfs_minor = ZFS_MIN_MINOR;
206ea8dc4b6Seschrock 				else
207ea8dc4b6Seschrock 					zfs_minor = 0;
208ea8dc4b6Seschrock 			} else {
209ea8dc4b6Seschrock 				zfs_minor++;
210ea8dc4b6Seschrock 			}
211ea8dc4b6Seschrock 			*dev = makedevice(zfs_major, zfs_minor);
212ea8dc4b6Seschrock 			mutex_exit(&zfs_dev_mtx);
213ea8dc4b6Seschrock 		} while (vfs_devismounted(*dev) && zfs_minor != start);
214ea8dc4b6Seschrock 		if (zfs_minor == start) {
215ea8dc4b6Seschrock 			/*
216ea8dc4b6Seschrock 			 * We are using all ~262,000 minor numbers for the
217ea8dc4b6Seschrock 			 * current major number.  Create a new major number.
218ea8dc4b6Seschrock 			 */
219ea8dc4b6Seschrock 			if ((new_major = getudev()) == (major_t)-1) {
220ea8dc4b6Seschrock 				cmn_err(CE_WARN,
221ea8dc4b6Seschrock 				    "zfs_mount: Can't get unique major "
222ea8dc4b6Seschrock 				    "device number.");
223ea8dc4b6Seschrock 				return (-1);
224ea8dc4b6Seschrock 			}
225ea8dc4b6Seschrock 			mutex_enter(&zfs_dev_mtx);
226ea8dc4b6Seschrock 			zfs_major = new_major;
227ea8dc4b6Seschrock 			zfs_minor = 0;
228ea8dc4b6Seschrock 
229ea8dc4b6Seschrock 			mutex_exit(&zfs_dev_mtx);
230ea8dc4b6Seschrock 		} else {
231ea8dc4b6Seschrock 			break;
232ea8dc4b6Seschrock 		}
233ea8dc4b6Seschrock 		/* CONSTANTCONDITION */
234ea8dc4b6Seschrock 	} while (1);
235ea8dc4b6Seschrock 
236ea8dc4b6Seschrock 	return (0);
237ea8dc4b6Seschrock }
238ea8dc4b6Seschrock 
239fa9e4066Sahrens static void
atime_changed_cb(void * arg,uint64_t newval)240fa9e4066Sahrens atime_changed_cb(void *arg, uint64_t newval)
241fa9e4066Sahrens {
242fa9e4066Sahrens 	zfsvfs_t *zfsvfs = arg;
243fa9e4066Sahrens 
244fa9e4066Sahrens 	if (newval == TRUE) {
245fa9e4066Sahrens 		zfsvfs->z_atime = TRUE;
246fa9e4066Sahrens 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME);
247fa9e4066Sahrens 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_ATIME, NULL, 0);
248fa9e4066Sahrens 	} else {
249fa9e4066Sahrens 		zfsvfs->z_atime = FALSE;
250fa9e4066Sahrens 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_ATIME);
251fa9e4066Sahrens 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME, NULL, 0);
252fa9e4066Sahrens 	}
253fa9e4066Sahrens }
254fa9e4066Sahrens 
2557b55fa8eSck static void
xattr_changed_cb(void * arg,uint64_t newval)2567b55fa8eSck xattr_changed_cb(void *arg, uint64_t newval)
2577b55fa8eSck {
2587b55fa8eSck 	zfsvfs_t *zfsvfs = arg;
2597b55fa8eSck 
2607b55fa8eSck 	if (newval == TRUE) {
2617b55fa8eSck 		/* XXX locking on vfs_flag? */
2627b55fa8eSck 		zfsvfs->z_vfs->vfs_flag |= VFS_XATTR;
2637b55fa8eSck 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR);
2647b55fa8eSck 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_XATTR, NULL, 0);
2657b55fa8eSck 	} else {
2667b55fa8eSck 		/* XXX locking on vfs_flag? */
2677b55fa8eSck 		zfsvfs->z_vfs->vfs_flag &= ~VFS_XATTR;
2687b55fa8eSck 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_XATTR);
2697b55fa8eSck 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR, NULL, 0);
2707b55fa8eSck 	}
2717b55fa8eSck }
2727b55fa8eSck 
273fa9e4066Sahrens static void
blksz_changed_cb(void * arg,uint64_t newval)274fa9e4066Sahrens blksz_changed_cb(void *arg, uint64_t newval)
275fa9e4066Sahrens {
276fa9e4066Sahrens 	zfsvfs_t *zfsvfs = arg;
277b5152584SMatthew Ahrens 	ASSERT3U(newval, <=, spa_maxblocksize(dmu_objset_spa(zfsvfs->z_os)));
278b5152584SMatthew Ahrens 	ASSERT3U(newval, >=, SPA_MINBLOCKSIZE);
279b5152584SMatthew Ahrens 	ASSERT(ISP2(newval));
280fa9e4066Sahrens 
281fa9e4066Sahrens 	zfsvfs->z_max_blksz = newval;
282fa9e4066Sahrens 	zfsvfs->z_vfs->vfs_bsize = newval;
283fa9e4066Sahrens }
284fa9e4066Sahrens 
285fa9e4066Sahrens static void
readonly_changed_cb(void * arg,uint64_t newval)286fa9e4066Sahrens readonly_changed_cb(void *arg, uint64_t newval)
287fa9e4066Sahrens {
288fa9e4066Sahrens 	zfsvfs_t *zfsvfs = arg;
289fa9e4066Sahrens 
290fa9e4066Sahrens 	if (newval) {
291fa9e4066Sahrens 		/* XXX locking on vfs_flag? */
292fa9e4066Sahrens 		zfsvfs->z_vfs->vfs_flag |= VFS_RDONLY;
293fa9e4066Sahrens 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RW);
294fa9e4066Sahrens 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RO, NULL, 0);
295fa9e4066Sahrens 	} else {
296fa9e4066Sahrens 		/* XXX locking on vfs_flag? */
297fa9e4066Sahrens 		zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY;
298fa9e4066Sahrens 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RO);
299fa9e4066Sahrens 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RW, NULL, 0);
300fa9e4066Sahrens 	}
301fa9e4066Sahrens }
302fa9e4066Sahrens 
303fa9e4066Sahrens static void
devices_changed_cb(void * arg,uint64_t newval)304fa9e4066Sahrens devices_changed_cb(void *arg, uint64_t newval)
305fa9e4066Sahrens {
306fa9e4066Sahrens 	zfsvfs_t *zfsvfs = arg;
307fa9e4066Sahrens 
308fa9e4066Sahrens 	if (newval == FALSE) {
309fa9e4066Sahrens 		zfsvfs->z_vfs->vfs_flag |= VFS_NODEVICES;
310fa9e4066Sahrens 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES);
311fa9e4066Sahrens 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES, NULL, 0);
312fa9e4066Sahrens 	} else {
313fa9e4066Sahrens 		zfsvfs->z_vfs->vfs_flag &= ~VFS_NODEVICES;
314fa9e4066Sahrens 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES);
315fa9e4066Sahrens 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES, NULL, 0);
316fa9e4066Sahrens 	}
317fa9e4066Sahrens }
318fa9e4066Sahrens 
319fa9e4066Sahrens static void
setuid_changed_cb(void * arg,uint64_t newval)320fa9e4066Sahrens setuid_changed_cb(void *arg, uint64_t newval)
321fa9e4066Sahrens {
322fa9e4066Sahrens 	zfsvfs_t *zfsvfs = arg;
323fa9e4066Sahrens 
324fa9e4066Sahrens 	if (newval == FALSE) {
325fa9e4066Sahrens 		zfsvfs->z_vfs->vfs_flag |= VFS_NOSETUID;
326fa9e4066Sahrens 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_SETUID);
327fa9e4066Sahrens 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID, NULL, 0);
328fa9e4066Sahrens 	} else {
329fa9e4066Sahrens 		zfsvfs->z_vfs->vfs_flag &= ~VFS_NOSETUID;
330fa9e4066Sahrens 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID);
331fa9e4066Sahrens 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_SETUID, NULL, 0);
332fa9e4066Sahrens 	}
333fa9e4066Sahrens }
334fa9e4066Sahrens 
335fa9e4066Sahrens static void
exec_changed_cb(void * arg,uint64_t newval)336fa9e4066Sahrens exec_changed_cb(void *arg, uint64_t newval)
337fa9e4066Sahrens {
338fa9e4066Sahrens 	zfsvfs_t *zfsvfs = arg;
339fa9e4066Sahrens 
340fa9e4066Sahrens 	if (newval == FALSE) {
341fa9e4066Sahrens 		zfsvfs->z_vfs->vfs_flag |= VFS_NOEXEC;
342fa9e4066Sahrens 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_EXEC);
343fa9e4066Sahrens 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC, NULL, 0);
344fa9e4066Sahrens 	} else {
345fa9e4066Sahrens 		zfsvfs->z_vfs->vfs_flag &= ~VFS_NOEXEC;
346fa9e4066Sahrens 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC);
347fa9e4066Sahrens 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_EXEC, NULL, 0);
348fa9e4066Sahrens 	}
349fa9e4066Sahrens }
350fa9e4066Sahrens 
351da6c28aaSamw /*
352da6c28aaSamw  * The nbmand mount option can be changed at mount time.
353da6c28aaSamw  * We can't allow it to be toggled on live file systems or incorrect
354da6c28aaSamw  * behavior may be seen from cifs clients
355da6c28aaSamw  *
356da6c28aaSamw  * This property isn't registered via dsl_prop_register(), but this callback
357da6c28aaSamw  * will be called when a file system is first mounted
358da6c28aaSamw  */
359da6c28aaSamw static void
nbmand_changed_cb(void * arg,uint64_t newval)360da6c28aaSamw nbmand_changed_cb(void *arg, uint64_t newval)
361da6c28aaSamw {
362da6c28aaSamw 	zfsvfs_t *zfsvfs = arg;
363da6c28aaSamw 	if (newval == FALSE) {
364da6c28aaSamw 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND);
365da6c28aaSamw 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND, NULL, 0);
366da6c28aaSamw 	} else {
367da6c28aaSamw 		vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND);
368da6c28aaSamw 		vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND, NULL, 0);
369da6c28aaSamw 	}
370da6c28aaSamw }
371da6c28aaSamw 
372fa9e4066Sahrens static void
snapdir_changed_cb(void * arg,uint64_t newval)373fa9e4066Sahrens snapdir_changed_cb(void *arg, uint64_t newval)
374fa9e4066Sahrens {
375fa9e4066Sahrens 	zfsvfs_t *zfsvfs = arg;
376fa9e4066Sahrens 
377fa9e4066Sahrens 	zfsvfs->z_show_ctldir = newval;
378fa9e4066Sahrens }
379fa9e4066Sahrens 
380da6c28aaSamw static void
vscan_changed_cb(void * arg,uint64_t newval)381da6c28aaSamw vscan_changed_cb(void *arg, uint64_t newval)
382da6c28aaSamw {
383da6c28aaSamw 	zfsvfs_t *zfsvfs = arg;
384da6c28aaSamw 
385da6c28aaSamw 	zfsvfs->z_vscan = newval;
386da6c28aaSamw }
387da6c28aaSamw 
388a3c49ce1SAlbert Lee static void
acl_mode_changed_cb(void * arg,uint64_t newval)389a3c49ce1SAlbert Lee acl_mode_changed_cb(void *arg, uint64_t newval)
390a3c49ce1SAlbert Lee {
391a3c49ce1SAlbert Lee 	zfsvfs_t *zfsvfs = arg;
392a3c49ce1SAlbert Lee 
393a3c49ce1SAlbert Lee 	zfsvfs->z_acl_mode = newval;
394a3c49ce1SAlbert Lee }
395a3c49ce1SAlbert Lee 
396fa9e4066Sahrens static void
acl_inherit_changed_cb(void * arg,uint64_t newval)397fa9e4066Sahrens acl_inherit_changed_cb(void *arg, uint64_t newval)
398fa9e4066Sahrens {
399fa9e4066Sahrens 	zfsvfs_t *zfsvfs = arg;
400fa9e4066Sahrens 
401fa9e4066Sahrens 	zfsvfs->z_acl_inherit = newval;
402fa9e4066Sahrens }
403fa9e4066Sahrens 
404ea8dc4b6Seschrock static int
zfs_register_callbacks(vfs_t * vfsp)405ea8dc4b6Seschrock zfs_register_callbacks(vfs_t *vfsp)
406ea8dc4b6Seschrock {
407ea8dc4b6Seschrock 	struct dsl_dataset *ds = NULL;
408ea8dc4b6Seschrock 	objset_t *os = NULL;
409ea8dc4b6Seschrock 	zfsvfs_t *zfsvfs = NULL;
410da6c28aaSamw 	uint64_t nbmand;
411d5285caeSGeorge Wilson 	boolean_t readonly = B_FALSE;
412d5285caeSGeorge Wilson 	boolean_t do_readonly = B_FALSE;
413d5285caeSGeorge Wilson 	boolean_t setuid = B_FALSE;
414d5285caeSGeorge Wilson 	boolean_t do_setuid = B_FALSE;
415d5285caeSGeorge Wilson 	boolean_t exec = B_FALSE;
416d5285caeSGeorge Wilson 	boolean_t do_exec = B_FALSE;
417d5285caeSGeorge Wilson 	boolean_t devices = B_FALSE;
418d5285caeSGeorge Wilson 	boolean_t do_devices = B_FALSE;
419d5285caeSGeorge Wilson 	boolean_t xattr = B_FALSE;
420d5285caeSGeorge Wilson 	boolean_t do_xattr = B_FALSE;
421d5285caeSGeorge Wilson 	boolean_t atime = B_FALSE;
422d5285caeSGeorge Wilson 	boolean_t do_atime = B_FALSE;
423ea8dc4b6Seschrock 	int error = 0;
424ea8dc4b6Seschrock 
425ea8dc4b6Seschrock 	ASSERT(vfsp);
426ea8dc4b6Seschrock 	zfsvfs = vfsp->vfs_data;
427ea8dc4b6Seschrock 	ASSERT(zfsvfs);
428ea8dc4b6Seschrock 	os = zfsvfs->z_os;
429fa9e4066Sahrens 
430fa9e4066Sahrens 	/*
431ea8dc4b6Seschrock 	 * The act of registering our callbacks will destroy any mount
432ea8dc4b6Seschrock 	 * options we may have.  In order to enable temporary overrides
4337b55fa8eSck 	 * of mount options, we stash away the current values and
434ea8dc4b6Seschrock 	 * restore them after we register the callbacks.
435