]>
Commit | Line | Data |
---|---|---|
103c1972 CH |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | /* | |
3 | * Copyright (C) 2007 Oracle. All rights reserved. | |
4 | * Copyright (C) 2022 Christoph Hellwig. | |
5 | */ | |
6 | ||
7 | #ifndef BTRFS_BIO_H | |
8 | #define BTRFS_BIO_H | |
9 | ||
10 | #include <linux/bio.h> | |
11 | #include <linux/workqueue.h> | |
12 | #include "tree-checker.h" | |
13 | ||
14 | struct btrfs_bio; | |
15 | struct btrfs_fs_info; | |
16 | ||
17 | #define BTRFS_BIO_INLINE_CSUM_SIZE 64 | |
18 | ||
19 | /* | |
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. | |
23 | */ | |
24 | #define BTRFS_MAX_BIO_SECTORS (256) | |
25 | ||
26 | typedef void (*btrfs_bio_end_io_t)(struct btrfs_bio *bbio); | |
27 | ||
28 | /* | |
e0cfbb2c CH |
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. | |
103c1972 CH |
31 | */ |
32 | struct btrfs_bio { | |
4317ff00 QW |
33 | /* |
34 | * Inode and offset into it that this I/O operates on. | |
35 | * Only set for data I/O. | |
36 | */ | |
d0e5cb2b | 37 | struct btrfs_inode *inode; |
103c1972 CH |
38 | u64 file_offset; |
39 | ||
103c1972 | 40 | union { |
0d3acb25 | 41 | /* |
cbfce4c7 CH |
42 | * For data reads: checksumming and original I/O information. |
43 | * (for internal use in the btrfs_submit_bio machinery only) | |
0d3acb25 | 44 | */ |
103c1972 CH |
45 | struct { |
46 | u8 *csum; | |
47 | u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE]; | |
0d3acb25 | 48 | struct bvec_iter saved_iter; |
103c1972 CH |
49 | }; |
50 | ||
cbfce4c7 CH |
51 | /* |
52 | * For data writes: | |
ec63b84d | 53 | * - ordered extent covering the bio |
cbfce4c7 CH |
54 | * - pointer to the checksums for this bio |
55 | * - original physical address from the allocator | |
56 | * (for zone append only) | |
57 | */ | |
58 | struct { | |
ec63b84d | 59 | struct btrfs_ordered_extent *ordered; |
cbfce4c7 CH |
60 | struct btrfs_ordered_sum *sums; |
61 | u64 orig_physical; | |
62 | }; | |
63 | ||
64 | /* For metadata reads: parentness verification. */ | |
103c1972 CH |
65 | struct btrfs_tree_parent_check parent_check; |
66 | }; | |
67 | ||
68 | /* End I/O information supplied to btrfs_bio_alloc */ | |
69 | btrfs_bio_end_io_t end_io; | |
70 | void *private; | |
71 | ||
e0cfbb2c | 72 | /* For internal use in read end I/O handling */ |
295fe46f | 73 | unsigned int mirror_num; |
852eee62 | 74 | atomic_t pending_ios; |
103c1972 CH |
75 | struct work_struct end_io_work; |
76 | ||
4317ff00 QW |
77 | /* File system that this I/O operates on. */ |
78 | struct btrfs_fs_info *fs_info; | |
79 | ||
103c1972 CH |
80 | /* |
81 | * This member must come last, bio_alloc_bioset will allocate enough | |
82 | * bytes for entire btrfs_bio but relies on bio being last. | |
83 | */ | |
84 | struct bio bio; | |
85 | }; | |
86 | ||
87 | static inline struct btrfs_bio *btrfs_bio(struct bio *bio) | |
88 | { | |
89 | return container_of(bio, struct btrfs_bio, bio); | |
90 | } | |
91 | ||
92 | int __init btrfs_bioset_init(void); | |
93 | void __cold btrfs_bioset_exit(void); | |
94 | ||
4317ff00 | 95 | void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_fs_info *fs_info, |
67d66982 | 96 | btrfs_bio_end_io_t end_io, void *private); |
b41bbd29 | 97 | struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf, |
4317ff00 | 98 | struct btrfs_fs_info *fs_info, |
b41bbd29 | 99 | btrfs_bio_end_io_t end_io, void *private); |
ec63b84d | 100 | void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status); |
103c1972 | 101 | |
3480373e CH |
102 | /* Submit using blkcg_punt_bio_submit. */ |
103 | #define REQ_BTRFS_CGROUP_PUNT REQ_FS_PRIVATE | |
104 | ||
ae42a154 | 105 | void btrfs_submit_bio(struct btrfs_bio *bbio, int mirror_num); |
4886ff7b | 106 | void btrfs_submit_repair_write(struct btrfs_bio *bbio, int mirror_num, bool dev_replace); |
103c1972 CH |
107 | int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, |
108 | u64 length, u64 logical, struct page *page, | |
109 | unsigned int pg_offset, int mirror_num); | |
110 | ||
111 | #endif |