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