diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-09-07 12:39:59 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:08:26 -0400 |
commit | 5055b50939843c027e1cf4602316035d9f21f032 (patch) | |
tree | 7582ea1aaf8f57df9b5ca1a8e3028a49ef61fe42 /fs/bcachefs/rebalance.c | |
parent | 4430ea7046fcb2112c5888705a6a674d53d9db03 (diff) |
bcachefs: Rebalance now adds replicas if needed
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/rebalance.c')
-rw-r--r-- | fs/bcachefs/rebalance.c | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/fs/bcachefs/rebalance.c b/fs/bcachefs/rebalance.c index 0997c0621b7c..9eb3ac856eed 100644 --- a/fs/bcachefs/rebalance.c +++ b/fs/bcachefs/rebalance.c @@ -42,9 +42,6 @@ void bch2_rebalance_add_key(struct bch_fs *c, const union bch_extent_entry *entry; struct extent_ptr_decoded p; - if (!bkey_extent_is_data(k.k)) - return; - if (!io_opts->background_target && !io_opts->background_compression) return; @@ -72,30 +69,26 @@ static enum data_cmd rebalance_pred(struct bch_fs *c, void *arg, struct bch_io_opts *io_opts, struct data_opts *data_opts) { - switch (k.k->type) { - case KEY_TYPE_extent: { - struct bkey_s_c_extent e = bkey_s_c_to_extent(k); - const union bch_extent_entry *entry; - struct extent_ptr_decoded p; - - /* Make sure we have room to add a new pointer: */ - if (bkey_val_u64s(e.k) + BKEY_EXTENT_PTR_U64s_MAX > - BKEY_EXTENT_VAL_U64s_MAX) - return DATA_SKIP; - - extent_for_each_ptr_decode(e, p, entry) - if (rebalance_ptr_pred(c, p, io_opts)) - goto found; - - return DATA_SKIP; -found: - data_opts->target = io_opts->background_target; - data_opts->btree_insert_flags = 0; - return DATA_ADD_REPLICAS; - } - default: - return DATA_SKIP; + struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); + const union bch_extent_entry *entry; + struct extent_ptr_decoded p; + unsigned nr_replicas = 0; + + bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { + nr_replicas += !p.ptr.cached; + + if (rebalance_ptr_pred(c, p, io_opts)) + goto found; } + + if (nr_replicas < io_opts->data_replicas) + goto found; + + return DATA_SKIP; +found: + data_opts->target = io_opts->background_target; + data_opts->btree_insert_flags = 0; + return DATA_ADD_REPLICAS; } struct rebalance_work { |