1e5e600c9SMark Murray.\" 25385e8bfSChad David.\" Copyright (C) 2002 Chad David <davidc@acns.ab.ca>. All rights reserved. 3e5e600c9SMark Murray.\" 4e5e600c9SMark Murray.\" Redistribution and use in source and binary forms, with or without 5e5e600c9SMark Murray.\" modification, are permitted provided that the following conditions 6e5e600c9SMark Murray.\" are met: 7e5e600c9SMark Murray.\" 1. Redistributions of source code must retain the above copyright 85385e8bfSChad David.\" notice(s), this list of conditions and the following disclaimer as 95385e8bfSChad David.\" the first lines of this file unmodified other than the possible 105385e8bfSChad David.\" addition of one or more copyright notices. 11e5e600c9SMark Murray.\" 2. Redistributions in binary form must reproduce the above copyright 125385e8bfSChad David.\" notice(s), this list of conditions and the following disclaimer in the 13e5e600c9SMark Murray.\" documentation and/or other materials provided with the distribution. 14e5e600c9SMark Murray.\" 155385e8bfSChad David.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 165385e8bfSChad David.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 175385e8bfSChad David.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 185385e8bfSChad David.\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 195385e8bfSChad David.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 205385e8bfSChad David.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 215385e8bfSChad David.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 225385e8bfSChad David.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 235385e8bfSChad David.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 245385e8bfSChad David.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 255385e8bfSChad David.\" DAMAGE. 26e5e600c9SMark Murray.\" 27*fda32d58SRyan Libby.Dd June 21, 2024 28e5e600c9SMark Murray.Dt LOCK 9 293d45e180SRuslan Ermilov.Os 30e5e600c9SMark Murray.Sh NAME 31e5e600c9SMark Murray.Nm lockinit , 325385e8bfSChad David.Nm lockdestroy , 335385e8bfSChad David.Nm lockmgr , 347f527abcSAttilio Rao.Nm lockmgr_args , 3548a12f89SAttilio Rao.Nm lockmgr_args_rw , 36fc2d483eSAttilio Rao.Nm lockmgr_disown , 37*fda32d58SRyan Libby.Nm lockmgr_disowned , 38*fda32d58SRyan Libby.Nm lockmgr_lock_flags , 39fa885265SAttilio Rao.Nm lockmgr_printinfo , 40f0c5fe2dSAttilio Rao.Nm lockmgr_recursed , 4148a12f89SAttilio Rao.Nm lockmgr_rw , 42*fda32d58SRyan Libby.Nm lockmgr_slock , 43*fda32d58SRyan Libby.Nm lockmgr_unlock , 44*fda32d58SRyan Libby.Nm lockmgr_xlock , 4578a25172SAttilio Rao.Nm lockstatus , 46f0c5fe2dSAttilio Rao.Nm lockmgr_assert 475385e8bfSChad David.Nd "lockmgr family of functions" 48e5e600c9SMark Murray.Sh SYNOPSIS 4932eef9aeSRuslan Ermilov.In sys/types.h 50008f392eSAttilio Rao.In sys/lock.h 515385e8bfSChad David.In sys/lockmgr.h 52e5e600c9SMark Murray.Ft void 53c4a7ba6eSChad David.Fn lockinit "struct lock *lkp" "int prio" "const char *wmesg" "int timo" "int flags" 545385e8bfSChad David.Ft void 555385e8bfSChad David.Fn lockdestroy "struct lock *lkp" 56e5e600c9SMark Murray.Ft int 5748a12f89SAttilio Rao.Fn lockmgr "struct lock *lkp" "u_int flags" "struct mtx *ilk" 585385e8bfSChad David.Ft int 5948a12f89SAttilio Rao.Fn lockmgr_args "struct lock *lkp" "u_int flags" "struct mtx *ilk" "const char *wmesg" "int prio" "int timo" 6048a12f89SAttilio Rao.Ft int 6148a12f89SAttilio Rao.Fn lockmgr_args_rw "struct lock *lkp" "u_int flags" "struct rwlock *ilk" "const char *wmesg" "int prio" "int timo" 625385e8bfSChad David.Ft void 63fc2d483eSAttilio Rao.Fn lockmgr_disown "struct lock *lkp" 64*fda32d58SRyan Libby.Ft int 65*fda32d58SRyan Libby.Fn lockmgr_disowned "const struct lock *lkp" 66*fda32d58SRyan Libby.Ft int 67*fda32d58SRyan Libby.Fn lockmgr_lock_flags "struct lock *lkp" "u_int flags" "struct lock_object *ilk" "const char *file" "int line" 68fc2d483eSAttilio Rao.Ft void 69d576deedSPawel Jakub Dawidek.Fn lockmgr_printinfo "const struct lock *lkp" 70fa885265SAttilio Rao.Ft int 71d576deedSPawel Jakub Dawidek.Fn lockmgr_recursed "const struct lock *lkp" 727f527abcSAttilio Rao.Ft int 7348a12f89SAttilio Rao.Fn lockmgr_rw "struct lock *lkp" "u_int flags" "struct rwlock *ilk" 7448a12f89SAttilio Rao.Ft int 75*fda32d58SRyan Libby.Fn lockmgr_slock "struct lock *lkp" "u_int flags" "const char *file" "int line" 76*fda32d58SRyan Libby.Ft int 77*fda32d58SRyan Libby.Fn lockmgr_unlock "struct lock *lkp" 78*fda32d58SRyan Libby.Ft int 79*fda32d58SRyan Libby.Fn lockmgr_xlock "struct lock *lkp" "u_int flags" "const char *file" "int line" 80*fda32d58SRyan Libby.Ft int 81d576deedSPawel Jakub Dawidek.Fn lockstatus "const struct lock *lkp" 82f0c5fe2dSAttilio Rao.Pp 83f0c5fe2dSAttilio Rao.Cd "options INVARIANTS" 84f0c5fe2dSAttilio Rao.Cd "options INVARIANT_SUPPORT" 85f0c5fe2dSAttilio Rao.Ft void 86d576deedSPawel Jakub Dawidek.Fn lockmgr_assert "const struct lock *lkp" "int what" 87e5e600c9SMark Murray.Sh DESCRIPTION 885385e8bfSChad DavidThe 89e5e600c9SMark Murray.Fn lockinit 905385e8bfSChad Davidfunction is used to initialize a lock. 91ffa23792SChad DavidIt must be called before any operation can be performed on a lock. 925385e8bfSChad DavidIts arguments are: 935385e8bfSChad David.Bl -tag -width ".Fa wmesg" 945385e8bfSChad David.It Fa lkp 955385e8bfSChad DavidA pointer to the lock to initialize. 965385e8bfSChad David.It Fa prio 975385e8bfSChad DavidThe priority passed to 98e7573e7aSJohn Baldwin.Xr sleep 9 . 995385e8bfSChad David.It Fa wmesg 1005385e8bfSChad DavidThe lock message. 1015385e8bfSChad DavidThis is used for both debugging output and 102e7573e7aSJohn Baldwin.Xr sleep 9 . 1035385e8bfSChad David.It Fa timo 1045385e8bfSChad DavidThe timeout value passed to 105e7573e7aSJohn Baldwin.Xr sleep 9 . 1065385e8bfSChad David.It Fa flags 107008f392eSAttilio RaoThe flags the lock is to be initialized with: 108abd94b3dSAttilio Rao.Bl -tag -width ".Dv LK_CANRECURSE" 1095385e8bfSChad David.It Dv LK_CANRECURSE 1105385e8bfSChad DavidAllow recursive exclusive locks. 111008f392eSAttilio Rao.It Dv LK_NOPROFILE 112008f392eSAttilio RaoDisable lock profiling for this lock. 113f3a331b7SMaxim Konovalov.It Dv LK_NOSHARE 114f3a331b7SMaxim KonovalovAllow exclusive locks only. 115abd94b3dSAttilio Rao.It Dv LK_NOWITNESS 116abd94b3dSAttilio RaoInstruct 117abd94b3dSAttilio Rao.Xr witness 4 118abd94b3dSAttilio Raoto ignore this lock. 119abd94b3dSAttilio Rao.It Dv LK_NODUP 120abd94b3dSAttilio Rao.Xr witness 4 121abd94b3dSAttilio Raoshould log messages about duplicate locks being acquired. 122008f392eSAttilio Rao.It Dv LK_QUIET 123008f392eSAttilio RaoDisable 124008f392eSAttilio Rao.Xr ktr 4 125008f392eSAttilio Raologging for this lock. 1265385e8bfSChad David.El 1275385e8bfSChad David.El 128e5e600c9SMark Murray.Pp 1295385e8bfSChad DavidThe 1305385e8bfSChad David.Fn lockdestroy 1315385e8bfSChad Davidfunction is used to destroy a lock, and while it is called in a number of 1325385e8bfSChad Davidplaces in the kernel, it currently does nothing. 1335385e8bfSChad David.Pp 1345385e8bfSChad DavidThe 1355385e8bfSChad David.Fn lockmgr 13648a12f89SAttilio Raoand 13748a12f89SAttilio Rao.Fn lockmgr_rw 13848a12f89SAttilio Raofunctions handle general locking functionality within the kernel, including 1395385e8bfSChad Davidsupport for shared and exclusive locks, and recursion. 1405385e8bfSChad David.Fn lockmgr 14148a12f89SAttilio Raoand 14248a12f89SAttilio Rao.Fn lockmgr_rw 14348a12f89SAttilio Raoare also able to upgrade and downgrade locks. 1445385e8bfSChad David.Pp 14548a12f89SAttilio RaoTheir arguments are: 14648a12f89SAttilio Rao.Bl -tag -width ".Fa flags" 1475385e8bfSChad David.It Fa lkp 1485385e8bfSChad DavidA pointer to the lock to manipulate. 1495385e8bfSChad David.It Fa flags 1505385e8bfSChad DavidFlags indicating what action is to be taken. 15172ba3c08SKonstantin Belousov.Bl -tag -width ".Dv LK_NODDLKTREAT" 152e5e600c9SMark Murray.It Dv LK_SHARED 1535385e8bfSChad DavidAcquire a shared lock. 154c858f5ceSAndriy GaponIf an exclusive lock is currently held, 155c858f5ceSAndriy Gapon.Dv EDEADLK 156c858f5ceSAndriy Gaponwill be returned. 157e5e600c9SMark Murray.It Dv LK_EXCLUSIVE 1585385e8bfSChad DavidAcquire an exclusive lock. 1595385e8bfSChad DavidIf an exclusive lock is already held, and 1608271a102SRuslan Ermilov.Dv LK_CANRECURSE 1615385e8bfSChad Davidis not set, the system will 1625385e8bfSChad David.Xr panic 9 . 163e5e600c9SMark Murray.It Dv LK_DOWNGRADE 1645385e8bfSChad DavidDowngrade exclusive lock to a shared lock. 1655385e8bfSChad DavidDowngrading a shared lock is not permitted. 166c858f5ceSAndriy GaponIf an exclusive lock has been recursed, the system will 167c858f5ceSAndriy Gapon.Xr panic 9 . 1685385e8bfSChad David.It Dv LK_UPGRADE 1695385e8bfSChad DavidUpgrade a shared lock to an exclusive lock. 1705dc5cbb2SKonstantin BelousovIf this call fails, the shared lock is lost, even if the 1715dc5cbb2SKonstantin Belousov.Dv LK_NOWAIT 1725dc5cbb2SKonstantin Belousovflag is specified. 173653ed924SKonstantin BelousovDuring the upgrade, the shared lock could 174653ed924SKonstantin Belousovbe temporarily dropped. 175ffa23792SChad DavidAttempts to upgrade an exclusive lock will cause a 1765385e8bfSChad David.Xr panic 9 . 1775dc5cbb2SKonstantin Belousov.It Dv LK_TRYUPGRADE 1785dc5cbb2SKonstantin BelousovTry to upgrade a shared lock to an exclusive lock. 1795dc5cbb2SKonstantin BelousovThe failure to upgrade does not result in the dropping 1805dc5cbb2SKonstantin Belousovof the shared lock ownership. 181e5e600c9SMark Murray.It Dv LK_RELEASE 1825385e8bfSChad DavidRelease the lock. 1835385e8bfSChad DavidReleasing a lock that is not held can cause a 1845385e8bfSChad David.Xr panic 9 . 185e5e600c9SMark Murray.It Dv LK_DRAIN 1865385e8bfSChad DavidWait for all activity on the lock to end, then mark it decommissioned. 1875385e8bfSChad DavidThis is used before freeing a lock that is part of a piece of memory that is 1885385e8bfSChad Davidabout to be freed. 1895385e8bfSChad David(As documented in 190fe08efe6SRuslan Ermilov.In sys/lockmgr.h . ) 1915385e8bfSChad David.It Dv LK_SLEEPFAIL 1925385e8bfSChad DavidFail if operation has slept. 1935385e8bfSChad David.It Dv LK_NOWAIT 1945385e8bfSChad DavidDo not allow the call to sleep. 1955385e8bfSChad DavidThis can be used to test the lock. 196da590a3eSRyan Libby.It Dv LK_TIMELOCK 197da590a3eSRyan LibbyUse 198da590a3eSRyan Libby.Fa timo 199da590a3eSRyan Libbyduring a sleep; otherwise, 0 is used. 200031e0f3cSAttilio Rao.It Dv LK_NOWITNESS 201031e0f3cSAttilio RaoSkip the 202031e0f3cSAttilio Rao.Xr witness 4 203031e0f3cSAttilio Raochecks for this instance. 2045385e8bfSChad David.It Dv LK_CANRECURSE 2055385e8bfSChad DavidAllow recursion on an exclusive lock. 2065385e8bfSChad DavidFor every lock there must be a release. 2075385e8bfSChad David.It Dv LK_INTERLOCK 2085385e8bfSChad DavidUnlock the interlock (which should be locked already). 20972ba3c08SKonstantin Belousov.It Dv LK_NODDLKTREAT 21072ba3c08SKonstantin BelousovNormally, 21172ba3c08SKonstantin Belousov.Fn lockmgr 21272ba3c08SKonstantin Belousovpostpones serving further shared requests for shared-locked lock if there is 21372ba3c08SKonstantin Belousovexclusive waiter, to avoid exclusive lock starvation. 21472ba3c08SKonstantin BelousovBut, if the thread requesting the shared lock already owns a shared lockmgr 21572ba3c08SKonstantin Belousovlock, the request is granted even in presence of the parallel exclusive lock 21672ba3c08SKonstantin Belousovrequest, which is done to avoid deadlocks with recursive shared acquisition. 21772ba3c08SKonstantin Belousov.Pp 21872ba3c08SKonstantin BelousovThe 21972ba3c08SKonstantin Belousov.Dv LK_NODDLKTREAT 22072ba3c08SKonstantin Belousovflag can only be used by code which requests shared non-recursive lock. 22172ba3c08SKonstantin BelousovThe flag allows exclusive requests to preempt the current shared request 22272ba3c08SKonstantin Belousoveven if the current thread owns shared locks. 22372ba3c08SKonstantin BelousovThis is safe since shared lock is guaranteed to not recurse, and is used 22472ba3c08SKonstantin Belousovwhen thread is known to held unrelated shared locks, to not cause 2257851d429SEdward Tomasz Napieralaunnecessary starvation. 2267851d429SEdward Tomasz NapieralaAn example is 22772ba3c08SKonstantin Belousov.Dv vp 22872ba3c08SKonstantin Belousovlocking in VFS 22972ba3c08SKonstantin Belousov.Xr lookup 9 , 23072ba3c08SKonstantin Belousovwhen 23172ba3c08SKonstantin Belousov.Dv dvp 23272ba3c08SKonstantin Belousovis already locked. 233e5e600c9SMark Murray.El 23448a12f89SAttilio Rao.It Fa ilk 2355385e8bfSChad DavidAn interlock mutex for controlling group access to the lock. 2365385e8bfSChad DavidIf 2375385e8bfSChad David.Dv LK_INTERLOCK 2385385e8bfSChad Davidis specified, 2395385e8bfSChad David.Fn lockmgr 24048a12f89SAttilio Raoand 24148a12f89SAttilio Rao.Fn lockmgr_rw 24248a12f89SAttilio Raoassume 24348a12f89SAttilio Rao.Fa ilk 2445385e8bfSChad Davidis currently owned and not recursed, and will return it unlocked. 2455385e8bfSChad DavidSee 2465385e8bfSChad David.Xr mtx_assert 9 . 2475385e8bfSChad David.El 2485385e8bfSChad David.Pp 2495385e8bfSChad DavidThe 2507f527abcSAttilio Rao.Fn lockmgr_args 25148a12f89SAttilio Raoand 25248a12f89SAttilio Rao.Fn lockmgr_args_rw 25348a12f89SAttilio Raofunction work like 2547f527abcSAttilio Rao.Fn lockmgr 25548a12f89SAttilio Raoand 25648a12f89SAttilio Rao.Fn lockmgr_rw 2577f527abcSAttilio Raobut accepting a 2587f527abcSAttilio Rao.Fa wmesg , 2597f527abcSAttilio Rao.Fa timo 2607f527abcSAttilio Raoand 2617f527abcSAttilio Rao.Fa prio 26206e361fbSChristian Bruefferon a per-instance basis. 26306e361fbSChristian BruefferThe specified values will override the default 2647f527abcSAttilio Raoones, but this can still be used passing, respectively, 2657f527abcSAttilio Rao.Dv LK_WMESG_DEFAULT , 2667f527abcSAttilio Rao.Dv LK_PRIO_DEFAULT 2677f527abcSAttilio Raoand 2687f527abcSAttilio Rao.Dv LK_TIMO_DEFAULT . 2695385e8bfSChad David.Pp 2705385e8bfSChad DavidThe 271*fda32d58SRyan Libby.Fn lockmgr_lock_flags 272*fda32d58SRyan Libbyfunction works like 273*fda32d58SRyan Libby.Fn lockmgr 274*fda32d58SRyan Libbybut accepts explicit 275*fda32d58SRyan Libby.Fa file 276*fda32d58SRyan Libbyand 277*fda32d58SRyan Libby.Fa line 278*fda32d58SRyan Libbyarguments for lock tracing. 279*fda32d58SRyan Libby.Pp 280*fda32d58SRyan LibbyThe 281*fda32d58SRyan Libby.Fn lockmgr_slock , 282*fda32d58SRyan Libby.Fn lockmgr_xlock , 283*fda32d58SRyan Libbyand 284*fda32d58SRyan Libby.Fn lockmgr_unlock 285*fda32d58SRyan Libbyfunctions are lightweight entry points that function like 286*fda32d58SRyan Libby.Fn lockmgr 287*fda32d58SRyan Libbyfor the 288*fda32d58SRyan Libby.Dv LK_SHARED , 289*fda32d58SRyan Libby.Dv LK_EXCLUSIVE , 290*fda32d58SRyan Libbyand 291*fda32d58SRyan Libby.Dv LK_RELEASE 292*fda32d58SRyan Libbyoperations respectively. 293*fda32d58SRyan LibbyThey provide functionality similar to 294*fda32d58SRyan Libby.Xr sx 9 295*fda32d58SRyan Libbylocks in that none of the additional 296*fda32d58SRyan Libby.Xr lockmgr 9 297*fda32d58SRyan Libbyfeatures are supported. 298*fda32d58SRyan LibbySpecifically, these functions do not support unlocking interlocks, the 299*fda32d58SRyan Libby.Dv LK_SLEEPFAIL 300*fda32d58SRyan Libbyflag, or locks with shared locking disabled via 301*fda32d58SRyan Libby.Dv LK_NOSHARE . 302*fda32d58SRyan LibbyThey also accept explicit 303*fda32d58SRyan Libby.Fa file 304*fda32d58SRyan Libbyand 305*fda32d58SRyan Libby.Fa line 306*fda32d58SRyan Libbyarguments for lock tracing. 307*fda32d58SRyan Libby.Pp 308*fda32d58SRyan LibbyThe 309fc2d483eSAttilio Rao.Fn lockmgr_disown 3103220cdf4SAttilio Raofunction switches the owner from the current thread to be 311fc2d483eSAttilio Rao.Dv LK_KERNPROC , 312584b5892SChristian Bruefferif the lock is already held. 313fc2d483eSAttilio Rao.Pp 314fc2d483eSAttilio RaoThe 315*fda32d58SRyan Libby.Fn lockmgr_disowned 316*fda32d58SRyan Libbyfunction returns true or false according to whether the lock is held by 317*fda32d58SRyan Libby.Dv LK_KERNPROC . 318*fda32d58SRyan Libby.Pp 319*fda32d58SRyan LibbyThe 3205385e8bfSChad David.Fn lockmgr_printinfo 3215385e8bfSChad Davidfunction prints debugging information about the lock. 3225385e8bfSChad DavidIt is used primarily by 3235385e8bfSChad David.Xr VOP_PRINT 9 3245385e8bfSChad Davidfunctions. 325fa885265SAttilio Rao.Pp 326fa885265SAttilio RaoThe 327fa885265SAttilio Rao.Fn lockmgr_recursed 328fa885265SAttilio Raofunction returns true if the lock is recursed, 0 329fa885265SAttilio Raootherwise. 330f0c5fe2dSAttilio Rao.Pp 3317f527abcSAttilio RaoThe 3327f527abcSAttilio Rao.Fn lockstatus 3337f527abcSAttilio Raofunction returns the status of the lock in relation to the current thread. 3347f527abcSAttilio Rao.Pp 335f0c5fe2dSAttilio RaoWhen compiled with 336f0c5fe2dSAttilio Rao.Cd "options INVARIANTS" 337f0c5fe2dSAttilio Raoand 338f0c5fe2dSAttilio Rao.Cd "options INVARIANT_SUPPORT" , 339f0c5fe2dSAttilio Raothe 340f0c5fe2dSAttilio Rao.Fn lockmgr_assert 341f0c5fe2dSAttilio Raofunction tests 342f0c5fe2dSAttilio Rao.Fa lkp 343f0c5fe2dSAttilio Raofor the assertions specified in 344f0c5fe2dSAttilio Rao.Fa what , 345f0c5fe2dSAttilio Raoand panics if they are not met. 346f0c5fe2dSAttilio RaoOne of the following assertions must be specified: 347f0c5fe2dSAttilio Rao.Bl -tag -width ".Dv KA_UNLOCKED" 348f0c5fe2dSAttilio Rao.It Dv KA_LOCKED 349f0c5fe2dSAttilio RaoAssert that the current thread has either a shared or an exclusive lock on the 350f0c5fe2dSAttilio Rao.Vt lkp 351f0c5fe2dSAttilio Raolock pointed to by the first argument. 352f0c5fe2dSAttilio Rao.It Dv KA_SLOCKED 353f0c5fe2dSAttilio RaoAssert that the current thread has a shared lock on the 354f0c5fe2dSAttilio Rao.Vt lkp 355f0c5fe2dSAttilio Raolock pointed to by the first argument. 356f0c5fe2dSAttilio Rao.It Dv KA_XLOCKED 357f0c5fe2dSAttilio RaoAssert that the current thread has an exclusive lock on the 358f0c5fe2dSAttilio Rao.Vt lkp 359f0c5fe2dSAttilio Raolock pointed to by the first argument. 360f0c5fe2dSAttilio Rao.It Dv KA_UNLOCKED 361f0c5fe2dSAttilio RaoAssert that the current thread has no lock on the 362f0c5fe2dSAttilio Rao.Vt lkp 363f0c5fe2dSAttilio Raolock pointed to by the first argument. 364f0c5fe2dSAttilio Rao.El 365f0c5fe2dSAttilio Rao.Pp 366f0c5fe2dSAttilio RaoIn addition, one of the following optional assertions can be used with 367f0c5fe2dSAttilio Raoeither an 368f0c5fe2dSAttilio Rao.Dv KA_LOCKED , 369f0c5fe2dSAttilio Rao.Dv KA_SLOCKED , 370f0c5fe2dSAttilio Raoor 371f0c5fe2dSAttilio Rao.Dv KA_XLOCKED 372f0c5fe2dSAttilio Raoassertion: 373f0c5fe2dSAttilio Rao.Bl -tag -width ".Dv KA_NOTRECURSED" 374f0c5fe2dSAttilio Rao.It Dv KA_RECURSED 375f0c5fe2dSAttilio RaoAssert that the current thread has a recursed lock on 376f0c5fe2dSAttilio Rao.Fa lkp . 377f0c5fe2dSAttilio Rao.It Dv KA_NOTRECURSED 378af176d73SChristian BruefferAssert that the current thread does not have a recursed lock on 379f0c5fe2dSAttilio Rao.Fa lkp . 380f0c5fe2dSAttilio Rao.El 381e5e600c9SMark Murray.Sh RETURN VALUES 3825385e8bfSChad DavidThe 3835385e8bfSChad David.Fn lockmgr 38448a12f89SAttilio Raoand 38548a12f89SAttilio Rao.Fn lockmgr_rw 38648a12f89SAttilio Raofunctions return 0 on success and non-zero on failure. 3875385e8bfSChad David.Pp 3885385e8bfSChad DavidThe 3895385e8bfSChad David.Fn lockstatus 3905385e8bfSChad Davidfunction returns: 3915385e8bfSChad David.Bl -tag -width ".Dv LK_EXCLUSIVE" 3925385e8bfSChad David.It Dv LK_EXCLUSIVE 3933220cdf4SAttilio RaoAn exclusive lock is held by the current thread. 3945385e8bfSChad David.It Dv LK_EXCLOTHER 3953220cdf4SAttilio RaoAn exclusive lock is held by someone other than the current thread. 3965385e8bfSChad David.It Dv LK_SHARED 3975385e8bfSChad DavidA shared lock is held. 3985385e8bfSChad David.It Li 0 3995385e8bfSChad DavidThe lock is not held by anyone. 4005385e8bfSChad David.El 4015385e8bfSChad David.Sh ERRORS 4025385e8bfSChad David.Fn lockmgr 40348a12f89SAttilio Raoand 40448a12f89SAttilio Rao.Fn lockmgr_rw 40548a12f89SAttilio Raofail if: 4065385e8bfSChad David.Bl -tag -width Er 4075385e8bfSChad David.It Bq Er EBUSY 4088271a102SRuslan Ermilov.Dv LK_FORCEUPGRADE 4095385e8bfSChad Davidwas requested and another thread had already requested a lock upgrade. 4105385e8bfSChad David.It Bq Er EBUSY 4115385e8bfSChad David.Dv LK_NOWAIT 4125dc5cbb2SKonstantin Belousovwas set, and a sleep would have been required, or 4135dc5cbb2SKonstantin Belousov.Dv LK_TRYUPGRADE 4145dc5cbb2SKonstantin Belousovoperation was not able to upgrade the lock. 415*fda32d58SRyan Libby.It Bq Er EDEADLK 416*fda32d58SRyan LibbyA shared lock was attempted while the thread already held the exclusive lock. 4175385e8bfSChad David.It Bq Er ENOLCK 4188271a102SRuslan Ermilov.Dv LK_SLEEPFAIL 4195385e8bfSChad Davidwas set and 4205385e8bfSChad David.Fn lockmgr 42148a12f89SAttilio Raoor 42248a12f89SAttilio Rao.Fn lockmgr_rw 4235385e8bfSChad Daviddid sleep. 4245385e8bfSChad David.It Bq Er EINTR 4258271a102SRuslan Ermilov.Dv PCATCH 4265385e8bfSChad Davidwas set in the lock priority, and a signal was delivered during a sleep. 4275385e8bfSChad DavidNote the 428e5e600c9SMark Murray.Er ERESTART 4295385e8bfSChad Daviderror below. 4305385e8bfSChad David.It Bq Er ERESTART 4315385e8bfSChad David.Dv PCATCH 4325385e8bfSChad Davidwas set in the lock priority, a signal was delivered during a sleep, 4335385e8bfSChad Davidand the system call is to be restarted. 4345385e8bfSChad David.It Bq Er EWOULDBLOCK 4355385e8bfSChad Davida non-zero timeout was given, and the timeout expired. 4365385e8bfSChad David.El 4375385e8bfSChad David.Sh LOCKS 4385385e8bfSChad DavidIf 4395385e8bfSChad David.Dv LK_INTERLOCK 4405385e8bfSChad Davidis passed in the 4415385e8bfSChad David.Fa flags 4425385e8bfSChad Davidargument to 44348a12f89SAttilio Rao.Fn lockmgr 44448a12f89SAttilio Raoor 44548a12f89SAttilio Rao.Fn lockmgr_rw , 4465385e8bfSChad Davidthe 44748a12f89SAttilio Rao.Fa ilk 4485385e8bfSChad Davidmust be held prior to calling 44948a12f89SAttilio Rao.Fn lockmgr 45048a12f89SAttilio Raoor 45148a12f89SAttilio Rao.Fn lockmgr_rw , 4525385e8bfSChad Davidand will be returned unlocked. 4535385e8bfSChad David.Pp 4545385e8bfSChad DavidUpgrade attempts that fail result in the loss of the lock that 4555385e8bfSChad Davidis currently held. 4565385e8bfSChad DavidAlso, it is invalid to upgrade an 4575385e8bfSChad Davidexclusive lock, and a 4585385e8bfSChad David.Xr panic 9 4595385e8bfSChad Davidwill be the result of trying. 4605385e8bfSChad David.Sh SEE ALSO 461*fda32d58SRyan Libby.Xr witness 4 , 462a280550aSJulian Elischer.Xr condvar 9 , 463a280550aSJulian Elischer.Xr locking 9 , 4641e9469d1SChristian Brueffer.Xr mtx_assert 9 , 465a280550aSJulian Elischer.Xr mutex 9 , 4661e9469d1SChristian Brueffer.Xr panic 9 , 467a280550aSJulian Elischer.Xr rwlock 9 , 468e7573e7aSJohn Baldwin.Xr sleep 9 , 469a280550aSJulian Elischer.Xr sx 9 , 4705385e8bfSChad David.Xr VOP_PRINT 9 4715385e8bfSChad David.Sh AUTHORS 472571dba6eSHiten PandyaThis manual page was written by 4738a7314fcSBaptiste Daroussin.An Chad David Aq Mt davidc@acns.ab.ca . 474