fs/xfs/libxfs/xfs_rmap_btree.c
Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_rmap_btree.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/libxfs/xfs_rmap_btree.c- Extension
.c- Size
- 23664 bytes
- Lines
- 873
- 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_trans.hxfs_alloc.hxfs_btree.hxfs_btree_staging.hxfs_rmap.hxfs_rmap_btree.hxfs_health.hxfs_trace.hxfs_error.hxfs_extent_busy.hxfs_ag.hxfs_ag_resv.hxfs_buf_mem.hxfs_btree_mem.h
Detected Declarations
function typesfunction xfs_rmapbt_set_rootfunction xfs_rmapbt_alloc_blockfunction xfs_rmapbt_free_blockfunction xfs_rmapbt_get_minrecsfunction xfs_rmapbt_get_maxrecsfunction ondisk_rec_offset_to_keyfunction xfs_rmapbt_init_key_from_recfunction xfs_rmapbt_init_high_key_from_recfunction xfs_rmapbt_init_rec_from_curfunction xfs_rmapbt_init_ptr_from_curfunction offset_keymaskfunction xfs_rmapbt_cmp_key_with_curfunction xfs_rmapbt_cmp_two_keysfunction xfs_rmapbt_verifyfunction xfs_rmapbt_read_verifyfunction xfs_rmapbt_write_verifyfunction xfs_rmapbt_keys_inorderfunction xfs_rmapbt_recs_inorderfunction xfs_rmapbt_keys_contiguousfunction xfs_rmapbt_init_cursorfunction xfs_rmapbt_mem_block_maxrecsfunction xfs_rmapbt_mem_verifyfunction xfs_rmapbt_mem_rw_verifyfunction xfs_rmapbt_mem_cursorfunction xfs_rmapbt_mem_initfunction xfs_rmapbt_mem_maxlevelsfunction xfs_rmapbt_commit_staged_btreefunction xfs_rmapbt_block_maxrecsfunction xfs_rmapbt_maxrecsfunction xfs_rmapbt_maxlevels_ondiskfunction xfs_rmapbt_compute_maxlevelsfunction xfs_rmapbt_calc_sizefunction xfs_rmapbt_max_sizefunction xfs_rmapbt_calc_reservesfunction xfs_rmapbt_init_cur_cachefunction xfs_rmapbt_destroy_cur_cache
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2014 Red Hat, Inc.
* All Rights Reserved.
*/
#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_trans.h"
#include "xfs_alloc.h"
#include "xfs_btree.h"
#include "xfs_btree_staging.h"
#include "xfs_rmap.h"
#include "xfs_rmap_btree.h"
#include "xfs_health.h"
#include "xfs_trace.h"
#include "xfs_error.h"
#include "xfs_extent_busy.h"
#include "xfs_ag.h"
#include "xfs_ag_resv.h"
#include "xfs_buf_mem.h"
#include "xfs_btree_mem.h"
static struct kmem_cache *xfs_rmapbt_cur_cache;
/*
* Reverse map btree.
*
* This is a per-ag tree used to track the owner(s) of a given extent. With
* reflink it is possible for there to be multiple owners, which is a departure
* from classic XFS. Owner records for data extents are inserted when the
* extent is mapped and removed when an extent is unmapped. Owner records for
* all other block types (i.e. metadata) are inserted when an extent is
* allocated and removed when an extent is freed. There can only be one owner
* of a metadata extent, usually an inode or some other metadata structure like
* an AG btree.
*
* The rmap btree is part of the free space management, so blocks for the tree
* are sourced from the agfl. Hence we need transaction reservation support for
* this tree so that the freelist is always large enough. This also impacts on
* the minimum space we need to leave free in the AG.
*
* The tree is ordered by [ag block, owner, offset]. This is a large key size,
* but it is the only way to enforce unique keys when a block can be owned by
* multiple files at any offset. There's no need to order/search by extent
* size for online updating/management of the tree. It is intended that most
* reverse lookups will be to find the owner(s) of a particular block, or to
* try to recover tree and file data from corrupt primary metadata.
*/
static struct xfs_btree_cur *
xfs_rmapbt_dup_cursor(
struct xfs_btree_cur *cur)
{
return xfs_rmapbt_init_cursor(cur->bc_mp, cur->bc_tp,
cur->bc_ag.agbp, to_perag(cur->bc_group));
}
STATIC void
xfs_rmapbt_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 = to_perag(cur->bc_group);
ASSERT(ptr->s != 0);
agf->agf_rmap_root = ptr->s;
be32_add_cpu(&agf->agf_rmap_level, inc);
pag->pagf_rmap_level += inc;
xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_ROOTS | XFS_AGF_LEVELS);
}
STATIC int
xfs_rmapbt_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;
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_trans.h`.
- Detected declarations: `function types`, `function xfs_rmapbt_set_root`, `function xfs_rmapbt_alloc_block`, `function xfs_rmapbt_free_block`, `function xfs_rmapbt_get_minrecs`, `function xfs_rmapbt_get_maxrecs`, `function ondisk_rec_offset_to_key`, `function xfs_rmapbt_init_key_from_rec`, `function xfs_rmapbt_init_high_key_from_rec`, `function xfs_rmapbt_init_rec_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.