]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/io_types.h
9842019d19b3b70e0bd560a4fb349e23eebf51cc
[bcachefs-tools-debian] / libbcachefs / io_types.h
1 #ifndef _BCACHE_IO_TYPES_H
2 #define _BCACHE_IO_TYPES_H
3
4 #include "btree_types.h"
5 #include "buckets_types.h"
6 #include "keylist_types.h"
7 #include "super_types.h"
8
9 #include <linux/llist.h>
10 #include <linux/workqueue.h>
11
12 struct extent_pick_ptr {
13         struct bch_extent_crc128        crc;
14         struct bch_extent_ptr           ptr;
15         struct bch_dev                  *ca;
16 };
17
18 struct bch_read_bio {
19         struct bch_fs           *c;
20
21         /*
22          * Reads will often have to be split, and if the extent being read from
23          * was checksummed or compressed we'll also have to allocate bounce
24          * buffers and copy the data back into the original bio.
25          *
26          * If we didn't have to split, we have to save and restore the original
27          * bi_end_io - @split below indicates which:
28          */
29         union {
30         struct bch_read_bio     *parent;
31         bio_end_io_t            *end_io;
32         };
33
34         /*
35          * Saved copy of bio->bi_iter, from submission time - allows us to
36          * resubmit on IO error, and also to copy data back to the original bio
37          * when we're bouncing:
38          */
39         struct bvec_iter        bvec_iter;
40
41         unsigned                submit_time_us;
42         u8                      flags;
43         union {
44         struct {
45         u8                      bounce:1,
46                                 split:1,
47                                 process_context:1,
48                                 retry:2;
49         };
50         u8                      _state;
51         };
52
53         struct extent_pick_ptr  pick;
54         struct bversion         version;
55
56         struct promote_op       *promote;
57
58         /*
59          * If we have to retry the read (IO error, checksum failure, read stale
60          * data (raced with allocator), we retry the portion of the parent bio
61          * that failed (i.e. this bio's portion, bvec_iter).
62          *
63          * But we need to stash the inode somewhere:
64          */
65         u64                     inode;
66
67         struct work_struct      work;
68
69         struct bio              bio;
70 };
71
72 struct bch_write_bio {
73         struct bch_fs           *c;
74         struct bch_dev          *ca;
75         union {
76         struct bch_write_bio    *parent;
77         struct closure          *cl;
78         };
79
80         u8                      ptr_idx;
81         u8                      replicas_failed;
82         u8                      order;
83
84         unsigned                split:1,
85                                 bounce:1,
86                                 put_bio:1,
87                                 have_io_ref:1,
88                                 used_mempool:1;
89
90         unsigned                submit_time_us;
91         void                    *data;
92
93         struct bio              bio;
94 };
95
96 struct bch_write_op {
97         struct closure          cl;
98         struct bch_fs           *c;
99         struct workqueue_struct *io_wq;
100
101         unsigned                written; /* sectors */
102
103         short                   error;
104
105         u16                     flags;
106         unsigned                csum_type:4;
107         unsigned                compression_type:4;
108         unsigned                nr_replicas:4;
109         unsigned                alloc_reserve:4;
110         unsigned                nonce:14;
111
112         struct bpos             pos;
113         struct bversion         version;
114
115         /* For BCH_WRITE_DATA_COMPRESSED: */
116         struct bch_extent_crc128 crc;
117         unsigned                size;
118
119         struct disk_reservation res;
120
121         struct write_point      *wp;
122
123         union {
124         u8                      open_buckets[16];
125         struct {
126         struct bch_write_op     *next;
127         unsigned long           expires;
128         };
129         };
130
131         /*
132          * If caller wants to flush but hasn't passed us a journal_seq ptr, we
133          * still need to stash the journal_seq somewhere:
134          */
135         union {
136                 u64                     *journal_seq_p;
137                 u64                     journal_seq;
138         };
139
140         int                     (*index_update_fn)(struct bch_write_op *);
141
142         struct bch_devs_mask    failed;
143
144         struct keylist          insert_keys;
145         u64                     inline_keys[BKEY_EXTENT_U64s_MAX * 2];
146
147         /* Must be last: */
148         struct bch_write_bio    wbio;
149 };
150
151 #endif /* _BCACHE_IO_TYPES_H */