1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _BCACHEFS_IO_WRITE_H 3 #define _BCACHEFS_IO_WRITE_H 4 5 #include "checksum.h" 6 #include "io_write_types.h" 7 8 #define to_wbio(_bio) \ 9 container_of((_bio), struct bch_write_bio, bio) 10 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); 13 14 void bch2_submit_wbio_replicas(struct bch_write_bio *, struct bch_fs *, 15 enum bch_data_type, const struct bkey_i *, bool); 16 17 __printf(3, 4) 18 void bch2_write_op_error(struct bch_write_op *op, u64, const char *, ...); 19 20 #define BCH_WRITE_FLAGS() \ 21 x(alloc_nowait) \ 22 x(cached) \ 23 x(data_encoded) \ 24 x(pages_stable) \ 25 x(pages_owned) \ 26 x(only_specified_devs) \ 27 x(wrote_data_inline) \ 28 x(check_enospc) \ 29 x(sync) \ 30 x(move) \ 31 x(in_worker) \ 32 x(submitted) \ 33 x(io_error) \ 34 x(convert_unwritten) 35 36 enum __bch_write_flags { 37 #define x(f) __BCH_WRITE_##f, 38 BCH_WRITE_FLAGS() 39 #undef x 40 }; 41 42 enum bch_write_flags { 43 #define x(f) BCH_WRITE_##f = BIT(__BCH_WRITE_##f), 44 BCH_WRITE_FLAGS() 45 #undef x 46 }; 47 48 static inline struct workqueue_struct *index_update_wq(struct bch_write_op *op) 49 { 50 return op->watermark == BCH_WATERMARK_copygc 51 ? op->c->copygc_wq 52 : op->c->btree_update_wq; 53 } 54 55 int bch2_sum_sector_overwrites(struct btree_trans *, struct btree_iter *, 56 struct bkey_i *, bool *, s64 *, s64 *); 57 int bch2_extent_update(struct btree_trans *, subvol_inum, 58 struct btree_iter *, struct bkey_i *, 59 struct disk_reservation *, u64, s64 *, bool); 60 61 static inline void bch2_write_op_init(struct bch_write_op *op, struct bch_fs *c, 62 struct bch_io_opts opts) 63 { 64 op->c = c; 65 op->end_io = NULL; 66 op->flags = 0; 67 op->written = 0; 68 op->error = 0; 69 op->csum_type = bch2_data_checksum_type(c, opts); 70 op->compression_opt = opts.compression; 71 op->nr_replicas = 0; 72 op->nr_replicas_required = c->opts.data_replicas_required; 73 op->watermark = BCH_WATERMARK_normal; 74 op->incompressible = 0; 75 op->open_buckets.nr = 0; 76 op->devs_have.nr = 0; 77 op->target = 0; 78 op->opts = opts; 79 op->subvol = 0; 80 op->pos = POS_MAX; 81 op->version = ZERO_VERSION; 82 op->write_point = (struct write_point_specifier) { 0 }; 83 op->res = (struct disk_reservation) { 0 }; 84 op->new_i_size = U64_MAX; 85 op->i_sectors_delta = 0; 86 op->devs_need_flush = NULL; 87 } 88 89 CLOSURE_CALLBACK(bch2_write); 90 void bch2_write_point_do_index_updates(struct work_struct *); 91 92 static inline struct bch_write_bio *wbio_init(struct bio *bio) 93 { 94 struct bch_write_bio *wbio = to_wbio(bio); 95 96 memset(&wbio->wbio, 0, sizeof(wbio->wbio)); 97 return wbio; 98 } 99 100 void bch2_write_op_to_text(struct printbuf *, struct bch_write_op *); 101 102 void bch2_fs_io_write_exit(struct bch_fs *); 103 int bch2_fs_io_write_init(struct bch_fs *); 104 105 #endif /* _BCACHEFS_IO_WRITE_H */ 106