/* SPDX-License-Identifier: GPL-2.0 */1/*2* Copyright (C) 2007 Oracle. All rights reserved.3* Copyright (C) 2022 Christoph Hellwig.4*/56#ifndef BTRFS_BIO_H7#define BTRFS_BIO_H89#include <linux/types.h>10#include <linux/bio.h>11#include <linux/workqueue.h>12#include "tree-checker.h"1314struct btrfs_bio;15struct btrfs_fs_info;16struct btrfs_inode;1718#define BTRFS_BIO_INLINE_CSUM_SIZE 641920typedef void (*btrfs_bio_end_io_t)(struct btrfs_bio *bbio);2122/*23* Highlevel btrfs I/O structure. It is allocated by btrfs_bio_alloc and24* passed to btrfs_submit_bbio() for mapping to the physical devices.25*/26struct btrfs_bio {27/*28* Inode and offset into it that this I/O operates on.29*30* If the inode is a data one, csum verification and read-repair31* will be done automatically.32* If the inode is a metadata one, everything is handled by the caller.33*/34struct btrfs_inode *inode;35u64 file_offset;3637union {38/*39* For data reads: checksumming and original I/O information.40* (for internal use in the btrfs_submit_bbio() machinery only)41*/42struct {43u8 *csum;44u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];45struct bvec_iter saved_iter;46};4748/*49* For data writes:50* - ordered extent covering the bio51* - pointer to the checksums for this bio52* - original physical address from the allocator53* (for zone append only)54* - original logical address, used for checksumming fscrypt bios55*/56struct {57struct btrfs_ordered_extent *ordered;58struct btrfs_ordered_sum *sums;59struct work_struct csum_work;60struct completion csum_done;61struct bvec_iter csum_saved_iter;62u64 orig_physical;63u64 orig_logical;64};6566/* For metadata reads: parentness verification. */67struct btrfs_tree_parent_check parent_check;68};6970/* For internal use in read end I/O handling */71struct work_struct end_io_work;7273/* End I/O information supplied to btrfs_bio_alloc */74btrfs_bio_end_io_t end_io;75void *private;7677atomic_t pending_ios;78u16 mirror_num;7980/* Save the first error status of split bio. */81blk_status_t status;8283/* Use the commit root to look up csums (data read bio only). */84bool csum_search_commit_root:1;8586/*87* Since scrub will reuse btree inode, we need this flag to distinguish88* scrub bios.89*/90bool is_scrub:1;9192/* Whether the bio is coming from copy_remapped_data_io(). */93bool is_remap:1;9495/* Whether the csum generation for data write is async. */96bool async_csum:1;9798/* Whether the bio is written using zone append. */99bool can_use_append:1;100101/*102* This member must come last, bio_alloc_bioset will allocate enough103* bytes for entire btrfs_bio but relies on bio being last.104*/105struct bio bio;106};107108static inline struct btrfs_bio *btrfs_bio(struct bio *bio)109{110return container_of(bio, struct btrfs_bio, bio);111}112113int __init btrfs_bioset_init(void);114void __cold btrfs_bioset_exit(void);115116void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_inode *inode, u64 file_offset,117btrfs_bio_end_io_t end_io, void *private);118struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf,119struct btrfs_inode *inode, u64 file_offset,120btrfs_bio_end_io_t end_io, void *private);121void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status);122123/* Submit using blkcg_punt_bio_submit. */124#define REQ_BTRFS_CGROUP_PUNT REQ_FS_PRIVATE125126void btrfs_submit_bbio(struct btrfs_bio *bbio, int mirror_num);127void btrfs_submit_repair_write(struct btrfs_bio *bbio, int mirror_num, bool dev_replace);128int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 fileoff,129u32 length, u64 logical, const phys_addr_t paddrs[],130unsigned int step, int mirror_num);131132#endif133134135