fs/btrfs/disk-io.c
Source file repositories/reference/linux-study-clean/fs/btrfs/disk-io.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/disk-io.c- Extension
.c- Size
- 147817 bytes
- Lines
- 5040
- 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/blkdev.hlinux/radix-tree.hlinux/writeback.hlinux/workqueue.hlinux/kthread.hlinux/slab.hlinux/migrate.hlinux/ratelimit.hlinux/uuid.hlinux/semaphore.hlinux/error-injection.hlinux/crc32c.hlinux/sched/mm.hlinux/unaligned.hctree.hdisk-io.htransaction.hbtrfs_inode.hdelayed-inode.hbio.hprint-tree.hlocking.htree-log.hfree-space-cache.hfree-space-tree.hdev-replace.hraid56.hsysfs.hqgroup.hcompression.htree-checker.h
Detected Declarations
function csum_tree_blockfunction btrfs_buffer_uptodatefunction btrfs_supported_super_csumfunction btrfs_check_super_csumfunction btrfs_repair_eb_io_failurefunction btrfs_read_extent_bufferfunction btree_csum_one_biofunction check_tree_block_fsidfunction btrfs_validate_extent_bufferfunction btrfs_header_generationfunction btree_migrate_foliofunction btree_release_foliofunction btree_invalidate_foliofunction btree_dirty_foliofunction global_root_cmpfunction global_root_key_cmpfunction btrfs_global_root_insertfunction btrfs_global_root_deletefunction btrfs_global_root_idfunction btrfs_alloc_log_tree_nodefunction btrfs_init_log_root_treefunction btrfs_add_log_treefunction btrfs_root_idfunction btrfs_free_fs_rootfunction btrfs_root_refsfunction btrfs_insert_fs_rootfunction btrfs_check_leaked_rootsfunction free_global_rootsfunction btrfs_free_fs_infofunction btrfs_put_rootfunction alreadyfunction cleaner_kthreadfunction transaction_kthreadfunction find_newest_super_backupfunction backup_super_rootsfunction read_backup_rootfunction btrfs_stop_all_workersfunction free_root_extent_buffersfunction free_global_root_pointersfunction free_root_pointersfunction btrfs_put_rootfunction btrfs_free_fs_rootsfunction btrfs_init_scrubfunction btrfs_init_balancefunction btrfs_init_btree_inodefunction btrfs_init_dev_replace_locksfunction btrfs_init_qgroupfunction btrfs_init_workqueues
Annotated Snippet
if (!failed_mirror) {
failed = true;
failed_mirror = eb->read_mirror;
}
mirror_num++;
if (mirror_num == failed_mirror)
mirror_num++;
if (mirror_num > num_copies)
break;
}
if (failed && !ret && failed_mirror)
btrfs_repair_eb_io_failure(eb, failed_mirror);
return ret;
}
/*
* Checksum a dirty tree block before IO.
*/
int btree_csum_one_bio(struct btrfs_bio *bbio)
{
struct extent_buffer *eb = bbio->private;
struct btrfs_fs_info *fs_info = eb->fs_info;
u64 found_start = btrfs_header_bytenr(eb);
u64 last_trans;
u8 result[BTRFS_CSUM_SIZE];
int ret;
/* Btree blocks are always contiguous on disk. */
if (WARN_ON_ONCE(bbio->file_offset != eb->start))
return -EIO;
if (WARN_ON_ONCE(bbio->bio.bi_iter.bi_size != eb->len))
return -EIO;
/*
* If an extent_buffer is marked as EXTENT_BUFFER_ZONED_ZEROOUT, don't
* checksum it but zero-out its content. This is done to preserve
* ordering of I/O without unnecessarily writing out data.
*/
if (test_bit(EXTENT_BUFFER_ZONED_ZEROOUT, &eb->bflags)) {
memzero_extent_buffer(eb, 0, eb->len);
return 0;
}
if (WARN_ON_ONCE(found_start != eb->start))
return -EIO;
if (WARN_ON(!btrfs_meta_folio_test_uptodate(eb->folios[0], eb)))
return -EIO;
ASSERT(memcmp_extent_buffer(eb, fs_info->fs_devices->metadata_uuid,
offsetof(struct btrfs_header, fsid),
BTRFS_FSID_SIZE) == 0);
csum_tree_block(eb, result);
if (btrfs_header_level(eb))
ret = btrfs_check_node(eb);
else
ret = btrfs_check_leaf(eb);
if (ret < 0)
goto error;
/*
* Also check the generation, the eb reached here must be newer than
* last committed. Or something seriously wrong happened.
*/
last_trans = btrfs_get_last_trans_committed(fs_info);
if (unlikely(btrfs_header_generation(eb) <= last_trans)) {
ret = -EUCLEAN;
btrfs_err(fs_info,
"block=%llu bad generation, have %llu expect > %llu",
eb->start, btrfs_header_generation(eb), last_trans);
goto error;
}
write_extent_buffer(eb, result, 0, fs_info->csum_size);
return 0;
error:
btrfs_print_tree(eb, 0);
btrfs_err(fs_info, "block=%llu write time tree block corruption detected",
eb->start);
/*
* Be noisy if this is an extent buffer from a log tree. We don't abort
* a transaction in case there's a bad log tree extent buffer, we just
* fallback to a transaction commit. Still we want to know when there is
* a bad log tree extent buffer, as that may signal a bug somewhere.
*/
Annotation
- Immediate include surface: `linux/fs.h`, `linux/blkdev.h`, `linux/radix-tree.h`, `linux/writeback.h`, `linux/workqueue.h`, `linux/kthread.h`, `linux/slab.h`, `linux/migrate.h`.
- Detected declarations: `function csum_tree_block`, `function btrfs_buffer_uptodate`, `function btrfs_supported_super_csum`, `function btrfs_check_super_csum`, `function btrfs_repair_eb_io_failure`, `function btrfs_read_extent_buffer`, `function btree_csum_one_bio`, `function check_tree_block_fsid`, `function btrfs_validate_extent_buffer`, `function btrfs_header_generation`.
- 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.