vfs_lock_file(9)
π vfs_lock_file(9) β your fave file byte range lock, straight from the Kernel API Manual β¨
okay so bestie, welcome to vfs_lock_file(9)! this is the manual page vibe, and yes itβs the Kernel API Manual one π
πΈ NAME πΈ
vfs_lock_file β file byte range lock. literally what it says on the tin, no cap π
β¨ SYNOPSIS β¨
int vfs_lock_file (struct file *filp , unsigned int cmd , struct file_lock *fl , struct file_lock *conf );
π¦ ARGUMENTS π¦
filpβ the file to apply the lock to. main character file energy π«Άcmdβ type of locking operation (F_SETLK,F_GETLK, etc.). pick your fighter πflβ the lock to be applied. yes bestie, this is the lock itself π₯confβ place to return a copy of the conflicting lock, if found. found drama? put it here π
π DESCRIPTION π
okay so a caller that doesnβt care about the conflicting lock may pass NULL as the final argument. simple as that, no stress β¨
but listen: if the filesystem defines a private ->lock method, then conf will be left unchanged; so a caller that cares should initialize it to some acceptable default. donβt leave it looking at you like that π«Ά
now, to avoid blocking kernel daemons, such as lockd, that need to acquire POSIX locks, the ->lock interface may return asynchronously, before the lock has been granted or denied by the underlying filesystem, if (and only if) lm_grant is set. additionally, FOP_ASYNC_LOCK in file_operations fop_flags need to be set. both things, bestie π
callers expecting ->lock to return asynchronously will only use F_SETLK, not F_SETLKW; they will set FL_SLEEP if (and only if) the request is for a blocking lock. okay? okay β¨
when ->lock does return asynchronously, it must return FILE_LOCK_DEFERRED, and call ->lm_grant when the lock request completes. no cap π₯
if the request is for non-blocking lock, the file system should return FILE_LOCK_DEFERRED, then try to get the lock and call the callback routine with the result. if the request timed out, the callback routine will return a nonzero return code, and the file system should release the lock. periodt π
the file system is also responsible to keep a corresponding posix lock when it grants a lock, so the VFS can find out which locks are locally held and do the correct lock cleanup when required. thatβs a whole responsibility, bestie π
and the underlying filesystem must not drop the kernel lock or call->lm_grantbefore returning to the caller with aFILE_LOCK_DEFERREDreturn code. not before. iykyk π¨
π SEE ALSO π
kernel file: ./fs/locks.c β and the whole SEE ALSO squad is:
locks_owner_has_blockers(9)lease_open_conflict(9)locks_delete_block(9)posix_lock_file(9)posix_lock_inode_wait(9)inode_lease_ignore_mask(9)__break_lease(9)lease_get_mtime(9)__fcntl_getlease(9)generic_setlease(9)vfs_setlease(9)fcntl_setlease(9)fcntl_setdeleg(9)flock_lock_inode_wait(9)locks_lock_inode_wait(9)sys_flock(9)vfs_test_lock(9)locks_translate_pid(9)vfs_cancel_lock(9)vfs_inode_has_locks(9)
byeee bestie π β source/version is ./fs, and the date on this one is October 2026 πβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms