1 .\" Copyright (c) 1996 Doug Rabson
3 .\" All rights reserved.
5 .\" This program is free software.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
16 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
17 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 .\" $FreeBSD: src/share/man/man9/VOP_LOCK.9,v 1.8.2.3 2001/12/17 11:30:18 ru Exp $
28 .\" $DragonFly: src/share/man/man9/VOP_LOCK.9,v 1.7 2007/12/02 22:39:56 swildner Exp $
38 .Nd serialize access to a vnode
44 .Fn VOP_LOCK "struct vnode *vp" "int flags" "struct proc *p"
46 .Fn VOP_UNLOCK "struct vnode *vp" "int flags" "struct proc *p"
48 .Fn VOP_ISLOCKED "struct vnode *vp" "struct proc *p"
50 .Fn vn_lock "struct vnode *vp" "int flags" "struct proc *p"
52 These calls are used to serialize access to the filesystem, such as
53 to prevent two writes to the same file from happening at the
59 the vnode being locked or unlocked
61 One of the lock request types:
62 .Bl -column LK_EXCLUPGRADE -offset indent
63 .It Dv LK_SHARED Ta "Shared lock"
64 .It Dv LK_EXCLUSIVE Ta "Exclusive lock"
65 .It Dv LK_UPGRADE Ta "Shared-to-exclusive upgrade"
66 .It Dv LK_EXCLUPGRADE Ta "First shared-to-exclusive upgrade"
67 .It Dv LK_DOWNGRADE Ta "Exclusive-to-shared downgrade"
68 .It Dv LK_RELEASE Ta "Release any type of lock"
73 with these lock flags:
74 .Bl -column LK_CANRECURSE -offset indent
75 .It Dv LK_NOWAIT Ta "Do not sleep to wait for lock"
76 .It Dv LK_SLEEPFAIL Ta "Sleep, then return failure"
77 .It Dv LK_CANRECURSE Ta "Allow recursive exclusive lock"
82 with these control flags:
83 .Bl -column LK_RETRY -offset indent
84 .It Dv LK_RETRY Ta "Retry until locked"
85 .It Dv LK_NOOBJ Ta "Don't create object"
88 process context to use for the locks
91 Kernel code should use
93 to lock a vnode rather than calling
97 Zero is returned on success, otherwise an error is returned.
103 * Other filesystem specific data.
109 #define VTOVON(vp) ((struct vopnode *) (vp)->v_data)
112 vop_lock(struct vnode *vp)
117 while (vp->v_flag & VXLOCK) {
118 vp->v_flag |= VXWANT;
119 tsleep((caddr_t)vp, 0, "voplk1", 0);
121 if (vp->v_tag == VT_NON)
125 if (vop->von_flag & VON_LOCKED) {
126 vop->von_flag |= VON_WANTED;
127 tsleep((caddr_t) vop, 0, "voplk2", 0);
131 vop->von_flag |= VON_LOCKED;
137 vop_unlock(struct vnode *vp)
139 struct vopnode *vop = VTOVON(vp);
141 if ((vop->von_flag & VON_LOCKED) == 0) {
142 panic("vop_unlock not locked");
144 vop->von_flag &= ~VON_LOCKED;
145 if (vop->von_flag & VON_WANTED) {
146 vop->von_flag &= ~VON_WANTED;
147 wakeup((caddr_t) vop);
154 vop_islocked(struct vnode *vp)
156 struct vopnode *vop = VTOVON(vp);
158 if (vop->von_flag & VON_LOCKED)
167 This man page was written by