Skip to content

Commit bd864bc

Browse files
author
Kent Overstreet
committed
bcachefs: Fix bch2_trigger_alloc when upgrading from old versions
bch2_trigger_alloc was assuming that the new key would always be newly created and thus always an alloc_v4 key, but - not when called from btree_gc. Signed-off-by: Kent Overstreet <[email protected]>
1 parent a24e6e7 commit bd864bc

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

fs/bcachefs/alloc_background.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,19 @@ int bch2_trigger_alloc(struct btree_trans *trans,
829829

830830
struct bch_alloc_v4 old_a_convert;
831831
const struct bch_alloc_v4 *old_a = bch2_alloc_to_v4(old, &old_a_convert);
832-
struct bch_alloc_v4 *new_a = bkey_s_to_alloc_v4(new).v;
832+
833+
struct bch_alloc_v4 *new_a;
834+
if (likely(new.k->type == KEY_TYPE_alloc_v4)) {
835+
new_a = bkey_s_to_alloc_v4(new).v;
836+
} else {
837+
BUG_ON(!(flags & BTREE_TRIGGER_gc));
838+
839+
struct bkey_i_alloc_v4 *new_ka = bch2_alloc_to_v4_mut_inlined(trans, new.s_c);
840+
ret = PTR_ERR_OR_ZERO(new_ka);
841+
if (unlikely(ret))
842+
goto err;
843+
new_a = &new_ka->v;
844+
}
833845

834846
if (flags & BTREE_TRIGGER_transactional) {
835847
alloc_data_type_set(new_a, new_a->data_type);

0 commit comments

Comments
 (0)