3 .\" Copyright (c) 1996 Doug Rabson
5 .\" All rights reserved.
7 .\" This program is free software.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
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.
18 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 .Nd serialize access to a vnode
45 .Fn VOP_LOCK "struct vnode *vp" "int flags" "struct thread *td"
47 .Fn VOP_UNLOCK "struct vnode *vp" "int flags" "struct thread *td"
49 .Fn VOP_ISLOCKED "struct vnode *vp" "struct thread *td"
51 .Fn vn_lock "struct vnode *vp" "int flags" "struct thread *td"
53 These calls are used to serialize access to the file system, such as
54 to prevent two writes to the same file from happening at the
60 The vnode being locked or unlocked.
62 One of the lock request types:
64 .Bl -tag -width ".Dv LK_EXCLUPGRADE" -offset indent -compact
70 Shared-to-exclusive upgrade.
72 First shared-to-exclusive upgrade.
74 Exclusive-to-shared downgrade.
76 Release any type of lock.
78 Wait for all lock activity to end.
83 with these lock flags:
85 .Bl -tag -width ".Dv LK_EXCLUPGRADE" -offset indent -compact
87 Do not sleep to wait for lock.
89 Sleep, then return failure.
91 Allow recursive exclusive lock.
93 Lock is to be reenabled after drain.
100 with these control flags:
102 .Bl -tag -width ".Dv LK_EXCLUPGRADE" -offset indent -compact
104 Specify when the caller already has a simple lock
106 will unlock the simple lock after getting the lock).
110 Do not create object.
113 Thread context to use for the locks.
116 Kernel code should use
118 to lock a vnode rather than calling
122 Zero is returned on success, otherwise an error is returned.
128 * Other file system specific data.
134 #define VTOVON(vp) ((struct vopnode *) (vp)->v_data)
137 vop_lock(struct vnode *vp)
142 while (vp->v_flag & VXLOCK) {
143 vp->v_flag |= VXWANT;
144 tsleep((caddr_t)vp, PINOD, "voplk1", 0);
146 if (vp->v_tag == VT_NON)
150 if (vop->von_flag & VON_LOCKED) {
151 vop->von_flag |= VON_WANTED;
152 tsleep((caddr_t) vop, PINOD, "voplk2", 0);
156 vop->von_flag |= VON_LOCKED;
162 vop_unlock(struct vnode *vp)
164 struct vopnode *vop = VTOVON(vp);
166 if ((vop->von_flag & VON_LOCKED) == 0) {
167 panic("vop_unlock not locked");
169 vop->von_flag &= ~VON_LOCKED;
170 if (vop->von_flag & VON_WANTED) {
171 vop->von_flag &= ~VON_WANTED;
172 wakeup((caddr_t) vop);
179 vop_islocked(struct vnode *vp)
181 struct vopnode *vop = VTOVON(vp);
183 if (vop->von_flag & VON_LOCKED)
192 This manual page was written by