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

bcachefs: Fix bch2_sort_repack_merge()

bch2_bkey_normalize() modifies the value, and we were modifying the
original value in the src btree node - but, we're called without a write
lock held on the src node. Oops...
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 76426098
......@@ -415,25 +415,22 @@ bch2_sort_repack_merge(struct bch_fs *c,
struct bkey_format *out_f,
bool filter_whiteouts)
{
struct bkey_packed *prev = NULL, *k_packed, *next;
struct bkey k_unpacked;
struct bkey_packed *prev = NULL, *k_packed;
struct bkey_s k;
struct btree_nr_keys nr;
BKEY_PADDED(k) tmp;
memset(&nr, 0, sizeof(nr));
next = bch2_btree_node_iter_next_all(iter, src);
while ((k_packed = next)) {
/*
* The filter might modify the size of @k's value, so advance
* the iterator first:
*/
next = bch2_btree_node_iter_next_all(iter, src);
while ((k_packed = bch2_btree_node_iter_next_all(iter, src))) {
if (filter_whiteouts && bkey_whiteout(k_packed))
continue;
k = __bkey_disassemble(src, k_packed, &k_unpacked);
EBUG_ON(bkeyp_val_u64s(&src->format, k_packed) >
BKEY_EXTENT_VAL_U64s_MAX);
bch2_bkey_unpack(src, &tmp.k, k_packed);
k = bkey_i_to_s(&tmp.k);
if (filter_whiteouts &&
bch2_bkey_normalize(c, k))
......
......@@ -1590,9 +1590,9 @@ bool bch2_extent_normalize(struct bch_fs *c, struct bkey_s k)
/* will only happen if all pointers were cached: */
if (!bkey_val_u64s(k.k))
k.k->type = KEY_TYPE_deleted;
k.k->type = KEY_TYPE_discard;
return false;
return bkey_whiteout(k.k);
}
void bch2_bkey_mark_replicas_cached(struct bch_fs *c, struct bkey_s k,
......
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