]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/io.h
Update bcachefs sources to e82e656279 bcachefs: Cleanups for building in userspace
[bcachefs-tools-debian] / libbcachefs / io.h
1 #ifndef _BCACHEFS_IO_H
2 #define _BCACHEFS_IO_H
3
4 #include <linux/hash.h>
5 #include "io_types.h"
6
7 #define to_wbio(_bio)                   \
8         container_of((_bio), struct bch_write_bio, bio)
9
10 #define to_rbio(_bio)                   \
11         container_of((_bio), struct bch_read_bio, bio)
12
13 void bch2_bio_free_pages_pool(struct bch_fs *, struct bio *);
14 void bch2_bio_alloc_pages_pool(struct bch_fs *, struct bio *, size_t);
15
16 void bch2_submit_wbio_replicas(struct bch_write_bio *, struct bch_fs *,
17                                enum bch_data_type, const struct bkey_i *);
18
19 enum bch_write_flags {
20         BCH_WRITE_ALLOC_NOWAIT          = (1 << 0),
21         BCH_WRITE_CACHED                = (1 << 1),
22         BCH_WRITE_FLUSH                 = (1 << 2),
23         BCH_WRITE_DATA_COMPRESSED       = (1 << 3),
24         BCH_WRITE_THROTTLE              = (1 << 4),
25
26         /* Internal: */
27         BCH_WRITE_JOURNAL_SEQ_PTR       = (1 << 5),
28         BCH_WRITE_DONE                  = (1 << 6),
29         BCH_WRITE_LOOPED                = (1 << 7),
30 };
31
32 static inline u64 *op_journal_seq(struct bch_write_op *op)
33 {
34         return (op->flags & BCH_WRITE_JOURNAL_SEQ_PTR)
35                 ? op->journal_seq_p : &op->journal_seq;
36 }
37
38 static inline struct write_point *foreground_write_point(struct bch_fs *c,
39                                                          unsigned long v)
40 {
41         return c->write_points +
42                 hash_long(v, ilog2(ARRAY_SIZE(c->write_points)));
43 }
44
45 void bch2_write_op_init(struct bch_write_op *, struct bch_fs *,
46                         struct disk_reservation, struct write_point *,
47                         struct bpos, u64 *, unsigned);
48 void bch2_write(struct closure *);
49
50 static inline struct bch_write_bio *wbio_init(struct bio *bio)
51 {
52         struct bch_write_bio *wbio = to_wbio(bio);
53
54         memset(wbio, 0, offsetof(struct bch_write_bio, bio));
55         return wbio;
56 }
57
58 void bch2_wake_delayed_writes(unsigned long data);
59
60 struct bch_devs_mask;
61 struct cache_promote_op;
62 struct extent_pick_ptr;
63
64 int __bch2_read_extent(struct bch_fs *, struct bch_read_bio *, struct bvec_iter,
65                        struct bkey_s_c k, struct extent_pick_ptr *, unsigned);
66 void __bch2_read(struct bch_fs *, struct bch_read_bio *, struct bvec_iter,
67                  u64, struct bch_devs_mask *, unsigned);
68
69 enum bch_read_flags {
70         BCH_READ_RETRY_IF_STALE         = 1 << 0,
71         BCH_READ_MAY_PROMOTE            = 1 << 1,
72         BCH_READ_USER_MAPPED            = 1 << 2,
73
74         /* internal: */
75         BCH_READ_MUST_BOUNCE            = 1 << 3,
76         BCH_READ_MUST_CLONE             = 1 << 4,
77         BCH_READ_IN_RETRY               = 1 << 5,
78 };
79
80 static inline void bch2_read_extent(struct bch_fs *c,
81                                     struct bch_read_bio *rbio,
82                                     struct bkey_s_c k,
83                                     struct extent_pick_ptr *pick,
84                                     unsigned flags)
85 {
86         rbio->_state = 0;
87         __bch2_read_extent(c, rbio, rbio->bio.bi_iter, k, pick, flags);
88 }
89
90 static inline void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio,
91                              u64 inode)
92 {
93         rbio->_state = 0;
94         __bch2_read(c, rbio, rbio->bio.bi_iter, inode, NULL,
95                     BCH_READ_RETRY_IF_STALE|
96                     BCH_READ_MAY_PROMOTE|
97                     BCH_READ_USER_MAPPED);
98 }
99
100 static inline struct bch_read_bio *rbio_init(struct bio *bio)
101 {
102         struct bch_read_bio *rbio = to_rbio(bio);
103
104         rbio->_state = 0;
105         return rbio;
106 }
107
108 #endif /* _BCACHEFS_IO_H */