fs/xfs/xfs_buf.c
Source file repositories/reference/linux-study-clean/fs/xfs/xfs_buf.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/xfs_buf.c- Extension
.c- Size
- 52347 bytes
- Lines
- 2073
- 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
xfs_platform.hlinux/backing-dev.hlinux/dax.hxfs_shared.hxfs_format.hxfs_log_format.hxfs_trans_resv.hxfs_mount.hxfs_trace.hxfs_log.hxfs_log_recover.hxfs_log_priv.hxfs_trans.hxfs_buf_item.hxfs_errortag.hxfs_error.hxfs_ag.hxfs_buf_mem.hxfs_notify_failure.h
Detected Declarations
function xfs_buf_is_uncachedfunction xfs_buf_stalefunction xfs_buf_free_callbackfunction xfs_buf_freefunction xfs_buf_alloc_kmemfunction vmallocfunction xfs_buf_allocfunction _xfs_buf_obj_cmpfunction xfs_buf_map_verifyfunction xfs_buf_find_lockfunction xfs_buf_lookupfunction xfs_buf_find_insertfunction xfs_buftarg_get_pagfunction xfs_buf_get_mapfunction _xfs_buf_readfunction xfs_buf_reverifyfunction xfs_buf_read_mapfunction xfs_buf_readahead_mapfunction xfs_buf_read_uncachedfunction xfs_buf_get_uncachedfunction releasefunction xfs_buf_destroyfunction xfs_buf_killfunction xfs_buf_relefunction xfs_buf_trylockfunction xfs_buf_lockfunction xfs_buf_unlockfunction xfs_buf_wait_unpinfunction xfs_buf_ioerror_alert_ratelimitedfunction xfs_buf_ioerror_permanentfunction xfs_buf_ioend_handle_errorfunction __xfs_buf_ioendfunction xfs_buf_ioendfunction xfs_buf_ioend_workfunction __xfs_buf_ioerrorfunction xfs_buf_ioerror_alertfunction xfs_buf_ioend_failfunction xfs_bwritefunction xfs_buf_bio_end_iofunction xfs_buf_bio_opfunction xfs_buf_submit_biofunction xfs_buf_iowaitfunction xfs_buf_verify_writefunction xfs_buf_submitfunction __xfs_buf_mark_corruptfunction targetsfunction xfs_buftarg_waitfunction xfs_buftarg_drain
Annotated Snippet
if (!xfs_buf_trylock(bp)) {
XFS_STATS_INC(bp->b_mount, xb_busy_locked);
return -EAGAIN;
}
} else {
xfs_buf_lock(bp);
XFS_STATS_INC(bp->b_mount, xb_get_locked_waited);
}
/*
* if the buffer is stale, clear all the external state associated with
* it. We need to keep flags such as how we allocated the buffer memory
* intact here.
*/
if (bp->b_flags & XBF_STALE) {
if (flags & XBF_LIVESCAN) {
xfs_buf_unlock(bp);
return -ENOENT;
}
ASSERT((bp->b_flags & _XBF_DELWRI_Q) == 0);
bp->b_flags &= _XBF_KMEM;
bp->b_ops = NULL;
}
return 0;
}
static inline int
xfs_buf_lookup(
struct xfs_buftarg *btp,
struct xfs_buf_map *map,
xfs_buf_flags_t flags,
struct xfs_buf **bpp)
{
struct xfs_buf *bp;
int error;
rcu_read_lock();
bp = rhashtable_lookup(&btp->bt_hash, map, xfs_buf_hash_params);
if (!bp || !lockref_get_not_dead(&bp->b_lockref)) {
rcu_read_unlock();
return -ENOENT;
}
rcu_read_unlock();
error = xfs_buf_find_lock(bp, flags);
if (error) {
xfs_buf_rele(bp);
return error;
}
trace_xfs_buf_find(bp, flags, _RET_IP_);
*bpp = bp;
return 0;
}
/*
* Insert the new_bp into the hash table. This consumes the perag reference
* taken for the lookup regardless of the result of the insert.
*/
static int
xfs_buf_find_insert(
struct xfs_buftarg *btp,
struct xfs_perag *pag,
struct xfs_buf_map *cmap,
struct xfs_buf_map *map,
int nmaps,
xfs_buf_flags_t flags,
struct xfs_buf **bpp)
{
struct xfs_buf *new_bp;
struct xfs_buf *bp;
int error;
error = xfs_buf_alloc(btp, map, nmaps, flags, &new_bp);
if (error)
goto out_drop_pag;
/* The new buffer keeps the perag reference until it is freed. */
new_bp->b_pag = pag;
retry:
rcu_read_lock();
bp = rhashtable_lookup_get_insert_fast(&btp->bt_hash,
&new_bp->b_rhash_head, xfs_buf_hash_params);
if (IS_ERR(bp)) {
rcu_read_unlock();
error = PTR_ERR(bp);
goto out_free_buf;
}
if (bp) {
Annotation
- Immediate include surface: `xfs_platform.h`, `linux/backing-dev.h`, `linux/dax.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`.
- Detected declarations: `function xfs_buf_is_uncached`, `function xfs_buf_stale`, `function xfs_buf_free_callback`, `function xfs_buf_free`, `function xfs_buf_alloc_kmem`, `function vmalloc`, `function xfs_buf_alloc`, `function _xfs_buf_obj_cmp`, `function xfs_buf_map_verify`, `function xfs_buf_find_lock`.
- 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.