fs/xfs/scrub/rcbag.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/rcbag.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/rcbag.c- Extension
.c- Size
- 6037 bytes
- Lines
- 308
- 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.
- 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_shared.hxfs_format.hxfs_log_format.hxfs_trans.hxfs_trans_resv.hxfs_mount.hxfs_defer.hxfs_btree.hxfs_buf_mem.hxfs_btree_mem.hxfs_error.hscrub/scrub.hscrub/rcbag_btree.hscrub/rcbag.hscrub/trace.h
Detected Declarations
struct rcbagfunction rcbag_initfunction rcbag_freefunction rcbag_addfunction rcbag_countfunction rcbag_rec_next_bnofunction rcbag_next_edgefunction rcbag_remove_ending_atfunction rcbag_dump
Annotated Snippet
struct rcbag {
struct xfs_mount *mp;
struct xfbtree xfbtree;
uint64_t nr_items;
};
int
rcbag_init(
struct xfs_mount *mp,
struct xfs_buftarg *btp,
struct rcbag **bagp)
{
struct rcbag *bag;
int error;
bag = kzalloc_obj(struct rcbag, XCHK_GFP_FLAGS);
if (!bag)
return -ENOMEM;
bag->nr_items = 0;
bag->mp = mp;
error = rcbagbt_mem_init(mp, &bag->xfbtree, btp);
if (error)
goto out_bag;
*bagp = bag;
return 0;
out_bag:
kfree(bag);
return error;
}
void
rcbag_free(
struct rcbag **bagp)
{
struct rcbag *bag = *bagp;
xfbtree_destroy(&bag->xfbtree);
kfree(bag);
*bagp = NULL;
}
/* Track an rmap in the refcount bag. */
int
rcbag_add(
struct rcbag *bag,
struct xfs_trans *tp,
const struct xfs_rmap_irec *rmap)
{
struct rcbag_rec bagrec;
struct xfs_mount *mp = bag->mp;
struct xfs_btree_cur *cur;
int has;
int error;
cur = rcbagbt_mem_cursor(mp, tp, &bag->xfbtree);
error = rcbagbt_lookup_eq(cur, rmap, &has);
if (error)
goto out_cur;
if (has) {
error = rcbagbt_get_rec(cur, &bagrec, &has);
if (error)
goto out_cur;
if (!has) {
error = -EFSCORRUPTED;
goto out_cur;
}
bagrec.rbg_refcount++;
error = rcbagbt_update(cur, &bagrec);
if (error)
goto out_cur;
} else {
bagrec.rbg_startblock = rmap->rm_startblock;
bagrec.rbg_blockcount = rmap->rm_blockcount;
bagrec.rbg_refcount = 1;
error = rcbagbt_insert(cur, &bagrec, &has);
if (error)
goto out_cur;
if (!has) {
error = -EFSCORRUPTED;
goto out_cur;
}
}
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_trans.h`, `xfs_trans_resv.h`, `xfs_mount.h`.
- Detected declarations: `struct rcbag`, `function rcbag_init`, `function rcbag_free`, `function rcbag_add`, `function rcbag_count`, `function rcbag_rec_next_bno`, `function rcbag_next_edge`, `function rcbag_remove_ending_at`, `function rcbag_dump`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
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.