vnode.h revision 70374
138889Sjdp/*
2218822Sdim * Copyright (c) 1989, 1993
338889Sjdp *	The Regents of the University of California.  All rights reserved.
438889Sjdp *
538889Sjdp * Redistribution and use in source and binary forms, with or without
638889Sjdp * modification, are permitted provided that the following conditions
738889Sjdp * are met:
838889Sjdp * 1. Redistributions of source code must retain the above copyright
938889Sjdp *    notice, this list of conditions and the following disclaimer.
1038889Sjdp * 2. Redistributions in binary form must reproduce the above copyright
1138889Sjdp *    notice, this list of conditions and the following disclaimer in the
1238889Sjdp *    documentation and/or other materials provided with the distribution.
1338889Sjdp * 3. All advertising materials mentioning features or use of this software
1438889Sjdp *    must display the following acknowledgement:
1538889Sjdp *	This product includes software developed by the University of
1638889Sjdp *	California, Berkeley and its contributors.
1738889Sjdp * 4. Neither the name of the University nor the names of its contributors
1838889Sjdp *    may be used to endorse or promote products derived from this software
19218822Sdim *    without specific prior written permission.
20218822Sdim *
2138889Sjdp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2238889Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2338889Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2438889Sjdp * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2538889Sjdp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2638889Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2738889Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2838889Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2938889Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3038889Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3138889Sjdp * SUCH DAMAGE.
3238889Sjdp *
3338889Sjdp *	@(#)vnode.h	8.7 (Berkeley) 2/4/94
3477298Sobrien * $FreeBSD: head/sys/sys/vnode.h 70374 2000-12-26 19:41:38Z dillon $
3577298Sobrien */
3638889Sjdp
3738889Sjdp#ifndef _SYS_VNODE_H_
3838889Sjdp#define	_SYS_VNODE_H_
3938889Sjdp
4077298Sobrien#include <sys/lock.h>
4138889Sjdp#include <sys/mutex.h>
4277298Sobrien#include <sys/queue.h>
4377298Sobrien#include <sys/select.h>
4477298Sobrien#include <sys/uio.h>
4538889Sjdp#include <sys/acl.h>
4638889Sjdp
4738889Sjdp/*
4838889Sjdp * The vnode is the focus of all file activity in UNIX.  There is a
4938889Sjdp * unique vnode allocated for each active file, each current directory,
5038889Sjdp * each mounted-on file, text file, and the root.
5138889Sjdp */
5238889Sjdp
5338889Sjdp/*
5438889Sjdp * Vnode types.  VNON means no type.
5538889Sjdp */
5638889Sjdpenum vtype	{ VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };
5738889Sjdp
5838889Sjdp/*
5938889Sjdp * Vnode tag types.
6038889Sjdp * These are for the benefit of external programs only (e.g., pstat)
6138889Sjdp * and should NEVER be inspected by the kernel.
6238889Sjdp */
6338889Sjdpenum vtagtype	{
6438889Sjdp	VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_PC, VT_LFS, VT_LOFS, VT_FDESC,
6538889Sjdp	VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS,
6638889Sjdp	VT_UNION, VT_MSDOSFS, VT_DEVFS, VT_TFS, VT_VFS, VT_CODA, VT_NTFS,
6738889Sjdp	VT_HPFS, VT_NWFS
6838889Sjdp};
6938889Sjdp
7038889Sjdp/*
7138889Sjdp * Each underlying filesystem allocates its own private area and hangs
7238889Sjdp * it from v_data.  If non-null, this area is freed in getnewvnode().
7338889Sjdp */
7438889SjdpTAILQ_HEAD(buflists, buf);
7538889Sjdp
7638889Sjdptypedef	int 	vop_t __P((void *));
7738889Sjdpstruct namecache;
7838889Sjdp
7938889Sjdp/*
8038889Sjdp * Reading or writing any of these items requires holding the appropriate lock.
8138889Sjdp * v_freelist is locked by the global vnode_free_list simple lock.
8238889Sjdp * v_mntvnodes is locked by the global mntvnodes simple lock.
8338889Sjdp * v_flag, v_usecount, v_holdcount and v_writecount are
8438889Sjdp *    locked by the v_interlock mutex.
8538889Sjdp * v_pollinfo is locked by the lock contained inside it.
8638889Sjdp */
8738889Sjdpstruct vnode {
8838889Sjdp	u_long	v_flag;				/* vnode flags (see below) */
8938889Sjdp	int	v_usecount;			/* reference count of users */
9038889Sjdp	int	v_writecount;			/* reference count of writers */
9178828Sobrien	int	v_holdcnt;			/* page & buffer references */
9278828Sobrien	u_long	v_id;				/* capability identifier */
9378828Sobrien	struct	mount *v_mount;			/* ptr to vfs we are in */
9478828Sobrien	vop_t	**v_op;				/* vnode operations vector */
9578828Sobrien	TAILQ_ENTRY(vnode) v_freelist;		/* vnode freelist */
9638889Sjdp	LIST_ENTRY(vnode) v_mntvnodes;		/* vnodes for mount point */
97130561Sobrien	struct	buflists v_cleanblkhd;		/* clean blocklist head */
9838889Sjdp	struct	buflists v_dirtyblkhd;		/* dirty blocklist head */
9978828Sobrien	LIST_ENTRY(vnode) v_synclist;		/* vnodes with dirty buffers */
10078828Sobrien	long	v_numoutput;			/* num of writes in progress */
10138889Sjdp	enum	vtype v_type;			/* vnode type */
102130561Sobrien	union {
10338889Sjdp		struct mount	*vu_mountedhere;/* ptr to mounted vfs (VDIR) */
10438889Sjdp		struct socket	*vu_socket;	/* unix ipc (VSOCK) */
10538889Sjdp		struct {
10638889Sjdp			struct specinfo	*vu_specinfo; /* device (VCHR, VBLK) */
10777298Sobrien			SLIST_ENTRY(vnode) vu_specnext;
10838889Sjdp		} vu_spec;
10938889Sjdp		struct fifoinfo	*vu_fifoinfo;	/* fifo (VFIFO) */
11078828Sobrien	} v_un;
11138889Sjdp	struct	nqlease *v_lease;		/* Soft reference to lease */
11277298Sobrien	daddr_t	v_lastw;			/* last write (write cluster) */
11377298Sobrien	daddr_t	v_cstart;			/* start block of cluster */
11438889Sjdp	daddr_t	v_lasta;			/* last allocation */
11538889Sjdp	int	v_clen;				/* length of current cluster */
11638889Sjdp	struct vm_object *v_object;		/* Place to store VM object */
11738889Sjdp	struct	mtx v_interlock;		/* lock on usecount and flag */
11838889Sjdp	struct	lock v_lock;			/* used if fs don't have one */
11977298Sobrien	struct	lock *v_vnlock;			/* pointer to vnode lock */
12038889Sjdp	enum	vtagtype v_tag;			/* type of underlying data */
12177298Sobrien	void 	*v_data;			/* private data for fs */
12277298Sobrien	LIST_HEAD(, namecache) v_cache_src;	/* Cache entries from us */
12377298Sobrien	TAILQ_HEAD(, namecache) v_cache_dst;	/* Cache entries to us */
12477298Sobrien	struct	vnode *v_dd;			/* .. vnode */
12577298Sobrien	u_long	v_ddid;				/* .. capability identifier */
12638889Sjdp	struct	{
12738889Sjdp		struct	simplelock vpi_lock;	/* lock to protect below */
12838889Sjdp		struct	selinfo vpi_selinfo;	/* identity of poller(s) */
12938889Sjdp		short	vpi_events;		/* what they are looking for */
13038889Sjdp		short	vpi_revents;		/* what has happened */
13138889Sjdp	} v_pollinfo;
13238889Sjdp	struct proc *v_vxproc;			/* proc owning VXLOCK */
13338889Sjdp#ifdef	DEBUG_LOCKS
13477298Sobrien	const char *filename;			/* Source file doing locking */
13577298Sobrien	int line;				/* Line number doing locking */
13677298Sobrien#endif
13777298Sobrien};
13878828Sobrien#define	v_mountedhere	v_un.vu_mountedhere
13938889Sjdp#define	v_socket	v_un.vu_socket
14038889Sjdp#define	v_rdev		v_un.vu_spec.vu_specinfo
14138889Sjdp#define	v_specnext	v_un.vu_spec.vu_specnext
14238889Sjdp#define	v_fifoinfo	v_un.vu_fifoinfo
14338889Sjdp
14438889Sjdp#define	VN_POLLEVENT(vp, events)				\
14538889Sjdp	do {							\
14638889Sjdp		if ((vp)->v_pollinfo.vpi_events & (events))	\
14738889Sjdp			vn_pollevent((vp), (events));		\
14838889Sjdp	} while (0)
14938889Sjdp
15038889Sjdp/*
15178828Sobrien * Vnode flags.
15238889Sjdp */
15338889Sjdp#define	VROOT		0x00001	/* root of its file system */
15438889Sjdp#define	VTEXT		0x00002	/* vnode is a pure text prototype */
15538889Sjdp#define	VSYSTEM		0x00004	/* vnode being used by kernel */
15638889Sjdp#define	VISTTY		0x00008	/* vnode represents a tty */
15738889Sjdp#define	VXLOCK		0x00100	/* vnode is locked to change underlying type */
15838889Sjdp#define	VXWANT		0x00200	/* process is waiting for vnode */
15938889Sjdp#define	VBWAIT		0x00400	/* waiting for output to complete */
16038889Sjdp/* open for business    0x00800 */
16138889Sjdp/* open for business    0x01000 */
16238889Sjdp#define	VOBJBUF		0x02000	/* Allocate buffers in VM object */
16338889Sjdp#define	VCOPYONWRITE    0x04000 /* vnode is doing copy-on-write */
16438889Sjdp#define	VAGE		0x08000	/* Insert vnode at head of free list */
16578828Sobrien#define	VOLOCK		0x10000	/* vnode is locked waiting for an object */
16678828Sobrien#define	VOWANT		0x20000	/* a process is waiting for VOLOCK */
16738889Sjdp#define	VDOOMED		0x40000	/* This vnode is being recycled */
16838889Sjdp#define	VFREE		0x80000	/* This vnode is on the freelist */
16938889Sjdp/* open for business	0x100000 */
17038889Sjdp#define	VONWORKLST	0x200000 /* On syncer work-list */
17138889Sjdp#define	VMOUNT		0x400000 /* Mount in progress */
17238889Sjdp
17338889Sjdp/*
17438889Sjdp * Vnode attributes.  A field value of VNOVAL represents a field whose value
17538889Sjdp * is unavailable (getattr) or which is not to be changed (setattr).
17638889Sjdp */
17738889Sjdpstruct vattr {
17838889Sjdp	enum vtype	va_type;	/* vnode type (for create) */
17938889Sjdp	u_short		va_mode;	/* files access mode and type */
18038889Sjdp	short		va_nlink;	/* number of references to file */
18138889Sjdp	uid_t		va_uid;		/* owner user id */
18238889Sjdp	gid_t		va_gid;		/* owner group id */
18338889Sjdp	udev_t		va_fsid;	/* file system id */
18438889Sjdp	long		va_fileid;	/* file id */
18538889Sjdp	u_quad_t	va_size;	/* file size in bytes */
18678828Sobrien	long		va_blocksize;	/* blocksize preferred for i/o */
18738889Sjdp	struct timespec	va_atime;	/* time of last access */
18838889Sjdp	struct timespec	va_mtime;	/* time of last modification */
18938889Sjdp	struct timespec	va_ctime;	/* time file changed */
19038889Sjdp	u_long		va_gen;		/* generation number of file */
19138889Sjdp	u_long		va_flags;	/* flags defined for file */
19238889Sjdp	udev_t		va_rdev;	/* device the special file represents */
19338889Sjdp	u_quad_t	va_bytes;	/* bytes of disk space held by file */
19438889Sjdp	u_quad_t	va_filerev;	/* file modification number */
19538889Sjdp	u_int		va_vaflags;	/* operations flags, see below */
19638889Sjdp	long		va_spare;	/* remain quad aligned */
19738889Sjdp};
19838889Sjdp
19938889Sjdp/*
20038889Sjdp * Flags for va_vaflags.
20138889Sjdp */
20238889Sjdp#define	VA_UTIMES_NULL	0x01		/* utimes argument was NULL */
20338889Sjdp#define VA_EXCLUSIVE	0x02		/* exclusive create request */
20438889Sjdp
20538889Sjdp/*
20638889Sjdp * Flags for ioflag. (high 16 bits used to ask for read-ahead and
20738889Sjdp * help with write clustering)
20838889Sjdp */
20938889Sjdp#define	IO_UNIT		0x01		/* do I/O as atomic unit */
21078828Sobrien#define	IO_APPEND	0x02		/* append write to end */
21138889Sjdp#define	IO_SYNC		0x04		/* do I/O synchronously */
21278828Sobrien#define	IO_NODELOCKED	0x08		/* underlying node already locked */
21378828Sobrien#define	IO_NDELAY	0x10		/* FNDELAY flag set in file table */
21438889Sjdp#define	IO_VMIO		0x20		/* data already in VMIO space */
21538889Sjdp#define	IO_INVAL	0x40		/* invalidate after I/O */
21638889Sjdp#define IO_ASYNC	0x80		/* bawrite rather then bdwrite */
21738889Sjdp
21838889Sjdp/*
21978828Sobrien *  Modes.  Some values same as Ixxx entries from inode.h for now.
22078828Sobrien */
22138889Sjdp#define	VADMIN	010000		/* permission to administer vnode */
22278828Sobrien#define	VSUID	004000		/* set user id on execution */
22378828Sobrien#define	VSGID	002000		/* set group id on execution */
22478828Sobrien#define	VSVTX	001000		/* save swapped text even after use */
22578828Sobrien#define	VREAD	000400		/* read, write, execute permissions */
22638889Sjdp#define	VWRITE	000200
22738889Sjdp#define	VEXEC	000100
22838889Sjdp
22938889Sjdp/*
23038889Sjdp * Token indicating no attribute value yet assigned.
23138889Sjdp */
23238889Sjdp#define	VNOVAL	(-1)
23338889Sjdp
23438889Sjdp#ifdef _KERNEL
23538889Sjdp
23638889Sjdp#ifdef MALLOC_DECLARE
23738889SjdpMALLOC_DECLARE(M_VNODE);
23838889Sjdp#endif
23938889Sjdp
24038889Sjdp/*
24138889Sjdp * Convert between vnode types and inode formats (since POSIX.1
242130561Sobrien * defines mode word of stat structure in terms of inode formats).
24338889Sjdp */
24477298Sobrienextern enum vtype	iftovt_tab[];
24577298Sobrienextern int		vttoif_tab[];
24678828Sobrien#define IFTOVT(mode)	(iftovt_tab[((mode) & S_IFMT) >> 12])
24778828Sobrien#define VTTOIF(indx)	(vttoif_tab[(int)(indx)])
24878828Sobrien#define MAKEIMODE(indx, mode)	(int)(VTTOIF(indx) | (mode))
24978828Sobrien
25078828Sobrien/*
25178828Sobrien * Flags to various vnode functions.
25278828Sobrien */
25378828Sobrien#define	SKIPSYSTEM	0x0001	/* vflush: skip vnodes marked VSYSTEM */
25478828Sobrien#define	FORCECLOSE	0x0002	/* vflush: force file closure */
25578828Sobrien#define	WRITECLOSE	0x0004	/* vflush: only close writable files */
25678828Sobrien#define	DOCLOSE		0x0008	/* vclean: close active files */
25778828Sobrien#define	V_SAVE		0x0001	/* vinvalbuf: sync file first */
25878828Sobrien#define	REVOKEALL	0x0001	/* vop_revoke: revoke all aliases */
25978828Sobrien#define	V_WAIT		0x0001	/* vn_start_write: sleep for suspend */
26078828Sobrien#define	V_NOWAIT	0x0002	/* vn_start_write: don't sleep for suspend */
26178828Sobrien#define	V_XSLEEP	0x0004	/* vn_start_write: just return after sleep */
26277298Sobrien
26377298Sobrien#define	VREF(vp)	vref(vp)
26477298Sobrien
26578828Sobrien
26678828Sobrien#ifdef DIAGNOSTIC
26778828Sobrien#define	VATTR_NULL(vap)	vattr_null(vap)
26877298Sobrien#else
26938889Sjdp#define	VATTR_NULL(vap)	(*(vap) = va_null)	/* initialize a vattr */
27077298Sobrien#endif /* DIAGNOSTIC */
27177298Sobrien
27277298Sobrien#define	NULLVP	((struct vnode *)NULL)
27377298Sobrien
27477298Sobrien#define	VNODEOP_SET(f) \
27577298Sobrien	C_SYSINIT(f##init, SI_SUB_VFS, SI_ORDER_SECOND, vfs_add_vnodeops, &f); \
27677298Sobrien	C_SYSUNINIT(f##uninit, SI_SUB_VFS, SI_ORDER_SECOND, vfs_rm_vnodeops, &f);
27777298Sobrien
27877298Sobrien/*
27977298Sobrien * Global vnode data.
28077298Sobrien */
28177298Sobrienextern	struct vnode *rootvnode;	/* root (i.e. "/") vnode */
28277298Sobrienextern	int desiredvnodes;		/* number of vnodes desired */
28377298Sobrienextern	time_t syncdelay;		/* max time to delay syncing data */
28477298Sobrienextern	time_t filedelay;		/* time to delay syncing files */
28577298Sobrienextern	time_t dirdelay;		/* time to delay syncing directories */
28678828Sobrienextern	time_t metadelay;		/* time to delay syncing metadata */
28756944Sobrienextern	struct vm_zone *namei_zone;
28856944Sobrienextern	int prtactive;			/* nonzero to call vprint() */
28956944Sobrienextern	struct vattr va_null;		/* predefined null vattr structure */
29056944Sobrienextern	int vfs_ioopt;
29178828Sobrien
29256944Sobrien/*
29356944Sobrien * Macro/function to check for client cache inconsistency w.r.t. leasing.
29478828Sobrien */
29538889Sjdp#define	LEASE_READ	0x1		/* Check lease for readers */
29678828Sobrien#define	LEASE_WRITE	0x2		/* Check lease for modifiers */
29778828Sobrien
29856944Sobrien
29978828Sobrienextern void	(*lease_updatetime) __P((int deltat));
30078828Sobrien
30178828Sobrien#define VSHOULDFREE(vp)	\
30278828Sobrien	(!((vp)->v_flag & (VFREE|VDOOMED)) && \
30378828Sobrien	 !(vp)->v_holdcnt && !(vp)->v_usecount && \
30478828Sobrien	 (!(vp)->v_object || \
30578828Sobrien	  !((vp)->v_object->ref_count || (vp)->v_object->resident_page_count)))
30678828Sobrien
30778828Sobrien#define VSHOULDBUSY(vp)	\
30878828Sobrien	(((vp)->v_flag & VFREE) && \
30978828Sobrien	 ((vp)->v_holdcnt || (vp)->v_usecount))
31078828Sobrien
31178828Sobrien#endif /* _KERNEL */
31278828Sobrien
31378828Sobrien
31456944Sobrien/*
31578828Sobrien * Mods for extensibility.
31638889Sjdp */
31778828Sobrien
31878828Sobrien/*
31978828Sobrien * Flags for vdesc_flags:
32078828Sobrien */
32178828Sobrien#define VDESC_MAX_VPS		16
32238889Sjdp/* Low order 16 flag bits are reserved for willrele flags for vp arguments. */
32378828Sobrien#define VDESC_VP0_WILLRELE	0x0001
32478828Sobrien#define VDESC_VP1_WILLRELE	0x0002
32578828Sobrien#define VDESC_VP2_WILLRELE	0x0004
32678828Sobrien#define VDESC_VP3_WILLRELE	0x0008
32778828Sobrien#define VDESC_NOMAP_VPP		0x0100
32878828Sobrien#define VDESC_VPP_WILLRELE	0x0200
32978828Sobrien
33078828Sobrien/*
33178828Sobrien * VDESC_NO_OFFSET is used to identify the end of the offset list
33278828Sobrien * and in places where no such field exists.
33378828Sobrien */
33478828Sobrien#define VDESC_NO_OFFSET -1
33578828Sobrien
33678828Sobrien/*
33738889Sjdp * This structure describes the vnode operation taking place.
33878828Sobrien */
33978828Sobrienstruct vnodeop_desc {
34078828Sobrien	int	vdesc_offset;		/* offset in vector--first for speed */
34138889Sjdp	char    *vdesc_name;		/* a readable name for debugging */
34278828Sobrien	int	vdesc_flags;		/* VDESC_* flags */
34378828Sobrien
34438889Sjdp	/*
34578828Sobrien	 * These ops are used by bypass routines to map and locate arguments.
34638889Sjdp	 * Creds and procs are not needed in bypass routines, but sometimes
34778828Sobrien	 * they are useful to (for example) transport layers.
34878828Sobrien	 * Nameidata is useful because it has a cred in it.
34978828Sobrien	 */
35078828Sobrien	int	*vdesc_vp_offsets;	/* list ended by VDESC_NO_OFFSET */
35178828Sobrien	int	vdesc_vpp_offset;	/* return vpp location */
35238889Sjdp	int	vdesc_cred_offset;	/* cred location, if any */
35378828Sobrien	int	vdesc_proc_offset;	/* proc location, if any */
35478828Sobrien	int	vdesc_componentname_offset; /* if any */
355130561Sobrien	/*
356130561Sobrien	 * Finally, we've got a list of private data (about each operation)
35778828Sobrien	 * for each transport layer.  (Support to manage this list is not
35878828Sobrien	 * yet part of BSD.)
35978828Sobrien	 */
36078828Sobrien	caddr_t	*vdesc_transports;
36178828Sobrien};
36278828Sobrien
36338889Sjdp#ifdef _KERNEL
364104834Sobrien/*
36578828Sobrien * A list of all the operation descs.
36678828Sobrien */
36778828Sobrienextern struct vnodeop_desc *vnodeop_descs[];
36878828Sobrien
36938889Sjdp/*
37078828Sobrien * Interlock for scanning list of vnodes attached to a mountpoint
37178828Sobrien */
37278828Sobrienextern struct simplelock mntvnode_slock;
37378828Sobrien
37478828Sobrien/*
37578828Sobrien * This macro is very helpful in defining those offsets in the vdesc struct.
37638889Sjdp *
37778828Sobrien * This is stolen from X11R4.  I ignored all the fancy stuff for
37878828Sobrien * Crays, so if you decide to port this to such a serious machine,
37978828Sobrien * you might want to consult Intrinsic.h's XtOffset{,Of,To}.
38078828Sobrien */
38178828Sobrien#define VOPARG_OFFSET(p_type,field) \
38278828Sobrien        ((int) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
38338889Sjdp#define VOPARG_OFFSETOF(s_type,field) \
38478828Sobrien	VOPARG_OFFSET(s_type*,field)
38538889Sjdp#define VOPARG_OFFSETTO(S_TYPE,S_OFFSET,STRUCT_P) \
38678828Sobrien	((S_TYPE)(((char*)(STRUCT_P))+(S_OFFSET)))
38778828Sobrien
38878828Sobrien
38978828Sobrien/*
39078828Sobrien * This structure is used to configure the new vnodeops vector.
39178828Sobrien */
39278828Sobrienstruct vnodeopv_entry_desc {
39378828Sobrien	struct vnodeop_desc *opve_op;   /* which operation this is */
39478828Sobrien	vop_t *opve_impl;		/* code implementing this operation */
39578828Sobrien};
39678828Sobrienstruct vnodeopv_desc {
39778828Sobrien			/* ptr to the ptr to the vector where op should go */
39878828Sobrien	vop_t ***opv_desc_vector_p;
39978828Sobrien	struct vnodeopv_entry_desc *opv_desc_ops;   /* null terminated list */
40078828Sobrien};
40178828Sobrien
40278828Sobrien/*
40378828Sobrien * A generic structure.
40478828Sobrien * This can be used by bypass routines to identify generic arguments.
40578828Sobrien */
40678828Sobrienstruct vop_generic_args {
40778828Sobrien	struct vnodeop_desc *a_desc;
40878828Sobrien	/* other random data follows, presumably */
40978828Sobrien};
41078828Sobrien
41178828Sobrien
41278828Sobrien#ifdef DEBUG_VFS_LOCKS
41378828Sobrien/*
41478828Sobrien * Macros to aid in tracing VFS locking problems.  Not totally
41578828Sobrien * reliable since if the process sleeps between changing the lock
41678828Sobrien * state and checking it with the assert, some other process could
41778828Sobrien * change the state.  They are good enough for debugging a single
41878828Sobrien * filesystem using a single-threaded test.  I find that 'cvs co src'
41978828Sobrien * is a pretty good test.
42078828Sobrien */
42178828Sobrien
42278828Sobrien/*
42378828Sobrien * [dfr] Kludge until I get around to fixing all the vfs locking.
42438889Sjdp */
42578828Sobrien#define IS_LOCKING_VFS(vp)	((vp)->v_tag == VT_UFS		\
42678828Sobrien				 || (vp)->v_tag == VT_MFS	\
42778828Sobrien				 || (vp)->v_tag == VT_NFS	\
42878828Sobrien				 || (vp)->v_tag == VT_LFS	\
42938889Sjdp				 || (vp)->v_tag == VT_ISOFS	\
43078828Sobrien				 || (vp)->v_tag == VT_MSDOSFS	\
43178828Sobrien				 || (vp)->v_tag == VT_DEVFS)
43278828Sobrien
43378828Sobrien#define ASSERT_VOP_LOCKED(vp, str)					\
43478828Sobriendo {									\
43578828Sobrien	struct vnode *_vp = (vp);					\
43678828Sobrien									\
43778828Sobrien	if (_vp && IS_LOCKING_VFS(_vp) && !VOP_ISLOCKED(_vp, NULL))	\
43878828Sobrien		panic("%s: %p is not locked but should be", str, _vp);	\
43938889Sjdp} while (0)
44038889Sjdp
44138889Sjdp#define ASSERT_VOP_UNLOCKED(vp, str)					\
44238889Sjdpdo {									\
44338889Sjdp	struct vnode *_vp = (vp);					\
44438889Sjdp	int lockstate;							\
44538889Sjdp									\
44678828Sobrien	if (_vp && IS_LOCKING_VFS(_vp)) {				\
44738889Sjdp		lockstate = VOP_ISLOCKED(_vp, curproc);			\
44838889Sjdp		if (lockstate == LK_EXCLUSIVE)				\
449130561Sobrien			panic("%s: %p is locked but should not be",	\
45038889Sjdp			    str, _vp);					\
45138889Sjdp	}								\
45278828Sobrien} while (0)
45338889Sjdp
45438889Sjdp#define ASSERT_VOP_ELOCKED(vp, str)					\
45589857Sobriendo {									\
45638889Sjdp	struct vnode *_vp = (vp);					\
45778828Sobrien									\
45838889Sjdp	if (_vp && IS_LOCKING_VFS(_vp) &&				\
45938889Sjdp	    VOP_ISLOCKED(_vp, curproc) != LK_EXCLUSIVE)			\
46038889Sjdp		panic("%s: %p is not exclusive locked but should be",	\
46138889Sjdp		    str, _vp);						\
46238889Sjdp} while (0)
46338889Sjdp
46438889Sjdp#define ASSERT_VOP_ELOCKED_OTHER(vp, str)				\
46538889Sjdpdo {									\
46678828Sobrien	struct vnode *_vp = (vp);					\
46738889Sjdp									\
46838889Sjdp	if (_vp && IS_LOCKING_VFS(_vp) &&				\
46938889Sjdp	    VOP_ISLOCKED(_vp, curproc) != LK_EXCLOTHER)			\
47038889Sjdp		panic("%s: %p is not exclusive locked by another proc",	\
47138889Sjdp		    str, _vp);						\
47278828Sobrien} while (0)
47378828Sobrien
47438889Sjdp#define ASSERT_VOP_SLOCKED(vp, str)					\
47538889Sjdpdo {									\
476130561Sobrien	struct vnode *_vp = (vp);					\
47738889Sjdp									\
47838889Sjdp	if (_vp && IS_LOCKING_VFS(_vp) &&				\
47938889Sjdp	    VOP_ISLOCKED(_vp, NULL) != LK_SHARED)			\
48078828Sobrien		panic("%s: %p is not locked shared but should be",	\
48138889Sjdp		    str, _vp);						\
48238889Sjdp} while (0)
48338889Sjdp
48438889Sjdp#else
48538889Sjdp
48638889Sjdp#define ASSERT_VOP_LOCKED(vp, str)
48778828Sobrien#define ASSERT_VOP_UNLOCKED(vp, str)
48838889Sjdp
48938889Sjdp#endif
490130561Sobrien
49138889Sjdp/*
49238889Sjdp * VOCALL calls an op given an ops vector.  We break it out because BSD's
49338889Sjdp * vclean changes the ops vector and then wants to call ops with the old
49438889Sjdp * vector.
49538889Sjdp */
49638889Sjdp#define VOCALL(OPSV,OFF,AP) (( *((OPSV)[(OFF)])) (AP))
49738889Sjdp
49838889Sjdp/*
49989857Sobrien * This call works for vnodes in the kernel.
50038889Sjdp */
50178828Sobrien#define VCALL(VP,OFF,AP) VOCALL((VP)->v_op,(OFF),(AP))
50238889Sjdp#define VDESC(OP) (& __CONCAT(OP,_desc))
50378828Sobrien#define VOFFSET(OP) (VDESC(OP)->vdesc_offset)
50478828Sobrien
50578828Sobrien/*
50678828Sobrien * VMIO support inline
50778828Sobrien */
50878828Sobrien
50978828Sobrienextern int vmiodirenable;
51038889Sjdp
51178828Sobrienstatic __inline int
51238889Sjdpvn_canvmio(struct vnode *vp)
51338889Sjdp{
51438889Sjdp    if (vp && (vp->v_type == VREG || (vmiodirenable && vp->v_type == VDIR)))
51578828Sobrien        return(TRUE);
51678828Sobrien    return(FALSE);
51778828Sobrien}
51838889Sjdp
51938889Sjdp/*
52038889Sjdp * Finally, include the default set of vnode operations.
52178828Sobrien */
52278828Sobrien#include "vnode_if.h"
52378828Sobrien
52478828Sobrien/*
52578828Sobrien * Public vnode manipulation functions.
52638889Sjdp */
52738889Sjdpstruct componentname;
52878828Sobrienstruct file;
52938889Sjdpstruct mount;
53078828Sobrienstruct nameidata;
53138889Sjdpstruct ostat;
53238889Sjdpstruct proc;
533struct stat;
534struct nstat;
535struct ucred;
536struct uio;
537struct vattr;
538struct vnode;
539struct vop_bwrite_args;
540
541extern int	(*lease_check_hook) __P((struct vop_lease_args *));
542
543struct	vnode *addaliasu __P((struct vnode *vp, udev_t nvp_rdev));
544int 	bdevvp __P((dev_t dev, struct vnode **vpp));
545/* cache_* may belong in namei.h. */
546void	cache_enter __P((struct vnode *dvp, struct vnode *vp,
547	    struct componentname *cnp));
548int	cache_lookup __P((struct vnode *dvp, struct vnode **vpp,
549	    struct componentname *cnp));
550void	cache_purge __P((struct vnode *vp));
551void	cache_purgevfs __P((struct mount *mp));
552void	cvtstat __P((struct stat *st, struct ostat *ost));
553void	cvtnstat __P((struct stat *sb, struct nstat *nsb));
554int 	getnewvnode __P((enum vtagtype tag,
555	    struct mount *mp, vop_t **vops, struct vnode **vpp));
556int	lease_check __P((struct vop_lease_args *ap));
557int	spec_vnoperate __P((struct vop_generic_args *));
558int	speedup_syncer __P((void));
559int	textvp_fullpath __P((struct proc *p, char **retbuf, char **retfreebuf));
560int	vaccess __P((enum vtype type, mode_t file_mode, uid_t uid, gid_t gid,
561	    mode_t acc_mode, struct ucred *cred, int *privused));
562void 	vattr_null __P((struct vattr *vap));
563int 	vcount __P((struct vnode *vp));
564void	vdrop __P((struct vnode *));
565int	vfinddev __P((dev_t dev, enum vtype type, struct vnode **vpp));
566void	vfs_add_vnodeops __P((const void *));
567void	vfs_rm_vnodeops __P((const void *));
568int	vflush __P((struct mount *mp, struct vnode *skipvp, int flags));
569int 	vget __P((struct vnode *vp, int lockflag, struct proc *p));
570void 	vgone __P((struct vnode *vp));
571void	vgonel __P((struct vnode *vp, struct proc *p));
572void	vhold __P((struct vnode *));
573int	vinvalbuf __P((struct vnode *vp, int save, struct ucred *cred,
574
575	    struct proc *p, int slpflag, int slptimeo));
576int	vtruncbuf __P((struct vnode *vp, struct ucred *cred, struct proc *p,
577		off_t length, int blksize));
578void	vprint __P((char *label, struct vnode *vp));
579int	vrecycle __P((struct vnode *vp, struct simplelock *inter_lkp,
580	    struct proc *p));
581int 	vn_close __P((struct vnode *vp,
582	    int flags, struct ucred *cred, struct proc *p));
583void	vn_finished_write __P((struct mount *mp));
584int	vn_isdisk __P((struct vnode *vp, int *errp));
585int	vn_lock __P((struct vnode *vp, int flags, struct proc *p));
586#ifdef	DEBUG_LOCKS
587int	debug_vn_lock __P((struct vnode *vp, int flags, struct proc *p,
588	    const char *filename, int line));
589#define vn_lock(vp,flags,p) debug_vn_lock(vp,flags,p,__FILE__,__LINE__)
590#endif
591int 	vn_open __P((struct nameidata *ndp, int *flagp, int cmode));
592void	vn_pollevent __P((struct vnode *vp, int events));
593void	vn_pollgone __P((struct vnode *vp));
594int	vn_pollrecord __P((struct vnode *vp, struct proc *p, int events));
595int 	vn_rdwr __P((enum uio_rw rw, struct vnode *vp, caddr_t base,
596	    int len, off_t offset, enum uio_seg segflg, int ioflg,
597	    struct ucred *cred, int *aresid, struct proc *p));
598int	vn_stat __P((struct vnode *vp, struct stat *sb, struct proc *p));
599int	vn_start_write __P((struct vnode *vp, struct mount **mpp, int flags));
600dev_t	vn_todev __P((struct vnode *vp));
601int	vn_write_suspend_wait __P((struct vnode *vp, struct mount *mp,
602		int flags));
603int 	vn_writechk __P((struct vnode *vp));
604int	vn_extattr_get __P((struct vnode *vp, int ioflg, const char *attrname,
605		int *buflen, char *buf, struct proc *p));
606int	vn_extattr_set __P((struct vnode *vp, int ioflg, const char *attrname,
607		int buflen, char *buf, struct proc *p));
608int	vn_extattr_rm(struct vnode *vp, int ioflg, const char *attrname,
609		struct proc *p);
610int	vfs_cache_lookup __P((struct vop_lookup_args *ap));
611int	vfs_object_create __P((struct vnode *vp, struct proc *p,
612                struct ucred *cred));
613void	vfs_timestamp __P((struct timespec *));
614void	vfs_write_resume __P((struct mount *mp));
615void	vfs_write_suspend __P((struct mount *mp));
616int	vop_stdbwrite __P((struct vop_bwrite_args *ap));
617int	vop_stdgetwritemount __P((struct vop_getwritemount_args *));
618int	vop_stdinactive __P((struct vop_inactive_args *));
619int	vop_stdislocked __P((struct vop_islocked_args *));
620int	vop_stdlock __P((struct vop_lock_args *));
621int	vop_stdunlock __P((struct vop_unlock_args *));
622int	vop_noislocked __P((struct vop_islocked_args *));
623int	vop_nolock __P((struct vop_lock_args *));
624int	vop_nopoll __P((struct vop_poll_args *));
625int	vop_nounlock __P((struct vop_unlock_args *));
626int	vop_stdpathconf __P((struct vop_pathconf_args *));
627int	vop_stdpoll __P((struct vop_poll_args *));
628int	vop_revoke __P((struct vop_revoke_args *));
629int	vop_sharedlock __P((struct vop_lock_args *));
630int	vop_eopnotsupp __P((struct vop_generic_args *ap));
631int	vop_ebadf __P((struct vop_generic_args *ap));
632int	vop_einval __P((struct vop_generic_args *ap));
633int	vop_enotty __P((struct vop_generic_args *ap));
634int	vop_defaultop __P((struct vop_generic_args *ap));
635int	vop_null __P((struct vop_generic_args *ap));
636int	vop_panic __P((struct vop_generic_args *ap));
637int	vop_stdcreatevobject __P((struct vop_createvobject_args *ap));
638int	vop_stddestroyvobject __P((struct vop_destroyvobject_args *ap));
639int	vop_stdgetvobject __P((struct vop_getvobject_args *ap));
640
641void	vfree __P((struct vnode *));
642void 	vput __P((struct vnode *vp));
643void 	vrele __P((struct vnode *vp));
644void	vref __P((struct vnode *vp));
645void	vbusy __P((struct vnode *vp));
646
647extern	vop_t **default_vnodeop_p;
648extern	vop_t **spec_vnodeop_p;
649extern	vop_t **dead_vnodeop_p;
650
651#endif /* _KERNEL */
652
653#endif /* !_SYS_VNODE_H_ */
654