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

bcachefs: Convert bch2_dev_freespace_init() to for_each_btree_key_commit()

The new for_each_btree_key2() macro handles transaction retries,
allowing us to avoid nested transactions - which we want to avoid since
they're tricky to do completely correctly and upcoming assertions are
going to be checking for that.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 4910a950
...@@ -1218,16 +1218,13 @@ void bch2_do_invalidates(struct bch_fs *c) ...@@ -1218,16 +1218,13 @@ void bch2_do_invalidates(struct bch_fs *c)
percpu_ref_put(&c->writes); percpu_ref_put(&c->writes);
} }
static int bucket_freespace_init(struct btree_trans *trans, struct btree_iter *iter) static int bucket_freespace_init(struct btree_trans *trans, struct btree_iter *iter,
struct bkey_s_c k, struct bch_dev *ca)
{ {
struct bch_alloc_v4 a; struct bch_alloc_v4 a;
struct bkey_s_c k;
int ret;
k = bch2_btree_iter_peek_slot(iter); if (iter->pos.offset >= ca->mi.nbuckets)
ret = bkey_err(k); return 1;
if (ret)
return ret;
bch2_alloc_to_v4(k, &a); bch2_alloc_to_v4(k, &a);
return bch2_bucket_do_index(trans, k, &a, true); return bch2_bucket_do_index(trans, k, &a, true);
...@@ -1243,24 +1240,15 @@ static int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca) ...@@ -1243,24 +1240,15 @@ static int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca)
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
for_each_btree_key(&trans, iter, BTREE_ID_alloc, ret = for_each_btree_key_commit(&trans, iter, BTREE_ID_alloc,
POS(ca->dev_idx, ca->mi.first_bucket), POS(ca->dev_idx, ca->mi.first_bucket),
BTREE_ITER_SLOTS| BTREE_ITER_SLOTS|BTREE_ITER_PREFETCH, k,
BTREE_ITER_PREFETCH, k, ret) { NULL, NULL, BTREE_INSERT_LAZY_RW,
if (iter.pos.offset >= ca->mi.nbuckets) bucket_freespace_init(&trans, &iter, k, ca));
break;
ret = commit_do(&trans, NULL, NULL,
BTREE_INSERT_LAZY_RW,
bucket_freespace_init(&trans, &iter));
if (ret)
break;
}
bch2_trans_iter_exit(&trans, &iter);
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
if (ret) { if (ret < 0) {
bch_err(ca, "error initializing free space: %i", ret); bch_err(ca, "error initializing free space: %i", ret);
return ret; return ret;
} }
...@@ -1270,7 +1258,7 @@ static int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca) ...@@ -1270,7 +1258,7 @@ static int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca)
SET_BCH_MEMBER_FREESPACE_INITIALIZED(m, true); SET_BCH_MEMBER_FREESPACE_INITIALIZED(m, true);
mutex_unlock(&c->sb_lock); mutex_unlock(&c->sb_lock);
return ret; return 0;
} }
int bch2_fs_freespace_init(struct bch_fs *c) int bch2_fs_freespace_init(struct bch_fs *c)
......
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