fs/xfs/xfs_trans.c
Source file repositories/reference/linux-study-clean/fs/xfs/xfs_trans.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/xfs_trans.c- Extension
.c- Size
- 39667 bytes
- Lines
- 1443
- 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_extent_busy.hxfs_quota.hxfs_trans.hxfs_trans_priv.hxfs_log.hxfs_log_priv.hxfs_trace.hxfs_error.hxfs_defer.hxfs_inode.hxfs_dquot_item.hxfs_dquot.hxfs_icache.hxfs_rtbitmap.hxfs_rtgroup.hxfs_sb.h
Detected Declarations
function xfs_trans_trace_reservationsfunction xfs_trans_initfunction xfs_trans_freefunction xfs_trans_dupfunction xfs_trans_reservefunction __xfs_trans_allocfunction xfs_trans_allocfunction xfs_trans_alloc_emptyfunction xfs_trans_mod_sbfunction xfs_trans_apply_sb_deltasfunction xfs_trans_unreserve_and_mod_sbfunction xfs_trans_add_itemfunction xfs_trans_del_itemfunction xfs_trans_free_itemsfunction list_for_each_entry_safefunction xfs_trans_precommit_sortfunction xfs_trans_run_precommitsfunction list_for_each_entry_safefunction __xfs_trans_commitfunction xfs_trans_commitfunction functionfunction xfs_trans_commitfunction xfs_trans_alloc_inodefunction xfs_trans_reserve_morefunction xfs_trans_reserve_more_inodefunction xfs_trans_alloc_icreatefunction xfs_trans_alloc_ichangefunction xfs_trans_alloc_dir
Annotated Snippet
if (error) {
error = -ENOSPC;
goto undo_log;
}
tp->t_rtx_res += rtextents;
}
return 0;
undo_log:
xfs_log_ticket_ungrant(mp->m_log, tp->t_ticket);
tp->t_ticket = NULL;
tp->t_log_res = 0;
tp->t_flags &= ~XFS_TRANS_PERM_LOG_RES;
undo_blocks:
if (blocks > 0) {
xfs_add_fdblocks(mp, blocks);
tp->t_blk_res = 0;
}
return error;
}
static struct xfs_trans *
__xfs_trans_alloc(
struct xfs_mount *mp,
uint flags)
{
struct xfs_trans *tp;
ASSERT(!(flags & XFS_TRANS_RES_FDBLKS) || xfs_has_lazysbcount(mp));
tp = kmem_cache_zalloc(xfs_trans_cache, GFP_KERNEL | __GFP_NOFAIL);
if (!(flags & XFS_TRANS_NO_WRITECOUNT))
sb_start_intwrite(mp->m_super);
xfs_trans_set_context(tp);
tp->t_flags = flags;
tp->t_mountp = mp;
INIT_LIST_HEAD(&tp->t_items);
INIT_LIST_HEAD(&tp->t_busy);
INIT_LIST_HEAD(&tp->t_dfops);
tp->t_highest_agno = NULLAGNUMBER;
return tp;
}
int
xfs_trans_alloc(
struct xfs_mount *mp,
struct xfs_trans_res *resp,
uint blocks,
uint rtextents,
uint flags,
struct xfs_trans **tpp)
{
struct xfs_trans *tp;
bool want_retry = true;
int error;
ASSERT(resp->tr_logres > 0);
/*
* Allocate the handle before we do our freeze accounting and setting up
* GFP_NOFS allocation context so that we avoid lockdep false positives
* by doing GFP_KERNEL allocations inside sb_start_intwrite().
*/
retry:
tp = __xfs_trans_alloc(mp, flags);
WARN_ON(mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE);
error = xfs_trans_reserve(tp, resp, blocks, rtextents);
if (error == -ENOSPC && want_retry) {
xfs_trans_cancel(tp);
/*
* We weren't able to reserve enough space for the transaction.
* Flush the other speculative space allocations to free space.
* Do not perform a synchronous scan because callers can hold
* other locks.
*/
error = xfs_blockgc_flush_all(mp);
if (error)
return error;
want_retry = false;
goto retry;
}
if (error) {
xfs_trans_cancel(tp);
return error;
}
trace_xfs_trans_alloc(tp, _RET_IP_);
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_extent_busy.h`.
- Detected declarations: `function xfs_trans_trace_reservations`, `function xfs_trans_init`, `function xfs_trans_free`, `function xfs_trans_dup`, `function xfs_trans_reserve`, `function __xfs_trans_alloc`, `function xfs_trans_alloc`, `function xfs_trans_alloc_empty`, `function xfs_trans_mod_sb`, `function xfs_trans_apply_sb_deltas`.
- 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.