VOP_LOCK(9)
β¨ VOP_LOCK β it's giving "one at a time, bestie" β¨
okay so welcome to VOP_LOCK(9), a page from the Kernel Developer's Manual π and honestly? this one is so important it's not even funny.
πΈ NAME πΈ
VOP_LOCK, VOP_UNLOCK, VOP_ISLOCKED, vn_lock β the way to serialize access to a vnode π«Ά
π SYNOPSIS π
#include <sys/param.h>
#include <sys/lock.h>
#include <sys/vnode.h>
int
VOP_LOCK(struct vnode *vp, int flags);
int
VOP_UNLOCK(struct vnode *vp, int flags);
int
VOP_ISLOCKED(struct vnode *vp);
int
vn_lock(struct vnode *vp, int flags);
π DESCRIPTION π
These calls are literally the bouncers of the filesystem β they serialize access to the file system, so like, two writes to the same file don't happen at the same time and cause chaos π no cap.
The arguments are, bestie:
vpβ the vnode getting locked or unlocked. the main character of this whole situation πflagsβ one of the lock request types:LK_SHAREDβ shared lock. we're all just vibing here πLK_EXCLUSIVEβ exclusive lock. my vnode, my rules πLK_UPGRADEβ shared-to-exclusive upgrade. glow-up arc β¨LK_DOWNGRADEβ exclusive-to-shared downgrade. humble era πLK_RELEASEβ release any type of lock. bye bestie π¦LK_DRAINβ wait for all lock activity to end. we're not leaving until everyone's gone, periodt π
The lock type may be or'ed with these lock flags:
LK_NOWAITβ do not sleep to wait for lock. no napping on the job π΄π«LK_SLEEPFAILβ sleep, then return failure. wake up and choose violence πLK_CANRECURSEβ allow recursive exclusive lock. it's giving inception πLK_NOWITNESSβ instructwitness(4)to ignore this instance. not me telling witness to look away π
The lock type may be or'ed with these control flags:
LK_INTERLOCKβ specify when the caller already has a simple lock (VOP_LOCK()will unlock the simple lock after getting the lock). π§LK_RETRYβ retry until locked. we try again and again until it works, obsessed fr fr π₯
π¨ real talk, kernel devs: kernel code should usevn_lock()to lock a vnode rather than callingVOP_LOCK()directly. and btwvn_lock()also does not want a thread specified as argument, but it assumescurthreadto be used. iykyk π
β RETURN VALUES β
Zero is returned on success, otherwise an error is returned. that's it, that's the tea π
π SEE ALSO π
π AUTHORS π
This manual page was written by Doug Rabson. iconic behavior, honestly π
Debian Β· February 25, 2008 β yeah she's been slaying since '08, and this is your girl signing off, mwah π π«Άβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1996 Doug Rabson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms