xref: /netbsd-src/share/man/man9/vnode.9 (revision 2e2322c9c07009df921d11b1268f8506affbb8ba)
1.\"     $NetBSD: vnode.9,v 1.73 2016/12/14 15:48:54 hannken 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 December 14, 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_mntvnodes;		/* vnodes for mount point */
179	struct buflists	v_cleanblkhd;		/* clean blocklist head */
180	struct buflists	v_dirtyblkhd;		/* dirty blocklist head */
181	TAILQ_ENTRY(vnode) v_synclist;		/* vnodes with dirty bufs */
182	LIST_HEAD(, namecache) v_dnclist;	/* namecaches (children) */
183	LIST_HEAD(, namecache) v_nclist;	/* namecaches (parent) */
184	union {
185		struct mount	*vu_mountedhere;/* ptr to vfs (VDIR) */
186		struct socket	*vu_socket;	/* unix ipc (VSOCK) */
187		struct specnode	*vu_specnode;	/* device (VCHR, VBLK) */
188		struct fifoinfo	*vu_fifoinfo;	/* fifo (VFIFO) */
189		struct uvm_ractx *vu_ractx;	/* read-ahead ctx (VREG) */
190	} v_un;
191	enum vtype	v_type;			/* vnode type */
192	enum vtagtype	v_tag;			/* type of underlying data */
193	struct vnlock	v_lock;			/* lock for this vnode */
194	void 		*v_data;		/* private data for fs */
195	struct klist	v_klist;		/* notes attached to vnode */
196};
197.Ed
198.Pp
199Most members of the vnode structure should be treated as opaque and
200only manipulated using the proper functions.
201There are some rather common exceptions detailed throughout this page.
202.Pp
203Files and file systems are inextricably linked with the virtual memory
204system and
205.Em v_uobj
206contains the data maintained by the virtual memory system.
207For compatibility with code written before the integration of
208.Xr uvm 9
209into
210.Nx ,
211C-preprocessor directives are used to alias the members of
212.Em v_uobj .
213.Pp
214Vnode flags are recorded by
215.Em v_iflag ,
216.Em v_vflag
217and
218.Em v_uflag .
219Valid flags are:
220.Pp
221.Bl -tag -offset indent -width ".Dv VI_WRMAPDIRTY" -compact
222.It Dv VV_ROOT
223This vnode is the root of its file system.
224.It Dv VV_SYSTEM
225This vnode is being used by the kernel; only used to skip quota files in
226.Fn vflush .
227.It Dv VV_ISTTY
228This vnode represents a tty; used when reading dead vnodes.
229.It Dv VV_MAPPED
230This vnode might have user mappings.
231.It Dv VV_MPSAFE
232This file system is MP safe.
233.It Dv VV_LOCKSWORK
234This vnode's file system supports locking.
235.It Dv VI_TEXT
236This vnode is a pure text prototype.
237.It Dv VI_EXECMAP
238This vnode has executable mappings.
239.It Dv VI_WRMAP
240This vnode might have PROT_WRITE user mappings.
241.It Dv VI_WRMAPDIRTY
242This vnode might have dirty pages due to
243.Dv VWRITEMAP .
244.It Dv VI_XLOCK
245This vnode is currently locked to change underlying type.
246.It Dv VI_ONWORKLST
247This vnode is on syncer work-list.
248.It Dv VI_MARKER
249A dummy marker vnode.
250.It Dv VI_CLEAN
251This vnode has been reclaimed and is no longer attached to a file system.
252.It Dv VU_DIROP
253This vnode is involved in a directory operation.
254This flag is used exclusively by LFS.
255.El
256.Pp
257The
258.Dv VI_XLOCK
259flag is used to prevent multiple processes from entering
260the vnode reclamation code.
261It is also used as a flag to indicate that reclamation is in progress.
262Before
263.Em v_iflag
264can be modified, the
265.Em v_interlock
266mutex must be acquired.
267See
268.Xr lock 9
269for details on the kernel locking API.
270.Pp
271Each vnode has three reference counts:
272.Em v_usecount ,
273.Em v_writecount
274and
275.Em v_holdcnt .
276The first is the number of active references within the
277kernel to the vnode.
278This count is maintained by
279.Fn vref ,
280.Fn vrele ,
281.Fn vrele_async ,
282and
283.Fn vput .
284The second is the number of active references within the kernel to the
285vnode performing write access to the file.
286It is maintained by the
287.Xr open 2
288and
289.Xr close 2
290system calls.
291The third is the number of references within the kernel
292requiring the vnode to remain active and not be recycled.
293This count is maintained by
294.Fn vhold
295and
296.Fn holdrele .
297When both the
298.Em v_usecount
299and
300.Em v_holdcnt
301reach zero, the vnode is cached.
302The transition from the cache is handled by a kernel thread and
303.Fn vrecycle .
304Access to
305.Em v_usecount ,
306.Em v_writecount
307and
308.Em v_holdcnt
309is also protected by the
310.Em v_interlock
311mutex.
312.Pp
313The number of pending synchronous and asynchronous writes on the
314vnode are recorded in
315.Em v_numoutput .
316It is used by
317.Xr fsync 2
318to wait for all writes to complete before returning to the user.
319Its value must only be modified at splbio (see
320.Xr spl 9 ) .
321It does not track the number of dirty buffers attached to the
322vnode.
323.Pp
324.Em v_dnclist
325and
326.Em v_nclist
327are used by
328.Xr namecache 9
329to maintain the list of associated entries so that
330.Xr cache_purge 9
331can purge them.
332.Pp
333The link to the file system which owns the vnode is recorded by
334.Em v_mount .
335See
336.Xr vfsops 9
337for further information of file system mount status.
338.Pp
339The
340.Em v_op
341pointer points to its vnode operations vector.
342This vector describes what operations can be done to the file associated
343with the vnode.
344The system maintains one vnode operations vector for each file system
345type configured into the kernel.
346The vnode operations vector contains a pointer to a function for
347each operation supported by the file system.
348See
349.Xr vnodeops 9
350for a description of vnode operations.
351.Pp
352When a valid vnode which is cached is used again, the user must call
353.Fn vget
354to increment the reference count.
355When a user wants a new vnode for another file,
356.Fn vcache_get
357or
358.Fn vcache_new
359is invoked to allocate a vnode and initialize it for the new file.
360.Pp
361The type of object the vnode represents is recorded by
362.Em v_type .
363It is used by generic code to perform checks to ensure operations are
364performed on valid file system objects.
365Valid types are:
366.Pp
367.Bl -tag -offset indent -width VFIFO -compact
368.It Dv VNON
369The vnode has no type.
370.It Dv VREG
371The vnode represents a regular file.
372.It Dv VDIR
373The vnode represents a directory.
374.It Dv VBLK
375The vnode represents a block special device.
376.It Dv VCHR
377The vnode represents a character special device.
378.It Dv VLNK
379The vnode represents a symbolic link.
380.It Dv VSOCK
381The vnode represents a socket.
382.It Dv VFIFO
383The vnode represents a pipe.
384.It Dv VBAD
385The vnode represents a bad file (not currently used).
386.El
387.Pp
388Vnode tag types are used by external programs only (e.g.,
389.Xr pstat 8 ) ,
390and should never be inspected by the kernel.
391Its use is deprecated
392since new
393.Em v_tag
394values cannot be defined for loadable file systems.
395The
396.Em v_tag
397member is read-only.
398Valid tag types are:
399.Pp
400.Bl -tag -offset indent -width "VT_FILECORE " -compact
401.It Dv VT_NON
402non file system
403.It Dv VT_UFS
404universal file system
405.It Dv VT_NFS
406network file system
407.It Dv VT_MFS
408memory file system
409.It Dv VT_MSDOSFS
410FAT file system
411.It Dv VT_LFS
412log-structured file system
413.It Dv VT_LOFS
414loopback file system
415.It Dv VT_FDESC
416file descriptor file system
417.It Dv VT_NULL
418null file system layer
419.It Dv VT_UMAP
420uid/gid remapping file system layer
421.It Dv VT_KERNFS
422kernel interface file system
423.It Dv VT_PROCFS
424process interface file system
425.It Dv VT_AFS
426AFS file system
427.It Dv VT_ISOFS
428ISO 9660 file system(s)
429.It Dv VT_UNION
430union file system
431.It Dv VT_ADOSFS
432Amiga file system
433.It Dv VT_EXT2FS
434Linux's ext2 file system
435.It Dv VT_CODA
436Coda file system
437.It Dv VT_FILECORE
438filecore file system
439.It Dv VT_NTFS
440Microsoft NT's file system
441.It Dv VT_VFS
442virtual file system
443.It Dv VT_OVERLAY
444overlay file system
445.It Dv VT_SMBFS
446SMB file system
447.It Dv VT_PTYFS
448pseudo-terminal device file system
449.It Dv VT_TMPFS
450efficient memory file system
451.It Dv VT_UDF
452universal disk format file system
453.It Dv VT_SYSVBFS
454systemV boot file system
455.El
456.Pp
457All vnode locking operations use
458.Em v_lock .
459This lock is acquired by calling
460.Xr vn_lock 9
461and released by calling
462.Xr VOP_UNLOCK 9 .
463The reason for this asymmetry is that
464.Xr vn_lock 9
465is a wrapper for
466.Xr VOP_LOCK 9
467with extra checks, while the unlocking step usually does not need
468additional checks and thus has no wrapper.
469.Pp
470The vnode locking operation is complicated because it is used for many
471purposes.
472Sometimes it is used to bundle a series of vnode operations (see
473.Xr vnodeops 9 )
474into an atomic group.
475Many file systems rely on it to prevent race conditions in updating
476file system type specific data structures rather than using their
477own private locks.
478The vnode lock can operate as a multiple-reader (shared-access lock)
479or single-writer lock (exclusive access lock), however many current file
480system implementations were written assuming only single-writer
481locking.
482Multiple-reader locking functions equivalently only in the presence
483of big-lock SMP locking or a uni-processor machine.
484The lock may be held while sleeping.
485While the
486.Em v_lock
487is acquired, the holder is guaranteed that the vnode will not be
488reclaimed or invalidated.
489Most file system functions require that you hold the vnode lock on entry.
490See
491.Xr lock 9
492for details on the kernel locking API.
493.Pp
494Each file system underlying a vnode allocates its own private area and
495hangs it from
496.Em v_data .
497.Pp
498Most functions discussed in this page that operate on vnodes cannot be
499called from interrupt context.
500The members
501.Em v_numoutput ,
502.Em v_holdcnt ,
503.Em v_dirtyblkhd ,
504.Em v_cleanblkhd ,
505and
506.Em v_synclist
507are modified in interrupt context and must be protected by
508.Xr splbio 9
509unless it is certain that there is no chance an interrupt handler will
510modify them.
511The vnode lock must not be acquired within interrupt context.
512.Sh FUNCTIONS
513.Bl -tag -width compact
514.It Fn vref "vp"
515Increment
516.Em v_usecount
517of the vnode
518.Em vp .
519Any kernel thread system which uses a vnode (e.g., during the operation
520of some algorithm or to store in a data structure) should call
521.Fn vref .
522.It Fn vrele "vp"
523Decrement
524.Em v_usecount
525of unlocked vnode
526.Em vp .
527Any code in the system which is using a vnode should call
528.Fn vrele
529when it is finished with the vnode.
530If
531.Em v_usecount
532of the vnode reaches zero and
533.Em v_holdcnt
534is greater than zero, the vnode is placed on the holdlist.
535If both
536.Em v_usecount
537and
538.Em v_holdcnt
539are zero, the vnode is cached.
540.It Fn vrele_async "vp"
541Will asychronously release the vnode in different context than the caller,
542sometime after the call.
543.It Fn vget "vp" "lockflags" "wait"
544Reclaim vnode
545.Fa vp
546from the cache and increment its reference count.
547.Pp
548The vnode
549.Fa vp
550may be changing state: another thread may be initializing it from disk,
551or revoking it with
552.Xr revoke 2 ,
553or reclaiming it with
554.Xr VOP_RECLAIM 9 .
555In that case,
556.Fn vget
557will wait until the state has changed, if
558.Fa lockflags
559is
560.Li 0
561and
562.Fa wait
563is
564.Li true ;
565or will return
566.Er EBUSY
567if
568.Fa lockflags
569is
570.Dv LK_NOWAIT
571and
572.Fa wait
573is
574.Li false .
575.Pp
576(The extra argument enables the compiler to detect old code which
577additionally used
578.Fn vget
579to lock the vnode.)
580.Pp
581Returns
582.Bl -tag -offset abcd -width ENOENT -compact
583.It Er EBUSY
584if
585.Fa vp
586was changing state and
587.Fa wait
588is false.
589.It Er ENOENT
590if the system was reclaiming
591.Fa vp
592with
593.Xr VOP_RECLAIM 9 .
594.It Li 0
595on success.
596.El
597.It Fn vput "vp"
598Legacy convenience routine for unlocking and releasing
599.Fa vp .
600Equivalent to:
601.Bd -literal -offset abcd
602.No "VOP_UNLOCK(" Ns Fa vp Ns Li ");"
603.No "vrele(" Ns Fa vp Ns Li ");"
604.Ed
605.Pp
606Note that this is
607.Em not
608an inverse of
609.Fn vget .
610The name appears so for hysterical raisins.
611New code should prefer using
612.Xr VOP_UNLOCK 9
613and
614.Fn vrele
615directly.
616.It Fn vhold "vp"
617Mark the vnode
618.Fa vp
619as active by incrementing
620.Em vp-\*[Gt]v_holdcnt .
621Once held, the vnode will not be recycled until it is
622released with
623.Fn holdrele .
624.It Fn holdrele "vp"
625Mark the vnode
626.Fa vp
627as inactive by decrementing
628.Em vp-\*[Gt]v_holdcnt .
629.It Fn vcache_get "mp" "key" "key_len" "vpp"
630Allocate a new vnode.
631The new vnode is returned referenced in the address specified by
632.Fa vpp .
633.Pp
634The argument
635.Fa mp
636is the mount point for the file system to lookup the file in.
637.Pp
638The arguments
639.Fa key
640and
641.Fa key_len
642uniquely identify the file in the file system.
643.Pp
644If a vnode is successfully retrieved zero is returned, otherwise an
645appropriate error code is returned.
646.It Fn vcache_new "mp" "dvp" "vap" "cred" "vpp"
647Allocate a new vnode with a new file.
648The new vnode is returned referenced in the address specified by
649.Fa vpp .
650.Pp
651The argument
652.Fa mp
653is the mount point for the file system to create the file in.
654.Pp
655The argument
656.Fa dvp
657points to the directory to create the file in.
658.Pp
659The argument
660.Fa vap
661points to the attributes for the file to create.
662.Pp
663The argument
664.Fa cred
665holds the credentials for the file to create.
666.Pp
667If a vnode is successfully created zero is returned, otherwise an
668appropriate error code is returned.
669.It Fn vcache_rekey_enter "mp" "vp" "old_key" "old_key_len" "new_key" "new_key_len"
670Prepare to change the key of a cached vnode.
671.Pp
672The argument
673.Fa mp
674is the mount point for the file system the vnode
675.Fa vp
676resides in.
677.Pp
678The arguments
679.Fa old_key
680and
681.Fa old_key_len
682identify the cached vnode.
683.Pp
684The arguments
685.Fa new_key
686and
687.Fa new_key_len
688will identify the vnode after rename.
689.Pp
690If the new key already exists
691.Er EEXIST
692is returned, otherwise zero is returned.
693.It Fn vcache_rekey_exit "mp" "vp" "old_key" "old_key_len" "new_key" "new_key_len"
694Finish rename after calling
695.Fn vcache_rekey_enter .
696.It Fn vrecycle "vp"
697Recycle the referenced vnode
698.Fa vp
699if this is the last reference.
700.Fn vrecycle
701is a null operation if the reference count is greater than one.
702.It Fn vgone "vp"
703Eliminate all activity associated with the unlocked vnode
704.Fa vp
705in preparation for recycling.
706.It Fn vgonel "vp" "p"
707Eliminate all activity associated with the locked vnode
708.Fa vp
709in preparation for recycling.
710.It Fn vdead_check "vp" "flags"
711Check the vnode
712.Fa vp
713for being or becoming dead.
714Returns
715.Er ENOENT
716for a dead vnode and zero otherwise.
717If
718.Fa flags
719is
720.Dv VDEAD_NOWAIT
721it will return
722.Er EBUSY
723if the vnode is becoming dead and the function will not sleep.
724.Pp
725Whenever this function returns a non-zero value all future calls
726for this
727.Fa vp
728will also return a non-zero value.
729.It Fn vflush "mp" "skipvp" "flags"
730Remove any vnodes in the vnode table belonging to mount point
731.Fa mp .
732If
733.Fa skipvp
734is not
735.Dv NULL
736it is exempt from being flushed.
737The argument
738.Fa flags
739is a set of flags modifying the operation of
740.Fn vflush .
741If
742.Dv FORCECLOSE
743is not specified, there should not be any active vnodes and
744the error
745.Er EBUSY
746is returned if any are found (this is a user error, not a system error).
747If
748.Dv FORCECLOSE
749is specified, active vnodes that are found are detached.
750If
751.Dv WRITECLOSE
752is set, only flush out regular file vnodes open for writing.
753SKIPSYSTEM causes any vnodes marked
754.Dv V_SYSTEM
755to be skipped.
756.It Fn vaccess "type" "file_mode" "uid" "gid" "acc_mode" "cred"
757Do access checking by comparing the file's permissions to the caller's
758desired access type
759.Fa acc_mode
760and credentials
761.Fa cred .
762.It Fn bdevvp "dev" "vpp"
763Create a vnode for a block device.
764.Fn bdevvp
765is used for root file systems, swap areas and for memory file system
766special devices.
767.It Fn cdevvp "dev" "vpp"
768Create a vnode for a character device.
769.Fn cdevvp
770is used for the console and kernfs special devices.
771.It Fn vfinddev "dev" "vtype" "vpp"
772Lookup a vnode by device number.
773The vnode is referenced and returned in the address specified by
774.Fa vpp .
775.It Fn vdevgone "int maj" "int min" "int minh" "enum vtype type"
776Reclaim all vnodes that correspond to the specified minor number range
777.Fa minl
778to
779.Fa minh
780(endpoints inclusive) of the specified major
781.Fa maj .
782.It Fn vwakeup "bp"
783Update outstanding I/O count
784.Em vp-\*[Gt]v_numoutput
785for the vnode
786.Em bp-\*[Gt]b_vp
787and do a wakeup if requested and
788.Em vp-\*[Gt]vflag
789has
790.Dv VBWAIT
791set.
792.It Fn vflushbuf "vp" "sync"
793Flush all dirty buffers to disk for the file with the locked vnode
794.Fa vp .
795The argument
796.Fa sync
797specifies whether the I/O should be synchronous and
798.Fn vflushbuf
799will sleep until
800.Em vp-\*[Gt]v_numoutput
801is zero and
802.Em vp-\*[Gt]v_dirtyblkhd
803is empty.
804.It Fn vinvalbuf "vp" "flags" "cred" "l" "slpflag" "slptimeo"
805Flush out and invalidate all buffers associated with locked vnode
806.Fa vp .
807The argument
808.Fa l
809and
810.Fa cred
811specified the calling process and its credentials.
812The
813.Xr ltsleep 9
814flag and timeout are specified by the arguments
815.Fa slpflag
816and
817.Fa slptimeo
818respectively.
819If the operation is successful zero is returned, otherwise an
820appropriate error code is returned.
821.It Fn vtruncbuf "vp" "lbn" "slpflag" "slptimeo"
822Destroy any in-core buffers past the file truncation length for the
823locked vnode
824.Fa vp .
825The truncation length is specified by
826.Fa lbn .
827.Fn vtruncbuf
828will sleep while the I/O is performed,  The
829.Xr ltsleep 9
830flag and timeout are specified by the arguments
831.Fa slpflag
832and
833.Fa slptimeo
834respectively.
835If the operation is successful zero is returned, otherwise an
836appropriate error code is returned.
837.It Fn vprint "label" "vp"
838This function is used by the kernel to dump vnode information during a
839panic.
840It is only used if the kernel option DIAGNOSTIC is compiled into the kernel.
841The argument
842.Fa label
843is a string to prefix the information dump of vnode
844.Fa vp .
845.El
846.Sh CODE REFERENCES
847The vnode framework is implemented within the file
848.Pa sys/kern/vfs_subr.c .
849.Sh SEE ALSO
850.Xr intro 9 ,
851.Xr lock 9 ,
852.Xr namecache 9 ,
853.Xr namei 9 ,
854.Xr uvm 9 ,
855.Xr vattr 9 ,
856.Xr vfs 9 ,
857.Xr vfsops 9 ,
858.Xr vnodeops 9 ,
859.Xr vnsubr 9
860.Sh BUGS
861The locking protocol is inconsistent.
862Many vnode operations are passed locked vnodes on entry but release
863the lock before they exit.
864The locking protocol is used in some places to attempt to make a
865series of operations atomic (e.g., access check then operation).
866This does not work for non-local file systems that do not support locking
867(e.g., NFS).
868The
869.Nm
870interface would benefit from a simpler locking protocol.
871