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