fs/btrfs/bio.c
Source file repositories/reference/linux-study-clean/fs/btrfs/bio.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/bio.c- Extension
.c- Size
- 31947 bytes
- Lines
- 1073
- 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/blk_types.hlinux/bio.hbio.hctree.hvolumes.hraid56.hasync-thread.hdev-replace.hzoned.hfile-item.hraid-stripe-tree.h
Detected Declarations
struct btrfs_failed_biostruct async_submit_biofunction is_data_bbiofunction bbio_has_ordered_extentfunction btrfs_bio_initfunction btrfs_bio_end_iofunction next_repair_mirrorfunction prev_repair_mirrorfunction btrfs_repair_donefunction btrfs_end_repair_biofunction btrfs_bio_for_each_blockfunction mirrorfunction btrfs_check_read_biofunction btrfs_bio_for_each_blockfunction btrfs_log_dev_io_errorfunction simple_end_io_workfunction btrfs_simple_end_iofunction btrfs_raid56_end_iofunction orig_write_end_io_workfunction btrfs_orig_write_end_iofunction clone_write_end_io_workfunction btrfs_clone_write_end_iofunction btrfs_submit_dev_biofunction btrfs_submit_mirrored_biofunction btrfs_submit_biofunction btrfs_bio_csumfunction run_one_async_startfunction run_one_async_donefunction should_async_writefunction btrfs_wq_submit_biofunction btrfs_append_map_lengthfunction btrfs_submit_chunkfunction assert_bbio_alignmentfunction btrfs_submit_bbiofunction btrfs_submit_bbiofunction btrfs_submit_repair_writefunction btrfs_bioset_initfunction btrfs_bioset_exit
Annotated Snippet
struct btrfs_failed_bio {
struct btrfs_bio *bbio;
int num_copies;
atomic_t repair_count;
};
/* Is this a data path I/O that needs storage layer checksum and repair? */
static inline bool is_data_bbio(const struct btrfs_bio *bbio)
{
return bbio->inode && is_data_inode(bbio->inode);
}
static bool bbio_has_ordered_extent(const struct btrfs_bio *bbio)
{
return is_data_bbio(bbio) && btrfs_op(&bbio->bio) == BTRFS_MAP_WRITE;
}
/*
* Initialize a btrfs_bio structure. This skips the embedded bio itself as it
* is already initialized by the block layer.
*/
void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_inode *inode, u64 file_offset,
btrfs_bio_end_io_t end_io, void *private)
{
/* @inode parameter is mandatory. */
ASSERT(inode);
memset(bbio, 0, offsetof(struct btrfs_bio, bio));
bbio->inode = inode;
bbio->end_io = end_io;
bbio->private = private;
bbio->file_offset = file_offset;
atomic_set(&bbio->pending_ios, 1);
WRITE_ONCE(bbio->status, BLK_STS_OK);
}
/*
* Allocate a btrfs_bio structure. The btrfs_bio is the main I/O container for
* btrfs, and is used for all I/O submitted through btrfs_submit_bbio().
*
* Just like the underlying bio_alloc_bioset it will not fail as it is backed by
* a mempool.
*/
struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf,
struct btrfs_inode *inode, u64 file_offset,
btrfs_bio_end_io_t end_io, void *private)
{
struct btrfs_bio *bbio;
struct bio *bio;
bio = bio_alloc_bioset(NULL, nr_vecs, opf, GFP_NOFS, &btrfs_bioset);
bbio = btrfs_bio(bio);
btrfs_bio_init(bbio, inode, file_offset, end_io, private);
return bbio;
}
static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info,
struct btrfs_bio *orig_bbio,
u64 map_length)
{
struct btrfs_bio *bbio;
struct bio *bio;
bio = bio_split(&orig_bbio->bio, map_length >> SECTOR_SHIFT, GFP_NOFS,
&btrfs_clone_bioset);
if (IS_ERR(bio))
return ERR_CAST(bio);
bbio = btrfs_bio(bio);
btrfs_bio_init(bbio, orig_bbio->inode, orig_bbio->file_offset, NULL, orig_bbio);
orig_bbio->file_offset += map_length;
if (bbio_has_ordered_extent(bbio)) {
refcount_inc(&orig_bbio->ordered->refs);
bbio->ordered = orig_bbio->ordered;
bbio->orig_logical = orig_bbio->orig_logical;
orig_bbio->orig_logical += map_length;
}
bbio->csum_search_commit_root = orig_bbio->csum_search_commit_root;
bbio->can_use_append = orig_bbio->can_use_append;
bbio->is_scrub = orig_bbio->is_scrub;
bbio->is_remap = orig_bbio->is_remap;
bbio->async_csum = orig_bbio->async_csum;
atomic_inc(&orig_bbio->pending_ios);
return bbio;
}
void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status)
{
Annotation
- Immediate include surface: `linux/blk_types.h`, `linux/bio.h`, `bio.h`, `ctree.h`, `volumes.h`, `raid56.h`, `async-thread.h`, `dev-replace.h`.
- Detected declarations: `struct btrfs_failed_bio`, `struct async_submit_bio`, `function is_data_bbio`, `function bbio_has_ordered_extent`, `function btrfs_bio_init`, `function btrfs_bio_end_io`, `function next_repair_mirror`, `function prev_repair_mirror`, `function btrfs_repair_done`, `function btrfs_end_repair_bio`.
- 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.