fs/xfs/libxfs/xfs_exchmaps.c
Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_exchmaps.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/libxfs/xfs_exchmaps.c- Extension
.c- Size
- 34347 bytes
- Lines
- 1238
- 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_resv.hxfs_mount.hxfs_defer.hxfs_inode.hxfs_trans.hxfs_bmap.hxfs_icache.hxfs_quota.hxfs_exchmaps.hxfs_trace.hxfs_bmap_btree.hxfs_trans_space.hxfs_error.hxfs_errortag.hxfs_health.hxfs_exchmaps_item.hxfs_da_format.hxfs_da_btree.hxfs_attr_leaf.hxfs_attr.hxfs_dir2_priv.hxfs_dir2.hxfs_symlink_remote.h
Detected Declarations
struct xfs_exchmaps_adjacentfunction xfs_exchmaps_ensure_cowforkfunction xfs_exchmaps_update_sizefunction xmi_advancefunction xmi_has_more_exchange_workfunction xmi_has_postop_workfunction xfs_exchmaps_check_forksfunction xfs_exchmaps_update_quotafunction xfs_exchmaps_can_skip_mappingfunction xfs_exchmaps_find_mappingsfunction xfs_exchmaps_one_stepfunction xfs_exchmaps_attr_to_sffunction xfs_exchmaps_dir_to_sffunction xfs_exchmaps_link_to_sffunction xfs_exchmaps_clear_reflinkfunction xfs_exchmaps_do_postop_workfunction xfs_exchmaps_finish_onefunction xfs_exchmaps_bmbt_blocksfunction xfs_exchmaps_rmapbt_blocksfunction xfs_exchmaps_estimate_overheadfunction xmi_can_mergefunction xmi_can_merge_allfunction xmi_delta_nextents_stepfunction xmi_ensure_delta_nextentsfunction xmi_nextfunction xfs_exchmaps_intent_init_cachefunction xfs_exchmaps_intent_destroy_cachefunction xmi_can_exchange_reflink_flagsfunction xfs_exchmaps_init_intentfunction xfs_exchmaps_estimatefunction xfs_exchmaps_reqforkfunction xfs_exchmaps_set_reflinkfunction xfs_exchmaps_ensure_reflinkfunction xfs_exchmaps_ensure_large_extent_countsfunction xfs_exchmaps_upgrade_extent_countsfunction xfs_exchange_mappings
Annotated Snippet
struct xfs_exchmaps_adjacent {
struct xfs_bmbt_irec left1;
struct xfs_bmbt_irec right1;
struct xfs_bmbt_irec left2;
struct xfs_bmbt_irec right2;
};
#define ADJACENT_INIT { \
.left1 = { .br_startblock = HOLESTARTBLOCK }, \
.right1 = { .br_startblock = HOLESTARTBLOCK }, \
.left2 = { .br_startblock = HOLESTARTBLOCK }, \
.right2 = { .br_startblock = HOLESTARTBLOCK }, \
}
/* Information to reset reflink flag / CoW fork state after an exchange. */
/*
* If the reflink flag is set on either inode, make sure it has an incore CoW
* fork, since all reflink inodes must have them. If there's a CoW fork and it
* has mappings in it, make sure the inodes are tagged appropriately so that
* speculative preallocations can be GC'd if we run low of space.
*/
static inline void
xfs_exchmaps_ensure_cowfork(
struct xfs_inode *ip)
{
struct xfs_ifork *cfork;
if (xfs_is_reflink_inode(ip))
xfs_ifork_init_cow(ip);
cfork = xfs_ifork_ptr(ip, XFS_COW_FORK);
if (!cfork)
return;
if (cfork->if_bytes > 0)
xfs_inode_set_cowblocks_tag(ip);
else
xfs_inode_clear_cowblocks_tag(ip);
}
/*
* Adjust the on-disk inode size upwards if needed so that we never add
* mappings into the file past EOF. This is crucial so that log recovery won't
* get confused by the sudden appearance of post-eof mappings.
*/
STATIC void
xfs_exchmaps_update_size(
struct xfs_trans *tp,
struct xfs_inode *ip,
struct xfs_bmbt_irec *imap,
xfs_fsize_t new_isize)
{
struct xfs_mount *mp = tp->t_mountp;
xfs_fsize_t len;
if (new_isize < 0)
return;
len = min(XFS_FSB_TO_B(mp, imap->br_startoff + imap->br_blockcount),
new_isize);
if (len <= ip->i_disk_size)
return;
trace_xfs_exchmaps_update_inode_size(ip, len);
ip->i_disk_size = len;
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
}
/* Advance the incore state tracking after exchanging a mapping. */
static inline void
xmi_advance(
struct xfs_exchmaps_intent *xmi,
const struct xfs_bmbt_irec *irec)
{
xmi->xmi_startoff1 += irec->br_blockcount;
xmi->xmi_startoff2 += irec->br_blockcount;
xmi->xmi_blockcount -= irec->br_blockcount;
}
/* Do we still have more mappings to exchange? */
static inline bool
xmi_has_more_exchange_work(const struct xfs_exchmaps_intent *xmi)
{
return xmi->xmi_blockcount > 0;
}
/* Do we have post-operation cleanups to perform? */
static inline bool
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_defer.h`.
- Detected declarations: `struct xfs_exchmaps_adjacent`, `function xfs_exchmaps_ensure_cowfork`, `function xfs_exchmaps_update_size`, `function xmi_advance`, `function xmi_has_more_exchange_work`, `function xmi_has_postop_work`, `function xfs_exchmaps_check_forks`, `function xfs_exchmaps_update_quota`, `function xfs_exchmaps_can_skip_mapping`, `function xfs_exchmaps_find_mappings`.
- 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.