vnode.h revision 83366
1193850Strasz/* 2197405Strasz * Copyright (c) 1989, 1993 3193850Strasz * The Regents of the University of California. All rights reserved. 4193850Strasz * 5193850Strasz * Redistribution and use in source and binary forms, with or without 6193850Strasz * modification, are permitted provided that the following conditions 7193850Strasz * are met: 8193850Strasz * 1. Redistributions of source code must retain the above copyright 9193850Strasz * notice, this list of conditions and the following disclaimer. 10193850Strasz * 2. Redistributions in binary form must reproduce the above copyright 11193850Strasz * notice, this list of conditions and the following disclaimer in the 12193850Strasz * documentation and/or other materials provided with the distribution. 13193850Strasz * 3. All advertising materials mentioning features or use of this software 14193850Strasz * must display the following acknowledgement: 15193850Strasz * This product includes software developed by the University of 16193850Strasz * California, Berkeley and its contributors. 17193850Strasz * 4. Neither the name of the University nor the names of its contributors 18193850Strasz * may be used to endorse or promote products derived from this software 19193850Strasz * without specific prior written permission. 20193850Strasz * 21193850Strasz * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22193850Strasz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23193850Strasz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24193850Strasz * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25193850Strasz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26193850Strasz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27193850Strasz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28193850Strasz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29193850Strasz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30193850Strasz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31193850Strasz * SUCH DAMAGE. 32193850Strasz * 33193850Strasz * @(#)vnode.h 8.7 (Berkeley) 2/4/94 34193850Strasz * $FreeBSD: head/sys/sys/vnode.h 83366 2001-09-12 08:38:13Z julian $ 35193850Strasz */ 36193850Strasz 37193850Strasz#ifndef _SYS_VNODE_H_ 38193850Strasz#define _SYS_VNODE_H_ 39193850Strasz 40193850Strasz/* 41193850Strasz * XXX - compatability until lockmgr() goes away or all the #includes are 42193850Strasz * updated. 43193850Strasz */ 44193850Strasz#include <sys/lockmgr.h> 45193850Strasz 46193850Strasz#include <sys/queue.h> 47193850Strasz#include <sys/_lock.h> 48193850Strasz#include <sys/_mutex.h> 49193850Strasz#include <sys/selinfo.h> 50193850Strasz#include <sys/uio.h> 51193850Strasz#include <sys/acl.h> 52197405Strasz 53193850Strasz/* 54197405Strasz * The vnode is the focus of all file activity in UNIX. There is a 55197405Strasz * unique vnode allocated for each active file, each current directory, 56197405Strasz * each mounted-on file, text file, and the root. 57197405Strasz */ 58197405Strasz 59197405Strasz/* 60197405Strasz * Vnode types. VNON means no type. 61197405Strasz */ 62197405Straszenum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD }; 63197405Strasz 64197405Strasz/* 65197405Strasz * Vnode tag types. 66197405Strasz * These are for the benefit of external programs only (e.g., pstat) 67197405Strasz * and should NEVER be inspected by the kernel. 68197405Strasz */ 69197405Straszenum vtagtype { 70197405Strasz VT_NON, VT_UFS, VT_NFS, VT_UNUSED, VT_PC, VT_LFS, VT_LOFS, VT_FDESC, 71197405Strasz VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS, 72197405Strasz VT_UNION, VT_MSDOSFS, VT_DEVFS, VT_TFS, VT_VFS, VT_CODA, VT_NTFS, 73197405Strasz VT_HPFS, VT_NWFS, VT_PSEUDOFS, VT_SMBFS 74197405Strasz}; 75193850Strasz 76197405Strasz/* 77197405Strasz * Each underlying filesystem allocates its own private area and hangs 78197405Strasz * it from v_data. If non-null, this area is freed in getnewvnode(). 79197405Strasz */ 80197405StraszTAILQ_HEAD(buflists, buf); 81197405Strasz 82197405Strasztypedef int vop_t __P((void *)); 83197405Straszstruct namecache; 84197405Strasz 85200723Strasz/* 86200723Strasz * Reading or writing any of these items requires holding the appropriate lock. 87200723Strasz * v_freelist is locked by the global vnode_free_list mutex. 88200723Strasz * v_mntvnodes is locked by the global mntvnodes mutex. 89200723Strasz * v_flag, v_usecount, v_holdcount and v_writecount are 90200723Strasz * locked by the v_interlock mutex. 91200723Strasz * v_pollinfo is locked by the lock contained inside it. 92197405Strasz */ 93197405Straszstruct vnode { 94197405Strasz u_long v_flag; /* vnode flags (see below) */ 95197405Strasz int v_usecount; /* reference count of users */ 96197405Strasz int v_writecount; /* reference count of writers */ 97197405Strasz int v_holdcnt; /* page & buffer references */ 98197405Strasz u_long v_id; /* capability identifier */ 99197405Strasz struct mount *v_mount; /* ptr to vfs we are in */ 100197405Strasz vop_t **v_op; /* vnode operations vector */ 101197405Strasz TAILQ_ENTRY(vnode) v_freelist; /* vnode freelist */ 102197405Strasz LIST_ENTRY(vnode) v_mntvnodes; /* vnodes for mount point */ 103197405Strasz struct buflists v_cleanblkhd; /* clean blocklist head */ 104197405Strasz struct buflists v_dirtyblkhd; /* dirty blocklist head */ 105197405Strasz LIST_ENTRY(vnode) v_synclist; /* vnodes with dirty buffers */ 106197405Strasz long v_numoutput; /* num of writes in progress */ 107197405Strasz enum vtype v_type; /* vnode type */ 108197405Strasz union { 109197405Strasz struct mount *vu_mountedhere;/* ptr to mounted vfs (VDIR) */ 110197405Strasz struct socket *vu_socket; /* unix ipc (VSOCK) */ 111197405Strasz struct { 112197405Strasz struct specinfo *vu_specinfo; /* device (VCHR, VBLK) */ 113197405Strasz SLIST_ENTRY(vnode) vu_specnext; 114197405Strasz } vu_spec; 115197405Strasz struct fifoinfo *vu_fifoinfo; /* fifo (VFIFO) */ 116197405Strasz } v_un; 117197405Strasz struct nqlease *v_lease; /* Soft reference to lease */ 118197405Strasz daddr_t v_lastw; /* last write (write cluster) */ 119197405Strasz daddr_t v_cstart; /* start block of cluster */ 120197405Strasz daddr_t v_lasta; /* last allocation */ 121197405Strasz int v_clen; /* length of current cluster */ 122197405Strasz struct vm_object *v_object; /* Place to store VM object */ 123197405Strasz struct mtx v_interlock; /* lock on usecount and flag */ 124197405Strasz struct lock v_lock; /* used if fs don't have one */ 125197405Strasz struct lock *v_vnlock; /* pointer to vnode lock */ 126197405Strasz enum vtagtype v_tag; /* type of underlying data */ 127197405Strasz void *v_data; /* private data for fs */ 128197405Strasz LIST_HEAD(, namecache) v_cache_src; /* Cache entries from us */ 129197405Strasz TAILQ_HEAD(, namecache) v_cache_dst; /* Cache entries to us */ 130197405Strasz struct vnode *v_dd; /* .. vnode */ 131197405Strasz u_long v_ddid; /* .. capability identifier */ 132197405Strasz struct { 133197405Strasz struct mtx vpi_lock; /* lock to protect below */ 134197405Strasz struct selinfo vpi_selinfo; /* identity of poller(s) */ 135197405Strasz short vpi_events; /* what they are looking for */ 136197405Strasz short vpi_revents; /* what has happened */ 137197405Strasz } v_pollinfo; 138197405Strasz struct thread *v_vxproc; /* thread owning VXLOCK */ 139197405Strasz#ifdef DEBUG_LOCKS 140197405Strasz const char *filename; /* Source file doing locking */ 141197405Strasz int line; /* Line number doing locking */ 142197405Strasz#endif 143197405Strasz}; 144197405Strasz#define v_mountedhere v_un.vu_mountedhere 145197405Strasz#define v_socket v_un.vu_socket 146197405Strasz#define v_rdev v_un.vu_spec.vu_specinfo 147197405Strasz#define v_specnext v_un.vu_spec.vu_specnext 148197405Strasz#define v_fifoinfo v_un.vu_fifoinfo 149197405Strasz 150197405Strasz#define VN_POLLEVENT(vp, events) \ 151197405Strasz do { \ 152197405Strasz if ((vp)->v_pollinfo.vpi_events & (events)) \ 153197405Strasz vn_pollevent((vp), (events)); \ 154197405Strasz } while (0) 155197405Strasz 156197405Strasz/* 157197405Strasz * Vnode flags. 158197405Strasz */ 159197405Strasz#define VROOT 0x00001 /* root of its file system */ 160197405Strasz#define VTEXT 0x00002 /* vnode is a pure text prototype */ 161197405Strasz#define VSYSTEM 0x00004 /* vnode being used by kernel */ 162197405Strasz#define VISTTY 0x00008 /* vnode represents a tty */ 163197405Strasz#define VXLOCK 0x00100 /* vnode is locked to change underlying type */ 164197405Strasz#define VXWANT 0x00200 /* thread is waiting for vnode */ 165214522Strasz#define VBWAIT 0x00400 /* waiting for output to complete */ 166197405Strasz#define VNOSYNC 0x01000 /* unlinked, stop syncing */ 167201019Strasz/* open for business 0x01000 */ 168201019Strasz#define VOBJBUF 0x02000 /* Allocate buffers in VM object */ 169201019Strasz#define VCOPYONWRITE 0x04000 /* vnode is doing copy-on-write */ 170201019Strasz#define VAGE 0x08000 /* Insert vnode at head of free list */ 171201019Strasz#define VOLOCK 0x10000 /* vnode is locked waiting for an object */ 172201019Strasz#define VOWANT 0x20000 /* a thread is waiting for VOLOCK */ 173201019Strasz#define VDOOMED 0x40000 /* This vnode is being recycled */ 174201019Strasz#define VFREE 0x80000 /* This vnode is on the freelist */ 175197405Strasz/* open for business 0x100000 */ 176197405Strasz#define VONWORKLST 0x200000 /* On syncer work-list */ 177197405Strasz#define VMOUNT 0x400000 /* Mount in progress */ 178197405Strasz 179197405Strasz/* 180197405Strasz * Vnode attributes. A field value of VNOVAL represents a field whose value 181197405Strasz * is unavailable (getattr) or which is not to be changed (setattr). 182197405Strasz */ 183197405Straszstruct vattr { 184197405Strasz enum vtype va_type; /* vnode type (for create) */ 185197405Strasz u_short va_mode; /* files access mode and type */ 186197405Strasz short va_nlink; /* number of references to file */ 187197405Strasz uid_t va_uid; /* owner user id */ 188197405Strasz gid_t va_gid; /* owner group id */ 189197405Strasz udev_t va_fsid; /* file system id */ 190197405Strasz long va_fileid; /* file id */ 191197405Strasz u_quad_t va_size; /* file size in bytes */ 192197405Strasz long va_blocksize; /* blocksize preferred for i/o */ 193197405Strasz struct timespec va_atime; /* time of last access */ 194197405Strasz struct timespec va_mtime; /* time of last modification */ 195197405Strasz struct timespec va_ctime; /* time file changed */ 196197405Strasz u_long va_gen; /* generation number of file */ 197197405Strasz u_long va_flags; /* flags defined for file */ 198197405Strasz udev_t va_rdev; /* device the special file represents */ 199197405Strasz u_quad_t va_bytes; /* bytes of disk space held by file */ 200197405Strasz u_quad_t va_filerev; /* file modification number */ 201197405Strasz u_int va_vaflags; /* operations flags, see below */ 202197405Strasz long va_spare; /* remain quad aligned */ 203197405Strasz}; 204197405Strasz 205197405Strasz/* 206197405Strasz * Flags for va_vaflags. 207197405Strasz */ 208197405Strasz#define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */ 209197405Strasz#define VA_EXCLUSIVE 0x02 /* exclusive create request */ 210197405Strasz 211197405Strasz/* 212197405Strasz * Flags for ioflag. (high 16 bits used to ask for read-ahead and 213197405Strasz * help with write clustering) 214197405Strasz */ 215197405Strasz#define IO_UNIT 0x01 /* do I/O as atomic unit */ 216197405Strasz#define IO_APPEND 0x02 /* append write to end */ 217197405Strasz#define IO_SYNC 0x04 /* do I/O synchronously */ 218197405Strasz#define IO_NODELOCKED 0x08 /* underlying node already locked */ 219197405Strasz#define IO_NDELAY 0x10 /* FNDELAY flag set in file table */ 220212002Sjh#define IO_VMIO 0x20 /* data already in VMIO space */ 221212002Sjh#define IO_INVAL 0x40 /* invalidate after I/O */ 222212002Sjh#define IO_ASYNC 0x80 /* bawrite rather then bdwrite */ 223212002Sjh#define IO_DIRECT 0x100 /* attempt to bypass buffer cache */ 224212002Sjh 225212002Sjh/* 226212002Sjh * Modes. Some values same as Ixxx entries from inode.h for now. 227212002Sjh */ 228212002Sjh#define VADMIN 010000 /* permission to administer vnode */ 229212002Sjh#define VSUID 004000 /* set user id on execution */ 230212002Sjh#define VSGID 002000 /* set group id on execution */ 231197405Strasz#define VSVTX 001000 /* save swapped text even after use */ 232197405Strasz#define VREAD 000400 /* read, write, execute permissions */ 233197405Strasz#define VWRITE 000200 234197405Strasz#define VEXEC 000100 235197405Strasz 236197405Strasz/* 237197405Strasz * Token indicating no attribute value yet assigned. 238197405Strasz */ 239197405Strasz#define VNOVAL (-1) 240197405Strasz 241197405Strasz#ifdef _KERNEL 242197405Strasz 243197405Strasz#ifdef MALLOC_DECLARE 244197405StraszMALLOC_DECLARE(M_VNODE); 245197405Strasz#endif 246197405Strasz 247197405Strasz/* 248197405Strasz * Convert between vnode types and inode formats (since POSIX.1 249197405Strasz * defines mode word of stat structure in terms of inode formats). 250197405Strasz */ 251212002Sjhextern enum vtype iftovt_tab[]; 252212002Sjhextern int vttoif_tab[]; 253212002Sjh#define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12]) 254212002Sjh#define VTTOIF(indx) (vttoif_tab[(int)(indx)]) 255212002Sjh#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) 256212002Sjh 257212002Sjh/* 258212002Sjh * Flags to various vnode functions. 259197405Strasz */ 260197405Strasz#define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */ 261197405Strasz#define FORCECLOSE 0x0002 /* vflush: force file closure */ 262197405Strasz#define WRITECLOSE 0x0004 /* vflush: only close writable files */ 263197405Strasz#define DOCLOSE 0x0008 /* vclean: close active files */ 264197405Strasz#define V_SAVE 0x0001 /* vinvalbuf: sync file first */ 265197405Strasz#define REVOKEALL 0x0001 /* vop_revoke: revoke all aliases */ 266197405Strasz#define V_WAIT 0x0001 /* vn_start_write: sleep for suspend */ 267197405Strasz#define V_NOWAIT 0x0002 /* vn_start_write: don't sleep for suspend */ 268197405Strasz#define V_XSLEEP 0x0004 /* vn_start_write: just return after sleep */ 269197405Strasz 270197405Strasz#define VREF(vp) vref(vp) 271197405Strasz 272197405Strasz 273197405Strasz#ifdef DIAGNOSTIC 274197405Strasz#define VATTR_NULL(vap) vattr_null(vap) 275197405Strasz#else 276197405Strasz#define VATTR_NULL(vap) (*(vap) = va_null) /* initialize a vattr */ 277197405Strasz#endif /* DIAGNOSTIC */ 278197405Strasz 279197405Strasz#define NULLVP ((struct vnode *)NULL) 280197405Strasz 281197405Strasz#define VNODEOP_SET(f) \ 282197405Strasz C_SYSINIT(f##init, SI_SUB_VFS, SI_ORDER_SECOND, vfs_add_vnodeops, &f); \ 283197405Strasz C_SYSUNINIT(f##uninit, SI_SUB_VFS, SI_ORDER_SECOND, vfs_rm_vnodeops, &f); 284197405Strasz 285197405Strasz/* 286197405Strasz * Global vnode data. 287197405Strasz */ 288197405Straszextern struct vnode *rootvnode; /* root (i.e. "/") vnode */ 289197405Straszextern int desiredvnodes; /* number of vnodes desired */ 290197405Straszextern time_t syncdelay; /* max time to delay syncing data */ 291197405Straszextern time_t filedelay; /* time to delay syncing files */ 292197405Straszextern time_t dirdelay; /* time to delay syncing directories */ 293197405Straszextern time_t metadelay; /* time to delay syncing metadata */ 294193850Straszextern struct vm_zone *namei_zone; 295193850Straszextern int prtactive; /* nonzero to call vprint() */ 296193850Straszextern struct vattr va_null; /* predefined null vattr structure */ 297193850Straszextern int vfs_ioopt; 298193850Strasz 299193850Strasz/* 300193850Strasz * Macro/function to check for client cache inconsistency w.r.t. leasing. 301193850Strasz */ 302193850Strasz#define LEASE_READ 0x1 /* Check lease for readers */ 303193850Strasz#define LEASE_WRITE 0x2 /* Check lease for modifiers */ 304193850Strasz 305193850Strasz 306193850Straszextern void (*lease_updatetime) __P((int deltat)); 307193850Strasz 308193850Strasz#define VSHOULDFREE(vp) \ 309193850Strasz (!((vp)->v_flag & (VFREE|VDOOMED)) && \ 310193850Strasz !(vp)->v_holdcnt && !(vp)->v_usecount && \ 311193850Strasz (!(vp)->v_object || \ 312193850Strasz !((vp)->v_object->ref_count || (vp)->v_object->resident_page_count))) 313193850Strasz 314193850Strasz#define VSHOULDBUSY(vp) \ 315193850Strasz (((vp)->v_flag & VFREE) && \ 316193850Strasz ((vp)->v_holdcnt || (vp)->v_usecount)) 317193850Strasz 318193850Strasz#define VI_LOCK(vp) mtx_lock(&(vp)->v_interlock) 319193850Strasz#define VI_TRYLOCK(vp) mtx_trylock(&(vp)->v_interlock) 320193850Strasz#define VI_UNLOCK(vp) mtx_unlock(&(vp)->v_interlock) 321193850Strasz 322193850Strasz#endif /* _KERNEL */ 323193850Strasz 324193850Strasz 325193850Strasz/* 326193850Strasz * Mods for extensibility. 327193850Strasz */ 328193850Strasz 329193850Strasz/* 330193850Strasz * Flags for vdesc_flags: 331193850Strasz */ 332193850Strasz#define VDESC_MAX_VPS 16 333193850Strasz/* Low order 16 flag bits are reserved for willrele flags for vp arguments. */ 334193850Strasz#define VDESC_VP0_WILLRELE 0x0001 335193850Strasz#define VDESC_VP1_WILLRELE 0x0002 336193850Strasz#define VDESC_VP2_WILLRELE 0x0004 337193850Strasz#define VDESC_VP3_WILLRELE 0x0008 338193850Strasz#define VDESC_NOMAP_VPP 0x0100 339193850Strasz#define VDESC_VPP_WILLRELE 0x0200 340193850Strasz 341193850Strasz/* 342193850Strasz * VDESC_NO_OFFSET is used to identify the end of the offset list 343193850Strasz * and in places where no such field exists. 344193850Strasz */ 345193850Strasz#define VDESC_NO_OFFSET -1 346193850Strasz 347193850Strasz/* 348193850Strasz * This structure describes the vnode operation taking place. 349193850Strasz */ 350193850Straszstruct vnodeop_desc { 351193850Strasz int vdesc_offset; /* offset in vector,first for speed */ 352212906Strasz char *vdesc_name; /* a readable name for debugging */ 353212906Strasz int vdesc_flags; /* VDESC_* flags */ 354212906Strasz 355212906Strasz /* 356212906Strasz * These ops are used by bypass routines to map and locate arguments. 357212906Strasz * Creds and procs are not needed in bypass routines, but sometimes 358193850Strasz * they are useful to (for example) transport layers. 359212906Strasz * Nameidata is useful because it has a cred in it. 360212906Strasz */ 361212906Strasz int *vdesc_vp_offsets; /* list ended by VDESC_NO_OFFSET */ 362212906Strasz int vdesc_vpp_offset; /* return vpp location */ 363212906Strasz int vdesc_cred_offset; /* cred location, if any */ 364212906Strasz int vdesc_thread_offset; /* thread location, if any */ 365212906Strasz int vdesc_componentname_offset; /* if any */ 366212906Strasz /* 367212906Strasz * Finally, we've got a list of private data (about each operation) 368212906Strasz * for each transport layer. (Support to manage this list is not 369212906Strasz * yet part of BSD.) 370212906Strasz */ 371212906Strasz caddr_t *vdesc_transports; 372212906Strasz}; 373212906Strasz 374212906Strasz#ifdef _KERNEL 375212906Strasz/* 376212906Strasz * A list of all the operation descs. 377212906Strasz */ 378212906Straszextern struct vnodeop_desc *vnodeop_descs[]; 379212906Strasz 380212906Strasz/* 381212906Strasz * Interlock for scanning list of vnodes attached to a mountpoint 382212906Strasz */ 383212906Straszextern struct mtx mntvnode_mtx; 384212906Strasz 385212906Strasz/* 386212906Strasz * This macro is very helpful in defining those offsets in the vdesc struct. 387212906Strasz * 388212906Strasz * This is stolen from X11R4. I ignored all the fancy stuff for 389212906Strasz * Crays, so if you decide to port this to such a serious machine, 390212906Strasz * you might want to consult Intrinsic.h's XtOffset{,Of,To}. 391212906Strasz */ 392212906Strasz#define VOPARG_OFFSET(p_type,field) \ 393212906Strasz ((int) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL))) 394212906Strasz#define VOPARG_OFFSETOF(s_type,field) \ 395212906Strasz VOPARG_OFFSET(s_type*,field) 396212906Strasz#define VOPARG_OFFSETTO(S_TYPE,S_OFFSET,STRUCT_P) \ 397212906Strasz ((S_TYPE)(((char*)(STRUCT_P))+(S_OFFSET))) 398212906Strasz 399212906Strasz 400212906Strasz/* 401212906Strasz * This structure is used to configure the new vnodeops vector. 402212906Strasz */ 403212906Straszstruct vnodeopv_entry_desc { 404212906Strasz struct vnodeop_desc *opve_op; /* which operation this is */ 405212906Strasz vop_t *opve_impl; /* code implementing this operation */ 406212906Strasz}; 407212906Straszstruct vnodeopv_desc { 408193850Strasz /* ptr to the ptr to the vector where op should go */ 409193850Strasz vop_t ***opv_desc_vector_p; 410193850Strasz struct vnodeopv_entry_desc *opv_desc_ops; /* null terminated list */ 411193850Strasz}; 412193850Strasz 413193850Strasz/* 414193850Strasz * A generic structure. 415193850Strasz * This can be used by bypass routines to identify generic arguments. 416193850Strasz */ 417193850Straszstruct vop_generic_args { 418193850Strasz struct vnodeop_desc *a_desc; 419193850Strasz /* other random data follows, presumably */ 420193850Strasz}; 421193850Strasz 422193850Strasz 423193850Strasz#ifdef DEBUG_VFS_LOCKS 424193850Strasz/* 425193850Strasz * Macros to aid in tracing VFS locking problems. Not totally 426193850Strasz * reliable since if the thread sleeps between changing the lock 427193850Strasz * state and checking it with the assert, some other thread could 428193850Strasz * change the state. They are good enough for debugging a single 429193850Strasz * filesystem using a single-threaded test. I find that 'cvs co src' 430193850Strasz * is a pretty good test. 431193850Strasz */ 432193850Strasz 433193850Strasz/* 434193850Strasz * [dfr] Kludge until I get around to fixing all the vfs locking. 435193850Strasz */ 436193850Strasz#define IS_LOCKING_VFS(vp) ((vp)->v_tag == VT_UFS \ 437193850Strasz || (vp)->v_tag == VT_NFS \ 438193850Strasz || (vp)->v_tag == VT_LFS \ 439193850Strasz || (vp)->v_tag == VT_ISOFS \ 440193850Strasz || (vp)->v_tag == VT_MSDOSFS \ 441193850Strasz || (vp)->v_tag == VT_DEVFS) 442193850Strasz 443193850Strasz#define ASSERT_VOP_LOCKED(vp, str) \ 444193850Straszdo { \ 445193850Strasz struct vnode *_vp = (vp); \ 446193850Strasz \ 447193850Strasz if (_vp && IS_LOCKING_VFS(_vp) && !VOP_ISLOCKED(_vp, NULL)) \ 448193850Strasz panic("%s: %p is not locked but should be", str, _vp); \ 449193850Strasz} while (0) 450193850Strasz 451193850Strasz#define ASSERT_VOP_UNLOCKED(vp, str) \ 452193850Straszdo { \ 453193850Strasz struct vnode *_vp = (vp); \ 454193850Strasz int lockstate; \ 455193850Strasz \ 456193850Strasz if (_vp && IS_LOCKING_VFS(_vp)) { \ 457193850Strasz lockstate = VOP_ISLOCKED(_vp, curthread); \ 458193850Strasz if (lockstate == LK_EXCLUSIVE) \ 459193850Strasz panic("%s: %p is locked but should not be", \ 460193850Strasz str, _vp); \ 461193850Strasz } \ 462193850Strasz} while (0) 463193850Strasz 464193850Strasz#define ASSERT_VOP_ELOCKED(vp, str) \ 465193850Straszdo { \ 466193850Strasz struct vnode *_vp = (vp); \ 467193850Strasz \ 468193850Strasz if (_vp && IS_LOCKING_VFS(_vp) && \ 469193850Strasz VOP_ISLOCKED(_vp, curthread) != LK_EXCLUSIVE) \ 470193850Strasz panic("%s: %p is not exclusive locked but should be", \ 471193850Strasz str, _vp); \ 472193850Strasz} while (0) 473193850Strasz 474193850Strasz#define ASSERT_VOP_ELOCKED_OTHER(vp, str) \ 475193850Straszdo { \ 476193850Strasz struct vnode *_vp = (vp); \ 477193850Strasz \ 478193850Strasz if (_vp && IS_LOCKING_VFS(_vp) && \ 479193850Strasz VOP_ISLOCKED(_vp, curthread) != LK_EXCLOTHER) \ 480193850Strasz panic("%s: %p is not exclusive locked by another thread", \ 481193850Strasz str, _vp); \ 482193850Strasz} while (0) 483193850Strasz 484193850Strasz#define ASSERT_VOP_SLOCKED(vp, str) \ 485193850Straszdo { \ 486193850Strasz struct vnode *_vp = (vp); \ 487193850Strasz \ 488193850Strasz if (_vp && IS_LOCKING_VFS(_vp) && \ 489193850Strasz VOP_ISLOCKED(_vp, NULL) != LK_SHARED) \ 490193850Strasz panic("%s: %p is not locked shared but should be", \ 491193850Strasz str, _vp); \ 492193850Strasz} while (0) 493193850Strasz 494193850Strasz#else 495193850Strasz 496193850Strasz#define ASSERT_VOP_LOCKED(vp, str) 497193850Strasz#define ASSERT_VOP_UNLOCKED(vp, str) 498193850Strasz 499193850Strasz#endif 500193850Strasz 501193850Strasz/* 502193850Strasz * VOCALL calls an op given an ops vector. We break it out because BSD's 503193850Strasz * vclean changes the ops vector and then wants to call ops with the old 504193850Strasz * vector. 505193850Strasz */ 506193850Strasz#define VOCALL(OPSV,OFF,AP) (( *((OPSV)[(OFF)])) (AP)) 507193850Strasz 508193850Strasz/* 509193850Strasz * This call works for vnodes in the kernel. 510193850Strasz */ 511193850Strasz#define VCALL(VP,OFF,AP) VOCALL((VP)->v_op,(OFF),(AP)) 512193850Strasz#define VDESC(OP) (& __CONCAT(OP,_desc)) 513193850Strasz#define VOFFSET(OP) (VDESC(OP)->vdesc_offset) 514193850Strasz 515193850Strasz/* 516193850Strasz * VMIO support inline 517193850Strasz */ 518193850Strasz 519193850Straszextern int vmiodirenable; 520193850Strasz 521193850Straszstatic __inline int 522193850Straszvn_canvmio(struct vnode *vp) 523193850Strasz{ 524193850Strasz if (vp && (vp->v_type == VREG || (vmiodirenable && vp->v_type == VDIR))) 525193850Strasz return(TRUE); 526193850Strasz return(FALSE); 527193850Strasz} 528193850Strasz 529193850Strasz/* 530193850Strasz * Finally, include the default set of vnode operations. 531193850Strasz */ 532193850Strasz#include "vnode_if.h" 533193850Strasz 534193850Strasz/* 535193850Strasz * Public vnode manipulation functions. 536193850Strasz */ 537193850Straszstruct componentname; 538193850Straszstruct file; 539193850Straszstruct mount; 540193850Straszstruct nameidata; 541193850Straszstruct ostat; 542193850Straszstruct thread; 543193850Straszstruct proc; 544193850Straszstruct stat; 545193850Straszstruct nstat; 546193850Straszstruct ucred; 547193850Straszstruct uio; 548193850Straszstruct vattr; 549193850Straszstruct vnode; 550193850Strasz 551193850Straszextern int (*lease_check_hook) __P((struct vop_lease_args *)); 552193850Strasz 553193850Straszstruct vnode *addaliasu __P((struct vnode *vp, udev_t nvp_rdev)); 554193850Straszint bdevvp __P((dev_t dev, struct vnode **vpp)); 555193850Strasz/* cache_* may belong in namei.h. */ 556193850Straszvoid cache_enter __P((struct vnode *dvp, struct vnode *vp, 557193850Strasz struct componentname *cnp)); 558193850Straszint cache_lookup __P((struct vnode *dvp, struct vnode **vpp, 559193850Strasz struct componentname *cnp)); 560193850Straszvoid cache_purge __P((struct vnode *vp)); 561193850Straszvoid cache_purgevfs __P((struct mount *mp)); 562193850Straszvoid cache_purgeleafdirs __P((int ndir)); 563193850Straszvoid cvtstat __P((struct stat *st, struct ostat *ost)); 564193850Straszvoid cvtnstat __P((struct stat *sb, struct nstat *nsb)); 565193850Straszint getnewvnode __P((enum vtagtype tag, 566193850Strasz struct mount *mp, vop_t **vops, struct vnode **vpp)); 567193850Straszint lease_check __P((struct vop_lease_args *ap)); 568193850Straszint spec_vnoperate __P((struct vop_generic_args *)); 569193850Straszint speedup_syncer __P((void)); 570193850Straszint textvp_fullpath __P((struct proc *p, char **retbuf, 571193850Strasz char **retfreebuf)); 572193850Straszint vaccess __P((enum vtype type, mode_t file_mode, uid_t uid, gid_t gid, 573193850Strasz mode_t acc_mode, struct ucred *cred, int *privused)); 574193850Straszint vaccess_acl_posix1e __P((enum vtype type, uid_t file_uid, 575193850Strasz gid_t file_gid, struct acl *acl, mode_t acc_mode, 576193850Strasz struct ucred *cred, int *privused)); 577193850Straszvoid vattr_null __P((struct vattr *vap)); 578193850Straszint vcount __P((struct vnode *vp)); 579193850Straszvoid vdrop __P((struct vnode *)); 580193850Straszint vfinddev __P((dev_t dev, enum vtype type, struct vnode **vpp)); 581193850Straszvoid vfs_add_vnodeops __P((const void *)); 582193850Straszvoid vfs_rm_vnodeops __P((const void *)); 583193850Straszint vflush __P((struct mount *mp, int rootrefs, int flags)); 584193850Straszint vget __P((struct vnode *vp, int lockflag, struct thread *td)); 585193850Straszvoid vgone __P((struct vnode *vp)); 586193850Straszvoid vgonel __P((struct vnode *vp, struct thread *td)); 587193850Straszvoid vhold __P((struct vnode *)); 588193850Straszint vinvalbuf __P((struct vnode *vp, int save, struct ucred *cred, 589193850Strasz struct thread *td, int slpflag, int slptimeo)); 590193850Straszint vtruncbuf __P((struct vnode *vp, struct ucred *cred, struct thread *td, 591193850Strasz off_t length, int blksize)); 592193850Straszvoid vprint __P((char *label, struct vnode *vp)); 593193850Straszint vrecycle __P((struct vnode *vp, struct mtx *inter_lkp, 594193850Strasz struct thread *td)); 595193850Straszint vn_close __P((struct vnode *vp, 596193850Strasz int flags, struct ucred *cred, struct thread *td)); 597193850Straszvoid vn_finished_write __P((struct mount *mp)); 598193850Straszint vn_isdisk __P((struct vnode *vp, int *errp)); 599193850Straszint vn_lock __P((struct vnode *vp, int flags, struct thread *td)); 600193850Strasz#ifdef DEBUG_LOCKS 601193850Straszint debug_vn_lock __P((struct vnode *vp, int flags, struct thread *p, 602193850Strasz const char *filename, int line)); 603193850Strasz#define vn_lock(vp,flags,p) debug_vn_lock(vp,flags,p,__FILE__,__LINE__) 604193850Strasz#endif 605193850Straszint vn_mkdir __P((char *path, int mode, enum uio_seg segflg, struct thread *td)); 606193850Straszint vn_open __P((struct nameidata *ndp, int *flagp, int cmode)); 607193850Straszvoid vn_pollevent __P((struct vnode *vp, int events)); 608193850Straszvoid vn_pollgone __P((struct vnode *vp)); 609193850Straszint vn_pollrecord __P((struct vnode *vp, struct thread *p, int events)); 610193850Straszint vn_rdwr __P((enum uio_rw rw, struct vnode *vp, caddr_t base, 611193850Strasz int len, off_t offset, enum uio_seg segflg, int ioflg, 612193850Strasz struct ucred *cred, int *aresid, struct thread *td)); 613193850Straszint vn_rdwr_inchunks __P((enum uio_rw rw, struct vnode *vp, caddr_t base, 614193850Strasz int len, off_t offset, enum uio_seg segflg, int ioflg, 615193850Strasz struct ucred *cred, int *aresid, struct thread *td)); 616193850Straszint vn_stat __P((struct vnode *vp, struct stat *sb, struct thread *td)); 617193850Straszint vn_start_write __P((struct vnode *vp, struct mount **mpp, int flags)); 618193850Straszdev_t vn_todev __P((struct vnode *vp)); 619193850Straszint vn_write_suspend_wait __P((struct vnode *vp, struct mount *mp, 620193850Strasz int flags)); 621193850Straszint vn_writechk __P((struct vnode *vp)); 622193850Straszint vn_extattr_get __P((struct vnode *vp, int ioflg, int attrnamespace, 623193850Strasz const char *attrname, int *buflen, char *buf, struct thread *td)); 624193850Straszint vn_extattr_set __P((struct vnode *vp, int ioflg, int attrnamespace, 625193850Strasz const char *attrname, int buflen, char *buf, struct thread *td)); 626193850Straszint vn_extattr_rm(struct vnode *vp, int ioflg, int attrnamespace, 627193850Strasz const char *attrname, struct thread *td); 628193850Straszint vfs_cache_lookup __P((struct vop_lookup_args *ap)); 629193850Straszint vfs_object_create __P((struct vnode *vp, struct thread *td, 630193850Strasz struct ucred *cred)); 631193850Straszvoid vfs_timestamp __P((struct timespec *)); 632193850Straszvoid vfs_write_resume __P((struct mount *mp)); 633193850Straszvoid vfs_write_suspend __P((struct mount *mp)); 634193850Straszint vop_stdbmap __P((struct vop_bmap_args *)); 635193850Straszint vop_stdgetwritemount __P((struct vop_getwritemount_args *)); 636193850Straszint vop_stdgetpages __P((struct vop_getpages_args *)); 637193850Straszint vop_stdinactive __P((struct vop_inactive_args *)); 638193850Straszint vop_stdislocked __P((struct vop_islocked_args *)); 639193850Straszint vop_stdlock __P((struct vop_lock_args *)); 640193850Straszint vop_stdputpages __P((struct vop_putpages_args *)); 641193850Straszint vop_stdunlock __P((struct vop_unlock_args *)); 642193850Straszint vop_noislocked __P((struct vop_islocked_args *)); 643193850Straszint vop_nolock __P((struct vop_lock_args *)); 644193850Straszint vop_nopoll __P((struct vop_poll_args *)); 645193850Straszint vop_nounlock __P((struct vop_unlock_args *)); 646193850Straszint vop_stdpathconf __P((struct vop_pathconf_args *)); 647193850Straszint vop_stdpoll __P((struct vop_poll_args *)); 648193850Straszint vop_revoke __P((struct vop_revoke_args *)); 649193850Straszint vop_sharedlock __P((struct vop_lock_args *)); 650193850Straszint vop_eopnotsupp __P((struct vop_generic_args *ap)); 651193850Straszint vop_ebadf __P((struct vop_generic_args *ap)); 652193850Straszint vop_einval __P((struct vop_generic_args *ap)); 653193850Straszint vop_enotty __P((struct vop_generic_args *ap)); 654193850Straszint vop_defaultop __P((struct vop_generic_args *ap)); 655193850Straszint vop_null __P((struct vop_generic_args *ap)); 656193850Straszint vop_panic __P((struct vop_generic_args *ap)); 657193850Straszint vop_stdcreatevobject __P((struct vop_createvobject_args *ap)); 658193850Straszint vop_stddestroyvobject __P((struct vop_destroyvobject_args *ap)); 659193850Straszint vop_stdgetvobject __P((struct vop_getvobject_args *ap)); 660193850Strasz 661193850Straszvoid vfree __P((struct vnode *)); 662193850Straszvoid vput __P((struct vnode *vp)); 663193850Straszvoid vrele __P((struct vnode *vp)); 664193850Straszvoid vref __P((struct vnode *vp)); 665193850Straszvoid vbusy __P((struct vnode *vp)); 666193850Strasz 667193850Straszextern vop_t **default_vnodeop_p; 668193850Straszextern vop_t **spec_vnodeop_p; 669193850Straszextern vop_t **dead_vnodeop_p; 670193850Strasz 671193850Strasz#endif /* _KERNEL */ 672193850Strasz 673193850Strasz#endif /* !_SYS_VNODE_H_ */ 674193850Strasz