Commit 91ecd41b authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_extent_ptr_desired_durability()

This adds a new helper for getting a pointer's durability irrespective
of the device state, and uses it in the the data update path.

This fixes a bug where we do a data update but request 0 replicas to be
allocated, because the replica being rewritten is on a device marked as
failed.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 253748a2
...@@ -474,7 +474,7 @@ int bch2_data_update_init(struct btree_trans *trans, ...@@ -474,7 +474,7 @@ int bch2_data_update_init(struct btree_trans *trans,
if (crc_is_compressed(p.crc)) if (crc_is_compressed(p.crc))
reserve_sectors += k.k->size; reserve_sectors += k.k->size;
m->op.nr_replicas += bch2_extent_ptr_durability(c, &p); m->op.nr_replicas += bch2_extent_ptr_desired_durability(c, &p);
} else if (!p.ptr.cached) { } 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);
} }
......
...@@ -641,9 +641,8 @@ unsigned bch2_bkey_replicas(struct bch_fs *c, struct bkey_s_c k) ...@@ -641,9 +641,8 @@ unsigned bch2_bkey_replicas(struct bch_fs *c, struct bkey_s_c k)
return replicas; return replicas;
} }
unsigned bch2_extent_ptr_durability(struct bch_fs *c, struct extent_ptr_decoded *p) unsigned bch2_extent_ptr_desired_durability(struct bch_fs *c, struct extent_ptr_decoded *p)
{ {
unsigned durability = 0;
struct bch_dev *ca; struct bch_dev *ca;
if (p->ptr.cached) if (p->ptr.cached)
...@@ -651,13 +650,28 @@ unsigned bch2_extent_ptr_durability(struct bch_fs *c, struct extent_ptr_decoded ...@@ -651,13 +650,28 @@ unsigned bch2_extent_ptr_durability(struct bch_fs *c, struct extent_ptr_decoded
ca = bch_dev_bkey_exists(c, p->ptr.dev); ca = bch_dev_bkey_exists(c, p->ptr.dev);
if (ca->mi.state != BCH_MEMBER_STATE_failed) return ca->mi.durability +
durability = max_t(unsigned, durability, ca->mi.durability); (p->has_ec
? p->ec.redundancy
: 0);
}
if (p->has_ec) unsigned bch2_extent_ptr_durability(struct bch_fs *c, struct extent_ptr_decoded *p)
durability += p->ec.redundancy; {
struct bch_dev *ca;
return durability; if (p->ptr.cached)
return 0;
ca = bch_dev_bkey_exists(c, p->ptr.dev);
if (ca->mi.state == BCH_MEMBER_STATE_failed)
return 0;
return ca->mi.durability +
(p->has_ec
? p->ec.redundancy
: 0);
} }
unsigned bch2_bkey_durability(struct bch_fs *c, struct bkey_s_c k) unsigned bch2_bkey_durability(struct bch_fs *c, struct bkey_s_c k)
......
...@@ -610,6 +610,7 @@ bool bch2_bkey_is_incompressible(struct bkey_s_c); ...@@ -610,6 +610,7 @@ bool bch2_bkey_is_incompressible(struct bkey_s_c);
unsigned bch2_bkey_sectors_compressed(struct bkey_s_c); unsigned bch2_bkey_sectors_compressed(struct bkey_s_c);
unsigned bch2_bkey_replicas(struct bch_fs *, struct bkey_s_c); unsigned bch2_bkey_replicas(struct bch_fs *, struct bkey_s_c);
unsigned bch2_extent_ptr_desired_durability(struct bch_fs *, struct extent_ptr_decoded *);
unsigned bch2_extent_ptr_durability(struct bch_fs *, struct extent_ptr_decoded *); unsigned bch2_extent_ptr_durability(struct bch_fs *, struct extent_ptr_decoded *);
unsigned bch2_bkey_durability(struct bch_fs *, struct bkey_s_c); unsigned bch2_bkey_durability(struct bch_fs *, struct bkey_s_c);
......
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