bcachefs: Simplify option logic in rebalance
Since bch2_move_get_io_opts() now synchronizes io_opts with options from bch_extent_rebalance, delete the ad-hoc logic in rebalance.c that previously did this. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
+10
-10
@@ -1447,14 +1447,15 @@ const struct bch_extent_rebalance *bch2_bkey_rebalance_opts(struct bkey_s_c k)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c, struct bkey_s_c k,
|
||||
unsigned target, unsigned compression)
|
||||
unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c,
|
||||
struct bch_io_opts *opts,
|
||||
struct bkey_s_c k)
|
||||
{
|
||||
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
|
||||
unsigned rewrite_ptrs = 0;
|
||||
|
||||
if (compression) {
|
||||
unsigned compression_type = bch2_compression_opt_to_type(compression);
|
||||
if (opts->background_compression) {
|
||||
unsigned compression_type = bch2_compression_opt_to_type(opts->background_compression);
|
||||
const union bch_extent_entry *entry;
|
||||
struct extent_ptr_decoded p;
|
||||
unsigned ptr_bit = 1;
|
||||
@@ -1472,11 +1473,12 @@ unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c, struct bkey_s_c k,
|
||||
}
|
||||
}
|
||||
incompressible:
|
||||
if (target && bch2_target_accepts_data(c, BCH_DATA_user, target)) {
|
||||
if (opts->background_target &&
|
||||
bch2_target_accepts_data(c, BCH_DATA_user, opts->background_target)) {
|
||||
unsigned ptr_bit = 1;
|
||||
|
||||
bkey_for_each_ptr(ptrs, ptr) {
|
||||
if (!ptr->cached && !bch2_dev_in_target(c, ptr->dev, target))
|
||||
if (!ptr->cached && !bch2_dev_in_target(c, ptr->dev, opts->background_target))
|
||||
rewrite_ptrs |= ptr_bit;
|
||||
ptr_bit <<= 1;
|
||||
}
|
||||
@@ -1529,8 +1531,7 @@ bool bch2_bkey_rebalance_needs_update(struct bch_fs *c, struct bch_io_opts *opts
|
||||
|
||||
const struct bch_extent_rebalance *old = bch2_bkey_rebalance_opts(k);
|
||||
|
||||
if (k.k->type == KEY_TYPE_reflink_v ||
|
||||
bch2_bkey_ptrs_need_rebalance(c, k, opts->background_target, opts->background_compression)) {
|
||||
if (k.k->type == KEY_TYPE_reflink_v || bch2_bkey_ptrs_need_rebalance(c, opts, k)) {
|
||||
struct bch_extent_rebalance new = io_opts_to_rebalance_opts(opts);
|
||||
return old == NULL || memcmp(old, &new, sizeof(new));
|
||||
} else {
|
||||
@@ -1548,8 +1549,7 @@ int bch2_bkey_set_needs_rebalance(struct bch_fs *c, struct bch_io_opts *opts,
|
||||
struct bch_extent_rebalance *old =
|
||||
(struct bch_extent_rebalance *) bch2_bkey_rebalance_opts(k.s_c);
|
||||
|
||||
if (k.k->type == KEY_TYPE_reflink_v ||
|
||||
bch2_bkey_ptrs_need_rebalance(c, k.s_c, opts->background_target, opts->background_compression)) {
|
||||
if (k.k->type == KEY_TYPE_reflink_v || bch2_bkey_ptrs_need_rebalance(c, opts, k.s_c)) {
|
||||
if (!old) {
|
||||
old = bkey_val_end(k);
|
||||
k.k->u64s += sizeof(*old) / sizeof(u64);
|
||||
|
||||
@@ -711,8 +711,7 @@ static inline bool bch2_extent_ptr_eq(struct bch_extent_ptr ptr1,
|
||||
void bch2_ptr_swab(struct bkey_s);
|
||||
|
||||
const struct bch_extent_rebalance *bch2_bkey_rebalance_opts(struct bkey_s_c);
|
||||
unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *, struct bkey_s_c,
|
||||
unsigned, unsigned);
|
||||
unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *, struct bch_io_opts *, struct bkey_s_c);
|
||||
u64 bch2_bkey_sectors_need_rebalance(struct bch_fs *, struct bkey_s_c);
|
||||
|
||||
bool bch2_bkey_rebalance_needs_update(struct bch_fs *, struct bch_io_opts *, struct bkey_s_c);
|
||||
|
||||
+15
-32
@@ -121,6 +121,9 @@ static int bch2_bkey_clear_needs_rebalance(struct btree_trans *trans,
|
||||
struct btree_iter *iter,
|
||||
struct bkey_s_c k)
|
||||
{
|
||||
if (!bch2_bkey_rebalance_opts(k))
|
||||
return 0;
|
||||
|
||||
struct bkey_i *n = bch2_bkey_make_mut(trans, iter, &k, 0);
|
||||
int ret = PTR_ERR_OR_ZERO(n);
|
||||
if (ret)
|
||||
@@ -134,31 +137,27 @@ static int bch2_bkey_clear_needs_rebalance(struct btree_trans *trans,
|
||||
static struct bkey_s_c next_rebalance_extent(struct btree_trans *trans,
|
||||
struct bpos work_pos,
|
||||
struct btree_iter *extent_iter,
|
||||
struct bch_io_opts *io_opts,
|
||||
struct data_update_opts *data_opts)
|
||||
{
|
||||
struct bch_fs *c = trans->c;
|
||||
struct bkey_s_c k;
|
||||
|
||||
bch2_trans_iter_exit(trans, extent_iter);
|
||||
bch2_trans_iter_init(trans, extent_iter,
|
||||
work_pos.inode ? BTREE_ID_extents : BTREE_ID_reflink,
|
||||
work_pos,
|
||||
BTREE_ITER_all_snapshots);
|
||||
k = bch2_btree_iter_peek_slot(extent_iter);
|
||||
struct bkey_s_c k = bch2_btree_iter_peek_slot(extent_iter);
|
||||
if (bkey_err(k))
|
||||
return k;
|
||||
|
||||
const struct bch_extent_rebalance *r = k.k ? bch2_bkey_rebalance_opts(k) : NULL;
|
||||
if (!r) {
|
||||
/* raced due to btree write buffer, nothing to do */
|
||||
return bkey_s_c_null;
|
||||
}
|
||||
int ret = bch2_move_get_io_opts_one(trans, io_opts, extent_iter, k);
|
||||
if (ret)
|
||||
return bkey_s_c_err(ret);
|
||||
|
||||
memset(data_opts, 0, sizeof(*data_opts));
|
||||
|
||||
data_opts->rewrite_ptrs =
|
||||
bch2_bkey_ptrs_need_rebalance(c, k, r->background_target, r->background_compression);
|
||||
data_opts->target = r->background_target;
|
||||
data_opts->rewrite_ptrs = bch2_bkey_ptrs_need_rebalance(c, io_opts, k);
|
||||
data_opts->target = io_opts->background_target;
|
||||
data_opts->write_flags |= BCH_WRITE_ONLY_SPECIFIED_DEVS;
|
||||
|
||||
if (!data_opts->rewrite_ptrs) {
|
||||
@@ -179,9 +178,9 @@ static struct bkey_s_c next_rebalance_extent(struct btree_trans *trans,
|
||||
struct printbuf buf = PRINTBUF;
|
||||
|
||||
prt_str(&buf, "target=");
|
||||
bch2_target_to_text(&buf, c, r->background_target);
|
||||
bch2_target_to_text(&buf, c, io_opts->background_target);
|
||||
prt_str(&buf, " compression=");
|
||||
bch2_compression_opt_to_text(&buf, r->background_compression);
|
||||
bch2_compression_opt_to_text(&buf, io_opts->background_compression);
|
||||
prt_str(&buf, " ");
|
||||
bch2_bkey_val_to_text(&buf, c, k);
|
||||
|
||||
@@ -212,14 +211,10 @@ static int do_rebalance_extent(struct moving_context *ctxt,
|
||||
bch2_bkey_buf_init(&sk);
|
||||
|
||||
ret = bkey_err(k = next_rebalance_extent(trans, work_pos,
|
||||
extent_iter, &data_opts));
|
||||
extent_iter, &io_opts, &data_opts));
|
||||
if (ret || !k.k)
|
||||
goto out;
|
||||
|
||||
ret = bch2_move_get_io_opts_one(trans, &io_opts, extent_iter, k);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
atomic64_add(k.k->size, &ctxt->stats->sectors_seen);
|
||||
|
||||
/*
|
||||
@@ -253,20 +248,8 @@ static bool rebalance_pred(struct bch_fs *c, void *arg,
|
||||
struct bch_io_opts *io_opts,
|
||||
struct data_update_opts *data_opts)
|
||||
{
|
||||
unsigned target, compression;
|
||||
|
||||
if (k.k->p.inode) {
|
||||
target = io_opts->background_target;
|
||||
compression = io_opts->background_compression;
|
||||
} else {
|
||||
const struct bch_extent_rebalance *r = bch2_bkey_rebalance_opts(k);
|
||||
|
||||
target = r ? r->background_target : io_opts->background_target;
|
||||
compression = r ? r->background_compression : io_opts->background_compression;
|
||||
}
|
||||
|
||||
data_opts->rewrite_ptrs = bch2_bkey_ptrs_need_rebalance(c, k, target, compression);
|
||||
data_opts->target = target;
|
||||
data_opts->rewrite_ptrs = bch2_bkey_ptrs_need_rebalance(c, io_opts, k);
|
||||
data_opts->target = io_opts->background_target;
|
||||
data_opts->write_flags |= BCH_WRITE_ONLY_SPECIFIED_DEVS;
|
||||
return data_opts->rewrite_ptrs != 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user