bcachefs: for_each_btree_key_continue()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2024-04-07 00:52:47 -04:00
parent a21107eeb1
commit 665e8b3239
2 changed files with 20 additions and 29 deletions

View File

@ -793,31 +793,13 @@ static int bch2_check_extents_to_backpointers_pass(struct btree_trans *trans,
while (level >= depth) { while (level >= depth) {
struct btree_iter iter; struct btree_iter iter;
bch2_trans_node_iter_init(trans, &iter, btree_id, POS_MIN, 0, bch2_trans_node_iter_init(trans, &iter, btree_id, POS_MIN, 0, level,
level,
BTREE_ITER_PREFETCH); BTREE_ITER_PREFETCH);
while (1) {
bch2_trans_begin(trans);
struct bkey_s_c k = bch2_btree_iter_peek(&iter); ret = for_each_btree_key_continue(trans, iter, 0, k, ({
if (!k.k)
break;
ret = bkey_err(k) ?:
check_extent_to_backpointers(trans, s, btree_id, level, k) ?: check_extent_to_backpointers(trans, s, btree_id, level, k) ?:
bch2_trans_commit(trans, NULL, NULL, bch2_trans_commit(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc);
BCH_TRANS_COMMIT_no_enospc); }));
if (bch2_err_matches(ret, BCH_ERR_transaction_restart)) {
ret = 0;
continue;
}
if (ret)
break;
if (bpos_eq(iter.pos, SPOS_MAX))
break;
bch2_btree_iter_advance(&iter);
}
bch2_trans_iter_exit(trans, &iter);
if (ret) if (ret)
return ret; return ret;

View File

@ -699,16 +699,12 @@ transaction_restart: \
_ret2 ?: trans_was_restarted(_trans, _restart_count); \ _ret2 ?: trans_was_restarted(_trans, _restart_count); \
}) })
#define for_each_btree_key_upto(_trans, _iter, _btree_id, \ #define for_each_btree_key_upto_continue(_trans, _iter, \
_start, _end, _flags, _k, _do) \ _end, _flags, _k, _do) \
({ \ ({ \
struct btree_iter _iter; \
struct bkey_s_c _k; \ struct bkey_s_c _k; \
int _ret3 = 0; \ int _ret3 = 0; \
\ \
bch2_trans_iter_init((_trans), &(_iter), (_btree_id), \
(_start), (_flags)); \
\
do { \ do { \
_ret3 = lockrestart_do(_trans, ({ \ _ret3 = lockrestart_do(_trans, ({ \
(_k) = bch2_btree_iter_peek_upto_type(&(_iter), \ (_k) = bch2_btree_iter_peek_upto_type(&(_iter), \
@ -724,6 +720,19 @@ transaction_restart: \
_ret3; \ _ret3; \
}) })
#define for_each_btree_key_continue(_trans, _iter, _flags, _k, _do) \
for_each_btree_key_upto_continue(_trans, _iter, SPOS_MAX, _flags, _k, _do)
#define for_each_btree_key_upto(_trans, _iter, _btree_id, \
_start, _end, _flags, _k, _do) \
({ \
struct btree_iter _iter; \
bch2_trans_iter_init((_trans), &(_iter), (_btree_id), \
(_start), (_flags)); \
\
for_each_btree_key_upto_continue(_trans, _iter, _end, _flags, _k, _do);\
})
#define for_each_btree_key(_trans, _iter, _btree_id, \ #define for_each_btree_key(_trans, _iter, _btree_id, \
_start, _flags, _k, _do) \ _start, _flags, _k, _do) \
for_each_btree_key_upto(_trans, _iter, _btree_id, _start, \ for_each_btree_key_upto(_trans, _iter, _btree_id, _start, \