fs/jbd2/checkpoint.c
Source file repositories/reference/linux-study-clean/fs/jbd2/checkpoint.c
File Facts
- System
- Linux kernel
- Corpus path
fs/jbd2/checkpoint.c- Extension
.c- Size
- 21518 bytes
- Lines
- 730
- 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
linux/time.hlinux/fs.hlinux/jbd2.hlinux/errno.hlinux/slab.hlinux/blkdev.htrace/events/jbd2.h
Detected Declarations
function __buffer_unlinkfunction __jbd2_log_wait_for_spacefunction __flush_batchfunction jbd2_log_do_checkpointfunction jbd2_cleanup_journal_tailfunction journal_shrink_one_cp_listfunction jbd2_journal_shrink_checkpoint_listfunction __jbd2_journal_clean_checkpoint_listfunction jbd2_journal_destroy_checkpointfunction diskfunction jbd2_journal_try_remove_checkpointfunction __jbd2_journal_insert_checkpointfunction __jbd2_journal_drop_transaction
Annotated Snippet
if (journal->j_flags & JBD2_ABORT) {
mutex_unlock(&journal->j_checkpoint_mutex);
return;
}
spin_lock(&journal->j_list_lock);
space_left = jbd2_log_space_left(journal);
if (space_left < nblocks) {
int chkpt = journal->j_checkpoint_transactions != NULL;
tid_t tid = 0;
bool has_transaction = false;
if (journal->j_committing_transaction) {
tid = journal->j_committing_transaction->t_tid;
has_transaction = true;
}
spin_unlock(&journal->j_list_lock);
write_unlock(&journal->j_state_lock);
if (chkpt) {
jbd2_log_do_checkpoint(journal);
} else if (jbd2_cleanup_journal_tail(journal) <= 0) {
/*
* We were able to recover space or the
* journal was aborted due to an error.
*/
;
} else if (has_transaction) {
/*
* jbd2_journal_commit_transaction() may want
* to take the checkpoint_mutex if JBD2_FLUSHED
* is set. So we need to temporarily drop it.
*/
mutex_unlock(&journal->j_checkpoint_mutex);
jbd2_log_wait_commit(journal, tid);
write_lock(&journal->j_state_lock);
continue;
} else {
printk(KERN_ERR "%s: needed %d blocks and "
"only had %d space available\n",
__func__, nblocks, space_left);
printk(KERN_ERR "%s: no way to get more "
"journal space in %s\n", __func__,
journal->j_devname);
WARN_ON(1);
jbd2_journal_abort(journal, -ENOSPC);
}
write_lock(&journal->j_state_lock);
} else {
spin_unlock(&journal->j_list_lock);
}
mutex_unlock(&journal->j_checkpoint_mutex);
}
}
static void
__flush_batch(journal_t *journal, int *batch_count)
{
int i;
struct blk_plug plug;
blk_start_plug(&plug);
for (i = 0; i < *batch_count; i++)
write_dirty_buffer(journal->j_chkpt_bhs[i], JBD2_JOURNAL_REQ_FLAGS);
blk_finish_plug(&plug);
for (i = 0; i < *batch_count; i++) {
struct buffer_head *bh = journal->j_chkpt_bhs[i];
BUFFER_TRACE(bh, "brelse");
__brelse(bh);
journal->j_chkpt_bhs[i] = NULL;
}
*batch_count = 0;
}
/*
* Perform an actual checkpoint. We take the first transaction on the
* list of transactions to be checkpointed and send all its buffers
* to disk. We submit larger chunks of data at once.
*
* The journal should be locked before calling this function.
* Called with j_checkpoint_mutex held.
*/
int jbd2_log_do_checkpoint(journal_t *journal)
{
struct journal_head *jh;
struct buffer_head *bh;
transaction_t *transaction;
tid_t this_tid;
int result, batch_count = 0;
jbd2_debug(1, "Start checkpoint\n");
Annotation
- Immediate include surface: `linux/time.h`, `linux/fs.h`, `linux/jbd2.h`, `linux/errno.h`, `linux/slab.h`, `linux/blkdev.h`, `trace/events/jbd2.h`.
- Detected declarations: `function __buffer_unlink`, `function __jbd2_log_wait_for_space`, `function __flush_batch`, `function jbd2_log_do_checkpoint`, `function jbd2_cleanup_journal_tail`, `function journal_shrink_one_cp_list`, `function jbd2_journal_shrink_checkpoint_list`, `function __jbd2_journal_clean_checkpoint_list`, `function jbd2_journal_destroy_checkpoint`, `function disk`.
- 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.