xref: /netbsd-src/share/man/man9/vnode.9 (revision 92e958de60c71aa0f2452bd7074cbb006fe6546b)
1.\"     $NetBSD: vnode.9,v 1.72 2016/08/20 12:41:31 wiz Exp $
2.\"
3.\" Copyright (c) 2001, 2005, 2006 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Gregory McGarry.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd August 20, 2016
31.Dt VNODE 9
32.Os
33.Sh NAME
34.Nm vnode ,
35.Nm vref ,
36.Nm vrele ,
37.Nm vrele_async ,
38.Nm vget ,
39.Nm vput ,
40.Nm vhold ,
41.Nm holdrele ,
42.Nm vcache_get ,
43.Nm vcache_new ,
44.Nm vcache_rekey_enter ,
45.Nm vcache_rekey_exit ,
46.Nm vrecycle ,
47.Nm vgone ,
48.Nm vgonel ,
49.Nm vdead_check ,
50.Nm vflush ,
51.Nm vaccess ,
52.Nm bdevvp ,
53.Nm cdevvp ,
54.Nm vfinddev ,
55.Nm vdevgone ,
56.Nm vwakeup ,
57.Nm vflushbuf ,
58.Nm vinvalbuf ,
59.Nm vtruncbuf ,
60.Nm vprint
61.Nd kernel representation of a file or directory
62.Sh SYNOPSIS
63.In sys/param.h
64.In sys/vnode.h
65.Ft void
66.Fn vref "struct vnode *vp"
67.Ft void
68.Fn vrele "struct vnode *vp"
69.Ft void
70.Fn vrele_async "struct vnode *vp"
71.Ft int
72.Fn vget "struct vnode *vp" "int lockflag" "int wait"
73.Ft void
74.Fn vput "struct vnode *vp"
75.Ft void
76.Fn vhold "struct vnode *vp"
77.Ft void
78.Fn holdrele "struct vnode *vp"
79.Ft int
80.Fn vcache_get "struct mount *mp" "const void *key" "size_t key_len" "struct vnode **vpp"
81.Ft int
82.Fn vcache_new "struct mount *mp" "struct vnode *dvp" "struct vattr *vap" "kauth_cred_t cred" "struct vnode **vpp"
83.Ft int
84.Fn vcache_rekey_enter "struct mount *mp" "struct vnode *vp" "const void *old_key" "size_t old_key_len" "const void *new_key" "size_t new_key_len"
85.Ft void
86.Fn vcache_rekey_exit "struct mount *mp" "struct vnode *vp" "const void *old_key" "size_t old_key_len" "const void *new_key" "size_t new_key_len"
87.Ft int
88.Fn vrecycle "struct vnode *vp"
89.Ft void
90.Fn vgone "struct vnode *vp"
91.Ft void
92.Fn vgonel "struct vnode *vp" "struct lwp *l"
93.Ft int
94.Fn vdead_check "struct vnode *vp" "int flags"
95.Ft int
96.Fn vflush "struct mount *mp" "struct vnode *skipvp" "int flags"
97.Ft int
98.Fn vaccess "enum vtype type" "mode_t file_mode" "uid_t uid" "gid_t gid" "mode_t acc_mode" "kauth_cred_t cred"
99.Ft int
100.Fn bdevvp "dev_t dev" "struct vnode **vpp"
101.Ft int
102.Fn cdevvp "dev_t dev" "struct vnode **vpp"
103.Ft int
104.Fn vfinddev "dev_t dev" "enum vtype" "struct vnode **vpp"
105.Ft void
106.Fn vdevgone "int maj" "int minl" "int minh" "enum vtype type"
107.Ft void
108.Fn vwakeup "struct buf *bp"
109.Ft int
110.Fn vflushbuf "struct vnode *vp" "int sync"
111.Ft int
112.Fn vinvalbuf "struct vnode *vp" "int flags" "kauth_cred_t cred" "struct lwp *l" "int slpflag" "int slptimeo"
113.Ft int
114.Fn vtruncbuf "struct vnode *vp" "daddr_t lbn" "int slpflag" "int slptimeo"
115.Ft void
116.Fn vprint "const char *label" "struct vnode *vp"
117.Sh DESCRIPTION
118A
119.Em vnode
120represents an on-disk file in use by the system.
121Each
122.Xr vfs 9
123file system provides a set of
124.Xr vnodeops 9
125operations on vnodes, invoked by file-system-independent system calls
126and supported by file-system-independent library routines.
127.Pp
128Each mounted file system provides a vnode for the root of the file
129system, via
130.Xr VFS_ROOT 9 .
131Other vnodes are obtained by
132.Xr VOP_LOOKUP 9 .
133Users of vnodes usually invoke these indirectly via
134.Xr namei 9
135to obtain vnodes from paths.
136.Pp
137Each file system usually maintains a cache mapping recently used inode
138numbers, or the equivalent, to vnodes, and a cache mapping recently
139used file names to vnodes.
140If memory is scarce, the system may decide to
141.Em reclaim
142an unused cached vnode, calling
143.Xr VOP_RECLAIM 9
144to remove it from the caches and to free file-system-specific memory
145associated with it.
146A file system may also choose to immediately reclaim a cached vnode
147once it is unused, in
148.Xr VOP_INACTIVE 9 ,
149if the vnode has been deleted on disk.
150.Pp
151When a file system retrieves a vnode from a cache, the vnode may not
152have any users, and another thread in the system may be simultaneously
153deciding to reclaim it.
154Thus, to retrieve a vnode from a cache, one must use
155.Fn vget ,
156not
157.Fn vref ,
158to acquire the first reference, and be prepared for
159.Fn vget
160to fail if another thread is reclaiming the vnode.
161.Pp
162The vnode has the following structure:
163.Bd -literal
164struct vnode {
165	struct uvm_object v_uobj;		/* the VM object */
166	kcondvar_t	v_cv;			/* synchronization */
167	voff_t		v_size;			/* size of file */
168	voff_t		v_writesize;		/* new size after write */
169	int		v_iflag;		/* VI_* flags */
170	int		v_vflag;		/* VV_* flags */
171	int		v_uflag;		/* VU_* flags */
172	int		v_numoutput;		/* # of pending writes */
173	int		v_writecount;		/* ref count of writers */
174	int		v_holdcnt;		/* page & buffer refs */
175	int		v_synclist_slot;	/* synclist slot index */
176	struct mount	*v_mount;		/* ptr to vfs we are in */
177	int		(**v_op)(void *);	/* vnode operations vector */
178	TAILQ_ENTRY(vnode) v_freelist;		/* vnode freelist */
179	struct vnodelst	*v_freelisthd;		/* which freelist? */
180	TAILQ_ENTRY(vnode) v_mntvnodes;		/* vnodes for mount point */
181	struct buflists	v_cleanblkhd;		/* clean blocklist head */
182	struct buflists	v_dirtyblkhd;		/* dirty blocklist head */
183	TAILQ_ENTRY(vnode) v_synclist;		/* vnodes with dirty bufs */
184	LIST_HEAD(, namecache) v_dnclist;	/* namecaches (children) */
185	LIST_HEAD(, namecache) v_nclist;	/* namecaches (parent) */
186	union {
187		struct mount	*vu_mountedhere;/* ptr to vfs (VDIR) */
188		struct socket	*vu_socket;	/* unix ipc (VSOCK) */
189		struct specnode	*vu_specnode;	/* device (VCHR, VBLK) */
190		struct fifoinfo	*vu_fifoinfo;	/* fifo (VFIFO) */
191		struct uvm_ractx *vu_ractx;	/* read-ahead ctx (VREG) */
192	} v_un;
193	enum vtype	v_type;			/* vnode type */
194	enum vtagtype	v_tag;			/* type of underlying data */
195	struct vnlock	v_lock;			/* lock for this vnode */
196	void 		*v_data;		/* private data for fs */
197	struct klist	v_klist;		/* notes attached to vnode */
198};
199.Ed
200.Pp
201Most members of the vnode structure should be treated as opaque and
202only manipulated using the proper functions.
203There are some rather common exceptions detailed throughout this page.
204.Pp
205Files and file systems are inextricably linked with the virtual memory
206system and
207.Em v_uobj
208contains the data maintained by the virtual memory system.
209For compatibility with code written before the integration of
210.Xr uvm 9
211into
212.Nx ,
213C-preprocessor directives are used to alias the members of
214.Em v_uobj .
215.Pp
216Vnode flags are recorded by
217.Em v_iflag ,
218.Em v_vflag
219and
220.Em v_uflag .
221Valid flags are:
222.Pp
223.Bl -tag -offset indent -width ".Dv VI_WRMAPDIRTY" -compact
224.It Dv VV_ROOT
225This vnode is the root of its file system.
226.It Dv VV_SYSTEM
227This vnode is being used by the kernel; only used to skip quota files in
228.Fn vflush .
229.It Dv VV_ISTTY
230This vnode represents a tty; used when reading dead vnodes.
231.It Dv VV_MAPPED
232This vnode might have user mappings.
233.It Dv VV_MPSAFE
234This file system is MP safe.
235.It Dv VV_LOCKSWORK
236This vnode's file system supports locking.
237.It Dv VI_TEXT
238This vnode is a pure text prototype.
239.It Dv VI_EXECMAP
240This vnode has executable mappings.
241.It Dv VI_WRMAP
242This vnode might have PROT_WRITE user mappings.
243.It Dv VI_WRMAPDIRTY
244This vnode might have dirty pages due to
245.Dv VWRITEMAP .
246.It Dv VI_XLOCK
247This vnode is currently locked to change underlying type.
248.It Dv VI_ONWORKLST
249This vnode is on syncer work-list.
250.It Dv VI_MARKER
251A dummy marker vnode.
252.It Dv VI_CLEAN
253This vnode has been reclaimed and is no longer attached to a file system.
254.It Dv VU_DIROP
255This vnode is involved in a directory operation.
256This flag is used exclusively by LFS.
257.El
258.Pp
259The
260.Dv VI_XLOCK
261flag is used to prevent multiple processes from entering
262the vnode reclamation code.
263It is also used as a flag to indicate that reclamation is in progress.
264Before
265.Em v_iflag
266can be modified, the
267.Em v_interlock
268mutex must be acquired.
269See
270.Xr lock 9
271for details on the kernel locking API.
272.Pp
273Each vnode has three reference counts:
274.Em v_usecount ,
275.Em v_writecount
276and
277.Em v_holdcnt .
278The first is the number of active references within the
279kernel to the vnode.
280This count is maintained by
281.Fn vref ,
282.Fn vrele ,
283.Fn vrele_async ,
284and
285.Fn vput .
286The second is the number of active references within the kernel to the
287vnode performing write access to the file.
288It is maintained by the
289.Xr open 2
290and
291.Xr close 2
292system calls.
293The third is the number of references within the kernel
294requiring the vnode to remain active and not be recycled.
295This count is maintained by
296.Fn vhold
297and
298.Fn holdrele .
299When both the
300.Em v_usecount
301and
302.Em v_holdcnt
303reach zero, the vnode is recycled to the freelist and may be reused
304for another file.
305The transition to and from the freelist is handled by
306a kernel thread
307and
308.Fn vrecycle .
309Access to
310.Em v_usecount ,
311.Em v_writecount
312and
313.Em v_holdcnt
314is also protected by the
315.Em v_interlock
316mutex.
317.Pp
318The number of pending synchronous and asynchronous writes on the
319vnode are recorded in
320.Em v_numoutput .
321It is used by
322.Xr fsync 2
323to wait for all writes to complete before returning to the user.
324Its value must only be modified at splbio (see
325.Xr spl 9 ) .
326It does not track the number of dirty buffers attached to the
327vnode.
328.Pp
329.Em v_dnclist
330and
331.Em v_nclist
332are used by
333.Xr namecache 9
334to maintain the list of associated entries so that
335.Xr cache_purge 9
336can purge them.
337.Pp
338The link to the file system which owns the vnode is recorded by
339.Em v_mount .
340See
341.Xr vfsops 9
342for further information of file system mount status.
343.Pp
344The
345.Em v_op
346pointer points to its vnode operations vector.
347This vector describes what operations can be done to the file associated
348with the vnode.
349The system maintains one vnode operations vector for each file system
350type configured into the kernel.
351The vnode operations vector contains a pointer to a function for
352each operation supported by the file system.
353See
354.Xr vnodeops 9
355for a description of vnode operations.
356.Pp
357When not in use, vnodes are kept on the freelist through
358.Em v_freelist .
359The vnodes still reference valid files but may be reused to refer to a
360new file at any time.
361When a valid vnode which is on the freelist is used again, the user
362must call
363.Fn vget
364to increment the reference count and retrieve it from the freelist.
365When a user wants a new vnode for another file,
366.Fn vcache_get
367or
368.Fn vcache_new
369is invoked to allocate a vnode and initialize it for the new file.
370.Pp
371The type of object the vnode represents is recorded by
372.Em v_type .
373It is used by generic code to perform checks to ensure operations are
374performed on valid file system objects.
375Valid types are:
376.Pp
377.Bl -tag -offset indent -width VFIFO -compact
378.It Dv VNON
379The vnode has no type.
380.It Dv VREG
381The vnode represents a regular file.
382.It Dv VDIR
383The vnode represents a directory.
384.It Dv VBLK
385The vnode represents a block special device.
386.It Dv VCHR
387The vnode represents a character special device.
388.It Dv VLNK
389The vnode represents a symbolic link.
390.It Dv VSOCK
391The vnode represents a socket.
392.It Dv VFIFO
393The vnode represents a pipe.
394.It Dv VBAD
395The vnode represents a bad file (not currently used).
396.El
397.Pp
398Vnode tag types are used by external programs only (e.g.,
399.Xr pstat 8 ) ,
400and should never be inspected by the kernel.
401Its use is deprecated
402since new
403.Em v_tag
404values cannot be defined for loadable file systems.
405The
406.Em v_tag
407member is read-only.
408Valid tag types are:
409.Pp
410.Bl -tag -offset indent -width "VT_FILECORE " -compact
411.It Dv VT_NON
412non file system
413.It Dv VT_UFS
414universal file system
415.It Dv VT_NFS
416network file system
417.It Dv VT_MFS
418memory file system
419.It Dv VT_MSDOSFS
420FAT file system
421.It Dv VT_LFS
422log-structured file system
423.It Dv VT_LOFS
424loopback file system
425.It Dv VT_FDESC
426file descriptor file system
427.It Dv VT_NULL
428null file system layer
429.It Dv VT_UMAP
430uid/gid remapping file system layer
431.It Dv VT_KERNFS
432kernel interface file system
433.It Dv VT_PROCFS
434process interface file system
435.It Dv VT_AFS
436AFS file system
437.It Dv VT_ISOFS
438ISO 9660 file system(s)
439.It Dv VT_UNION
440union file system
441.It Dv VT_ADOSFS
442Amiga file system
443.It Dv VT_EXT2FS
444Linux's ext2 file system
445.It Dv VT_CODA
446Coda file system
447.It Dv VT_FILECORE
448filecore file system
449.It Dv VT_NTFS
450Microsoft NT's file system
451.It Dv VT_VFS
452virtual file system
453.It Dv VT_OVERLAY
454overlay file system
455.It Dv VT_SMBFS
456SMB file system
457.It Dv VT_PTYFS
458pseudo-terminal device file system
459.It Dv VT_TMPFS
460efficient memory file system
461.It Dv VT_UDF
462universal disk format file system
463.It Dv VT_SYSVBFS
464systemV boot file system
465.El
466.Pp
467All vnode locking operations use
468.Em v_lock .
469This lock is acquired by calling
470.Xr vn_lock 9
471and released by calling
472.Xr VOP_UNLOCK 9 .
473The reason for this asymmetry is that
474.Xr vn_lock 9
475is a wrapper for
476.Xr VOP_LOCK 9
477with extra checks, while the unlocking step usually does not need
478additional checks and thus has no wrapper.
479.Pp
480The vnode locking operation is complicated because it is used for many
481purposes.
482Sometimes it is used to bundle a series of vnode operations (see
483.Xr vnodeops 9 )
484into an atomic group.
485Many file systems rely on it to prevent race conditions in updating
486file system type specific data structures rather than using their
487own private locks.
488The vnode lock can operate as a multiple-reader (shared-access lock)
489or single-writer lock (exclusive access lock), however many current file
490system implementations were written assuming only single-writer
491locking.
492Multiple-reader locking functions equivalently only in the presence
493of big-lock SMP locking or a uni-processor machine.
494The lock may be held while sleeping.
495While the
496.Em v_lock
497is acquired, the holder is guaranteed that the vnode will not be
498reclaimed or invalidated.
499Most file system functions require that you hold the vnode lock on entry.
500See
501.Xr lock 9
502for details on the kernel locking API.
503.Pp
504Each file system underlying a vnode allocates its own private area and
505hangs it from
506.Em v_data .
507.Pp
508Most functions discussed in this page that operate on vnodes cannot be
509called from interrupt context.
510The members
511.Em v_numoutput ,
512.Em v_holdcnt ,
513.Em v_dirtyblkhd ,
514.Em v_cleanblkhd ,
515.Em v_freelist ,
516and
517.Em v_synclist
518are modified in interrupt context and must be protected by
519.Xr splbio 9
520unless it is certain that there is no chance an interrupt handler will
521modify them.
522The vnode lock must not be acquired within interrupt context.
523.Sh FUNCTIONS
524.Bl -tag -width compact
525.It Fn vref "vp"
526Increment
527.Em v_usecount
528of the vnode
529.Em vp .
530Any kernel thread system which uses a vnode (e.g., during the operation
531of some algorithm or to store in a data structure) should call
532.Fn vref .
533.It Fn vrele "vp"
534Decrement
535.Em v_usecount
536of unlocked vnode
537.Em vp .
538Any code in the system which is using a vnode should call
539.Fn vrele
540when it is finished with the vnode.
541If
542.Em v_usecount
543of the vnode reaches zero and
544.Em v_holdcnt
545is greater than zero, the vnode is placed on the holdlist.
546If both
547.Em v_usecount
548and
549.Em v_holdcnt
550are zero, the vnode is placed on the freelist.
551.It Fn vrele_async "vp"
552Will asychronously release the vnode in different context than the caller,
553sometime after the call.
554.It Fn vget "vp" "lockflags" "wait"
555Reclaim vnode
556.Fa vp
557from the freelist and increment its reference count.
558.Pp
559The vnode
560.Fa vp
561may be changing state: another thread may be initializing it from disk,
562or revoking it with
563.Xr revoke 2 ,
564or reclaiming it with
565.Xr VOP_RECLAIM 9 .
566In that case,
567.Fn vget
568will wait until the state has changed, if
569.Fa lockflags
570is
571.Li 0
572and
573.Fa wait
574is
575.Li true ;
576or will return
577.Er EBUSY
578if
579.Fa lockflags
580is
581.Dv LK_NOWAIT
582and
583.Fa wait
584is
585.Li false .
586.Pp
587(The extra argument enables the compiler to detect old code which
588additionally used
589.Fn vget
590to lock the vnode.)
591.Pp
592Returns
593.Bl -tag -offset abcd -width ENOENT -compact
594.It Er EBUSY
595if
596.Fa vp
597was changing state and
598.Fa wait
599is false.
600.It Er ENOENT
601if the system was reclaiming
602.Fa vp
603with
604.Xr VOP_RECLAIM 9 .
605.It Li 0
606on success.
607.El
608.It Fn vput "vp"
609Legacy convenience routine for unlocking and releasing
610.Fa vp .
611Equivalent to:
612.Bd -literal -offset abcd
613.No "VOP_UNLOCK(" Ns Fa vp Ns Li ");"
614.No "vrele(" Ns Fa vp Ns Li ");"
615.Ed
616.Pp
617Note that this is
618.Em not
619an inverse of
620.Fn vget .
621The name appears so for hysterical raisins.
622New code should prefer using
623.Xr VOP_UNLOCK 9
624and
625.Fn vrele
626directly.
627.It Fn vhold "vp"
628Mark the vnode
629.Fa vp
630as active by incrementing
631.Em vp-\*[Gt]v_holdcnt
632and moving the vnode from the freelist to the holdlist.
633Once on the holdlist, the vnode will not be recycled until it is
634released with
635.Fn holdrele .
636.It Fn holdrele "vp"
637Mark the vnode
638.Fa vp
639as inactive by decrementing
640.Em vp-\*[Gt]v_holdcnt
641and moving the vnode from the holdlist to the freelist.
642.It Fn vcache_get "mp" "key" "key_len" "vpp"
643Allocate a new vnode.
644The new vnode is returned referenced in the address specified by
645.Fa vpp .
646.Pp
647The argument
648.Fa mp
649is the mount point for the file system to lookup the file in.
650.Pp
651The arguments
652.Fa key
653and
654.Fa key_len
655uniquely identify the file in the file system.
656.Pp
657If a vnode is successfully retrieved zero is returned, otherwise an
658appropriate error code is returned.
659.It Fn vcache_new "mp" "dvp" "vap" "cred" "vpp"
660Allocate a new vnode with a new file.
661The new vnode is returned referenced in the address specified by
662.Fa vpp .
663.Pp
664The argument
665.Fa mp
666is the mount point for the file system to create the file in.
667.Pp
668The argument
669.Fa dvp
670points to the directory to create the file in.
671.Pp
672The argument
673.Fa vap
674points to the attributes for the file to create.
675.Pp
676The argument
677.Fa cred
678holds the credentials for the file to create.
679.Pp
680If a vnode is successfully created zero is returned, otherwise an
681appropriate error code is returned.
682.It Fn vcache_rekey_enter "mp" "vp" "old_key" "old_key_len" "new_key" "new_key_len"
683Prepare to change the key of a cached vnode.
684.Pp
685The argument
686.Fa mp
687is the mount point for the file system the vnode
688.Fa vp
689resides in.
690.Pp
691The arguments
692.Fa old_key
693and
694.Fa old_key_len
695identify the cached vnode.
696.Pp
697The arguments
698.Fa new_key
699and
700.Fa new_key_len
701will identify the vnode after rename.
702.Pp
703If the new key already exists
704.Er EEXIST
705is returned, otherwise zero is returned.
706.It Fn vcache_rekey_exit "mp" "vp" "old_key" "old_key_len" "new_key" "new_key_len"
707Finish rename after calling
708.Fn vcache_rekey_enter .
709.It Fn vrecycle "vp"
710Recycle the referenced vnode
711.Fa vp
712if this is the last reference.
713.Fn vrecycle
714is a null operation if the reference count is greater than one.
715.It Fn vgone "vp"
716Eliminate all activity associated with the unlocked vnode
717.Fa vp
718in preparation for recycling.
719.It Fn vgonel "vp" "p"
720Eliminate all activity associated with the locked vnode
721.Fa vp
722in preparation for recycling.
723.It Fn vdead_check "vp" "flags"
724Check the vnode
725.Fa vp
726for being or becoming dead.
727Returns
728.Er ENOENT
729for a dead vnode and zero otherwise.
730If
731.Fa flags
732is
733.Dv VDEAD_NOWAIT
734it will return
735.Er EBUSY
736if the vnode is becoming dead and the function will not sleep.
737.Pp
738Whenever this function returns a non-zero value all future calls
739for this
740.Fa vp
741will also return a non-zero value.
742.It Fn vflush "mp" "skipvp" "flags"
743Remove any vnodes in the vnode table belonging to mount point
744.Fa mp .
745If
746.Fa skipvp
747is not
748.Dv NULL
749it is exempt from being flushed.
750The argument
751.Fa flags
752is a set of flags modifying the operation of
753.Fn vflush .
754If
755.Dv FORCECLOSE
756is not specified, there should not be any active vnodes and
757the error
758.Er EBUSY
759is returned if any are found (this is a user error, not a system error).
760If
761.Dv FORCECLOSE
762is specified, active vnodes that are found are detached.
763If
764.Dv WRITECLOSE
765is set, only flush out regular file vnodes open for writing.
766SKIPSYSTEM causes any vnodes marked
767.Dv V_SYSTEM
768to be skipped.
769.It Fn vaccess "type" "file_mode" "uid" "gid" "acc_mode" "cred"
770Do access checking by comparing the file's permissions to the caller's
771desired access type
772.Fa acc_mode
773and credentials
774.Fa cred .
775.It Fn bdevvp "dev" "vpp"
776Create a vnode for a block device.
777.Fn bdevvp
778is used for root file systems, swap areas and for memory file system
779special devices.
780.It Fn cdevvp "dev" "vpp"
781Create a vnode for a character device.
782.Fn cdevvp
783is used for the console and kernfs special devices.
784.It Fn vfinddev "dev" "vtype" "vpp"
785Lookup a vnode by device number.
786The vnode is referenced and returned in the address specified by
787.Fa vpp .
788.It Fn vdevgone "int maj" "int min" "int minh" "enum vtype type"
789Reclaim all vnodes that correspond to the specified minor number range
790.Fa minl
791to
792.Fa minh
793(endpoints inclusive) of the specified major
794.Fa maj .
795.It Fn vwakeup "bp"
796Update outstanding I/O count
797.Em vp-\*[Gt]v_numoutput
798for the vnode
799.Em bp-\*[Gt]b_vp
800and do a wakeup if requested and
801.Em vp-\*[Gt]vflag
802has
803.Dv VBWAIT
804set.
805.It Fn vflushbuf "vp" "sync"
806Flush all dirty buffers to disk for the file with the locked vnode
807.Fa vp .
808The argument
809.Fa sync
810specifies whether the I/O should be synchronous and
811.Fn vflushbuf
812will sleep until
813.Em vp-\*[Gt]v_numoutput
814is zero and
815.Em vp-\*[Gt]v_dirtyblkhd
816is empty.
817.It Fn vinvalbuf "vp" "flags" "cred" "l" "slpflag" "slptimeo"
818Flush out and invalidate all buffers associated with locked vnode
819.Fa vp .
820The argument
821.Fa l
822and
823.Fa cred
824specified the calling process and its credentials.
825The
826.Xr ltsleep 9
827flag and timeout are specified by the arguments
828.Fa slpflag
829and
830.Fa slptimeo
831respectively.
832If the operation is successful zero is returned, otherwise an
833appropriate error code is returned.
834.It Fn vtruncbuf "vp" "lbn" "slpflag" "slptimeo"
835Destroy any in-core buffers past the file truncation length for the
836locked vnode
837.Fa vp .
838The truncation length is specified by
839.Fa lbn .
840.Fn vtruncbuf
841will sleep while the I/O is performed,  The
842.Xr ltsleep 9
843flag and timeout are specified by the arguments
844.Fa slpflag
845and
846.Fa slptimeo
847respectively.
848If the operation is successful zero is returned, otherwise an
849appropriate error code is returned.
850.It Fn vprint "label" "vp"
851This function is used by the kernel to dump vnode information during a
852panic.
853It is only used if the kernel option DIAGNOSTIC is compiled into the kernel.
854The argument
855.Fa label
856is a string to prefix the information dump of vnode
857.Fa vp .
858.El
859.Sh CODE REFERENCES
860The vnode framework is implemented within the file
861.Pa sys/kern/vfs_subr.c .
862.Sh SEE ALSO
863.Xr intro 9 ,
864.Xr lock 9 ,
865.Xr namecache 9 ,
866.Xr namei 9 ,
867.Xr uvm 9 ,
868.Xr vattr 9 ,
869.Xr vfs 9 ,
870.Xr vfsops 9 ,
871.Xr vnodeops 9 ,
872.Xr vnsubr 9
873.Sh BUGS
874The locking protocol is inconsistent.
875Many vnode operations are passed locked vnodes on entry but release
876the lock before they exit.
877The locking protocol is used in some places to attempt to make a
878series of operations atomic (e.g., access check then operation).
879This does not work for non-local file systems that do not support locking
880(e.g., NFS).
881The
882.Nm
883interface would benefit from a simpler locking protocol.
884