bcachefs: bch2_data_update_init() considers ptr durability

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2023-02-27 23:16:37 -05:00
parent a64adedb86
commit 11bb67a4a3

View File

@ -425,7 +425,7 @@ int bch2_data_update_init(struct btree_trans *trans,
struct extent_ptr_decoded p; struct extent_ptr_decoded p;
const struct bch_extent_ptr *ptr; const struct bch_extent_ptr *ptr;
unsigned i, reserve_sectors = k.k->size * data_opts.extra_replicas; unsigned i, reserve_sectors = k.k->size * data_opts.extra_replicas;
unsigned int ptrs_locked = 0; unsigned ptrs_locked = 0;
int ret; int ret;
bch2_bkey_buf_init(&m->k); bch2_bkey_buf_init(&m->k);
@ -438,6 +438,7 @@ int bch2_data_update_init(struct btree_trans *trans,
m->op.version = k.k->version; m->op.version = k.k->version;
m->op.target = data_opts.target; m->op.target = data_opts.target;
m->op.write_point = wp; m->op.write_point = wp;
m->op.nr_replicas = 0;
m->op.flags |= BCH_WRITE_PAGES_STABLE| m->op.flags |= BCH_WRITE_PAGES_STABLE|
BCH_WRITE_PAGES_OWNED| BCH_WRITE_PAGES_OWNED|
BCH_WRITE_DATA_ENCODED| BCH_WRITE_DATA_ENCODED|
@ -456,17 +457,16 @@ int bch2_data_update_init(struct btree_trans *trans,
bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
bool locked; bool locked;
if (((1U << i) & m->data_opts.rewrite_ptrs) && if (((1U << i) & m->data_opts.rewrite_ptrs)) {
p.ptr.cached) BUG_ON(p.ptr.cached);
BUG();
if (!((1U << i) & m->data_opts.rewrite_ptrs) && if (crc_is_compressed(p.crc))
!p.ptr.cached) reserve_sectors += k.k->size;
m->op.nr_replicas += bch2_extent_ptr_durability(c, &p);
} else if (!p.ptr.cached) {
bch2_dev_list_add_dev(&m->op.devs_have, p.ptr.dev); bch2_dev_list_add_dev(&m->op.devs_have, p.ptr.dev);
}
if (((1U << i) & m->data_opts.rewrite_ptrs) &&
crc_is_compressed(p.crc))
reserve_sectors += k.k->size;
/* /*
* op->csum_type is normally initialized from the fs/file's * op->csum_type is normally initialized from the fs/file's
@ -513,8 +513,8 @@ int bch2_data_update_init(struct btree_trans *trans,
goto err; goto err;
} }
m->op.nr_replicas = m->op.nr_replicas_required = m->op.nr_replicas += m->data_opts.extra_replicas;
hweight32(m->data_opts.rewrite_ptrs) + m->data_opts.extra_replicas; m->op.nr_replicas_required = m->op.nr_replicas;
BUG_ON(!m->op.nr_replicas); BUG_ON(!m->op.nr_replicas);