xref: /titanic_44/usr/src/uts/common/sys/vnode.h (revision e5ba14ff435beeefdaa2e6649e175c74afe02c76)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 /*
30  * University Copyright- Copyright (c) 1982, 1986, 1988
31  * The Regents of the University of California
32  * All Rights Reserved
33  *
34  * University Acknowledgment- Portions of this document are derived from
35  * software developed by the University of California, Berkeley, and its
36  * contributors.
37  */
38 
39 #ifndef _SYS_VNODE_H
40 #define	_SYS_VNODE_H
41 
42 #pragma ident	"%Z%%M%	%I%	%E% SMI"
43 
44 #include <sys/types.h>
45 #include <sys/t_lock.h>
46 #include <sys/rwstlock.h>
47 #include <sys/time_impl.h>
48 #include <sys/cred.h>
49 #include <sys/uio.h>
50 #include <sys/resource.h>
51 #include <vm/seg_enum.h>
52 #include <sys/kstat.h>
53 #include <sys/kmem.h>
54 #include <sys/list.h>
55 #ifdef	_KERNEL
56 #include <sys/buf.h>
57 #endif	/* _KERNEL */
58 
59 #ifdef	__cplusplus
60 extern "C" {
61 #endif
62 
63 /*
64  * Statistics for all vnode operations.
65  * All operations record number of ops (since boot/mount/zero'ed).
66  * Certain I/O operations (read, write, readdir) also record number
67  * of bytes transferred.
68  * This appears in two places in the system: one is embedded in each
69  * vfs_t.  There is also an array of vopstats_t structures allocated
70  * on a per-fstype basis.
71  */
72 
73 #define	VOPSTATS_STR	"vopstats_"	/* Initial string for vopstat kstats */
74 
75 typedef struct vopstats {
76 	kstat_named_t	nopen;		/* VOP_OPEN */
77 	kstat_named_t	nclose;		/* VOP_CLOSE */
78 	kstat_named_t	nread;		/* VOP_READ */
79 	kstat_named_t	read_bytes;
80 	kstat_named_t	nwrite;		/* VOP_WRITE */
81 	kstat_named_t	write_bytes;
82 	kstat_named_t	nioctl;		/* VOP_IOCTL */
83 	kstat_named_t	nsetfl;		/* VOP_SETFL */
84 	kstat_named_t	ngetattr;	/* VOP_GETATTR */
85 	kstat_named_t	nsetattr;	/* VOP_SETATTR */
86 	kstat_named_t	naccess;	/* VOP_ACCESS */
87 	kstat_named_t	nlookup;	/* VOP_LOOKUP */
88 	kstat_named_t	ncreate;	/* VOP_CREATE */
89 	kstat_named_t	nremove;	/* VOP_REMOVE */
90 	kstat_named_t	nlink;		/* VOP_LINK */
91 	kstat_named_t	nrename;	/* VOP_RENAME */
92 	kstat_named_t	nmkdir;		/* VOP_MKDIR */
93 	kstat_named_t	nrmdir;		/* VOP_RMDIR */
94 	kstat_named_t	nreaddir;	/* VOP_READDIR */
95 	kstat_named_t	readdir_bytes;
96 	kstat_named_t	nsymlink;	/* VOP_SYMLINK */
97 	kstat_named_t	nreadlink;	/* VOP_READLINK */
98 	kstat_named_t	nfsync;		/* VOP_FSYNC */
99 	kstat_named_t	ninactive;	/* VOP_INACTIVE */
100 	kstat_named_t	nfid;		/* VOP_FID */
101 	kstat_named_t	nrwlock;	/* VOP_RWLOCK */
102 	kstat_named_t	nrwunlock;	/* VOP_RWUNLOCK */
103 	kstat_named_t	nseek;		/* VOP_SEEK */
104 	kstat_named_t	ncmp;		/* VOP_CMP */
105 	kstat_named_t	nfrlock;	/* VOP_FRLOCK */
106 	kstat_named_t	nspace;		/* VOP_SPACE */
107 	kstat_named_t	nrealvp;	/* VOP_REALVP */
108 	kstat_named_t	ngetpage;	/* VOP_GETPAGE */
109 	kstat_named_t	nputpage;	/* VOP_PUTPAGE */
110 	kstat_named_t	nmap;		/* VOP_MAP */
111 	kstat_named_t	naddmap;	/* VOP_ADDMAP */
112 	kstat_named_t	ndelmap;	/* VOP_DELMAP */
113 	kstat_named_t	npoll;		/* VOP_POLL */
114 	kstat_named_t	ndump;		/* VOP_DUMP */
115 	kstat_named_t	npathconf;	/* VOP_PATHCONF */
116 	kstat_named_t	npageio;	/* VOP_PAGEIO */
117 	kstat_named_t	ndumpctl;	/* VOP_DUMPCTL */
118 	kstat_named_t	ndispose;	/* VOP_DISPOSE */
119 	kstat_named_t	nsetsecattr;	/* VOP_SETSECATTR */
120 	kstat_named_t	ngetsecattr;	/* VOP_GETSECATTR */
121 	kstat_named_t	nshrlock;	/* VOP_SHRLOCK */
122 	kstat_named_t	nvnevent;	/* VOP_VNEVENT */
123 } vopstats_t;
124 
125 /*
126  * The vnode is the focus of all file activity in UNIX.
127  * A vnode is allocated for each active file, each current
128  * directory, each mounted-on file, and the root.
129  *
130  * Each vnode is usually associated with a file-system-specific node (for
131  * UFS, this is the in-memory inode).  Generally, a vnode and an fs-node
132  * should be created and destroyed together as a pair.
133  *
134  * If a vnode is reused for a new file, it should be reinitialized by calling
135  * either vn_reinit() or vn_recycle().
136  *
137  * vn_reinit() resets the entire vnode as if it was returned by vn_alloc().
138  * The caller is responsible for setting up the entire vnode after calling
139  * vn_reinit().  This is important when using kmem caching where the vnode is
140  * allocated by a constructor, for instance.
141  *
142  * vn_recycle() is used when the file system keeps some state around in both
143  * the vnode and the associated FS-node.  In UFS, for example, the inode of
144  * a deleted file can be reused immediately.  The v_data, v_vfsp, v_op, etc.
145  * remains the same but certain fields related to the previous instance need
146  * to be reset.  In particular:
147  *	v_femhead
148  *	v_path
149  *	v_rdcnt, v_wrcnt
150  *	v_mmap_read, v_mmap_write
151  */
152 
153 /*
154  * vnode types.  VNON means no type.  These values are unrelated to
155  * values in on-disk inodes.
156  */
157 typedef enum vtype {
158 	VNON	= 0,
159 	VREG	= 1,
160 	VDIR	= 2,
161 	VBLK	= 3,
162 	VCHR	= 4,
163 	VLNK	= 5,
164 	VFIFO	= 6,
165 	VDOOR	= 7,
166 	VPROC	= 8,
167 	VSOCK	= 9,
168 	VPORT	= 10,
169 	VBAD	= 11
170 } vtype_t;
171 
172 /*
173  * VSD - Vnode Specific Data
174  * Used to associate additional private data with a vnode.
175  */
176 struct vsd_node {
177 	list_node_t vs_nodes;		/* list of all VSD nodes */
178 	uint_t vs_nkeys;		/* entries in value array */
179 	void **vs_value;		/* array of value/key */
180 };
181 
182 /*
183  * Many of the fields in the vnode are read-only once they are initialized
184  * at vnode creation time.  Other fields are protected by locks.
185  *
186  * IMPORTANT: vnodes should be created ONLY by calls to vn_alloc().  They
187  * may not be embedded into the file-system specific node (inode).  The
188  * size of vnodes may change.
189  *
190  * The v_lock protects:
191  *   v_flag
192  *   v_stream
193  *   v_count
194  *   v_shrlocks
195  *   v_path
196  *   v_vsd
197  *
198  * A special lock (implemented by vn_vfswlock in vnode.c) protects:
199  *   v_vfsmountedhere
200  *
201  * The global flock_lock mutex (in flock.c) protects:
202  *   v_filocks
203  *
204  * IMPORTANT NOTE:
205  *
206  *   The following vnode fields are considered public and may safely be
207  *   accessed by file systems or other consumers:
208  *
209  *     v_lock
210  *     v_flag
211  *     v_count
212  *     v_data
213  *     v_vfsp
214  *     v_stream
215  *     v_type
216  *     v_rdev
217  *
218  * ALL OTHER FIELDS SHOULD BE ACCESSED ONLY BY THE OWNER OF THAT FIELD.
219  * In particular, file systems should not access other fields; they may
220  * change or even be removed.  The functionality which was once provided
221  * by these fields is available through vn_* functions.
222  */
223 
224 struct fem_head;	/* from fem.h */
225 
226 typedef struct vnode {
227 	kmutex_t	v_lock;		/* protects vnode fields */
228 	uint_t		v_flag;		/* vnode flags (see below) */
229 	uint_t		v_count;	/* reference count */
230 	void		*v_data;	/* private data for fs */
231 	struct vfs	*v_vfsp;	/* ptr to containing VFS */
232 	struct stdata	*v_stream;	/* associated stream */
233 	enum vtype	v_type;		/* vnode type */
234 	dev_t		v_rdev;		/* device (VCHR, VBLK) */
235 
236 	/* PRIVATE FIELDS BELOW - DO NOT USE */
237 
238 	struct vfs	*v_vfsmountedhere; /* ptr to vfs mounted here */
239 	struct vnodeops	*v_op;		/* vnode operations */
240 	struct page	*v_pages;	/* vnode pages list */
241 	pgcnt_t		v_npages;	/* # pages on this vnode */
242 	pgcnt_t		v_msnpages;	/* # pages charged to v_mset */
243 	struct page	*v_scanfront;	/* scanner front hand */
244 	struct page	*v_scanback;	/* scanner back hand */
245 	struct filock	*v_filocks;	/* ptr to filock list */
246 	struct shrlocklist *v_shrlocks;	/* ptr to shrlock list */
247 	krwlock_t	v_nbllock;	/* sync for NBMAND locks */
248 	kcondvar_t	v_cv;		/* synchronize locking */
249 	void		*v_locality;	/* hook for locality info */
250 	struct fem_head	*v_femhead;	/* fs monitoring */
251 	char		*v_path;	/* cached path */
252 	uint_t		v_rdcnt;	/* open for read count  (VREG only) */
253 	uint_t		v_wrcnt;	/* open for write count (VREG only) */
254 	u_longlong_t	v_mmap_read;	/* mmap read count */
255 	u_longlong_t	v_mmap_write;	/* mmap write count */
256 	void		*v_mpssdata;	/* info for large page mappings */
257 	hrtime_t	v_scantime;	/* last time this vnode was scanned */
258 	ushort_t	v_mset;		/* memory set ID */
259 	uint_t		v_msflags;	/* memory set flags */
260 	struct vnode	*v_msnext;	/* list of vnodes on an mset */
261 	struct vnode	*v_msprev;	/* list of vnodes on an mset */
262 	krwlock_t	v_mslock;	/* protects v_mset */
263 	void		*v_fopdata;	/* list of file ops event watches */
264 	struct vsd_node *v_vsd;		/* vnode specific data */
265 } vnode_t;
266 
267 #define	IS_DEVVP(vp)	\
268 	((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
269 
270 /*
271  * vnode flags.
272  */
273 #define	VROOT		0x01	/* root of its file system */
274 #define	VNOCACHE	0x02	/* don't keep cache pages on vnode */
275 #define	VNOMAP		0x04	/* file cannot be mapped/faulted */
276 #define	VDUP		0x08	/* file should be dup'ed rather then opened */
277 #define	VNOSWAP		0x10	/* file cannot be used as virtual swap device */
278 #define	VNOMOUNT	0x20	/* file cannot be covered by mount */
279 #define	VISSWAP		0x40	/* vnode is being used for swap */
280 #define	VSWAPLIKE	0x80	/* vnode acts like swap (but may not be) */
281 
282 #define	IS_SWAPVP(vp)	(((vp)->v_flag & (VISSWAP | VSWAPLIKE)) != 0)
283 
284 typedef struct vn_vfslocks_entry {
285 	rwstlock_t ve_lock;
286 	void *ve_vpvfs;
287 	struct vn_vfslocks_entry *ve_next;
288 	uint32_t ve_refcnt;
289 	char pad[64 - sizeof (rwstlock_t) - 2 * sizeof (void *) - \
290 	    sizeof (uint32_t)];
291 } vn_vfslocks_entry_t;
292 
293 /*
294  * The following two flags are used to lock the v_vfsmountedhere field
295  */
296 #define	VVFSLOCK	0x100
297 #define	VVFSWAIT	0x200
298 
299 /*
300  * Used to serialize VM operations on a vnode
301  */
302 #define	VVMLOCK		0x400
303 
304 /*
305  * Tell vn_open() not to fail a directory open for writing but
306  * to go ahead and call VOP_OPEN() to let the filesystem check.
307  */
308 #define	VDIROPEN	0x800
309 
310 /*
311  * Flag to let the VM system know that this file is most likely a binary
312  * or shared library since it has been mmap()ed EXEC at some time.
313  */
314 #define	VVMEXEC		0x1000
315 
316 #define	VPXFS		0x2000  /* clustering: global fs proxy vnode */
317 
318 #define	IS_PXFSVP(vp)	((vp)->v_flag & VPXFS)
319 
320 #define	V_XATTRDIR	0x4000	/* attribute unnamed directory */
321 
322 #define	V_LOCALITY	0x8000	/* whether locality aware */
323 
324 /*
325  * Flag that indicates the VM should maintain the v_pages list with all modified
326  * pages on one end and unmodified pages at the other. This makes finding dirty
327  * pages to write back to disk much faster at the expense of taking a minor
328  * fault on the first store instruction which touches a writable page.
329  */
330 #define	VMODSORT	(0x10000)
331 #define	IS_VMODSORT(vp) \
332 	(pvn_vmodsort_supported != 0 && ((vp)->v_flag  & VMODSORT) != 0)
333 
334 #define	VISSWAPFS	0x20000	/* vnode is being used for swapfs */
335 #define	IS_SWAPFSVP(vp)	(((vp)->v_flag & VISSWAPFS) != 0)
336 
337 /*
338  * Vnode attributes.  A bit-mask is supplied as part of the
339  * structure to indicate the attributes the caller wants to
340  * set (setattr) or extract (getattr).
341  */
342 
343 /*
344  * Note that va_nodeid and va_nblocks are 64bit data type.
345  * We support large files over NFSV3. With Solaris client and
346  * Server that generates 64bit ino's and sizes these fields
347  * will overflow if they are 32 bit sizes.
348  */
349 
350 typedef struct vattr {
351 	uint_t		va_mask;	/* bit-mask of attributes */
352 	vtype_t		va_type;	/* vnode type (for create) */
353 	mode_t		va_mode;	/* file access mode */
354 	uid_t		va_uid;		/* owner user id */
355 	gid_t		va_gid;		/* owner group id */
356 	dev_t		va_fsid;	/* file system id (dev for now) */
357 	u_longlong_t	va_nodeid;	/* node id */
358 	nlink_t		va_nlink;	/* number of references to file */
359 	u_offset_t	va_size;	/* file size in bytes */
360 	timestruc_t	va_atime;	/* time of last access */
361 	timestruc_t	va_mtime;	/* time of last modification */
362 	timestruc_t	va_ctime;	/* time of last status change */
363 	dev_t		va_rdev;	/* device the file represents */
364 	uint_t		va_blksize;	/* fundamental block size */
365 	u_longlong_t	va_nblocks;	/* # of blocks allocated */
366 	uint_t		va_seq;		/* sequence number */
367 } vattr_t;
368 
369 #ifdef _SYSCALL32
370 /*
371  * For bigtypes time_t changed to 64 bit on the 64-bit kernel.
372  * Define an old version for user/kernel interface
373  */
374 
375 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
376 #pragma pack(4)
377 #endif
378 
379 typedef struct vattr32 {
380 	uint32_t	va_mask;	/* bit-mask of attributes */
381 	vtype_t		va_type;	/* vnode type (for create) */
382 	mode32_t	va_mode;	/* file access mode */
383 	uid32_t		va_uid;		/* owner user id */
384 	gid32_t		va_gid;		/* owner group id */
385 	dev32_t		va_fsid;	/* file system id (dev for now) */
386 	u_longlong_t	va_nodeid;	/* node id */
387 	nlink_t		va_nlink;	/* number of references to file */
388 	u_offset_t	va_size;	/* file size in bytes */
389 	timestruc32_t	va_atime;	/* time of last access */
390 	timestruc32_t	va_mtime;	/* time of last modification */
391 	timestruc32_t	va_ctime;	/* time of last status change */
392 	dev32_t		va_rdev;	/* device the file represents */
393 	uint32_t	va_blksize;	/* fundamental block size */
394 	u_longlong_t	va_nblocks;	/* # of blocks allocated */
395 	uint32_t	va_seq;		/* sequence number */
396 } vattr32_t;
397 
398 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
399 #pragma pack()
400 #endif
401 
402 #else  /* not _SYSCALL32 */
403 #define	vattr32		vattr
404 typedef vattr_t		vattr32_t;
405 #endif /* _SYSCALL32 */
406 
407 /*
408  * Attributes of interest to the caller of setattr or getattr.
409  */
410 #define	AT_TYPE		0x0001
411 #define	AT_MODE		0x0002
412 #define	AT_UID		0x0004
413 #define	AT_GID		0x0008
414 #define	AT_FSID		0x0010
415 #define	AT_NODEID	0x0020
416 #define	AT_NLINK	0x0040
417 #define	AT_SIZE		0x0080
418 #define	AT_ATIME	0x0100
419 #define	AT_MTIME	0x0200
420 #define	AT_CTIME	0x0400
421 #define	AT_RDEV		0x0800
422 #define	AT_BLKSIZE	0x1000
423 #define	AT_NBLOCKS	0x2000
424 /*			0x4000 */	/* unused */
425 #define	AT_SEQ		0x8000
426 
427 #define	AT_ALL		(AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\
428 			AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\
429 			AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
430 
431 #define	AT_STAT		(AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
432 			AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV|AT_TYPE)
433 
434 #define	AT_TIMES	(AT_ATIME|AT_MTIME|AT_CTIME)
435 
436 #define	AT_NOSET	(AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
437 			AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
438 
439 /*
440  *  Modes.  Some values same as S_xxx entries from stat.h for convenience.
441  */
442 #define	VSUID		04000		/* set user id on execution */
443 #define	VSGID		02000		/* set group id on execution */
444 #define	VSVTX		01000		/* save swapped text even after use */
445 
446 /*
447  * Permissions.
448  */
449 #define	VREAD		00400
450 #define	VWRITE		00200
451 #define	VEXEC		00100
452 
453 #define	MODEMASK	07777		/* mode bits plus permission bits */
454 #define	PERMMASK	00777		/* permission bits */
455 
456 /*
457  * Check whether mandatory file locking is enabled.
458  */
459 
460 #define	MANDMODE(mode)		(((mode) & (VSGID|(VEXEC>>3))) == VSGID)
461 #define	MANDLOCK(vp, mode)	((vp)->v_type == VREG && MANDMODE(mode))
462 
463 /*
464  * Flags for vnode operations.
465  */
466 enum rm		{ RMFILE, RMDIRECTORY };	/* rm or rmdir (remove) */
467 enum symfollow	{ NO_FOLLOW, FOLLOW };		/* follow symlinks (or not) */
468 enum vcexcl	{ NONEXCL, EXCL };		/* (non)excl create */
469 enum create	{ CRCREAT, CRMKNOD, CRMKDIR };	/* reason for create */
470 
471 typedef enum rm		rm_t;
472 typedef enum symfollow	symfollow_t;
473 typedef enum vcexcl	vcexcl_t;
474 typedef enum create	create_t;
475 
476 /* Vnode Events - Used by VOP_VNEVENT */
477 typedef enum vnevent	{
478 	VE_SUPPORT	= 0,	/* Query */
479 	VE_RENAME_SRC	= 1,	/* Rename, with vnode as source */
480 	VE_RENAME_DEST	= 2,	/* Rename, with vnode as target/destination */
481 	VE_REMOVE	= 3,	/* Remove of vnode's name */
482 	VE_RMDIR	= 4,	/* Remove of directory vnode's name */
483 	VE_CREATE	= 5,	/* Create with vnode's name which exists */
484 	VE_LINK		= 6, 	/* Link with vnode's name as source */
485 	VE_RENAME_DEST_DIR	= 7, 	/* Rename with vnode as target dir */
486 	VE_MOUNTEDOVER	= 8 	/* File or Filesystem got mounted over vnode */
487 } vnevent_t;
488 
489 /*
490  * Values for checking vnode open and map counts
491  */
492 enum v_mode { V_READ, V_WRITE, V_RDORWR, V_RDANDWR };
493 
494 typedef enum v_mode v_mode_t;
495 
496 #define	V_TRUE	1
497 #define	V_FALSE	0
498 
499 /*
500  * Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations
501  */
502 
503 typedef struct vsecattr {
504 	uint_t		vsa_mask;	/* See below */
505 	int		vsa_aclcnt;	/* ACL entry count */
506 	void		*vsa_aclentp;	/* pointer to ACL entries */
507 	int		vsa_dfaclcnt;	/* default ACL entry count */
508 	void		*vsa_dfaclentp;	/* pointer to default ACL entries */
509 } vsecattr_t;
510 
511 /* vsa_mask values */
512 #define	VSA_ACL		0x0001
513 #define	VSA_ACLCNT	0x0002
514 #define	VSA_DFACL	0x0004
515 #define	VSA_DFACLCNT	0x0008
516 #define	VSA_ACE		0x0010
517 #define	VSA_ACECNT	0x0020
518 
519 /*
520  * Structure used by various vnode operations to determine
521  * the context (pid, host, identity) of a caller.
522  *
523  * The cc_caller_id is used to identify one or more callers who invoke
524  * operations, possibly on behalf of others.  For example, the NFS
525  * server could have it's own cc_caller_id which can be detected by
526  * vnode/vfs operations or (FEM) monitors on those operations.  New
527  * caller IDs are generated by fs_new_caller_id().
528  */
529 typedef struct caller_context {
530 	pid_t		cc_pid;		/* Process ID of the caller */
531 	int		cc_sysid;	/* System ID, used for remote calls */
532 	u_longlong_t	cc_caller_id;	/* Identifier for (set of) caller(s) */
533 } caller_context_t;
534 
535 /*
536  * Structure tags for function prototypes, defined elsewhere.
537  */
538 struct pathname;
539 struct fid;
540 struct flock64;
541 struct flk_callback;
542 struct shrlock;
543 struct page;
544 struct seg;
545 struct as;
546 struct pollhead;
547 
548 #ifdef	_KERNEL
549 
550 /*
551  * VNODE_OPS defines all the vnode operations.  It is used to define
552  * the vnodeops structure (below) and the fs_func_p union (vfs_opreg.h).
553  */
554 #define	VNODE_OPS							\
555 	int	(*vop_open)(vnode_t **, int, cred_t *);			\
556 	int	(*vop_close)(vnode_t *, int, int, offset_t, cred_t *);	\
557 	int	(*vop_read)(vnode_t *, uio_t *, int, cred_t *,		\
558 				caller_context_t *);			\
559 	int	(*vop_write)(vnode_t *, uio_t *, int, cred_t *,		\
560 				caller_context_t *);			\
561 	int	(*vop_ioctl)(vnode_t *, int, intptr_t, int, cred_t *,	\
562 				int *);					\
563 	int	(*vop_setfl)(vnode_t *, int, int, cred_t *);		\
564 	int	(*vop_getattr)(vnode_t *, vattr_t *, int, cred_t *);	\
565 	int	(*vop_setattr)(vnode_t *, vattr_t *, int, cred_t *,	\
566 				caller_context_t *);			\
567 	int	(*vop_access)(vnode_t *, int, int, cred_t *);		\
568 	int	(*vop_lookup)(vnode_t *, char *, vnode_t **,		\
569 				struct pathname *,			\
570 				int, vnode_t *, cred_t *);		\
571 	int	(*vop_create)(vnode_t *, char *, vattr_t *, vcexcl_t,	\
572 				int, vnode_t **, cred_t *, int);	\
573 	int	(*vop_remove)(vnode_t *, char *, cred_t *);		\
574 	int	(*vop_link)(vnode_t *, vnode_t *, char *, cred_t *);	\
575 	int	(*vop_rename)(vnode_t *, char *, vnode_t *, char *,	\
576 				cred_t *);				\
577 	int	(*vop_mkdir)(vnode_t *, char *, vattr_t *, vnode_t **,	\
578 				cred_t *);				\
579 	int	(*vop_rmdir)(vnode_t *, char *, vnode_t *, cred_t *);	\
580 	int	(*vop_readdir)(vnode_t *, uio_t *, cred_t *, int *);	\
581 	int	(*vop_symlink)(vnode_t *, char *, vattr_t *, char *,	\
582 				cred_t *);				\
583 	int	(*vop_readlink)(vnode_t *, uio_t *, cred_t *);		\
584 	int	(*vop_fsync)(vnode_t *, int, cred_t *);			\
585 	void	(*vop_inactive)(vnode_t *, cred_t *);			\
586 	int	(*vop_fid)(vnode_t *, struct fid *);			\
587 	int	(*vop_rwlock)(vnode_t *, int, caller_context_t *);	\
588 	void	(*vop_rwunlock)(vnode_t *, int, caller_context_t *);	\
589 	int	(*vop_seek)(vnode_t *, offset_t, offset_t *);		\
590 	int	(*vop_cmp)(vnode_t *, vnode_t *);			\
591 	int	(*vop_frlock)(vnode_t *, int, struct flock64 *,		\
592 				int, offset_t,				\
593 				struct flk_callback *, cred_t *);	\
594 	int	(*vop_space)(vnode_t *, int, struct flock64 *,		\
595 				int, offset_t,				\
596 				cred_t *, caller_context_t *);		\
597 	int	(*vop_realvp)(vnode_t *, vnode_t **);			\
598 	int	(*vop_getpage)(vnode_t *, offset_t, size_t, uint_t *,	\
599 				struct page **, size_t, struct seg *,	\
600 				caddr_t, enum seg_rw, cred_t *);	\
601 	int	(*vop_putpage)(vnode_t *, offset_t, size_t,		\
602 				int, cred_t *);				\
603 	int	(*vop_map)(vnode_t *, offset_t, struct as *,		\
604 				caddr_t *, size_t,			\
605 				uchar_t, uchar_t, uint_t, cred_t *);	\
606 	int	(*vop_addmap)(vnode_t *, offset_t, struct as *,		\
607 				caddr_t, size_t,			\
608 				uchar_t, uchar_t, uint_t, cred_t *);	\
609 	int	(*vop_delmap)(vnode_t *, offset_t, struct as *,		\
610 				caddr_t, size_t,			\
611 				uint_t, uint_t, uint_t, cred_t *);	\
612 	int	(*vop_poll)(vnode_t *, short, int, short *,		\
613 				struct pollhead **);			\
614 	int	(*vop_dump)(vnode_t *, caddr_t, int, int);		\
615 	int	(*vop_pathconf)(vnode_t *, int, ulong_t *, cred_t *);	\
616 	int	(*vop_pageio)(vnode_t *, struct page *,			\
617 				u_offset_t, size_t, int, cred_t *);	\
618 	int	(*vop_dumpctl)(vnode_t *, int, int *);			\
619 	void	(*vop_dispose)(vnode_t *, struct page *,		\
620 				int, int, cred_t *);			\
621 	int	(*vop_setsecattr)(vnode_t *, vsecattr_t *,		\
622 				int, cred_t *);				\
623 	int	(*vop_getsecattr)(vnode_t *, vsecattr_t *,		\
624 				int, cred_t *);				\
625 	int	(*vop_shrlock)(vnode_t *, int, struct shrlock *,	\
626 				int, cred_t *);				\
627 	int	(*vop_vnevent)(vnode_t *, vnevent_t, vnode_t *, char *)	\
628 	/* NB: No ";" */
629 
630 /*
631  * Operations on vnodes.  Note: File systems must never operate directly
632  * on a 'vnodeops' structure -- it WILL change in future releases!  They
633  * must use vn_make_ops() to create the structure.
634  */
635 typedef struct vnodeops {
636 	const char *vnop_name;
637 	VNODE_OPS;	/* Signatures of all vnode operations (vops) */
638 } vnodeops_t;
639 
640 typedef int (*fs_generic_func_p) ();	/* Generic vop/vfsop/femop/fsemop ptr */
641 
642 extern int	fop_open(vnode_t **, int, cred_t *);
643 extern int	fop_close(vnode_t *, int, int, offset_t, cred_t *);
644 extern int	fop_read(vnode_t *, uio_t *, int, cred_t *, caller_context_t *);
645 extern int	fop_write(vnode_t *, uio_t *, int, cred_t *,
646 				caller_context_t *);
647 extern int	fop_ioctl(vnode_t *, int, intptr_t, int, cred_t *, int *);
648 extern int	fop_setfl(vnode_t *, int, int, cred_t *);
649 extern int	fop_getattr(vnode_t *, vattr_t *, int, cred_t *);
650 extern int	fop_setattr(vnode_t *, vattr_t *, int, cred_t *,
651 				caller_context_t *);
652 extern int	fop_access(vnode_t *, int, int, cred_t *);
653 extern int	fop_lookup(vnode_t *, char *, vnode_t **, struct pathname *,
654 				int, vnode_t *, cred_t *);
655 extern int	fop_create(vnode_t *, char *, vattr_t *, vcexcl_t, int,
656 				vnode_t **, cred_t *, int);
657 extern int	fop_remove(vnode_t *vp, char *, cred_t *);
658 extern int	fop_link(vnode_t *, vnode_t *, char *, cred_t *);
659 extern int	fop_rename(vnode_t *, char *, vnode_t *, char *, cred_t *);
660 extern int	fop_mkdir(vnode_t *, char *, vattr_t *, vnode_t **, cred_t *);
661 extern int	fop_rmdir(vnode_t *, char *, vnode_t *, cred_t *);
662 extern int	fop_readdir(vnode_t *, uio_t *, cred_t *, int *);
663 extern int	fop_symlink(vnode_t *, char *, vattr_t *, char *, cred_t *);
664 extern int	fop_readlink(vnode_t *, uio_t *, cred_t *);
665 extern int	fop_fsync(vnode_t *, int, cred_t *);
666 extern void	fop_inactive(vnode_t *, cred_t *);
667 extern int	fop_fid(vnode_t *, struct fid *);
668 extern int	fop_rwlock(vnode_t *, int, caller_context_t *);
669 extern void	fop_rwunlock(vnode_t *, int, caller_context_t *);
670 extern int	fop_seek(vnode_t *, offset_t, offset_t *);
671 extern int	fop_cmp(vnode_t *, vnode_t *);
672 extern int	fop_frlock(vnode_t *, int, struct flock64 *, int, offset_t,
673 				struct flk_callback *, cred_t *);
674 extern int	fop_space(vnode_t *, int, struct flock64 *, int, offset_t,
675 				cred_t *, caller_context_t *);
676 extern int	fop_realvp(vnode_t *, vnode_t **);
677 extern int	fop_getpage(vnode_t *, offset_t, size_t, uint_t *,
678 				struct page **, size_t, struct seg *,
679 				caddr_t, enum seg_rw, cred_t *);
680 extern int	fop_putpage(vnode_t *, offset_t, size_t, int, cred_t *);
681 extern int	fop_map(vnode_t *, offset_t, struct as *, caddr_t *, size_t,
682 				uchar_t, uchar_t, uint_t, cred_t *cr);
683 extern int	fop_addmap(vnode_t *, offset_t, struct as *, caddr_t, size_t,
684 				uchar_t, uchar_t, uint_t, cred_t *);
685 extern int	fop_delmap(vnode_t *, offset_t, struct as *, caddr_t, size_t,
686 				uint_t, uint_t, uint_t, cred_t *);
687 extern int	fop_poll(vnode_t *, short, int, short *, struct pollhead **);
688 extern int	fop_dump(vnode_t *, caddr_t, int, int);
689 extern int	fop_pathconf(vnode_t *, int, ulong_t *, cred_t *);
690 extern int	fop_pageio(vnode_t *, struct page *, u_offset_t, size_t, int,
691 				cred_t *);
692 extern int	fop_dumpctl(vnode_t *, int, int *);
693 extern void	fop_dispose(vnode_t *, struct page *, int, int, cred_t *);
694 extern int	fop_setsecattr(vnode_t *, vsecattr_t *, int, cred_t *);
695 extern int	fop_getsecattr(vnode_t *, vsecattr_t *, int, cred_t *);
696 extern int	fop_shrlock(vnode_t *, int, struct shrlock *, int, cred_t *);
697 extern int	fop_vnevent(vnode_t *, vnevent_t, vnode_t *, char *);
698 
699 #endif	/* _KERNEL */
700 
701 #define	VOP_OPEN(vpp, mode, cr) \
702 	fop_open(vpp, mode, cr)
703 #define	VOP_CLOSE(vp, f, c, o, cr) \
704 	fop_close(vp, f, c, o, cr)
705 #define	VOP_READ(vp, uiop, iof, cr, ct) \
706 	fop_read(vp, uiop, iof, cr, ct)
707 #define	VOP_WRITE(vp, uiop, iof, cr, ct) \
708 	fop_write(vp, uiop, iof, cr, ct)
709 #define	VOP_IOCTL(vp, cmd, a, f, cr, rvp) \
710 	fop_ioctl(vp, cmd, a, f, cr, rvp)
711 #define	VOP_SETFL(vp, f, a, cr) \
712 	fop_setfl(vp, f, a, cr)
713 #define	VOP_GETATTR(vp, vap, f, cr) \
714 	fop_getattr(vp, vap, f, cr)
715 #define	VOP_SETATTR(vp, vap, f, cr, ct) \
716 	fop_setattr(vp, vap, f, cr, ct)
717 #define	VOP_ACCESS(vp, mode, f, cr) \
718 	fop_access(vp, mode, f, cr)
719 #define	VOP_LOOKUP(vp, cp, vpp, pnp, f, rdir, cr) \
720 	fop_lookup(vp, cp, vpp, pnp, f, rdir, cr)
721 #define	VOP_CREATE(dvp, p, vap, ex, mode, vpp, cr, flag) \
722 	fop_create(dvp, p, vap, ex, mode, vpp, cr, flag)
723 #define	VOP_REMOVE(dvp, p, cr) \
724 	fop_remove(dvp, p, cr)
725 #define	VOP_LINK(tdvp, fvp, p, cr) \
726 	fop_link(tdvp, fvp, p, cr)
727 #define	VOP_RENAME(fvp, fnm, tdvp, tnm, cr) \
728 	fop_rename(fvp, fnm, tdvp, tnm, cr)
729 #define	VOP_MKDIR(dp, p, vap, vpp, cr) \
730 	fop_mkdir(dp, p, vap, vpp, cr)
731 #define	VOP_RMDIR(dp, p, cdir, cr) \
732 	fop_rmdir(dp, p, cdir, cr)
733 #define	VOP_READDIR(vp, uiop, cr, eofp) \
734 	fop_readdir(vp, uiop, cr, eofp)
735 #define	VOP_SYMLINK(dvp, lnm, vap, tnm, cr) \
736 	fop_symlink(dvp, lnm, vap, tnm, cr)
737 #define	VOP_READLINK(vp, uiop, cr) \
738 	fop_readlink(vp, uiop, cr)
739 #define	VOP_FSYNC(vp, syncflag, cr) \
740 	fop_fsync(vp, syncflag, cr)
741 #define	VOP_INACTIVE(vp, cr) \
742 	fop_inactive(vp, cr)
743 #define	VOP_FID(vp, fidp) \
744 	fop_fid(vp, fidp)
745 #define	VOP_RWLOCK(vp, w, ct) \
746 	fop_rwlock(vp, w, ct)
747 #define	VOP_RWUNLOCK(vp, w, ct) \
748 	fop_rwunlock(vp, w, ct)
749 #define	VOP_SEEK(vp, ooff, noffp) \
750 	fop_seek(vp, ooff, noffp)
751 #define	VOP_CMP(vp1, vp2) \
752 	fop_cmp(vp1, vp2)
753 #define	VOP_FRLOCK(vp, cmd, a, f, o, cb, cr) \
754 	fop_frlock(vp, cmd, a, f, o, cb, cr)
755 #define	VOP_SPACE(vp, cmd, a, f, o, cr, ct) \
756 	fop_space(vp, cmd, a, f, o, cr, ct)
757 #define	VOP_REALVP(vp1, vp2) \
758 	fop_realvp(vp1, vp2)
759 #define	VOP_GETPAGE(vp, of, sz, pr, pl, ps, sg, a, rw, cr) \
760 	fop_getpage(vp, of, sz, pr, pl, ps, sg, a, rw, cr)
761 #define	VOP_PUTPAGE(vp, of, sz, fl, cr) \
762 	fop_putpage(vp, of, sz, fl, cr)
763 #define	VOP_MAP(vp, of, as, a, sz, p, mp, fl, cr) \
764 	fop_map(vp, of, as, a, sz, p, mp, fl, cr)
765 #define	VOP_ADDMAP(vp, of, as, a, sz, p, mp, fl, cr) \
766 	fop_addmap(vp, of, as, a, sz, p, mp, fl, cr)
767 #define	VOP_DELMAP(vp, of, as, a, sz, p, mp, fl, cr) \
768 	fop_delmap(vp, of, as, a, sz, p, mp, fl, cr)
769 #define	VOP_POLL(vp, events, anyyet, reventsp, phpp) \
770 	fop_poll(vp, events, anyyet, reventsp, phpp)
771 #define	VOP_DUMP(vp, addr, bn, count) \
772 	fop_dump(vp, addr, bn, count)
773 #define	VOP_PATHCONF(vp, cmd, valp, cr) \
774 	fop_pathconf(vp, cmd, valp, cr)
775 #define	VOP_PAGEIO(vp, pp, io_off, io_len, flags, cr) \
776 	fop_pageio(vp, pp, io_off, io_len, flags, cr)
777 #define	VOP_DUMPCTL(vp, action, blkp) \
778 	fop_dumpctl(vp, action, blkp)
779 #define	VOP_DISPOSE(vp, pp, flag, dn, cr) \
780 	fop_dispose(vp, pp, flag, dn, cr)
781 #define	VOP_GETSECATTR(vp, vsap, f, cr) \
782 	fop_getsecattr(vp, vsap, f, cr)
783 #define	VOP_SETSECATTR(vp, vsap, f, cr) \
784 	fop_setsecattr(vp, vsap, f, cr)
785 #define	VOP_SHRLOCK(vp, cmd, shr, f, cr) \
786 	fop_shrlock(vp, cmd, shr, f, cr)
787 #define	VOP_VNEVENT(vp, vnevent, dvp, fnm) \
788 	fop_vnevent(vp, vnevent, dvp, fnm)
789 
790 #define	VOPNAME_OPEN		"open"
791 #define	VOPNAME_CLOSE		"close"
792 #define	VOPNAME_READ		"read"
793 #define	VOPNAME_WRITE		"write"
794 #define	VOPNAME_IOCTL		"ioctl"
795 #define	VOPNAME_SETFL		"setfl"
796 #define	VOPNAME_GETATTR		"getattr"
797 #define	VOPNAME_SETATTR		"setattr"
798 #define	VOPNAME_ACCESS		"access"
799 #define	VOPNAME_LOOKUP		"lookup"
800 #define	VOPNAME_CREATE		"create"
801 #define	VOPNAME_REMOVE		"remove"
802 #define	VOPNAME_LINK		"link"
803 #define	VOPNAME_RENAME		"rename"
804 #define	VOPNAME_MKDIR		"mkdir"
805 #define	VOPNAME_RMDIR		"rmdir"
806 #define	VOPNAME_READDIR		"readdir"
807 #define	VOPNAME_SYMLINK		"symlink"
808 #define	VOPNAME_READLINK	"readlink"
809 #define	VOPNAME_FSYNC		"fsync"
810 #define	VOPNAME_INACTIVE	"inactive"
811 #define	VOPNAME_FID		"fid"
812 #define	VOPNAME_RWLOCK		"rwlock"
813 #define	VOPNAME_RWUNLOCK	"rwunlock"
814 #define	VOPNAME_SEEK		"seek"
815 #define	VOPNAME_CMP		"cmp"
816 #define	VOPNAME_FRLOCK		"frlock"
817 #define	VOPNAME_SPACE		"space"
818 #define	VOPNAME_REALVP		"realvp"
819 #define	VOPNAME_GETPAGE		"getpage"
820 #define	VOPNAME_PUTPAGE		"putpage"
821 #define	VOPNAME_MAP		"map"
822 #define	VOPNAME_ADDMAP		"addmap"
823 #define	VOPNAME_DELMAP		"delmap"
824 #define	VOPNAME_POLL		"poll"
825 #define	VOPNAME_DUMP		"dump"
826 #define	VOPNAME_PATHCONF	"pathconf"
827 #define	VOPNAME_PAGEIO		"pageio"
828 #define	VOPNAME_DUMPCTL		"dumpctl"
829 #define	VOPNAME_DISPOSE		"dispose"
830 #define	VOPNAME_GETSECATTR	"getsecattr"
831 #define	VOPNAME_SETSECATTR	"setsecattr"
832 #define	VOPNAME_SHRLOCK		"shrlock"
833 #define	VOPNAME_VNEVENT		"vnevent"
834 
835 /*
836  * Flags for VOP_LOOKUP
837  */
838 #define	LOOKUP_DIR		0x01	/* want parent dir vp */
839 #define	LOOKUP_XATTR		0x02	/* lookup up extended attr dir */
840 #define	CREATE_XATTR_DIR	0x04	/* Create extended attr dir */
841 
842 /*
843  * Flags for VOP_RWLOCK/VOP_RWUNLOCK
844  * VOP_RWLOCK will return the flag that was actually set, or -1 if none.
845  */
846 #define	V_WRITELOCK_TRUE	(1)	/* Request write-lock on the vnode */
847 #define	V_WRITELOCK_FALSE	(0)	/* Request read-lock on the vnode */
848 
849 /*
850  * Flags for VOP_DUMPCTL
851  */
852 #define	DUMP_ALLOC	0
853 #define	DUMP_FREE	1
854 #define	DUMP_SCAN	2
855 
856 /*
857  * Public vnode manipulation functions.
858  */
859 #ifdef	_KERNEL
860 
861 vnode_t *vn_alloc(int);
862 void	vn_reinit(vnode_t *);
863 void	vn_recycle(vnode_t *);
864 void	vn_free(vnode_t *);
865 
866 int	vn_is_readonly(vnode_t *);
867 int   	vn_is_opened(vnode_t *, v_mode_t);
868 int   	vn_is_mapped(vnode_t *, v_mode_t);
869 
870 int	vn_can_change_zones(vnode_t *vp);
871 
872 int	vn_has_flocks(vnode_t *);
873 int	vn_has_mandatory_locks(vnode_t *, int);
874 int	vn_has_cached_data(vnode_t *);
875 
876 void	vn_setops(vnode_t *, vnodeops_t *);
877 vnodeops_t *vn_getops(vnode_t *);
878 int	vn_matchops(vnode_t *, vnodeops_t *);
879 int	vn_matchopval(vnode_t *, char *, fs_generic_func_p);
880 int	vn_ismntpt(vnode_t *);
881 
882 struct vfs *vn_mountedvfs(vnode_t *);
883 
884 void	vn_create_cache(void);
885 void	vn_destroy_cache(void);
886 
887 void	vn_freevnodeops(vnodeops_t *);
888 
889 int	vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode,
890 		struct vnode **vpp, enum create crwhy, mode_t umask);
891 int	vn_openat(char *pnamep, enum uio_seg seg, int filemode, int createmode,
892 		struct vnode **vpp, enum create crwhy,
893 		mode_t umask, struct vnode *startvp);
894 int	vn_create(char *pnamep, enum uio_seg seg, struct vattr *vap,
895 		enum vcexcl excl, int mode, struct vnode **vpp,
896 		enum create why, int flag, mode_t umask);
897 int	vn_createat(char *pnamep, enum uio_seg seg, struct vattr *vap,
898 		enum vcexcl excl, int mode, struct vnode **vpp,
899 		enum create why, int flag, mode_t umask, struct vnode *startvp);
900 int	vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, ssize_t len,
901 		offset_t offset, enum uio_seg seg, int ioflag, rlim64_t ulimit,
902 		cred_t *cr, ssize_t *residp);
903 void	vn_rele(struct vnode *vp);
904 void	vn_rele_stream(struct vnode *vp);
905 int	vn_link(char *from, char *to, enum uio_seg seg);
906 int	vn_rename(char *from, char *to, enum uio_seg seg);
907 int	vn_renameat(vnode_t *fdvp, char *fname, vnode_t *tdvp, char *tname,
908 		enum uio_seg seg);
909 int	vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag);
910 int	vn_removeat(vnode_t *startvp, char *fnamep, enum uio_seg seg,
911 		enum rm dirflag);
912 int	vn_compare(vnode_t *vp1, vnode_t *vp2);
913 int	vn_vfswlock(struct vnode *vp);
914 int	vn_vfswlock_wait(struct vnode *vp);
915 int	vn_vfsrlock(struct vnode *vp);
916 int	vn_vfsrlock_wait(struct vnode *vp);
917 void	vn_vfsunlock(struct vnode *vp);
918 int	vn_vfswlock_held(struct vnode *vp);
919 vnode_t *specvp(struct vnode *vp, dev_t dev, vtype_t type, struct cred *cr);
920 vnode_t *makespecvp(dev_t dev, vtype_t type);
921 vn_vfslocks_entry_t *vn_vfslocks_getlock(void *);
922 void	vn_vfslocks_rele(vn_vfslocks_entry_t *);
923 
924 void vn_copypath(struct vnode *src, struct vnode *dst);
925 void vn_setpath_str(struct vnode *vp, const char *str, size_t len);
926 void vn_setpath(vnode_t *rootvp, struct vnode *startvp, struct vnode *vp,
927     const char *path, size_t plen);
928 
929 /* Vnode event notification */
930 void	vnevent_rename_src(vnode_t *, vnode_t *, char *);
931 void	vnevent_rename_dest(vnode_t *, vnode_t *, char *);
932 void	vnevent_remove(vnode_t *, vnode_t *, char *);
933 void	vnevent_rmdir(vnode_t *, vnode_t *, char *);
934 void	vnevent_create(vnode_t *);
935 void	vnevent_link(vnode_t *);
936 void	vnevent_rename_dest_dir(vnode_t *);
937 void	vnevent_mountedover(vnode_t *);
938 int	vnevent_support(vnode_t *);
939 
940 /* Vnode specific data */
941 void vsd_create(uint_t *, void (*)(void *));
942 void vsd_destroy(uint_t *);
943 void *vsd_get(vnode_t *, uint_t);
944 int vsd_set(vnode_t *, uint_t, void *);
945 void vsd_free(vnode_t *);
946 
947 /* Context identification */
948 u_longlong_t	fs_new_caller_id();
949 
950 int	vn_vmpss_usepageio(vnode_t *);
951 
952 /*
953  * Needed for use of IS_VMODSORT() in kernel.
954  */
955 extern uint_t pvn_vmodsort_supported;
956 
957 #define	VN_HOLD(vp)	{ \
958 	mutex_enter(&(vp)->v_lock); \
959 	(vp)->v_count++; \
960 	mutex_exit(&(vp)->v_lock); \
961 }
962 
963 #define	VN_RELE(vp)	{ \
964 	vn_rele(vp); \
965 }
966 
967 #define	VN_SET_VFS_TYPE_DEV(vp, vfsp, type, dev)	{ \
968 	(vp)->v_vfsp = (vfsp); \
969 	(vp)->v_type = (type); \
970 	(vp)->v_rdev = (dev); \
971 }
972 
973 /*
974  * Compare two vnodes for equality.  In general this macro should be used
975  * in preference to calling VOP_CMP directly.
976  */
977 #define	VN_CMP(VP1, VP2)	((VP1) == (VP2) ? 1 : 	\
978 	((VP1) && (VP2) && (vn_getops(VP1) == vn_getops(VP2)) ? \
979 	VOP_CMP(VP1, VP2) : 0))
980 
981 extern struct vnode kvp;
982 extern struct vnode zvp;
983 
984 #define	VN_ISKAS(vp)		((vp) == &kvp || (vp) == &zvp)
985 
986 #endif	/* _KERNEL */
987 
988 /*
989  * Flags to VOP_SETATTR/VOP_GETATTR.
990  */
991 #define	ATTR_UTIME	0x01	/* non-default utime(2) request */
992 #define	ATTR_EXEC	0x02	/* invocation from exec(2) */
993 #define	ATTR_COMM	0x04	/* yield common vp attributes */
994 #define	ATTR_HINT	0x08	/* information returned will be `hint' */
995 #define	ATTR_REAL	0x10	/* yield attributes of the real vp */
996 
997 /*
998  * Generally useful macros.
999  */
1000 #define	VBSIZE(vp)	((vp)->v_vfsp->vfs_bsize)
1001 
1002 #define	VTOZONE(vp)	((vp)->v_vfsp->vfs_zone)
1003 
1004 #define	NULLVP		((struct vnode *)0)
1005 #define	NULLVPP		((struct vnode **)0)
1006 
1007 #ifdef	_KERNEL
1008 
1009 /*
1010  * Structure used while handling asynchronous VOP_PUTPAGE operations.
1011  */
1012 struct async_reqs {
1013 	struct async_reqs *a_next;	/* pointer to next arg struct */
1014 	struct vnode *a_vp;		/* vnode pointer */
1015 	u_offset_t a_off;			/* offset in file */
1016 	uint_t a_len;			/* size of i/o request */
1017 	int a_flags;			/* flags to indicate operation type */
1018 	struct cred *a_cred;		/* cred pointer	*/
1019 	ushort_t a_prealloced;		/* set if struct is pre-allocated */
1020 };
1021 
1022 /*
1023  * VN_DISPOSE() -- given a page pointer, safely invoke VOP_DISPOSE().
1024  */
1025 #define	VN_DISPOSE(pp, flag, dn, cr)	{ \
1026 	extern struct vnode kvp; \
1027 	if ((pp)->p_vnode != NULL && !VN_ISKAS((pp)->p_vnode)) \
1028 		VOP_DISPOSE((pp)->p_vnode, (pp), (flag), (dn), (cr)); \
1029 	else if ((flag) == B_FREE) \
1030 		page_free((pp), (dn)); \
1031 	else \
1032 		page_destroy((pp), (dn)); \
1033 	}
1034 
1035 #endif	/* _KERNEL */
1036 
1037 #ifdef	__cplusplus
1038 }
1039 #endif
1040 
1041 #endif	/* _SYS_VNODE_H */
1042