]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/io.h
253316a4be998d1a78fa84e14cc83332a7cb743c
[bcachefs-tools-debian] / libbcachefs / io.h
1 #ifndef _BCACHE_IO_H
2 #define _BCACHE_IO_H
3
4 #include "io_types.h"
5
6 #define to_wbio(_bio)                   \
7         container_of((_bio), struct bch_write_bio, bio)
8
9 #define to_rbio(_bio)                   \
10         container_of((_bio), struct bch_read_bio, bio)
11
12 void bch2_bio_free_pages_pool(struct bch_fs *, struct bio *);
13 void bch2_bio_alloc_pages_pool(struct bch_fs *, struct bio *, size_t);
14
15 enum bch_write_flags {
16         BCH_WRITE_ALLOC_NOWAIT          = (1 << 0),
17         BCH_WRITE_DISCARD               = (1 << 1),
18         BCH_WRITE_CACHED                = (1 << 2),
19         BCH_WRITE_FLUSH                 = (1 << 3),
20         BCH_WRITE_DISCARD_ON_ERROR      = (1 << 4),
21         BCH_WRITE_DATA_COMPRESSED       = (1 << 5),
22
23         /* Internal: */
24         BCH_WRITE_JOURNAL_SEQ_PTR       = (1 << 6),
25         BCH_WRITE_DONE                  = (1 << 7),
26         BCH_WRITE_LOOPED                = (1 << 8),
27 };
28
29 static inline u64 *op_journal_seq(struct bch_write_op *op)
30 {
31         return (op->flags & BCH_WRITE_JOURNAL_SEQ_PTR)
32                 ? op->journal_seq_p : &op->journal_seq;
33 }
34
35 static inline struct write_point *foreground_write_point(struct bch_fs *c,
36                                                          unsigned long v)
37 {
38         return c->write_points +
39                 hash_long(v, ilog2(ARRAY_SIZE(c->write_points)));
40 }
41
42 void bch2_write_op_init(struct bch_write_op *, struct bch_fs *,
43                         struct bch_write_bio *,
44                         struct disk_reservation, struct write_point *,
45                         struct bpos, u64 *, unsigned);
46 void bch2_write(struct closure *);
47
48 struct cache_promote_op;
49
50 struct extent_pick_ptr;
51
52 void bch2_read_extent_iter(struct bch_fs *, struct bch_read_bio *,
53                            struct bvec_iter, struct bkey_s_c k,
54                            struct extent_pick_ptr *, unsigned);
55
56 static inline void bch2_read_extent(struct bch_fs *c,
57                                     struct bch_read_bio *orig,
58                                     struct bkey_s_c k,
59                                     struct extent_pick_ptr *pick,
60                                     unsigned flags)
61 {
62         bch2_read_extent_iter(c, orig, orig->bio.bi_iter,
63                              k, pick, flags);
64 }
65
66 enum bch_read_flags {
67         BCH_READ_FORCE_BOUNCE           = 1 << 0,
68         BCH_READ_RETRY_IF_STALE         = 1 << 1,
69         BCH_READ_PROMOTE                = 1 << 2,
70         BCH_READ_IS_LAST                = 1 << 3,
71         BCH_READ_MAY_REUSE_BIO          = 1 << 4,
72         BCH_READ_USER_MAPPED            = 1 << 5,
73 };
74
75 void bch2_read(struct bch_fs *, struct bch_read_bio *, u64);
76
77 void bch2_submit_wbio_replicas(struct bch_write_bio *, struct bch_fs *,
78                                const struct bkey_i *);
79
80 int bch2_discard(struct bch_fs *, struct bpos, struct bpos,
81                  struct bversion, struct disk_reservation *,
82                  struct extent_insert_hook *, u64 *);
83
84 void bch2_read_retry_work(struct work_struct *);
85 void bch2_wake_delayed_writes(unsigned long data);
86
87 #endif /* _BCACHE_IO_H */