diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2021-12-25 20:07:00 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:21 -0400 |
commit | 5222a4607cd8b9d8882e81796917c10193d10be0 (patch) | |
tree | b68fb2d883efdb75eaf1376c9f2a0baf30fb30fc /fs/bcachefs/ec.c | |
parent | f28620c108a9476c7b4b25b8e36b94b6b2b29295 (diff) | |
download | lwn-5222a4607cd8b9d8882e81796917c10193d10be0.tar.gz lwn-5222a4607cd8b9d8882e81796917c10193d10be0.zip |
bcachefs: BTREE_ITER_WITH_JOURNAL
This adds a new btree iterator flag, BTREE_ITER_WITH_JOURNAL, that is
automatically enabled when initializing a btree iterator before journal
replay has completed - it overlays the contents of the journal with the
btree.
This lets us delete bch2_btree_and_journal_walk() and just use the
normal btree iterator interface instead - which also lets us delete a
significant amount of duplicated code.
Note that BTREE_ITER_WITH_JOURNAL is still unoptimized in this patch -
we're redoing the binary search over keys in the journal every time we
call bch2_btree_iter_peek().
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/ec.c')
-rw-r--r-- | fs/bcachefs/ec.c | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c index e18d2ecf7f07..86421f65d139 100644 --- a/fs/bcachefs/ec.c +++ b/fs/bcachefs/ec.c @@ -1558,50 +1558,48 @@ void bch2_stripes_heap_start(struct bch_fs *c) bch2_stripes_heap_insert(c, m, iter.pos); } -static int bch2_stripes_read_fn(struct btree_trans *trans, struct bkey_s_c k) +int bch2_stripes_read(struct bch_fs *c) { + struct btree_trans trans; + struct btree_iter iter; + struct bkey_s_c k; const struct bch_stripe *s; - struct bch_fs *c = trans->c; struct stripe *m; unsigned i; - int ret = 0; + int ret; - if (k.k->type != KEY_TYPE_stripe) - return 0; + bch2_trans_init(&trans, c, 0, 0); - ret = __ec_stripe_mem_alloc(c, k.k->p.offset, GFP_KERNEL); - if (ret) - return ret; + for_each_btree_key(&trans, iter, BTREE_ID_stripes, POS_MIN, + BTREE_ITER_PREFETCH, k, ret) { + if (k.k->type != KEY_TYPE_stripe) + continue; - s = bkey_s_c_to_stripe(k).v; + ret = __ec_stripe_mem_alloc(c, k.k->p.offset, GFP_KERNEL); + if (ret) + break; - m = genradix_ptr(&c->stripes, k.k->p.offset); - m->alive = true; - m->sectors = le16_to_cpu(s->sectors); - m->algorithm = s->algorithm; - m->nr_blocks = s->nr_blocks; - m->nr_redundant = s->nr_redundant; - m->blocks_nonempty = 0; + s = bkey_s_c_to_stripe(k).v; - for (i = 0; i < s->nr_blocks; i++) - m->blocks_nonempty += !!stripe_blockcount_get(s, i); + m = genradix_ptr(&c->stripes, k.k->p.offset); + m->alive = true; + m->sectors = le16_to_cpu(s->sectors); + m->algorithm = s->algorithm; + m->nr_blocks = s->nr_blocks; + m->nr_redundant = s->nr_redundant; + m->blocks_nonempty = 0; - spin_lock(&c->ec_stripes_heap_lock); - bch2_stripes_heap_update(c, m, k.k->p.offset); - spin_unlock(&c->ec_stripes_heap_lock); - - return ret; -} + for (i = 0; i < s->nr_blocks; i++) + m->blocks_nonempty += !!stripe_blockcount_get(s, i); -int bch2_stripes_read(struct bch_fs *c) -{ - struct btree_trans trans; - int ret; + spin_lock(&c->ec_stripes_heap_lock); + bch2_stripes_heap_update(c, m, k.k->p.offset); + spin_unlock(&c->ec_stripes_heap_lock); + } + bch2_trans_iter_exit(&trans, &iter); - bch2_trans_init(&trans, c, 0, 0); - ret = bch2_btree_and_journal_walk(&trans, BTREE_ID_stripes, - bch2_stripes_read_fn); bch2_trans_exit(&trans); + if (ret) bch_err(c, "error reading stripes: %i", ret); |