fs/xfs/xfs_reflink.c
Source file repositories/reference/linux-study-clean/fs/xfs/xfs_reflink.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/xfs_reflink.c- Extension
.c- Size
- 55611 bytes
- Lines
- 1929
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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_bmap_util.hxfs_trace.hxfs_icache.hxfs_btree.hxfs_refcount_btree.hxfs_refcount.hxfs_bmap_btree.hxfs_trans_space.hxfs_bit.hxfs_alloc.hxfs_quota.hxfs_reflink.hxfs_iomap.hxfs_ag.hxfs_ag_resv.hxfs_health.hxfs_rtrefcount_btree.hxfs_rtalloc.hxfs_rtgroup.hxfs_metafile.h
Detected Declarations
function xfs_reflink_find_sharedfunction xfs_reflink_find_rtsharedfunction xfs_reflink_trim_around_sharedfunction xfs_bmap_trim_cowfunction xfs_reflink_convert_cow_lockedfunction xfs_reflink_convert_cowfunction xfs_find_trim_cow_extentfunction xfs_reflink_convert_unwrittenfunction xfs_reflink_fill_cow_holefunction xfs_reflink_fill_delallocfunction xfs_reflink_allocate_cowfunction xfs_reflink_cancel_cow_blocksfunction xfs_reflink_cancel_cow_rangefunction xfs_reflink_update_quotafunction xfs_reflink_end_cow_extent_lockedfunction xfs_reflink_end_cow_extentfunction xfs_reflink_end_cowfunction xfs_reflink_end_atomic_cowfunction xfs_reflink_max_atomic_cowfunction xfs_reflink_recover_cowfunction Reflinkingfunction xfs_reflink_update_destfunction xfs_reflink_ag_has_free_spacefunction xfs_reflink_remap_extentfunction xfs_reflink_remap_blocksfunction xfs_reflink_zero_posteoffunction xfs_reflink_remap_prepfunction xfs_reflink_inode_has_shared_extentsfunction xfs_reflink_clear_inode_flagfunction xfs_reflink_try_clear_inode_flagfunction xfs_reflink_unsharefunction xfs_reflink_supports_rextsize
Annotated Snippet
if (found) {
xfs_trans_cancel(tp);
break;
}
ASSERT(isnullstartblock(cmap->br_startblock) ||
cmap->br_startblock == DELAYSTARTBLOCK);
/*
* Replace delalloc reservation with an unwritten extent.
*/
nimaps = 1;
error = xfs_bmapi_write(tp, ip, cmap->br_startoff,
cmap->br_blockcount,
XFS_BMAPI_COWFORK | XFS_BMAPI_PREALLOC, 0,
cmap, &nimaps);
if (error)
goto out_trans_cancel;
xfs_inode_set_cowblocks_tag(ip);
error = xfs_trans_commit(tp);
if (error)
return error;
} while (cmap->br_startoff + cmap->br_blockcount <= imap->br_startoff);
return xfs_reflink_convert_unwritten(ip, imap, cmap, convert_now);
out_trans_cancel:
xfs_trans_cancel(tp);
return error;
}
/* Allocate all CoW reservations covering a range of blocks in a file. */
int
xfs_reflink_allocate_cow(
struct xfs_inode *ip,
struct xfs_bmbt_irec *imap,
struct xfs_bmbt_irec *cmap,
bool *shared,
uint *lockmode,
bool convert_now)
{
int error;
bool found;
xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
if (!ip->i_cowfp) {
ASSERT(!xfs_is_reflink_inode(ip));
xfs_ifork_init_cow(ip);
}
error = xfs_find_trim_cow_extent(ip, imap, cmap, shared, &found);
if (error || !*shared)
return error;
/* CoW fork has a real extent */
if (found)
return xfs_reflink_convert_unwritten(ip, imap, cmap,
convert_now);
/*
* CoW fork does not have an extent and data extent is shared.
* Allocate a real extent in the CoW fork.
*/
if (cmap->br_startoff > imap->br_startoff)
return xfs_reflink_fill_cow_hole(ip, imap, cmap, shared,
lockmode, convert_now);
/*
* CoW fork has a delalloc reservation. Replace it with a real extent.
* There may or may not be a data fork mapping.
*/
if (isnullstartblock(cmap->br_startblock) ||
cmap->br_startblock == DELAYSTARTBLOCK)
return xfs_reflink_fill_delalloc(ip, imap, cmap, shared,
lockmode, convert_now);
/* Shouldn't get here. */
ASSERT(0);
return -EFSCORRUPTED;
}
/*
* Cancel CoW reservations for some block range of an inode.
*
* If cancel_real is true this function cancels all COW fork extents for the
* inode; if cancel_real is false, real extents are not cleared.
*
* Caller must have already joined the inode to the current transaction. The
* inode will be joined to the transaction returned to the caller.
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: `function xfs_reflink_find_shared`, `function xfs_reflink_find_rtshared`, `function xfs_reflink_trim_around_shared`, `function xfs_bmap_trim_cow`, `function xfs_reflink_convert_cow_locked`, `function xfs_reflink_convert_cow`, `function xfs_find_trim_cow_extent`, `function xfs_reflink_convert_unwritten`, `function xfs_reflink_fill_cow_hole`, `function xfs_reflink_fill_delalloc`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.