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

bcachefs: Fix freespace initialization

bch2_dev_freespace_init() was using __bch2_trans_do() incorrectly, and
calling bch2_bucket_do_index() with a stale alloc key.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 401ec4db
...@@ -1190,12 +1190,26 @@ void bch2_do_invalidates(struct bch_fs *c) ...@@ -1190,12 +1190,26 @@ void bch2_do_invalidates(struct bch_fs *c)
queue_work(system_long_wq, &c->invalidate_work); queue_work(system_long_wq, &c->invalidate_work);
} }
static int bucket_freespace_init(struct btree_trans *trans, struct btree_iter *iter)
{
struct bch_alloc_v4 a;
struct bkey_s_c k;
int ret;
k = bch2_btree_iter_peek_slot(iter);
ret = bkey_err(k);
if (ret)
return ret;
bch2_alloc_to_v4(k, &a);
return bch2_bucket_do_index(trans, k, &a, true);
}
static int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca) static int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca)
{ {
struct btree_trans trans; struct btree_trans trans;
struct btree_iter iter; struct btree_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bch_alloc_v4 a;
struct bch_member *m; struct bch_member *m;
int ret; int ret;
...@@ -1208,10 +1222,9 @@ static int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca) ...@@ -1208,10 +1222,9 @@ static int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca)
if (iter.pos.offset >= ca->mi.nbuckets) if (iter.pos.offset >= ca->mi.nbuckets)
break; break;
bch2_alloc_to_v4(k, &a);
ret = __bch2_trans_do(&trans, NULL, NULL, ret = __bch2_trans_do(&trans, NULL, NULL,
BTREE_INSERT_LAZY_RW, BTREE_INSERT_LAZY_RW,
bch2_bucket_do_index(&trans, k, &a, true)); bucket_freespace_init(&trans, &iter));
if (ret) if (ret)
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