Commit 5055b509 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Rebalance now adds replicas if needed

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 4430ea70
...@@ -661,7 +661,7 @@ struct bch_reservation { ...@@ -661,7 +661,7 @@ struct bch_reservation {
/* Maximum possible size of an entire extent value: */ /* Maximum possible size of an entire extent value: */
#define BKEY_EXTENT_VAL_U64s_MAX \ #define BKEY_EXTENT_VAL_U64s_MAX \
(BKEY_EXTENT_PTR_U64s_MAX * (BCH_REPLICAS_MAX + 1)) (1 + BKEY_EXTENT_PTR_U64s_MAX * (BCH_REPLICAS_MAX + 1))
#define BKEY_PADDED(key) __BKEY_PADDED(key, BKEY_EXTENT_VAL_U64s_MAX) #define BKEY_PADDED(key) __BKEY_PADDED(key, BKEY_EXTENT_VAL_U64s_MAX)
......
...@@ -42,9 +42,6 @@ void bch2_rebalance_add_key(struct bch_fs *c, ...@@ -42,9 +42,6 @@ void bch2_rebalance_add_key(struct bch_fs *c,
const union bch_extent_entry *entry; const union bch_extent_entry *entry;
struct extent_ptr_decoded p; struct extent_ptr_decoded p;
if (!bkey_extent_is_data(k.k))
return;
if (!io_opts->background_target && if (!io_opts->background_target &&
!io_opts->background_compression) !io_opts->background_compression)
return; return;
...@@ -72,30 +69,26 @@ static enum data_cmd rebalance_pred(struct bch_fs *c, void *arg, ...@@ -72,30 +69,26 @@ static enum data_cmd rebalance_pred(struct bch_fs *c, void *arg,
struct bch_io_opts *io_opts, struct bch_io_opts *io_opts,
struct data_opts *data_opts) struct data_opts *data_opts)
{ {
switch (k.k->type) { struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
case KEY_TYPE_extent: { const union bch_extent_entry *entry;
struct bkey_s_c_extent e = bkey_s_c_to_extent(k); struct extent_ptr_decoded p;
const union bch_extent_entry *entry; unsigned nr_replicas = 0;
struct extent_ptr_decoded p;
bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
/* Make sure we have room to add a new pointer: */ nr_replicas += !p.ptr.cached;
if (bkey_val_u64s(e.k) + BKEY_EXTENT_PTR_U64s_MAX >
BKEY_EXTENT_VAL_U64s_MAX) if (rebalance_ptr_pred(c, p, io_opts))
return DATA_SKIP; goto found;
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;
} }
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 { struct rebalance_work {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment