fs/btrfs/transaction.c
Source file repositories/reference/linux-study-clean/fs/btrfs/transaction.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/transaction.c- Extension
.c- Size
- 85791 bytes
- Lines
- 2775
- 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.
- 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/fs.hlinux/slab.hlinux/sched.hlinux/sched/mm.hlinux/writeback.hlinux/pagemap.hlinux/blkdev.hlinux/uuid.hlinux/timekeeping.hmisc.hctree.hdisk-io.hextent_io.htransaction.hlocking.htree-log.hvolumes.hdev-replace.hqgroup.hblock-group.hspace-info.hfs.haccessors.hextent-tree.hroot-tree.hdir-item.huuid-tree.hioctl.hrelocation.hscrub.hordered-data.hdelayed-inode.h
Detected Declarations
function btrfs_put_transactionfunction happenfunction switch_commit_rootsfunction list_for_each_entry_safefunction extwriter_counter_incfunction extwriter_counter_decfunction extwriter_counter_initfunction extwriter_counter_readfunction chunkfunction join_transactionfunction record_root_in_transfunction btrfs_add_dropped_rootfunction btrfs_record_root_in_transfunction is_transaction_blockedfunction wait_current_transfunction may_wait_transactionfunction need_reserve_reloc_rootfunction btrfs_reserve_trans_metadatafunction start_transactionfunction may_wait_transactionfunction btrfs_attach_transactionfunction btrfs_attach_transaction_barrierfunction btrfs_attach_transaction_barrierfunction wait_for_commitfunction btrfs_wait_for_commitfunction list_for_each_entryfunction list_for_each_entry_reversefunction btrfs_throttlefunction btrfs_should_end_transactionfunction btrfs_trans_release_metadatafunction __btrfs_end_transactionfunction btrfs_end_transactionfunction btrfs_end_transaction_throttlefunction btrfs_write_marked_extentsfunction __btrfs_wait_marked_extentsfunction __btrfs_wait_marked_extentsfunction btrfs_wait_extentsfunction btrfs_wait_tree_log_extentsfunction btrfs_write_and_wait_transactionfunction update_cowonly_rootfunction commit_cowonly_rootsfunction btrfs_maybe_wake_unfinished_dropfunction btrfs_add_dead_rootfunction commit_fs_rootsfunction qgroup_account_snapshotfunction create_pending_snapshotfunction create_pending_snapshotsfunction list_for_each_entry_safe
Annotated Snippet
while (!list_empty(&transaction->deleted_bgs)) {
struct btrfs_block_group *cache;
cache = list_first_entry(&transaction->deleted_bgs,
struct btrfs_block_group,
bg_list);
/*
* Not strictly necessary to lock, as no other task will be using a
* block_group on the deleted_bgs list during a transaction abort.
*/
spin_lock(&transaction->fs_info->unused_bgs_lock);
list_del_init(&cache->bg_list);
spin_unlock(&transaction->fs_info->unused_bgs_lock);
btrfs_unfreeze_block_group(cache);
btrfs_put_block_group(cache);
}
WARN_ON(!list_empty(&transaction->dev_update_list));
kfree(transaction);
}
}
static noinline void switch_commit_roots(struct btrfs_trans_handle *trans)
{
struct btrfs_transaction *cur_trans = trans->transaction;
struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_root *root, *tmp;
/*
* At this point no one can be using this transaction to modify any tree
* and no one can start another transaction to modify any tree either.
*/
ASSERT(cur_trans->state == TRANS_STATE_COMMIT_DOING,
"cur_trans->state=%d", cur_trans->state);
down_write(&fs_info->commit_root_sem);
if (test_bit(BTRFS_FS_RELOC_RUNNING, &fs_info->flags))
fs_info->last_reloc_trans = trans->transid;
list_for_each_entry_safe(root, tmp, &cur_trans->switch_commits,
dirty_list) {
list_del_init(&root->dirty_list);
free_extent_buffer(root->commit_root);
root->commit_root = btrfs_root_node(root);
btrfs_extent_io_tree_release(&root->dirty_log_pages);
btrfs_qgroup_clean_swapped_blocks(root);
}
/* We can free old roots now. */
spin_lock(&cur_trans->dropped_roots_lock);
while (!list_empty(&cur_trans->dropped_roots)) {
root = list_first_entry(&cur_trans->dropped_roots,
struct btrfs_root, root_list);
list_del_init(&root->root_list);
spin_unlock(&cur_trans->dropped_roots_lock);
btrfs_free_log(trans, root);
btrfs_drop_and_free_fs_root(fs_info, root);
spin_lock(&cur_trans->dropped_roots_lock);
}
spin_unlock(&cur_trans->dropped_roots_lock);
up_write(&fs_info->commit_root_sem);
}
static inline void extwriter_counter_inc(struct btrfs_transaction *trans,
unsigned int type)
{
if (type & TRANS_EXTWRITERS)
atomic_inc(&trans->num_extwriters);
}
static inline void extwriter_counter_dec(struct btrfs_transaction *trans,
unsigned int type)
{
if (type & TRANS_EXTWRITERS)
atomic_dec(&trans->num_extwriters);
}
static inline void extwriter_counter_init(struct btrfs_transaction *trans,
unsigned int type)
{
atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0));
}
static inline int extwriter_counter_read(struct btrfs_transaction *trans)
{
return atomic_read(&trans->num_extwriters);
}
/*
Annotation
- Immediate include surface: `linux/fs.h`, `linux/slab.h`, `linux/sched.h`, `linux/sched/mm.h`, `linux/writeback.h`, `linux/pagemap.h`, `linux/blkdev.h`, `linux/uuid.h`.
- Detected declarations: `function btrfs_put_transaction`, `function happen`, `function switch_commit_roots`, `function list_for_each_entry_safe`, `function extwriter_counter_inc`, `function extwriter_counter_dec`, `function extwriter_counter_init`, `function extwriter_counter_read`, `function chunk`, `function join_transaction`.
- 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.