bcachefs: Kill bch2_path_put_nokeep()
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 19:40:24 +0000 (15:40 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 23 May 2025 11:59:43 +0000 (07:59 -0400)
bch2_path_put_nokeep() was intended for paths we wouldn't need to
preserve for a transaction restart - it always frees them right away
when the ref hits 0.

But since paths are shared, freeing unconditionally is a bug, the path
might have been used elsewhere and have should_be_locked set, i.e. we
need to keep it locked until the end of the transaction.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c

index 0f0b80c8c29a76767658c74af016963321f1c472..b366407878d047e2e319849fbd23021bcff2f07e 100644 (file)
@@ -1431,15 +1431,6 @@ void bch2_path_put(struct btree_trans *trans, btree_path_idx_t path_idx, bool in
        __bch2_path_free(trans, path_idx);
 }
 
-static void bch2_path_put_nokeep(struct btree_trans *trans, btree_path_idx_t path,
-                                bool intent)
-{
-       if (!__btree_path_put(trans, trans->paths + path, intent))
-               return;
-
-       __bch2_path_free(trans, path);
-}
-
 void __noreturn bch2_trans_restart_error(struct btree_trans *trans, u32 restart_count)
 {
        panic("trans->restart_count %u, should be %u, last restarted by %pS\n",
@@ -2358,8 +2349,7 @@ struct bkey_s_c bch2_btree_iter_peek_max(struct btree_trans *trans, struct btree
        }
 
        if (iter->update_path) {
-               bch2_path_put_nokeep(trans, iter->update_path,
-                                    iter->flags & BTREE_ITER_intent);
+               bch2_path_put(trans, iter->update_path, iter->flags & BTREE_ITER_intent);
                iter->update_path = 0;
        }
 
@@ -2388,8 +2378,8 @@ struct bkey_s_c bch2_btree_iter_peek_max(struct btree_trans *trans, struct btree
 
                        if (iter->update_path &&
                            !bkey_eq(trans->paths[iter->update_path].pos, k.k->p)) {
-                               bch2_path_put_nokeep(trans, iter->update_path,
-                                                    iter->flags & BTREE_ITER_intent);
+                               bch2_path_put(trans, iter->update_path,
+                                             iter->flags & BTREE_ITER_intent);
                                iter->update_path = 0;
                        }
 
@@ -2648,7 +2638,7 @@ struct bkey_s_c bch2_btree_iter_peek_prev_min(struct btree_trans *trans, struct
                                 * the last possible snapshot overwrite, return
                                 * it:
                                 */
-                               bch2_path_put_nokeep(trans, iter->path,
+                               bch2_path_put(trans, iter->path,
                                              iter->flags & BTREE_ITER_intent);
                                iter->path = saved_path;
                                saved_path = 0;
@@ -2678,8 +2668,8 @@ struct bkey_s_c bch2_btree_iter_peek_prev_min(struct btree_trans *trans, struct
                                 * our previous saved candidate:
                                 */
                                if (saved_path) {
-                                       bch2_path_put_nokeep(trans, saved_path,
-                                             iter->flags & BTREE_ITER_intent);
+                                       bch2_path_put(trans, saved_path,
+                                                     iter->flags & BTREE_ITER_intent);
                                        saved_path = 0;
                                }
 
@@ -2722,7 +2712,7 @@ struct bkey_s_c bch2_btree_iter_peek_prev_min(struct btree_trans *trans, struct
                iter->pos.snapshot = iter->snapshot;
 out_no_locked:
        if (saved_path)
-               bch2_path_put_nokeep(trans, saved_path, iter->flags & BTREE_ITER_intent);
+               bch2_path_put(trans, saved_path, iter->flags & BTREE_ITER_intent);
 
        bch2_btree_iter_verify_entry_exit(iter);
        bch2_btree_iter_verify(trans, iter);
@@ -3045,7 +3035,7 @@ static inline void btree_path_list_add(struct btree_trans *trans,
 void bch2_trans_iter_exit(struct btree_trans *trans, struct btree_iter *iter)
 {
        if (iter->update_path)
-               bch2_path_put_nokeep(trans, iter->update_path,
+               bch2_path_put(trans, iter->update_path,
                              iter->flags & BTREE_ITER_intent);
        if (iter->path)
                bch2_path_put(trans, iter->path,