Commit 511b629a authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_btree_iter_peek_node_and_restart()

Minor refactoring for the Rust interface.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent b65499b7
...@@ -1723,6 +1723,17 @@ struct btree *bch2_btree_iter_peek_node(struct btree_iter *iter) ...@@ -1723,6 +1723,17 @@ struct btree *bch2_btree_iter_peek_node(struct btree_iter *iter)
goto out; goto out;
} }
struct btree *bch2_btree_iter_peek_node_and_restart(struct btree_iter *iter)
{
struct btree *b;
while (b = bch2_btree_iter_peek_node(iter),
bch2_err_matches(PTR_ERR_OR_ZERO(b), BCH_ERR_transaction_restart))
bch2_trans_begin(iter->trans);
return b;
}
struct btree *bch2_btree_iter_next_node(struct btree_iter *iter) struct btree *bch2_btree_iter_next_node(struct btree_iter *iter)
{ {
struct btree_trans *trans = iter->trans; struct btree_trans *trans = iter->trans;
......
...@@ -294,6 +294,7 @@ int __must_check __bch2_btree_iter_traverse(struct btree_iter *iter); ...@@ -294,6 +294,7 @@ int __must_check __bch2_btree_iter_traverse(struct btree_iter *iter);
int __must_check bch2_btree_iter_traverse(struct btree_iter *); int __must_check bch2_btree_iter_traverse(struct btree_iter *);
struct btree *bch2_btree_iter_peek_node(struct btree_iter *); struct btree *bch2_btree_iter_peek_node(struct btree_iter *);
struct btree *bch2_btree_iter_peek_node_and_restart(struct btree_iter *);
struct btree *bch2_btree_iter_next_node(struct btree_iter *); struct btree *bch2_btree_iter_next_node(struct btree_iter *);
struct bkey_s_c bch2_btree_iter_peek_upto(struct btree_iter *, struct bpos); struct bkey_s_c bch2_btree_iter_peek_upto(struct btree_iter *, struct bpos);
...@@ -520,18 +521,6 @@ static inline struct bkey_i *bch2_bkey_get_mut(struct btree_trans *trans, ...@@ -520,18 +521,6 @@ static inline struct bkey_i *bch2_bkey_get_mut(struct btree_trans *trans,
u32 bch2_trans_begin(struct btree_trans *); u32 bch2_trans_begin(struct btree_trans *);
static inline struct btree *
__btree_iter_peek_node_and_restart(struct btree_trans *trans, struct btree_iter *iter)
{
struct btree *b;
while (b = bch2_btree_iter_peek_node(iter),
bch2_err_matches(PTR_ERR_OR_ZERO(b), BCH_ERR_transaction_restart))
bch2_trans_begin(trans);
return b;
}
/* /*
* XXX * XXX
* this does not handle transaction restarts from bch2_btree_iter_next_node() * this does not handle transaction restarts from bch2_btree_iter_next_node()
...@@ -541,7 +530,7 @@ __btree_iter_peek_node_and_restart(struct btree_trans *trans, struct btree_iter ...@@ -541,7 +530,7 @@ __btree_iter_peek_node_and_restart(struct btree_trans *trans, struct btree_iter
_locks_want, _depth, _flags, _b, _ret) \ _locks_want, _depth, _flags, _b, _ret) \
for (bch2_trans_node_iter_init((_trans), &(_iter), (_btree_id), \ for (bch2_trans_node_iter_init((_trans), &(_iter), (_btree_id), \
_start, _locks_want, _depth, _flags); \ _start, _locks_want, _depth, _flags); \
(_b) = __btree_iter_peek_node_and_restart((_trans), &(_iter)),\ (_b) = bch2_btree_iter_peek_node_and_restart(&(_iter)), \
!((_ret) = PTR_ERR_OR_ZERO(_b)) && (_b); \ !((_ret) = PTR_ERR_OR_ZERO(_b)) && (_b); \
(_b) = bch2_btree_iter_next_node(&(_iter))) (_b) = bch2_btree_iter_next_node(&(_iter)))
......
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