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