Commit a8abd3a7 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: bch2_trans_reset() calls should be at the tops of loops

It needs to be called when we get -EINTR due to e.g. lock restart - this
fixes a transaction iterators overflow bug.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 780c4e43
...@@ -299,11 +299,6 @@ static inline void bch2_trans_begin(struct btree_trans *trans) ...@@ -299,11 +299,6 @@ static inline void bch2_trans_begin(struct btree_trans *trans)
return bch2_trans_reset(trans, TRANS_RESET_ITERS|TRANS_RESET_MEM); return bch2_trans_reset(trans, TRANS_RESET_ITERS|TRANS_RESET_MEM);
} }
static inline void bch2_trans_begin_updates(struct btree_trans *trans)
{
return bch2_trans_reset(trans, TRANS_RESET_MEM);
}
void *bch2_trans_kmalloc(struct btree_trans *, size_t); void *bch2_trans_kmalloc(struct btree_trans *, size_t);
void bch2_trans_init(struct btree_trans *, struct bch_fs *, unsigned, size_t); void bch2_trans_init(struct btree_trans *, struct bch_fs *, unsigned, size_t);
int bch2_trans_exit(struct btree_trans *); int bch2_trans_exit(struct btree_trans *);
......
...@@ -869,6 +869,8 @@ int bch2_btree_delete_at_range(struct btree_trans *trans, ...@@ -869,6 +869,8 @@ int bch2_btree_delete_at_range(struct btree_trans *trans,
bkey_cmp(iter->pos, end) < 0) { bkey_cmp(iter->pos, end) < 0) {
struct bkey_i delete; struct bkey_i delete;
bch2_trans_reset(trans, TRANS_RESET_MEM);
bkey_init(&delete.k); bkey_init(&delete.k);
/* /*
......
...@@ -2650,6 +2650,8 @@ static long bchfs_fallocate(struct bch_inode_info *inode, int mode, ...@@ -2650,6 +2650,8 @@ static long bchfs_fallocate(struct bch_inode_info *inode, int mode,
struct bkey_i_reservation reservation; struct bkey_i_reservation reservation;
struct bkey_s_c k; struct bkey_s_c k;
bch2_trans_reset(&trans, TRANS_RESET_MEM);
k = bch2_btree_iter_peek_slot(iter); k = bch2_btree_iter_peek_slot(iter);
if ((ret = bkey_err(k))) if ((ret = bkey_err(k)))
goto bkey_err; goto bkey_err;
...@@ -2696,8 +2698,6 @@ static long bchfs_fallocate(struct bch_inode_info *inode, int mode, ...@@ -2696,8 +2698,6 @@ static long bchfs_fallocate(struct bch_inode_info *inode, int mode,
reservation.v.nr_replicas = disk_res.nr_replicas; reservation.v.nr_replicas = disk_res.nr_replicas;
} }
bch2_trans_begin_updates(&trans);
ret = bch2_extent_update(&trans, iter, &reservation.k_i, ret = bch2_extent_update(&trans, iter, &reservation.k_i,
&disk_res, &inode->ei_journal_seq, &disk_res, &inode->ei_journal_seq,
0, &i_sectors_delta); 0, &i_sectors_delta);
......
...@@ -336,6 +336,8 @@ int bch2_fpunch_at(struct btree_trans *trans, struct btree_iter *iter, ...@@ -336,6 +336,8 @@ int bch2_fpunch_at(struct btree_trans *trans, struct btree_iter *iter,
bch2_disk_reservation_init(c, 0); bch2_disk_reservation_init(c, 0);
struct bkey_i delete; struct bkey_i delete;
bch2_trans_reset(trans, TRANS_RESET_MEM);
ret = bkey_err(k); ret = bkey_err(k);
if (ret) if (ret)
goto btree_err; goto btree_err;
...@@ -347,8 +349,6 @@ int bch2_fpunch_at(struct btree_trans *trans, struct btree_iter *iter, ...@@ -347,8 +349,6 @@ int bch2_fpunch_at(struct btree_trans *trans, struct btree_iter *iter,
bch2_key_resize(&delete.k, max_sectors); bch2_key_resize(&delete.k, max_sectors);
bch2_cut_back(end, &delete); bch2_cut_back(end, &delete);
bch2_trans_begin_updates(trans);
ret = bch2_extent_update(trans, iter, &delete, ret = bch2_extent_update(trans, iter, &delete,
&disk_res, journal_seq, &disk_res, journal_seq,
0, i_sectors_delta); 0, i_sectors_delta);
...@@ -410,14 +410,14 @@ int bch2_write_index_default(struct bch_write_op *op) ...@@ -410,14 +410,14 @@ int bch2_write_index_default(struct bch_write_op *op)
BTREE_ITER_SLOTS|BTREE_ITER_INTENT); BTREE_ITER_SLOTS|BTREE_ITER_INTENT);
do { do {
bch2_trans_reset(&trans, TRANS_RESET_MEM);
k = bch2_keylist_front(keys); k = bch2_keylist_front(keys);
bkey_on_stack_realloc(&sk, c, k->k.u64s); bkey_on_stack_realloc(&sk, c, k->k.u64s);
bkey_copy(sk.k, k); bkey_copy(sk.k, k);
bch2_cut_front(iter->pos, sk.k); bch2_cut_front(iter->pos, sk.k);
bch2_trans_begin_updates(&trans);
ret = bch2_extent_update(&trans, iter, sk.k, ret = bch2_extent_update(&trans, iter, sk.k,
&op->res, op_journal_seq(op), &op->res, op_journal_seq(op),
op->new_i_size, &op->i_sectors_delta); op->new_i_size, &op->i_sectors_delta);
......
...@@ -185,7 +185,8 @@ s64 bch2_remap_range(struct bch_fs *c, ...@@ -185,7 +185,8 @@ s64 bch2_remap_range(struct bch_fs *c,
BTREE_ITER_INTENT); BTREE_ITER_INTENT);
while (1) { while (1) {
bch2_trans_begin_updates(&trans); bch2_trans_reset(&trans, TRANS_RESET_MEM);
trans.mem_top = 0; trans.mem_top = 0;
if (fatal_signal_pending(current)) { if (fatal_signal_pending(current)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment