bcachefs: reserve path idx 0 for sentinal

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2023-12-07 13:11:44 -05:00
parent 5028b9078c
commit f8fd5871be
2 changed files with 6 additions and 4 deletions

View File

@ -2515,7 +2515,7 @@ static void btree_trans_verify_sorted_refs(struct btree_trans *trans)
struct btree_path *path;
unsigned i;
BUG_ON(trans->nr_sorted != bitmap_weight(trans->paths_allocated, BTREE_ITER_MAX));
BUG_ON(trans->nr_sorted != bitmap_weight(trans->paths_allocated, BTREE_ITER_MAX) - 1);
trans_for_each_path(trans, path) {
BUG_ON(path->sorted_idx >= trans->nr_sorted);
@ -2896,6 +2896,8 @@ struct btree_trans *__bch2_trans_get(struct bch_fs *c, unsigned fn_idx)
atomic_inc_not_zero(&c->journal_keys.ref);
closure_init_stack(&trans->ref);
trans->paths_allocated[0] = 1;
s = btree_trans_stats(trans);
if (s && s->max_mem) {
unsigned expected_mem_bytes = roundup_pow_of_two(s->max_mem);

View File

@ -80,7 +80,7 @@ __trans_next_path(struct btree_trans *trans, unsigned idx)
_path = __trans_next_path((_trans), (_path)->idx + 1))
#define trans_for_each_path(_trans, _path) \
trans_for_each_path_from(_trans, _path, 0)
trans_for_each_path_from(_trans, _path, 1)
static inline struct btree_path *
__trans_next_path_safe(struct btree_trans *trans, unsigned *idx)
@ -103,7 +103,7 @@ __trans_next_path_safe(struct btree_trans *trans, unsigned *idx)
_idx++)
#define trans_for_each_path_safe(_trans, _path, _idx) \
trans_for_each_path_safe_from(_trans, _path, _idx, 0)
trans_for_each_path_safe_from(_trans, _path, _idx, 1)
static inline struct btree_path *next_btree_path(struct btree_trans *trans, struct btree_path *path)
{
@ -155,7 +155,7 @@ __trans_next_path_with_node(struct btree_trans *trans, struct btree *b,
}
#define trans_for_each_path_with_node(_trans, _b, _path) \
for (_path = __trans_next_path_with_node((_trans), (_b), 0); \
for (_path = __trans_next_path_with_node((_trans), (_b), 1); \
(_path); \
_path = __trans_next_path_with_node((_trans), (_b), \
(_path)->idx + 1))