1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_IO_WRITE_H
3 #define _BCACHEFS_IO_WRITE_H
6 #include "io_write_types.h"
8 #define to_wbio(_bio) \
9 container_of((_bio), struct bch_write_bio, bio)
11 void bch2_bio_free_pages_pool(struct bch_fs *, struct bio *);
12 void bch2_bio_alloc_pages_pool(struct bch_fs *, struct bio *, size_t);
14 #ifndef CONFIG_BCACHEFS_NO_LATENCY_ACCT
15 void bch2_latency_acct(struct bch_dev *, u64, int);
17 static inline void bch2_latency_acct(struct bch_dev *ca, u64 submit_time, int rw) {}
20 void bch2_submit_wbio_replicas(struct bch_write_bio *, struct bch_fs *,
21 enum bch_data_type, const struct bkey_i *, bool);
23 void bch2_write_op_error(struct printbuf *out, struct bch_write_op *op);
25 #define BCH_WRITE_FLAGS() \
31 x(ONLY_SPECIFIED_DEVS) \
32 x(WROTE_DATA_INLINE) \
42 enum __bch_write_flags {
43 #define x(f) __BCH_WRITE_##f,
48 enum bch_write_flags {
49 #define x(f) BCH_WRITE_##f = BIT(__BCH_WRITE_##f),
54 static inline struct workqueue_struct *index_update_wq(struct bch_write_op *op)
56 return op->watermark == BCH_WATERMARK_copygc
58 : op->c->btree_update_wq;
61 int bch2_sum_sector_overwrites(struct btree_trans *, struct btree_iter *,
62 struct bkey_i *, bool *, s64 *, s64 *);
63 int bch2_extent_update(struct btree_trans *, subvol_inum,
64 struct btree_iter *, struct bkey_i *,
65 struct disk_reservation *, u64, s64 *, bool);
67 static inline void bch2_write_op_init(struct bch_write_op *op, struct bch_fs *c,
68 struct bch_io_opts opts)
75 op->csum_type = bch2_data_checksum_type(c, opts);
76 op->compression_opt = opts.compression;
78 op->nr_replicas_required = c->opts.data_replicas_required;
79 op->watermark = BCH_WATERMARK_normal;
80 op->incompressible = 0;
81 op->open_buckets.nr = 0;
87 op->version = ZERO_VERSION;
88 op->write_point = (struct write_point_specifier) { 0 };
89 op->res = (struct disk_reservation) { 0 };
90 op->new_i_size = U64_MAX;
91 op->i_sectors_delta = 0;
92 op->devs_need_flush = NULL;
95 CLOSURE_CALLBACK(bch2_write);
96 void bch2_write_point_do_index_updates(struct work_struct *);
98 static inline struct bch_write_bio *wbio_init(struct bio *bio)
100 struct bch_write_bio *wbio = to_wbio(bio);
102 memset(&wbio->wbio, 0, sizeof(wbio->wbio));
106 void bch2_write_op_to_text(struct printbuf *, struct bch_write_op *);
108 void bch2_fs_io_write_exit(struct bch_fs *);
109 int bch2_fs_io_write_init(struct bch_fs *);
111 #endif /* _BCACHEFS_IO_WRITE_H */