summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-06-10 19:39:00 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2022-06-16 22:01:09 -0400
commitf469dfd8b72fb46a928a549501e82063f06c2981 (patch)
tree3c51b37f44d1c1e4ae7237a9c2a7eaa84ffd02d0
parent00f556b17dbf0d0c06c4dcaea6b3bda1048a47a5 (diff)
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: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--fs/bcachefs/alloc_background.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c
index d114ba0949a8..86df10e67ce7 100644
--- a/fs/bcachefs/alloc_background.c
+++ b/fs/bcachefs/alloc_background.c
@@ -1190,12 +1190,26 @@ void bch2_do_invalidates(struct bch_fs *c)
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)
{
struct btree_trans trans;
struct btree_iter iter;
struct bkey_s_c k;
- struct bch_alloc_v4 a;
struct bch_member *m;
int ret;
@@ -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)
break;
- bch2_alloc_to_v4(k, &a);
ret = __bch2_trans_do(&trans, NULL, NULL,
BTREE_INSERT_LAZY_RW,
- bch2_bucket_do_index(&trans, k, &a, true));
+ bucket_freespace_init(&trans, &iter));
if (ret)
break;
}