Commit 9ec211b0 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Fix ec_stripes_read()

The bkey_s_c returned by btree_iter_(peek|next) points into the btree
iter type, so advancing the iterator and then using the one previously
returned is a bug...
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 37954a27
...@@ -1517,7 +1517,7 @@ LE32_BITMASK(JSET_BIG_ENDIAN, struct jset, flags, 4, 5); ...@@ -1517,7 +1517,7 @@ LE32_BITMASK(JSET_BIG_ENDIAN, struct jset, flags, 4, 5);
x(XATTRS, 3, "xattrs") \ x(XATTRS, 3, "xattrs") \
x(ALLOC, 4, "alloc") \ x(ALLOC, 4, "alloc") \
x(QUOTAS, 5, "quotas") \ x(QUOTAS, 5, "quotas") \
x(EC, 6, "erasure_coding") \ x(EC, 6, "stripes") \
x(REFLINK, 7, "reflink") x(REFLINK, 7, "reflink")
enum btree_id { enum btree_id {
......
...@@ -135,8 +135,6 @@ void bch2_stripe_to_text(struct printbuf *out, struct bch_fs *c, ...@@ -135,8 +135,6 @@ void bch2_stripe_to_text(struct printbuf *out, struct bch_fs *c,
pr_buf(out, " %u:%llu:%u", s->ptrs[i].dev, pr_buf(out, " %u:%llu:%u", s->ptrs[i].dev,
(u64) s->ptrs[i].offset, (u64) s->ptrs[i].offset,
stripe_blockcount_get(s, i)); stripe_blockcount_get(s, i));
bch2_bkey_ptrs_to_text(out, c, k);
} }
static int ptr_matches_stripe(struct bch_fs *c, static int ptr_matches_stripe(struct bch_fs *c,
...@@ -1277,7 +1275,7 @@ int bch2_stripes_read(struct bch_fs *c, struct journal_keys *journal_keys) ...@@ -1277,7 +1275,7 @@ int bch2_stripes_read(struct bch_fs *c, struct journal_keys *journal_keys)
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *btree_iter; struct btree_iter *btree_iter;
struct journal_iter journal_iter; struct journal_iter journal_iter;
struct bkey_s_c btree_k, journal_k, k; struct bkey_s_c btree_k, journal_k;
int ret; int ret;
ret = bch2_fs_ec_start(c); ret = bch2_fs_ec_start(c);
...@@ -1293,33 +1291,31 @@ int bch2_stripes_read(struct bch_fs *c, struct journal_keys *journal_keys) ...@@ -1293,33 +1291,31 @@ int bch2_stripes_read(struct bch_fs *c, struct journal_keys *journal_keys)
journal_k = bch2_journal_iter_peek(&journal_iter); journal_k = bch2_journal_iter_peek(&journal_iter);
while (1) { while (1) {
bool btree;
if (btree_k.k && journal_k.k) { if (btree_k.k && journal_k.k) {
int cmp = bkey_cmp(btree_k.k->p, journal_k.k->p); int cmp = bkey_cmp(btree_k.k->p, journal_k.k->p);
if (cmp < 0) { if (!cmp)
k = btree_k;
btree_k = bch2_btree_iter_next(btree_iter); btree_k = bch2_btree_iter_next(btree_iter);
} else if (cmp == 0) { btree = cmp < 0;
btree_k = bch2_btree_iter_next(btree_iter);
k = journal_k;
journal_k = bch2_journal_iter_next(&journal_iter);
} else {
k = journal_k;
journal_k = bch2_journal_iter_next(&journal_iter);
}
} else if (btree_k.k) { } else if (btree_k.k) {
k = btree_k; btree = true;
btree_k = bch2_btree_iter_next(btree_iter);
} else if (journal_k.k) { } else if (journal_k.k) {
k = journal_k; btree = false;
journal_k = bch2_journal_iter_next(&journal_iter);
} else { } else {
break; break;
} }
bch2_mark_key(c, k, 0, 0, NULL, 0, bch2_mark_key(c, btree ? btree_k : journal_k,
0, 0, NULL, 0,
BCH_BUCKET_MARK_ALLOC_READ| BCH_BUCKET_MARK_ALLOC_READ|
BCH_BUCKET_MARK_NOATOMIC); BCH_BUCKET_MARK_NOATOMIC);
if (btree)
btree_k = bch2_btree_iter_next(btree_iter);
else
journal_k = bch2_journal_iter_next(&journal_iter);
} }
ret = bch2_trans_exit(&trans) ?: ret; ret = bch2_trans_exit(&trans) ?: ret;
......
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