vnode.h revision 133741
162587Sitojun/* 278064Sume * Copyright (c) 1989, 1993 362587Sitojun * The Regents of the University of California. All rights reserved. 452904Sshin * 552904Sshin * Redistribution and use in source and binary forms, with or without 652904Sshin * modification, are permitted provided that the following conditions 753541Sshin * are met: 852904Sshin * 1. Redistributions of source code must retain the above copyright 952904Sshin * notice, this list of conditions and the following disclaimer. 1052904Sshin * 2. Redistributions in binary form must reproduce the above copyright 1152904Sshin * notice, this list of conditions and the following disclaimer in the 1252904Sshin * documentation and/or other materials provided with the distribution. 1352904Sshin * 4. Neither the name of the University nor the names of its contributors 1452904Sshin * may be used to endorse or promote products derived from this software 1552904Sshin * without specific prior written permission. 1652904Sshin * 1752904Sshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1852904Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1953541Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2052904Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2152904Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2252904Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2352904Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2452904Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2552904Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2652904Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2752904Sshin * SUCH DAMAGE. 2852904Sshin * 2952904Sshin * @(#)vnode.h 8.7 (Berkeley) 2/4/94 3052904Sshin * $FreeBSD: head/sys/sys/vnode.h 133741 2004-08-15 06:24:42Z jmg $ 3152904Sshin */ 3252904Sshin 3352904Sshin#ifndef _SYS_VNODE_H_ 3452904Sshin#define _SYS_VNODE_H_ 3552904Sshin 3652904Sshin/* 3752904Sshin * XXX - compatability until lockmgr() goes away or all the #includes are 3852904Sshin * updated. 3952904Sshin */ 4052904Sshin#include <sys/lockmgr.h> 4152904Sshin 4252904Sshin#include <sys/queue.h> 4352904Sshin#include <sys/_lock.h> 4452904Sshin#include <sys/lock.h> 4552904Sshin#include <sys/_mutex.h> 4652904Sshin#include <sys/mutex.h> 4752904Sshin#include <sys/selinfo.h> 4852904Sshin#include <sys/uio.h> 4952904Sshin#include <sys/acl.h> 5052904Sshin#include <sys/ktr.h> 5152904Sshin 5252904Sshin/* 5352904Sshin * The vnode is the focus of all file activity in UNIX. There is a 5452904Sshin * unique vnode allocated for each active file, each current directory, 5552904Sshin * each mounted-on file, text file, and the root. 5652904Sshin */ 5752904Sshin 5852904Sshin/* 5952904Sshin * Vnode types. VNON means no type. 6052904Sshin */ 6152904Sshinenum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD }; 6252904Sshin 6352904Sshin/* 6452904Sshin * Each underlying filesystem allocates its own private area and hangs 6552904Sshin * it from v_data. If non-null, this area is freed in getnewvnode(). 6652904Sshin */ 6752904SshinTAILQ_HEAD(buflists, buf); 6862587Sitojun 6978064Sumetypedef int vop_t(void *); 7057120Sshinstruct namecache; 7157120Sshin 7262587Sitojunstruct vpollinfo { 7362587Sitojun struct mtx vpi_lock; /* lock to protect below */ 7462587Sitojun struct selinfo vpi_selinfo; /* identity of poller(s) */ 7552904Sshin short vpi_events; /* what they are looking for */ 7652904Sshin short vpi_revents; /* what has happened */ 7778064Sume}; 7878064Sume 7952904Sshin/* 8062587Sitojun * Reading or writing any of these items requires holding the appropriate lock. 8178064Sume * 8252904Sshin * Lock reference: 8352904Sshin * c - namecache mutex 8452904Sshin * f - freelist mutex 8552904Sshin * G - Giant 8652904Sshin * i - interlock 8752904Sshin * m - mntvnodes mutex 8852904Sshin * p - pollinfo lock 8952904Sshin * s - spechash mutex 9052904Sshin * S - syncer mutex 9152904Sshin * u - Only a reference to the vnode is needed to read. 9262587Sitojun * v - vnode lock 9352904Sshin * 9452904Sshin * Vnodes may be found on many lists. The general way to deal with operating 9552904Sshin * on a vnode that is on a list is: 9652904Sshin * 1) Lock the list and find the vnode. 9752904Sshin * 2) Lock interlock so that the vnode does not go away. 9852904Sshin * 3) Unlock the list to avoid lock order reversals. 9952904Sshin * 4) vget with LK_INTERLOCK and check for ENOENT, or 10052904Sshin * 5) Check for XLOCK if the vnode lock is not required. 10152904Sshin * 6) Perform your operation, then vput(). 10252904Sshin * 10352904Sshin * XXX Not all fields are locked yet and some fields that are marked are not 10452904Sshin * locked consistently. This is a work in progress. Requires Giant! 10552904Sshin */ 10652904Sshin 10752904Sshinstruct vnode { 10852904Sshin struct mtx v_interlock; /* lock for "i" things */ 10952904Sshin u_long v_iflag; /* i vnode flags (see below) */ 11097181Smike int v_usecount; /* i ref count of users */ 11152904Sshin long v_numoutput; /* i writes in progress */ 11252904Sshin struct thread *v_vxthread; /* i thread owning VXLOCK */ 11352904Sshin int v_holdcnt; /* i page & buffer references */ 11452904Sshin struct buflists v_cleanblkhd; /* i SORTED clean blocklist */ 11552904Sshin struct buf *v_cleanblkroot; /* i clean buf splay tree */ 11697181Smike int v_cleanbufcnt; /* i number of clean buffers */ 11752904Sshin struct buflists v_dirtyblkhd; /* i SORTED dirty blocklist */ 11852904Sshin struct buf *v_dirtyblkroot; /* i dirty buf splay tree */ 11952904Sshin int v_dirtybufcnt; /* i number of dirty buffers */ 12052904Sshin u_long v_vflag; /* v vnode flags */ 12152904Sshin int v_writecount; /* v ref count of writers */ 12252904Sshin struct vm_object *v_object; /* v Place to store VM object */ 12397181Smike daddr_t v_lastw; /* v last write (write cluster) */ 12497181Smike daddr_t v_cstart; /* v start block of cluster */ 12597181Smike daddr_t v_lasta; /* v last allocation (cluster) */ 12652904Sshin int v_clen; /* v length of current cluster */ 12752904Sshin union { 12852904Sshin struct mount *vu_mountedhere;/* v ptr to mounted vfs (VDIR) */ 12962587Sitojun struct socket *vu_socket; /* v unix ipc (VSOCK) */ 13095023Ssuz struct { 13162587Sitojun struct cdev *vu_cdev; /* v device (VCHR, VBLK) */ 13262587Sitojun SLIST_ENTRY(vnode) vu_specnext; /* s device aliases */ 13362587Sitojun } vu_spec; 13452904Sshin struct fifoinfo *vu_fifoinfo; /* v fifo (VFIFO) */ 13552904Sshin } v_un; 13662587Sitojun TAILQ_ENTRY(vnode) v_freelist; /* f vnode freelist */ 13752904Sshin TAILQ_ENTRY(vnode) v_nmntvnodes; /* m vnodes for mount point */ 13852904Sshin LIST_ENTRY(vnode) v_synclist; /* S dirty vnode list */ 13997181Smike enum vtype v_type; /* u vnode type */ 14097181Smike const char *v_tag; /* u type of underlying data */ 14197181Smike void *v_data; /* u private data for fs */ 14297181Smike struct lock v_lock; /* u used if fs don't have one */ 14352904Sshin struct lock *v_vnlock; /* u pointer to vnode lock */ 14452904Sshin vop_t **v_op; /* u vnode operations vector */ 14597181Smike struct mount *v_mount; /* u ptr to vfs we are in */ 14662587Sitojun LIST_HEAD(, namecache) v_cache_src; /* c Cache entries from us */ 14752904Sshin TAILQ_HEAD(, namecache) v_cache_dst; /* c Cache entries to us */ 14897181Smike u_long v_id; /* c capability identifier */ 14952904Sshin struct vnode *v_dd; /* c .. vnode */ 150100503Sume u_long v_ddid; /* c .. capability identifier */ 15197181Smike struct vpollinfo *v_pollinfo; /* G Poll events, p for *v_pi */ 15297181Smike struct label *v_label; /* MAC label for vnode */ 15397181Smike#ifdef DEBUG_LOCKS 15462587Sitojun const char *filename; /* Source file doing locking */ 15597181Smike int line; /* Line number doing locking */ 15652904Sshin#endif 15752904Sshin dev_t v_cachedfs; /* cached fs id */ 15852904Sshin ino_t v_cachedid; /* cached file id */ 15952904Sshin int v_bsize; /* block size for I/O */ 16052904Sshin}; 16195023Ssuz#define v_mountedhere v_un.vu_mountedhere 16262587Sitojun#define v_socket v_un.vu_socket 16362587Sitojun#define v_rdev v_un.vu_spec.vu_cdev 16452904Sshin#define v_specnext v_un.vu_spec.vu_specnext 16562587Sitojun#define v_fifoinfo v_un.vu_fifoinfo 16652904Sshin 16762587Sitojun/* 16852904Sshin * Userland version of struct vnode, for sysctl. 16962587Sitojun */ 17052904Sshinstruct xvnode { 17152904Sshin size_t xv_size; /* sizeof(struct xvnode) */ 17252904Sshin void *xv_vnode; /* address of real vnode */ 17352904Sshin u_long xv_flag; /* vnode vflags */ 17478064Sume int xv_usecount; /* reference count of users */ 17578064Sume int xv_writecount; /* reference count of writers */ 17652904Sshin int xv_holdcnt; /* page & buffer references */ 17752904Sshin u_long xv_id; /* capability identifier */ 17852904Sshin void *xv_mount; /* address of parent mount */ 17952904Sshin long xv_numoutput; /* num of writes in progress */ 18052904Sshin enum vtype xv_type; /* vnode type */ 18152904Sshin union { 18252904Sshin void *xvu_socket; /* socket, if VSOCK */ 18352904Sshin void *xvu_fifo; /* fifo, if VFIFO */ 18452904Sshin dev_t xvu_rdev; /* maj/min, if VBLK/VCHR */ 18552904Sshin struct { 18695023Ssuz dev_t xvu_dev; /* device, if VDIR/VREG/VLNK */ 18797181Smike ino_t xvu_ino; /* id, if VDIR/VREG/VLNK */ 18862587Sitojun } xv_uns; 18962587Sitojun } xv_un; 19062587Sitojun}; 19162587Sitojun#define xv_socket xv_un.xvu_socket 19262587Sitojun#define xv_fifo xv_un.xvu_fifo 19362587Sitojun#define xv_rdev xv_un.xvu_rdev 19462587Sitojun#define xv_dev xv_un.xv_uns.xvu_dev 19562587Sitojun#define xv_ino xv_un.xv_uns.xvu_ino 19697181Smike 19762587Sitojun#define VN_POLLEVENT(vp, events) \ 19862587Sitojun do { \ 19962587Sitojun if ((vp)->v_pollinfo != NULL && \ 20062587Sitojun (vp)->v_pollinfo->vpi_events & (events)) \ 20162587Sitojun vn_pollevent((vp), (events)); \ 20262587Sitojun } while (0) 20362587Sitojun 20462587Sitojun#define VN_KNOTE(vp, b, a) \ 20552904Sshin do { \ 20652904Sshin if ((vp)->v_pollinfo != NULL) \ 20752904Sshin KNOTE(&vp->v_pollinfo->vpi_selinfo.si_note, (b), (a)); \ 20852904Sshin } while (0) 20952904Sshin#define VN_KNOTE_LOCKED(vp, b) VN_KNOTE(vp, b, 1) 21052904Sshin#define VN_KNOTE_UNLOCKED(vp, b) VN_KNOTE(vp, b, 0) 21197181Smike 21262587Sitojun/* 21352904Sshin * Vnode flags. 21452904Sshin * VI flags are protected by interlock and live in v_iflag 21562587Sitojun * VV flags are protected by the vnode lock and live in v_vflag 21652904Sshin */ 21752904Sshin#define VI_XLOCK 0x0001 /* vnode is locked to change vtype */ 21862587Sitojun#define VI_XWANT 0x0002 /* thread is waiting for vnode */ 21952904Sshin#define VI_BWAIT 0x0004 /* waiting for output to complete */ 22052904Sshin#define VI_OLOCK 0x0008 /* vnode is locked waiting for an object */ 22162587Sitojun#define VI_OWANT 0x0010 /* a thread is waiting for VOLOCK */ 22252904Sshin#define VI_MOUNT 0x0020 /* Mount in progress */ 22352904Sshin#define VI_AGE 0x0040 /* Insert vnode at head of free list */ 22462587Sitojun#define VI_DOOMED 0x0080 /* This vnode is being recycled */ 22552904Sshin#define VI_FREE 0x0100 /* This vnode is on the freelist */ 22652904Sshin#define VI_OBJDIRTY 0x0400 /* object might be dirty */ 22797181Smike#define VI_DOINGINACT 0x0800 /* VOP_INACTIVE is in progress */ 22852904Sshin/* 22952904Sshin * XXX VI_ONWORKLST could be replaced with a check for NULL list elements 23052904Sshin * in v_synclist. 23197181Smike */ 23252904Sshin#define VI_ONWORKLST 0x0200 /* On syncer work-list */ 23352904Sshin 23452904Sshin#define VV_ROOT 0x0001 /* root of its filesystem */ 23597181Smike#define VV_ISTTY 0x0002 /* vnode represents a tty */ 23652904Sshin#define VV_NOSYNC 0x0004 /* unlinked, stop syncing */ 23752904Sshin#define VV_OBJBUF 0x0008 /* Allocate buffers in VM object */ 23852904Sshin#define VV_CACHEDLABEL 0x0010 /* Vnode has valid cached MAC label */ 23953877Sitojun#define VV_TEXT 0x0020 /* vnode is a pure text prototype */ 24053877Sitojun#define VV_COPYONWRITE 0x0040 /* vnode is doing copy-on-write */ 24153877Sitojun#define VV_SYSTEM 0x0080 /* vnode being used by kernel */ 24252904Sshin#define VV_PROCDEP 0x0100 /* vnode is process dependent */ 24353877Sitojun 24462587Sitojun/* 24562587Sitojun * Vnode attributes. A field value of VNOVAL represents a field whose value 24653877Sitojun * is unavailable (getattr) or which is not to be changed (setattr). 24797181Smike */ 24862587Sitojunstruct vattr { 24962587Sitojun enum vtype va_type; /* vnode type (for create) */ 25053877Sitojun u_short va_mode; /* files access mode and type */ 25197181Smike short va_nlink; /* number of references to file */ 25252904Sshin uid_t va_uid; /* owner user id */ 25378064Sume gid_t va_gid; /* owner group id */ 25478064Sume dev_t va_fsid; /* filesystem id */ 25578064Sume long va_fileid; /* file id */ 25678064Sume u_quad_t va_size; /* file size in bytes */ 25778064Sume long va_blocksize; /* blocksize preferred for i/o */ 25878064Sume struct timespec va_atime; /* time of last access */ 25978064Sume struct timespec va_mtime; /* time of last modification */ 26078064Sume struct timespec va_ctime; /* time file changed */ 26152904Sshin struct timespec va_birthtime; /* time file created */ 26252904Sshin u_long va_gen; /* generation number of file */ 26352904Sshin u_long va_flags; /* flags defined for file */ 26462587Sitojun dev_t va_rdev; /* device the special file represents */ 26578064Sume u_quad_t va_bytes; /* bytes of disk space held by file */ 26678064Sume u_quad_t va_filerev; /* file modification number */ 26778064Sume u_int va_vaflags; /* operations flags, see below */ 26878064Sume long va_spare; /* remain quad aligned */ 26952904Sshin}; 27052904Sshin 27152904Sshin/* 27252904Sshin * Flags for va_vaflags. 27362587Sitojun */ 27478064Sume#define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */ 27578064Sume#define VA_EXCLUSIVE 0x02 /* exclusive create request */ 27678064Sume 27778064Sume/* 27852904Sshin * Flags for ioflag. (high 16 bits used to ask for read-ahead and 27952904Sshin * help with write clustering) 28052904Sshin */ 28152904Sshin#define IO_UNIT 0x0001 /* do I/O as atomic unit */ 28262587Sitojun#define IO_APPEND 0x0002 /* append write to end */ 28378064Sume#define IO_SYNC 0x0004 /* do I/O synchronously */ 28478064Sume#define IO_NODELOCKED 0x0008 /* underlying node already locked */ 28578064Sume#define IO_NDELAY 0x0010 /* FNDELAY flag set in file table */ 28678064Sume#define IO_VMIO 0x0020 /* data already in VMIO space */ 28778064Sume#define IO_INVAL 0x0040 /* invalidate after I/O */ 28852904Sshin#define IO_ASYNC 0x0080 /* bawrite rather then bdwrite */ 28952904Sshin#define IO_DIRECT 0x0100 /* attempt to bypass buffer cache */ 29052904Sshin#define IO_EXT 0x0400 /* operate on external attributes */ 29152904Sshin#define IO_NORMAL 0x0800 /* operate on regular data */ 29262587Sitojun#define IO_NOMACCHECK 0x1000 /* MAC checks unnecessary */ 29378064Sume 29478064Sume#define IO_SEQMAX 0x7F /* seq heuristic max value */ 29578064Sume#define IO_SEQSHIFT 16 /* seq heuristic in upper 16 bits */ 29652904Sshin 29752904Sshin/* 29852904Sshin * Modes. Some values same as Ixxx entries from inode.h for now. 29952904Sshin */ 30052904Sshin#define VEXEC 000100 /* execute/search permission */ 30195023Ssuz#define VWRITE 000200 /* write permission */ 30262587Sitojun#define VREAD 000400 /* read permission */ 30362587Sitojun#define VSVTX 001000 /* save swapped text even after use */ 30462587Sitojun#define VSGID 002000 /* set group id on execution */ 30562587Sitojun#define VSUID 004000 /* set user id on execution */ 30662587Sitojun#define VADMIN 010000 /* permission to administer */ 30752904Sshin#define VSTAT 020000 /* permission to retrieve attrs */ 30862587Sitojun#define VAPPEND 040000 /* permission to write/append */ 30962587Sitojun#define VALLPERM (VEXEC | VWRITE | VREAD | VADMIN | VSTAT | VAPPEND) 31062587Sitojun 31162587Sitojun/* 31262587Sitojun * Token indicating no attribute value yet assigned. 31352904Sshin */ 31452904Sshin#define VNOVAL (-1) 31552904Sshin 31652904Sshin/* 31752904Sshin * LK_TIMELOCK timeout for vnode locks (used mainly by the pageout daemon) 31852904Sshin */ 31962587Sitojun#define VLKTIMEOUT (hz / 20 + 1) 32052904Sshin 32162587Sitojun#ifdef _KERNEL 32252904Sshin 32352904Sshin#ifdef MALLOC_DECLARE 32452904SshinMALLOC_DECLARE(M_VNODE); 32552904Sshin#endif 32652904Sshin 32752904Sshin/* 32852904Sshin * Convert between vnode types and inode formats (since POSIX.1 32995023Ssuz * defines mode word of stat structure in terms of inode formats). 33062587Sitojun */ 33152904Sshinextern enum vtype iftovt_tab[]; 33262587Sitojunextern int vttoif_tab[]; 33352904Sshin#define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12]) 33452904Sshin#define VTTOIF(indx) (vttoif_tab[(int)(indx)]) 33552904Sshin#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) 33652904Sshin 33752904Sshin/* 33895023Ssuz * Flags to various vnode functions. 33962587Sitojun */ 34052904Sshin#define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */ 34152904Sshin#define FORCECLOSE 0x0002 /* vflush: force file closure */ 34262587Sitojun#define WRITECLOSE 0x0004 /* vflush: only close writable files */ 34352904Sshin#define DOCLOSE 0x0008 /* vclean: close active files */ 34452904Sshin#define V_SAVE 0x0001 /* vinvalbuf: sync file first */ 34562587Sitojun#define V_ALT 0x0002 /* vinvalbuf: invalidate only alternate bufs */ 34652904Sshin#define V_NORMAL 0x0004 /* vinvalbuf: invalidate only regular bufs */ 34752904Sshin#define REVOKEALL 0x0001 /* vop_revoke: revoke all aliases */ 34862587Sitojun#define V_WAIT 0x0001 /* vn_start_write: sleep for suspend */ 34952904Sshin#define V_NOWAIT 0x0002 /* vn_start_write: don't sleep for suspend */ 35052904Sshin#define V_XSLEEP 0x0004 /* vn_start_write: just return after sleep */ 35162587Sitojun 35252904Sshin#define VREF(vp) vref(vp) 35352904Sshin 35452904Sshin#ifdef DIAGNOSTIC 35562587Sitojun#define VATTR_NULL(vap) vattr_null(vap) 35652904Sshin#else 35752904Sshin#define VATTR_NULL(vap) (*(vap) = va_null) /* initialize a vattr */ 35862587Sitojun#endif /* DIAGNOSTIC */ 35952904Sshin 36052904Sshin#define NULLVP ((struct vnode *)NULL) 36162587Sitojun 36252904Sshin#define VNODEOP_SET(f) \ 36352904Sshin C_SYSINIT(f##init, SI_SUB_VFS, SI_ORDER_SECOND, vfs_add_vnodeops, &f); \ 36462587Sitojun C_SYSUNINIT(f##uninit, SI_SUB_VFS, SI_ORDER_SECOND, vfs_rm_vnodeops, &f); 36552904Sshin 36652904Sshin/* 36762587Sitojun * Global vnode data. 36852904Sshin */ 36952904Sshinextern struct vnode *rootvnode; /* root (i.e. "/") vnode */ 37052904Sshinextern int async_io_version; /* 0 or POSIX version of AIO i'face */ 37152904Sshinextern int desiredvnodes; /* number of vnodes desired */ 37295023Ssuzextern struct uma_zone *namei_zone; 37378064Sumeextern int prtactive; /* nonzero to call vprint() */ 37452904Sshinextern struct vattr va_null; /* predefined null vattr structure */ 37552904Sshin 37662587Sitojun/* 37752904Sshin * Macro/function to check for client cache inconsistency w.r.t. leasing. 37852904Sshin */ 37952904Sshin#define LEASE_READ 0x1 /* Check lease for readers */ 38078064Sume#define LEASE_WRITE 0x2 /* Check lease for modifiers */ 38178064Sume 38278064Sumeextern void (*lease_updatetime)(int deltat); 38378064Sume 38478064Sume/* Requires interlock. */ 38578064Sume#define VSHOULDFREE(vp) \ 38678064Sume (!((vp)->v_iflag & (VI_FREE|VI_DOOMED|VI_DOINGINACT)) && \ 38778064Sume !(vp)->v_holdcnt && !(vp)->v_usecount && \ 38852904Sshin (!(vp)->v_object || \ 38952904Sshin !((vp)->v_object->ref_count || (vp)->v_object->resident_page_count))) 39052904Sshin 39197181Smike/* Requires interlock. */ 39252904Sshin#define VMIGHTFREE(vp) \ 39352904Sshin (!((vp)->v_iflag & (VI_FREE|VI_DOOMED|VI_XLOCK|VI_DOINGINACT)) && \ 39452904Sshin LIST_EMPTY(&(vp)->v_cache_src) && !(vp)->v_usecount) 39552904Sshin 39652904Sshin/* Requires interlock. */ 39752904Sshin#define VSHOULDBUSY(vp) \ 39852904Sshin (((vp)->v_iflag & VI_FREE) && \ 39952904Sshin ((vp)->v_holdcnt || (vp)->v_usecount)) 40052904Sshin 40152904Sshin#define VI_LOCK(vp) mtx_lock(&(vp)->v_interlock) 40297181Smike#define VI_TRYLOCK(vp) mtx_trylock(&(vp)->v_interlock) 40397181Smike#define VI_UNLOCK(vp) mtx_unlock(&(vp)->v_interlock) 40497181Smike#define VI_MTX(vp) (&(vp)->v_interlock) 40597181Smike 40697181Smike#endif /* _KERNEL */ 40797181Smike 40897181Smike/* 40997181Smike * Mods for extensibility. 41097181Smike */ 41152904Sshin 41262587Sitojun/* 41362587Sitojun * Flags for vdesc_flags: 41462587Sitojun */ 41562587Sitojun#define VDESC_MAX_VPS 16 41662587Sitojun/* Low order 16 flag bits are reserved for willrele flags for vp arguments. */ 41762587Sitojun#define VDESC_VP0_WILLRELE 0x0001 41862587Sitojun#define VDESC_VP1_WILLRELE 0x0002 41962587Sitojun#define VDESC_VP2_WILLRELE 0x0004 42062587Sitojun#define VDESC_VP3_WILLRELE 0x0008 42162587Sitojun#define VDESC_NOMAP_VPP 0x0100 42278064Sume#define VDESC_VPP_WILLRELE 0x0200 42378064Sume 42462587Sitojun/* 42562587Sitojun * VDESC_NO_OFFSET is used to identify the end of the offset list 42662587Sitojun * and in places where no such field exists. 42762587Sitojun */ 42862587Sitojun#define VDESC_NO_OFFSET -1 42962587Sitojun 43078064Sume/* 43162587Sitojun * This structure describes the vnode operation taking place. 43278064Sume */ 43378064Sumestruct vnodeop_desc { 43478064Sume int vdesc_offset; /* offset in vector,first for speed */ 43552904Sshin char *vdesc_name; /* a readable name for debugging */ 43695023Ssuz int vdesc_flags; /* VDESC_* flags */ 43762587Sitojun 43878064Sume /* 43962587Sitojun * These ops are used by bypass routines to map and locate arguments. 44052904Sshin * Creds and procs are not needed in bypass routines, but sometimes 44195023Ssuz * they are useful to (for example) transport layers. 44262587Sitojun * Nameidata is useful because it has a cred in it. 44362587Sitojun */ 44462587Sitojun int *vdesc_vp_offsets; /* list ended by VDESC_NO_OFFSET */ 44562587Sitojun int vdesc_vpp_offset; /* return vpp location */ 44662587Sitojun int vdesc_cred_offset; /* cred location, if any */ 44778064Sume int vdesc_thread_offset; /* thread location, if any */ 44878064Sume int vdesc_componentname_offset; /* if any */ 44965124Sitojun /* 45052904Sshin * Finally, we've got a list of private data (about each operation) 45162587Sitojun * for each transport layer. (Support to manage this list is not 45262587Sitojun * yet part of BSD.) 45362587Sitojun */ 45452904Sshin caddr_t *vdesc_transports; 45552904Sshin}; 45652904Sshin 45752904Sshin#ifdef _KERNEL 45895023Ssuz/* 45995023Ssuz * A list of all the operation descs. 46052904Sshin */ 46152904Sshinextern struct vnodeop_desc *vnodeop_descs[]; 46252904Sshin 46352904Sshin#define VOPARG_OFFSETOF(s_type, field) __offsetof(s_type, field) 46452904Sshin#define VOPARG_OFFSETTO(s_type, s_offset, struct_p) \ 46562587Sitojun ((s_type)(((char*)(struct_p)) + (s_offset))) 46662587Sitojun 46752904Sshin/* 46852904Sshin * This structure is used to configure the new vnodeops vector. 46952904Sshin */ 47052904Sshinstruct vnodeopv_entry_desc { 47152904Sshin struct vnodeop_desc *opve_op; /* which operation this is */ 47252904Sshin vop_t *opve_impl; /* code implementing this operation */ 47362587Sitojun}; 47462587Sitojunstruct vnodeopv_desc { 47552904Sshin /* ptr to the ptr to the vector where op should go */ 47652904Sshin vop_t ***opv_desc_vector_p; 47752904Sshin struct vnodeopv_entry_desc *opv_desc_ops; /* null terminated list */ 47852904Sshin}; 47952904Sshin 48052904Sshin/* 48152904Sshin * A generic structure. 48252904Sshin * This can be used by bypass routines to identify generic arguments. 48352904Sshin */ 48452904Sshinstruct vop_generic_args { 48552904Sshin struct vnodeop_desc *a_desc; 48652904Sshin /* other random data follows, presumably */ 48752904Sshin}; 48852904Sshin 48952904Sshin#ifdef DEBUG_VFS_LOCKS 49052904Sshin/* 49162587Sitojun * Support code to aid in debugging VFS locking problems. Not totally 49252904Sshin * reliable since if the thread sleeps between changing the lock 49362587Sitojun * state and checking it with the assert, some other thread could 49452904Sshin * change the state. They are good enough for debugging a single 49552904Sshin * filesystem using a single-threaded test. 49652904Sshin */ 49752904Sshinvoid assert_vi_locked(struct vnode *vp, const char *str); 49852904Sshinvoid assert_vi_unlocked(struct vnode *vp, const char *str); 49952904Sshin#if 0 50052904Sshinvoid assert_vop_elocked(struct vnode *vp, const char *str); 50152904Sshinvoid assert_vop_elocked_other(struct vnode *vp, const char *str); 50252904Sshin#endif 50352904Sshinvoid assert_vop_locked(struct vnode *vp, const char *str); 50452904Sshin#if 0 50552904Sshinvoi0 assert_vop_slocked(struct vnode *vp, const char *str); 50652904Sshin#endif 50752904Sshinvoid assert_vop_unlocked(struct vnode *vp, const char *str); 50852904Sshin 50952904Sshin/* These are called from within the actual VOPS. */ 51052904Sshinvoid vop_lock_pre(void *a); 51152904Sshinvoid vop_lock_post(void *a, int rc); 51252904Sshinvoid vop_lookup_post(void *a, int rc); 51352904Sshinvoid vop_lookup_pre(void *a); 51452904Sshinvoid vop_rename_pre(void *a); 51552904Sshinvoid vop_strategy_pre(void *a); 51652904Sshinvoid vop_unlock_post(void *a, int rc); 51752904Sshinvoid vop_unlock_pre(void *a); 51852904Sshin 51952904Sshin#define ASSERT_VI_LOCKED(vp, str) assert_vi_locked((vp), (str)) 52052904Sshin#define ASSERT_VI_UNLOCKED(vp, str) assert_vi_unlocked((vp), (str)) 52152904Sshin#if 0 52252904Sshin#define ASSERT_VOP_ELOCKED(vp, str) assert_vop_elocked((vp), (str)) 52352904Sshin#define ASSERT_VOP_ELOCKED_OTHER(vp, str) assert_vop_locked_other((vp), (str)) 52452904Sshin#endif 52552904Sshin#define ASSERT_VOP_LOCKED(vp, str) assert_vop_locked((vp), (str)) 52652904Sshin#if 0 52752904Sshin#define ASSERT_VOP_SLOCKED(vp, str) assert_vop_slocked((vp), (str)) 52852904Sshin#endif 52952904Sshin#define ASSERT_VOP_UNLOCKED(vp, str) assert_vop_unlocked((vp), (str)) 53052904Sshin 53152904Sshin#else /* !DEBUG_VFS_LOCKS */ 53252904Sshin 53352904Sshin#define ASSERT_VI_LOCKED(vp, str) 53452904Sshin#define ASSERT_VI_UNLOCKED(vp, str) 53552904Sshin#if 0 53652904Sshin#define ASSERT_VOP_ELOCKED(vp, str) 53752904Sshin#define ASSERT_VOP_ELOCKED_OTHER(vp, str) 53852904Sshin#endif 53952904Sshin#define ASSERT_VOP_LOCKED(vp, str) 54052904Sshin#if 0 54152904Sshin#define ASSERT_VOP_SLOCKED(vp, str) 54252904Sshin#endif 54362587Sitojun#define ASSERT_VOP_UNLOCKED(vp, str) 54462587Sitojun#endif /* DEBUG_VFS_LOCKS */ 54562587Sitojun 54652904Sshin/* 54762587Sitojun * VOCALL calls an op given an ops vector. We break it out because BSD's 54852904Sshin * vclean changes the ops vector and then wants to call ops with the old 54962587Sitojun * vector. 55062587Sitojun */ 55162587Sitojun#define VOCALL(OPSV,OFF,AP) (( *((OPSV)[(OFF)])) (AP)) 55262587Sitojun 55362587Sitojun/* 55462587Sitojun * This call works for vnodes in the kernel. 55562587Sitojun */ 55662587Sitojun#define VCALL(VP,OFF,AP) VOCALL((VP)->v_op,(OFF),(AP)) 55762587Sitojun#define VDESC(OP) (& __CONCAT(OP,_desc)) 55862587Sitojun#define VOFFSET(OP) (VDESC(OP)->vdesc_offset) 55962587Sitojun 56062587Sitojun/* 56162587Sitojun * VMIO support inline 56262587Sitojun */ 56362587Sitojun 56462587Sitojunextern int vmiodirenable; 56562587Sitojun 56662587Sitojunstatic __inline int 56795023Ssuzvn_canvmio(struct vnode *vp) 56862587Sitojun{ 56962604Sitojun if (vp && (vp->v_type == VREG || (vmiodirenable && vp->v_type == VDIR))) 57078064Sume return(TRUE); 57162604Sitojun return(FALSE); 57262604Sitojun} 57362604Sitojun 57478064Sume/* 57578064Sume * Finally, include the default set of vnode operations. 57678064Sume */ 57778064Sume#include "vnode_if.h" 57878064Sume 57978064Sume/* 58078064Sume * Public vnode manipulation functions. 58152904Sshin */ 58265124Sitojunstruct componentname; 58378064Sumestruct file; 58478064Sumestruct mount; 58553541Sshinstruct nameidata; 58653541Sshinstruct ostat; 58753541Sshinstruct thread; 58878064Sumestruct proc; 58978064Sumestruct stat; 59078064Sumestruct nstat; 59178064Sumestruct ucred; 59253541Sshinstruct uio; 59352904Sshinstruct vattr; 59478064Sumestruct vnode; 59552904Sshin 59662587Sitojunextern int (*lease_check_hook)(struct vop_lease_args *); 59752904Sshinextern int (*softdep_fsync_hook)(struct vnode *); 59852904Sshinextern int (*softdep_process_worklist_hook)(struct mount *); 59952904Sshin 60052904Sshinstruct vnode *addaliasu(struct vnode *vp, dev_t nvp_rdev); 60178064Sumeint bdevvp(struct cdev *dev, struct vnode **vpp); 60278064Sume/* cache_* may belong in namei.h. */ 60392700Sdarrenrvoid cache_enter(struct vnode *dvp, struct vnode *vp, 60452904Sshin struct componentname *cnp); 60552904Sshinint cache_lookup(struct vnode *dvp, struct vnode **vpp, 60652904Sshin struct componentname *cnp); 60752904Sshinvoid cache_purge(struct vnode *vp); 60852904Sshinvoid cache_purgevfs(struct mount *mp); 60952904Sshinint cache_leaf_test(struct vnode *vp); 61052904Sshinint change_dir(struct vnode *vp, struct thread *td); 61152904Sshinint change_root(struct vnode *vp, struct thread *td); 61278064Sumevoid cvtstat(struct stat *st, struct ostat *ost); 61378064Sumevoid cvtnstat(struct stat *sb, struct nstat *nsb); 61478064Sumeint getnewvnode(const char *tag, struct mount *mp, vop_t **vops, 61583934Sbrooks struct vnode **vpp); 61683934Sbrooksint lease_check(struct vop_lease_args *ap); 61752904Sshinint spec_vnoperate(struct vop_generic_args *); 61852904Sshinint speedup_syncer(void); 61997181Smike#define textvp_fullpath(p, rb, rfb) \ 62097181Smike vn_fullpath(FIRST_THREAD_IN_PROC(p), (p)->p_textvp, rb, rfb) 62197181Smikeint vn_fullpath(struct thread *td, struct vnode *vn, 62297181Smike char **retbuf, char **freebuf); 62397181Smikeint vaccess(enum vtype type, mode_t file_mode, uid_t uid, gid_t gid, 62452904Sshin mode_t acc_mode, struct ucred *cred, int *privused); 62552904Sshinint vaccess_acl_posix1e(enum vtype type, uid_t file_uid, 62652904Sshin gid_t file_gid, struct acl *acl, mode_t acc_mode, 62778064Sume struct ucred *cred, int *privused); 62878064Sumevoid vattr_null(struct vattr *vap); 62997181Smikeint vcount(struct vnode *vp); 63078064Sumevoid vdrop(struct vnode *); 63197181Smikevoid vdropl(struct vnode *); 63297181Smikeint vfinddev(struct cdev *dev, struct vnode **vpp); 63397181Smikevoid vfs_add_vnodeops(const void *); 63452904Sshinvoid vfs_rm_vnodeops(const void *); 63578064Sumeint vflush(struct mount *mp, int rootrefs, int flags, struct thread *td); 63678064Sumeint vget(struct vnode *vp, int lockflag, struct thread *td); 63778064Sumevoid vgone(struct vnode *vp); 63878064Sumevoid vgonel(struct vnode *vp, struct thread *td); 63978064Sumevoid vhold(struct vnode *); 64078064Sumevoid vholdl(struct vnode *); 64178064Sumeint vinvalbuf(struct vnode *vp, int save, struct ucred *cred, 64278064Sume struct thread *td, int slpflag, int slptimeo); 64378064Sumeint vtruncbuf(struct vnode *vp, struct ucred *cred, struct thread *td, 64478064Sume off_t length, int blksize); 64578064Sumevoid vprint(char *label, struct vnode *vp); 64678064Sumeint vrecycle(struct vnode *vp, struct mtx *inter_lkp, 64778064Sume struct thread *td); 64897181Smikeint vn_close(struct vnode *vp, 64997181Smike int flags, struct ucred *file_cred, struct thread *td); 65078064Sumevoid vn_finished_write(struct mount *mp); 65178064Sumeint vn_isdisk(struct vnode *vp, int *errp); 65278064Sumeint vn_lock(struct vnode *vp, int flags, struct thread *td); 65397181Smike#ifdef DEBUG_LOCKS 65478064Sumeint debug_vn_lock(struct vnode *vp, int flags, struct thread *p, 65597181Smike const char *filename, int line); 65678064Sume#define vn_lock(vp,flags,p) debug_vn_lock(vp,flags,p,__FILE__,__LINE__) 65778064Sume#endif 65878064Sumeint vn_open(struct nameidata *ndp, int *flagp, int cmode, int fdidx); 65978064Sumeint vn_open_cred(struct nameidata *ndp, int *flagp, int cmode, 66078064Sume struct ucred *cred, int fdidx); 66178064Sumevoid vn_pollevent(struct vnode *vp, int events); 66278064Sumevoid vn_pollgone(struct vnode *vp); 66378064Sumeint vn_pollrecord(struct vnode *vp, struct thread *p, int events); 66452904Sshinint vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, 66552904Sshin int len, off_t offset, enum uio_seg segflg, int ioflg, 66697181Smike struct ucred *active_cred, struct ucred *file_cred, int *aresid, 66797181Smike struct thread *td); 66852904Sshinint vn_rdwr_inchunks(enum uio_rw rw, struct vnode *vp, caddr_t base, 669 size_t len, off_t offset, enum uio_seg segflg, int ioflg, 670 struct ucred *active_cred, struct ucred *file_cred, size_t *aresid, 671 struct thread *td); 672int vn_stat(struct vnode *vp, struct stat *sb, struct ucred *active_cred, 673 struct ucred *file_cred, struct thread *td); 674int vn_start_write(struct vnode *vp, struct mount **mpp, int flags); 675struct cdev *vn_todev(struct vnode *vp); 676int vn_write_suspend_wait(struct vnode *vp, struct mount *mp, 677 int flags); 678int vn_writechk(struct vnode *vp); 679int vn_extattr_get(struct vnode *vp, int ioflg, int attrnamespace, 680 const char *attrname, int *buflen, char *buf, struct thread *td); 681int vn_extattr_set(struct vnode *vp, int ioflg, int attrnamespace, 682 const char *attrname, int buflen, char *buf, struct thread *td); 683int vn_extattr_rm(struct vnode *vp, int ioflg, int attrnamespace, 684 const char *attrname, struct thread *td); 685int vfs_cache_lookup(struct vop_lookup_args *ap); 686int vfs_object_create(struct vnode *vp, struct thread *td, 687 struct ucred *cred); 688void vfs_timestamp(struct timespec *); 689void vfs_write_resume(struct mount *mp); 690int vfs_write_suspend(struct mount *mp); 691int vop_stdbmap(struct vop_bmap_args *); 692int vop_stdfsync(struct vop_fsync_args *); 693int vop_stdgetwritemount(struct vop_getwritemount_args *); 694int vop_stdgetpages(struct vop_getpages_args *); 695int vop_stdinactive(struct vop_inactive_args *); 696int vop_stdislocked(struct vop_islocked_args *); 697int vop_stdlock(struct vop_lock_args *); 698int vop_stdputpages(struct vop_putpages_args *); 699int vop_stdunlock(struct vop_unlock_args *); 700int vop_nopoll(struct vop_poll_args *); 701int vop_stdpathconf(struct vop_pathconf_args *); 702int vop_stdpoll(struct vop_poll_args *); 703int vop_revoke(struct vop_revoke_args *); 704int vop_eopnotsupp(struct vop_generic_args *ap); 705int vop_ebadf(struct vop_generic_args *ap); 706int vop_einval(struct vop_generic_args *ap); 707int vop_enotty(struct vop_generic_args *ap); 708int vop_defaultop(struct vop_generic_args *ap); 709int vop_null(struct vop_generic_args *ap); 710int vop_panic(struct vop_generic_args *ap); 711int vop_stdcreatevobject(struct vop_createvobject_args *ap); 712int vop_stddestroyvobject(struct vop_destroyvobject_args *ap); 713int vop_stdgetvobject(struct vop_getvobject_args *ap); 714 715void vfree(struct vnode *); 716void vput(struct vnode *vp); 717void vrele(struct vnode *vp); 718void vref(struct vnode *vp); 719int vrefcnt(struct vnode *vp); 720void vbusy(struct vnode *vp); 721void v_addpollinfo(struct vnode *vp); 722 723extern vop_t **default_vnodeop_p; 724extern vop_t **spec_vnodeop_p; 725extern vop_t **dead_vnodeop_p; 726 727#endif /* _KERNEL */ 728 729#endif /* !_SYS_VNODE_H_ */ 730