fs/xfs/libxfs/xfs_rmap.c
Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_rmap.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/libxfs/xfs_rmap.c- Extension
.c- Size
- 83489 bytes
- Lines
- 3143
- 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_bit.hxfs_mount.hxfs_sb.hxfs_defer.hxfs_btree.hxfs_trans.hxfs_alloc.hxfs_rmap.hxfs_rmap_btree.hxfs_trace.hxfs_errortag.hxfs_error.hxfs_inode.hxfs_ag.hxfs_health.hxfs_rmap_item.hxfs_rtgroup.hxfs_rtrmap_btree.h
Detected Declarations
struct xfs_find_left_neighbor_infostruct xfs_rmap_query_range_infostruct xfs_rmap_ownercountfunction xfs_rmap_lookup_lefunction xfs_rmap_lookup_eqfunction worksfunction xfs_rmap_insertfunction xfs_rmap_deletefunction xfs_rmap_btrec_to_irecfunction xfs_rmap_check_irecfunction xfs_rtrmap_check_meta_irecfunction xfs_rtrmap_check_inode_irecfunction xfs_rtrmap_check_irecfunction xfs_rmap_check_btrecfunction xfs_rmap_complain_bad_recfunction xfs_rmap_get_recfunction xfs_rmap_find_left_neighbor_helperfunction xfs_rmap_find_left_neighborfunction xfs_rmap_lookup_le_range_helperfunction xfs_rmap_lookup_le_rangefunction xfs_rmap_free_check_ownerfunction ownerfunction xfs_rmap_hook_disablefunction xfs_rmap_hook_enablefunction xfs_rmap_update_hookfunction xfs_rmap_hook_addfunction xfs_rmap_hook_delfunction xfs_rmap_hook_setupfunction xfs_rmap_freefunction xfs_rmap_is_mergeablefunction xfs_rmap_mapfunction xfs_rmap_allocfunction xfs_rmap_convertfunction xfs_rmap_convert_sharedfunction overlapfunction overlapfunction xfs_rmap_map_rawfunction xfs_rmap_query_range_helperfunction xfs_rmap_query_rangefunction xfs_rmap_query_allfunction __xfs_rmap_finish_intentfunction xfs_rmap_finish_init_cursorfunction xfs_rtrmap_finish_init_cursorfunction xfs_rmap_finish_onefunction xfs_rmap_update_is_neededfunction __xfs_rmap_addfunction xfs_rmap_map_extentfunction xfs_rmap_unmap_extent
Annotated Snippet
struct xfs_find_left_neighbor_info {
struct xfs_rmap_irec high;
struct xfs_rmap_irec *irec;
};
/* For each rmap given, figure out if it matches the key we want. */
STATIC int
xfs_rmap_find_left_neighbor_helper(
struct xfs_btree_cur *cur,
const struct xfs_rmap_irec *rec,
void *priv)
{
struct xfs_find_left_neighbor_info *info = priv;
trace_xfs_rmap_find_left_neighbor_candidate(cur, rec->rm_startblock,
rec->rm_blockcount, rec->rm_owner, rec->rm_offset,
rec->rm_flags);
if (rec->rm_owner != info->high.rm_owner)
return 0;
if (!XFS_RMAP_NON_INODE_OWNER(rec->rm_owner) &&
!(rec->rm_flags & XFS_RMAP_BMBT_BLOCK) &&
rec->rm_offset + rec->rm_blockcount - 1 != info->high.rm_offset)
return 0;
*info->irec = *rec;
return -ECANCELED;
}
/*
* Find the record to the left of the given extent, being careful only to
* return a match with the same owner and adjacent physical and logical
* block ranges.
*/
STATIC int
xfs_rmap_find_left_neighbor(
struct xfs_btree_cur *cur,
xfs_agblock_t bno,
uint64_t owner,
uint64_t offset,
unsigned int flags,
struct xfs_rmap_irec *irec,
int *stat)
{
struct xfs_find_left_neighbor_info info;
int found = 0;
int error;
*stat = 0;
if (bno == 0)
return 0;
info.high.rm_startblock = bno - 1;
info.high.rm_owner = owner;
if (!XFS_RMAP_NON_INODE_OWNER(owner) &&
!(flags & XFS_RMAP_BMBT_BLOCK)) {
if (offset == 0)
return 0;
info.high.rm_offset = offset - 1;
} else
info.high.rm_offset = 0;
info.high.rm_flags = flags;
info.high.rm_blockcount = 0;
info.irec = irec;
trace_xfs_rmap_find_left_neighbor_query(cur, bno, 0, owner, offset,
flags);
/*
* Historically, we always used the range query to walk every reverse
* mapping that could possibly overlap the key that the caller asked
* for, and filter out the ones that don't. That is very slow when
* there are a lot of records.
*
* However, there are two scenarios where the classic btree search can
* produce correct results -- if the index contains a record that is an
* exact match for the lookup key; and if there are no other records
* between the record we want and the key we supplied.
*
* As an optimization, try a non-overlapped lookup first. This makes
* extent conversion and remap operations run a bit faster if the
* physical extents aren't being shared. If we don't find what we
* want, we fall back to the overlapped query.
*/
error = xfs_rmap_lookup_le(cur, bno, owner, offset, flags, irec,
&found);
if (error)
return error;
if (found)
error = xfs_rmap_find_left_neighbor_helper(cur, irec, &info);
if (!error)
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_bit.h`, `xfs_mount.h`.
- Detected declarations: `struct xfs_find_left_neighbor_info`, `struct xfs_rmap_query_range_info`, `struct xfs_rmap_ownercount`, `function xfs_rmap_lookup_le`, `function xfs_rmap_lookup_eq`, `function works`, `function xfs_rmap_insert`, `function xfs_rmap_delete`, `function xfs_rmap_btrec_to_irec`, `function xfs_rmap_check_irec`.
- 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.