xref: /linux/fs/bcachefs/data_update.h (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef _BCACHEFS_DATA_UPDATE_H
4 #define _BCACHEFS_DATA_UPDATE_H
5 
6 #include "bkey_buf.h"
7 #include "io_read.h"
8 #include "io_write_types.h"
9 
10 struct moving_context;
11 
12 struct data_update_opts {
13 	unsigned	rewrite_ptrs;
14 	unsigned	kill_ptrs;
15 	u16		target;
16 	u8		extra_replicas;
17 	unsigned	btree_insert_flags;
18 	unsigned	write_flags;
19 
20 	int		read_dev;
21 	bool		scrub;
22 };
23 
24 void bch2_data_update_opts_to_text(struct printbuf *, struct bch_fs *,
25 				   struct bch_io_opts *, struct data_update_opts *);
26 
27 #define BCH_DATA_UPDATE_TYPES()		\
28 	x(copygc,	0)		\
29 	x(rebalance,	1)		\
30 	x(promote,	2)
31 
32 enum bch_data_update_types {
33 #define x(n, id)	BCH_DATA_UPDATE_##n = id,
34 	BCH_DATA_UPDATE_TYPES()
35 #undef x
36 };
37 
38 struct data_update {
39 	enum bch_data_update_types type;
40 	/* extent being updated: */
41 	bool			read_done;
42 	enum btree_id		btree_id;
43 	struct bkey_buf		k;
44 	struct data_update_opts	data_opts;
45 	struct moving_context	*ctxt;
46 	struct bch_move_stats	*stats;
47 
48 	struct bch_read_bio	rbio;
49 	struct bch_write_op	op;
50 	struct bio_vec		*bvecs;
51 };
52 
53 struct promote_op {
54 	struct rcu_head		rcu;
55 	u64			start_time;
56 #ifdef CONFIG_BCACHEFS_ASYNC_OBJECT_LISTS
57 	unsigned		list_idx;
58 #endif
59 
60 	struct rhash_head	hash;
61 	struct bpos		pos;
62 
63 	struct work_struct	work;
64 	struct data_update	write;
65 	struct bio_vec		bi_inline_vecs[]; /* must be last */
66 };
67 
68 void bch2_data_update_to_text(struct printbuf *, struct data_update *);
69 void bch2_data_update_inflight_to_text(struct printbuf *, struct data_update *);
70 
71 int bch2_data_update_index_update(struct bch_write_op *);
72 
73 void bch2_data_update_read_done(struct data_update *);
74 
75 int bch2_extent_drop_ptrs(struct btree_trans *,
76 			  struct btree_iter *,
77 			  struct bkey_s_c,
78 			  struct bch_io_opts *,
79 			  struct data_update_opts *);
80 
81 int bch2_data_update_bios_init(struct data_update *, struct bch_fs *,
82 			       struct bch_io_opts *);
83 
84 void bch2_data_update_exit(struct data_update *);
85 int bch2_data_update_init(struct btree_trans *, struct btree_iter *,
86 			  struct moving_context *,
87 			  struct data_update *,
88 			  struct write_point_specifier,
89 			  struct bch_io_opts *, struct data_update_opts,
90 			  enum btree_id, struct bkey_s_c);
91 void bch2_data_update_opts_normalize(struct bkey_s_c, struct data_update_opts *);
92 
93 #endif /* _BCACHEFS_DATA_UPDATE_H */
94