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