1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_IO_WRITE_TYPES_H
3 #define _BCACHEFS_IO_WRITE_TYPES_H
4 
5 #include "alloc_types.h"
6 #include "btree_types.h"
7 #include "buckets_types.h"
8 #include "extents_types.h"
9 #include "keylist_types.h"
10 #include "opts.h"
11 #include "super_types.h"
12 
13 #include <linux/llist.h>
14 #include <linux/workqueue.h>
15 
16 #define BCH_WRITE_FLAGS()		\
17 	x(alloc_nowait)			\
18 	x(cached)			\
19 	x(data_encoded)			\
20 	x(pages_stable)			\
21 	x(pages_owned)			\
22 	x(only_specified_devs)		\
23 	x(wrote_data_inline)		\
24 	x(check_enospc)			\
25 	x(sync)				\
26 	x(move)				\
27 	x(in_worker)			\
28 	x(submitted)			\
29 	x(io_error)			\
30 	x(convert_unwritten)
31 
32 enum __bch_write_flags {
33 #define x(f)	__BCH_WRITE_##f,
34 	BCH_WRITE_FLAGS()
35 #undef x
36 };
37 
38 enum bch_write_flags {
39 #define x(f)	BCH_WRITE_##f = BIT(__BCH_WRITE_##f),
40 	BCH_WRITE_FLAGS()
41 #undef x
42 };
43 
44 struct bch_write_bio {
45 	struct_group(wbio,
46 	struct bch_fs		*c;
47 	struct bch_write_bio	*parent;
48 
49 	u64			submit_time;
50 	u64			inode_offset;
51 	u64			nocow_bucket;
52 
53 	struct bch_devs_list	failed;
54 	u8			dev;
55 
56 	unsigned		split:1,
57 				bounce:1,
58 				put_bio:1,
59 				have_ioref:1,
60 				nocow:1,
61 				used_mempool:1,
62 				first_btree_write:1;
63 	);
64 
65 	struct bio		bio;
66 };
67 
68 struct bch_write_op {
69 	struct closure		cl;
70 	struct bch_fs		*c;
71 	void			(*end_io)(struct bch_write_op *);
72 	u64			start_time;
73 
74 #ifdef CONFIG_BCACHEFS_ASYNC_OBJECT_LISTS
75 	unsigned		list_idx;
76 #endif
77 
78 	unsigned		written; /* sectors */
79 	u16			flags;
80 	s16			error; /* dio write path expects it to hold -ERESTARTSYS... */
81 
82 	unsigned		compression_opt:8;
83 	unsigned		csum_type:4;
84 	unsigned		nr_replicas:4;
85 	unsigned		nr_replicas_required:4;
86 	unsigned		watermark:3;
87 	unsigned		incompressible:1;
88 	unsigned		stripe_waited:1;
89 
90 	struct bch_devs_list	devs_have;
91 	u16			target;
92 	u16			nonce;
93 	struct bch_io_opts	opts;
94 
95 	u32			subvol;
96 	struct bpos		pos;
97 	struct bversion		version;
98 
99 	/* For BCH_WRITE_data_encoded: */
100 	struct bch_extent_crc_unpacked crc;
101 
102 	struct write_point_specifier write_point;
103 
104 	struct write_point	*wp;
105 	struct list_head	wp_list;
106 
107 	struct disk_reservation	res;
108 
109 	struct open_buckets	open_buckets;
110 
111 	u64			new_i_size;
112 	s64			i_sectors_delta;
113 
114 	struct bch_devs_mask	failed;
115 
116 	struct keylist		insert_keys;
117 	u64			inline_keys[BKEY_EXTENT_U64s_MAX * 2];
118 
119 	/*
120 	 * Bitmask of devices that have had nocow writes issued to them since
121 	 * last flush:
122 	 */
123 	struct bch_devs_mask	*devs_need_flush;
124 
125 	/* Must be last: */
126 	struct bch_write_bio	wbio;
127 };
128 
129 #endif /* _BCACHEFS_IO_WRITE_TYPES_H */
130