fs/afs/flock.c
Source file repositories/reference/linux-study-clean/fs/afs/flock.c
File Facts
- System
- Linux kernel
- Corpus path
fs/afs/flock.c- Extension
.c- Size
- 24008 bytes
- Lines
- 878
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
internal.h
Detected Declarations
function afs_set_lock_statefunction afs_lock_may_be_availablefunction afs_schedule_lock_extensionfunction afs_lock_op_donefunction locksfunction list_for_each_entry_safefunction afs_next_lockerfunction list_for_each_entry_safefunction afs_kill_lockers_enoentfunction afs_lock_successfunction afs_set_lockfunction afs_extend_lockfunction afs_release_lockfunction afs_lock_workfunction afs_defer_unlockfunction afs_do_setlk_checkfunction afs_do_setlkfunction afs_do_unlkfunction afs_do_getlkfunction afs_lockfunction afs_flockfunction originalfunction afs_fl_release_private
Annotated Snippet
afs_file_key(p->c.flc_file) == key) {
list_del_init(&p->fl_u.afs.link);
p->fl_u.afs.state = error;
locks_wake_up(p);
}
/* Select the next locker to hand off to. */
if (next && (lock_is_write(next) || lock_is_read(p)))
continue;
next = p;
}
vnode->lock_key = NULL;
key_put(key);
if (next) {
afs_set_lock_state(vnode, AFS_VNODE_LOCK_SETTING);
next->fl_u.afs.state = AFS_LOCK_YOUR_TRY;
trace_afs_flock_op(vnode, next, afs_flock_op_wake);
locks_wake_up(next);
} else {
afs_set_lock_state(vnode, AFS_VNODE_LOCK_NONE);
trace_afs_flock_ev(vnode, NULL, afs_flock_no_lockers, 0);
}
_leave("");
}
/*
* Kill off all waiters in the the pending lock queue due to the vnode being
* deleted.
*/
static void afs_kill_lockers_enoent(struct afs_vnode *vnode)
{
struct file_lock *p;
afs_set_lock_state(vnode, AFS_VNODE_LOCK_DELETED);
while (!list_empty(&vnode->pending_locks)) {
p = list_entry(vnode->pending_locks.next,
struct file_lock, fl_u.afs.link);
list_del_init(&p->fl_u.afs.link);
p->fl_u.afs.state = -ENOENT;
locks_wake_up(p);
}
key_put(vnode->lock_key);
vnode->lock_key = NULL;
}
static void afs_lock_success(struct afs_operation *op)
{
_enter("op=%08x", op->debug_id);
afs_vnode_commit_status(op, &op->file[0]);
}
static const struct afs_operation_ops afs_set_lock_operation = {
.issue_afs_rpc = afs_fs_set_lock,
.issue_yfs_rpc = yfs_fs_set_lock,
.success = afs_lock_success,
.aborted = afs_check_for_remote_deletion,
};
/*
* Get a lock on a file
*/
static int afs_set_lock(struct afs_vnode *vnode, struct key *key,
afs_lock_type_t type)
{
struct afs_operation *op;
_enter("%s{%llx:%llu.%u},%x,%u",
vnode->volume->name,
vnode->fid.vid,
vnode->fid.vnode,
vnode->fid.unique,
key_serial(key), type);
op = afs_alloc_operation(key, vnode->volume);
if (IS_ERR(op))
return PTR_ERR(op);
afs_op_set_vnode(op, 0, vnode);
op->lock.type = type;
op->ops = &afs_set_lock_operation;
return afs_do_sync_operation(op);
}
static const struct afs_operation_ops afs_extend_lock_operation = {
Annotation
- Immediate include surface: `internal.h`.
- Detected declarations: `function afs_set_lock_state`, `function afs_lock_may_be_available`, `function afs_schedule_lock_extension`, `function afs_lock_op_done`, `function locks`, `function list_for_each_entry_safe`, `function afs_next_locker`, `function list_for_each_entry_safe`, `function afs_kill_lockers_enoent`, `function afs_lock_success`.
- 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.