1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2007 Oracle. All rights reserved.
4 * Copyright (C) 2022 Christoph Hellwig.
10 #include <linux/bio.h>
11 #include <linux/workqueue.h>
12 #include "tree-checker.h"
17 #define BTRFS_BIO_INLINE_CSUM_SIZE 64
20 * Maximum number of sectors for a single bio to limit the size of the
21 * checksum array. This matches the number of bio_vecs per bio and thus the
22 * I/O size for buffered I/O.
24 #define BTRFS_MAX_BIO_SECTORS (256)
26 typedef void (*btrfs_bio_end_io_t)(struct btrfs_bio *bbio);
29 * Highlevel btrfs I/O structure. It is allocated by btrfs_bio_alloc and
30 * passed to btrfs_submit_bio for mapping to the physical devices.
33 /* Inode and offset into it that this I/O operates on. */
34 struct btrfs_inode *inode;
39 * Data checksumming and original I/O information for internal
40 * use in the btrfs_submit_bio machinery.
44 u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
45 struct bvec_iter saved_iter;
48 /* For metadata parentness verification. */
49 struct btrfs_tree_parent_check parent_check;
52 /* End I/O information supplied to btrfs_bio_alloc */
53 btrfs_bio_end_io_t end_io;
56 /* For internal use in read end I/O handling */
57 unsigned int mirror_num;
59 struct work_struct end_io_work;
62 * This member must come last, bio_alloc_bioset will allocate enough
63 * bytes for entire btrfs_bio but relies on bio being last.
68 static inline struct btrfs_bio *btrfs_bio(struct bio *bio)
70 return container_of(bio, struct btrfs_bio, bio);
73 int __init btrfs_bioset_init(void);
74 void __cold btrfs_bioset_exit(void);
76 void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_inode *inode,
77 btrfs_bio_end_io_t end_io, void *private);
78 struct bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf,
79 struct btrfs_inode *inode,
80 btrfs_bio_end_io_t end_io, void *private);
82 static inline void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status)
84 bbio->bio.bi_status = status;
88 /* Bio only refers to one ordered extent. */
89 #define REQ_BTRFS_ONE_ORDERED REQ_DRV
91 void btrfs_submit_bio(struct bio *bio, int mirror_num);
92 int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
93 u64 length, u64 logical, struct page *page,
94 unsigned int pg_offset, int mirror_num);