fs/xfs/xfs_extent_busy.c
Source file repositories/reference/linux-study-clean/fs/xfs/xfs_extent_busy.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/xfs_extent_busy.c- Extension
.c- Size
- 18559 bytes
- Lines
- 728
- 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.hxfs_fs.hxfs_format.hxfs_log_format.hxfs_shared.hxfs_trans_resv.hxfs_mount.hxfs_alloc.hxfs_extent_busy.hxfs_trace.hxfs_trans.hxfs_log.hxfs_ag.hxfs_rtgroup.h
Detected Declarations
struct xfs_extent_busy_treefunction xfs_extent_busy_insert_listfunction xfs_extent_busy_insertfunction xfs_extent_busy_insert_discardfunction xfs_extent_busy_searchfunction xfs_extent_busy_update_extentfunction xfs_extent_busy_reusefunction xfs_extent_busy_trimfunction xfs_extent_busy_clear_onefunction xfs_extent_busy_clearfunction xfs_extent_busy_flushfunction xfs_extent_busy_wait_groupfunction xfs_extent_busy_wait_allfunction xfs_extent_busy_ag_cmpfunction xfs_extent_busy_list_emptyfunction xfs_extent_busy_alloc
Annotated Snippet
struct xfs_extent_busy_tree {
spinlock_t eb_lock;
struct rb_root eb_tree;
unsigned int eb_gen;
wait_queue_head_t eb_wait;
};
static void
xfs_extent_busy_insert_list(
struct xfs_group *xg,
xfs_agblock_t bno,
xfs_extlen_t len,
unsigned int flags,
struct list_head *busy_list)
{
struct xfs_extent_busy_tree *eb = xg->xg_busy_extents;
struct xfs_extent_busy *new;
struct xfs_extent_busy *busyp;
struct rb_node **rbp;
struct rb_node *parent = NULL;
new = kzalloc_obj(struct xfs_extent_busy, GFP_KERNEL | __GFP_NOFAIL);
new->group = xfs_group_hold(xg);
new->bno = bno;
new->length = len;
INIT_LIST_HEAD(&new->list);
new->flags = flags;
/* trace before insert to be able to see failed inserts */
trace_xfs_extent_busy(xg, bno, len);
spin_lock(&eb->eb_lock);
rbp = &eb->eb_tree.rb_node;
while (*rbp) {
parent = *rbp;
busyp = rb_entry(parent, struct xfs_extent_busy, rb_node);
if (new->bno < busyp->bno) {
rbp = &(*rbp)->rb_left;
ASSERT(new->bno + new->length <= busyp->bno);
} else if (new->bno > busyp->bno) {
rbp = &(*rbp)->rb_right;
ASSERT(bno >= busyp->bno + busyp->length);
} else {
ASSERT(0);
}
}
rb_link_node(&new->rb_node, parent, rbp);
rb_insert_color(&new->rb_node, &eb->eb_tree);
/* always process discard lists in fifo order */
list_add_tail(&new->list, busy_list);
spin_unlock(&eb->eb_lock);
}
void
xfs_extent_busy_insert(
struct xfs_trans *tp,
struct xfs_group *xg,
xfs_agblock_t bno,
xfs_extlen_t len,
unsigned int flags)
{
xfs_extent_busy_insert_list(xg, bno, len, flags, &tp->t_busy);
}
void
xfs_extent_busy_insert_discard(
struct xfs_group *xg,
xfs_agblock_t bno,
xfs_extlen_t len,
struct list_head *busy_list)
{
xfs_extent_busy_insert_list(xg, bno, len, XFS_EXTENT_BUSY_DISCARDED,
busy_list);
}
/*
* Search for a busy extent within the range of the extent we are about to
* allocate. You need to be holding the busy extent tree lock when calling
* xfs_extent_busy_search(). This function returns 0 for no overlapping busy
* extent, -1 for an overlapping but not exact busy extent, and 1 for an exact
* match. This is done so that a non-zero return indicates an overlap that
* will require a synchronous transaction, but it can still be
* used to distinguish between a partial or exact match.
*/
int
xfs_extent_busy_search(
struct xfs_group *xg,
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_shared.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_alloc.h`.
- Detected declarations: `struct xfs_extent_busy_tree`, `function xfs_extent_busy_insert_list`, `function xfs_extent_busy_insert`, `function xfs_extent_busy_insert_discard`, `function xfs_extent_busy_search`, `function xfs_extent_busy_update_extent`, `function xfs_extent_busy_reuse`, `function xfs_extent_busy_trim`, `function xfs_extent_busy_clear_one`, `function xfs_extent_busy_clear`.
- 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.