xref: /freebsd/share/man/man9/VOP_LOCK.9 (revision 61e21613)
1.\" -*- nroff -*-
2.\"
3.\" Copyright (c) 1996 Doug Rabson
4.\"
5.\" All rights reserved.
6.\"
7.\" This program is free software.
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 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.
28.\"
29.Dd August 23, 2022
30.Dt VOP_LOCK 9
31.Os
32.Sh NAME
33.Nm VOP_LOCK ,
34.Nm VOP_UNLOCK ,
35.Nm VOP_ISLOCKED ,
36.Nm vn_lock
37.Nd serialize access to a vnode
38.Sh SYNOPSIS
39.In sys/param.h
40.In sys/lock.h
41.In sys/vnode.h
42.Ft int
43.Fn VOP_LOCK "struct vnode *vp" "int flags"
44.Ft int
45.Fn VOP_UNLOCK "struct vnode *vp"
46.Ft int
47.Fn VOP_ISLOCKED "struct vnode *vp"
48.Ft int
49.Fn vn_lock "struct vnode *vp" "int flags"
50.Sh DESCRIPTION
51These calls are used to serialize access to the file system, such as
52to prevent two writes to the same file from happening at the
53same time.
54.Pp
55The arguments are:
56.Bl -tag -width flags
57.It Fa vp
58The vnode being locked or unlocked.
59.It Fa flags
60One of the lock request types:
61.Pp
62.Bl -tag -width ".Dv LK_CANRECURSE" -offset indent -compact
63.It Dv LK_SHARED
64Shared lock.
65.It Dv LK_EXCLUSIVE
66Exclusive lock.
67.It Dv LK_UPGRADE
68Shared-to-exclusive upgrade.
69.It Dv LK_DOWNGRADE
70Exclusive-to-shared downgrade.
71.It Dv LK_RELEASE
72Release any type of lock.
73.It Dv LK_DRAIN
74Wait for all lock activity to end.
75.El
76.Pp
77The lock type may be
78.Em or Ns 'ed
79with these lock flags:
80.Pp
81.Bl -tag -width ".Dv LK_CANRECURSE" -offset indent -compact
82.It Dv LK_NOWAIT
83Do not sleep to wait for lock.
84.It Dv LK_SLEEPFAIL
85Sleep, then return failure.
86.It Dv LK_CANRECURSE
87Allow recursive exclusive lock.
88.It Dv LK_NOWITNESS
89Instruct
90.Xr witness 4
91to ignore this instance.
92.El
93.Pp
94The lock type may be
95.Em or Ns 'ed
96with these control flags:
97.Pp
98.Bl -tag -width ".Dv LK_CANRECURSE" -offset indent -compact
99.It Dv LK_INTERLOCK
100Specify when the caller already has a simple lock
101.Po Fn VOP_LOCK
102will unlock the simple lock after getting the lock
103.Pc .
104.It Dv LK_RETRY
105Retry until locked.
106.El
107.Pp
108Kernel code should use
109.Fn vn_lock
110to lock a vnode rather than calling
111.Fn VOP_LOCK
112directly.
113.Fn vn_lock
114also does not want a thread specified as argument but it
115assumes curthread to be used.
116.El
117.Sh RETURN VALUES
118Zero is returned on success, otherwise an error is returned.
119.Sh SEE ALSO
120.Xr vnode 9
121.Sh AUTHORS
122This manual page was written by
123.An Doug Rabson .
124