xref: /titanic_54/usr/src/uts/common/fs/vnode.c (revision ca2c313831d5ab50b351578f2405a2c129436534)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate  * The Regents of the University of California
337c478bd9Sstevel@tonic-gate  * All Rights Reserved
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate  * contributors.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #include <sys/types.h>
447c478bd9Sstevel@tonic-gate #include <sys/param.h>
457c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
467c478bd9Sstevel@tonic-gate #include <sys/errno.h>
477c478bd9Sstevel@tonic-gate #include <sys/cred.h>
487c478bd9Sstevel@tonic-gate #include <sys/user.h>
497c478bd9Sstevel@tonic-gate #include <sys/uio.h>
507c478bd9Sstevel@tonic-gate #include <sys/file.h>
517c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
527c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
537c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
547c478bd9Sstevel@tonic-gate #include <sys/rwstlock.h>
557c478bd9Sstevel@tonic-gate #include <sys/fem.h>
567c478bd9Sstevel@tonic-gate #include <sys/stat.h>
577c478bd9Sstevel@tonic-gate #include <sys/mode.h>
587c478bd9Sstevel@tonic-gate #include <sys/conf.h>
597c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
607c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
617c478bd9Sstevel@tonic-gate #include <sys/systm.h>
627c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
637c478bd9Sstevel@tonic-gate #include <sys/debug.h>
647c478bd9Sstevel@tonic-gate #include <c2/audit.h>
657c478bd9Sstevel@tonic-gate #include <sys/acl.h>
667c478bd9Sstevel@tonic-gate #include <sys/nbmlock.h>
677c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
687c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h>
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /* Determine if this vnode is a file that is read-only */
717c478bd9Sstevel@tonic-gate #define	ISROFILE(vp)	\
727c478bd9Sstevel@tonic-gate 	((vp)->v_type != VCHR && (vp)->v_type != VBLK && \
737c478bd9Sstevel@tonic-gate 	    (vp)->v_type != VFIFO && vn_is_readonly(vp))
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * Convert stat(2) formats to vnode types and vice versa.  (Knows about
777c478bd9Sstevel@tonic-gate  * numerical order of S_IFMT and vnode types.)
787c478bd9Sstevel@tonic-gate  */
797c478bd9Sstevel@tonic-gate enum vtype iftovt_tab[] = {
807c478bd9Sstevel@tonic-gate 	VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
817c478bd9Sstevel@tonic-gate 	VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VNON
827c478bd9Sstevel@tonic-gate };
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate ushort_t vttoif_tab[] = {
857c478bd9Sstevel@tonic-gate 	0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, S_IFIFO,
867c478bd9Sstevel@tonic-gate 	S_IFDOOR, 0, S_IFSOCK, S_IFPORT, 0
877c478bd9Sstevel@tonic-gate };
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  * The system vnode cache.
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate kmem_cache_t *vn_cache;
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * Vnode operations vector.
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate static const fs_operation_trans_def_t vn_ops_table[] = {
1017c478bd9Sstevel@tonic-gate 	VOPNAME_OPEN, offsetof(struct vnodeops, vop_open),
1027c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	VOPNAME_CLOSE, offsetof(struct vnodeops, vop_close),
1057c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	VOPNAME_READ, offsetof(struct vnodeops, vop_read),
1087c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	VOPNAME_WRITE, offsetof(struct vnodeops, vop_write),
1117c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	VOPNAME_IOCTL, offsetof(struct vnodeops, vop_ioctl),
1147c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	VOPNAME_SETFL, offsetof(struct vnodeops, vop_setfl),
1177c478bd9Sstevel@tonic-gate 	    fs_setfl, fs_nosys,
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 	VOPNAME_GETATTR, offsetof(struct vnodeops, vop_getattr),
1207c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	VOPNAME_SETATTR, offsetof(struct vnodeops, vop_setattr),
1237c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	VOPNAME_ACCESS, offsetof(struct vnodeops, vop_access),
1267c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	VOPNAME_LOOKUP, offsetof(struct vnodeops, vop_lookup),
1297c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 	VOPNAME_CREATE, offsetof(struct vnodeops, vop_create),
1327c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	VOPNAME_REMOVE, offsetof(struct vnodeops, vop_remove),
1357c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 	VOPNAME_LINK, offsetof(struct vnodeops, vop_link),
1387c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	VOPNAME_RENAME, offsetof(struct vnodeops, vop_rename),
1417c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	VOPNAME_MKDIR, offsetof(struct vnodeops, vop_mkdir),
1447c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	VOPNAME_RMDIR, offsetof(struct vnodeops, vop_rmdir),
1477c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	VOPNAME_READDIR, offsetof(struct vnodeops, vop_readdir),
1507c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	VOPNAME_SYMLINK, offsetof(struct vnodeops, vop_symlink),
1537c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	VOPNAME_READLINK, offsetof(struct vnodeops, vop_readlink),
1567c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	VOPNAME_FSYNC, offsetof(struct vnodeops, vop_fsync),
1597c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	VOPNAME_INACTIVE, offsetof(struct vnodeops, vop_inactive),
1627c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	VOPNAME_FID, offsetof(struct vnodeops, vop_fid),
1657c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	VOPNAME_RWLOCK, offsetof(struct vnodeops, vop_rwlock),
1687c478bd9Sstevel@tonic-gate 	    fs_rwlock, fs_rwlock,
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	VOPNAME_RWUNLOCK, offsetof(struct vnodeops, vop_rwunlock),
1717c478bd9Sstevel@tonic-gate 	    (fs_generic_func_p) fs_rwunlock,
1727c478bd9Sstevel@tonic-gate 	    (fs_generic_func_p) fs_rwunlock,	/* no errors allowed */
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 	VOPNAME_SEEK, offsetof(struct vnodeops, vop_seek),
1757c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	VOPNAME_CMP, offsetof(struct vnodeops, vop_cmp),
1787c478bd9Sstevel@tonic-gate 	    fs_cmp, fs_cmp,		/* no errors allowed */
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	VOPNAME_FRLOCK, offsetof(struct vnodeops, vop_frlock),
1817c478bd9Sstevel@tonic-gate 	    fs_frlock, fs_nosys,
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	VOPNAME_SPACE, offsetof(struct vnodeops, vop_space),
1847c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	VOPNAME_REALVP, offsetof(struct vnodeops, vop_realvp),
1877c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	VOPNAME_GETPAGE, offsetof(struct vnodeops, vop_getpage),
1907c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	VOPNAME_PUTPAGE, offsetof(struct vnodeops, vop_putpage),
1937c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 	VOPNAME_MAP, offsetof(struct vnodeops, vop_map),
1967c478bd9Sstevel@tonic-gate 	    (fs_generic_func_p) fs_nosys_map,
1977c478bd9Sstevel@tonic-gate 	    (fs_generic_func_p) fs_nosys_map,
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	VOPNAME_ADDMAP, offsetof(struct vnodeops, vop_addmap),
2007c478bd9Sstevel@tonic-gate 	    (fs_generic_func_p) fs_nosys_addmap,
2017c478bd9Sstevel@tonic-gate 	    (fs_generic_func_p) fs_nosys_addmap,
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	VOPNAME_DELMAP, offsetof(struct vnodeops, vop_delmap),
2047c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	VOPNAME_POLL, offsetof(struct vnodeops, vop_poll),
2077c478bd9Sstevel@tonic-gate 	    (fs_generic_func_p) fs_poll, (fs_generic_func_p) fs_nosys_poll,
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 	VOPNAME_DUMP, offsetof(struct vnodeops, vop_dump),
2107c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	VOPNAME_PATHCONF, offsetof(struct vnodeops, vop_pathconf),
2137c478bd9Sstevel@tonic-gate 	    fs_pathconf, fs_nosys,
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	VOPNAME_PAGEIO, offsetof(struct vnodeops, vop_pageio),
2167c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	VOPNAME_DUMPCTL, offsetof(struct vnodeops, vop_dumpctl),
2197c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	VOPNAME_DISPOSE, offsetof(struct vnodeops, vop_dispose),
2227c478bd9Sstevel@tonic-gate 	    (fs_generic_func_p) fs_dispose,
2237c478bd9Sstevel@tonic-gate 	    (fs_generic_func_p) fs_nodispose,
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	VOPNAME_SETSECATTR, offsetof(struct vnodeops, vop_setsecattr),
2267c478bd9Sstevel@tonic-gate 	    fs_nosys, fs_nosys,
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	VOPNAME_GETSECATTR, offsetof(struct vnodeops, vop_getsecattr),
2297c478bd9Sstevel@tonic-gate 	    fs_fab_acl, fs_nosys,
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	VOPNAME_SHRLOCK, offsetof(struct vnodeops, vop_shrlock),
2327c478bd9Sstevel@tonic-gate 	    fs_shrlock, fs_nosys,
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	VOPNAME_VNEVENT, offsetof(struct vnodeops, vop_vnevent),
2357c478bd9Sstevel@tonic-gate 	    (fs_generic_func_p) fs_vnevent_nosupport,
2367c478bd9Sstevel@tonic-gate 	    (fs_generic_func_p) fs_vnevent_nosupport,
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 	NULL, 0, NULL, NULL
2397c478bd9Sstevel@tonic-gate };
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate /*
2437c478bd9Sstevel@tonic-gate  * Read or write a vnode.  Called from kernel code.
2447c478bd9Sstevel@tonic-gate  */
2457c478bd9Sstevel@tonic-gate int
2467c478bd9Sstevel@tonic-gate vn_rdwr(
2477c478bd9Sstevel@tonic-gate 	enum uio_rw rw,
2487c478bd9Sstevel@tonic-gate 	struct vnode *vp,
2497c478bd9Sstevel@tonic-gate 	caddr_t base,
2507c478bd9Sstevel@tonic-gate 	ssize_t len,
2517c478bd9Sstevel@tonic-gate 	offset_t offset,
2527c478bd9Sstevel@tonic-gate 	enum uio_seg seg,
2537c478bd9Sstevel@tonic-gate 	int ioflag,
2547c478bd9Sstevel@tonic-gate 	rlim64_t ulimit,	/* meaningful only if rw is UIO_WRITE */
2557c478bd9Sstevel@tonic-gate 	cred_t *cr,
2567c478bd9Sstevel@tonic-gate 	ssize_t *residp)
2577c478bd9Sstevel@tonic-gate {
2587c478bd9Sstevel@tonic-gate 	struct uio uio;
2597c478bd9Sstevel@tonic-gate 	struct iovec iov;
2607c478bd9Sstevel@tonic-gate 	int error;
2617c478bd9Sstevel@tonic-gate 	int in_crit = 0;
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	if (rw == UIO_WRITE && ISROFILE(vp))
2647c478bd9Sstevel@tonic-gate 		return (EROFS);
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 	if (len < 0)
2677c478bd9Sstevel@tonic-gate 		return (EIO);
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	iov.iov_base = base;
2707c478bd9Sstevel@tonic-gate 	iov.iov_len = len;
2717c478bd9Sstevel@tonic-gate 	uio.uio_iov = &iov;
2727c478bd9Sstevel@tonic-gate 	uio.uio_iovcnt = 1;
2737c478bd9Sstevel@tonic-gate 	uio.uio_loffset = offset;
2747c478bd9Sstevel@tonic-gate 	uio.uio_segflg = (short)seg;
2757c478bd9Sstevel@tonic-gate 	uio.uio_resid = len;
2767c478bd9Sstevel@tonic-gate 	uio.uio_llimit = ulimit;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	/*
2797c478bd9Sstevel@tonic-gate 	 * We have to enter the critical region before calling VOP_RWLOCK
2807c478bd9Sstevel@tonic-gate 	 * to avoid a deadlock with ufs.
2817c478bd9Sstevel@tonic-gate 	 */
2827c478bd9Sstevel@tonic-gate 	if (nbl_need_check(vp)) {
2837c478bd9Sstevel@tonic-gate 		int svmand;
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 		nbl_start_crit(vp, RW_READER);
2867c478bd9Sstevel@tonic-gate 		in_crit = 1;
2877c478bd9Sstevel@tonic-gate 		error = nbl_svmand(vp, cr, &svmand);
2887c478bd9Sstevel@tonic-gate 		if (error != 0)
2897c478bd9Sstevel@tonic-gate 			goto done;
2907c478bd9Sstevel@tonic-gate 		if (nbl_conflict(vp, rw == UIO_WRITE ? NBL_WRITE : NBL_READ,
2917c478bd9Sstevel@tonic-gate 		    uio.uio_offset, uio.uio_resid, svmand)) {
2927c478bd9Sstevel@tonic-gate 			error = EACCES;
2937c478bd9Sstevel@tonic-gate 			goto done;
2947c478bd9Sstevel@tonic-gate 		}
2957c478bd9Sstevel@tonic-gate 	}
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	(void) VOP_RWLOCK(vp,
2987c478bd9Sstevel@tonic-gate 		rw == UIO_WRITE ? V_WRITELOCK_TRUE : V_WRITELOCK_FALSE, NULL);
2997c478bd9Sstevel@tonic-gate 	if (rw == UIO_WRITE) {
3007c478bd9Sstevel@tonic-gate 		uio.uio_fmode = FWRITE;
3017c478bd9Sstevel@tonic-gate 		uio.uio_extflg = UIO_COPY_DEFAULT;
3027c478bd9Sstevel@tonic-gate 		error = VOP_WRITE(vp, &uio, ioflag, cr, NULL);
3037c478bd9Sstevel@tonic-gate 	} else {
3047c478bd9Sstevel@tonic-gate 		uio.uio_fmode = FREAD;
3057c478bd9Sstevel@tonic-gate 		uio.uio_extflg = UIO_COPY_CACHED;
3067c478bd9Sstevel@tonic-gate 		error = VOP_READ(vp, &uio, ioflag, cr, NULL);
3077c478bd9Sstevel@tonic-gate 	}
3087c478bd9Sstevel@tonic-gate 	VOP_RWUNLOCK(vp, rw == UIO_WRITE ? V_WRITELOCK_TRUE : V_WRITELOCK_FALSE,
3097c478bd9Sstevel@tonic-gate 									NULL);
3107c478bd9Sstevel@tonic-gate 	if (residp)
3117c478bd9Sstevel@tonic-gate 		*residp = uio.uio_resid;
3127c478bd9Sstevel@tonic-gate 	else if (uio.uio_resid)
3137c478bd9Sstevel@tonic-gate 		error = EIO;
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate done:
3167c478bd9Sstevel@tonic-gate 	if (in_crit)
3177c478bd9Sstevel@tonic-gate 		nbl_end_crit(vp);
3187c478bd9Sstevel@tonic-gate 	return (error);
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate /*
3227c478bd9Sstevel@tonic-gate  * Release a vnode.  Call VOP_INACTIVE on last reference or
3237c478bd9Sstevel@tonic-gate  * decrement reference count.
3247c478bd9Sstevel@tonic-gate  *
3257c478bd9Sstevel@tonic-gate  * To avoid race conditions, the v_count is left at 1 for
3267c478bd9Sstevel@tonic-gate  * the call to VOP_INACTIVE. This prevents another thread
3277c478bd9Sstevel@tonic-gate  * from reclaiming and releasing the vnode *before* the
3287c478bd9Sstevel@tonic-gate  * VOP_INACTIVE routine has a chance to destroy the vnode.
3297c478bd9Sstevel@tonic-gate  * We can't have more than 1 thread calling VOP_INACTIVE
3307c478bd9Sstevel@tonic-gate  * on a vnode.
3317c478bd9Sstevel@tonic-gate  */
3327c478bd9Sstevel@tonic-gate void
3337c478bd9Sstevel@tonic-gate vn_rele(vnode_t *vp)
3347c478bd9Sstevel@tonic-gate {
3357c478bd9Sstevel@tonic-gate 	if (vp->v_count == 0)
3367c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "vn_rele: vnode ref count 0");
3377c478bd9Sstevel@tonic-gate 	mutex_enter(&vp->v_lock);
3387c478bd9Sstevel@tonic-gate 	if (vp->v_count == 1) {
3397c478bd9Sstevel@tonic-gate 		mutex_exit(&vp->v_lock);
3407c478bd9Sstevel@tonic-gate 		VOP_INACTIVE(vp, CRED());
3417c478bd9Sstevel@tonic-gate 	} else {
3427c478bd9Sstevel@tonic-gate 		vp->v_count--;
3437c478bd9Sstevel@tonic-gate 		mutex_exit(&vp->v_lock);
3447c478bd9Sstevel@tonic-gate 	}
3457c478bd9Sstevel@tonic-gate }
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate /*
3487c478bd9Sstevel@tonic-gate  * Like vn_rele() except that it clears v_stream under v_lock.
3497c478bd9Sstevel@tonic-gate  * This is used by sockfs when it dismantels the association between
3507c478bd9Sstevel@tonic-gate  * the sockfs node and the vnode in the underlaying file system.
3517c478bd9Sstevel@tonic-gate  * v_lock has to be held to prevent a thread coming through the lookupname
3527c478bd9Sstevel@tonic-gate  * path from accessing a stream head that is going away.
3537c478bd9Sstevel@tonic-gate  */
3547c478bd9Sstevel@tonic-gate void
3557c478bd9Sstevel@tonic-gate vn_rele_stream(vnode_t *vp)
3567c478bd9Sstevel@tonic-gate {
3577c478bd9Sstevel@tonic-gate 	if (vp->v_count == 0)
3587c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "vn_rele: vnode ref count 0");
3597c478bd9Sstevel@tonic-gate 	mutex_enter(&vp->v_lock);
3607c478bd9Sstevel@tonic-gate 	vp->v_stream = NULL;
3617c478bd9Sstevel@tonic-gate 	if (vp->v_count == 1) {
3627c478bd9Sstevel@tonic-gate 		mutex_exit(&vp->v_lock);
3637c478bd9Sstevel@tonic-gate 		VOP_INACTIVE(vp, CRED());
3647c478bd9Sstevel@tonic-gate 	} else {
3657c478bd9Sstevel@tonic-gate 		vp->v_count--;
3667c478bd9Sstevel@tonic-gate 		mutex_exit(&vp->v_lock);
3677c478bd9Sstevel@tonic-gate 	}
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate int
3717c478bd9Sstevel@tonic-gate vn_open(
3727c478bd9Sstevel@tonic-gate 	char *pnamep,
3737c478bd9Sstevel@tonic-gate 	enum uio_seg seg,
3747c478bd9Sstevel@tonic-gate 	int filemode,
3757c478bd9Sstevel@tonic-gate 	int createmode,
3767c478bd9Sstevel@tonic-gate 	struct vnode **vpp,
3777c478bd9Sstevel@tonic-gate 	enum create crwhy,
3787c478bd9Sstevel@tonic-gate 	mode_t umask)
3797c478bd9Sstevel@tonic-gate {
3807c478bd9Sstevel@tonic-gate 	return (vn_openat(pnamep, seg, filemode,
3817c478bd9Sstevel@tonic-gate 			createmode, vpp, crwhy, umask, NULL));
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate /*
3867c478bd9Sstevel@tonic-gate  * Open/create a vnode.
3877c478bd9Sstevel@tonic-gate  * This may be callable by the kernel, the only known use
3887c478bd9Sstevel@tonic-gate  * of user context being that the current user credentials
3897c478bd9Sstevel@tonic-gate  * are used for permissions.  crwhy is defined iff filemode & FCREAT.
3907c478bd9Sstevel@tonic-gate  */
3917c478bd9Sstevel@tonic-gate int
3927c478bd9Sstevel@tonic-gate vn_openat(
3937c478bd9Sstevel@tonic-gate 	char *pnamep,
3947c478bd9Sstevel@tonic-gate 	enum uio_seg seg,
3957c478bd9Sstevel@tonic-gate 	int filemode,
3967c478bd9Sstevel@tonic-gate 	int createmode,
3977c478bd9Sstevel@tonic-gate 	struct vnode **vpp,
3987c478bd9Sstevel@tonic-gate 	enum create crwhy,
3997c478bd9Sstevel@tonic-gate 	mode_t umask,
4007c478bd9Sstevel@tonic-gate 	struct vnode *startvp)
4017c478bd9Sstevel@tonic-gate {
4027c478bd9Sstevel@tonic-gate 	struct vnode *vp;
4037c478bd9Sstevel@tonic-gate 	int mode;
4047c478bd9Sstevel@tonic-gate 	int error;
4057c478bd9Sstevel@tonic-gate 	int in_crit = 0;
4067c478bd9Sstevel@tonic-gate 	struct vattr vattr;
4077c478bd9Sstevel@tonic-gate 	enum symfollow follow;
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 	mode = 0;
4107c478bd9Sstevel@tonic-gate 	if (filemode & FREAD)
4117c478bd9Sstevel@tonic-gate 		mode |= VREAD;
4127c478bd9Sstevel@tonic-gate 	if (filemode & (FWRITE|FTRUNC))
4137c478bd9Sstevel@tonic-gate 		mode |= VWRITE;
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 	/* symlink interpretation */
4167c478bd9Sstevel@tonic-gate 	if (filemode & FNOFOLLOW)
4177c478bd9Sstevel@tonic-gate 		follow = NO_FOLLOW;
4187c478bd9Sstevel@tonic-gate 	else
4197c478bd9Sstevel@tonic-gate 		follow = FOLLOW;
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate top:
4227c478bd9Sstevel@tonic-gate 	if (filemode & FCREAT) {
4237c478bd9Sstevel@tonic-gate 		enum vcexcl excl;
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate 		/*
4267c478bd9Sstevel@tonic-gate 		 * Wish to create a file.
4277c478bd9Sstevel@tonic-gate 		 */
4287c478bd9Sstevel@tonic-gate 		vattr.va_type = VREG;
4297c478bd9Sstevel@tonic-gate 		vattr.va_mode = createmode;
4307c478bd9Sstevel@tonic-gate 		vattr.va_mask = AT_TYPE|AT_MODE;
4317c478bd9Sstevel@tonic-gate 		if (filemode & FTRUNC) {
4327c478bd9Sstevel@tonic-gate 			vattr.va_size = 0;
4337c478bd9Sstevel@tonic-gate 			vattr.va_mask |= AT_SIZE;
4347c478bd9Sstevel@tonic-gate 		}
4357c478bd9Sstevel@tonic-gate 		if (filemode & FEXCL)
4367c478bd9Sstevel@tonic-gate 			excl = EXCL;
4377c478bd9Sstevel@tonic-gate 		else
4387c478bd9Sstevel@tonic-gate 			excl = NONEXCL;
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate 		if (error =
4417c478bd9Sstevel@tonic-gate 		    vn_createat(pnamep, seg, &vattr, excl, mode, &vp, crwhy,
4427c478bd9Sstevel@tonic-gate 					(filemode & ~(FTRUNC|FEXCL)),
4437c478bd9Sstevel@tonic-gate 						umask, startvp))
4447c478bd9Sstevel@tonic-gate 			return (error);
4457c478bd9Sstevel@tonic-gate 	} else {
4467c478bd9Sstevel@tonic-gate 		/*
4477c478bd9Sstevel@tonic-gate 		 * Wish to open a file.  Just look it up.
4487c478bd9Sstevel@tonic-gate 		 */
4497c478bd9Sstevel@tonic-gate 		if (error = lookupnameat(pnamep, seg, follow,
4507c478bd9Sstevel@tonic-gate 		    NULLVPP, &vp, startvp)) {
4517c478bd9Sstevel@tonic-gate 			if (error == ESTALE)
4527c478bd9Sstevel@tonic-gate 				goto top;
4537c478bd9Sstevel@tonic-gate 			return (error);
4547c478bd9Sstevel@tonic-gate 		}
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 		/*
4577c478bd9Sstevel@tonic-gate 		 * Get the attributes to check whether file is large.
4587c478bd9Sstevel@tonic-gate 		 * We do this only if the FOFFMAX flag is not set and
4597c478bd9Sstevel@tonic-gate 		 * only for regular files.
4607c478bd9Sstevel@tonic-gate 		 */
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 		if (!(filemode & FOFFMAX) && (vp->v_type == VREG)) {
4637c478bd9Sstevel@tonic-gate 			vattr.va_mask = AT_SIZE;
4647c478bd9Sstevel@tonic-gate 			if ((error = VOP_GETATTR(vp, &vattr, 0, CRED()))) {
4657c478bd9Sstevel@tonic-gate 				goto out;
4667c478bd9Sstevel@tonic-gate 			}
4677c478bd9Sstevel@tonic-gate 			if (vattr.va_size > (u_offset_t)MAXOFF32_T) {
4687c478bd9Sstevel@tonic-gate 				/*
4697c478bd9Sstevel@tonic-gate 				 * Large File API - regular open fails
4707c478bd9Sstevel@tonic-gate 				 * if FOFFMAX flag is set in file mode
4717c478bd9Sstevel@tonic-gate 				 */
4727c478bd9Sstevel@tonic-gate 				error = EOVERFLOW;
4737c478bd9Sstevel@tonic-gate 				goto out;
4747c478bd9Sstevel@tonic-gate 			}
4757c478bd9Sstevel@tonic-gate 		}
4767c478bd9Sstevel@tonic-gate 		/*
4777c478bd9Sstevel@tonic-gate 		 * Can't write directories, active texts, or
4787c478bd9Sstevel@tonic-gate 		 * read-only filesystems.  Can't truncate files
4797c478bd9Sstevel@tonic-gate 		 * on which mandatory locking is in effect.
4807c478bd9Sstevel@tonic-gate 		 */
4817c478bd9Sstevel@tonic-gate 		if (filemode & (FWRITE|FTRUNC)) {
4827c478bd9Sstevel@tonic-gate 			/*
4837c478bd9Sstevel@tonic-gate 			 * Allow writable directory if VDIROPEN flag is set.
4847c478bd9Sstevel@tonic-gate 			 */
4857c478bd9Sstevel@tonic-gate 			if (vp->v_type == VDIR && !(vp->v_flag & VDIROPEN)) {
4867c478bd9Sstevel@tonic-gate 				error = EISDIR;
4877c478bd9Sstevel@tonic-gate 				goto out;
4887c478bd9Sstevel@tonic-gate 			}
4897c478bd9Sstevel@tonic-gate 			if (ISROFILE(vp)) {
4907c478bd9Sstevel@tonic-gate 				error = EROFS;
4917c478bd9Sstevel@tonic-gate 				goto out;
4927c478bd9Sstevel@tonic-gate 			}
4937c478bd9Sstevel@tonic-gate 			/*
4947c478bd9Sstevel@tonic-gate 			 * Can't truncate files on which mandatory locking
4957c478bd9Sstevel@tonic-gate 			 * or non-blocking mandatory locking is in effect.
4967c478bd9Sstevel@tonic-gate 			 */
4977c478bd9Sstevel@tonic-gate 			if (filemode & FTRUNC) {
4987c478bd9Sstevel@tonic-gate 				vnode_t *rvp;
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate 				if (VOP_REALVP(vp, &rvp) != 0)
5017c478bd9Sstevel@tonic-gate 					rvp = vp;
5027c478bd9Sstevel@tonic-gate 				if (nbl_need_check(vp)) {
5037c478bd9Sstevel@tonic-gate 					nbl_start_crit(vp, RW_READER);
5047c478bd9Sstevel@tonic-gate 					in_crit = 1;
5057c478bd9Sstevel@tonic-gate 					vattr.va_mask = AT_MODE|AT_SIZE;
5067c478bd9Sstevel@tonic-gate 					if ((error = VOP_GETATTR(vp, &vattr, 0,
5077c478bd9Sstevel@tonic-gate 					    CRED())) == 0) {
5087c478bd9Sstevel@tonic-gate 						if (rvp->v_filocks != NULL)
5097c478bd9Sstevel@tonic-gate 							if (MANDLOCK(vp,
5107c478bd9Sstevel@tonic-gate 							    vattr.va_mode))
5117c478bd9Sstevel@tonic-gate 								error = EAGAIN;
5127c478bd9Sstevel@tonic-gate 						if (!error) {
5137c478bd9Sstevel@tonic-gate 							if (nbl_conflict(vp,
5147c478bd9Sstevel@tonic-gate 							    NBL_WRITE, 0,
5157c478bd9Sstevel@tonic-gate 							    vattr.va_size, 0))
5167c478bd9Sstevel@tonic-gate 								error = EACCES;
5177c478bd9Sstevel@tonic-gate 						}
5187c478bd9Sstevel@tonic-gate 					}
5197c478bd9Sstevel@tonic-gate 				} else if (rvp->v_filocks != NULL) {
5207c478bd9Sstevel@tonic-gate 					vattr.va_mask = AT_MODE;
5217c478bd9Sstevel@tonic-gate 					if ((error = VOP_GETATTR(vp, &vattr,
5227c478bd9Sstevel@tonic-gate 					    0, CRED())) == 0 && MANDLOCK(vp,
5237c478bd9Sstevel@tonic-gate 					    vattr.va_mode))
5247c478bd9Sstevel@tonic-gate 						error = EAGAIN;
5257c478bd9Sstevel@tonic-gate 				}
5267c478bd9Sstevel@tonic-gate 			}
5277c478bd9Sstevel@tonic-gate 			if (error)
5287c478bd9Sstevel@tonic-gate 				goto out;
5297c478bd9Sstevel@tonic-gate 		}
5307c478bd9Sstevel@tonic-gate 		/*
5317c478bd9Sstevel@tonic-gate 		 * Check permissions.
5327c478bd9Sstevel@tonic-gate 		 */
5337c478bd9Sstevel@tonic-gate 		if (error = VOP_ACCESS(vp, mode, 0, CRED()))
5347c478bd9Sstevel@tonic-gate 			goto out;
5357c478bd9Sstevel@tonic-gate 	}
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	/*
5387c478bd9Sstevel@tonic-gate 	 * Do remaining checks for FNOFOLLOW and FNOLINKS.
5397c478bd9Sstevel@tonic-gate 	 */
5407c478bd9Sstevel@tonic-gate 	if ((filemode & FNOFOLLOW) && vp->v_type == VLNK) {
5417c478bd9Sstevel@tonic-gate 		error = EINVAL;
5427c478bd9Sstevel@tonic-gate 		goto out;
5437c478bd9Sstevel@tonic-gate 	}
5447c478bd9Sstevel@tonic-gate 	if (filemode & FNOLINKS) {
5457c478bd9Sstevel@tonic-gate 		vattr.va_mask = AT_NLINK;
5467c478bd9Sstevel@tonic-gate 		if ((error = VOP_GETATTR(vp, &vattr, 0, CRED()))) {
5477c478bd9Sstevel@tonic-gate 			goto out;
5487c478bd9Sstevel@tonic-gate 		}
5497c478bd9Sstevel@tonic-gate 		if (vattr.va_nlink != 1) {
5507c478bd9Sstevel@tonic-gate 			error = EMLINK;
5517c478bd9Sstevel@tonic-gate 			goto out;
5527c478bd9Sstevel@tonic-gate 		}
5537c478bd9Sstevel@tonic-gate 	}
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate 	/*
5567c478bd9Sstevel@tonic-gate 	 * Opening a socket corresponding to the AF_UNIX pathname
5577c478bd9Sstevel@tonic-gate 	 * in the filesystem name space is not supported.
5587c478bd9Sstevel@tonic-gate 	 * However, VSOCK nodes in namefs are supported in order
5597c478bd9Sstevel@tonic-gate 	 * to make fattach work for sockets.
5607c478bd9Sstevel@tonic-gate 	 *
5617c478bd9Sstevel@tonic-gate 	 * XXX This uses VOP_REALVP to distinguish between
5627c478bd9Sstevel@tonic-gate 	 * an unopened namefs node (where VOP_REALVP returns a
5637c478bd9Sstevel@tonic-gate 	 * different VSOCK vnode) and a VSOCK created by vn_create
5647c478bd9Sstevel@tonic-gate 	 * in some file system (where VOP_REALVP would never return
5657c478bd9Sstevel@tonic-gate 	 * a different vnode).
5667c478bd9Sstevel@tonic-gate 	 */
5677c478bd9Sstevel@tonic-gate 	if (vp->v_type == VSOCK) {
5687c478bd9Sstevel@tonic-gate 		struct vnode *nvp;
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate 		error = VOP_REALVP(vp, &nvp);
5717c478bd9Sstevel@tonic-gate 		if (error != 0 || nvp == NULL || nvp == vp ||
5727c478bd9Sstevel@tonic-gate 		    nvp->v_type != VSOCK) {
5737c478bd9Sstevel@tonic-gate 			error = EOPNOTSUPP;
5747c478bd9Sstevel@tonic-gate 			goto out;
5757c478bd9Sstevel@tonic-gate 		}
5767c478bd9Sstevel@tonic-gate 	}
5777c478bd9Sstevel@tonic-gate 	/*
5787c478bd9Sstevel@tonic-gate 	 * Do opening protocol.
5797c478bd9Sstevel@tonic-gate 	 */
5807c478bd9Sstevel@tonic-gate 	error = VOP_OPEN(&vp, filemode, CRED());
5817c478bd9Sstevel@tonic-gate 	/*
5827c478bd9Sstevel@tonic-gate 	 * Truncate if required.
5837c478bd9Sstevel@tonic-gate 	 */
5847c478bd9Sstevel@tonic-gate 	if (error == 0 && (filemode & FTRUNC) && !(filemode & FCREAT)) {
5857c478bd9Sstevel@tonic-gate 		vattr.va_size = 0;
5867c478bd9Sstevel@tonic-gate 		vattr.va_mask = AT_SIZE;
5877c478bd9Sstevel@tonic-gate 		if ((error = VOP_SETATTR(vp, &vattr, 0, CRED(), NULL)) != 0)
5887c478bd9Sstevel@tonic-gate 			(void) VOP_CLOSE(vp, filemode, 1, (offset_t)0, CRED());
5897c478bd9Sstevel@tonic-gate 	}
5907c478bd9Sstevel@tonic-gate out:
5917c478bd9Sstevel@tonic-gate 	ASSERT(vp->v_count > 0);
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate 	if (in_crit) {
5947c478bd9Sstevel@tonic-gate 		nbl_end_crit(vp);
5957c478bd9Sstevel@tonic-gate 		in_crit = 0;
5967c478bd9Sstevel@tonic-gate 	}
5977c478bd9Sstevel@tonic-gate 	if (error) {
5987c478bd9Sstevel@tonic-gate 		/*
5997c478bd9Sstevel@tonic-gate 		 * The following clause was added to handle a problem
6007c478bd9Sstevel@tonic-gate 		 * with NFS consistency.  It is possible that a lookup
6017c478bd9Sstevel@tonic-gate 		 * of the file to be opened succeeded, but the file
6027c478bd9Sstevel@tonic-gate 		 * itself doesn't actually exist on the server.  This
6037c478bd9Sstevel@tonic-gate 		 * is chiefly due to the DNLC containing an entry for
6047c478bd9Sstevel@tonic-gate 		 * the file which has been removed on the server.  In
6057c478bd9Sstevel@tonic-gate 		 * this case, we just start over.  If there was some
6067c478bd9Sstevel@tonic-gate 		 * other cause for the ESTALE error, then the lookup
6077c478bd9Sstevel@tonic-gate 		 * of the file will fail and the error will be returned
6087c478bd9Sstevel@tonic-gate 		 * above instead of looping around from here.
6097c478bd9Sstevel@tonic-gate 		 */
6107c478bd9Sstevel@tonic-gate 		VN_RELE(vp);
6117c478bd9Sstevel@tonic-gate 		if (error == ESTALE)
6127c478bd9Sstevel@tonic-gate 			goto top;
6137c478bd9Sstevel@tonic-gate 	} else
6147c478bd9Sstevel@tonic-gate 		*vpp = vp;
6157c478bd9Sstevel@tonic-gate 	return (error);
6167c478bd9Sstevel@tonic-gate }
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate int
6197c478bd9Sstevel@tonic-gate vn_create(
6207c478bd9Sstevel@tonic-gate 	char *pnamep,
6217c478bd9Sstevel@tonic-gate 	enum uio_seg seg,
6227c478bd9Sstevel@tonic-gate 	struct vattr *vap,
6237c478bd9Sstevel@tonic-gate 	enum vcexcl excl,
6247c478bd9Sstevel@tonic-gate 	int mode,
6257c478bd9Sstevel@tonic-gate 	struct vnode **vpp,
6267c478bd9Sstevel@tonic-gate 	enum create why,
6277c478bd9Sstevel@tonic-gate 	int flag,
6287c478bd9Sstevel@tonic-gate 	mode_t umask)
6297c478bd9Sstevel@tonic-gate {
6307c478bd9Sstevel@tonic-gate 	return (vn_createat(pnamep, seg, vap, excl, mode, vpp,
6317c478bd9Sstevel@tonic-gate 			why, flag, umask, NULL));
6327c478bd9Sstevel@tonic-gate }
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate /*
6357c478bd9Sstevel@tonic-gate  * Create a vnode (makenode).
6367c478bd9Sstevel@tonic-gate  */
6377c478bd9Sstevel@tonic-gate int
6387c478bd9Sstevel@tonic-gate vn_createat(
6397c478bd9Sstevel@tonic-gate 	char *pnamep,
6407c478bd9Sstevel@tonic-gate 	enum uio_seg seg,
6417c478bd9Sstevel@tonic-gate 	struct vattr *vap,
6427c478bd9Sstevel@tonic-gate 	enum vcexcl excl,
6437c478bd9Sstevel@tonic-gate 	int mode,
6447c478bd9Sstevel@tonic-gate 	struct vnode **vpp,
6457c478bd9Sstevel@tonic-gate 	enum create why,
6467c478bd9Sstevel@tonic-gate 	int flag,
6477c478bd9Sstevel@tonic-gate 	mode_t umask,
6487c478bd9Sstevel@tonic-gate 	struct vnode *startvp)
6497c478bd9Sstevel@tonic-gate {
6507c478bd9Sstevel@tonic-gate 	struct vnode *dvp;	/* ptr to parent dir vnode */
6517c478bd9Sstevel@tonic-gate 	struct vnode *vp = NULL;
6527c478bd9Sstevel@tonic-gate 	struct pathname pn;
6537c478bd9Sstevel@tonic-gate 	int error;
6547c478bd9Sstevel@tonic-gate 	int in_crit = 0;
6557c478bd9Sstevel@tonic-gate 	struct vattr vattr;
6567c478bd9Sstevel@tonic-gate 	enum symfollow follow;
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 	ASSERT((vap->va_mask & (AT_TYPE|AT_MODE)) == (AT_TYPE|AT_MODE));
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	/* symlink interpretation */
6617c478bd9Sstevel@tonic-gate 	if ((flag & FNOFOLLOW) || excl == EXCL)
6627c478bd9Sstevel@tonic-gate 		follow = NO_FOLLOW;
6637c478bd9Sstevel@tonic-gate 	else
6647c478bd9Sstevel@tonic-gate 		follow = FOLLOW;
6657c478bd9Sstevel@tonic-gate 	flag &= ~(FNOFOLLOW|FNOLINKS);
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate top:
6687c478bd9Sstevel@tonic-gate 	/*
6697c478bd9Sstevel@tonic-gate 	 * Lookup directory.
6707c478bd9Sstevel@tonic-gate 	 * If new object is a file, call lower level to create it.
6717c478bd9Sstevel@tonic-gate 	 * Note that it is up to the lower level to enforce exclusive
6727c478bd9Sstevel@tonic-gate 	 * creation, if the file is already there.
6737c478bd9Sstevel@tonic-gate 	 * This allows the lower level to do whatever
6747c478bd9Sstevel@tonic-gate 	 * locking or protocol that is needed to prevent races.
6757c478bd9Sstevel@tonic-gate 	 * If the new object is directory call lower level to make
6767c478bd9Sstevel@tonic-gate 	 * the new directory, with "." and "..".
6777c478bd9Sstevel@tonic-gate 	 */
6787c478bd9Sstevel@tonic-gate 	if (error = pn_get(pnamep, seg, &pn))
6797c478bd9Sstevel@tonic-gate 		return (error);
6807c478bd9Sstevel@tonic-gate #ifdef  C2_AUDIT
6817c478bd9Sstevel@tonic-gate 	if (audit_active)
6827c478bd9Sstevel@tonic-gate 		audit_vncreate_start();
6837c478bd9Sstevel@tonic-gate #endif /* C2_AUDIT */
6847c478bd9Sstevel@tonic-gate 	dvp = NULL;
6857c478bd9Sstevel@tonic-gate 	*vpp = NULL;
6867c478bd9Sstevel@tonic-gate 	/*
6877c478bd9Sstevel@tonic-gate 	 * lookup will find the parent directory for the vnode.
6887c478bd9Sstevel@tonic-gate 	 * When it is done the pn holds the name of the entry
6897c478bd9Sstevel@tonic-gate 	 * in the directory.
6907c478bd9Sstevel@tonic-gate 	 * If this is a non-exclusive create we also find the node itself.
6917c478bd9Sstevel@tonic-gate 	 */
6927c478bd9Sstevel@tonic-gate 	error = lookuppnat(&pn, NULL, follow, &dvp,
6937c478bd9Sstevel@tonic-gate 	    (excl == EXCL) ? NULLVPP : vpp, startvp);
6947c478bd9Sstevel@tonic-gate 	if (error) {
6957c478bd9Sstevel@tonic-gate 		pn_free(&pn);
6967c478bd9Sstevel@tonic-gate 		if (error == ESTALE)
6977c478bd9Sstevel@tonic-gate 			goto top;
6987c478bd9Sstevel@tonic-gate 		if (why == CRMKDIR && error == EINVAL)
6997c478bd9Sstevel@tonic-gate 			error = EEXIST;		/* SVID */
7007c478bd9Sstevel@tonic-gate 		return (error);
7017c478bd9Sstevel@tonic-gate 	}
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 	if (why != CRMKNOD)
7047c478bd9Sstevel@tonic-gate 		vap->va_mode &= ~VSVTX;
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate 	/*
7077c478bd9Sstevel@tonic-gate 	 * If default ACLs are defined for the directory don't apply the
7087c478bd9Sstevel@tonic-gate 	 * umask if umask is passed.
7097c478bd9Sstevel@tonic-gate 	 */
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate 	if (umask) {
7127c478bd9Sstevel@tonic-gate 
7137c478bd9Sstevel@tonic-gate 		vsecattr_t vsec;
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate 		vsec.vsa_aclcnt = 0;
7167c478bd9Sstevel@tonic-gate 		vsec.vsa_aclentp = NULL;
7177c478bd9Sstevel@tonic-gate 		vsec.vsa_dfaclcnt = 0;
7187c478bd9Sstevel@tonic-gate 		vsec.vsa_dfaclentp = NULL;
7197c478bd9Sstevel@tonic-gate 		vsec.vsa_mask = VSA_DFACLCNT;
7207c478bd9Sstevel@tonic-gate 		if (error = VOP_GETSECATTR(dvp, &vsec, 0, CRED())) {
7217c478bd9Sstevel@tonic-gate 			if (*vpp != NULL)
7227c478bd9Sstevel@tonic-gate 				VN_RELE(*vpp);
7237c478bd9Sstevel@tonic-gate 			goto out;
7247c478bd9Sstevel@tonic-gate 		}
7257c478bd9Sstevel@tonic-gate 
7267c478bd9Sstevel@tonic-gate 		/*
7277c478bd9Sstevel@tonic-gate 		 * Apply the umask if no default ACLs.
7287c478bd9Sstevel@tonic-gate 		 */
7297c478bd9Sstevel@tonic-gate 		if (vsec.vsa_dfaclcnt == 0)
7307c478bd9Sstevel@tonic-gate 			vap->va_mode &= ~umask;
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate 		/*
7337c478bd9Sstevel@tonic-gate 		 * VOP_GETSECATTR() may have allocated memory for ACLs we
7347c478bd9Sstevel@tonic-gate 		 * didn't request, so double-check and free it if necessary.
7357c478bd9Sstevel@tonic-gate 		 */
7367c478bd9Sstevel@tonic-gate 		if (vsec.vsa_aclcnt && vsec.vsa_aclentp != NULL)
7377c478bd9Sstevel@tonic-gate 			kmem_free((caddr_t)vsec.vsa_aclentp,
7387c478bd9Sstevel@tonic-gate 				vsec.vsa_aclcnt * sizeof (aclent_t));
7397c478bd9Sstevel@tonic-gate 		if (vsec.vsa_dfaclcnt && vsec.vsa_dfaclentp != NULL)
7407c478bd9Sstevel@tonic-gate 			kmem_free((caddr_t)vsec.vsa_dfaclentp,
7417c478bd9Sstevel@tonic-gate 				vsec.vsa_dfaclcnt * sizeof (aclent_t));
7427c478bd9Sstevel@tonic-gate 	}
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 	/*
7457c478bd9Sstevel@tonic-gate 	 * In general we want to generate EROFS if the file system is
7467c478bd9Sstevel@tonic-gate 	 * readonly.  However, POSIX (IEEE Std. 1003.1) section 5.3.1
7477c478bd9Sstevel@tonic-gate 	 * documents the open system call, and it says that O_CREAT has no
7487c478bd9Sstevel@tonic-gate 	 * effect if the file already exists.  Bug 1119649 states
7497c478bd9Sstevel@tonic-gate 	 * that open(path, O_CREAT, ...) fails when attempting to open an
7507c478bd9Sstevel@tonic-gate 	 * existing file on a read only file system.  Thus, the first part
7517c478bd9Sstevel@tonic-gate 	 * of the following if statement has 3 checks:
7527c478bd9Sstevel@tonic-gate 	 *	if the file exists &&
7537c478bd9Sstevel@tonic-gate 	 *		it is being open with write access &&
7547c478bd9Sstevel@tonic-gate 	 *		the file system is read only
7557c478bd9Sstevel@tonic-gate 	 *	then generate EROFS
7567c478bd9Sstevel@tonic-gate 	 */
7577c478bd9Sstevel@tonic-gate 	if ((*vpp != NULL && (mode & VWRITE) && ISROFILE(*vpp)) ||
7587c478bd9Sstevel@tonic-gate 	    (*vpp == NULL && dvp->v_vfsp->vfs_flag & VFS_RDONLY)) {
7597c478bd9Sstevel@tonic-gate 		if (*vpp)
7607c478bd9Sstevel@tonic-gate 			VN_RELE(*vpp);
7617c478bd9Sstevel@tonic-gate 		error = EROFS;
7627c478bd9Sstevel@tonic-gate 	} else if (excl == NONEXCL && *vpp != NULL) {
7637c478bd9Sstevel@tonic-gate 		vnode_t *rvp;
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate 		/*
7667c478bd9Sstevel@tonic-gate 		 * File already exists.  If a mandatory lock has been
7677c478bd9Sstevel@tonic-gate 		 * applied, return error.
7687c478bd9Sstevel@tonic-gate 		 */
7697c478bd9Sstevel@tonic-gate 		vp = *vpp;
7707c478bd9Sstevel@tonic-gate 		if (VOP_REALVP(vp, &rvp) != 0)
7717c478bd9Sstevel@tonic-gate 			rvp = vp;
7727c478bd9Sstevel@tonic-gate 		if ((vap->va_mask & AT_SIZE) && nbl_need_check(vp)) {
7737c478bd9Sstevel@tonic-gate 			nbl_start_crit(vp, RW_READER);
7747c478bd9Sstevel@tonic-gate 			in_crit = 1;
7757c478bd9Sstevel@tonic-gate 		}
7767c478bd9Sstevel@tonic-gate 		if (rvp->v_filocks != NULL || rvp->v_shrlocks != NULL) {
7777c478bd9Sstevel@tonic-gate 			vattr.va_mask = AT_MODE|AT_SIZE;
7787c478bd9Sstevel@tonic-gate 			if (error = VOP_GETATTR(vp, &vattr, 0, CRED())) {
7797c478bd9Sstevel@tonic-gate 				goto out;
7807c478bd9Sstevel@tonic-gate 			}
7817c478bd9Sstevel@tonic-gate 			if (MANDLOCK(vp, vattr.va_mode)) {
7827c478bd9Sstevel@tonic-gate 				error = EAGAIN;
7837c478bd9Sstevel@tonic-gate 				goto out;
7847c478bd9Sstevel@tonic-gate 			}
7857c478bd9Sstevel@tonic-gate 			/*
7867c478bd9Sstevel@tonic-gate 			 * File cannot be truncated if non-blocking mandatory
7877c478bd9Sstevel@tonic-gate 			 * locks are currently on the file.
7887c478bd9Sstevel@tonic-gate 			 */
7897c478bd9Sstevel@tonic-gate 			if ((vap->va_mask & AT_SIZE) && in_crit) {
7907c478bd9Sstevel@tonic-gate 				u_offset_t offset;
7917c478bd9Sstevel@tonic-gate 				ssize_t length;
7927c478bd9Sstevel@tonic-gate 
7937c478bd9Sstevel@tonic-gate 				offset = vap->va_size > vattr.va_size ?
7947c478bd9Sstevel@tonic-gate 						vattr.va_size : vap->va_size;
7957c478bd9Sstevel@tonic-gate 				length = vap->va_size > vattr.va_size ?
7967c478bd9Sstevel@tonic-gate 						vap->va_size - vattr.va_size :
7977c478bd9Sstevel@tonic-gate 						vattr.va_size - vap->va_size;
7987c478bd9Sstevel@tonic-gate 				if (nbl_conflict(vp, NBL_WRITE, offset,
7997c478bd9Sstevel@tonic-gate 						length, 0)) {
8007c478bd9Sstevel@tonic-gate 					error = EACCES;
8017c478bd9Sstevel@tonic-gate 					goto out;
8027c478bd9Sstevel@tonic-gate 				}
8037c478bd9Sstevel@tonic-gate 			}
8047c478bd9Sstevel@tonic-gate 		}
8057c478bd9Sstevel@tonic-gate 
8067c478bd9Sstevel@tonic-gate 		/*
8077c478bd9Sstevel@tonic-gate 		 * If the file is the root of a VFS, we've crossed a
8087c478bd9Sstevel@tonic-gate 		 * mount point and the "containing" directory that we
8097c478bd9Sstevel@tonic-gate 		 * acquired above (dvp) is irrelevant because it's in
8107c478bd9Sstevel@tonic-gate 		 * a different file system.  We apply VOP_CREATE to the
8117c478bd9Sstevel@tonic-gate 		 * target itself instead of to the containing directory
8127c478bd9Sstevel@tonic-gate 		 * and supply a null path name to indicate (conventionally)
8137c478bd9Sstevel@tonic-gate 		 * the node itself as the "component" of interest.
8147c478bd9Sstevel@tonic-gate 		 *
8157c478bd9Sstevel@tonic-gate 		 * The intercession of the file system is necessary to
8167c478bd9Sstevel@tonic-gate 		 * ensure that the appropriate permission checks are
8177c478bd9Sstevel@tonic-gate 		 * done.
8187c478bd9Sstevel@tonic-gate 		 */
8197c478bd9Sstevel@tonic-gate 		if (vp->v_flag & VROOT) {
8207c478bd9Sstevel@tonic-gate 			ASSERT(why != CRMKDIR);
8217c478bd9Sstevel@tonic-gate 			error =
8227c478bd9Sstevel@tonic-gate 			    VOP_CREATE(vp, "", vap, excl, mode, vpp, CRED(),
8237c478bd9Sstevel@tonic-gate 				    flag);
8247c478bd9Sstevel@tonic-gate 			/*
8257c478bd9Sstevel@tonic-gate 			 * If the create succeeded, it will have created
8267c478bd9Sstevel@tonic-gate 			 * a new reference to the vnode.  Give up the
8277c478bd9Sstevel@tonic-gate 			 * original reference.  The assertion should not
8287c478bd9Sstevel@tonic-gate 			 * get triggered because NBMAND locks only apply to
8297c478bd9Sstevel@tonic-gate 			 * VREG files.  And if in_crit is non-zero for some
8307c478bd9Sstevel@tonic-gate 			 * reason, detect that here, rather than when we
8317c478bd9Sstevel@tonic-gate 			 * deference a null vp.
8327c478bd9Sstevel@tonic-gate 			 */
8337c478bd9Sstevel@tonic-gate 			ASSERT(in_crit == 0);
8347c478bd9Sstevel@tonic-gate 			VN_RELE(vp);
8357c478bd9Sstevel@tonic-gate 			vp = NULL;
8367c478bd9Sstevel@tonic-gate 			goto out;
8377c478bd9Sstevel@tonic-gate 		}
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate 		/*
8407c478bd9Sstevel@tonic-gate 		 * Large File API - non-large open (FOFFMAX flag not set)
8417c478bd9Sstevel@tonic-gate 		 * of regular file fails if the file size exceeds MAXOFF32_T.
8427c478bd9Sstevel@tonic-gate 		 */
8437c478bd9Sstevel@tonic-gate 		if (why != CRMKDIR &&
8447c478bd9Sstevel@tonic-gate 		    !(flag & FOFFMAX) &&
8457c478bd9Sstevel@tonic-gate 		    (vp->v_type == VREG)) {
8467c478bd9Sstevel@tonic-gate 			vattr.va_mask = AT_SIZE;
8477c478bd9Sstevel@tonic-gate 			if ((error = VOP_GETATTR(vp, &vattr, 0, CRED()))) {
8487c478bd9Sstevel@tonic-gate 				goto out;
8497c478bd9Sstevel@tonic-gate 			}
8507c478bd9Sstevel@tonic-gate 			if ((vattr.va_size > (u_offset_t)MAXOFF32_T)) {
8517c478bd9Sstevel@tonic-gate 				error = EOVERFLOW;
8527c478bd9Sstevel@tonic-gate 				goto out;
8537c478bd9Sstevel@tonic-gate 			}
8547c478bd9Sstevel@tonic-gate 		}
8557c478bd9Sstevel@tonic-gate 	}
8567c478bd9Sstevel@tonic-gate 
8577c478bd9Sstevel@tonic-gate 	if (error == 0) {
8587c478bd9Sstevel@tonic-gate 		/*
8597c478bd9Sstevel@tonic-gate 		 * Call mkdir() if specified, otherwise create().
8607c478bd9Sstevel@tonic-gate 		 */
8617c478bd9Sstevel@tonic-gate 		int must_be_dir = pn_fixslash(&pn);	/* trailing '/'? */
8627c478bd9Sstevel@tonic-gate 
8637c478bd9Sstevel@tonic-gate 		if (why == CRMKDIR)
8647c478bd9Sstevel@tonic-gate 			error = VOP_MKDIR(dvp, pn.pn_path, vap, vpp, CRED());
8657c478bd9Sstevel@tonic-gate 		else if (!must_be_dir)
8667c478bd9Sstevel@tonic-gate 			error = VOP_CREATE(dvp, pn.pn_path, vap,
8677c478bd9Sstevel@tonic-gate 			    excl, mode, vpp, CRED(), flag);
8687c478bd9Sstevel@tonic-gate 		else
8697c478bd9Sstevel@tonic-gate 			error = ENOTDIR;
8707c478bd9Sstevel@tonic-gate 	}
8717c478bd9Sstevel@tonic-gate 
8727c478bd9Sstevel@tonic-gate out:
8737c478bd9Sstevel@tonic-gate 
8747c478bd9Sstevel@tonic-gate #ifdef C2_AUDIT
8757c478bd9Sstevel@tonic-gate 	if (audit_active)
8767c478bd9Sstevel@tonic-gate 		audit_vncreate_finish(*vpp, error);
8777c478bd9Sstevel@tonic-gate #endif  /* C2_AUDIT */
8787c478bd9Sstevel@tonic-gate 	if (in_crit) {
8797c478bd9Sstevel@tonic-gate 		nbl_end_crit(vp);
8807c478bd9Sstevel@tonic-gate 		in_crit = 0;
8817c478bd9Sstevel@tonic-gate 	}
8827c478bd9Sstevel@tonic-gate 	if (vp != NULL) {
8837c478bd9Sstevel@tonic-gate 		VN_RELE(vp);
8847c478bd9Sstevel@tonic-gate 		vp = NULL;
8857c478bd9Sstevel@tonic-gate 	}
8867c478bd9Sstevel@tonic-gate 	pn_free(&pn);
8877c478bd9Sstevel@tonic-gate 	VN_RELE(dvp);
8887c478bd9Sstevel@tonic-gate 	/*
8897c478bd9Sstevel@tonic-gate 	 * The following clause was added to handle a problem
8907c478bd9Sstevel@tonic-gate 	 * with NFS consistency.  It is possible that a lookup
8917c478bd9Sstevel@tonic-gate 	 * of the file to be created succeeded, but the file
8927c478bd9Sstevel@tonic-gate 	 * itself doesn't actually exist on the server.  This
8937c478bd9Sstevel@tonic-gate 	 * is chiefly due to the DNLC containing an entry for
8947c478bd9Sstevel@tonic-gate 	 * the file which has been removed on the server.  In
8957c478bd9Sstevel@tonic-gate 	 * this case, we just start over.  If there was some
8967c478bd9Sstevel@tonic-gate 	 * other cause for the ESTALE error, then the lookup
8977c478bd9Sstevel@tonic-gate 	 * of the file will fail and the error will be returned
8987c478bd9Sstevel@tonic-gate 	 * above instead of looping around from here.
8997c478bd9Sstevel@tonic-gate 	 */
9007c478bd9Sstevel@tonic-gate 	if (error == ESTALE)
9017c478bd9Sstevel@tonic-gate 		goto top;
9027c478bd9Sstevel@tonic-gate 	return (error);
9037c478bd9Sstevel@tonic-gate }
9047c478bd9Sstevel@tonic-gate 
9057c478bd9Sstevel@tonic-gate int
9067c478bd9Sstevel@tonic-gate vn_link(char *from, char *to, enum uio_seg seg)
9077c478bd9Sstevel@tonic-gate {
9087c478bd9Sstevel@tonic-gate 	struct vnode *fvp;		/* from vnode ptr */
9097c478bd9Sstevel@tonic-gate 	struct vnode *tdvp;		/* to directory vnode ptr */
9107c478bd9Sstevel@tonic-gate 	struct pathname pn;
9117c478bd9Sstevel@tonic-gate 	int error;
9127c478bd9Sstevel@tonic-gate 	struct vattr vattr;
9137c478bd9Sstevel@tonic-gate 	dev_t fsid;
9147c478bd9Sstevel@tonic-gate 
9157c478bd9Sstevel@tonic-gate top:
9167c478bd9Sstevel@tonic-gate 	fvp = tdvp = NULL;
9177c478bd9Sstevel@tonic-gate 	if (error = pn_get(to, seg, &pn))
9187c478bd9Sstevel@tonic-gate 		return (error);
9197c478bd9Sstevel@tonic-gate 	if (error = lookupname(from, seg, NO_FOLLOW, NULLVPP, &fvp))
9207c478bd9Sstevel@tonic-gate 		goto out;
9217c478bd9Sstevel@tonic-gate 	if (error = lookuppn(&pn, NULL, NO_FOLLOW, &tdvp, NULLVPP))
9227c478bd9Sstevel@tonic-gate 		goto out;
9237c478bd9Sstevel@tonic-gate 	/*
9247c478bd9Sstevel@tonic-gate 	 * Make sure both source vnode and target directory vnode are
9257c478bd9Sstevel@tonic-gate 	 * in the same vfs and that it is writeable.
9267c478bd9Sstevel@tonic-gate 	 */
9277c478bd9Sstevel@tonic-gate 	vattr.va_mask = AT_FSID;
9287c478bd9Sstevel@tonic-gate 	if (error = VOP_GETATTR(fvp, &vattr, 0, CRED()))
9297c478bd9Sstevel@tonic-gate 		goto out;
9307c478bd9Sstevel@tonic-gate 	fsid = vattr.va_fsid;
9317c478bd9Sstevel@tonic-gate 	vattr.va_mask = AT_FSID;
9327c478bd9Sstevel@tonic-gate 	if (error = VOP_GETATTR(tdvp, &vattr, 0, CRED()))
9337c478bd9Sstevel@tonic-gate 		goto out;
9347c478bd9Sstevel@tonic-gate 	if (fsid != vattr.va_fsid) {
9357c478bd9Sstevel@tonic-gate 		error = EXDEV;
9367c478bd9Sstevel@tonic-gate 		goto out;
9377c478bd9Sstevel@tonic-gate 	}
9387c478bd9Sstevel@tonic-gate 	if (tdvp->v_vfsp->vfs_flag & VFS_RDONLY) {
9397c478bd9Sstevel@tonic-gate 		error = EROFS;
9407c478bd9Sstevel@tonic-gate 		goto out;
9417c478bd9Sstevel@tonic-gate 	}
9427c478bd9Sstevel@tonic-gate 	/*
9437c478bd9Sstevel@tonic-gate 	 * Do the link.
9447c478bd9Sstevel@tonic-gate 	 */
9457c478bd9Sstevel@tonic-gate 	(void) pn_fixslash(&pn);
9467c478bd9Sstevel@tonic-gate 	error = VOP_LINK(tdvp, fvp, pn.pn_path, CRED());
9477c478bd9Sstevel@tonic-gate out:
9487c478bd9Sstevel@tonic-gate 	pn_free(&pn);
9497c478bd9Sstevel@tonic-gate 	if (fvp)
9507c478bd9Sstevel@tonic-gate 		VN_RELE(fvp);
9517c478bd9Sstevel@tonic-gate 	if (tdvp)
9527c478bd9Sstevel@tonic-gate 		VN_RELE(tdvp);
9537c478bd9Sstevel@tonic-gate 	if (error == ESTALE)
9547c478bd9Sstevel@tonic-gate 		goto top;
9557c478bd9Sstevel@tonic-gate 	return (error);
9567c478bd9Sstevel@tonic-gate }
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate int
9597c478bd9Sstevel@tonic-gate vn_rename(char *from, char *to, enum uio_seg seg)
9607c478bd9Sstevel@tonic-gate {
9617c478bd9Sstevel@tonic-gate 	return (vn_renameat(NULL, from, NULL, to, seg));
9627c478bd9Sstevel@tonic-gate }
9637c478bd9Sstevel@tonic-gate 
9647c478bd9Sstevel@tonic-gate int
9657c478bd9Sstevel@tonic-gate vn_renameat(vnode_t *fdvp, char *fname, vnode_t *tdvp,
9667c478bd9Sstevel@tonic-gate 		char *tname, enum uio_seg seg)
9677c478bd9Sstevel@tonic-gate {
9687c478bd9Sstevel@tonic-gate 	int error;
9697c478bd9Sstevel@tonic-gate 	struct vattr vattr;
9707c478bd9Sstevel@tonic-gate 	struct pathname fpn;		/* from pathname */
9717c478bd9Sstevel@tonic-gate 	struct pathname tpn;		/* to pathname */
9727c478bd9Sstevel@tonic-gate 	dev_t fsid;
9737c478bd9Sstevel@tonic-gate 	int in_crit = 0;
9747c478bd9Sstevel@tonic-gate 	vnode_t *fromvp, *fvp;
9757c478bd9Sstevel@tonic-gate 	vnode_t *tovp;
9767c478bd9Sstevel@tonic-gate 
9777c478bd9Sstevel@tonic-gate top:
9787c478bd9Sstevel@tonic-gate 	fvp = fromvp = tovp = NULL;
9797c478bd9Sstevel@tonic-gate 	/*
9807c478bd9Sstevel@tonic-gate 	 * Get to and from pathnames.
9817c478bd9Sstevel@tonic-gate 	 */
9827c478bd9Sstevel@tonic-gate 	if (error = pn_get(fname, seg, &fpn))
9837c478bd9Sstevel@tonic-gate 		return (error);
9847c478bd9Sstevel@tonic-gate 	if (error = pn_get(tname, seg, &tpn)) {
9857c478bd9Sstevel@tonic-gate 		pn_free(&fpn);
9867c478bd9Sstevel@tonic-gate 		return (error);
9877c478bd9Sstevel@tonic-gate 	}
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate 	/*
9907c478bd9Sstevel@tonic-gate 	 * First we need to resolve the correct directories
9917c478bd9Sstevel@tonic-gate 	 * The passed in directories may only be a starting point,
9927c478bd9Sstevel@tonic-gate 	 * but we need the real directories the file(s) live in.
9937c478bd9Sstevel@tonic-gate 	 * For example the fname may be something like usr/lib/sparc
9947c478bd9Sstevel@tonic-gate 	 * and we were passed in the / directory, but we need to
9957c478bd9Sstevel@tonic-gate 	 * use the lib directory for the rename.
9967c478bd9Sstevel@tonic-gate 	 */
9977c478bd9Sstevel@tonic-gate 
9987c478bd9Sstevel@tonic-gate #ifdef  C2_AUDIT
9997c478bd9Sstevel@tonic-gate 	if (audit_active)
10007c478bd9Sstevel@tonic-gate 		audit_setfsat_path(1);
10017c478bd9Sstevel@tonic-gate #endif /* C2_AUDIT */
10027c478bd9Sstevel@tonic-gate 	/*
10037c478bd9Sstevel@tonic-gate 	 * Lookup to and from directories.
10047c478bd9Sstevel@tonic-gate 	 */
10057c478bd9Sstevel@tonic-gate 	if (error = lookuppnat(&fpn, NULL, NO_FOLLOW, &fromvp, &fvp, fdvp)) {
10067c478bd9Sstevel@tonic-gate 		goto out;
10077c478bd9Sstevel@tonic-gate 	}
10087c478bd9Sstevel@tonic-gate 
10097c478bd9Sstevel@tonic-gate 	/*
10107c478bd9Sstevel@tonic-gate 	 * Make sure there is an entry.
10117c478bd9Sstevel@tonic-gate 	 */
10127c478bd9Sstevel@tonic-gate 	if (fvp == NULL) {
10137c478bd9Sstevel@tonic-gate 		error = ENOENT;
10147c478bd9Sstevel@tonic-gate 		goto out;
10157c478bd9Sstevel@tonic-gate 	}
10167c478bd9Sstevel@tonic-gate 
10177c478bd9Sstevel@tonic-gate #ifdef  C2_AUDIT
10187c478bd9Sstevel@tonic-gate 	if (audit_active)
10197c478bd9Sstevel@tonic-gate 		audit_setfsat_path(3);
10207c478bd9Sstevel@tonic-gate #endif /* C2_AUDIT */
10217c478bd9Sstevel@tonic-gate 	if (error = lookuppnat(&tpn, NULL, NO_FOLLOW, &tovp, NULLVPP, tdvp)) {
10227c478bd9Sstevel@tonic-gate 		goto out;
10237c478bd9Sstevel@tonic-gate 	}
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate 	/*
10267c478bd9Sstevel@tonic-gate 	 * Make sure both the from vnode directory and the to directory
10277c478bd9Sstevel@tonic-gate 	 * are in the same vfs and the to directory is writable.
10287c478bd9Sstevel@tonic-gate 	 * We check fsid's, not vfs pointers, so loopback fs works.
10297c478bd9Sstevel@tonic-gate 	 */
10307c478bd9Sstevel@tonic-gate 	if (fromvp != tovp) {
10317c478bd9Sstevel@tonic-gate 		vattr.va_mask = AT_FSID;
10327c478bd9Sstevel@tonic-gate 		if (error = VOP_GETATTR(fromvp, &vattr, 0, CRED()))
10337c478bd9Sstevel@tonic-gate 			goto out;
10347c478bd9Sstevel@tonic-gate 		fsid = vattr.va_fsid;
10357c478bd9Sstevel@tonic-gate 		vattr.va_mask = AT_FSID;
10367c478bd9Sstevel@tonic-gate 		if (error = VOP_GETATTR(tovp, &vattr, 0, CRED()))
10377c478bd9Sstevel@tonic-gate 			goto out;
10387c478bd9Sstevel@tonic-gate 		if (fsid != vattr.va_fsid) {
10397c478bd9Sstevel@tonic-gate 			error = EXDEV;
10407c478bd9Sstevel@tonic-gate 			goto out;
10417c478bd9Sstevel@tonic-gate 		}
10427c478bd9Sstevel@tonic-gate 	}
10437c478bd9Sstevel@tonic-gate 
10447c478bd9Sstevel@tonic-gate 	if (tovp->v_vfsp->vfs_flag & VFS_RDONLY) {
10457c478bd9Sstevel@tonic-gate 		error = EROFS;
10467c478bd9Sstevel@tonic-gate 		goto out;
10477c478bd9Sstevel@tonic-gate 	}
10487c478bd9Sstevel@tonic-gate 
10497c478bd9Sstevel@tonic-gate 	if (nbl_need_check(fvp)) {
10507c478bd9Sstevel@tonic-gate 		nbl_start_crit(fvp, RW_READER);
10517c478bd9Sstevel@tonic-gate 		in_crit = 1;
10527c478bd9Sstevel@tonic-gate 		if (nbl_conflict(fvp, NBL_RENAME, 0, 0, 0)) {
10537c478bd9Sstevel@tonic-gate 			error = EACCES;
10547c478bd9Sstevel@tonic-gate 			goto out;
10557c478bd9Sstevel@tonic-gate 		}
10567c478bd9Sstevel@tonic-gate 	}
10577c478bd9Sstevel@tonic-gate 
10587c478bd9Sstevel@tonic-gate 	/*
10597c478bd9Sstevel@tonic-gate 	 * Do the rename.
10607c478bd9Sstevel@tonic-gate 	 */
10617c478bd9Sstevel@tonic-gate 	(void) pn_fixslash(&tpn);
10627c478bd9Sstevel@tonic-gate 	error = VOP_RENAME(fromvp, fpn.pn_path, tovp, tpn.pn_path, CRED());
10637c478bd9Sstevel@tonic-gate 
10647c478bd9Sstevel@tonic-gate out:
10657c478bd9Sstevel@tonic-gate 	pn_free(&fpn);
10667c478bd9Sstevel@tonic-gate 	pn_free(&tpn);
10677c478bd9Sstevel@tonic-gate 	if (in_crit) {
10687c478bd9Sstevel@tonic-gate 		nbl_end_crit(fvp);
10697c478bd9Sstevel@tonic-gate 		in_crit = 0;
10707c478bd9Sstevel@tonic-gate 	}
10717c478bd9Sstevel@tonic-gate 	if (fromvp)
10727c478bd9Sstevel@tonic-gate 		VN_RELE(fromvp);
10737c478bd9Sstevel@tonic-gate 	if (tovp)
10747c478bd9Sstevel@tonic-gate 		VN_RELE(tovp);
10757c478bd9Sstevel@tonic-gate 	if (fvp)
10767c478bd9Sstevel@tonic-gate 		VN_RELE(fvp);
10777c478bd9Sstevel@tonic-gate 	if (error == ESTALE)
10787c478bd9Sstevel@tonic-gate 		goto top;
10797c478bd9Sstevel@tonic-gate 	return (error);
10807c478bd9Sstevel@tonic-gate }
10817c478bd9Sstevel@tonic-gate 
10827c478bd9Sstevel@tonic-gate /*
10837c478bd9Sstevel@tonic-gate  * Remove a file or directory.
10847c478bd9Sstevel@tonic-gate  */
10857c478bd9Sstevel@tonic-gate int
10867c478bd9Sstevel@tonic-gate vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag)
10877c478bd9Sstevel@tonic-gate {
10887c478bd9Sstevel@tonic-gate 	return (vn_removeat(NULL, fnamep, seg, dirflag));
10897c478bd9Sstevel@tonic-gate }
10907c478bd9Sstevel@tonic-gate 
10917c478bd9Sstevel@tonic-gate int
10927c478bd9Sstevel@tonic-gate vn_removeat(vnode_t *startvp, char *fnamep, enum uio_seg seg, enum rm dirflag)
10937c478bd9Sstevel@tonic-gate {
10947c478bd9Sstevel@tonic-gate 	struct vnode *vp;		/* entry vnode */
10957c478bd9Sstevel@tonic-gate 	struct vnode *dvp;		/* ptr to parent dir vnode */
10967c478bd9Sstevel@tonic-gate 	struct vnode *coveredvp;
10977c478bd9Sstevel@tonic-gate 	struct pathname pn;		/* name of entry */
10987c478bd9Sstevel@tonic-gate 	enum vtype vtype;
10997c478bd9Sstevel@tonic-gate 	int error;
11007c478bd9Sstevel@tonic-gate 	struct vfs *vfsp;
11017c478bd9Sstevel@tonic-gate 	struct vfs *dvfsp;	/* ptr to parent dir vfs */
11027c478bd9Sstevel@tonic-gate 	int in_crit = 0;
11037c478bd9Sstevel@tonic-gate 
11047c478bd9Sstevel@tonic-gate top:
11057c478bd9Sstevel@tonic-gate 	if (error = pn_get(fnamep, seg, &pn))
11067c478bd9Sstevel@tonic-gate 		return (error);
11077c478bd9Sstevel@tonic-gate 	dvp = vp = NULL;
11087c478bd9Sstevel@tonic-gate 	if (error = lookuppnat(&pn, NULL, NO_FOLLOW, &dvp, &vp, startvp)) {
11097c478bd9Sstevel@tonic-gate 		pn_free(&pn);
11107c478bd9Sstevel@tonic-gate 		if (error == ESTALE)
11117c478bd9Sstevel@tonic-gate 			goto top;
11127c478bd9Sstevel@tonic-gate 		return (error);
11137c478bd9Sstevel@tonic-gate 	}
11147c478bd9Sstevel@tonic-gate 
11157c478bd9Sstevel@tonic-gate 	/*
11167c478bd9Sstevel@tonic-gate 	 * Make sure there is an entry.
11177c478bd9Sstevel@tonic-gate 	 */
11187c478bd9Sstevel@tonic-gate 	if (vp == NULL) {
11197c478bd9Sstevel@tonic-gate 		error = ENOENT;
11207c478bd9Sstevel@tonic-gate 		goto out;
11217c478bd9Sstevel@tonic-gate 	}
11227c478bd9Sstevel@tonic-gate 
11237c478bd9Sstevel@tonic-gate 	vfsp = vp->v_vfsp;
11247c478bd9Sstevel@tonic-gate 	dvfsp = dvp->v_vfsp;
11257c478bd9Sstevel@tonic-gate 
11267c478bd9Sstevel@tonic-gate 	/*
11277c478bd9Sstevel@tonic-gate 	 * If the named file is the root of a mounted filesystem, fail,
11287c478bd9Sstevel@tonic-gate 	 * unless it's marked unlinkable.  In that case, unmount the
11297c478bd9Sstevel@tonic-gate 	 * filesystem and proceed to unlink the covered vnode.  (If the
11307c478bd9Sstevel@tonic-gate 	 * covered vnode is a directory, use rmdir instead of unlink,
11317c478bd9Sstevel@tonic-gate 	 * to avoid file system corruption.)
11327c478bd9Sstevel@tonic-gate 	 */
11337c478bd9Sstevel@tonic-gate 	if (vp->v_flag & VROOT) {
11347c478bd9Sstevel@tonic-gate 		if (vfsp->vfs_flag & VFS_UNLINKABLE) {
11357c478bd9Sstevel@tonic-gate 			if (dirflag == RMDIRECTORY) {
11367c478bd9Sstevel@tonic-gate 				/*
11377c478bd9Sstevel@tonic-gate 				 * User called rmdir(2) on a file that has
11387c478bd9Sstevel@tonic-gate 				 * been namefs mounted on top of.  Since
11397c478bd9Sstevel@tonic-gate 				 * namefs doesn't allow directories to
11407c478bd9Sstevel@tonic-gate 				 * be mounted on other files we know
11417c478bd9Sstevel@tonic-gate 				 * vp is not of type VDIR so fail to operation.
11427c478bd9Sstevel@tonic-gate 				 */
11437c478bd9Sstevel@tonic-gate 				error = ENOTDIR;
11447c478bd9Sstevel@tonic-gate 				goto out;
11457c478bd9Sstevel@tonic-gate 			}
11467c478bd9Sstevel@tonic-gate 			coveredvp = vfsp->vfs_vnodecovered;
11477c478bd9Sstevel@tonic-gate 			VN_HOLD(coveredvp);
11487c478bd9Sstevel@tonic-gate 			VN_RELE(vp);
11497c478bd9Sstevel@tonic-gate 			vp = NULL;
11507c478bd9Sstevel@tonic-gate 			if ((error = vn_vfswlock(coveredvp)) == 0)
11517c478bd9Sstevel@tonic-gate 				error = dounmount(vfsp, 0, CRED());
11527c478bd9Sstevel@tonic-gate 			/*
11537c478bd9Sstevel@tonic-gate 			 * Unmounted the namefs file system; now get
11547c478bd9Sstevel@tonic-gate 			 * the object it was mounted over.
11557c478bd9Sstevel@tonic-gate 			 */
11567c478bd9Sstevel@tonic-gate 			vp = coveredvp;
11577c478bd9Sstevel@tonic-gate 			/*
11587c478bd9Sstevel@tonic-gate 			 * If namefs was mounted over a directory, then
11597c478bd9Sstevel@tonic-gate 			 * we want to use rmdir() instead of unlink().
11607c478bd9Sstevel@tonic-gate 			 */
11617c478bd9Sstevel@tonic-gate 			if (vp->v_type == VDIR)
11627c478bd9Sstevel@tonic-gate 				dirflag = RMDIRECTORY;
11637c478bd9Sstevel@tonic-gate 		} else
11647c478bd9Sstevel@tonic-gate 			error = EBUSY;
11657c478bd9Sstevel@tonic-gate 
11667c478bd9Sstevel@tonic-gate 		if (error)
11677c478bd9Sstevel@tonic-gate 			goto out;
11687c478bd9Sstevel@tonic-gate 	}
11697c478bd9Sstevel@tonic-gate 
11707c478bd9Sstevel@tonic-gate 	/*
11717c478bd9Sstevel@tonic-gate 	 * Make sure filesystem is writeable.
11727c478bd9Sstevel@tonic-gate 	 * We check the parent directory's vfs in case this is an lofs vnode.
11737c478bd9Sstevel@tonic-gate 	 */
11747c478bd9Sstevel@tonic-gate 	if (dvfsp && dvfsp->vfs_flag & VFS_RDONLY) {
11757c478bd9Sstevel@tonic-gate 		error = EROFS;
11767c478bd9Sstevel@tonic-gate 		goto out;
11777c478bd9Sstevel@tonic-gate 	}
11787c478bd9Sstevel@tonic-gate 
11797c478bd9Sstevel@tonic-gate 	vtype = vp->v_type;
11807c478bd9Sstevel@tonic-gate 
11817c478bd9Sstevel@tonic-gate 	/*
11827c478bd9Sstevel@tonic-gate 	 * If there is the possibility of an nbmand share reservation, make
11837c478bd9Sstevel@tonic-gate 	 * sure it's okay to remove the file.  Keep a reference to the
11847c478bd9Sstevel@tonic-gate 	 * vnode, so that we can exit the nbl critical region after
11857c478bd9Sstevel@tonic-gate 	 * calling VOP_REMOVE.
11867c478bd9Sstevel@tonic-gate 	 * If there is no possibility of an nbmand share reservation,
11877c478bd9Sstevel@tonic-gate 	 * release the vnode reference now.  Filesystems like NFS may
11887c478bd9Sstevel@tonic-gate 	 * behave differently if there is an extra reference, so get rid of
11897c478bd9Sstevel@tonic-gate 	 * this one.  Fortunately, we can't have nbmand mounts on NFS
11907c478bd9Sstevel@tonic-gate 	 * filesystems.
11917c478bd9Sstevel@tonic-gate 	 */
11927c478bd9Sstevel@tonic-gate 	if (nbl_need_check(vp)) {
11937c478bd9Sstevel@tonic-gate 		nbl_start_crit(vp, RW_READER);
11947c478bd9Sstevel@tonic-gate 		in_crit = 1;
11957c478bd9Sstevel@tonic-gate 		if (nbl_conflict(vp, NBL_REMOVE, 0, 0, 0)) {
11967c478bd9Sstevel@tonic-gate 			error = EACCES;
11977c478bd9Sstevel@tonic-gate 			goto out;
11987c478bd9Sstevel@tonic-gate 		}
11997c478bd9Sstevel@tonic-gate 	} else {
12007c478bd9Sstevel@tonic-gate 		VN_RELE(vp);
12017c478bd9Sstevel@tonic-gate 		vp = NULL;
12027c478bd9Sstevel@tonic-gate 	}
12037c478bd9Sstevel@tonic-gate 
12047c478bd9Sstevel@tonic-gate 	if (dirflag == RMDIRECTORY) {
12057c478bd9Sstevel@tonic-gate 		/*
12067c478bd9Sstevel@tonic-gate 		 * Caller is using rmdir(2), which can only be applied to
12077c478bd9Sstevel@tonic-gate 		 * directories.
12087c478bd9Sstevel@tonic-gate 		 */
12097c478bd9Sstevel@tonic-gate 		if (vtype != VDIR) {
12107c478bd9Sstevel@tonic-gate 			error = ENOTDIR;
12117c478bd9Sstevel@tonic-gate 		} else {
12127c478bd9Sstevel@tonic-gate 			vnode_t *cwd;
12137c478bd9Sstevel@tonic-gate 			proc_t *pp = curproc;
12147c478bd9Sstevel@tonic-gate 
12157c478bd9Sstevel@tonic-gate 			mutex_enter(&pp->p_lock);
12167c478bd9Sstevel@tonic-gate 			cwd = PTOU(pp)->u_cdir;
12177c478bd9Sstevel@tonic-gate 			VN_HOLD(cwd);
12187c478bd9Sstevel@tonic-gate 			mutex_exit(&pp->p_lock);
12197c478bd9Sstevel@tonic-gate 			error = VOP_RMDIR(dvp, pn.pn_path, cwd, CRED());
12207c478bd9Sstevel@tonic-gate 			VN_RELE(cwd);
12217c478bd9Sstevel@tonic-gate 		}
12227c478bd9Sstevel@tonic-gate 	} else {
12237c478bd9Sstevel@tonic-gate 		/*
12247c478bd9Sstevel@tonic-gate 		 * Unlink(2) can be applied to anything.
12257c478bd9Sstevel@tonic-gate 		 */
12267c478bd9Sstevel@tonic-gate 		error = VOP_REMOVE(dvp, pn.pn_path, CRED());
12277c478bd9Sstevel@tonic-gate 	}
12287c478bd9Sstevel@tonic-gate 
12297c478bd9Sstevel@tonic-gate out:
12307c478bd9Sstevel@tonic-gate 	pn_free(&pn);
12317c478bd9Sstevel@tonic-gate 	if (in_crit) {
12327c478bd9Sstevel@tonic-gate 		nbl_end_crit(vp);
12337c478bd9Sstevel@tonic-gate 		in_crit = 0;
12347c478bd9Sstevel@tonic-gate 	}
12357c478bd9Sstevel@tonic-gate 	if (vp != NULL)
12367c478bd9Sstevel@tonic-gate 		VN_RELE(vp);
12377c478bd9Sstevel@tonic-gate 	if (dvp != NULL)
12387c478bd9Sstevel@tonic-gate 		VN_RELE(dvp);
12397c478bd9Sstevel@tonic-gate 	if (error == ESTALE)
12407c478bd9Sstevel@tonic-gate 		goto top;
12417c478bd9Sstevel@tonic-gate 	return (error);
12427c478bd9Sstevel@tonic-gate }
12437c478bd9Sstevel@tonic-gate 
12447c478bd9Sstevel@tonic-gate /*
12457c478bd9Sstevel@tonic-gate  * Utility function to compare equality of vnodes.
12467c478bd9Sstevel@tonic-gate  * Compare the underlying real vnodes, if there are underlying vnodes.
12477c478bd9Sstevel@tonic-gate  * This is a more thorough comparison than the VN_CMP() macro provides.
12487c478bd9Sstevel@tonic-gate  */
12497c478bd9Sstevel@tonic-gate int
12507c478bd9Sstevel@tonic-gate vn_compare(vnode_t *vp1, vnode_t *vp2)
12517c478bd9Sstevel@tonic-gate {
12527c478bd9Sstevel@tonic-gate 	vnode_t *realvp;
12537c478bd9Sstevel@tonic-gate 
12547c478bd9Sstevel@tonic-gate 	if (vp1 != NULL && VOP_REALVP(vp1, &realvp) == 0)
12557c478bd9Sstevel@tonic-gate 		vp1 = realvp;
12567c478bd9Sstevel@tonic-gate 	if (vp2 != NULL && VOP_REALVP(vp2, &realvp) == 0)
12577c478bd9Sstevel@tonic-gate 		vp2 = realvp;
12587c478bd9Sstevel@tonic-gate 	return (VN_CMP(vp1, vp2));
12597c478bd9Sstevel@tonic-gate }
12607c478bd9Sstevel@tonic-gate 
12617c478bd9Sstevel@tonic-gate /*
12627c478bd9Sstevel@tonic-gate  * The number of locks to hash into.  This value must be a power
12637c478bd9Sstevel@tonic-gate  * of 2 minus 1 and should probably also be prime.
12647c478bd9Sstevel@tonic-gate  */
12657c478bd9Sstevel@tonic-gate #define	NUM_BUCKETS	1023
12667c478bd9Sstevel@tonic-gate 
12677c478bd9Sstevel@tonic-gate struct  vn_vfslocks_bucket {
12687c478bd9Sstevel@tonic-gate 	kmutex_t vb_lock;
12697c478bd9Sstevel@tonic-gate 	vn_vfslocks_entry_t *vb_list;
12707c478bd9Sstevel@tonic-gate 	char pad[64 - sizeof (kmutex_t) - sizeof (void *)];
12717c478bd9Sstevel@tonic-gate };
12727c478bd9Sstevel@tonic-gate 
12737c478bd9Sstevel@tonic-gate /*
12747c478bd9Sstevel@tonic-gate  * Total number of buckets will be NUM_BUCKETS + 1 .
12757c478bd9Sstevel@tonic-gate  */
12767c478bd9Sstevel@tonic-gate 
12777c478bd9Sstevel@tonic-gate #pragma	align	64(vn_vfslocks_buckets)
12787c478bd9Sstevel@tonic-gate static	struct vn_vfslocks_bucket	vn_vfslocks_buckets[NUM_BUCKETS + 1];
12797c478bd9Sstevel@tonic-gate 
12807c478bd9Sstevel@tonic-gate #define	VN_VFSLOCKS_SHIFT	9
12817c478bd9Sstevel@tonic-gate 
12827c478bd9Sstevel@tonic-gate #define	VN_VFSLOCKS_HASH(vfsvpptr)	\
12837c478bd9Sstevel@tonic-gate 	((((intptr_t)(vfsvpptr)) >> VN_VFSLOCKS_SHIFT) & NUM_BUCKETS)
12847c478bd9Sstevel@tonic-gate 
12857c478bd9Sstevel@tonic-gate /*
12867c478bd9Sstevel@tonic-gate  * vn_vfslocks_getlock() uses an HASH scheme to generate
12877c478bd9Sstevel@tonic-gate  * rwstlock using vfs/vnode pointer passed to it.
12887c478bd9Sstevel@tonic-gate  *
12897c478bd9Sstevel@tonic-gate  * vn_vfslocks_rele() releases a reference in the
12907c478bd9Sstevel@tonic-gate  * HASH table which allows the entry allocated by
12917c478bd9Sstevel@tonic-gate  * vn_vfslocks_getlock() to be freed at a later
12927c478bd9Sstevel@tonic-gate  * stage when the refcount drops to zero.
12937c478bd9Sstevel@tonic-gate  */
12947c478bd9Sstevel@tonic-gate 
12957c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *
12967c478bd9Sstevel@tonic-gate vn_vfslocks_getlock(void *vfsvpptr)
12977c478bd9Sstevel@tonic-gate {
12987c478bd9Sstevel@tonic-gate 	struct vn_vfslocks_bucket *bp;
12997c478bd9Sstevel@tonic-gate 	vn_vfslocks_entry_t *vep;
13007c478bd9Sstevel@tonic-gate 	vn_vfslocks_entry_t *tvep;
13017c478bd9Sstevel@tonic-gate 
13027c478bd9Sstevel@tonic-gate 	ASSERT(vfsvpptr != NULL);
13037c478bd9Sstevel@tonic-gate 	bp = &vn_vfslocks_buckets[VN_VFSLOCKS_HASH(vfsvpptr)];
13047c478bd9Sstevel@tonic-gate 
13057c478bd9Sstevel@tonic-gate 	mutex_enter(&bp->vb_lock);
13067c478bd9Sstevel@tonic-gate 	for (vep = bp->vb_list; vep != NULL; vep = vep->ve_next) {
13077c478bd9Sstevel@tonic-gate 		if (vep->ve_vpvfs == vfsvpptr) {
13087c478bd9Sstevel@tonic-gate 			vep->ve_refcnt++;
13097c478bd9Sstevel@tonic-gate 			mutex_exit(&bp->vb_lock);
13107c478bd9Sstevel@tonic-gate 			return (vep);
13117c478bd9Sstevel@tonic-gate 		}
13127c478bd9Sstevel@tonic-gate 	}
13137c478bd9Sstevel@tonic-gate 	mutex_exit(&bp->vb_lock);
13147c478bd9Sstevel@tonic-gate 	vep = kmem_alloc(sizeof (*vep), KM_SLEEP);
13157c478bd9Sstevel@tonic-gate 	rwst_init(&vep->ve_lock, NULL, RW_DEFAULT, NULL);
13167c478bd9Sstevel@tonic-gate 	vep->ve_vpvfs = (char *)vfsvpptr;
13177c478bd9Sstevel@tonic-gate 	vep->ve_refcnt = 1;
13187c478bd9Sstevel@tonic-gate 	mutex_enter(&bp->vb_lock);
13197c478bd9Sstevel@tonic-gate 	for (tvep = bp->vb_list; tvep != NULL; tvep = tvep->ve_next) {
13207c478bd9Sstevel@tonic-gate 		if (tvep->ve_vpvfs == vfsvpptr) {
13217c478bd9Sstevel@tonic-gate 			tvep->ve_refcnt++;
13227c478bd9Sstevel@tonic-gate 			mutex_exit(&bp->vb_lock);
13237c478bd9Sstevel@tonic-gate 
13247c478bd9Sstevel@tonic-gate 			/*
13257c478bd9Sstevel@tonic-gate 			 * There is already an entry in the hash
13267c478bd9Sstevel@tonic-gate 			 * destroy what we just allocated.
13277c478bd9Sstevel@tonic-gate 			 */
13287c478bd9Sstevel@tonic-gate 			rwst_destroy(&vep->ve_lock);
13297c478bd9Sstevel@tonic-gate 			kmem_free(vep, sizeof (*vep));
13307c478bd9Sstevel@tonic-gate 			return (tvep);
13317c478bd9Sstevel@tonic-gate 		}
13327c478bd9Sstevel@tonic-gate 	}
13337c478bd9Sstevel@tonic-gate 	vep->ve_next = bp->vb_list;
13347c478bd9Sstevel@tonic-gate 	bp->vb_list = vep;
13357c478bd9Sstevel@tonic-gate 	mutex_exit(&bp->vb_lock);
13367c478bd9Sstevel@tonic-gate 	return (vep);
13377c478bd9Sstevel@tonic-gate }
13387c478bd9Sstevel@tonic-gate 
13397c478bd9Sstevel@tonic-gate void
13407c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vn_vfslocks_entry_t *vepent)
13417c478bd9Sstevel@tonic-gate {
13427c478bd9Sstevel@tonic-gate 	struct vn_vfslocks_bucket *bp;
13437c478bd9Sstevel@tonic-gate 	vn_vfslocks_entry_t *vep;
13447c478bd9Sstevel@tonic-gate 	vn_vfslocks_entry_t *pvep;
13457c478bd9Sstevel@tonic-gate 
13467c478bd9Sstevel@tonic-gate 	ASSERT(vepent != NULL);
13477c478bd9Sstevel@tonic-gate 	ASSERT(vepent->ve_vpvfs != NULL);
13487c478bd9Sstevel@tonic-gate 
13497c478bd9Sstevel@tonic-gate 	bp = &vn_vfslocks_buckets[VN_VFSLOCKS_HASH(vepent->ve_vpvfs)];
13507c478bd9Sstevel@tonic-gate 
13517c478bd9Sstevel@tonic-gate 	mutex_enter(&bp->vb_lock);
13527c478bd9Sstevel@tonic-gate 	vepent->ve_refcnt--;
13537c478bd9Sstevel@tonic-gate 
13547c478bd9Sstevel@tonic-gate 	if ((int32_t)vepent->ve_refcnt < 0)
13557c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "vn_vfslocks_rele: refcount negative");
13567c478bd9Sstevel@tonic-gate 
13577c478bd9Sstevel@tonic-gate 	if (vepent->ve_refcnt == 0) {
13587c478bd9Sstevel@tonic-gate 		for (vep = bp->vb_list; vep != NULL; vep = vep->ve_next) {
13597c478bd9Sstevel@tonic-gate 			if (vep->ve_vpvfs == vepent->ve_vpvfs) {
13607c478bd9Sstevel@tonic-gate 				if (bp->vb_list == vep)
13617c478bd9Sstevel@tonic-gate 					bp->vb_list = vep->ve_next;
13627c478bd9Sstevel@tonic-gate 				else {
13637c478bd9Sstevel@tonic-gate 					/* LINTED */
13647c478bd9Sstevel@tonic-gate 					pvep->ve_next = vep->ve_next;
13657c478bd9Sstevel@tonic-gate 				}
13667c478bd9Sstevel@tonic-gate 				mutex_exit(&bp->vb_lock);
13677c478bd9Sstevel@tonic-gate 				rwst_destroy(&vep->ve_lock);
13687c478bd9Sstevel@tonic-gate 				kmem_free(vep, sizeof (*vep));
13697c478bd9Sstevel@tonic-gate 				return;
13707c478bd9Sstevel@tonic-gate 			}
13717c478bd9Sstevel@tonic-gate 			pvep = vep;
13727c478bd9Sstevel@tonic-gate 		}
13737c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "vn_vfslocks_rele: vp/vfs not found");
13747c478bd9Sstevel@tonic-gate 	}
13757c478bd9Sstevel@tonic-gate 	mutex_exit(&bp->vb_lock);
13767c478bd9Sstevel@tonic-gate }
13777c478bd9Sstevel@tonic-gate 
13787c478bd9Sstevel@tonic-gate /*
13797c478bd9Sstevel@tonic-gate  * vn_vfswlock_wait is used to implement a lock which is logically a writers
13807c478bd9Sstevel@tonic-gate  * lock protecting the v_vfsmountedhere field.
13817c478bd9Sstevel@tonic-gate  * vn_vfswlock_wait has been modified to be similar to vn_vfswlock,
13827c478bd9Sstevel@tonic-gate  * except that it blocks to acquire the lock VVFSLOCK.
13837c478bd9Sstevel@tonic-gate  *
13847c478bd9Sstevel@tonic-gate  * traverse() and routines re-implementing part of traverse (e.g. autofs)
13857c478bd9Sstevel@tonic-gate  * need to hold this lock. mount(), vn_rename(), vn_remove() and so on
13867c478bd9Sstevel@tonic-gate  * need the non-blocking version of the writers lock i.e. vn_vfswlock
13877c478bd9Sstevel@tonic-gate  */
13887c478bd9Sstevel@tonic-gate int
13897c478bd9Sstevel@tonic-gate vn_vfswlock_wait(vnode_t *vp)
13907c478bd9Sstevel@tonic-gate {
13917c478bd9Sstevel@tonic-gate 	int retval;
13927c478bd9Sstevel@tonic-gate 	vn_vfslocks_entry_t *vpvfsentry;
13937c478bd9Sstevel@tonic-gate 	ASSERT(vp != NULL);
13947c478bd9Sstevel@tonic-gate 
13957c478bd9Sstevel@tonic-gate 	vpvfsentry = vn_vfslocks_getlock(vp);
13967c478bd9Sstevel@tonic-gate 	retval = rwst_enter_sig(&vpvfsentry->ve_lock, RW_WRITER);
13977c478bd9Sstevel@tonic-gate 
13987c478bd9Sstevel@tonic-gate 	if (retval == EINTR) {
13997c478bd9Sstevel@tonic-gate 		vn_vfslocks_rele(vpvfsentry);
14007c478bd9Sstevel@tonic-gate 		return (EINTR);
14017c478bd9Sstevel@tonic-gate 	}
14027c478bd9Sstevel@tonic-gate 	return (retval);
14037c478bd9Sstevel@tonic-gate }
14047c478bd9Sstevel@tonic-gate 
14057c478bd9Sstevel@tonic-gate int
14067c478bd9Sstevel@tonic-gate vn_vfsrlock_wait(vnode_t *vp)
14077c478bd9Sstevel@tonic-gate {
14087c478bd9Sstevel@tonic-gate 	int retval;
14097c478bd9Sstevel@tonic-gate 	vn_vfslocks_entry_t *vpvfsentry;
14107c478bd9Sstevel@tonic-gate 	ASSERT(vp != NULL);
14117c478bd9Sstevel@tonic-gate 
14127c478bd9Sstevel@tonic-gate 	vpvfsentry = vn_vfslocks_getlock(vp);
14137c478bd9Sstevel@tonic-gate 	retval = rwst_enter_sig(&vpvfsentry->ve_lock, RW_READER);
14147c478bd9Sstevel@tonic-gate 
14157c478bd9Sstevel@tonic-gate 	if (retval == EINTR) {
14167c478bd9Sstevel@tonic-gate 		vn_vfslocks_rele(vpvfsentry);
14177c478bd9Sstevel@tonic-gate 		return (EINTR);
14187c478bd9Sstevel@tonic-gate 	}
14197c478bd9Sstevel@tonic-gate 
14207c478bd9Sstevel@tonic-gate 	return (retval);
14217c478bd9Sstevel@tonic-gate }
14227c478bd9Sstevel@tonic-gate 
14237c478bd9Sstevel@tonic-gate 
14247c478bd9Sstevel@tonic-gate /*
14257c478bd9Sstevel@tonic-gate  * vn_vfswlock is used to implement a lock which is logically a writers lock
14267c478bd9Sstevel@tonic-gate  * protecting the v_vfsmountedhere field.
14277c478bd9Sstevel@tonic-gate  */
14287c478bd9Sstevel@tonic-gate int
14297c478bd9Sstevel@tonic-gate vn_vfswlock(vnode_t *vp)
14307c478bd9Sstevel@tonic-gate {
14317c478bd9Sstevel@tonic-gate 	vn_vfslocks_entry_t *vpvfsentry;
14327c478bd9Sstevel@tonic-gate 
14337c478bd9Sstevel@tonic-gate 	/*
14347c478bd9Sstevel@tonic-gate 	 * If vp is NULL then somebody is trying to lock the covered vnode
14357c478bd9Sstevel@tonic-gate 	 * of /.  (vfs_vnodecovered is NULL for /).  This situation will
14367c478bd9Sstevel@tonic-gate 	 * only happen when unmounting /.  Since that operation will fail
14377c478bd9Sstevel@tonic-gate 	 * anyway, return EBUSY here instead of in VFS_UNMOUNT.
14387c478bd9Sstevel@tonic-gate 	 */
14397c478bd9Sstevel@tonic-gate 	if (vp == NULL)
14407c478bd9Sstevel@tonic-gate 		return (EBUSY);
14417c478bd9Sstevel@tonic-gate 
14427c478bd9Sstevel@tonic-gate 	vpvfsentry = vn_vfslocks_getlock(vp);
14437c478bd9Sstevel@tonic-gate 
14447c478bd9Sstevel@tonic-gate 	if (rwst_tryenter(&vpvfsentry->ve_lock, RW_WRITER))
14457c478bd9Sstevel@tonic-gate 		return (0);
14467c478bd9Sstevel@tonic-gate 
14477c478bd9Sstevel@tonic-gate 	vn_vfslocks_rele(vpvfsentry);
14487c478bd9Sstevel@tonic-gate 	return (EBUSY);
14497c478bd9Sstevel@tonic-gate }
14507c478bd9Sstevel@tonic-gate 
14517c478bd9Sstevel@tonic-gate int
14527c478bd9Sstevel@tonic-gate vn_vfsrlock(vnode_t *vp)
14537c478bd9Sstevel@tonic-gate {
14547c478bd9Sstevel@tonic-gate 	vn_vfslocks_entry_t *vpvfsentry;
14557c478bd9Sstevel@tonic-gate 
14567c478bd9Sstevel@tonic-gate 	/*
14577c478bd9Sstevel@tonic-gate 	 * If vp is NULL then somebody is trying to lock the covered vnode
14587c478bd9Sstevel@tonic-gate 	 * of /.  (vfs_vnodecovered is NULL for /).  This situation will
14597c478bd9Sstevel@tonic-gate 	 * only happen when unmounting /.  Since that operation will fail
14607c478bd9Sstevel@tonic-gate 	 * anyway, return EBUSY here instead of in VFS_UNMOUNT.
14617c478bd9Sstevel@tonic-gate 	 */
14627c478bd9Sstevel@tonic-gate 	if (vp == NULL)
14637c478bd9Sstevel@tonic-gate 		return (EBUSY);
14647c478bd9Sstevel@tonic-gate 
14657c478bd9Sstevel@tonic-gate 	vpvfsentry = vn_vfslocks_getlock(vp);
14667c478bd9Sstevel@tonic-gate 
14677c478bd9Sstevel@tonic-gate 	if (rwst_tryenter(&vpvfsentry->ve_lock, RW_READER))
14687c478bd9Sstevel@tonic-gate 		return (0);
14697c478bd9Sstevel@tonic-gate 
14707c478bd9Sstevel@tonic-gate 	vn_vfslocks_rele(vpvfsentry);
14717c478bd9Sstevel@tonic-gate 	return (EBUSY);
14727c478bd9Sstevel@tonic-gate }
14737c478bd9Sstevel@tonic-gate 
14747c478bd9Sstevel@tonic-gate 
14757c478bd9Sstevel@tonic-gate /*
14767c478bd9Sstevel@tonic-gate  * For compatibility with old (deprecated) interface, continue
14777c478bd9Sstevel@tonic-gate  * to support vanilla mutex.
14787c478bd9Sstevel@tonic-gate  */
14797c478bd9Sstevel@tonic-gate int
14807c478bd9Sstevel@tonic-gate vn_vfslock(vnode_t *vp)
14817c478bd9Sstevel@tonic-gate {
14827c478bd9Sstevel@tonic-gate 	return (vn_vfswlock(vp));
14837c478bd9Sstevel@tonic-gate }
14847c478bd9Sstevel@tonic-gate 
14857c478bd9Sstevel@tonic-gate void
14867c478bd9Sstevel@tonic-gate vn_vfsunlock(vnode_t *vp)
14877c478bd9Sstevel@tonic-gate {
14887c478bd9Sstevel@tonic-gate 	vn_vfslocks_entry_t *vpvfsentry;
14897c478bd9Sstevel@tonic-gate 
14907c478bd9Sstevel@tonic-gate 	/*
14917c478bd9Sstevel@tonic-gate 	 * ve_refcnt needs to be decremented twice.
14927c478bd9Sstevel@tonic-gate 	 * 1. To release refernce after a call to vn_vfslocks_getlock()
14937c478bd9Sstevel@tonic-gate 	 * 2. To release the reference from the locking routines like
14947c478bd9Sstevel@tonic-gate 	 *    vn_vfsrlock/vn_vfswlock etc,.
14957c478bd9Sstevel@tonic-gate 	 */
14967c478bd9Sstevel@tonic-gate 	vpvfsentry = vn_vfslocks_getlock(vp);
14977c478bd9Sstevel@tonic-gate 	vn_vfslocks_rele(vpvfsentry);
14987c478bd9Sstevel@tonic-gate 
14997c478bd9Sstevel@tonic-gate 	rwst_exit(&vpvfsentry->ve_lock);
15007c478bd9Sstevel@tonic-gate 	vn_vfslocks_rele(vpvfsentry);
15017c478bd9Sstevel@tonic-gate }
15027c478bd9Sstevel@tonic-gate 
15037c478bd9Sstevel@tonic-gate int
15047c478bd9Sstevel@tonic-gate vn_vfswlock_held(vnode_t *vp)
15057c478bd9Sstevel@tonic-gate {
15067c478bd9Sstevel@tonic-gate 	int held;
15077c478bd9Sstevel@tonic-gate 	vn_vfslocks_entry_t *vpvfsentry;
15087c478bd9Sstevel@tonic-gate 
15097c478bd9Sstevel@tonic-gate 	ASSERT(vp != NULL);
15107c478bd9Sstevel@tonic-gate 
15117c478bd9Sstevel@tonic-gate 	vpvfsentry = vn_vfslocks_getlock(vp);
15127c478bd9Sstevel@tonic-gate 	held = rwst_lock_held(&vpvfsentry->ve_lock, RW_WRITER);
15137c478bd9Sstevel@tonic-gate 
15147c478bd9Sstevel@tonic-gate 	vn_vfslocks_rele(vpvfsentry);
15157c478bd9Sstevel@tonic-gate 	return (held);
15167c478bd9Sstevel@tonic-gate }
15177c478bd9Sstevel@tonic-gate 
15187c478bd9Sstevel@tonic-gate 
15197c478bd9Sstevel@tonic-gate int
15207c478bd9Sstevel@tonic-gate vn_make_ops(
15217c478bd9Sstevel@tonic-gate 	const char *name,			/* Name of file system */
15227c478bd9Sstevel@tonic-gate 	const fs_operation_def_t *templ,	/* Operation specification */
15237c478bd9Sstevel@tonic-gate 	vnodeops_t **actual)			/* Return the vnodeops */
15247c478bd9Sstevel@tonic-gate {
15257c478bd9Sstevel@tonic-gate 	int unused_ops;
15267c478bd9Sstevel@tonic-gate 	int error;
15277c478bd9Sstevel@tonic-gate 
15287c478bd9Sstevel@tonic-gate 	*actual = (vnodeops_t *)kmem_alloc(sizeof (vnodeops_t), KM_SLEEP);
15297c478bd9Sstevel@tonic-gate 
15307c478bd9Sstevel@tonic-gate 	(*actual)->vnop_name = name;
15317c478bd9Sstevel@tonic-gate 
15327c478bd9Sstevel@tonic-gate 	error = fs_build_vector(*actual, &unused_ops, vn_ops_table, templ);
15337c478bd9Sstevel@tonic-gate 	if (error) {
15347c478bd9Sstevel@tonic-gate 		kmem_free(*actual, sizeof (vnodeops_t));
15357c478bd9Sstevel@tonic-gate 	}
15367c478bd9Sstevel@tonic-gate 
15377c478bd9Sstevel@tonic-gate #if DEBUG
15387c478bd9Sstevel@tonic-gate 	if (unused_ops != 0)
15397c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "vn_make_ops: %s: %d operations supplied "
15407c478bd9Sstevel@tonic-gate 		    "but not used", name, unused_ops);
15417c478bd9Sstevel@tonic-gate #endif
15427c478bd9Sstevel@tonic-gate 
15437c478bd9Sstevel@tonic-gate 	return (error);
15447c478bd9Sstevel@tonic-gate }
15457c478bd9Sstevel@tonic-gate 
15467c478bd9Sstevel@tonic-gate /*
15477c478bd9Sstevel@tonic-gate  * Free the vnodeops created as a result of vn_make_ops()
15487c478bd9Sstevel@tonic-gate  */
15497c478bd9Sstevel@tonic-gate void
15507c478bd9Sstevel@tonic-gate vn_freevnodeops(vnodeops_t *vnops)
15517c478bd9Sstevel@tonic-gate {
15527c478bd9Sstevel@tonic-gate 	kmem_free(vnops, sizeof (vnodeops_t));
15537c478bd9Sstevel@tonic-gate }
15547c478bd9Sstevel@tonic-gate 
15557c478bd9Sstevel@tonic-gate /*
15567c478bd9Sstevel@tonic-gate  * Vnode cache.
15577c478bd9Sstevel@tonic-gate  */
15587c478bd9Sstevel@tonic-gate 
15597c478bd9Sstevel@tonic-gate /* ARGSUSED */
15607c478bd9Sstevel@tonic-gate static int
15617c478bd9Sstevel@tonic-gate vn_cache_constructor(void *buf, void *cdrarg, int kmflags)
15627c478bd9Sstevel@tonic-gate {
15637c478bd9Sstevel@tonic-gate 	struct vnode *vp;
15647c478bd9Sstevel@tonic-gate 
15657c478bd9Sstevel@tonic-gate 	vp = buf;
15667c478bd9Sstevel@tonic-gate 
15677c478bd9Sstevel@tonic-gate 	mutex_init(&vp->v_lock, NULL, MUTEX_DEFAULT, NULL);
15687c478bd9Sstevel@tonic-gate 	cv_init(&vp->v_cv, NULL, CV_DEFAULT, NULL);
15697c478bd9Sstevel@tonic-gate 	rw_init(&vp->v_nbllock, NULL, RW_DEFAULT, NULL);
15707c478bd9Sstevel@tonic-gate 	rw_init(&vp->v_mslock, NULL, RW_DEFAULT, NULL);
15717c478bd9Sstevel@tonic-gate 
15727c478bd9Sstevel@tonic-gate 	vp->v_femhead = NULL;	/* Must be done before vn_reinit() */
15737c478bd9Sstevel@tonic-gate 	vp->v_path = NULL;
15747c478bd9Sstevel@tonic-gate 	vp->v_mpssdata = NULL;
15757c478bd9Sstevel@tonic-gate 
15767c478bd9Sstevel@tonic-gate 	return (0);
15777c478bd9Sstevel@tonic-gate }
15787c478bd9Sstevel@tonic-gate 
15797c478bd9Sstevel@tonic-gate /* ARGSUSED */
15807c478bd9Sstevel@tonic-gate static void
15817c478bd9Sstevel@tonic-gate vn_cache_destructor(void *buf, void *cdrarg)
15827c478bd9Sstevel@tonic-gate {
15837c478bd9Sstevel@tonic-gate 	struct vnode *vp;
15847c478bd9Sstevel@tonic-gate 
15857c478bd9Sstevel@tonic-gate 	vp = buf;
15867c478bd9Sstevel@tonic-gate 
15877c478bd9Sstevel@tonic-gate 	rw_destroy(&vp->v_mslock);
15887c478bd9Sstevel@tonic-gate 	rw_destroy(&vp->v_nbllock);
15897c478bd9Sstevel@tonic-gate 	cv_destroy(&vp->v_cv);
15907c478bd9Sstevel@tonic-gate 	mutex_destroy(&vp->v_lock);
15917c478bd9Sstevel@tonic-gate }
15927c478bd9Sstevel@tonic-gate 
15937c478bd9Sstevel@tonic-gate void
15947c478bd9Sstevel@tonic-gate vn_create_cache(void)
15957c478bd9Sstevel@tonic-gate {
15967c478bd9Sstevel@tonic-gate 	vn_cache = kmem_cache_create("vn_cache", sizeof (struct vnode), 64,
15977c478bd9Sstevel@tonic-gate 	    vn_cache_constructor, vn_cache_destructor, NULL, NULL,
15987c478bd9Sstevel@tonic-gate 	    NULL, 0);
15997c478bd9Sstevel@tonic-gate }
16007c478bd9Sstevel@tonic-gate 
16017c478bd9Sstevel@tonic-gate void
16027c478bd9Sstevel@tonic-gate vn_destroy_cache(void)
16037c478bd9Sstevel@tonic-gate {
16047c478bd9Sstevel@tonic-gate 	kmem_cache_destroy(vn_cache);
16057c478bd9Sstevel@tonic-gate }
16067c478bd9Sstevel@tonic-gate 
16077c478bd9Sstevel@tonic-gate /*
16087c478bd9Sstevel@tonic-gate  * Used by file systems when fs-specific nodes (e.g., ufs inodes) are
16097c478bd9Sstevel@tonic-gate  * cached by the file system and vnodes remain associated.
16107c478bd9Sstevel@tonic-gate  */
16117c478bd9Sstevel@tonic-gate void
16127c478bd9Sstevel@tonic-gate vn_recycle(vnode_t *vp)
16137c478bd9Sstevel@tonic-gate {
16147c478bd9Sstevel@tonic-gate 	ASSERT(vp->v_pages == NULL);
16157c478bd9Sstevel@tonic-gate 
16167c478bd9Sstevel@tonic-gate 	/*
16177c478bd9Sstevel@tonic-gate 	 * XXX - This really belongs in vn_reinit(), but we have some issues
16187c478bd9Sstevel@tonic-gate 	 * with the counts.  Best to have it here for clean initialization.
16197c478bd9Sstevel@tonic-gate 	 */
16207c478bd9Sstevel@tonic-gate 	vp->v_rdcnt = 0;
16217c478bd9Sstevel@tonic-gate 	vp->v_wrcnt = 0;
16227c478bd9Sstevel@tonic-gate 	vp->v_mmap_read = 0;
16237c478bd9Sstevel@tonic-gate 	vp->v_mmap_write = 0;
16247c478bd9Sstevel@tonic-gate 
16257c478bd9Sstevel@tonic-gate 	/*
16267c478bd9Sstevel@tonic-gate 	 * If FEM was in use, make sure everything gets cleaned up
16277c478bd9Sstevel@tonic-gate 	 * NOTE: vp->v_femhead is initialized to NULL in the vnode
16287c478bd9Sstevel@tonic-gate 	 * constructor.
16297c478bd9Sstevel@tonic-gate 	 */
16307c478bd9Sstevel@tonic-gate 	if (vp->v_femhead) {
16317c478bd9Sstevel@tonic-gate 		/* XXX - There should be a free_femhead() that does all this */
16327c478bd9Sstevel@tonic-gate 		ASSERT(vp->v_femhead->femh_list == NULL);
16337c478bd9Sstevel@tonic-gate 		mutex_destroy(&vp->v_femhead->femh_lock);
16347c478bd9Sstevel@tonic-gate 		kmem_free(vp->v_femhead, sizeof (*(vp->v_femhead)));
16357c478bd9Sstevel@tonic-gate 		vp->v_femhead = NULL;
16367c478bd9Sstevel@tonic-gate 	}
16377c478bd9Sstevel@tonic-gate 	if (vp->v_path) {
16387c478bd9Sstevel@tonic-gate 		kmem_free(vp->v_path, strlen(vp->v_path) + 1);
16397c478bd9Sstevel@tonic-gate 		vp->v_path = NULL;
16407c478bd9Sstevel@tonic-gate 	}
16417c478bd9Sstevel@tonic-gate 	vp->v_mpssdata = NULL;
16427c478bd9Sstevel@tonic-gate }
16437c478bd9Sstevel@tonic-gate 
16447c478bd9Sstevel@tonic-gate /*
16457c478bd9Sstevel@tonic-gate  * Used to reset the vnode fields including those that are directly accessible
16467c478bd9Sstevel@tonic-gate  * as well as those which require an accessor function.
16477c478bd9Sstevel@tonic-gate  *
16487c478bd9Sstevel@tonic-gate  * Does not initialize:
16497c478bd9Sstevel@tonic-gate  *	synchronization objects: v_lock, v_nbllock, v_cv
16507c478bd9Sstevel@tonic-gate  *	v_data (since FS-nodes and vnodes point to each other and should
16517c478bd9Sstevel@tonic-gate  *		be updated simultaneously)
16527c478bd9Sstevel@tonic-gate  *	v_op (in case someone needs to make a VOP call on this object)
16537c478bd9Sstevel@tonic-gate  */
16547c478bd9Sstevel@tonic-gate void
16557c478bd9Sstevel@tonic-gate vn_reinit(vnode_t *vp)
16567c478bd9Sstevel@tonic-gate {
16577c478bd9Sstevel@tonic-gate 	vp->v_count = 1;
16587c478bd9Sstevel@tonic-gate 	vp->v_vfsp = NULL;
16597c478bd9Sstevel@tonic-gate 	vp->v_stream = NULL;
16607c478bd9Sstevel@tonic-gate 	vp->v_vfsmountedhere = NULL;
16617c478bd9Sstevel@tonic-gate 	vp->v_flag = 0;
16627c478bd9Sstevel@tonic-gate 	vp->v_type = VNON;
16637c478bd9Sstevel@tonic-gate 	vp->v_rdev = NODEV;
16647c478bd9Sstevel@tonic-gate 
16657c478bd9Sstevel@tonic-gate 	vp->v_filocks = NULL;
16667c478bd9Sstevel@tonic-gate 	vp->v_shrlocks = NULL;
16677c478bd9Sstevel@tonic-gate 	vp->v_pages = NULL;
16687c478bd9Sstevel@tonic-gate 	vp->v_npages = 0;
16697c478bd9Sstevel@tonic-gate 	vp->v_msnpages = 0;
16707c478bd9Sstevel@tonic-gate 	vp->v_scanfront = NULL;
16717c478bd9Sstevel@tonic-gate 	vp->v_scanback = NULL;
16727c478bd9Sstevel@tonic-gate 
16737c478bd9Sstevel@tonic-gate 	vp->v_locality = NULL;
16747c478bd9Sstevel@tonic-gate 	vp->v_scantime = 0;
16757c478bd9Sstevel@tonic-gate 	vp->v_mset = 0;
16767c478bd9Sstevel@tonic-gate 	vp->v_msflags = 0;
16777c478bd9Sstevel@tonic-gate 	vp->v_msnext = NULL;
16787c478bd9Sstevel@tonic-gate 	vp->v_msprev = NULL;
16797c478bd9Sstevel@tonic-gate 
16807c478bd9Sstevel@tonic-gate 	/* Handles v_femhead, v_path, and the r/w/map counts */
16817c478bd9Sstevel@tonic-gate 	vn_recycle(vp);
16827c478bd9Sstevel@tonic-gate }
16837c478bd9Sstevel@tonic-gate 
16847c478bd9Sstevel@tonic-gate vnode_t *
16857c478bd9Sstevel@tonic-gate vn_alloc(int kmflag)
16867c478bd9Sstevel@tonic-gate {
16877c478bd9Sstevel@tonic-gate 	vnode_t *vp;
16887c478bd9Sstevel@tonic-gate 
16897c478bd9Sstevel@tonic-gate 	vp = kmem_cache_alloc(vn_cache, kmflag);
16907c478bd9Sstevel@tonic-gate 
16917c478bd9Sstevel@tonic-gate 	if (vp != NULL) {
16927c478bd9Sstevel@tonic-gate 		vp->v_femhead = NULL;	/* Must be done before vn_reinit() */
16937c478bd9Sstevel@tonic-gate 		vn_reinit(vp);
16947c478bd9Sstevel@tonic-gate 	}
16957c478bd9Sstevel@tonic-gate 
16967c478bd9Sstevel@tonic-gate 	return (vp);
16977c478bd9Sstevel@tonic-gate }
16987c478bd9Sstevel@tonic-gate 
16997c478bd9Sstevel@tonic-gate void
17007c478bd9Sstevel@tonic-gate vn_free(vnode_t *vp)
17017c478bd9Sstevel@tonic-gate {
17027c478bd9Sstevel@tonic-gate 	/*
17037c478bd9Sstevel@tonic-gate 	 * Some file systems call vn_free() with v_count of zero,
17047c478bd9Sstevel@tonic-gate 	 * some with v_count of 1.  In any case, the value should
17057c478bd9Sstevel@tonic-gate 	 * never be anything else.
17067c478bd9Sstevel@tonic-gate 	 */
17077c478bd9Sstevel@tonic-gate 	ASSERT((vp->v_count == 0) || (vp->v_count == 1));
17087c478bd9Sstevel@tonic-gate 	if (vp->v_path != NULL) {
17097c478bd9Sstevel@tonic-gate 		kmem_free(vp->v_path, strlen(vp->v_path) + 1);
17107c478bd9Sstevel@tonic-gate 		vp->v_path = NULL;
17117c478bd9Sstevel@tonic-gate 	}
17127c478bd9Sstevel@tonic-gate 
17137c478bd9Sstevel@tonic-gate 	/* If FEM was in use, make sure everything gets cleaned up */
17147c478bd9Sstevel@tonic-gate 	if (vp->v_femhead) {
17157c478bd9Sstevel@tonic-gate 		/* XXX - There should be a free_femhead() that does all this */
17167c478bd9Sstevel@tonic-gate 		ASSERT(vp->v_femhead->femh_list == NULL);
17177c478bd9Sstevel@tonic-gate 		mutex_destroy(&vp->v_femhead->femh_lock);
17187c478bd9Sstevel@tonic-gate 		kmem_free(vp->v_femhead, sizeof (*(vp->v_femhead)));
17197c478bd9Sstevel@tonic-gate 		vp->v_femhead = NULL;
17207c478bd9Sstevel@tonic-gate 	}
17217c478bd9Sstevel@tonic-gate 	vp->v_mpssdata = NULL;
17227c478bd9Sstevel@tonic-gate 	kmem_cache_free(vn_cache, vp);
17237c478bd9Sstevel@tonic-gate }
17247c478bd9Sstevel@tonic-gate 
17257c478bd9Sstevel@tonic-gate /*
17267c478bd9Sstevel@tonic-gate  * vnode status changes, should define better states than 1, 0.
17277c478bd9Sstevel@tonic-gate  */
17287c478bd9Sstevel@tonic-gate void
17297c478bd9Sstevel@tonic-gate vn_reclaim(vnode_t *vp)
17307c478bd9Sstevel@tonic-gate {
17317c478bd9Sstevel@tonic-gate 	vfs_t   *vfsp = vp->v_vfsp;
17327c478bd9Sstevel@tonic-gate 
17337c478bd9Sstevel@tonic-gate 	if (vfsp == NULL || vfsp->vfs_femhead == NULL) {
17347c478bd9Sstevel@tonic-gate 		return;
17357c478bd9Sstevel@tonic-gate 	}
17367c478bd9Sstevel@tonic-gate 	(void) VFS_VNSTATE(vfsp, vp, VNTRANS_RECLAIMED);
17377c478bd9Sstevel@tonic-gate }
17387c478bd9Sstevel@tonic-gate 
17397c478bd9Sstevel@tonic-gate void
17407c478bd9Sstevel@tonic-gate vn_idle(vnode_t *vp)
17417c478bd9Sstevel@tonic-gate {
17427c478bd9Sstevel@tonic-gate 	vfs_t   *vfsp = vp->v_vfsp;
17437c478bd9Sstevel@tonic-gate 
17447c478bd9Sstevel@tonic-gate 	if (vfsp == NULL || vfsp->vfs_femhead == NULL) {
17457c478bd9Sstevel@tonic-gate 		return;
17467c478bd9Sstevel@tonic-gate 	}
17477c478bd9Sstevel@tonic-gate 	(void) VFS_VNSTATE(vfsp, vp, VNTRANS_IDLED);
17487c478bd9Sstevel@tonic-gate }
17497c478bd9Sstevel@tonic-gate void
17507c478bd9Sstevel@tonic-gate vn_exists(vnode_t *vp)
17517c478bd9Sstevel@tonic-gate {
17527c478bd9Sstevel@tonic-gate 	vfs_t   *vfsp = vp->v_vfsp;
17537c478bd9Sstevel@tonic-gate 
17547c478bd9Sstevel@tonic-gate 	if (vfsp == NULL || vfsp->vfs_femhead == NULL) {
17557c478bd9Sstevel@tonic-gate 		return;
17567c478bd9Sstevel@tonic-gate 	}
17577c478bd9Sstevel@tonic-gate 	(void) VFS_VNSTATE(vfsp, vp, VNTRANS_EXISTS);
17587c478bd9Sstevel@tonic-gate }
17597c478bd9Sstevel@tonic-gate 
17607c478bd9Sstevel@tonic-gate void
17617c478bd9Sstevel@tonic-gate vn_invalid(vnode_t *vp)
17627c478bd9Sstevel@tonic-gate {
17637c478bd9Sstevel@tonic-gate 	vfs_t   *vfsp = vp->v_vfsp;
17647c478bd9Sstevel@tonic-gate 
17657c478bd9Sstevel@tonic-gate 	if (vfsp == NULL || vfsp->vfs_femhead == NULL) {
17667c478bd9Sstevel@tonic-gate 		return;
17677c478bd9Sstevel@tonic-gate 	}
17687c478bd9Sstevel@tonic-gate 	(void) VFS_VNSTATE(vfsp, vp, VNTRANS_DESTROYED);
17697c478bd9Sstevel@tonic-gate }
17707c478bd9Sstevel@tonic-gate 
17717c478bd9Sstevel@tonic-gate /* Vnode event notification */
17727c478bd9Sstevel@tonic-gate 
17737c478bd9Sstevel@tonic-gate int
17747c478bd9Sstevel@tonic-gate vnevent_support(vnode_t *vp)
17757c478bd9Sstevel@tonic-gate {
17767c478bd9Sstevel@tonic-gate 	if (vp == NULL)
17777c478bd9Sstevel@tonic-gate 		return (EINVAL);
17787c478bd9Sstevel@tonic-gate 
17797c478bd9Sstevel@tonic-gate 	return (VOP_VNEVENT(vp, VE_SUPPORT));
17807c478bd9Sstevel@tonic-gate }
17817c478bd9Sstevel@tonic-gate 
17827c478bd9Sstevel@tonic-gate void
17837c478bd9Sstevel@tonic-gate vnevent_rename_src(vnode_t *vp)
17847c478bd9Sstevel@tonic-gate {
17857c478bd9Sstevel@tonic-gate 	if (vp == NULL || vp->v_femhead == NULL) {
17867c478bd9Sstevel@tonic-gate 		return;
17877c478bd9Sstevel@tonic-gate 	}
17887c478bd9Sstevel@tonic-gate 	(void) VOP_VNEVENT(vp, VE_RENAME_SRC);
17897c478bd9Sstevel@tonic-gate }
17907c478bd9Sstevel@tonic-gate 
17917c478bd9Sstevel@tonic-gate void
17927c478bd9Sstevel@tonic-gate vnevent_rename_dest(vnode_t *vp)
17937c478bd9Sstevel@tonic-gate {
17947c478bd9Sstevel@tonic-gate 	if (vp == NULL || vp->v_femhead == NULL) {
17957c478bd9Sstevel@tonic-gate 		return;
17967c478bd9Sstevel@tonic-gate 	}
17977c478bd9Sstevel@tonic-gate 	(void) VOP_VNEVENT(vp, VE_RENAME_DEST);
17987c478bd9Sstevel@tonic-gate }
17997c478bd9Sstevel@tonic-gate 
18007c478bd9Sstevel@tonic-gate void
18017c478bd9Sstevel@tonic-gate vnevent_remove(vnode_t *vp)
18027c478bd9Sstevel@tonic-gate {
18037c478bd9Sstevel@tonic-gate 	if (vp == NULL || vp->v_femhead == NULL) {
18047c478bd9Sstevel@tonic-gate 		return;
18057c478bd9Sstevel@tonic-gate 	}
18067c478bd9Sstevel@tonic-gate 	(void) VOP_VNEVENT(vp, VE_REMOVE);
18077c478bd9Sstevel@tonic-gate }
18087c478bd9Sstevel@tonic-gate 
18097c478bd9Sstevel@tonic-gate void
18107c478bd9Sstevel@tonic-gate vnevent_rmdir(vnode_t *vp)
18117c478bd9Sstevel@tonic-gate {
18127c478bd9Sstevel@tonic-gate 	if (vp == NULL || vp->v_femhead == NULL) {
18137c478bd9Sstevel@tonic-gate 		return;
18147c478bd9Sstevel@tonic-gate 	}
18157c478bd9Sstevel@tonic-gate 	(void) VOP_VNEVENT(vp, VE_RMDIR);
18167c478bd9Sstevel@tonic-gate }
18177c478bd9Sstevel@tonic-gate 
18187c478bd9Sstevel@tonic-gate /*
18197c478bd9Sstevel@tonic-gate  * Vnode accessors.
18207c478bd9Sstevel@tonic-gate  */
18217c478bd9Sstevel@tonic-gate 
18227c478bd9Sstevel@tonic-gate int
18237c478bd9Sstevel@tonic-gate vn_is_readonly(vnode_t *vp)
18247c478bd9Sstevel@tonic-gate {
18257c478bd9Sstevel@tonic-gate 	return (vp->v_vfsp->vfs_flag & VFS_RDONLY);
18267c478bd9Sstevel@tonic-gate }
18277c478bd9Sstevel@tonic-gate 
18287c478bd9Sstevel@tonic-gate int
18297c478bd9Sstevel@tonic-gate vn_has_flocks(vnode_t *vp)
18307c478bd9Sstevel@tonic-gate {
18317c478bd9Sstevel@tonic-gate 	return (vp->v_filocks != NULL);
18327c478bd9Sstevel@tonic-gate }
18337c478bd9Sstevel@tonic-gate 
18347c478bd9Sstevel@tonic-gate int
18357c478bd9Sstevel@tonic-gate vn_has_mandatory_locks(vnode_t *vp, int mode)
18367c478bd9Sstevel@tonic-gate {
18377c478bd9Sstevel@tonic-gate 	return ((vp->v_filocks != NULL) && (MANDLOCK(vp, mode)));
18387c478bd9Sstevel@tonic-gate }
18397c478bd9Sstevel@tonic-gate 
18407c478bd9Sstevel@tonic-gate int
18417c478bd9Sstevel@tonic-gate vn_has_cached_data(vnode_t *vp)
18427c478bd9Sstevel@tonic-gate {
18437c478bd9Sstevel@tonic-gate 	return (vp->v_pages != NULL);
18447c478bd9Sstevel@tonic-gate }
18457c478bd9Sstevel@tonic-gate 
18467c478bd9Sstevel@tonic-gate /*
18477c478bd9Sstevel@tonic-gate  * Return 0 if the vnode in question shouldn't be permitted into a zone via
18487c478bd9Sstevel@tonic-gate  * zone_enter(2).
18497c478bd9Sstevel@tonic-gate  */
18507c478bd9Sstevel@tonic-gate int
18517c478bd9Sstevel@tonic-gate vn_can_change_zones(vnode_t *vp)
18527c478bd9Sstevel@tonic-gate {
18537c478bd9Sstevel@tonic-gate 	struct vfssw *vswp;
18547c478bd9Sstevel@tonic-gate 	int allow = 1;
18557c478bd9Sstevel@tonic-gate 	vnode_t *rvp;
18567c478bd9Sstevel@tonic-gate 
18577c478bd9Sstevel@tonic-gate 	/*
18587c478bd9Sstevel@tonic-gate 	 * We always want to look at the underlying vnode if there is one.
18597c478bd9Sstevel@tonic-gate 	 */
18607c478bd9Sstevel@tonic-gate 	if (VOP_REALVP(vp, &rvp) != 0)
18617c478bd9Sstevel@tonic-gate 		rvp = vp;
18627c478bd9Sstevel@tonic-gate 	/*
18637c478bd9Sstevel@tonic-gate 	 * Some pseudo filesystems (including doorfs) don't actually register
18647c478bd9Sstevel@tonic-gate 	 * their vfsops_t, so the following may return NULL; we happily let
18657c478bd9Sstevel@tonic-gate 	 * such vnodes switch zones.
18667c478bd9Sstevel@tonic-gate 	 */
18677c478bd9Sstevel@tonic-gate 	vswp = vfs_getvfsswbyvfsops(vfs_getops(rvp->v_vfsp));
18687c478bd9Sstevel@tonic-gate 	if (vswp != NULL) {
18697c478bd9Sstevel@tonic-gate 		if (vswp->vsw_flag & VSW_NOTZONESAFE)
18707c478bd9Sstevel@tonic-gate 			allow = 0;
18717c478bd9Sstevel@tonic-gate 		vfs_unrefvfssw(vswp);
18727c478bd9Sstevel@tonic-gate 	}
18737c478bd9Sstevel@tonic-gate 	return (allow);
18747c478bd9Sstevel@tonic-gate }
18757c478bd9Sstevel@tonic-gate 
18767c478bd9Sstevel@tonic-gate /*
18777c478bd9Sstevel@tonic-gate  * Return nonzero if the vnode is a mount point, zero if not.
18787c478bd9Sstevel@tonic-gate  */
18797c478bd9Sstevel@tonic-gate int
18807c478bd9Sstevel@tonic-gate vn_ismntpt(vnode_t *vp)
18817c478bd9Sstevel@tonic-gate {
18827c478bd9Sstevel@tonic-gate 	return (vp->v_vfsmountedhere != NULL);
18837c478bd9Sstevel@tonic-gate }
18847c478bd9Sstevel@tonic-gate 
18857c478bd9Sstevel@tonic-gate /* Retrieve the vfs (if any) mounted on this vnode */
18867c478bd9Sstevel@tonic-gate vfs_t *
18877c478bd9Sstevel@tonic-gate vn_mountedvfs(vnode_t *vp)
18887c478bd9Sstevel@tonic-gate {
18897c478bd9Sstevel@tonic-gate 	return (vp->v_vfsmountedhere);
18907c478bd9Sstevel@tonic-gate }
18917c478bd9Sstevel@tonic-gate 
18927c478bd9Sstevel@tonic-gate /*
18937c478bd9Sstevel@tonic-gate  * vn_is_opened() checks whether a particular file is opened and
18947c478bd9Sstevel@tonic-gate  * whether the open is for read and/or write.
18957c478bd9Sstevel@tonic-gate  *
18967c478bd9Sstevel@tonic-gate  * Vnode counts are only kept on regular files (v_type=VREG).
18977c478bd9Sstevel@tonic-gate  */
18987c478bd9Sstevel@tonic-gate int
18997c478bd9Sstevel@tonic-gate vn_is_opened(
19007c478bd9Sstevel@tonic-gate 	vnode_t *vp,
19017c478bd9Sstevel@tonic-gate 	v_mode_t mode)
19027c478bd9Sstevel@tonic-gate {
19037c478bd9Sstevel@tonic-gate 
19047c478bd9Sstevel@tonic-gate 	ASSERT(vp != NULL);
19057c478bd9Sstevel@tonic-gate 
19067c478bd9Sstevel@tonic-gate 	switch (mode) {
19077c478bd9Sstevel@tonic-gate 	case V_WRITE:
19087c478bd9Sstevel@tonic-gate 		if (vp->v_wrcnt)
19097c478bd9Sstevel@tonic-gate 			return (V_TRUE);
19107c478bd9Sstevel@tonic-gate 		break;
19117c478bd9Sstevel@tonic-gate 	case V_RDANDWR:
19127c478bd9Sstevel@tonic-gate 		if (vp->v_rdcnt && vp->v_wrcnt)
19137c478bd9Sstevel@tonic-gate 			return (V_TRUE);
19147c478bd9Sstevel@tonic-gate 		break;
19157c478bd9Sstevel@tonic-gate 	case V_RDORWR:
19167c478bd9Sstevel@tonic-gate 		if (vp->v_rdcnt || vp->v_wrcnt)
19177c478bd9Sstevel@tonic-gate 			return (V_TRUE);
19187c478bd9Sstevel@tonic-gate 		break;
19197c478bd9Sstevel@tonic-gate 	case V_READ:
19207c478bd9Sstevel@tonic-gate 		if (vp->v_rdcnt)
19217c478bd9Sstevel@tonic-gate 			return (V_TRUE);
19227c478bd9Sstevel@tonic-gate 		break;
19237c478bd9Sstevel@tonic-gate 	}
19247c478bd9Sstevel@tonic-gate 
19257c478bd9Sstevel@tonic-gate 	return (V_FALSE);
19267c478bd9Sstevel@tonic-gate }
19277c478bd9Sstevel@tonic-gate 
19287c478bd9Sstevel@tonic-gate /*
19297c478bd9Sstevel@tonic-gate  * vn_is_mapped() checks whether a particular file is mapped and whether
19307c478bd9Sstevel@tonic-gate  * the file is mapped read and/or write.
19317c478bd9Sstevel@tonic-gate  */
19327c478bd9Sstevel@tonic-gate int
19337c478bd9Sstevel@tonic-gate vn_is_mapped(
19347c478bd9Sstevel@tonic-gate 	vnode_t *vp,
19357c478bd9Sstevel@tonic-gate 	v_mode_t mode)
19367c478bd9Sstevel@tonic-gate {
19377c478bd9Sstevel@tonic-gate 
19387c478bd9Sstevel@tonic-gate 	ASSERT(vp != NULL);
19397c478bd9Sstevel@tonic-gate 
19407c478bd9Sstevel@tonic-gate #if !defined(_LP64)
19417c478bd9Sstevel@tonic-gate 	switch (mode) {
19427c478bd9Sstevel@tonic-gate 	/*
19437c478bd9Sstevel@tonic-gate 	 * The atomic_add_64_nv functions force atomicity in the
19447c478bd9Sstevel@tonic-gate 	 * case of 32 bit architectures. Otherwise the 64 bit values
19457c478bd9Sstevel@tonic-gate 	 * require two fetches. The value of the fields may be
19467c478bd9Sstevel@tonic-gate 	 * (potentially) changed between the first fetch and the
19477c478bd9Sstevel@tonic-gate 	 * second
19487c478bd9Sstevel@tonic-gate 	 */
19497c478bd9Sstevel@tonic-gate 	case V_WRITE:
19507c478bd9Sstevel@tonic-gate 		if (atomic_add_64_nv((&(vp->v_mmap_write)), 0))
19517c478bd9Sstevel@tonic-gate 			return (V_TRUE);
19527c478bd9Sstevel@tonic-gate 		break;
19537c478bd9Sstevel@tonic-gate 	case V_RDANDWR:
19547c478bd9Sstevel@tonic-gate 		if ((atomic_add_64_nv((&(vp->v_mmap_read)), 0)) &&
19557c478bd9Sstevel@tonic-gate 		    (atomic_add_64_nv((&(vp->v_mmap_write)), 0)))
19567c478bd9Sstevel@tonic-gate 			return (V_TRUE);
19577c478bd9Sstevel@tonic-gate 		break;
19587c478bd9Sstevel@tonic-gate 	case V_RDORWR:
19597c478bd9Sstevel@tonic-gate 		if ((atomic_add_64_nv((&(vp->v_mmap_read)), 0)) ||
19607c478bd9Sstevel@tonic-gate 		    (atomic_add_64_nv((&(vp->v_mmap_write)), 0)))
19617c478bd9Sstevel@tonic-gate 			return (V_TRUE);
19627c478bd9Sstevel@tonic-gate 		break;
19637c478bd9Sstevel@tonic-gate 	case V_READ:
19647c478bd9Sstevel@tonic-gate 		if (atomic_add_64_nv((&(vp->v_mmap_read)), 0))
19657c478bd9Sstevel@tonic-gate 			return (V_TRUE);
19667c478bd9Sstevel@tonic-gate 		break;
19677c478bd9Sstevel@tonic-gate 	}
19687c478bd9Sstevel@tonic-gate #else
19697c478bd9Sstevel@tonic-gate 	switch (mode) {
19707c478bd9Sstevel@tonic-gate 	case V_WRITE:
19717c478bd9Sstevel@tonic-gate 		if (vp->v_mmap_write)
19727c478bd9Sstevel@tonic-gate 			return (V_TRUE);
19737c478bd9Sstevel@tonic-gate 		break;
19747c478bd9Sstevel@tonic-gate 	case V_RDANDWR:
19757c478bd9Sstevel@tonic-gate 		if (vp->v_mmap_read && vp->v_mmap_write)
19767c478bd9Sstevel@tonic-gate 			return (V_TRUE);
19777c478bd9Sstevel@tonic-gate 		break;
19787c478bd9Sstevel@tonic-gate 	case V_RDORWR:
19797c478bd9Sstevel@tonic-gate 		if (vp->v_mmap_read || vp->v_mmap_write)
19807c478bd9Sstevel@tonic-gate 			return (V_TRUE);
19817c478bd9Sstevel@tonic-gate 		break;
19827c478bd9Sstevel@tonic-gate 	case V_READ:
19837c478bd9Sstevel@tonic-gate 		if (vp->v_mmap_read)
19847c478bd9Sstevel@tonic-gate 			return (V_TRUE);
19857c478bd9Sstevel@tonic-gate 		break;
19867c478bd9Sstevel@tonic-gate 	}
19877c478bd9Sstevel@tonic-gate #endif
19887c478bd9Sstevel@tonic-gate 
19897c478bd9Sstevel@tonic-gate 	return (V_FALSE);
19907c478bd9Sstevel@tonic-gate }
19917c478bd9Sstevel@tonic-gate 
19927c478bd9Sstevel@tonic-gate /*
19937c478bd9Sstevel@tonic-gate  * Set the operations vector for a vnode.
19947c478bd9Sstevel@tonic-gate  *
19957c478bd9Sstevel@tonic-gate  * FEM ensures that the v_femhead pointer is filled in before the
19967c478bd9Sstevel@tonic-gate  * v_op pointer is changed.  This means that if the v_femhead pointer
19977c478bd9Sstevel@tonic-gate  * is NULL, and the v_op field hasn't changed since before which checked
19987c478bd9Sstevel@tonic-gate  * the v_femhead pointer; then our update is ok - we are not racing with
19997c478bd9Sstevel@tonic-gate  * FEM.
20007c478bd9Sstevel@tonic-gate  */
20017c478bd9Sstevel@tonic-gate void
20027c478bd9Sstevel@tonic-gate vn_setops(vnode_t *vp, vnodeops_t *vnodeops)
20037c478bd9Sstevel@tonic-gate {
20047c478bd9Sstevel@tonic-gate 	vnodeops_t	*op;
20057c478bd9Sstevel@tonic-gate 
20067c478bd9Sstevel@tonic-gate 	ASSERT(vp != NULL);
20077c478bd9Sstevel@tonic-gate 	ASSERT(vnodeops != NULL);
20087c478bd9Sstevel@tonic-gate 
20097c478bd9Sstevel@tonic-gate 	op = vp->v_op;
20107c478bd9Sstevel@tonic-gate 	membar_consumer();
20117c478bd9Sstevel@tonic-gate 	/*
20127c478bd9Sstevel@tonic-gate 	 * If vp->v_femhead == NULL, then we'll call casptr() to do the
20137c478bd9Sstevel@tonic-gate 	 * compare-and-swap on vp->v_op.  If either fails, then FEM is
20147c478bd9Sstevel@tonic-gate 	 * in effect on the vnode and we need to have FEM deal with it.
20157c478bd9Sstevel@tonic-gate 	 */
20167c478bd9Sstevel@tonic-gate 	if (vp->v_femhead != NULL || casptr(&vp->v_op, op, vnodeops) != op) {
20177c478bd9Sstevel@tonic-gate 		fem_setvnops(vp, vnodeops);
20187c478bd9Sstevel@tonic-gate 	}
20197c478bd9Sstevel@tonic-gate }
20207c478bd9Sstevel@tonic-gate 
20217c478bd9Sstevel@tonic-gate /*
20227c478bd9Sstevel@tonic-gate  * Retrieve the operations vector for a vnode
20237c478bd9Sstevel@tonic-gate  * As with vn_setops(above); make sure we aren't racing with FEM.
20247c478bd9Sstevel@tonic-gate  * FEM sets the v_op to a special, internal, vnodeops that wouldn't
20257c478bd9Sstevel@tonic-gate  * make sense to the callers of this routine.
20267c478bd9Sstevel@tonic-gate  */
20277c478bd9Sstevel@tonic-gate vnodeops_t *
20287c478bd9Sstevel@tonic-gate vn_getops(vnode_t *vp)
20297c478bd9Sstevel@tonic-gate {
20307c478bd9Sstevel@tonic-gate 	vnodeops_t	*op;
20317c478bd9Sstevel@tonic-gate 
20327c478bd9Sstevel@tonic-gate 	ASSERT(vp != NULL);
20337c478bd9Sstevel@tonic-gate 
20347c478bd9Sstevel@tonic-gate 	op = vp->v_op;
20357c478bd9Sstevel@tonic-gate 	membar_consumer();
20367c478bd9Sstevel@tonic-gate 	if (vp->v_femhead == NULL && op == vp->v_op) {
20377c478bd9Sstevel@tonic-gate 		return (op);
20387c478bd9Sstevel@tonic-gate 	} else {
20397c478bd9Sstevel@tonic-gate 		return (fem_getvnops(vp));
20407c478bd9Sstevel@tonic-gate 	}
20417c478bd9Sstevel@tonic-gate }
20427c478bd9Sstevel@tonic-gate 
20437c478bd9Sstevel@tonic-gate /*
20447c478bd9Sstevel@tonic-gate  * Returns non-zero (1) if the vnodeops matches that of the vnode.
20457c478bd9Sstevel@tonic-gate  * Returns zero (0) if not.
20467c478bd9Sstevel@tonic-gate  */
20477c478bd9Sstevel@tonic-gate int
20487c478bd9Sstevel@tonic-gate vn_matchops(vnode_t *vp, vnodeops_t *vnodeops)
20497c478bd9Sstevel@tonic-gate {
20507c478bd9Sstevel@tonic-gate 	return (vn_getops(vp) == vnodeops);
20517c478bd9Sstevel@tonic-gate }
20527c478bd9Sstevel@tonic-gate 
20537c478bd9Sstevel@tonic-gate /*
20547c478bd9Sstevel@tonic-gate  * Returns non-zero (1) if the specified operation matches the
20557c478bd9Sstevel@tonic-gate  * corresponding operation for that the vnode.
20567c478bd9Sstevel@tonic-gate  * Returns zero (0) if not.
20577c478bd9Sstevel@tonic-gate  */
20587c478bd9Sstevel@tonic-gate 
20597c478bd9Sstevel@tonic-gate #define	MATCHNAME(n1, n2) (((n1)[0] == (n2)[0]) && (strcmp((n1), (n2)) == 0))
20607c478bd9Sstevel@tonic-gate 
20617c478bd9Sstevel@tonic-gate int
20627c478bd9Sstevel@tonic-gate vn_matchopval(vnode_t *vp, char *vopname, fs_generic_func_p funcp)
20637c478bd9Sstevel@tonic-gate {
20647c478bd9Sstevel@tonic-gate 	const fs_operation_trans_def_t *otdp;
20657c478bd9Sstevel@tonic-gate 	fs_generic_func_p *loc = NULL;
20667c478bd9Sstevel@tonic-gate 	vnodeops_t	*vop = vn_getops(vp);
20677c478bd9Sstevel@tonic-gate 
20687c478bd9Sstevel@tonic-gate 	ASSERT(vopname != NULL);
20697c478bd9Sstevel@tonic-gate 
20707c478bd9Sstevel@tonic-gate 	for (otdp = vn_ops_table; otdp->name != NULL; otdp++) {
20717c478bd9Sstevel@tonic-gate 		if (MATCHNAME(otdp->name, vopname)) {
20727c478bd9Sstevel@tonic-gate 			loc = (fs_generic_func_p *)((char *)(vop)
20737c478bd9Sstevel@tonic-gate 							+ otdp->offset);
20747c478bd9Sstevel@tonic-gate 			break;
20757c478bd9Sstevel@tonic-gate 		}
20767c478bd9Sstevel@tonic-gate 	}
20777c478bd9Sstevel@tonic-gate 
20787c478bd9Sstevel@tonic-gate 	return ((loc != NULL) && (*loc == funcp));
20797c478bd9Sstevel@tonic-gate }
20807c478bd9Sstevel@tonic-gate 
20817c478bd9Sstevel@tonic-gate /*
20827c478bd9Sstevel@tonic-gate  * fs_new_caller_id() needs to return a unique ID on a given local system.
20837c478bd9Sstevel@tonic-gate  * The IDs do not need to survive across reboots.  These are primarily
20847c478bd9Sstevel@tonic-gate  * used so that (FEM) monitors can detect particular callers (such as
20857c478bd9Sstevel@tonic-gate  * the NFS server) to a given vnode/vfs operation.
20867c478bd9Sstevel@tonic-gate  */
20877c478bd9Sstevel@tonic-gate u_longlong_t
20887c478bd9Sstevel@tonic-gate fs_new_caller_id()
20897c478bd9Sstevel@tonic-gate {
20907c478bd9Sstevel@tonic-gate 	static uint64_t next_caller_id = 0LL; /* First call returns 1 */
20917c478bd9Sstevel@tonic-gate 
20927c478bd9Sstevel@tonic-gate 	return ((u_longlong_t)atomic_add_64_nv(&next_caller_id, 1));
20937c478bd9Sstevel@tonic-gate }
20947c478bd9Sstevel@tonic-gate 
20957c478bd9Sstevel@tonic-gate /*
20967c478bd9Sstevel@tonic-gate  * Given a starting vnode and a path, updates the path in the target vnode in
20977c478bd9Sstevel@tonic-gate  * a safe manner.  If the vnode already has path information embedded, then the
2098*ca2c3138Seschrock  * cached path is left untouched.
20997c478bd9Sstevel@tonic-gate  */
21007c478bd9Sstevel@tonic-gate void
21017c478bd9Sstevel@tonic-gate vn_setpath(vnode_t *rootvp, struct vnode *startvp, struct vnode *vp,
21027c478bd9Sstevel@tonic-gate     const char *path, size_t plen)
21037c478bd9Sstevel@tonic-gate {
21047c478bd9Sstevel@tonic-gate 	char	*rpath;
21057c478bd9Sstevel@tonic-gate 	vnode_t	*base;
21067c478bd9Sstevel@tonic-gate 	size_t	rpathlen, rpathalloc;
21077c478bd9Sstevel@tonic-gate 	int	doslash = 1;
21087c478bd9Sstevel@tonic-gate 
21097c478bd9Sstevel@tonic-gate 	if (*path == '/') {
21107c478bd9Sstevel@tonic-gate 		base = rootvp;
21117c478bd9Sstevel@tonic-gate 		path++;
21127c478bd9Sstevel@tonic-gate 		plen--;
21137c478bd9Sstevel@tonic-gate 	} else {
21147c478bd9Sstevel@tonic-gate 		base = startvp;
21157c478bd9Sstevel@tonic-gate 	}
21167c478bd9Sstevel@tonic-gate 
21177c478bd9Sstevel@tonic-gate 	/*
21187c478bd9Sstevel@tonic-gate 	 * We cannot grab base->v_lock while we hold vp->v_lock because of
21197c478bd9Sstevel@tonic-gate 	 * the potential for deadlock.
21207c478bd9Sstevel@tonic-gate 	 */
21217c478bd9Sstevel@tonic-gate 	mutex_enter(&base->v_lock);
21227c478bd9Sstevel@tonic-gate 	if (base->v_path == NULL) {
21237c478bd9Sstevel@tonic-gate 		mutex_exit(&base->v_lock);
21247c478bd9Sstevel@tonic-gate 		return;
21257c478bd9Sstevel@tonic-gate 	}
21267c478bd9Sstevel@tonic-gate 
21277c478bd9Sstevel@tonic-gate 	rpathlen = strlen(base->v_path);
21287c478bd9Sstevel@tonic-gate 	rpathalloc = rpathlen + plen + 1;
21297c478bd9Sstevel@tonic-gate 	/* Avoid adding a slash if there's already one there */
21307c478bd9Sstevel@tonic-gate 	if (base->v_path[rpathlen-1] == '/')
21317c478bd9Sstevel@tonic-gate 		doslash = 0;
21327c478bd9Sstevel@tonic-gate 	else
21337c478bd9Sstevel@tonic-gate 		rpathalloc++;
21347c478bd9Sstevel@tonic-gate 
21357c478bd9Sstevel@tonic-gate 	/*
21367c478bd9Sstevel@tonic-gate 	 * We don't want to call kmem_alloc(KM_SLEEP) with kernel locks held,
21377c478bd9Sstevel@tonic-gate 	 * so we must do this dance.  If, by chance, something changes the path,
21387c478bd9Sstevel@tonic-gate 	 * just give up since there is no real harm.
21397c478bd9Sstevel@tonic-gate 	 */
21407c478bd9Sstevel@tonic-gate 	mutex_exit(&base->v_lock);
21417c478bd9Sstevel@tonic-gate 
21427c478bd9Sstevel@tonic-gate 	rpath = kmem_alloc(rpathalloc, KM_SLEEP);
21437c478bd9Sstevel@tonic-gate 
21447c478bd9Sstevel@tonic-gate 	mutex_enter(&base->v_lock);
21457c478bd9Sstevel@tonic-gate 	if (base->v_path == NULL || strlen(base->v_path) != rpathlen) {
21467c478bd9Sstevel@tonic-gate 		mutex_exit(&base->v_lock);
21477c478bd9Sstevel@tonic-gate 		kmem_free(rpath, rpathalloc);
21487c478bd9Sstevel@tonic-gate 		return;
21497c478bd9Sstevel@tonic-gate 	}
21507c478bd9Sstevel@tonic-gate 	bcopy(base->v_path, rpath, rpathlen);
21517c478bd9Sstevel@tonic-gate 	mutex_exit(&base->v_lock);
21527c478bd9Sstevel@tonic-gate 
21537c478bd9Sstevel@tonic-gate 	if (doslash)
21547c478bd9Sstevel@tonic-gate 		rpath[rpathlen++] = '/';
21557c478bd9Sstevel@tonic-gate 	bcopy(path, rpath + rpathlen, plen);
21567c478bd9Sstevel@tonic-gate 	rpath[rpathlen + plen] = '\0';
21577c478bd9Sstevel@tonic-gate 
21587c478bd9Sstevel@tonic-gate 	mutex_enter(&vp->v_lock);
21597c478bd9Sstevel@tonic-gate 	if (vp->v_path != NULL) {
21607c478bd9Sstevel@tonic-gate 		mutex_exit(&vp->v_lock);
21617c478bd9Sstevel@tonic-gate 		kmem_free(rpath, rpathalloc);
21627c478bd9Sstevel@tonic-gate 	} else {
21637c478bd9Sstevel@tonic-gate 		vp->v_path = rpath;
21647c478bd9Sstevel@tonic-gate 		mutex_exit(&vp->v_lock);
21657c478bd9Sstevel@tonic-gate 	}
21667c478bd9Sstevel@tonic-gate }
21677c478bd9Sstevel@tonic-gate 
21687c478bd9Sstevel@tonic-gate /*
21697c478bd9Sstevel@tonic-gate  * Sets the path to the vnode to be the given string, regardless of current
21707c478bd9Sstevel@tonic-gate  * context.  The string must be a complete path from rootdir.  This is only used
21717c478bd9Sstevel@tonic-gate  * by fsop_root() for setting the path based on the mountpoint.
21727c478bd9Sstevel@tonic-gate  */
21737c478bd9Sstevel@tonic-gate void
21747c478bd9Sstevel@tonic-gate vn_setpath_str(struct vnode *vp, const char *str, size_t len)
21757c478bd9Sstevel@tonic-gate {
21767c478bd9Sstevel@tonic-gate 	char *buf = kmem_alloc(len + 1, KM_SLEEP);
21777c478bd9Sstevel@tonic-gate 
21787c478bd9Sstevel@tonic-gate 	mutex_enter(&vp->v_lock);
21797c478bd9Sstevel@tonic-gate 	if (vp->v_path != NULL) {
21807c478bd9Sstevel@tonic-gate 		mutex_exit(&vp->v_lock);
21817c478bd9Sstevel@tonic-gate 		kmem_free(buf, len + 1);
21827c478bd9Sstevel@tonic-gate 		return;
21837c478bd9Sstevel@tonic-gate 	}
21847c478bd9Sstevel@tonic-gate 
21857c478bd9Sstevel@tonic-gate 	vp->v_path = buf;
21867c478bd9Sstevel@tonic-gate 	bcopy(str, vp->v_path, len);
21877c478bd9Sstevel@tonic-gate 	vp->v_path[len] = '\0';
21887c478bd9Sstevel@tonic-gate 
21897c478bd9Sstevel@tonic-gate 	mutex_exit(&vp->v_lock);
21907c478bd9Sstevel@tonic-gate }
21917c478bd9Sstevel@tonic-gate 
21927c478bd9Sstevel@tonic-gate /*
21937c478bd9Sstevel@tonic-gate  * Similar to vn_setpath_str(), this function sets the path of the destination
21947c478bd9Sstevel@tonic-gate  * vnode to the be the same as the source vnode.
21957c478bd9Sstevel@tonic-gate  */
21967c478bd9Sstevel@tonic-gate void
21977c478bd9Sstevel@tonic-gate vn_copypath(struct vnode *src, struct vnode *dst)
21987c478bd9Sstevel@tonic-gate {
21997c478bd9Sstevel@tonic-gate 	char *buf;
22007c478bd9Sstevel@tonic-gate 	int alloc;
22017c478bd9Sstevel@tonic-gate 
22027c478bd9Sstevel@tonic-gate 	mutex_enter(&src->v_lock);
22037c478bd9Sstevel@tonic-gate 	if (src->v_path == NULL) {
22047c478bd9Sstevel@tonic-gate 		mutex_exit(&src->v_lock);
22057c478bd9Sstevel@tonic-gate 		return;
22067c478bd9Sstevel@tonic-gate 	}
22077c478bd9Sstevel@tonic-gate 	alloc = strlen(src->v_path) + 1;
22087c478bd9Sstevel@tonic-gate 
22097c478bd9Sstevel@tonic-gate 	/* avoid kmem_alloc() with lock held */
22107c478bd9Sstevel@tonic-gate 	mutex_exit(&src->v_lock);
22117c478bd9Sstevel@tonic-gate 	buf = kmem_alloc(alloc, KM_SLEEP);
22127c478bd9Sstevel@tonic-gate 	mutex_enter(&src->v_lock);
22137c478bd9Sstevel@tonic-gate 	if (src->v_path == NULL || strlen(src->v_path) + 1 != alloc) {
22147c478bd9Sstevel@tonic-gate 		mutex_exit(&src->v_lock);
22157c478bd9Sstevel@tonic-gate 		kmem_free(buf, alloc);
22167c478bd9Sstevel@tonic-gate 		return;
22177c478bd9Sstevel@tonic-gate 	}
22187c478bd9Sstevel@tonic-gate 	bcopy(src->v_path, buf, alloc);
22197c478bd9Sstevel@tonic-gate 	mutex_exit(&src->v_lock);
22207c478bd9Sstevel@tonic-gate 
22217c478bd9Sstevel@tonic-gate 	mutex_enter(&dst->v_lock);
22227c478bd9Sstevel@tonic-gate 	if (dst->v_path != NULL) {
22237c478bd9Sstevel@tonic-gate 		mutex_exit(&dst->v_lock);
22247c478bd9Sstevel@tonic-gate 		kmem_free(buf, alloc);
22257c478bd9Sstevel@tonic-gate 		return;
22267c478bd9Sstevel@tonic-gate 	}
22277c478bd9Sstevel@tonic-gate 	dst->v_path = buf;
22287c478bd9Sstevel@tonic-gate 	mutex_exit(&dst->v_lock);
22297c478bd9Sstevel@tonic-gate }
22307c478bd9Sstevel@tonic-gate 
22317c478bd9Sstevel@tonic-gate /*
22327c478bd9Sstevel@tonic-gate  * XXX Private interface for segvn routines that handle vnode
22337c478bd9Sstevel@tonic-gate  * large page segments.
22347c478bd9Sstevel@tonic-gate  *
22357c478bd9Sstevel@tonic-gate  * return 1 if vp's file system VOP_PAGEIO() implementation
22367c478bd9Sstevel@tonic-gate  * can be safely used instead of VOP_GETPAGE() for handling
22377c478bd9Sstevel@tonic-gate  * pagefaults against regular non swap files. VOP_PAGEIO()
22387c478bd9Sstevel@tonic-gate  * interface is considered safe here if its implementation
22397c478bd9Sstevel@tonic-gate  * is very close to VOP_GETPAGE() implementation.
22407c478bd9Sstevel@tonic-gate  * e.g. It zero's out the part of the page beyond EOF. Doesn't
22417c478bd9Sstevel@tonic-gate  * panic if there're file holes but instead returns an error.
22427c478bd9Sstevel@tonic-gate  * Doesn't assume file won't be changed by user writes, etc.
22437c478bd9Sstevel@tonic-gate  *
22447c478bd9Sstevel@tonic-gate  * return 0 otherwise.
22457c478bd9Sstevel@tonic-gate  *
22467c478bd9Sstevel@tonic-gate  * For now allow segvn to only use VOP_PAGEIO() with ufs and nfs.
22477c478bd9Sstevel@tonic-gate  */
22487c478bd9Sstevel@tonic-gate int
22497c478bd9Sstevel@tonic-gate vn_vmpss_usepageio(vnode_t *vp)
22507c478bd9Sstevel@tonic-gate {
22517c478bd9Sstevel@tonic-gate 	vfs_t   *vfsp = vp->v_vfsp;
22527c478bd9Sstevel@tonic-gate 	char *fsname = vfssw[vfsp->vfs_fstype].vsw_name;
22537c478bd9Sstevel@tonic-gate 	char *pageio_ok_fss[] = {"ufs", "nfs", NULL};
22547c478bd9Sstevel@tonic-gate 	char **fsok = pageio_ok_fss;
22557c478bd9Sstevel@tonic-gate 
22567c478bd9Sstevel@tonic-gate 	if (fsname == NULL) {
22577c478bd9Sstevel@tonic-gate 		return (0);
22587c478bd9Sstevel@tonic-gate 	}
22597c478bd9Sstevel@tonic-gate 
22607c478bd9Sstevel@tonic-gate 	for (; *fsok; fsok++) {
22617c478bd9Sstevel@tonic-gate 		if (strcmp(*fsok, fsname) == 0) {
22627c478bd9Sstevel@tonic-gate 			return (1);
22637c478bd9Sstevel@tonic-gate 		}
22647c478bd9Sstevel@tonic-gate 	}
22657c478bd9Sstevel@tonic-gate 	return (0);
22667c478bd9Sstevel@tonic-gate }
22677c478bd9Sstevel@tonic-gate 
22687c478bd9Sstevel@tonic-gate /* VOP_XXX() macros call the corresponding fop_xxx() function */
22697c478bd9Sstevel@tonic-gate 
22707c478bd9Sstevel@tonic-gate int
22717c478bd9Sstevel@tonic-gate fop_open(
22727c478bd9Sstevel@tonic-gate 	vnode_t **vpp,
22737c478bd9Sstevel@tonic-gate 	int mode,
22747c478bd9Sstevel@tonic-gate 	cred_t *cr)
22757c478bd9Sstevel@tonic-gate {
22767c478bd9Sstevel@tonic-gate 	int ret;
22777c478bd9Sstevel@tonic-gate 	vnode_t *vp = *vpp;
22787c478bd9Sstevel@tonic-gate 
22797c478bd9Sstevel@tonic-gate 	VN_HOLD(vp);
22807c478bd9Sstevel@tonic-gate 	/*
22817c478bd9Sstevel@tonic-gate 	 * Adding to the vnode counts before calling open
22827c478bd9Sstevel@tonic-gate 	 * avoids the need for a mutex. It circumvents a race
22837c478bd9Sstevel@tonic-gate 	 * condition where a query made on the vnode counts results in a
22847c478bd9Sstevel@tonic-gate 	 * false negative. The inquirer goes away believing the file is
22857c478bd9Sstevel@tonic-gate 	 * not open when there is an open on the file already under way.
22867c478bd9Sstevel@tonic-gate 	 *
22877c478bd9Sstevel@tonic-gate 	 * The counts are meant to prevent NFS from granting a delegation
22887c478bd9Sstevel@tonic-gate 	 * when it would be dangerous to do so.
22897c478bd9Sstevel@tonic-gate 	 *
22907c478bd9Sstevel@tonic-gate 	 * The vnode counts are only kept on regular files
22917c478bd9Sstevel@tonic-gate 	 */
22927c478bd9Sstevel@tonic-gate 	if ((*vpp)->v_type == VREG) {
22937c478bd9Sstevel@tonic-gate 		if (mode & FREAD)
22947c478bd9Sstevel@tonic-gate 			atomic_add_32(&((*vpp)->v_rdcnt), 1);
22957c478bd9Sstevel@tonic-gate 		if (mode & FWRITE)
22967c478bd9Sstevel@tonic-gate 			atomic_add_32(&((*vpp)->v_wrcnt), 1);
22977c478bd9Sstevel@tonic-gate 	}
22987c478bd9Sstevel@tonic-gate 
22997c478bd9Sstevel@tonic-gate 	ret = (*(*(vpp))->v_op->vop_open)(vpp, mode, cr);
23007c478bd9Sstevel@tonic-gate 
23017c478bd9Sstevel@tonic-gate 	if (ret) {
23027c478bd9Sstevel@tonic-gate 		/*
23037c478bd9Sstevel@tonic-gate 		 * Use the saved vp just in case the vnode ptr got trashed
23047c478bd9Sstevel@tonic-gate 		 * by the error.
23057c478bd9Sstevel@tonic-gate 		 */
23067c478bd9Sstevel@tonic-gate 		if ((vp->v_type == VREG) && (mode & FREAD))
23077c478bd9Sstevel@tonic-gate 			atomic_add_32(&(vp->v_rdcnt), -1);
23087c478bd9Sstevel@tonic-gate 		if ((vp->v_type == VREG) && (mode & FWRITE))
23097c478bd9Sstevel@tonic-gate 			atomic_add_32(&(vp->v_wrcnt), -1);
23107c478bd9Sstevel@tonic-gate 	} else {
23117c478bd9Sstevel@tonic-gate 		/*
23127c478bd9Sstevel@tonic-gate 		 * Some filesystems will return a different vnode,
23137c478bd9Sstevel@tonic-gate 		 * but the same path was still used to open it.
23147c478bd9Sstevel@tonic-gate 		 * So if we do change the vnode and need to
23157c478bd9Sstevel@tonic-gate 		 * copy over the path, do so here, rather than special
23167c478bd9Sstevel@tonic-gate 		 * casing each filesystem. Adjust the vnode counts to
23177c478bd9Sstevel@tonic-gate 		 * reflect the vnode switch.
23187c478bd9Sstevel@tonic-gate 		 */
23197c478bd9Sstevel@tonic-gate 
23207c478bd9Sstevel@tonic-gate 		if (*vpp != vp && *vpp != NULL) {
23217c478bd9Sstevel@tonic-gate 			vn_copypath(vp, *vpp);
23227c478bd9Sstevel@tonic-gate 			if (((*vpp)->v_type == VREG) && (mode & FREAD))
23237c478bd9Sstevel@tonic-gate 				atomic_add_32(&((*vpp)->v_rdcnt), 1);
23247c478bd9Sstevel@tonic-gate 			if ((vp->v_type == VREG) && (mode & FREAD))
23257c478bd9Sstevel@tonic-gate 				atomic_add_32(&(vp->v_rdcnt), -1);
23267c478bd9Sstevel@tonic-gate 			if (((*vpp)->v_type == VREG) && (mode & FWRITE))
23277c478bd9Sstevel@tonic-gate 				atomic_add_32(&((*vpp)->v_wrcnt), 1);
23287c478bd9Sstevel@tonic-gate 			if ((vp->v_type == VREG) && (mode & FWRITE))
23297c478bd9Sstevel@tonic-gate 				atomic_add_32(&(vp->v_wrcnt), -1);
23307c478bd9Sstevel@tonic-gate 		}
23317c478bd9Sstevel@tonic-gate 	}
23327c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
23337c478bd9Sstevel@tonic-gate 	return (ret);
23347c478bd9Sstevel@tonic-gate }
23357c478bd9Sstevel@tonic-gate 
23367c478bd9Sstevel@tonic-gate int
23377c478bd9Sstevel@tonic-gate fop_close(
23387c478bd9Sstevel@tonic-gate 	vnode_t *vp,
23397c478bd9Sstevel@tonic-gate 	int flag,
23407c478bd9Sstevel@tonic-gate 	int count,
23417c478bd9Sstevel@tonic-gate 	offset_t offset,
23427c478bd9Sstevel@tonic-gate 	cred_t *cr)
23437c478bd9Sstevel@tonic-gate {
23447c478bd9Sstevel@tonic-gate 	int error;
23457c478bd9Sstevel@tonic-gate 	error = (*(vp)->v_op->vop_close)(vp, flag, count, offset, cr);
23467c478bd9Sstevel@tonic-gate 	/*
23477c478bd9Sstevel@tonic-gate 	 * Check passed in count to handle possible dups. Vnode counts are only
23487c478bd9Sstevel@tonic-gate 	 * kept on regular files
23497c478bd9Sstevel@tonic-gate 	 */
23507c478bd9Sstevel@tonic-gate 	if ((vp->v_type == VREG) && (count == 1))  {
23517c478bd9Sstevel@tonic-gate 		if (flag & FREAD) {
23527c478bd9Sstevel@tonic-gate 			ASSERT(vp->v_rdcnt > 0);
23537c478bd9Sstevel@tonic-gate 			atomic_add_32(&(vp->v_rdcnt), -1);
23547c478bd9Sstevel@tonic-gate 		}
23557c478bd9Sstevel@tonic-gate 		if (flag & FWRITE) {
23567c478bd9Sstevel@tonic-gate 			ASSERT(vp->v_wrcnt > 0);
23577c478bd9Sstevel@tonic-gate 			atomic_add_32(&(vp->v_wrcnt), -1);
23587c478bd9Sstevel@tonic-gate 		}
23597c478bd9Sstevel@tonic-gate 	}
23607c478bd9Sstevel@tonic-gate 	return (error);
23617c478bd9Sstevel@tonic-gate }
23627c478bd9Sstevel@tonic-gate 
23637c478bd9Sstevel@tonic-gate int
23647c478bd9Sstevel@tonic-gate fop_read(
23657c478bd9Sstevel@tonic-gate 	vnode_t *vp,
23667c478bd9Sstevel@tonic-gate 	uio_t *uiop,
23677c478bd9Sstevel@tonic-gate 	int ioflag,
23687c478bd9Sstevel@tonic-gate 	cred_t *cr,
23697c478bd9Sstevel@tonic-gate 	struct caller_context *ct)
23707c478bd9Sstevel@tonic-gate {
23717c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_read)(vp, uiop, ioflag, cr, ct);
23727c478bd9Sstevel@tonic-gate }
23737c478bd9Sstevel@tonic-gate 
23747c478bd9Sstevel@tonic-gate int
23757c478bd9Sstevel@tonic-gate fop_write(
23767c478bd9Sstevel@tonic-gate 	vnode_t *vp,
23777c478bd9Sstevel@tonic-gate 	uio_t *uiop,
23787c478bd9Sstevel@tonic-gate 	int ioflag,
23797c478bd9Sstevel@tonic-gate 	cred_t *cr,
23807c478bd9Sstevel@tonic-gate 	struct caller_context *ct)
23817c478bd9Sstevel@tonic-gate {
23827c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_write)(vp, uiop, ioflag, cr, ct);
23837c478bd9Sstevel@tonic-gate }
23847c478bd9Sstevel@tonic-gate 
23857c478bd9Sstevel@tonic-gate int
23867c478bd9Sstevel@tonic-gate fop_ioctl(
23877c478bd9Sstevel@tonic-gate 	vnode_t *vp,
23887c478bd9Sstevel@tonic-gate 	int cmd,
23897c478bd9Sstevel@tonic-gate 	intptr_t arg,
23907c478bd9Sstevel@tonic-gate 	int flag,
23917c478bd9Sstevel@tonic-gate 	cred_t *cr,
23927c478bd9Sstevel@tonic-gate 	int *rvalp)
23937c478bd9Sstevel@tonic-gate {
23947c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_ioctl)(vp, cmd, arg, flag, cr, rvalp);
23957c478bd9Sstevel@tonic-gate }
23967c478bd9Sstevel@tonic-gate 
23977c478bd9Sstevel@tonic-gate int
23987c478bd9Sstevel@tonic-gate fop_setfl(
23997c478bd9Sstevel@tonic-gate 	vnode_t *vp,
24007c478bd9Sstevel@tonic-gate 	int oflags,
24017c478bd9Sstevel@tonic-gate 	int nflags,
24027c478bd9Sstevel@tonic-gate 	cred_t *cr)
24037c478bd9Sstevel@tonic-gate {
24047c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_setfl)(vp, oflags, nflags, cr);
24057c478bd9Sstevel@tonic-gate }
24067c478bd9Sstevel@tonic-gate 
24077c478bd9Sstevel@tonic-gate int
24087c478bd9Sstevel@tonic-gate fop_getattr(
24097c478bd9Sstevel@tonic-gate 	vnode_t *vp,
24107c478bd9Sstevel@tonic-gate 	vattr_t *vap,
24117c478bd9Sstevel@tonic-gate 	int flags,
24127c478bd9Sstevel@tonic-gate 	cred_t *cr)
24137c478bd9Sstevel@tonic-gate {
24147c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_getattr)(vp, vap, flags, cr);
24157c478bd9Sstevel@tonic-gate }
24167c478bd9Sstevel@tonic-gate 
24177c478bd9Sstevel@tonic-gate int
24187c478bd9Sstevel@tonic-gate fop_setattr(
24197c478bd9Sstevel@tonic-gate 	vnode_t *vp,
24207c478bd9Sstevel@tonic-gate 	vattr_t *vap,
24217c478bd9Sstevel@tonic-gate 	int flags,
24227c478bd9Sstevel@tonic-gate 	cred_t *cr,
24237c478bd9Sstevel@tonic-gate 	caller_context_t *ct)
24247c478bd9Sstevel@tonic-gate {
24257c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_setattr)(vp, vap, flags, cr, ct);
24267c478bd9Sstevel@tonic-gate }
24277c478bd9Sstevel@tonic-gate 
24287c478bd9Sstevel@tonic-gate int
24297c478bd9Sstevel@tonic-gate fop_access(
24307c478bd9Sstevel@tonic-gate 	vnode_t *vp,
24317c478bd9Sstevel@tonic-gate 	int mode,
24327c478bd9Sstevel@tonic-gate 	int flags,
24337c478bd9Sstevel@tonic-gate 	cred_t *cr)
24347c478bd9Sstevel@tonic-gate {
24357c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_access)(vp, mode, flags, cr);
24367c478bd9Sstevel@tonic-gate }
24377c478bd9Sstevel@tonic-gate 
24387c478bd9Sstevel@tonic-gate int
24397c478bd9Sstevel@tonic-gate fop_lookup(
24407c478bd9Sstevel@tonic-gate 	vnode_t *dvp,
24417c478bd9Sstevel@tonic-gate 	char *nm,
24427c478bd9Sstevel@tonic-gate 	vnode_t **vpp,
24437c478bd9Sstevel@tonic-gate 	pathname_t *pnp,
24447c478bd9Sstevel@tonic-gate 	int flags,
24457c478bd9Sstevel@tonic-gate 	vnode_t *rdir,
24467c478bd9Sstevel@tonic-gate 	cred_t *cr)
24477c478bd9Sstevel@tonic-gate {
2448*ca2c3138Seschrock 	int ret;
2449*ca2c3138Seschrock 
2450*ca2c3138Seschrock 	ret = (*(dvp)->v_op->vop_lookup)(dvp, nm, vpp, pnp, flags, rdir, cr);
2451*ca2c3138Seschrock 	if (ret == 0 && *vpp && (*vpp)->v_path == NULL)
2452*ca2c3138Seschrock 		vn_setpath(rootdir, dvp, *vpp, nm, strlen(nm));
2453*ca2c3138Seschrock 
2454*ca2c3138Seschrock 	return (ret);
24557c478bd9Sstevel@tonic-gate }
24567c478bd9Sstevel@tonic-gate 
24577c478bd9Sstevel@tonic-gate int
24587c478bd9Sstevel@tonic-gate fop_create(
24597c478bd9Sstevel@tonic-gate 	vnode_t *dvp,
24607c478bd9Sstevel@tonic-gate 	char *name,
24617c478bd9Sstevel@tonic-gate 	vattr_t *vap,
24627c478bd9Sstevel@tonic-gate 	vcexcl_t excl,
24637c478bd9Sstevel@tonic-gate 	int mode,
24647c478bd9Sstevel@tonic-gate 	vnode_t **vpp,
24657c478bd9Sstevel@tonic-gate 	cred_t *cr,
24667c478bd9Sstevel@tonic-gate 	int flag)
24677c478bd9Sstevel@tonic-gate {
24687c478bd9Sstevel@tonic-gate 	int ret;
24697c478bd9Sstevel@tonic-gate 
24707c478bd9Sstevel@tonic-gate 	ret = (*(dvp)->v_op->vop_create)
24717c478bd9Sstevel@tonic-gate 				(dvp, name, vap, excl, mode, vpp, cr, flag);
2472*ca2c3138Seschrock 	if (ret == 0 && *vpp && (*vpp)->v_path == NULL)
2473*ca2c3138Seschrock 		vn_setpath(rootdir, dvp, *vpp, name, strlen(name));
24747c478bd9Sstevel@tonic-gate 
24757c478bd9Sstevel@tonic-gate 	return (ret);
24767c478bd9Sstevel@tonic-gate }
24777c478bd9Sstevel@tonic-gate 
24787c478bd9Sstevel@tonic-gate int
24797c478bd9Sstevel@tonic-gate fop_remove(
24807c478bd9Sstevel@tonic-gate 	vnode_t *dvp,
24817c478bd9Sstevel@tonic-gate 	char *nm,
24827c478bd9Sstevel@tonic-gate 	cred_t *cr)
24837c478bd9Sstevel@tonic-gate {
24847c478bd9Sstevel@tonic-gate 	return (*(dvp)->v_op->vop_remove)(dvp, nm, cr);
24857c478bd9Sstevel@tonic-gate }
24867c478bd9Sstevel@tonic-gate 
24877c478bd9Sstevel@tonic-gate int
24887c478bd9Sstevel@tonic-gate fop_link(
24897c478bd9Sstevel@tonic-gate 	vnode_t *tdvp,
24907c478bd9Sstevel@tonic-gate 	vnode_t *svp,
24917c478bd9Sstevel@tonic-gate 	char *tnm,
24927c478bd9Sstevel@tonic-gate 	cred_t *cr)
24937c478bd9Sstevel@tonic-gate {
24947c478bd9Sstevel@tonic-gate 	return (*(tdvp)->v_op->vop_link)(tdvp, svp, tnm, cr);
24957c478bd9Sstevel@tonic-gate }
24967c478bd9Sstevel@tonic-gate 
24977c478bd9Sstevel@tonic-gate int
24987c478bd9Sstevel@tonic-gate fop_rename(
24997c478bd9Sstevel@tonic-gate 	vnode_t *sdvp,
25007c478bd9Sstevel@tonic-gate 	char *snm,
25017c478bd9Sstevel@tonic-gate 	vnode_t *tdvp,
25027c478bd9Sstevel@tonic-gate 	char *tnm,
25037c478bd9Sstevel@tonic-gate 	cred_t *cr)
25047c478bd9Sstevel@tonic-gate {
25057c478bd9Sstevel@tonic-gate 	return (*(sdvp)->v_op->vop_rename)(sdvp, snm, tdvp, tnm, cr);
25067c478bd9Sstevel@tonic-gate }
25077c478bd9Sstevel@tonic-gate 
25087c478bd9Sstevel@tonic-gate int
25097c478bd9Sstevel@tonic-gate fop_mkdir(
25107c478bd9Sstevel@tonic-gate 	vnode_t *dvp,
25117c478bd9Sstevel@tonic-gate 	char *dirname,
25127c478bd9Sstevel@tonic-gate 	vattr_t *vap,
25137c478bd9Sstevel@tonic-gate 	vnode_t **vpp,
25147c478bd9Sstevel@tonic-gate 	cred_t *cr)
25157c478bd9Sstevel@tonic-gate {
25167c478bd9Sstevel@tonic-gate 	int ret;
25177c478bd9Sstevel@tonic-gate 
25187c478bd9Sstevel@tonic-gate 	ret = (*(dvp)->v_op->vop_mkdir)(dvp, dirname, vap, vpp, cr);
2519*ca2c3138Seschrock 	if (ret == 0 && *vpp && (*vpp)->v_path == NULL)
2520*ca2c3138Seschrock 		vn_setpath(rootdir, dvp, *vpp, dirname, strlen(dirname));
25217c478bd9Sstevel@tonic-gate 
25227c478bd9Sstevel@tonic-gate 	return (ret);
25237c478bd9Sstevel@tonic-gate }
25247c478bd9Sstevel@tonic-gate 
25257c478bd9Sstevel@tonic-gate int
25267c478bd9Sstevel@tonic-gate fop_rmdir(
25277c478bd9Sstevel@tonic-gate 	vnode_t *dvp,
25287c478bd9Sstevel@tonic-gate 	char *nm,
25297c478bd9Sstevel@tonic-gate 	vnode_t *cdir,
25307c478bd9Sstevel@tonic-gate 	cred_t *cr)
25317c478bd9Sstevel@tonic-gate {
25327c478bd9Sstevel@tonic-gate 	return (*(dvp)->v_op->vop_rmdir)(dvp, nm, cdir, cr);
25337c478bd9Sstevel@tonic-gate }
25347c478bd9Sstevel@tonic-gate 
25357c478bd9Sstevel@tonic-gate int
25367c478bd9Sstevel@tonic-gate fop_readdir(
25377c478bd9Sstevel@tonic-gate 	vnode_t *vp,
25387c478bd9Sstevel@tonic-gate 	uio_t *uiop,
25397c478bd9Sstevel@tonic-gate 	cred_t *cr,
25407c478bd9Sstevel@tonic-gate 	int *eofp)
25417c478bd9Sstevel@tonic-gate {
25427c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_readdir)(vp, uiop, cr, eofp);
25437c478bd9Sstevel@tonic-gate }
25447c478bd9Sstevel@tonic-gate 
25457c478bd9Sstevel@tonic-gate int
25467c478bd9Sstevel@tonic-gate fop_symlink(
25477c478bd9Sstevel@tonic-gate 	vnode_t *dvp,
25487c478bd9Sstevel@tonic-gate 	char *linkname,
25497c478bd9Sstevel@tonic-gate 	vattr_t *vap,
25507c478bd9Sstevel@tonic-gate 	char *target,
25517c478bd9Sstevel@tonic-gate 	cred_t *cr)
25527c478bd9Sstevel@tonic-gate {
25537c478bd9Sstevel@tonic-gate 	return (*(dvp)->v_op->vop_symlink) (dvp, linkname, vap, target, cr);
25547c478bd9Sstevel@tonic-gate }
25557c478bd9Sstevel@tonic-gate 
25567c478bd9Sstevel@tonic-gate int
25577c478bd9Sstevel@tonic-gate fop_readlink(
25587c478bd9Sstevel@tonic-gate 	vnode_t *vp,
25597c478bd9Sstevel@tonic-gate 	uio_t *uiop,
25607c478bd9Sstevel@tonic-gate 	cred_t *cr)
25617c478bd9Sstevel@tonic-gate {
25627c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_readlink)(vp, uiop, cr);
25637c478bd9Sstevel@tonic-gate }
25647c478bd9Sstevel@tonic-gate 
25657c478bd9Sstevel@tonic-gate int
25667c478bd9Sstevel@tonic-gate fop_fsync(
25677c478bd9Sstevel@tonic-gate 	vnode_t *vp,
25687c478bd9Sstevel@tonic-gate 	int syncflag,
25697c478bd9Sstevel@tonic-gate 	cred_t *cr)
25707c478bd9Sstevel@tonic-gate {
25717c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_fsync)(vp, syncflag, cr);
25727c478bd9Sstevel@tonic-gate }
25737c478bd9Sstevel@tonic-gate 
25747c478bd9Sstevel@tonic-gate void
25757c478bd9Sstevel@tonic-gate fop_inactive(
25767c478bd9Sstevel@tonic-gate 	vnode_t *vp,
25777c478bd9Sstevel@tonic-gate 	cred_t *cr)
25787c478bd9Sstevel@tonic-gate {
25797c478bd9Sstevel@tonic-gate 	(*(vp)->v_op->vop_inactive)(vp, cr);
25807c478bd9Sstevel@tonic-gate }
25817c478bd9Sstevel@tonic-gate 
25827c478bd9Sstevel@tonic-gate int
25837c478bd9Sstevel@tonic-gate fop_fid(
25847c478bd9Sstevel@tonic-gate 	vnode_t *vp,
25857c478bd9Sstevel@tonic-gate 	fid_t *fidp)
25867c478bd9Sstevel@tonic-gate {
25877c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_fid)(vp, fidp);
25887c478bd9Sstevel@tonic-gate }
25897c478bd9Sstevel@tonic-gate 
25907c478bd9Sstevel@tonic-gate int
25917c478bd9Sstevel@tonic-gate fop_rwlock(
25927c478bd9Sstevel@tonic-gate 	vnode_t *vp,
25937c478bd9Sstevel@tonic-gate 	int write_lock,
25947c478bd9Sstevel@tonic-gate 	caller_context_t *ct)
25957c478bd9Sstevel@tonic-gate {
25967c478bd9Sstevel@tonic-gate 	return ((*(vp)->v_op->vop_rwlock)(vp, write_lock, ct));
25977c478bd9Sstevel@tonic-gate }
25987c478bd9Sstevel@tonic-gate 
25997c478bd9Sstevel@tonic-gate void
26007c478bd9Sstevel@tonic-gate fop_rwunlock(
26017c478bd9Sstevel@tonic-gate 	vnode_t *vp,
26027c478bd9Sstevel@tonic-gate 	int write_lock,
26037c478bd9Sstevel@tonic-gate 	caller_context_t *ct)
26047c478bd9Sstevel@tonic-gate {
26057c478bd9Sstevel@tonic-gate 	(*(vp)->v_op->vop_rwunlock)(vp, write_lock, ct);
26067c478bd9Sstevel@tonic-gate }
26077c478bd9Sstevel@tonic-gate 
26087c478bd9Sstevel@tonic-gate int
26097c478bd9Sstevel@tonic-gate fop_seek(
26107c478bd9Sstevel@tonic-gate 	vnode_t *vp,
26117c478bd9Sstevel@tonic-gate 	offset_t ooff,
26127c478bd9Sstevel@tonic-gate 	offset_t *noffp)
26137c478bd9Sstevel@tonic-gate {
26147c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_seek)(vp, ooff, noffp);
26157c478bd9Sstevel@tonic-gate }
26167c478bd9Sstevel@tonic-gate 
26177c478bd9Sstevel@tonic-gate int
26187c478bd9Sstevel@tonic-gate fop_cmp(
26197c478bd9Sstevel@tonic-gate 	vnode_t *vp1,
26207c478bd9Sstevel@tonic-gate 	vnode_t *vp2)
26217c478bd9Sstevel@tonic-gate {
26227c478bd9Sstevel@tonic-gate 	return (*(vp1)->v_op->vop_cmp)(vp1, vp2);
26237c478bd9Sstevel@tonic-gate }
26247c478bd9Sstevel@tonic-gate 
26257c478bd9Sstevel@tonic-gate int
26267c478bd9Sstevel@tonic-gate fop_frlock(
26277c478bd9Sstevel@tonic-gate 	vnode_t *vp,
26287c478bd9Sstevel@tonic-gate 	int cmd,
26297c478bd9Sstevel@tonic-gate 	flock64_t *bfp,
26307c478bd9Sstevel@tonic-gate 	int flag,
26317c478bd9Sstevel@tonic-gate 	offset_t offset,
26327c478bd9Sstevel@tonic-gate 	struct flk_callback *flk_cbp,
26337c478bd9Sstevel@tonic-gate 	cred_t *cr)
26347c478bd9Sstevel@tonic-gate {
26357c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_frlock)
26367c478bd9Sstevel@tonic-gate 				(vp, cmd, bfp, flag, offset, flk_cbp, cr);
26377c478bd9Sstevel@tonic-gate }
26387c478bd9Sstevel@tonic-gate 
26397c478bd9Sstevel@tonic-gate int
26407c478bd9Sstevel@tonic-gate fop_space(
26417c478bd9Sstevel@tonic-gate 	vnode_t *vp,
26427c478bd9Sstevel@tonic-gate 	int cmd,
26437c478bd9Sstevel@tonic-gate 	flock64_t *bfp,
26447c478bd9Sstevel@tonic-gate 	int flag,
26457c478bd9Sstevel@tonic-gate 	offset_t offset,
26467c478bd9Sstevel@tonic-gate 	cred_t *cr,
26477c478bd9Sstevel@tonic-gate 	caller_context_t *ct)
26487c478bd9Sstevel@tonic-gate {
26497c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_space)(vp, cmd, bfp, flag, offset, cr, ct);
26507c478bd9Sstevel@tonic-gate }
26517c478bd9Sstevel@tonic-gate 
26527c478bd9Sstevel@tonic-gate int
26537c478bd9Sstevel@tonic-gate fop_realvp(
26547c478bd9Sstevel@tonic-gate 	vnode_t *vp,
26557c478bd9Sstevel@tonic-gate 	vnode_t **vpp)
26567c478bd9Sstevel@tonic-gate {
26577c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_realvp)(vp, vpp);
26587c478bd9Sstevel@tonic-gate }
26597c478bd9Sstevel@tonic-gate 
26607c478bd9Sstevel@tonic-gate int
26617c478bd9Sstevel@tonic-gate fop_getpage(
26627c478bd9Sstevel@tonic-gate 	vnode_t *vp,
26637c478bd9Sstevel@tonic-gate 	offset_t off,
26647c478bd9Sstevel@tonic-gate 	size_t len,
26657c478bd9Sstevel@tonic-gate 	uint_t *protp,
26667c478bd9Sstevel@tonic-gate 	page_t **plarr,
26677c478bd9Sstevel@tonic-gate 	size_t plsz,
26687c478bd9Sstevel@tonic-gate 	struct seg *seg,
26697c478bd9Sstevel@tonic-gate 	caddr_t addr,
26707c478bd9Sstevel@tonic-gate 	enum seg_rw rw,
26717c478bd9Sstevel@tonic-gate 	cred_t *cr)
26727c478bd9Sstevel@tonic-gate {
26737c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_getpage)
26747c478bd9Sstevel@tonic-gate 			(vp, off, len, protp, plarr, plsz, seg, addr, rw, cr);
26757c478bd9Sstevel@tonic-gate }
26767c478bd9Sstevel@tonic-gate 
26777c478bd9Sstevel@tonic-gate int
26787c478bd9Sstevel@tonic-gate fop_putpage(
26797c478bd9Sstevel@tonic-gate 	vnode_t *vp,
26807c478bd9Sstevel@tonic-gate 	offset_t off,
26817c478bd9Sstevel@tonic-gate 	size_t len,
26827c478bd9Sstevel@tonic-gate 	int flags,
26837c478bd9Sstevel@tonic-gate 	cred_t *cr)
26847c478bd9Sstevel@tonic-gate {
26857c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_putpage)(vp, off, len, flags, cr);
26867c478bd9Sstevel@tonic-gate }
26877c478bd9Sstevel@tonic-gate 
26887c478bd9Sstevel@tonic-gate int
26897c478bd9Sstevel@tonic-gate fop_map(
26907c478bd9Sstevel@tonic-gate 	vnode_t *vp,
26917c478bd9Sstevel@tonic-gate 	offset_t off,
26927c478bd9Sstevel@tonic-gate 	struct as *as,
26937c478bd9Sstevel@tonic-gate 	caddr_t *addrp,
26947c478bd9Sstevel@tonic-gate 	size_t len,
26957c478bd9Sstevel@tonic-gate 	uchar_t prot,
26967c478bd9Sstevel@tonic-gate 	uchar_t maxprot,
26977c478bd9Sstevel@tonic-gate 	uint_t flags,
26987c478bd9Sstevel@tonic-gate 	cred_t *cr)
26997c478bd9Sstevel@tonic-gate {
27007c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_map)
27017c478bd9Sstevel@tonic-gate 			(vp, off, as, addrp, len, prot, maxprot, flags, cr);
27027c478bd9Sstevel@tonic-gate }
27037c478bd9Sstevel@tonic-gate 
27047c478bd9Sstevel@tonic-gate int
27057c478bd9Sstevel@tonic-gate fop_addmap(
27067c478bd9Sstevel@tonic-gate 	vnode_t *vp,
27077c478bd9Sstevel@tonic-gate 	offset_t off,
27087c478bd9Sstevel@tonic-gate 	struct as *as,
27097c478bd9Sstevel@tonic-gate 	caddr_t addr,
27107c478bd9Sstevel@tonic-gate 	size_t len,
27117c478bd9Sstevel@tonic-gate 	uchar_t prot,
27127c478bd9Sstevel@tonic-gate 	uchar_t maxprot,
27137c478bd9Sstevel@tonic-gate 	uint_t flags,
27147c478bd9Sstevel@tonic-gate 	cred_t *cr)
27157c478bd9Sstevel@tonic-gate {
27167c478bd9Sstevel@tonic-gate 	int error;
27177c478bd9Sstevel@tonic-gate 	u_longlong_t delta;
27187c478bd9Sstevel@tonic-gate 
27197c478bd9Sstevel@tonic-gate 	error = (*(vp)->v_op->vop_addmap)
27207c478bd9Sstevel@tonic-gate 			(vp, off, as, addr, len, prot, maxprot, flags, cr);
27217c478bd9Sstevel@tonic-gate 
27227c478bd9Sstevel@tonic-gate 	if ((!error) && (vp->v_type == VREG)) {
27237c478bd9Sstevel@tonic-gate 		delta = (u_longlong_t)btopr(len);
27247c478bd9Sstevel@tonic-gate 		/*
27257c478bd9Sstevel@tonic-gate 		 * If file is declared MAP_PRIVATE, it can't be written back
27267c478bd9Sstevel@tonic-gate 		 * even if open for write. Handle as read.
27277c478bd9Sstevel@tonic-gate 		 */
27287c478bd9Sstevel@tonic-gate 		if (flags & MAP_PRIVATE) {
27297c478bd9Sstevel@tonic-gate 			atomic_add_64((uint64_t *)(&(vp->v_mmap_read)),
27307c478bd9Sstevel@tonic-gate 				(int64_t)delta);
27317c478bd9Sstevel@tonic-gate 		} else {
27327c478bd9Sstevel@tonic-gate 			/*
27337c478bd9Sstevel@tonic-gate 			 * atomic_add_64 forces the fetch of a 64 bit value to
27347c478bd9Sstevel@tonic-gate 			 * be atomic on 32 bit machines
27357c478bd9Sstevel@tonic-gate 			 */
27367c478bd9Sstevel@tonic-gate 			if (maxprot & PROT_WRITE)
27377c478bd9Sstevel@tonic-gate 				atomic_add_64((uint64_t *)(&(vp->v_mmap_write)),
27387c478bd9Sstevel@tonic-gate 					(int64_t)delta);
27397c478bd9Sstevel@tonic-gate 			if (maxprot & PROT_READ)
27407c478bd9Sstevel@tonic-gate 				atomic_add_64((uint64_t *)(&(vp->v_mmap_read)),
27417c478bd9Sstevel@tonic-gate 					(int64_t)delta);
27427c478bd9Sstevel@tonic-gate 			if (maxprot & PROT_EXEC)
27437c478bd9Sstevel@tonic-gate 				atomic_add_64((uint64_t *)(&(vp->v_mmap_read)),
27447c478bd9Sstevel@tonic-gate 					(int64_t)delta);
27457c478bd9Sstevel@tonic-gate 		}
27467c478bd9Sstevel@tonic-gate 	}
27477c478bd9Sstevel@tonic-gate 	return (error);
27487c478bd9Sstevel@tonic-gate }
27497c478bd9Sstevel@tonic-gate 
27507c478bd9Sstevel@tonic-gate int
27517c478bd9Sstevel@tonic-gate fop_delmap(
27527c478bd9Sstevel@tonic-gate 	vnode_t *vp,
27537c478bd9Sstevel@tonic-gate 	offset_t off,
27547c478bd9Sstevel@tonic-gate 	struct as *as,
27557c478bd9Sstevel@tonic-gate 	caddr_t addr,
27567c478bd9Sstevel@tonic-gate 	size_t len,
27577c478bd9Sstevel@tonic-gate 	uint_t prot,
27587c478bd9Sstevel@tonic-gate 	uint_t maxprot,
27597c478bd9Sstevel@tonic-gate 	uint_t flags,
27607c478bd9Sstevel@tonic-gate 	cred_t *cr)
27617c478bd9Sstevel@tonic-gate {
27627c478bd9Sstevel@tonic-gate 	int error;
27637c478bd9Sstevel@tonic-gate 	u_longlong_t delta;
27647c478bd9Sstevel@tonic-gate 	error = (*(vp)->v_op->vop_delmap)
27657c478bd9Sstevel@tonic-gate 		(vp, off, as, addr, len, prot, maxprot, flags, cr);
27667c478bd9Sstevel@tonic-gate 
27677c478bd9Sstevel@tonic-gate 	/*
27687c478bd9Sstevel@tonic-gate 	 * NFS calls into delmap twice, the first time
27697c478bd9Sstevel@tonic-gate 	 * it simply establishes a callback mechanism and returns EAGAIN
27707c478bd9Sstevel@tonic-gate 	 * while the real work is being done upon the second invocation.
27717c478bd9Sstevel@tonic-gate 	 * We have to detect this here and only decrement the counts upon
27727c478bd9Sstevel@tonic-gate 	 * the second delmap request.
27737c478bd9Sstevel@tonic-gate 	 */
27747c478bd9Sstevel@tonic-gate 	if ((error != EAGAIN) && (vp->v_type == VREG)) {
27757c478bd9Sstevel@tonic-gate 
27767c478bd9Sstevel@tonic-gate 		delta = (u_longlong_t)btopr(len);
27777c478bd9Sstevel@tonic-gate 
27787c478bd9Sstevel@tonic-gate 		if (flags & MAP_PRIVATE) {
27797c478bd9Sstevel@tonic-gate 			atomic_add_64((uint64_t *)(&(vp->v_mmap_read)),
27807c478bd9Sstevel@tonic-gate 				(int64_t)(-delta));
27817c478bd9Sstevel@tonic-gate 		} else {
27827c478bd9Sstevel@tonic-gate 			/*
27837c478bd9Sstevel@tonic-gate 			 * atomic_add_64 forces the fetch of a 64 bit value
27847c478bd9Sstevel@tonic-gate 			 * to be atomic on 32 bit machines
27857c478bd9Sstevel@tonic-gate 			 */
27867c478bd9Sstevel@tonic-gate 			if (maxprot & PROT_WRITE)
27877c478bd9Sstevel@tonic-gate 				atomic_add_64((uint64_t *)(&(vp->v_mmap_write)),
27887c478bd9Sstevel@tonic-gate 					(int64_t)(-delta));
27897c478bd9Sstevel@tonic-gate 			if (maxprot & PROT_READ)
27907c478bd9Sstevel@tonic-gate 				atomic_add_64((uint64_t *)(&(vp->v_mmap_read)),
27917c478bd9Sstevel@tonic-gate 					(int64_t)(-delta));
27927c478bd9Sstevel@tonic-gate 			if (maxprot & PROT_EXEC)
27937c478bd9Sstevel@tonic-gate 				atomic_add_64((uint64_t *)(&(vp->v_mmap_read)),
27947c478bd9Sstevel@tonic-gate 					(int64_t)(-delta));
27957c478bd9Sstevel@tonic-gate 		}
27967c478bd9Sstevel@tonic-gate 	}
27977c478bd9Sstevel@tonic-gate 	return (error);
27987c478bd9Sstevel@tonic-gate }
27997c478bd9Sstevel@tonic-gate 
28007c478bd9Sstevel@tonic-gate 
28017c478bd9Sstevel@tonic-gate int
28027c478bd9Sstevel@tonic-gate fop_poll(
28037c478bd9Sstevel@tonic-gate 	vnode_t *vp,
28047c478bd9Sstevel@tonic-gate 	short events,
28057c478bd9Sstevel@tonic-gate 	int anyyet,
28067c478bd9Sstevel@tonic-gate 	short *reventsp,
28077c478bd9Sstevel@tonic-gate 	struct pollhead **phpp)
28087c478bd9Sstevel@tonic-gate {
28097c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_poll)(vp, events, anyyet, reventsp, phpp);
28107c478bd9Sstevel@tonic-gate }
28117c478bd9Sstevel@tonic-gate 
28127c478bd9Sstevel@tonic-gate int
28137c478bd9Sstevel@tonic-gate fop_dump(
28147c478bd9Sstevel@tonic-gate 	vnode_t *vp,
28157c478bd9Sstevel@tonic-gate 	caddr_t addr,
28167c478bd9Sstevel@tonic-gate 	int lbdn,
28177c478bd9Sstevel@tonic-gate 	int dblks)
28187c478bd9Sstevel@tonic-gate {
28197c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_dump)(vp, addr, lbdn, dblks);
28207c478bd9Sstevel@tonic-gate }
28217c478bd9Sstevel@tonic-gate 
28227c478bd9Sstevel@tonic-gate int
28237c478bd9Sstevel@tonic-gate fop_pathconf(
28247c478bd9Sstevel@tonic-gate 	vnode_t *vp,
28257c478bd9Sstevel@tonic-gate 	int cmd,
28267c478bd9Sstevel@tonic-gate 	ulong_t *valp,
28277c478bd9Sstevel@tonic-gate 	cred_t *cr)
28287c478bd9Sstevel@tonic-gate {
28297c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_pathconf)(vp, cmd, valp, cr);
28307c478bd9Sstevel@tonic-gate }
28317c478bd9Sstevel@tonic-gate 
28327c478bd9Sstevel@tonic-gate int
28337c478bd9Sstevel@tonic-gate fop_pageio(
28347c478bd9Sstevel@tonic-gate 	vnode_t *vp,
28357c478bd9Sstevel@tonic-gate 	struct page *pp,
28367c478bd9Sstevel@tonic-gate 	u_offset_t io_off,
28377c478bd9Sstevel@tonic-gate 	size_t io_len,
28387c478bd9Sstevel@tonic-gate 	int flags,
28397c478bd9Sstevel@tonic-gate 	cred_t *cr)
28407c478bd9Sstevel@tonic-gate {
28417c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_pageio)(vp, pp, io_off, io_len, flags, cr);
28427c478bd9Sstevel@tonic-gate }
28437c478bd9Sstevel@tonic-gate 
28447c478bd9Sstevel@tonic-gate int
28457c478bd9Sstevel@tonic-gate fop_dumpctl(
28467c478bd9Sstevel@tonic-gate 	vnode_t *vp,
28477c478bd9Sstevel@tonic-gate 	int action,
28487c478bd9Sstevel@tonic-gate 	int *blkp)
28497c478bd9Sstevel@tonic-gate {
28507c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_dumpctl)(vp, action, blkp);
28517c478bd9Sstevel@tonic-gate }
28527c478bd9Sstevel@tonic-gate 
28537c478bd9Sstevel@tonic-gate void
28547c478bd9Sstevel@tonic-gate fop_dispose(
28557c478bd9Sstevel@tonic-gate 	vnode_t *vp,
28567c478bd9Sstevel@tonic-gate 	page_t *pp,
28577c478bd9Sstevel@tonic-gate 	int flag,
28587c478bd9Sstevel@tonic-gate 	int dn,
28597c478bd9Sstevel@tonic-gate 	cred_t *cr)
28607c478bd9Sstevel@tonic-gate {
28617c478bd9Sstevel@tonic-gate 	(*(vp)->v_op->vop_dispose)(vp, pp, flag, dn, cr);
28627c478bd9Sstevel@tonic-gate }
28637c478bd9Sstevel@tonic-gate 
28647c478bd9Sstevel@tonic-gate int
28657c478bd9Sstevel@tonic-gate fop_setsecattr(
28667c478bd9Sstevel@tonic-gate 	vnode_t *vp,
28677c478bd9Sstevel@tonic-gate 	vsecattr_t *vsap,
28687c478bd9Sstevel@tonic-gate 	int flag,
28697c478bd9Sstevel@tonic-gate 	cred_t *cr)
28707c478bd9Sstevel@tonic-gate {
28717c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_setsecattr) (vp, vsap, flag, cr);
28727c478bd9Sstevel@tonic-gate }
28737c478bd9Sstevel@tonic-gate 
28747c478bd9Sstevel@tonic-gate int
28757c478bd9Sstevel@tonic-gate fop_getsecattr(
28767c478bd9Sstevel@tonic-gate 	vnode_t *vp,
28777c478bd9Sstevel@tonic-gate 	vsecattr_t *vsap,
28787c478bd9Sstevel@tonic-gate 	int flag,
28797c478bd9Sstevel@tonic-gate 	cred_t *cr)
28807c478bd9Sstevel@tonic-gate {
28817c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_getsecattr) (vp, vsap, flag, cr);
28827c478bd9Sstevel@tonic-gate }
28837c478bd9Sstevel@tonic-gate 
28847c478bd9Sstevel@tonic-gate int
28857c478bd9Sstevel@tonic-gate fop_shrlock(
28867c478bd9Sstevel@tonic-gate 	vnode_t *vp,
28877c478bd9Sstevel@tonic-gate 	int cmd,
28887c478bd9Sstevel@tonic-gate 	struct shrlock *shr,
28897c478bd9Sstevel@tonic-gate 	int flag,
28907c478bd9Sstevel@tonic-gate 	cred_t *cr)
28917c478bd9Sstevel@tonic-gate {
28927c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_shrlock)(vp, cmd, shr, flag, cr);
28937c478bd9Sstevel@tonic-gate }
28947c478bd9Sstevel@tonic-gate 
28957c478bd9Sstevel@tonic-gate int
28967c478bd9Sstevel@tonic-gate fop_vnevent(vnode_t *vp, vnevent_t vnevent)
28977c478bd9Sstevel@tonic-gate {
28987c478bd9Sstevel@tonic-gate 	return (*(vp)->v_op->vop_vnevent)(vp, vnevent);
28997c478bd9Sstevel@tonic-gate }
2900