fs/xfs/libxfs/xfs_refcount_btree.c
Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_refcount_btree.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/libxfs/xfs_refcount_btree.c- Extension
.c- Size
- 13498 bytes
- Lines
- 544
- 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.
- 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_resv.hxfs_mount.hxfs_btree.hxfs_btree_staging.hxfs_refcount_btree.hxfs_refcount.hxfs_alloc.hxfs_error.hxfs_health.hxfs_trace.hxfs_trans.hxfs_bit.hxfs_rmap.hxfs_ag.h
Detected Declarations
function xfs_refcountbt_dup_cursorfunction xfs_refcountbt_set_rootfunction xfs_refcountbt_alloc_blockfunction xfs_refcountbt_free_blockfunction xfs_refcountbt_get_minrecsfunction xfs_refcountbt_get_maxrecsfunction xfs_refcountbt_init_key_from_recfunction xfs_refcountbt_init_high_key_from_recfunction xfs_refcountbt_init_rec_from_curfunction xfs_refcountbt_init_ptr_from_curfunction xfs_refcountbt_cmp_key_with_curfunction xfs_refcountbt_cmp_two_keysfunction xfs_refcountbt_verifyfunction xfs_refcountbt_read_verifyfunction xfs_refcountbt_write_verifyfunction xfs_refcountbt_keys_inorderfunction xfs_refcountbt_recs_inorderfunction xfs_refcountbt_keys_contiguousfunction xfs_refcountbt_init_cursorfunction xfs_refcountbt_commit_staged_btreefunction xfs_refcountbt_block_maxrecsfunction xfs_refcountbt_maxrecsfunction xfs_refcountbt_maxlevels_ondiskfunction xfs_refcountbt_compute_maxlevelsfunction xfs_refcountbt_calc_sizefunction xfs_refcountbt_max_sizefunction xfs_refcountbt_calc_reservesfunction xfs_refcountbt_init_cur_cachefunction xfs_refcountbt_destroy_cur_cache
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2016 Oracle. All Rights Reserved.
* Author: Darrick J. Wong <darrick.wong@oracle.com>
*/
#include "xfs_platform.h"
#include "xfs_fs.h"
#include "xfs_shared.h"
#include "xfs_format.h"
#include "xfs_log_format.h"
#include "xfs_trans_resv.h"
#include "xfs_mount.h"
#include "xfs_btree.h"
#include "xfs_btree_staging.h"
#include "xfs_refcount_btree.h"
#include "xfs_refcount.h"
#include "xfs_alloc.h"
#include "xfs_error.h"
#include "xfs_health.h"
#include "xfs_trace.h"
#include "xfs_trans.h"
#include "xfs_bit.h"
#include "xfs_rmap.h"
#include "xfs_ag.h"
static struct kmem_cache *xfs_refcountbt_cur_cache;
static struct xfs_btree_cur *
xfs_refcountbt_dup_cursor(
struct xfs_btree_cur *cur)
{
return xfs_refcountbt_init_cursor(cur->bc_mp, cur->bc_tp,
cur->bc_ag.agbp, to_perag(cur->bc_group));
}
STATIC void
xfs_refcountbt_set_root(
struct xfs_btree_cur *cur,
const union xfs_btree_ptr *ptr,
int inc)
{
struct xfs_buf *agbp = cur->bc_ag.agbp;
struct xfs_agf *agf = agbp->b_addr;
struct xfs_perag *pag = agbp->b_pag;
ASSERT(ptr->s != 0);
agf->agf_refcount_root = ptr->s;
be32_add_cpu(&agf->agf_refcount_level, inc);
pag->pagf_refcount_level += inc;
xfs_alloc_log_agf(cur->bc_tp, agbp,
XFS_AGF_REFCOUNT_ROOT | XFS_AGF_REFCOUNT_LEVEL);
}
STATIC int
xfs_refcountbt_alloc_block(
struct xfs_btree_cur *cur,
const union xfs_btree_ptr *start,
union xfs_btree_ptr *new,
int *stat)
{
struct xfs_buf *agbp = cur->bc_ag.agbp;
struct xfs_agf *agf = agbp->b_addr;
struct xfs_alloc_arg args; /* block allocation args */
int error; /* error return value */
memset(&args, 0, sizeof(args));
args.tp = cur->bc_tp;
args.mp = cur->bc_mp;
args.pag = to_perag(cur->bc_group);
args.oinfo = XFS_RMAP_OINFO_REFC;
args.minlen = args.maxlen = args.prod = 1;
args.resv = XFS_AG_RESV_METADATA;
error = xfs_alloc_vextent_near_bno(&args,
xfs_agbno_to_fsb(args.pag, xfs_refc_block(args.mp)));
if (error)
goto out_error;
if (args.fsbno == NULLFSBLOCK) {
*stat = 0;
return 0;
}
ASSERT(args.agno == cur->bc_group->xg_gno);
ASSERT(args.len == 1);
new->s = cpu_to_be32(args.agbno);
be32_add_cpu(&agf->agf_refcount_blocks, 1);
xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_REFCOUNT_BLOCKS);
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_btree.h`.
- Detected declarations: `function xfs_refcountbt_dup_cursor`, `function xfs_refcountbt_set_root`, `function xfs_refcountbt_alloc_block`, `function xfs_refcountbt_free_block`, `function xfs_refcountbt_get_minrecs`, `function xfs_refcountbt_get_maxrecs`, `function xfs_refcountbt_init_key_from_rec`, `function xfs_refcountbt_init_high_key_from_rec`, `function xfs_refcountbt_init_rec_from_cur`, `function xfs_refcountbt_init_ptr_from_cur`.
- 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.