bcachefs: reserve path idx 0 for sentinal
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 7 Dec 2023 18:11:44 +0000 (13:11 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 1 Jan 2024 16:47:40 +0000 (11:47 -0500)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_iter.h

index 59815c0d0db638c6e3fb4d8490f43a7cb399b8d0..e2f010564ceb3968c303baed31a59a310c4bf5f5 100644 (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);
index 5f401056c3ed18ffcbf40c56080573a62b8ef5cc..5be3c1a2c82030f618f1c24fb6e95be567874c90 100644 (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))