fs/lockd/svclock.c
Source file repositories/reference/linux-study-clean/fs/lockd/svclock.c
File Facts
- System
- Linux kernel
- Corpus path
fs/lockd/svclock.c- Extension
.c- Size
- 29310 bytes
- Lines
- 1075
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/slab.hlinux/errno.hlinux/kernel.hlinux/sched.hlinux/sunrpc/clnt.hlinux/sunrpc/svc_xprt.hlockd.h
Detected Declarations
function nlmsvc_insert_block_lockedfunction list_for_eachfunction nlmsvc_insert_blockfunction nlmsvc_remove_blockfunction nlmsvc_lookup_blockfunction lockd_cookie_matchfunction nlmsvc_find_blockfunction nlmsvc_create_blockfunction nlmsvc_unlink_blockfunction nlmsvc_free_blockfunction nlmsvc_release_blockfunction nlmsvc_traverse_blocksfunction nlmsvc_get_lockownerfunction nlmsvc_put_lockownerfunction nlmsvc_release_lockownerfunction nlmsvc_locks_init_privatefunction nlmsvc_setgrantargsfunction nlmsvc_freegrantargsfunction nlmsvc_defer_lock_rqstfunction nlmsvc_lockfunction vfs_lock_filefunction nlmsvc_testlockfunction nlmsvc_unlockfunction nlmsvc_cancel_blockedfunction nlmsvc_retry_blockedfunction nlmsvc_grant_deferredfunction nlmsvc_notify_blockedfunction nlmsvc_get_ownerfunction nlmsvc_put_ownerfunction nlmsvc_grant_blockedfunction itselffunction nlmsvc_grant_releasefunction nlmsvc_grant_replyfunction retry_deferred_blockfunction nlmsvc_retry_blocked
Annotated Snippet
if (len < 2) {
strcpy(p-3, "...");
break;
}
sprintf(p, "%02x", cookie->data[i]);
p += 2;
len -= 2;
}
*p = '\0';
return buf;
}
#else
static inline const char *nlmdbg_cookie2a(const struct lockd_cookie *cookie)
{
return "???";
}
#endif
/*
* Insert a blocked lock into the global list
*/
static void
nlmsvc_insert_block_locked(struct nlm_block *block, unsigned long when)
{
struct nlm_block *b;
struct list_head *pos;
dprintk("lockd: nlmsvc_insert_block(%p, %ld)\n", block, when);
if (list_empty(&block->b_list)) {
kref_get(&block->b_count);
} else {
list_del_init(&block->b_list);
}
pos = &nlm_blocked;
if (when != NLM_NEVER) {
if ((when += jiffies) == NLM_NEVER)
when ++;
list_for_each(pos, &nlm_blocked) {
b = list_entry(pos, struct nlm_block, b_list);
if (time_after(b->b_when,when) || b->b_when == NLM_NEVER)
break;
}
/* On normal exit from the loop, pos == &nlm_blocked,
* so we will be adding to the end of the list - good
*/
}
list_add_tail(&block->b_list, pos);
block->b_when = when;
}
static void nlmsvc_insert_block(struct nlm_block *block, unsigned long when)
{
spin_lock(&nlm_blocked_lock);
nlmsvc_insert_block_locked(block, when);
spin_unlock(&nlm_blocked_lock);
}
/*
* Remove a block from the global list
*/
static inline void
nlmsvc_remove_block(struct nlm_block *block)
{
spin_lock(&nlm_blocked_lock);
if (!list_empty(&block->b_list)) {
list_del_init(&block->b_list);
spin_unlock(&nlm_blocked_lock);
nlmsvc_release_block(block);
return;
}
spin_unlock(&nlm_blocked_lock);
}
/*
* Find a block for a given lock
*/
static struct nlm_block *
nlmsvc_lookup_block(struct nlm_file *file, struct lockd_lock *lock)
{
struct nlm_block *block;
struct file_lock *fl;
dprintk("lockd: nlmsvc_lookup_block f=%p pd=%d %Ld-%Ld ty=%d\n",
file, lock->fl.c.flc_pid,
(long long)lock->fl.fl_start,
(long long)lock->fl.fl_end,
lock->fl.c.flc_type);
Annotation
- Immediate include surface: `linux/types.h`, `linux/slab.h`, `linux/errno.h`, `linux/kernel.h`, `linux/sched.h`, `linux/sunrpc/clnt.h`, `linux/sunrpc/svc_xprt.h`, `lockd.h`.
- Detected declarations: `function nlmsvc_insert_block_locked`, `function list_for_each`, `function nlmsvc_insert_block`, `function nlmsvc_remove_block`, `function nlmsvc_lookup_block`, `function lockd_cookie_match`, `function nlmsvc_find_block`, `function nlmsvc_create_block`, `function nlmsvc_unlink_block`, `function nlmsvc_free_block`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.