fs/jbd2/transaction.c
Source file repositories/reference/linux-study-clean/fs/jbd2/transaction.c
File Facts
- System
- Linux kernel
- Corpus path
fs/jbd2/transaction.c- Extension
.c- Size
- 89905 bytes
- Lines
- 2837
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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
linux/time.hlinux/fs.hlinux/jbd2.hlinux/errno.hlinux/slab.hlinux/timer.hlinux/mm.hlinux/highmem.hlinux/hrtimer.hlinux/backing-dev.hlinux/bug.hlinux/module.hlinux/sched/mm.htrace/events/jbd2.h
Detected Declarations
function jbd2_journal_init_transaction_cachefunction jbd2_journal_destroy_transaction_cachefunction jbd2_journal_free_transactionfunction journalfunction update_t_max_waitfunction wait_transaction_lockedfunction wait_transaction_switchingfunction sub_reserved_creditsfunction jbd2_max_user_trans_buffersfunction add_transaction_creditsfunction start_this_handlefunction jbd2_journal_startfunction __jbd2_journal_unreserve_handlefunction jbd2_journal_free_reservedfunction jbd2_journal_start_reservedfunction jbd2_journal_extendfunction stop_this_handlefunction jbd2__journal_restartfunction jbd2_journal_restartfunction jbd2_journal_wait_updatesfunction jbd2_journal_lock_updatesfunction jbd2_journal_unlock_updatesfunction warn_dirty_bufferfunction jbd2_freeze_jh_datafunction do_get_write_accessfunction statefunction stagefunction jbd2_write_access_grantedfunction jbd2_journal_get_write_accessfunction jbd2_journal_get_create_accessfunction jbd2_journal_get_undo_accessfunction jbd2_journal_set_triggersfunction jbd2_buffer_frozen_triggerfunction jbd2_buffer_abort_triggerfunction jbd2_journal_dirty_metadatafunction jbd2_journal_forgetfunction jbd2_journal_stopfunction time_after_eqfunction __blist_add_bufferfunction __blist_del_bufferfunction __jbd2_journal_temp_unlink_bufferfunction __jbd2_journal_unfile_bufferfunction jbd2_journal_try_to_free_buffersfunction bufferfunction transactionfunction jbd2_journal_invalidate_foliofunction __jbd2_journal_file_bufferfunction jbd2_journal_file_buffer
Annotated Snippet
jbd2_max_user_trans_buffers(journal)) {
read_unlock(&journal->j_state_lock);
jbd2_might_wait_for_commit(journal);
wait_event(journal->j_wait_reserved,
atomic_read(&journal->j_reserved_credits) + total <=
jbd2_max_user_trans_buffers(journal));
__acquire(&journal->j_state_lock); /* fake out sparse */
return 1;
}
wait_transaction_locked(journal);
__acquire(&journal->j_state_lock); /* fake out sparse */
return 1;
}
/*
* The commit code assumes that it can get enough log space
* without forcing a checkpoint. This is *critical* for
* correctness: a checkpoint of a buffer which is also
* associated with a committing transaction creates a deadlock,
* so commit simply cannot force through checkpoints.
*
* We must therefore ensure the necessary space in the journal
* *before* starting to dirty potentially checkpointed buffers
* in the new transaction.
*/
if (jbd2_log_space_left(journal) < journal->j_max_transaction_buffers) {
atomic_sub(total, &t->t_outstanding_credits);
read_unlock(&journal->j_state_lock);
jbd2_might_wait_for_commit(journal);
write_lock(&journal->j_state_lock);
if (jbd2_log_space_left(journal) <
journal->j_max_transaction_buffers)
__jbd2_log_wait_for_space(journal);
write_unlock(&journal->j_state_lock);
__acquire(&journal->j_state_lock); /* fake out sparse */
return 1;
}
/* No reservation? We are done... */
if (!rsv_blocks)
return 0;
needed = atomic_add_return(rsv_blocks, &journal->j_reserved_credits);
/* We allow at most half of a transaction to be reserved */
if (needed > jbd2_max_user_trans_buffers(journal) / 2) {
sub_reserved_credits(journal, rsv_blocks);
atomic_sub(total, &t->t_outstanding_credits);
read_unlock(&journal->j_state_lock);
jbd2_might_wait_for_commit(journal);
wait_event(journal->j_wait_reserved,
atomic_read(&journal->j_reserved_credits) + rsv_blocks
<= jbd2_max_user_trans_buffers(journal) / 2);
__acquire(&journal->j_state_lock); /* fake out sparse */
return 1;
}
return 0;
}
/*
* start_this_handle: Given a handle, deal with any locking or stalling
* needed to make sure that there is enough journal space for the handle
* to begin. Attach the handle to a transaction and set up the
* transaction's buffer credits.
*/
static int start_this_handle(journal_t *journal, handle_t *handle,
gfp_t gfp_mask)
{
transaction_t *transaction, *new_transaction = NULL;
int blocks = handle->h_total_credits;
int rsv_blocks = 0;
unsigned long ts = jiffies;
if (handle->h_rsv_handle)
rsv_blocks = handle->h_rsv_handle->h_total_credits;
/*
* Limit the number of reserved credits to 1/2 of maximum transaction
* size and limit the number of total credits to not exceed maximum
* transaction size per operation.
*/
if (rsv_blocks > jbd2_max_user_trans_buffers(journal) / 2 ||
rsv_blocks + blocks > jbd2_max_user_trans_buffers(journal)) {
printk(KERN_ERR "JBD2: %s wants too many credits "
"credits:%d rsv_credits:%d max:%d\n",
current->comm, blocks, rsv_blocks,
jbd2_max_user_trans_buffers(journal));
WARN_ON(1);
return -ENOSPC;
Annotation
- Immediate include surface: `linux/time.h`, `linux/fs.h`, `linux/jbd2.h`, `linux/errno.h`, `linux/slab.h`, `linux/timer.h`, `linux/mm.h`, `linux/highmem.h`.
- Detected declarations: `function jbd2_journal_init_transaction_cache`, `function jbd2_journal_destroy_transaction_cache`, `function jbd2_journal_free_transaction`, `function journal`, `function update_t_max_wait`, `function wait_transaction_locked`, `function wait_transaction_switching`, `function sub_reserved_credits`, `function jbd2_max_user_trans_buffers`, `function add_transaction_credits`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration 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.