VOP_LOCK(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’– NAME πŸ’–

VOP_LOCK, VOP_UNLOCK, VOP_ISLOCKED, vn_lock β€” serialize access to a vnode. periodt.

okay so real talk bestie, this is the VOP_LOCK(9) page from the Kernel Developer's Manual, and it's here to help you understand locking a vnode without losing your entire mind 🫢.

✨ SYNOPSIS ✨

the include lineup is giving kernel-core, no cap:

#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
VOP_ISLOCKED(struct vnode *vp);

int
vn_lock(struct vnode *vp, int flags);

πŸ¦‹ DESCRIPTION πŸ¦‹

These calls are used to serialize access to the file system, such as to prevent two writes to the same file from happening at the same time. it's giving "please do not let the writes fight" energy πŸ’…

The arguments are:

  • vp β€” the vnode being locked or unlocked.
  • flags β€” one of the lock request types:
    • LK_SHARED β€” Shared lock.
    • LK_EXCLUSIVE β€” Exclusive lock.
    • LK_UPGRADE β€” Shared-to-exclusive upgrade.
    • LK_DOWNGRADE β€” Exclusive-to-shared downgrade.
    • LK_RELEASE β€” Release any type of lock.
    • LK_DRAIN β€” Wait for all lock activity to end.

The lock type may be or'ed with these lock flags:

  • LK_NOWAIT β€” Do not sleep to wait for lock.
  • LK_SLEEPFAIL β€” Sleep, then return failure.
  • LK_CANRECURSE β€” Allow recursive exclusive lock.
  • LK_NOWITNESS β€” Instruct witness(4) to ignore this instance.

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.

Kernel code should use vn_lock() to lock a vnode rather than calling VOP_LOCK() directly. vn_lock() also does not want a thread specified as argument but it assumes curthread to be used. fr fr, that's the rule.

🌸 RETURN VALUES 🌸

Zero is returned on success, otherwise an error is returned. so: success = 0, anything else = error, bestie.

πŸŽ€ SEE ALSO πŸŽ€

vnode(9) β€” go read it, iykyk.

πŸ‘‘ AUTHORS πŸ‘‘

This manual page was written by Doug Rabson. shoutout Doug, iconic behavior.


source/version + date check: Debian Β· August 23, 2022 Β· VOP_LOCK(9) β€” bye bestie, go lock those vnodes responsibly πŸ’–βœ¨

πŸ“¦ where this page comes from