2000-10-24 03:33:24 +00:00
|
|
|
.\"
|
2002-01-26 00:09:41 +00:00
|
|
|
.\" Copyright (C) 2002 Chad David <davidc@acns.ab.ca>. All rights reserved.
|
2000-10-24 03:33:24 +00:00
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
2002-01-26 00:09:41 +00:00
|
|
|
.\" notice(s), this list of conditions and the following disclaimer as
|
|
|
|
.\" the first lines of this file unmodified other than the possible
|
|
|
|
.\" addition of one or more copyright notices.
|
2000-10-24 03:33:24 +00:00
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
2002-01-26 00:09:41 +00:00
|
|
|
.\" notice(s), this list of conditions and the following disclaimer in the
|
2000-10-24 03:33:24 +00:00
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
2002-01-26 00:09:41 +00:00
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
|
|
|
|
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
.\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
|
|
|
|
.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
.\" DAMAGE.
|
2000-10-24 03:33:24 +00:00
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2006-06-20 21:41:14 +00:00
|
|
|
.Dd June 20, 2006
|
2000-10-24 03:33:24 +00:00
|
|
|
.Dt LOCK 9
|
2001-07-10 15:31:11 +00:00
|
|
|
.Os
|
2000-10-24 03:33:24 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm lockinit ,
|
2002-01-26 00:09:41 +00:00
|
|
|
.Nm lockdestroy ,
|
2000-10-24 03:33:24 +00:00
|
|
|
.Nm lockcount ,
|
2002-01-26 00:09:41 +00:00
|
|
|
.Nm lockmgr ,
|
|
|
|
.Nm lockstatus ,
|
|
|
|
.Nm lockmgr_printinfo
|
|
|
|
.Nd "lockmgr family of functions"
|
2000-10-24 03:33:24 +00:00
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In sys/types.h
|
2002-01-26 00:09:41 +00:00
|
|
|
.In sys/lockmgr.h
|
2000-10-24 03:33:24 +00:00
|
|
|
.Ft void
|
2002-04-12 05:16:27 +00:00
|
|
|
.Fn lockinit "struct lock *lkp" "int prio" "const char *wmesg" "int timo" "int flags"
|
2002-01-26 00:09:41 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn lockdestroy "struct lock *lkp"
|
2000-10-24 03:33:24 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn lockcount "struct lock *lkp"
|
|
|
|
.Ft int
|
2002-01-26 00:09:41 +00:00
|
|
|
.Fn lockmgr "struct lock *lkp" "u_int flags" "struct mtx *interlkp" "struct thread *td"
|
|
|
|
.Ft int
|
2001-12-26 23:14:04 +00:00
|
|
|
.Fn lockstatus "struct lock *lkp" "struct thread *td"
|
2002-01-26 00:09:41 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn lockmgr_printinfo "struct lock *lkp"
|
2000-10-24 03:33:24 +00:00
|
|
|
.Sh DESCRIPTION
|
2002-01-26 00:09:41 +00:00
|
|
|
The
|
2000-10-24 03:33:24 +00:00
|
|
|
.Fn lockinit
|
2002-01-26 00:09:41 +00:00
|
|
|
function is used to initialize a lock.
|
2002-03-24 00:31:38 +00:00
|
|
|
It must be called before any operation can be performed on a lock.
|
2002-01-26 00:09:41 +00:00
|
|
|
Its arguments are:
|
|
|
|
.Bl -tag -width ".Fa wmesg"
|
|
|
|
.It Fa lkp
|
|
|
|
A pointer to the lock to initialize.
|
|
|
|
.It Fa prio
|
|
|
|
The priority passed to
|
2007-03-09 22:41:01 +00:00
|
|
|
.Xr sleep 9 .
|
2002-01-26 00:09:41 +00:00
|
|
|
.It Fa wmesg
|
|
|
|
The lock message.
|
|
|
|
This is used for both debugging output and
|
2007-03-09 22:41:01 +00:00
|
|
|
.Xr sleep 9 .
|
2002-01-26 00:09:41 +00:00
|
|
|
.It Fa timo
|
|
|
|
The timeout value passed to
|
2007-03-09 22:41:01 +00:00
|
|
|
.Xr sleep 9 .
|
2002-01-26 00:09:41 +00:00
|
|
|
.It Fa flags
|
|
|
|
The flags the lock is to be initialized with.
|
|
|
|
.Bl -tag -width ".Dv LG_CANRECURSE"
|
|
|
|
.It Dv LK_NOWAIT
|
|
|
|
Do not sleep while acquiring the lock.
|
|
|
|
.It Dv LK_SLEEPFAIL
|
|
|
|
Fail after a sleep.
|
|
|
|
.It Dv LK_CANRECURSE
|
|
|
|
Allow recursive exclusive locks.
|
2006-06-20 21:41:14 +00:00
|
|
|
.It Dv LK_NOSHARE
|
|
|
|
Allow exclusive locks only.
|
2002-01-26 00:09:41 +00:00
|
|
|
.It Dv LK_TIMELOCK
|
|
|
|
Use
|
|
|
|
.Fa timo
|
|
|
|
during a sleep; otherwise, 0 is used.
|
|
|
|
.El
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn lockdestroy
|
|
|
|
function is used to destroy a lock, and while it is called in a number of
|
|
|
|
places in the kernel, it currently does nothing.
|
|
|
|
.Pp
|
|
|
|
The
|
2000-10-24 03:33:24 +00:00
|
|
|
.Fn lockcount
|
2002-01-26 00:09:41 +00:00
|
|
|
function returns a count of the number of exclusive locks and shared locks
|
|
|
|
held against the lock
|
|
|
|
.Fa lkp .
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn lockmgr
|
|
|
|
function handles general locking functionality within the kernel, including
|
|
|
|
support for shared and exclusive locks, and recursion.
|
|
|
|
.Fn lockmgr
|
|
|
|
is also able to upgrade and downgrade locks.
|
2000-10-24 03:33:24 +00:00
|
|
|
.Pp
|
2002-01-26 00:09:41 +00:00
|
|
|
Its arguments are:
|
|
|
|
.Bl -tag -width ".Fa interlkp"
|
|
|
|
.It Fa lkp
|
|
|
|
A pointer to the lock to manipulate.
|
|
|
|
.It Fa flags
|
|
|
|
Flags indicating what action is to be taken.
|
2002-01-10 12:32:38 +00:00
|
|
|
.Bl -tag -width ".Dv LK_EXCLUPGRADE"
|
2000-10-24 03:33:24 +00:00
|
|
|
.It Dv LK_SHARED
|
2002-01-26 00:09:41 +00:00
|
|
|
Acquire a shared lock.
|
|
|
|
If an exclusive lock is currently held, it will be downgraded.
|
2000-10-24 03:33:24 +00:00
|
|
|
.It Dv LK_EXCLUSIVE
|
2002-01-26 00:09:41 +00:00
|
|
|
Acquire an exclusive lock.
|
|
|
|
If an exclusive lock is already held, and
|
2002-01-10 12:32:38 +00:00
|
|
|
.Dv LK_CANRECURSE
|
2002-01-26 00:09:41 +00:00
|
|
|
is not set, the system will
|
|
|
|
.Xr panic 9 .
|
2000-10-24 03:33:24 +00:00
|
|
|
.It Dv LK_DOWNGRADE
|
2002-01-26 00:09:41 +00:00
|
|
|
Downgrade exclusive lock to a shared lock.
|
|
|
|
Downgrading a shared lock is not permitted.
|
|
|
|
If an exclusive lock has been recursed, all references will be downgraded.
|
|
|
|
.It Dv LK_EXCLUPGRADE
|
|
|
|
Upgrade a shared lock to an exclusive lock.
|
|
|
|
Fails with
|
|
|
|
.Er EBUSY
|
2002-03-24 00:31:38 +00:00
|
|
|
if there is someone ahead of you in line waiting for an upgrade.
|
2002-01-26 00:09:41 +00:00
|
|
|
If this call fails, the shared lock is lost.
|
2002-03-24 00:31:38 +00:00
|
|
|
Attempts to upgrade an exclusive lock will cause a
|
2002-01-26 00:09:41 +00:00
|
|
|
.Xr panic 9 .
|
|
|
|
.It Dv LK_UPGRADE
|
|
|
|
Upgrade a shared lock to an exclusive lock.
|
|
|
|
If this call fails, the shared lock is lost.
|
2006-08-21 12:45:19 +00:00
|
|
|
During the upgrade, the shared lock could
|
|
|
|
be temporarily dropped.
|
2002-03-24 00:31:38 +00:00
|
|
|
Attempts to upgrade an exclusive lock will cause a
|
2002-01-26 00:09:41 +00:00
|
|
|
.Xr panic 9 .
|
2000-10-24 03:33:24 +00:00
|
|
|
.It Dv LK_RELEASE
|
2002-01-26 00:09:41 +00:00
|
|
|
Release the lock.
|
|
|
|
Releasing a lock that is not held can cause a
|
|
|
|
.Xr panic 9 .
|
2000-10-24 03:33:24 +00:00
|
|
|
.It Dv LK_DRAIN
|
2002-01-26 00:09:41 +00:00
|
|
|
Wait for all activity on the lock to end, then mark it decommissioned.
|
|
|
|
This is used before freeing a lock that is part of a piece of memory that is
|
|
|
|
about to be freed.
|
|
|
|
(As documented in
|
2003-09-08 19:57:22 +00:00
|
|
|
.In sys/lockmgr.h . )
|
2002-01-26 00:09:41 +00:00
|
|
|
.It Dv LK_SLEEPFAIL
|
|
|
|
Fail if operation has slept.
|
|
|
|
.It Dv LK_NOWAIT
|
|
|
|
Do not allow the call to sleep.
|
|
|
|
This can be used to test the lock.
|
|
|
|
.It Dv LK_CANRECURSE
|
|
|
|
Allow recursion on an exclusive lock.
|
|
|
|
For every lock there must be a release.
|
|
|
|
.It Dv LK_INTERLOCK
|
|
|
|
Unlock the interlock (which should be locked already).
|
|
|
|
.El
|
|
|
|
.It Fa interlkp
|
|
|
|
An interlock mutex for controlling group access to the lock.
|
|
|
|
If
|
|
|
|
.Dv LK_INTERLOCK
|
|
|
|
is specified,
|
|
|
|
.Fn lockmgr
|
|
|
|
assumes
|
|
|
|
.Fa interlkp
|
|
|
|
is currently owned and not recursed, and will return it unlocked.
|
|
|
|
See
|
|
|
|
.Xr mtx_assert 9 .
|
|
|
|
.It Fa td
|
|
|
|
A thread responsible for this call.
|
|
|
|
.Dv NULL
|
|
|
|
becomes
|
|
|
|
.Dv LK_KERNPROC .
|
2000-10-24 03:33:24 +00:00
|
|
|
.El
|
2002-01-26 00:09:41 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn lockstatus
|
|
|
|
function returns the status of the lock in relation to the
|
|
|
|
.Vt thread
|
|
|
|
passed to it.
|
|
|
|
Note that if
|
|
|
|
.Fa td
|
|
|
|
is
|
|
|
|
.Dv NULL
|
|
|
|
and an exclusive lock is held,
|
|
|
|
.Dv LK_EXCLUSIVE
|
|
|
|
will be returned.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn lockmgr_printinfo
|
|
|
|
function prints debugging information about the lock.
|
|
|
|
It is used primarily by
|
|
|
|
.Xr VOP_PRINT 9
|
|
|
|
functions.
|
2000-10-24 03:33:24 +00:00
|
|
|
.Sh RETURN VALUES
|
2002-01-26 00:09:41 +00:00
|
|
|
The
|
|
|
|
.Fn lockcount
|
|
|
|
function returns an integer greater than or equal to zero.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn lockmgr
|
|
|
|
function returns 0 on success and non-zero on failure.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn lockstatus
|
|
|
|
function returns:
|
|
|
|
.Bl -tag -width ".Dv LK_EXCLUSIVE"
|
|
|
|
.It Dv LK_EXCLUSIVE
|
|
|
|
An exclusive lock is held by the thread
|
|
|
|
.Fa td .
|
|
|
|
.It Dv LK_EXCLOTHER
|
|
|
|
An exclusive lock is held by someone other than the thread
|
|
|
|
.Fa td .
|
|
|
|
.It Dv LK_SHARED
|
|
|
|
A shared lock is held.
|
|
|
|
.It Li 0
|
|
|
|
The lock is not held by anyone.
|
|
|
|
.El
|
|
|
|
.Sh ERRORS
|
|
|
|
.Fn lockmgr
|
|
|
|
fails if:
|
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EBUSY
|
2002-01-10 12:32:38 +00:00
|
|
|
.Dv LK_FORCEUPGRADE
|
2002-01-26 00:09:41 +00:00
|
|
|
was requested and another thread had already requested a lock upgrade.
|
|
|
|
.It Bq Er EBUSY
|
|
|
|
.Dv LK_NOWAIT
|
|
|
|
was set, and a sleep would have been required.
|
|
|
|
.It Bq Er ENOLCK
|
2002-01-10 12:32:38 +00:00
|
|
|
.Dv LK_SLEEPFAIL
|
2002-01-26 00:09:41 +00:00
|
|
|
was set and
|
|
|
|
.Fn lockmgr
|
|
|
|
did sleep.
|
|
|
|
.It Bq Er EINTR
|
2002-01-10 12:32:38 +00:00
|
|
|
.Dv PCATCH
|
2002-01-26 00:09:41 +00:00
|
|
|
was set in the lock priority, and a signal was delivered during a sleep.
|
|
|
|
Note the
|
2000-10-24 03:33:24 +00:00
|
|
|
.Er ERESTART
|
2002-01-26 00:09:41 +00:00
|
|
|
error below.
|
|
|
|
.It Bq Er ERESTART
|
|
|
|
.Dv PCATCH
|
|
|
|
was set in the lock priority, a signal was delivered during a sleep,
|
|
|
|
and the system call is to be restarted.
|
|
|
|
.It Bq Er EWOULDBLOCK
|
|
|
|
a non-zero timeout was given, and the timeout expired.
|
|
|
|
.El
|
|
|
|
.Sh LOCKS
|
|
|
|
If
|
|
|
|
.Dv LK_INTERLOCK
|
|
|
|
is passed in the
|
|
|
|
.Fa flags
|
|
|
|
argument to
|
|
|
|
.Fn lockmgr ,
|
|
|
|
the
|
|
|
|
.Fa interlkp
|
|
|
|
must be held prior to calling
|
|
|
|
.Fn lockmgr ,
|
|
|
|
and will be returned unlocked.
|
|
|
|
.Pp
|
|
|
|
Upgrade attempts that fail result in the loss of the lock that
|
|
|
|
is currently held.
|
|
|
|
Also, it is invalid to upgrade an
|
|
|
|
exclusive lock, and a
|
|
|
|
.Xr panic 9
|
|
|
|
will be the result of trying.
|
|
|
|
.Sh SEE ALSO
|
2007-03-30 18:07:26 +00:00
|
|
|
.Xr condvar 9 ,
|
|
|
|
.Xr locking 9 ,
|
|
|
|
.Xr mutex 9 ,
|
|
|
|
.Xr rwlock 9 ,
|
2007-03-09 22:41:01 +00:00
|
|
|
.Xr sleep 9 ,
|
2007-03-30 18:07:26 +00:00
|
|
|
.Xr sx 9 ,
|
2002-01-26 00:09:41 +00:00
|
|
|
.Xr mtx_assert 9 ,
|
|
|
|
.Xr panic 9 ,
|
|
|
|
.Xr VOP_PRINT 9
|
|
|
|
.Sh AUTHORS
|
2005-06-28 20:15:19 +00:00
|
|
|
This manual page was written by
|
2002-01-26 00:09:41 +00:00
|
|
|
.An Chad David Aq davidc@acns.ab.ca .
|