Commit df5d4dae authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Fixes for replicas tracking

The continue statement in bch2_trans_mark_extent() was wrong - by
bailing out early, we'd be constructing the wrong replicas list to
update. Also, the assertion in update_replicas() was wrong - due to
rounding with compressed extents, it is possible for sectors to be 0
sometimes.

Also, change extent_to_replicas() in replicas.c to match the replicas
list we construct in buckets.c.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 6671a708
...@@ -520,7 +520,6 @@ static inline void update_replicas(struct bch_fs *c, ...@@ -520,7 +520,6 @@ static inline void update_replicas(struct bch_fs *c,
int idx = bch2_replicas_entry_idx(c, r); int idx = bch2_replicas_entry_idx(c, r);
BUG_ON(idx < 0); BUG_ON(idx < 0);
BUG_ON(!sectors);
switch (r->data_type) { switch (r->data_type) {
case BCH_DATA_BTREE: case BCH_DATA_BTREE:
...@@ -569,8 +568,12 @@ static inline void update_replicas_list(struct btree_trans *trans, ...@@ -569,8 +568,12 @@ static inline void update_replicas_list(struct btree_trans *trans,
{ {
struct replicas_delta_list *d; struct replicas_delta_list *d;
struct replicas_delta *n; struct replicas_delta *n;
unsigned b = replicas_entry_bytes(r) + 8; unsigned b;
if (!sectors)
return;
b = replicas_entry_bytes(r) + 8;
d = replicas_deltas_realloc(trans, b); d = replicas_deltas_realloc(trans, b);
n = (void *) d->d + d->used; n = (void *) d->d + d->used;
...@@ -1029,7 +1032,7 @@ static int bch2_mark_extent(struct bch_fs *c, struct bkey_s_c k, ...@@ -1029,7 +1032,7 @@ static int bch2_mark_extent(struct bch_fs *c, struct bkey_s_c k,
fs_usage, journal_seq, flags); fs_usage, journal_seq, flags);
if (p.ptr.cached) { if (p.ptr.cached) {
if (disk_sectors && !stale) if (!stale)
update_cached_sectors(c, fs_usage, p.ptr.dev, update_cached_sectors(c, fs_usage, p.ptr.dev,
disk_sectors); disk_sectors);
} else if (!p.ec_nr) { } else if (!p.ec_nr) {
...@@ -1048,8 +1051,7 @@ static int bch2_mark_extent(struct bch_fs *c, struct bkey_s_c k, ...@@ -1048,8 +1051,7 @@ static int bch2_mark_extent(struct bch_fs *c, struct bkey_s_c k,
} }
} }
if (dirty_sectors) update_replicas(c, fs_usage, &r.e, dirty_sectors);
update_replicas(c, fs_usage, &r.e, dirty_sectors);
return 0; return 0;
} }
...@@ -1561,12 +1563,6 @@ static int bch2_trans_mark_extent(struct btree_trans *trans, ...@@ -1561,12 +1563,6 @@ static int bch2_trans_mark_extent(struct btree_trans *trans,
? sectors ? sectors
: ptr_disk_sectors_delta(p, offset, sectors, flags); : ptr_disk_sectors_delta(p, offset, sectors, flags);
/*
* can happen due to rounding with compressed extents:
*/
if (!disk_sectors)
continue;
ret = bch2_trans_mark_pointer(trans, p, disk_sectors, ret = bch2_trans_mark_pointer(trans, p, disk_sectors,
data_type); data_type);
if (ret < 0) if (ret < 0)
...@@ -1575,7 +1571,7 @@ static int bch2_trans_mark_extent(struct btree_trans *trans, ...@@ -1575,7 +1571,7 @@ static int bch2_trans_mark_extent(struct btree_trans *trans,
stale = ret > 0; stale = ret > 0;
if (p.ptr.cached) { if (p.ptr.cached) {
if (disk_sectors && !stale) if (!stale)
update_cached_sectors_list(trans, p.ptr.dev, update_cached_sectors_list(trans, p.ptr.dev,
disk_sectors); disk_sectors);
} else if (!p.ec_nr) { } else if (!p.ec_nr) {
...@@ -1593,8 +1589,7 @@ static int bch2_trans_mark_extent(struct btree_trans *trans, ...@@ -1593,8 +1589,7 @@ static int bch2_trans_mark_extent(struct btree_trans *trans,
} }
} }
if (dirty_sectors) update_replicas_list(trans, &r.e, dirty_sectors);
update_replicas_list(trans, &r.e, dirty_sectors);
return 0; return 0;
} }
......
...@@ -80,7 +80,7 @@ static void extent_to_replicas(struct bkey_s_c k, ...@@ -80,7 +80,7 @@ static void extent_to_replicas(struct bkey_s_c k,
continue; continue;
if (p.ec_nr) { if (p.ec_nr) {
r->nr_devs = 0; r->nr_required = 0;
break; break;
} }
......
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