Commit 700c25b3 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Use bch2_trans_begin() more consistently

Upcoming patch will require that a transaction restart is always
immediately followed by bch2_trans_begin().
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 8b3e9bd6
...@@ -114,7 +114,7 @@ static inline int bch2_trans_commit(struct btree_trans *trans, ...@@ -114,7 +114,7 @@ static inline int bch2_trans_commit(struct btree_trans *trans,
_ret = (_do); \ _ret = (_do); \
if (_ret != -EINTR) \ if (_ret != -EINTR) \
break; \ break; \
bch2_trans_reset(_trans, 0); \ bch2_trans_begin(_trans); \
} \ } \
\ \
_ret; \ _ret; \
......
...@@ -784,6 +784,8 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter, ...@@ -784,6 +784,8 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,
bch2_bkey_buf_init(&sk); bch2_bkey_buf_init(&sk);
retry: retry:
bch2_trans_begin(trans);
while (1) { while (1) {
struct bkey_s_c k; struct bkey_s_c k;
unsigned bytes, sectors, offset_into_extent; unsigned bytes, sectors, offset_into_extent;
...@@ -2541,6 +2543,8 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode, ...@@ -2541,6 +2543,8 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode,
struct bpos atomic_end; struct bpos atomic_end;
unsigned trigger_flags = 0; unsigned trigger_flags = 0;
bch2_trans_begin(&trans);
k = insert k = insert
? bch2_btree_iter_peek_prev(src) ? bch2_btree_iter_peek_prev(src)
: bch2_btree_iter_peek(src); : bch2_btree_iter_peek(src);
......
...@@ -911,6 +911,8 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info, ...@@ -911,6 +911,8 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info,
iter = bch2_trans_get_iter(&trans, BTREE_ID_extents, iter = bch2_trans_get_iter(&trans, BTREE_ID_extents,
POS(ei->v.i_ino, start >> 9), 0); POS(ei->v.i_ino, start >> 9), 0);
retry: retry:
bch2_trans_begin(&trans);
while ((k = bch2_btree_iter_peek(iter)).k && while ((k = bch2_btree_iter_peek(iter)).k &&
!(ret = bkey_err(k)) && !(ret = bkey_err(k)) &&
bkey_cmp(iter->pos, end) < 0) { bkey_cmp(iter->pos, end) < 0) {
......
...@@ -376,14 +376,13 @@ int bch2_fpunch_at(struct btree_trans *trans, struct btree_iter *iter, ...@@ -376,14 +376,13 @@ int bch2_fpunch_at(struct btree_trans *trans, struct btree_iter *iter,
struct bkey_s_c k; struct bkey_s_c k;
int ret = 0, ret2 = 0; int ret = 0, ret2 = 0;
while ((k = bch2_btree_iter_peek(iter)).k && while ((bch2_trans_begin(trans),
(k = bch2_btree_iter_peek(iter)).k) &&
bkey_cmp(iter->pos, end) < 0) { bkey_cmp(iter->pos, end) < 0) {
struct disk_reservation disk_res = struct disk_reservation disk_res =
bch2_disk_reservation_init(c, 0); bch2_disk_reservation_init(c, 0);
struct bkey_i delete; struct bkey_i delete;
bch2_trans_begin(trans);
ret = bkey_err(k); ret = bkey_err(k);
if (ret) if (ret)
goto btree_err; goto btree_err;
...@@ -2278,12 +2277,13 @@ void __bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, ...@@ -2278,12 +2277,13 @@ void __bch2_read(struct bch_fs *c, struct bch_read_bio *rbio,
bch2_bkey_buf_init(&sk); bch2_bkey_buf_init(&sk);
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
retry:
bch2_trans_begin(&trans);
iter = bch2_trans_get_iter(&trans, BTREE_ID_extents, iter = bch2_trans_get_iter(&trans, BTREE_ID_extents,
POS(inode, bvec_iter.bi_sector), POS(inode, bvec_iter.bi_sector),
BTREE_ITER_SLOTS); BTREE_ITER_SLOTS);
retry:
bch2_trans_begin(&trans);
while (1) { while (1) {
unsigned bytes, sectors, offset_into_extent; unsigned bytes, sectors, offset_into_extent;
enum btree_id data_btree = BTREE_ID_extents; enum btree_id data_btree = BTREE_ID_extents;
...@@ -2339,19 +2339,20 @@ void __bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, ...@@ -2339,19 +2339,20 @@ void __bch2_read(struct bch_fs *c, struct bch_read_bio *rbio,
swap(bvec_iter.bi_size, bytes); swap(bvec_iter.bi_size, bytes);
bio_advance_iter(&rbio->bio, &bvec_iter, bytes); bio_advance_iter(&rbio->bio, &bvec_iter, bytes);
} }
bch2_trans_iter_put(&trans, iter);
if (ret == -EINTR || ret == READ_RETRY || ret == READ_RETRY_AVOID) if (ret == -EINTR || ret == READ_RETRY || ret == READ_RETRY_AVOID)
goto retry; goto retry;
bch2_trans_iter_put(&trans, iter);
bch2_trans_exit(&trans);
bch2_bkey_buf_exit(&sk, c);
if (ret) { if (ret) {
bch_err_inum_ratelimited(c, inode, bch_err_inum_ratelimited(c, inode,
"read error %i from btree lookup", ret); "read error %i from btree lookup", ret);
rbio->bio.bi_status = BLK_STS_IOERR; rbio->bio.bi_status = BLK_STS_IOERR;
bch2_rbio_done(rbio); bch2_rbio_done(rbio);
} }
bch2_trans_exit(&trans);
bch2_bkey_buf_exit(&sk, c);
} }
void bch2_fs_io_exit(struct bch_fs *c) void bch2_fs_io_exit(struct bch_fs *c)
......
...@@ -83,7 +83,7 @@ int bch2_migrate_index_update(struct bch_write_op *op) ...@@ -83,7 +83,7 @@ int bch2_migrate_index_update(struct bch_write_op *op)
bool extending = false, should_check_enospc; bool extending = false, should_check_enospc;
s64 i_sectors_delta = 0, disk_sectors_delta = 0; s64 i_sectors_delta = 0, disk_sectors_delta = 0;
bch2_trans_reset(&trans, 0); bch2_trans_begin(&trans);
k = bch2_btree_iter_peek_slot(iter); k = bch2_btree_iter_peek_slot(iter);
ret = bkey_err(k); ret = bkey_err(k);
...@@ -597,6 +597,8 @@ static int __bch2_move_data(struct bch_fs *c, ...@@ -597,6 +597,8 @@ static int __bch2_move_data(struct bch_fs *c,
} }
} while (delay); } while (delay);
bch2_trans_begin(&trans);
k = bch2_btree_iter_peek(iter); k = bch2_btree_iter_peek(iter);
stats->pos = iter->pos; stats->pos = iter->pos;
...@@ -652,8 +654,7 @@ static int __bch2_move_data(struct bch_fs *c, ...@@ -652,8 +654,7 @@ static int __bch2_move_data(struct bch_fs *c,
data_cmd, data_opts); data_cmd, data_opts);
if (ret2) { if (ret2) {
if (ret2 == -EINTR) { if (ret2 == -EINTR) {
bch2_trans_reset(&trans, 0); bch2_trans_begin(&trans);
bch2_trans_cond_resched(&trans);
continue; continue;
} }
......
...@@ -305,12 +305,12 @@ s64 bch2_remap_range(struct bch_fs *c, ...@@ -305,12 +305,12 @@ s64 bch2_remap_range(struct bch_fs *c,
dst_done = dst_iter->pos.offset - dst_start.offset; dst_done = dst_iter->pos.offset - dst_start.offset;
new_i_size = min(dst_iter->pos.offset << 9, new_i_size); new_i_size = min(dst_iter->pos.offset << 9, new_i_size);
bch2_trans_begin(&trans);
do { do {
struct bch_inode_unpacked inode_u; struct bch_inode_unpacked inode_u;
struct btree_iter *inode_iter; struct btree_iter *inode_iter;
bch2_trans_begin(&trans);
inode_iter = bch2_inode_peek(&trans, &inode_u, inode_iter = bch2_inode_peek(&trans, &inode_u,
dst_start.inode, BTREE_ITER_INTENT); dst_start.inode, BTREE_ITER_INTENT);
ret2 = PTR_ERR_OR_ZERO(inode_iter); ret2 = PTR_ERR_OR_ZERO(inode_iter);
......
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