Skip to content

Commit 659489f

Browse files
author
Kent Overstreet
committed
bcachefs: Kill bch2_path_put_nokeep()
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 <[email protected]>
1 parent 2a6c013 commit 659489f

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

fs/bcachefs/btree_iter.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,15 +1431,6 @@ void bch2_path_put(struct btree_trans *trans, btree_path_idx_t path_idx, bool in
14311431
__bch2_path_free(trans, path_idx);
14321432
}
14331433

1434-
static void bch2_path_put_nokeep(struct btree_trans *trans, btree_path_idx_t path,
1435-
bool intent)
1436-
{
1437-
if (!__btree_path_put(trans, trans->paths + path, intent))
1438-
return;
1439-
1440-
__bch2_path_free(trans, path);
1441-
}
1442-
14431434
void __noreturn bch2_trans_restart_error(struct btree_trans *trans, u32 restart_count)
14441435
{
14451436
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
23582349
}
23592350

23602351
if (iter->update_path) {
2361-
bch2_path_put_nokeep(trans, iter->update_path,
2362-
iter->flags & BTREE_ITER_intent);
2352+
bch2_path_put(trans, iter->update_path, iter->flags & BTREE_ITER_intent);
23632353
iter->update_path = 0;
23642354
}
23652355

@@ -2388,8 +2378,8 @@ struct bkey_s_c bch2_btree_iter_peek_max(struct btree_trans *trans, struct btree
23882378

23892379
if (iter->update_path &&
23902380
!bkey_eq(trans->paths[iter->update_path].pos, k.k->p)) {
2391-
bch2_path_put_nokeep(trans, iter->update_path,
2392-
iter->flags & BTREE_ITER_intent);
2381+
bch2_path_put(trans, iter->update_path,
2382+
iter->flags & BTREE_ITER_intent);
23932383
iter->update_path = 0;
23942384
}
23952385

@@ -2648,7 +2638,7 @@ struct bkey_s_c bch2_btree_iter_peek_prev_min(struct btree_trans *trans, struct
26482638
* the last possible snapshot overwrite, return
26492639
* it:
26502640
*/
2651-
bch2_path_put_nokeep(trans, iter->path,
2641+
bch2_path_put(trans, iter->path,
26522642
iter->flags & BTREE_ITER_intent);
26532643
iter->path = saved_path;
26542644
saved_path = 0;
@@ -2678,8 +2668,8 @@ struct bkey_s_c bch2_btree_iter_peek_prev_min(struct btree_trans *trans, struct
26782668
* our previous saved candidate:
26792669
*/
26802670
if (saved_path) {
2681-
bch2_path_put_nokeep(trans, saved_path,
2682-
iter->flags & BTREE_ITER_intent);
2671+
bch2_path_put(trans, saved_path,
2672+
iter->flags & BTREE_ITER_intent);
26832673
saved_path = 0;
26842674
}
26852675

@@ -2722,7 +2712,7 @@ struct bkey_s_c bch2_btree_iter_peek_prev_min(struct btree_trans *trans, struct
27222712
iter->pos.snapshot = iter->snapshot;
27232713
out_no_locked:
27242714
if (saved_path)
2725-
bch2_path_put_nokeep(trans, saved_path, iter->flags & BTREE_ITER_intent);
2715+
bch2_path_put(trans, saved_path, iter->flags & BTREE_ITER_intent);
27262716

27272717
bch2_btree_iter_verify_entry_exit(iter);
27282718
bch2_btree_iter_verify(trans, iter);
@@ -3045,7 +3035,7 @@ static inline void btree_path_list_add(struct btree_trans *trans,
30453035
void bch2_trans_iter_exit(struct btree_trans *trans, struct btree_iter *iter)
30463036
{
30473037
if (iter->update_path)
3048-
bch2_path_put_nokeep(trans, iter->update_path,
3038+
bch2_path_put(trans, iter->update_path,
30493039
iter->flags & BTREE_ITER_intent);
30503040
if (iter->path)
30513041
bch2_path_put(trans, iter->path,

0 commit comments

Comments
 (0)