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 β€” instruct witness(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 use vn_lock() to lock a vnode rather than calling VOP_LOCK() directly. and btw vn_lock() also does not want a thread specified as argument, but it assumes curthread to 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