xref: /onnv-gate/usr/src/uts/common/fs/autofs/auto_vfsops.c (revision 11185:f0c31008e395)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51488Srsb  * Common Development and Distribution License (the "License").
61488Srsb  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*11185SSean.McEnroe@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <sys/param.h>
270Sstevel@tonic-gate #include <sys/errno.h>
280Sstevel@tonic-gate #include <sys/proc.h>
290Sstevel@tonic-gate #include <sys/disp.h>
300Sstevel@tonic-gate #include <sys/vfs.h>
313898Srsb #include <sys/vfs_opreg.h>
320Sstevel@tonic-gate #include <sys/vnode.h>
330Sstevel@tonic-gate #include <sys/uio.h>
340Sstevel@tonic-gate #include <sys/kmem.h>
350Sstevel@tonic-gate #include <sys/cred.h>
360Sstevel@tonic-gate #include <sys/statvfs.h>
370Sstevel@tonic-gate #include <sys/mount.h>
380Sstevel@tonic-gate #include <sys/tiuser.h>
390Sstevel@tonic-gate #include <sys/cmn_err.h>
400Sstevel@tonic-gate #include <sys/debug.h>
410Sstevel@tonic-gate #include <sys/systm.h>
420Sstevel@tonic-gate #include <sys/sysmacros.h>
430Sstevel@tonic-gate #include <sys/pathname.h>
440Sstevel@tonic-gate #include <rpc/types.h>
450Sstevel@tonic-gate #include <rpc/auth.h>
460Sstevel@tonic-gate #include <rpc/clnt.h>
470Sstevel@tonic-gate #include <fs/fs_subr.h>
480Sstevel@tonic-gate #include <sys/fs/autofs.h>
490Sstevel@tonic-gate #include <sys/modctl.h>
500Sstevel@tonic-gate #include <sys/mntent.h>
510Sstevel@tonic-gate #include <sys/policy.h>
520Sstevel@tonic-gate #include <sys/zone.h>
530Sstevel@tonic-gate 
540Sstevel@tonic-gate static int autofs_init(int, char *);
550Sstevel@tonic-gate 
560Sstevel@tonic-gate static major_t autofs_major;
570Sstevel@tonic-gate static minor_t autofs_minor;
580Sstevel@tonic-gate 
594092Sevanl kmutex_t autofs_minor_lock;
600Sstevel@tonic-gate zone_key_t autofs_key;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate static mntopts_t auto_mntopts;
630Sstevel@tonic-gate 
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate  * The AUTOFS system call.
660Sstevel@tonic-gate  */
670Sstevel@tonic-gate static struct sysent autofssysent = {
680Sstevel@tonic-gate 	2,
690Sstevel@tonic-gate 	SE_32RVAL1 | SE_ARGC | SE_NOUNLOAD,
700Sstevel@tonic-gate 	autofssys
710Sstevel@tonic-gate };
720Sstevel@tonic-gate 
730Sstevel@tonic-gate static struct modlsys modlsys = {
740Sstevel@tonic-gate 	&mod_syscallops,
750Sstevel@tonic-gate 	"AUTOFS syscall",
760Sstevel@tonic-gate 	&autofssysent
770Sstevel@tonic-gate };
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #ifdef	_SYSCALL32_IMPL
800Sstevel@tonic-gate static struct modlsys  modlsys32 = {
810Sstevel@tonic-gate 	&mod_syscallops32,
820Sstevel@tonic-gate 	"AUTOFS syscall (32-bit)",
830Sstevel@tonic-gate 	&autofssysent
840Sstevel@tonic-gate };
850Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
860Sstevel@tonic-gate 
870Sstevel@tonic-gate static vfsdef_t vfw = {
880Sstevel@tonic-gate 	VFSDEF_VERSION,
890Sstevel@tonic-gate 	"autofs",
900Sstevel@tonic-gate 	autofs_init,
911488Srsb 	VSW_HASPROTO|VSW_CANRWRO|VSW_CANREMOUNT|VSW_STATS,
920Sstevel@tonic-gate 	&auto_mntopts
930Sstevel@tonic-gate };
940Sstevel@tonic-gate 
950Sstevel@tonic-gate /*
960Sstevel@tonic-gate  * Module linkage information for the kernel.
970Sstevel@tonic-gate  */
980Sstevel@tonic-gate static struct modlfs modlfs = {
990Sstevel@tonic-gate 	&mod_fsops, "filesystem for autofs", &vfw
1000Sstevel@tonic-gate };
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate static struct modlinkage modlinkage = {
1030Sstevel@tonic-gate 	MODREV_1,
1042516Sevanl 	&modlfs,
1050Sstevel@tonic-gate 	&modlsys,
1060Sstevel@tonic-gate #ifdef	_SYSCALL32_IMPL
1070Sstevel@tonic-gate 	&modlsys32,
1080Sstevel@tonic-gate #endif
1090Sstevel@tonic-gate 	NULL
1100Sstevel@tonic-gate };
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate /*
1130Sstevel@tonic-gate  * There are not enough stubs for rpcmod so we must force load it
1140Sstevel@tonic-gate  */
1150Sstevel@tonic-gate char _depends_on[] = "strmod/rpcmod misc/rpcsec fs/mntfs";
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate /*
1180Sstevel@tonic-gate  * This is the module initialization routine.
1190Sstevel@tonic-gate  */
1200Sstevel@tonic-gate int
1210Sstevel@tonic-gate _init(void)
1220Sstevel@tonic-gate {
1230Sstevel@tonic-gate 	return (mod_install(&modlinkage));
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate int
1270Sstevel@tonic-gate _fini(void)
1280Sstevel@tonic-gate {
1290Sstevel@tonic-gate 	/*
1300Sstevel@tonic-gate 	 * Don't allow the autofs module to be unloaded for now.
1310Sstevel@tonic-gate 	 */
1320Sstevel@tonic-gate 	return (EBUSY);
1330Sstevel@tonic-gate }
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate int
1360Sstevel@tonic-gate _info(struct modinfo *modinfop)
1370Sstevel@tonic-gate {
1380Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate static int autofs_fstype;
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate /*
1440Sstevel@tonic-gate  * autofs VFS operations
1450Sstevel@tonic-gate  */
1460Sstevel@tonic-gate static int auto_mount(vfs_t *, vnode_t *, struct mounta *, cred_t *);
1470Sstevel@tonic-gate static int auto_unmount(vfs_t *, int, cred_t *);
1480Sstevel@tonic-gate static int auto_root(vfs_t *, vnode_t **);
1490Sstevel@tonic-gate static int auto_statvfs(vfs_t *, struct statvfs64 *);
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate /*
1520Sstevel@tonic-gate  * Auto Mount options table
1530Sstevel@tonic-gate  */
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate static char *direct_cancel[] = { MNTOPT_INDIRECT, NULL };
1560Sstevel@tonic-gate static char *indirect_cancel[] = { MNTOPT_DIRECT, NULL };
1570Sstevel@tonic-gate static char *browse_cancel[] = { MNTOPT_NOBROWSE, NULL };
1580Sstevel@tonic-gate static char *nobrowse_cancel[] = { MNTOPT_BROWSE, NULL };
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate static mntopt_t mntopts[] = {
1610Sstevel@tonic-gate /*
1620Sstevel@tonic-gate  *	option name		cancel options	default arg	flags
1630Sstevel@tonic-gate  */
1640Sstevel@tonic-gate 	{ MNTOPT_DIRECT,	direct_cancel,	NULL,		0,
1650Sstevel@tonic-gate 		NULL },
1660Sstevel@tonic-gate 	{ MNTOPT_INDIRECT,	indirect_cancel, NULL,		0,
1670Sstevel@tonic-gate 		NULL },
1680Sstevel@tonic-gate 	{ MNTOPT_IGNORE,	NULL,		NULL,
1690Sstevel@tonic-gate 		MO_DEFAULT|MO_TAG,	NULL },
1700Sstevel@tonic-gate 	{ "nest",		NULL,		NULL,		MO_TAG,
1710Sstevel@tonic-gate 		NULL },
1720Sstevel@tonic-gate 	{ MNTOPT_BROWSE,	browse_cancel,	NULL,		MO_TAG,
1730Sstevel@tonic-gate 		NULL },
1740Sstevel@tonic-gate 	{ MNTOPT_NOBROWSE,	nobrowse_cancel, NULL,		MO_TAG,
1750Sstevel@tonic-gate 		NULL },
1760Sstevel@tonic-gate 	{ MNTOPT_RESTRICT,	NULL,		NULL,		MO_TAG,
1770Sstevel@tonic-gate 		NULL },
1780Sstevel@tonic-gate };
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate static mntopts_t auto_mntopts = {
1810Sstevel@tonic-gate 	sizeof (mntopts) / sizeof (mntopt_t),
1820Sstevel@tonic-gate 	mntopts
1830Sstevel@tonic-gate };
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate /*ARGSUSED*/
1860Sstevel@tonic-gate static void
1870Sstevel@tonic-gate autofs_zone_destructor(zoneid_t zoneid, void *arg)
1880Sstevel@tonic-gate {
1890Sstevel@tonic-gate 	struct autofs_globals *fngp = arg;
1900Sstevel@tonic-gate 	vnode_t *vp;
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 	if (fngp == NULL)
1930Sstevel@tonic-gate 		return;
1940Sstevel@tonic-gate 	ASSERT(fngp->fng_fnnode_count == 1);
1950Sstevel@tonic-gate 	ASSERT(fngp->fng_unmount_threads == 0);
1960Sstevel@tonic-gate 	/*
1970Sstevel@tonic-gate 	 * vn_alloc() initialized the rootnode with a count of 1; we need to
1980Sstevel@tonic-gate 	 * make this 0 to placate auto_freefnnode().
1990Sstevel@tonic-gate 	 */
2000Sstevel@tonic-gate 	vp = fntovn(fngp->fng_rootfnnodep);
2010Sstevel@tonic-gate 	ASSERT(vp->v_count == 1);
2020Sstevel@tonic-gate 	vp->v_count--;
2030Sstevel@tonic-gate 	auto_freefnnode(fngp->fng_rootfnnodep);
2040Sstevel@tonic-gate 	mutex_destroy(&fngp->fng_unmount_threads_lock);
2050Sstevel@tonic-gate 	kmem_free(fngp, sizeof (*fngp));
2060Sstevel@tonic-gate }
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate /*
2090Sstevel@tonic-gate  * rootfnnodep is allocated here.  Its sole purpose is to provide
2100Sstevel@tonic-gate  * read/write locking for top level fnnodes.  This object is
2110Sstevel@tonic-gate  * persistent and will not be deallocated until the zone is destroyed.
2120Sstevel@tonic-gate  *
2130Sstevel@tonic-gate  * The current zone is implied as the zone of interest, since we will be
2140Sstevel@tonic-gate  * calling zthread_create() which must be called from the correct zone.
2150Sstevel@tonic-gate  */
2162170Sevanl struct autofs_globals *
2170Sstevel@tonic-gate autofs_zone_init(void)
2180Sstevel@tonic-gate {
2190Sstevel@tonic-gate 	char rootname[sizeof ("root_fnnode_zone_") + ZONEID_WIDTH];
2200Sstevel@tonic-gate 	struct autofs_globals *fngp;
2210Sstevel@tonic-gate 	zoneid_t zoneid = getzoneid();
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate 	fngp = kmem_zalloc(sizeof (*fngp), KM_SLEEP);
2240Sstevel@tonic-gate 	(void) snprintf(rootname, sizeof (rootname), "root_fnnode_zone_%d",
2250Sstevel@tonic-gate 	    zoneid);
2260Sstevel@tonic-gate 	fngp->fng_rootfnnodep = auto_makefnnode(VNON, NULL, rootname, CRED(),
2270Sstevel@tonic-gate 	    fngp);
2280Sstevel@tonic-gate 	/*
2290Sstevel@tonic-gate 	 * Don't need to hold fng_rootfnnodep as it's never really used for
2300Sstevel@tonic-gate 	 * anything.
2310Sstevel@tonic-gate 	 */
2320Sstevel@tonic-gate 	fngp->fng_fnnode_count = 1;
2330Sstevel@tonic-gate 	fngp->fng_printed_not_running_msg = 0;
2340Sstevel@tonic-gate 	fngp->fng_zoneid = zoneid;
2350Sstevel@tonic-gate 	mutex_init(&fngp->fng_unmount_threads_lock, NULL, MUTEX_DEFAULT,
2360Sstevel@tonic-gate 	    NULL);
2370Sstevel@tonic-gate 	fngp->fng_unmount_threads = 0;
2380Sstevel@tonic-gate 
2392170Sevanl 	mutex_init(&fngp->fng_autofs_daemon_lock, NULL, MUTEX_DEFAULT, NULL);
2402170Sevanl 
2410Sstevel@tonic-gate 	/*
2420Sstevel@tonic-gate 	 * Start the unmounter thread for this zone.
2430Sstevel@tonic-gate 	 */
2440Sstevel@tonic-gate 	(void) zthread_create(NULL, 0, auto_do_unmount, fngp, 0, minclsyspri);
2450Sstevel@tonic-gate 	return (fngp);
2460Sstevel@tonic-gate }
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate int
2490Sstevel@tonic-gate autofs_init(int fstype, char *name)
2500Sstevel@tonic-gate {
2510Sstevel@tonic-gate 	static const fs_operation_def_t auto_vfsops_template[] = {
2523898Srsb 		VFSNAME_MOUNT,		{ .vfs_mount = auto_mount },
2533898Srsb 		VFSNAME_UNMOUNT,	{ .vfs_unmount = auto_unmount },
2543898Srsb 		VFSNAME_ROOT,		{ .vfs_root = auto_root },
2553898Srsb 		VFSNAME_STATVFS,	{ .vfs_statvfs = auto_statvfs },
2563898Srsb 		NULL,			NULL
2570Sstevel@tonic-gate 	};
2580Sstevel@tonic-gate 	int error;
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate 	autofs_fstype = fstype;
2610Sstevel@tonic-gate 	ASSERT(autofs_fstype != 0);
2620Sstevel@tonic-gate 	/*
2630Sstevel@tonic-gate 	 * Associate VFS ops vector with this fstype
2640Sstevel@tonic-gate 	 */
2650Sstevel@tonic-gate 	error = vfs_setfsops(fstype, auto_vfsops_template, NULL);
2660Sstevel@tonic-gate 	if (error != 0) {
2670Sstevel@tonic-gate 		cmn_err(CE_WARN, "autofs_init: bad vfs ops template");
2680Sstevel@tonic-gate 		return (error);
2690Sstevel@tonic-gate 	}
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate 	error = vn_make_ops(name, auto_vnodeops_template, &auto_vnodeops);
2720Sstevel@tonic-gate 	if (error != 0) {
2730Sstevel@tonic-gate 		(void) vfs_freevfsops_by_type(fstype);
2740Sstevel@tonic-gate 		cmn_err(CE_WARN, "autofs_init: bad vnode ops template");
2750Sstevel@tonic-gate 		return (error);
2760Sstevel@tonic-gate 	}
2770Sstevel@tonic-gate 
2780Sstevel@tonic-gate 	mutex_init(&autofs_minor_lock, NULL, MUTEX_DEFAULT, NULL);
2790Sstevel@tonic-gate 	/*
2800Sstevel@tonic-gate 	 * Assign unique major number for all autofs mounts
2810Sstevel@tonic-gate 	 */
2820Sstevel@tonic-gate 	if ((autofs_major = getudev()) == (major_t)-1) {
2830Sstevel@tonic-gate 		cmn_err(CE_WARN,
2840Sstevel@tonic-gate 		    "autofs: autofs_init: can't get unique device number");
2850Sstevel@tonic-gate 		mutex_destroy(&autofs_minor_lock);
2860Sstevel@tonic-gate 		return (1);
2870Sstevel@tonic-gate 	}
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate 	/*
2900Sstevel@tonic-gate 	 * We'd like to be able to provide a constructor here, but we can't
2910Sstevel@tonic-gate 	 * since it wants to zthread_create(), something it can't do in a ZSD
2920Sstevel@tonic-gate 	 * constructor.
2930Sstevel@tonic-gate 	 */
2940Sstevel@tonic-gate 	zone_key_create(&autofs_key, NULL, NULL, autofs_zone_destructor);
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate 	return (0);
2970Sstevel@tonic-gate }
2980Sstevel@tonic-gate 
2990Sstevel@tonic-gate static char *restropts[] = {
3000Sstevel@tonic-gate 	RESTRICTED_MNTOPTS
3010Sstevel@tonic-gate };
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate /*
3040Sstevel@tonic-gate  * This routine adds those options to the option string `buf' which are
3050Sstevel@tonic-gate  * forced by secpolicy_fs_mount.  If the automatic "security" options
3060Sstevel@tonic-gate  * are set, the option string gets them added if they aren't already
3070Sstevel@tonic-gate  * there.  We search the string with "strstr" and make sure that
3080Sstevel@tonic-gate  * the string we find is bracketed with <start|",">MNTOPT<","|"\0">
3090Sstevel@tonic-gate  *
3100Sstevel@tonic-gate  * This is one half of the option inheritence algorithm which
3110Sstevel@tonic-gate  * implements the "restrict" option.  The other half is implemented
3120Sstevel@tonic-gate  * in automountd; it takes its cue from the options we add here.
3130Sstevel@tonic-gate  */
3140Sstevel@tonic-gate static int
3150Sstevel@tonic-gate autofs_restrict_opts(struct vfs *vfsp, char *buf, size_t maxlen, size_t *curlen)
3160Sstevel@tonic-gate {
3170Sstevel@tonic-gate 	int i;
3180Sstevel@tonic-gate 	char *p;
3190Sstevel@tonic-gate 	size_t len = *curlen - 1;
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate 	/* Unrestricted */
3220Sstevel@tonic-gate 	if (!vfs_optionisset(vfsp, restropts[0], NULL))
3230Sstevel@tonic-gate 		return (0);
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate 	for (i = 0; i < sizeof (restropts)/sizeof (restropts[0]); i++) {
3260Sstevel@tonic-gate 		size_t olen = strlen(restropts[i]);
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 		/* Add "restrict" always and the others insofar set */
3290Sstevel@tonic-gate 		if ((i == 0 || vfs_optionisset(vfsp, restropts[i], NULL)) &&
3300Sstevel@tonic-gate 		    ((p = strstr(buf, restropts[i])) == NULL ||
3310Sstevel@tonic-gate 		    !((p == buf || p[-1] == ',') &&
3320Sstevel@tonic-gate 		    (p[olen] == '\0' || p[olen] == ',')))) {
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate 			if (len + olen + 1 > maxlen)
3350Sstevel@tonic-gate 				return (-1);
3360Sstevel@tonic-gate 
3370Sstevel@tonic-gate 			if (*buf != '\0')
3380Sstevel@tonic-gate 				buf[len++] = ',';
3390Sstevel@tonic-gate 			(void) strcpy(&buf[len], restropts[i]);
3400Sstevel@tonic-gate 			len += olen;
3410Sstevel@tonic-gate 		}
3420Sstevel@tonic-gate 	}
3430Sstevel@tonic-gate 	*curlen = len + 1;
3440Sstevel@tonic-gate 	return (0);
3450Sstevel@tonic-gate }
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate /* ARGSUSED */
3480Sstevel@tonic-gate static int
3490Sstevel@tonic-gate auto_mount(vfs_t *vfsp, vnode_t *vp, struct mounta *uap, cred_t *cr)
3500Sstevel@tonic-gate {
3510Sstevel@tonic-gate 	int error;
3520Sstevel@tonic-gate 	size_t len = 0;
3532170Sevanl 	autofs_args args;
3540Sstevel@tonic-gate 	fninfo_t *fnip = NULL;
3550Sstevel@tonic-gate 	vnode_t *rootvp = NULL;
3560Sstevel@tonic-gate 	fnnode_t *rootfnp = NULL;
3570Sstevel@tonic-gate 	char *data = uap->dataptr;
3580Sstevel@tonic-gate 	char datalen = uap->datalen;
3590Sstevel@tonic-gate 	dev_t autofs_dev;
3602170Sevanl 	char strbuff[MAXPATHLEN + 1];
361*11185SSean.McEnroe@Sun.COM 	vnode_t *kkvp;
3620Sstevel@tonic-gate 	struct autofs_globals *fngp;
3630Sstevel@tonic-gate 	zone_t *zone = curproc->p_zone;
3640Sstevel@tonic-gate 
3650Sstevel@tonic-gate 	AUTOFS_DPRINT((4, "auto_mount: vfs %p vp %p\n", (void *)vfsp,
3660Sstevel@tonic-gate 	    (void *)vp));
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	if ((error = secpolicy_fs_mount(cr, vp, vfsp)) != 0)
3690Sstevel@tonic-gate 		return (EPERM);
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate 	if (zone == global_zone) {
3720Sstevel@tonic-gate 		zone_t *mntzone;
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate 		mntzone = zone_find_by_path(refstr_value(vfsp->vfs_mntpt));
3750Sstevel@tonic-gate 		ASSERT(mntzone != NULL);
3760Sstevel@tonic-gate 		zone_rele(mntzone);
3770Sstevel@tonic-gate 		if (mntzone != zone) {
3780Sstevel@tonic-gate 			return (EBUSY);
3790Sstevel@tonic-gate 		}
3800Sstevel@tonic-gate 	}
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate 	/*
3830Sstevel@tonic-gate 	 * Stop the mount from going any further if the zone is going away.
3840Sstevel@tonic-gate 	 */
3850Sstevel@tonic-gate 	if (zone_status_get(zone) >= ZONE_IS_SHUTTING_DOWN)
3860Sstevel@tonic-gate 		return (EBUSY);
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate 	/*
3890Sstevel@tonic-gate 	 * We need a lock to serialize this; minor_lock is as good as any.
3900Sstevel@tonic-gate 	 */
3910Sstevel@tonic-gate 	mutex_enter(&autofs_minor_lock);
3920Sstevel@tonic-gate 	if ((fngp = zone_getspecific(autofs_key, zone)) == NULL) {
3930Sstevel@tonic-gate 		fngp = autofs_zone_init();
3940Sstevel@tonic-gate 		(void) zone_setspecific(autofs_key, zone, fngp);
3950Sstevel@tonic-gate 	}
3960Sstevel@tonic-gate 	mutex_exit(&autofs_minor_lock);
3970Sstevel@tonic-gate 	ASSERT(fngp != NULL);
3980Sstevel@tonic-gate 
3990Sstevel@tonic-gate 	/*
4000Sstevel@tonic-gate 	 * Get arguments
4010Sstevel@tonic-gate 	 */
4020Sstevel@tonic-gate 	if (uap->flags & MS_SYSSPACE) {
4030Sstevel@tonic-gate 		if (datalen != sizeof (args))
4040Sstevel@tonic-gate 			return (EINVAL);
4050Sstevel@tonic-gate 		error = kcopy(data, &args, sizeof (args));
4060Sstevel@tonic-gate 	} else {
4070Sstevel@tonic-gate 		if (get_udatamodel() == DATAMODEL_NATIVE) {
4080Sstevel@tonic-gate 			if (datalen != sizeof (args))
4090Sstevel@tonic-gate 				return (EINVAL);
4100Sstevel@tonic-gate 			error = copyin(data, &args, sizeof (args));
4110Sstevel@tonic-gate 		} else {
4120Sstevel@tonic-gate 			struct autofs_args32 args32;
4130Sstevel@tonic-gate 
4140Sstevel@tonic-gate 			if (datalen != sizeof (args32))
4150Sstevel@tonic-gate 				return (EINVAL);
4160Sstevel@tonic-gate 			error = copyin(data, &args32, sizeof (args32));
4170Sstevel@tonic-gate 
4180Sstevel@tonic-gate 			args.addr.maxlen = args32.addr.maxlen;
4190Sstevel@tonic-gate 			args.addr.len = args32.addr.len;
4200Sstevel@tonic-gate 			args.addr.buf = (char *)(uintptr_t)args32.addr.buf;
4210Sstevel@tonic-gate 			args.path = (char *)(uintptr_t)args32.path;
4220Sstevel@tonic-gate 			args.opts = (char *)(uintptr_t)args32.opts;
4230Sstevel@tonic-gate 			args.map = (char *)(uintptr_t)args32.map;
4240Sstevel@tonic-gate 			args.subdir = (char *)(uintptr_t)args32.subdir;
4250Sstevel@tonic-gate 			args.key = (char *)(uintptr_t)args32.key;
4260Sstevel@tonic-gate 			args.mount_to = args32.mount_to;
4270Sstevel@tonic-gate 			args.rpc_to = args32.rpc_to;
4280Sstevel@tonic-gate 			args.direct = args32.direct;
4290Sstevel@tonic-gate 		}
4300Sstevel@tonic-gate 	}
4310Sstevel@tonic-gate 	if (error)
4320Sstevel@tonic-gate 		return (EFAULT);
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate 	/*
4350Sstevel@tonic-gate 	 * For a remount, only update mount information
4360Sstevel@tonic-gate 	 * i.e. default mount options, map name, etc.
4370Sstevel@tonic-gate 	 */
4380Sstevel@tonic-gate 	if (uap->flags & MS_REMOUNT) {
4390Sstevel@tonic-gate 		fnip = vfstofni(vfsp);
4400Sstevel@tonic-gate 		if (fnip == NULL)
4410Sstevel@tonic-gate 			return (EINVAL);
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate 		if (args.direct == 1)
4440Sstevel@tonic-gate 			fnip->fi_flags |= MF_DIRECT;
4450Sstevel@tonic-gate 		else
4460Sstevel@tonic-gate 			fnip->fi_flags &= ~MF_DIRECT;
4470Sstevel@tonic-gate 		fnip->fi_mount_to = args.mount_to;
4480Sstevel@tonic-gate 		fnip->fi_rpc_to = args.rpc_to;
4490Sstevel@tonic-gate 
4500Sstevel@tonic-gate 		/*
4510Sstevel@tonic-gate 		 * Get default options
4520Sstevel@tonic-gate 		 */
4530Sstevel@tonic-gate 		if (uap->flags & MS_SYSSPACE)
4540Sstevel@tonic-gate 			error = copystr(args.opts, strbuff, sizeof (strbuff),
4550Sstevel@tonic-gate 			    &len);
4560Sstevel@tonic-gate 		else
4570Sstevel@tonic-gate 			error = copyinstr(args.opts, strbuff, sizeof (strbuff),
4580Sstevel@tonic-gate 			    &len);
4590Sstevel@tonic-gate 		if (error)
4600Sstevel@tonic-gate 			return (EFAULT);
4610Sstevel@tonic-gate 
4620Sstevel@tonic-gate 		if (autofs_restrict_opts(vfsp, strbuff, sizeof (strbuff), &len)
4630Sstevel@tonic-gate 		    != 0) {
4640Sstevel@tonic-gate 			return (EFAULT);
4650Sstevel@tonic-gate 		}
4660Sstevel@tonic-gate 
4670Sstevel@tonic-gate 		kmem_free(fnip->fi_opts, fnip->fi_optslen);
4680Sstevel@tonic-gate 		fnip->fi_opts = kmem_alloc(len, KM_SLEEP);
4690Sstevel@tonic-gate 		fnip->fi_optslen = (int)len;
4700Sstevel@tonic-gate 		bcopy(strbuff, fnip->fi_opts, len);
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate 		/*
4730Sstevel@tonic-gate 		 * Get context/map name
4740Sstevel@tonic-gate 		 */
4750Sstevel@tonic-gate 		if (uap->flags & MS_SYSSPACE)
4760Sstevel@tonic-gate 			error = copystr(args.map, strbuff, sizeof (strbuff),
4770Sstevel@tonic-gate 			    &len);
4780Sstevel@tonic-gate 		else
4790Sstevel@tonic-gate 			error = copyinstr(args.map, strbuff, sizeof (strbuff),
4800Sstevel@tonic-gate 			    &len);
4810Sstevel@tonic-gate 		if (error)
4820Sstevel@tonic-gate 			return (EFAULT);
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate 		kmem_free(fnip->fi_map, fnip->fi_maplen);
4850Sstevel@tonic-gate 		fnip->fi_map = kmem_alloc(len, KM_SLEEP);
4860Sstevel@tonic-gate 		fnip->fi_maplen = (int)len;
4870Sstevel@tonic-gate 		bcopy(strbuff, fnip->fi_map, len);
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate 		return (0);
4900Sstevel@tonic-gate 	}
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate 	/*
4930Sstevel@tonic-gate 	 * Allocate fninfo struct and attach it to vfs
4940Sstevel@tonic-gate 	 */
4950Sstevel@tonic-gate 	fnip = kmem_zalloc(sizeof (*fnip), KM_SLEEP);
4960Sstevel@tonic-gate 	fnip->fi_mountvfs = vfsp;
4970Sstevel@tonic-gate 
4980Sstevel@tonic-gate 	fnip->fi_mount_to = args.mount_to;
4990Sstevel@tonic-gate 	fnip->fi_rpc_to = args.rpc_to;
5000Sstevel@tonic-gate 	fnip->fi_refcnt = 0;
5010Sstevel@tonic-gate 	vfsp->vfs_bsize = AUTOFS_BLOCKSIZE;
5020Sstevel@tonic-gate 	vfsp->vfs_fstype = autofs_fstype;
5030Sstevel@tonic-gate 
5040Sstevel@tonic-gate 	/*
5050Sstevel@tonic-gate 	 * Assign a unique device id to the mount
5060Sstevel@tonic-gate 	 */
5070Sstevel@tonic-gate 	mutex_enter(&autofs_minor_lock);
5080Sstevel@tonic-gate 	do {
5090Sstevel@tonic-gate 		autofs_minor = (autofs_minor + 1) & L_MAXMIN32;
5100Sstevel@tonic-gate 		autofs_dev = makedevice(autofs_major, autofs_minor);
5110Sstevel@tonic-gate 	} while (vfs_devismounted(autofs_dev));
5120Sstevel@tonic-gate 	mutex_exit(&autofs_minor_lock);
5130Sstevel@tonic-gate 	vfsp->vfs_dev = autofs_dev;
5140Sstevel@tonic-gate 	vfs_make_fsid(&vfsp->vfs_fsid, autofs_dev, autofs_fstype);
5150Sstevel@tonic-gate 	vfsp->vfs_data = (void *)fnip;
5160Sstevel@tonic-gate 	vfsp->vfs_bcount = 0;
5170Sstevel@tonic-gate 
5180Sstevel@tonic-gate 	/*
5190Sstevel@tonic-gate 	 * Get daemon address
5200Sstevel@tonic-gate 	 */
5210Sstevel@tonic-gate 	fnip->fi_addr.len = args.addr.len;
5220Sstevel@tonic-gate 	fnip->fi_addr.maxlen = fnip->fi_addr.len;
5230Sstevel@tonic-gate 	fnip->fi_addr.buf = kmem_alloc(args.addr.len, KM_SLEEP);
5240Sstevel@tonic-gate 	if (uap->flags & MS_SYSSPACE)
5250Sstevel@tonic-gate 		error = kcopy(args.addr.buf, fnip->fi_addr.buf, args.addr.len);
5260Sstevel@tonic-gate 	else
5270Sstevel@tonic-gate 		error = copyin(args.addr.buf, fnip->fi_addr.buf, args.addr.len);
5280Sstevel@tonic-gate 	if (error) {
5290Sstevel@tonic-gate 		error = EFAULT;
5300Sstevel@tonic-gate 		goto errout;
5310Sstevel@tonic-gate 	}
5320Sstevel@tonic-gate 
5330Sstevel@tonic-gate 	fnip->fi_zoneid = getzoneid();
5340Sstevel@tonic-gate 	/*
5350Sstevel@tonic-gate 	 * Get path for mountpoint
5360Sstevel@tonic-gate 	 */
5370Sstevel@tonic-gate 	if (uap->flags & MS_SYSSPACE)
5380Sstevel@tonic-gate 		error = copystr(args.path, strbuff, sizeof (strbuff), &len);
5390Sstevel@tonic-gate 	else
5400Sstevel@tonic-gate 		error = copyinstr(args.path, strbuff, sizeof (strbuff), &len);
5410Sstevel@tonic-gate 	if (error) {
5420Sstevel@tonic-gate 		error = EFAULT;
5430Sstevel@tonic-gate 		goto errout;
5440Sstevel@tonic-gate 	}
5450Sstevel@tonic-gate 	fnip->fi_path = kmem_alloc(len, KM_SLEEP);
5460Sstevel@tonic-gate 	fnip->fi_pathlen = (int)len;
5470Sstevel@tonic-gate 	bcopy(strbuff, fnip->fi_path, len);
5480Sstevel@tonic-gate 
5490Sstevel@tonic-gate 	/*
5500Sstevel@tonic-gate 	 * Get default options
5510Sstevel@tonic-gate 	 */
5520Sstevel@tonic-gate 	if (uap->flags & MS_SYSSPACE)
5530Sstevel@tonic-gate 		error = copystr(args.opts, strbuff, sizeof (strbuff), &len);
5540Sstevel@tonic-gate 	else
5550Sstevel@tonic-gate 		error = copyinstr(args.opts, strbuff, sizeof (strbuff), &len);
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate 	if (error != 0 ||
5580Sstevel@tonic-gate 	    autofs_restrict_opts(vfsp, strbuff, sizeof (strbuff), &len) != 0) {
5590Sstevel@tonic-gate 		error = EFAULT;
5600Sstevel@tonic-gate 		goto errout;
5610Sstevel@tonic-gate 	}
5620Sstevel@tonic-gate 	fnip->fi_opts = kmem_alloc(len, KM_SLEEP);
5630Sstevel@tonic-gate 	fnip->fi_optslen = (int)len;
5640Sstevel@tonic-gate 	bcopy(strbuff, fnip->fi_opts, len);
5650Sstevel@tonic-gate 
5660Sstevel@tonic-gate 	/*
5670Sstevel@tonic-gate 	 * Get context/map name
5680Sstevel@tonic-gate 	 */
5690Sstevel@tonic-gate 	if (uap->flags & MS_SYSSPACE)
5700Sstevel@tonic-gate 		error = copystr(args.map, strbuff, sizeof (strbuff), &len);
5710Sstevel@tonic-gate 	else
5720Sstevel@tonic-gate 		error = copyinstr(args.map, strbuff, sizeof (strbuff), &len);
5730Sstevel@tonic-gate 	if (error) {
5740Sstevel@tonic-gate 		error = EFAULT;
5750Sstevel@tonic-gate 		goto errout;
5760Sstevel@tonic-gate 	}
5770Sstevel@tonic-gate 	fnip->fi_map = kmem_alloc(len, KM_SLEEP);
5780Sstevel@tonic-gate 	fnip->fi_maplen = (int)len;
5790Sstevel@tonic-gate 	bcopy(strbuff, fnip->fi_map, len);
5800Sstevel@tonic-gate 
5810Sstevel@tonic-gate 	/*
5820Sstevel@tonic-gate 	 * Get subdirectory within map
5830Sstevel@tonic-gate 	 */
5840Sstevel@tonic-gate 	if (uap->flags & MS_SYSSPACE)
5850Sstevel@tonic-gate 		error = copystr(args.subdir, strbuff, sizeof (strbuff), &len);
5860Sstevel@tonic-gate 	else
5870Sstevel@tonic-gate 		error = copyinstr(args.subdir, strbuff, sizeof (strbuff), &len);
5880Sstevel@tonic-gate 	if (error) {
5890Sstevel@tonic-gate 		error = EFAULT;
5900Sstevel@tonic-gate 		goto errout;
5910Sstevel@tonic-gate 	}
5920Sstevel@tonic-gate 	fnip->fi_subdir = kmem_alloc(len, KM_SLEEP);
5930Sstevel@tonic-gate 	fnip->fi_subdirlen = (int)len;
5940Sstevel@tonic-gate 	bcopy(strbuff, fnip->fi_subdir, len);
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate 	/*
5970Sstevel@tonic-gate 	 * Get the key
5980Sstevel@tonic-gate 	 */
5990Sstevel@tonic-gate 	if (uap->flags & MS_SYSSPACE)
6000Sstevel@tonic-gate 		error = copystr(args.key, strbuff, sizeof (strbuff), &len);
6010Sstevel@tonic-gate 	else
6020Sstevel@tonic-gate 		error = copyinstr(args.key, strbuff, sizeof (strbuff), &len);
6030Sstevel@tonic-gate 	if (error) {
6040Sstevel@tonic-gate 		error = EFAULT;
6050Sstevel@tonic-gate 		goto errout;
6060Sstevel@tonic-gate 	}
6070Sstevel@tonic-gate 	fnip->fi_key = kmem_alloc(len, KM_SLEEP);
6080Sstevel@tonic-gate 	fnip->fi_keylen = (int)len;
6090Sstevel@tonic-gate 	bcopy(strbuff, fnip->fi_key, len);
6100Sstevel@tonic-gate 
6110Sstevel@tonic-gate 	/*
6120Sstevel@tonic-gate 	 * Is this a direct mount?
6130Sstevel@tonic-gate 	 */
6140Sstevel@tonic-gate 	if (args.direct == 1)
6150Sstevel@tonic-gate 		fnip->fi_flags |= MF_DIRECT;
6160Sstevel@tonic-gate 
6170Sstevel@tonic-gate 	/*
6180Sstevel@tonic-gate 	 * Setup netconfig.
6190Sstevel@tonic-gate 	 * Can I pass in knconf as mount argument? what
6200Sstevel@tonic-gate 	 * happens when the daemon gets restarted?
6210Sstevel@tonic-gate 	 */
6220Sstevel@tonic-gate 	if ((error = lookupname("/dev/ticotsord", UIO_SYSSPACE, FOLLOW,
623*11185SSean.McEnroe@Sun.COM 	    NULLVPP, &kkvp)) != 0) {
6240Sstevel@tonic-gate 		cmn_err(CE_WARN, "autofs: lookupname: %d", error);
6250Sstevel@tonic-gate 		goto errout;
6260Sstevel@tonic-gate 	}
6270Sstevel@tonic-gate 
628*11185SSean.McEnroe@Sun.COM 	fnip->fi_knconf.knc_rdev = kkvp->v_rdev;
6290Sstevel@tonic-gate 	fnip->fi_knconf.knc_protofmly = NC_LOOPBACK;
6300Sstevel@tonic-gate 	fnip->fi_knconf.knc_semantics = NC_TPI_COTS_ORD;
631*11185SSean.McEnroe@Sun.COM 	VN_RELE(kkvp);
6320Sstevel@tonic-gate 
6330Sstevel@tonic-gate 	/*
6340Sstevel@tonic-gate 	 * Make the root vnode
6350Sstevel@tonic-gate 	 */
6360Sstevel@tonic-gate 	rootfnp = auto_makefnnode(VDIR, vfsp, fnip->fi_path, cr, fngp);
6370Sstevel@tonic-gate 	if (rootfnp == NULL) {
6380Sstevel@tonic-gate 		error = ENOMEM;
6390Sstevel@tonic-gate 		goto errout;
6400Sstevel@tonic-gate 	}
6410Sstevel@tonic-gate 	rootvp = fntovn(rootfnp);
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate 	rootvp->v_flag |= VROOT;
6440Sstevel@tonic-gate 	rootfnp->fn_mode = AUTOFS_MODE;
6450Sstevel@tonic-gate 	rootfnp->fn_parent = rootfnp;
6460Sstevel@tonic-gate 	/* account for ".." entry */
6470Sstevel@tonic-gate 	rootfnp->fn_linkcnt = rootfnp->fn_size = 1;
6480Sstevel@tonic-gate 	fnip->fi_rootvp = rootvp;
6490Sstevel@tonic-gate 
6500Sstevel@tonic-gate 	/*
6510Sstevel@tonic-gate 	 * Add to list of top level AUTOFS' if it is being mounted by
6520Sstevel@tonic-gate 	 * a user level process.
6530Sstevel@tonic-gate 	 */
6540Sstevel@tonic-gate 	if (!(uap->flags & MS_SYSSPACE)) {
6550Sstevel@tonic-gate 		rw_enter(&fngp->fng_rootfnnodep->fn_rwlock, RW_WRITER);
6560Sstevel@tonic-gate 		rootfnp->fn_parent = fngp->fng_rootfnnodep;
6570Sstevel@tonic-gate 		rootfnp->fn_next = fngp->fng_rootfnnodep->fn_dirents;
6580Sstevel@tonic-gate 		fngp->fng_rootfnnodep->fn_dirents = rootfnp;
6590Sstevel@tonic-gate 		rw_exit(&fngp->fng_rootfnnodep->fn_rwlock);
6600Sstevel@tonic-gate 	}
6610Sstevel@tonic-gate 
6620Sstevel@tonic-gate 	AUTOFS_DPRINT((5, "auto_mount: vfs %p root %p fnip %p return %d\n",
6630Sstevel@tonic-gate 	    (void *)vfsp, (void *)rootvp, (void *)fnip, error));
6640Sstevel@tonic-gate 
6650Sstevel@tonic-gate 	return (0);
6660Sstevel@tonic-gate 
6670Sstevel@tonic-gate errout:
6680Sstevel@tonic-gate 	ASSERT(fnip != NULL);
6690Sstevel@tonic-gate 	ASSERT((uap->flags & MS_REMOUNT) == 0);
6700Sstevel@tonic-gate 
6710Sstevel@tonic-gate 	if (fnip->fi_addr.buf != NULL)
6720Sstevel@tonic-gate 		kmem_free(fnip->fi_addr.buf, fnip->fi_addr.len);
6730Sstevel@tonic-gate 	if (fnip->fi_path != NULL)
6740Sstevel@tonic-gate 		kmem_free(fnip->fi_path, fnip->fi_pathlen);
6750Sstevel@tonic-gate 	if (fnip->fi_opts != NULL)
6760Sstevel@tonic-gate 		kmem_free(fnip->fi_opts, fnip->fi_optslen);
6770Sstevel@tonic-gate 	if (fnip->fi_map != NULL)
6780Sstevel@tonic-gate 		kmem_free(fnip->fi_map, fnip->fi_maplen);
6790Sstevel@tonic-gate 	if (fnip->fi_subdir != NULL)
6800Sstevel@tonic-gate 		kmem_free(fnip->fi_subdir, fnip->fi_subdirlen);
6810Sstevel@tonic-gate 	if (fnip->fi_key != NULL)
6820Sstevel@tonic-gate 		kmem_free(fnip->fi_key, fnip->fi_keylen);
6830Sstevel@tonic-gate 	kmem_free(fnip, sizeof (*fnip));
6840Sstevel@tonic-gate 
6850Sstevel@tonic-gate 	AUTOFS_DPRINT((5, "auto_mount: vfs %p root %p fnip %p return %d\n",
6860Sstevel@tonic-gate 	    (void *)vfsp, (void *)rootvp, (void *)fnip, error));
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate 	return (error);
6890Sstevel@tonic-gate }
6900Sstevel@tonic-gate 
6910Sstevel@tonic-gate /* ARGSUSED */
6920Sstevel@tonic-gate static int
6930Sstevel@tonic-gate auto_unmount(vfs_t *vfsp, int flag, cred_t *cr)
6940Sstevel@tonic-gate {
6950Sstevel@tonic-gate 	fninfo_t *fnip;
6960Sstevel@tonic-gate 	vnode_t *rvp;
6970Sstevel@tonic-gate 	fnnode_t *rfnp, *fnp, *pfnp;
6980Sstevel@tonic-gate 	fnnode_t *myrootfnnodep;
6990Sstevel@tonic-gate 
7000Sstevel@tonic-gate 	fnip = vfstofni(vfsp);
7010Sstevel@tonic-gate 	AUTOFS_DPRINT((4, "auto_unmount vfsp %p fnip %p\n", (void *)vfsp,
702*11185SSean.McEnroe@Sun.COM 	    (void *)fnip));
7030Sstevel@tonic-gate 
7040Sstevel@tonic-gate 	if (secpolicy_fs_unmount(cr, vfsp) != 0)
7050Sstevel@tonic-gate 		return (EPERM);
7060Sstevel@tonic-gate 	/*
7070Sstevel@tonic-gate 	 * forced unmount is not supported by this file system
7080Sstevel@tonic-gate 	 * and thus, ENOTSUP, is being returned.
7090Sstevel@tonic-gate 	 */
7100Sstevel@tonic-gate 	if (flag & MS_FORCE)
7110Sstevel@tonic-gate 		return (ENOTSUP);
7120Sstevel@tonic-gate 
7130Sstevel@tonic-gate 	ASSERT(vn_vfswlock_held(vfsp->vfs_vnodecovered));
7140Sstevel@tonic-gate 	rvp = fnip->fi_rootvp;
7150Sstevel@tonic-gate 	rfnp = vntofn(rvp);
7160Sstevel@tonic-gate 
7170Sstevel@tonic-gate 	if (rvp->v_count > 1 || rfnp->fn_dirents != NULL)
7180Sstevel@tonic-gate 		return (EBUSY);
7190Sstevel@tonic-gate 
7200Sstevel@tonic-gate 	/*
7210Sstevel@tonic-gate 	 * The root vnode is on the linked list of root fnnodes only if
7220Sstevel@tonic-gate 	 * this was not a trigger node. Since we have no way of knowing,
7230Sstevel@tonic-gate 	 * if we don't find it, then we assume it was a trigger node.
7240Sstevel@tonic-gate 	 */
7250Sstevel@tonic-gate 	myrootfnnodep = rfnp->fn_globals->fng_rootfnnodep;
7260Sstevel@tonic-gate 	pfnp = NULL;
7270Sstevel@tonic-gate 	rw_enter(&myrootfnnodep->fn_rwlock, RW_WRITER);
7280Sstevel@tonic-gate 	fnp = myrootfnnodep->fn_dirents;
7290Sstevel@tonic-gate 	while (fnp != NULL) {
7300Sstevel@tonic-gate 		if (fnp == rfnp) {
7310Sstevel@tonic-gate 			/*
7320Sstevel@tonic-gate 			 * A check here is made to see if rvp is busy.  If
7330Sstevel@tonic-gate 			 * so, return EBUSY.  Otherwise proceed with
7340Sstevel@tonic-gate 			 * disconnecting it from the list.
7350Sstevel@tonic-gate 			 */
7360Sstevel@tonic-gate 			if (rvp->v_count > 1 || rfnp->fn_dirents != NULL) {
7370Sstevel@tonic-gate 				rw_exit(&myrootfnnodep->fn_rwlock);
7380Sstevel@tonic-gate 				return (EBUSY);
7390Sstevel@tonic-gate 			}
7400Sstevel@tonic-gate 			if (pfnp)
7410Sstevel@tonic-gate 				pfnp->fn_next = fnp->fn_next;
7420Sstevel@tonic-gate 			else
7430Sstevel@tonic-gate 				myrootfnnodep->fn_dirents = fnp->fn_next;
7440Sstevel@tonic-gate 			fnp->fn_next = NULL;
7450Sstevel@tonic-gate 			break;
7460Sstevel@tonic-gate 		}
7470Sstevel@tonic-gate 		pfnp = fnp;
7480Sstevel@tonic-gate 		fnp = fnp->fn_next;
7490Sstevel@tonic-gate 	}
7500Sstevel@tonic-gate 	rw_exit(&myrootfnnodep->fn_rwlock);
7510Sstevel@tonic-gate 
7520Sstevel@tonic-gate 	ASSERT(rvp->v_count == 1);
7530Sstevel@tonic-gate 	ASSERT(rfnp->fn_size == 1);
7540Sstevel@tonic-gate 	ASSERT(rfnp->fn_linkcnt == 1);
7550Sstevel@tonic-gate 	/*
7560Sstevel@tonic-gate 	 * The following drops linkcnt to 0, therefore the disconnect is
7570Sstevel@tonic-gate 	 * not attempted when auto_inactive() is called by
7580Sstevel@tonic-gate 	 * vn_rele(). This is necessary because we have nothing to get
7590Sstevel@tonic-gate 	 * disconnected from since we're the root of the filesystem. As a
7600Sstevel@tonic-gate 	 * side effect the node is not freed, therefore I should free the
7610Sstevel@tonic-gate 	 * node here.
7620Sstevel@tonic-gate 	 *
7630Sstevel@tonic-gate 	 * XXX - I really need to think of a better way of doing this.
7640Sstevel@tonic-gate 	 */
7650Sstevel@tonic-gate 	rfnp->fn_size--;
7660Sstevel@tonic-gate 	rfnp->fn_linkcnt--;
7670Sstevel@tonic-gate 
7680Sstevel@tonic-gate 	/*
7690Sstevel@tonic-gate 	 * release of last reference causes node
7700Sstevel@tonic-gate 	 * to be freed
7710Sstevel@tonic-gate 	 */
7720Sstevel@tonic-gate 	VN_RELE(rvp);
7730Sstevel@tonic-gate 	rfnp->fn_parent = NULL;
7740Sstevel@tonic-gate 
7750Sstevel@tonic-gate 	auto_freefnnode(rfnp);
7760Sstevel@tonic-gate 
7770Sstevel@tonic-gate 	kmem_free(fnip->fi_addr.buf, fnip->fi_addr.len);
7780Sstevel@tonic-gate 	kmem_free(fnip->fi_path, fnip->fi_pathlen);
7790Sstevel@tonic-gate 	kmem_free(fnip->fi_map, fnip->fi_maplen);
7800Sstevel@tonic-gate 	kmem_free(fnip->fi_subdir, fnip->fi_subdirlen);
7810Sstevel@tonic-gate 	kmem_free(fnip->fi_key, fnip->fi_keylen);
7820Sstevel@tonic-gate 	kmem_free(fnip->fi_opts, fnip->fi_optslen);
7830Sstevel@tonic-gate 	kmem_free(fnip, sizeof (*fnip));
7840Sstevel@tonic-gate 	AUTOFS_DPRINT((5, "auto_unmount: return=0\n"));
7850Sstevel@tonic-gate 
7860Sstevel@tonic-gate 	return (0);
7870Sstevel@tonic-gate }
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate 
7900Sstevel@tonic-gate /*
7910Sstevel@tonic-gate  * find root of autofs
7920Sstevel@tonic-gate  */
7930Sstevel@tonic-gate static int
7940Sstevel@tonic-gate auto_root(vfs_t *vfsp, vnode_t **vpp)
7950Sstevel@tonic-gate {
7960Sstevel@tonic-gate 	*vpp = (vnode_t *)vfstofni(vfsp)->fi_rootvp;
7970Sstevel@tonic-gate 	VN_HOLD(*vpp);
7980Sstevel@tonic-gate 
7990Sstevel@tonic-gate 	AUTOFS_DPRINT((5, "auto_root: vfs %p, *vpp %p\n", (void *)vfsp,
8000Sstevel@tonic-gate 	    (void *)*vpp));
8010Sstevel@tonic-gate 	return (0);
8020Sstevel@tonic-gate }
8030Sstevel@tonic-gate 
8040Sstevel@tonic-gate /*
8050Sstevel@tonic-gate  * Get file system statistics.
8060Sstevel@tonic-gate  */
8070Sstevel@tonic-gate static int
8080Sstevel@tonic-gate auto_statvfs(vfs_t *vfsp, struct statvfs64 *sbp)
8090Sstevel@tonic-gate {
8100Sstevel@tonic-gate 	dev32_t d32;
8110Sstevel@tonic-gate 
8120Sstevel@tonic-gate 	AUTOFS_DPRINT((4, "auto_statvfs %p\n", (void *)vfsp));
8130Sstevel@tonic-gate 
8140Sstevel@tonic-gate 	bzero(sbp, sizeof (*sbp));
8150Sstevel@tonic-gate 	sbp->f_bsize	= vfsp->vfs_bsize;
8160Sstevel@tonic-gate 	sbp->f_frsize	= sbp->f_bsize;
8170Sstevel@tonic-gate 	sbp->f_blocks	= (fsblkcnt64_t)0;
8180Sstevel@tonic-gate 	sbp->f_bfree	= (fsblkcnt64_t)0;
8190Sstevel@tonic-gate 	sbp->f_bavail	= (fsblkcnt64_t)0;
8200Sstevel@tonic-gate 	sbp->f_files	= (fsfilcnt64_t)0;
8210Sstevel@tonic-gate 	sbp->f_ffree	= (fsfilcnt64_t)0;
8220Sstevel@tonic-gate 	sbp->f_favail	= (fsfilcnt64_t)0;
8230Sstevel@tonic-gate 	(void) cmpldev(&d32, vfsp->vfs_dev);
8240Sstevel@tonic-gate 	sbp->f_fsid	= d32;
8250Sstevel@tonic-gate 	(void) strcpy(sbp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name);
8260Sstevel@tonic-gate 	sbp->f_flag = vf_to_stf(vfsp->vfs_flag);
8270Sstevel@tonic-gate 	sbp->f_namemax = MAXNAMELEN;
8280Sstevel@tonic-gate 	(void) strcpy(sbp->f_fstr, MNTTYPE_AUTOFS);
8290Sstevel@tonic-gate 
8300Sstevel@tonic-gate 	return (0);
8310Sstevel@tonic-gate }
832