xref: /linux/fs/bcachefs/rebalance.h (revision 94b481f7671f412b571e4ee5e3b24f33a889812d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_REBALANCE_H
3 #define _BCACHEFS_REBALANCE_H
4 
5 #include "compress.h"
6 #include "disk_groups.h"
7 #include "opts.h"
8 #include "rebalance_types.h"
9 
io_opts_to_rebalance_opts(struct bch_fs * c,struct bch_io_opts * opts)10 static inline struct bch_extent_rebalance io_opts_to_rebalance_opts(struct bch_fs *c,
11 								    struct bch_io_opts *opts)
12 {
13 	struct bch_extent_rebalance r = {
14 		.type = BIT(BCH_EXTENT_ENTRY_rebalance),
15 #define x(_name)							\
16 		._name = opts->_name,					\
17 		._name##_from_inode = opts->_name##_from_inode,
18 		BCH_REBALANCE_OPTS()
19 #undef x
20 	};
21 
22 	if (r.background_target &&
23 	    !bch2_target_accepts_data(c, BCH_DATA_user, r.background_target))
24 		r.background_target = 0;
25 
26 	return r;
27 };
28 
29 u64 bch2_bkey_sectors_need_rebalance(struct bch_fs *, struct bkey_s_c);
30 int bch2_bkey_set_needs_rebalance(struct bch_fs *, struct bch_io_opts *, struct bkey_i *);
31 int bch2_get_update_rebalance_opts(struct btree_trans *,
32 				   struct bch_io_opts *,
33 				   struct btree_iter *,
34 				   struct bkey_s_c);
35 
36 int bch2_set_rebalance_needs_scan_trans(struct btree_trans *, u64);
37 int bch2_set_rebalance_needs_scan(struct bch_fs *, u64 inum);
38 int bch2_set_fs_needs_rebalance(struct bch_fs *);
39 
rebalance_wakeup(struct bch_fs * c)40 static inline void rebalance_wakeup(struct bch_fs *c)
41 {
42 	struct task_struct *p;
43 
44 	rcu_read_lock();
45 	p = rcu_dereference(c->rebalance.thread);
46 	if (p)
47 		wake_up_process(p);
48 	rcu_read_unlock();
49 }
50 
51 void bch2_rebalance_status_to_text(struct printbuf *, struct bch_fs *);
52 
53 void bch2_rebalance_stop(struct bch_fs *);
54 int bch2_rebalance_start(struct bch_fs *);
55 void bch2_fs_rebalance_init(struct bch_fs *);
56 
57 #endif /* _BCACHEFS_REBALANCE_H */
58