fs/btrfs/locking.c
Source file repositories/reference/linux-study-clean/fs/btrfs/locking.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/locking.c- Extension
.c- Size
- 10506 bytes
- Lines
- 384
- 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
linux/sched.hlinux/pagemap.hlinux/spinlock.hlinux/page-flags.hasm/bug.htrace/events/btrfs.hctree.hextent_io.hlocking.h
Detected Declarations
function btrfs_set_buffer_lockdep_classfunction btrfs_maybe_reset_lockdep_classfunction btrfs_set_eb_lock_ownerfunction btrfs_set_eb_lock_ownerfunction btrfs_try_tree_read_lockfunction btrfs_tree_read_unlockfunction btrfs_tree_lock_nestedfunction btrfs_tree_unlockfunction btrfs_unlock_up_safefunction btrfs_drew_lock_initfunction btrfs_drew_try_write_lockfunction btrfs_drew_write_lockfunction btrfs_drew_write_unlockfunction btrfs_drew_read_lockfunction btrfs_drew_read_unlock
Annotated Snippet
static void btrfs_set_eb_lock_owner(struct extent_buffer *eb, pid_t owner) { }
#endif
/*
* Extent buffer locking
* =====================
*
* We use a rw_semaphore for tree locking, and the semantics are exactly the
* same:
*
* - reader/writer exclusion
* - writer/writer exclusion
* - reader/reader sharing
* - try-lock semantics for readers and writers
*
* The rwsem implementation does opportunistic spinning which reduces number of
* times the locking task needs to sleep.
*/
/*
* btrfs_tree_read_lock_nested - lock extent buffer for read
* @eb: the eb to be locked
* @nest: the nesting level to be used for lockdep
*
* This takes the read lock on the extent buffer, using the specified nesting
* level for lockdep purposes.
*/
void btrfs_tree_read_lock_nested(struct extent_buffer *eb, enum btrfs_lock_nesting nest)
{
u64 start_ns = 0;
if (trace_btrfs_tree_read_lock_enabled())
start_ns = ktime_get_ns();
down_read_nested(&eb->lock, nest);
trace_btrfs_tree_read_lock(eb, start_ns);
}
/*
* Try-lock for read.
*
* Return true if the rwlock has been taken, false otherwise
*/
bool btrfs_try_tree_read_lock(struct extent_buffer *eb)
{
if (down_read_trylock(&eb->lock)) {
trace_btrfs_try_tree_read_lock(eb);
return true;
}
return false;
}
/*
* Release read lock.
*/
void btrfs_tree_read_unlock(struct extent_buffer *eb)
{
trace_btrfs_tree_read_unlock(eb);
up_read(&eb->lock);
}
/*
* Lock eb for write.
*
* @eb: the eb to lock
* @nest: the nesting to use for the lock
*
* Returns with the eb->lock write locked.
*/
void btrfs_tree_lock_nested(struct extent_buffer *eb, enum btrfs_lock_nesting nest)
__acquires(&eb->lock)
{
u64 start_ns = 0;
if (trace_btrfs_tree_lock_enabled())
start_ns = ktime_get_ns();
down_write_nested(&eb->lock, nest);
btrfs_set_eb_lock_owner(eb, current->pid);
trace_btrfs_tree_lock(eb, start_ns);
}
/*
* Release the write lock.
*/
void btrfs_tree_unlock(struct extent_buffer *eb)
{
trace_btrfs_tree_unlock(eb);
btrfs_set_eb_lock_owner(eb, 0);
up_write(&eb->lock);
Annotation
- Immediate include surface: `linux/sched.h`, `linux/pagemap.h`, `linux/spinlock.h`, `linux/page-flags.h`, `asm/bug.h`, `trace/events/btrfs.h`, `ctree.h`, `extent_io.h`.
- Detected declarations: `function btrfs_set_buffer_lockdep_class`, `function btrfs_maybe_reset_lockdep_class`, `function btrfs_set_eb_lock_owner`, `function btrfs_set_eb_lock_owner`, `function btrfs_try_tree_read_lock`, `function btrfs_tree_read_unlock`, `function btrfs_tree_lock_nested`, `function btrfs_tree_unlock`, `function btrfs_unlock_up_safe`, `function btrfs_drew_lock_init`.
- 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.