ether_input() no longer allows the MAC header to be passed separately,
[dragonfly.git] / share / man / man9 / VOP_LOCK.9
1 .\" Copyright (c) 1996 Doug Rabson
2 .\"
3 .\" All rights reserved.
4 .\"
5 .\" This program is free software.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
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.
15 .\"
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.
26 .\"
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.5 2004/06/01 11:36:53 hmp Exp $
29 .\"
30 .Dd July 24, 1996
31 .Os
32 .Dt VOP_LOCK 9
33 .Sh NAME
34 .Nm VOP_LOCK ,
35 .Nm VOP_UNLOCK ,
36 .Nm VOP_ISLOCKED ,
37 .Nm vn_lock
38 .Nd serialize access to a vnode
39 .Sh SYNOPSIS
40 .In sys/param.h
41 .In sys/lock.h
42 .In sys/vnode.h
43 .Ft int
44 .Fn VOP_LOCK "struct vnode *vp" "int flags" "struct proc *p"
45 .Ft int
46 .Fn VOP_UNLOCK "struct vnode *vp" "int flags" "struct proc *p"
47 .Ft int
48 .Fn VOP_ISLOCKED "struct vnode *vp" "struct proc *p"
49 .Ft int
50 .Fn vn_lock "struct vnode *vp" "int flags" "struct proc *p"
51 .Sh DESCRIPTION
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
54 same time.
55 .Pp
56 The arguments are:
57 .Bl -tag -width flags
58 .It Fa vp
59 the vnode being locked or unlocked
60 .It Fa flags
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"
69 .It Dv LK_DRAIN Ta "Wait for all lock activity to end"
70 .El
71 .Pp
72 The lock type may be
73 .Em or Ns 'ed
74 with these lock flags:
75 .Bl -column LK_CANRECURSE -offset indent
76 .It Dv LK_NOWAIT Ta "Do not sleep to wait for lock"
77 .It Dv LK_SLEEPFAIL Ta "Sleep, then return failure"
78 .It Dv LK_CANRECURSE Ta "Allow recursive exclusive lock"
79 .It Dv LK_REENABLE Ta "Lock is to be reenabled after drain"
80 .It Dv LK_NOPAUSE Ta "No spinloop"
81 .El
82 .Pp
83 The lock type may be
84 .Em or Ns 'ed
85 with these control flags:
86 .Bl -column LK_INTERLOCK -offset indent
87 .It Dv LK_INTERLOCK Ta "Specify when the caller already has a simple lock \
88 (VOP_LOCK will unlock the simple lock after getting the lock)"
89 .It Dv LK_RETRY Ta "Retry until locked"
90 .It Dv LK_NOOBJ Ta "Don't create object"
91 .El
92 .It Ar p
93 process context to use for the locks
94 .El
95 .Pp
96 Kernel code should use
97 .Fn vn_lock
98 to lock a vnode rather than calling
99 .Fn VOP_LOCK
100 directly.
101 .Sh RETURN VALUES
102 Zero is returned on success, otherwise an error is returned.
103 .Sh PSEUDOCODE
104 .Bd -literal
105 struct vopnode {
106     int von_flag;
107     /*
108      * Other filesystem specific data.
109      */
110     ...;
111 };
112 #define VON_LOCKED      1
113 #define VON_WANTED      2
114 #define VTOVON(vp)      ((struct vopnode *) (vp)->v_data)
115
116 int
117 vop_lock(struct vnode *vp)
118 {
119     struct vopnode* vop;
120
121 start:
122     while (vp->v_flag & VXLOCK) {
123         vp->v_flag |= VXWANT;
124         tsleep((caddr_t)vp, 0, "voplk1", 0);
125     }
126     if (vp->v_tag == VT_NON)
127         return ENOENT;
128
129     vop = VTOVON(vp);
130     if (vop->von_flag & VON_LOCKED) {
131         vop->von_flag |= VON_WANTED;
132         tsleep((caddr_t) vop, 0, "voplk2", 0);
133         goto start;
134     }
135
136     vop->von_flag |= VON_LOCKED;
137
138     return 0;
139 }
140
141 int
142 vop_unlock(struct vnode *vp)
143 {
144     struct vopnode *vop = VTOVON(vp);
145
146     if ((vop->von_flag & VON_LOCKED) == 0) {
147         panic("vop_unlock not locked");
148     }
149     vop->von_flag &= ~VON_LOCKED;
150     if (vop->von_flag & VON_WANTED) {
151         vop->von_flag &= ~VON_WANTED;
152         wakeup((caddr_t) vop);
153     }
154
155     return 0;
156 }
157
158 int
159 vop_islocked(struct vnode *vp)
160 {
161     struct vopnode *vop = VTOVON(vp);
162
163     if (vop->von_flag & VON_LOCKED)
164         return 1;
165     else
166         return 0;
167 }
168 .Ed
169 .Sh SEE ALSO
170 .Xr vnode 9
171 .Sh AUTHORS
172 This man page was written by
173 .An Doug Rabson .