summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-07-25 02:24:10 +0200
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 23:09:09 +0200
commit700c25b32a776a70849c025d898ba1a7431279e4 (patch)
tree89fbf0860e64ddbdd2e54ac70a3358fe5ac3ca0f
parentbcachefs: Always check for transaction restarts (diff)
downloadlinux-700c25b32a776a70849c025d898ba1a7431279e4.tar.xz
linux-700c25b32a776a70849c025d898ba1a7431279e4.zip
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: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--fs/bcachefs/btree_update.h2
-rw-r--r--fs/bcachefs/fs-io.c4
-rw-r--r--fs/bcachefs/fs.c2
-rw-r--r--fs/bcachefs/io.c17
-rw-r--r--fs/bcachefs/move.c7
-rw-r--r--fs/bcachefs/reflink.c4
6 files changed, 22 insertions, 14 deletions
diff --git a/fs/bcachefs/btree_update.h b/fs/bcachefs/btree_update.h
index bab135fae0b0..b5f35a419004 100644
--- a/fs/bcachefs/btree_update.h
+++ b/fs/bcachefs/btree_update.h
@@ -114,7 +114,7 @@ static inline int bch2_trans_commit(struct btree_trans *trans,
_ret = (_do); \
if (_ret != -EINTR) \
break; \
- bch2_trans_reset(_trans, 0); \
+ bch2_trans_begin(_trans); \
} \
\
_ret; \
diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c
index 1a06f77101ab..30e5acd2e97c 100644
--- a/fs/bcachefs/fs-io.c
+++ b/fs/bcachefs/fs-io.c
@@ -784,6 +784,8 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,
bch2_bkey_buf_init(&sk);
retry:
+ bch2_trans_begin(trans);
+
while (1) {
struct bkey_s_c k;
unsigned bytes, sectors, offset_into_extent;
@@ -2541,6 +2543,8 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode,
struct bpos atomic_end;
unsigned trigger_flags = 0;
+ bch2_trans_begin(&trans);
+
k = insert
? bch2_btree_iter_peek_prev(src)
: bch2_btree_iter_peek(src);
diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c
index 71e738b98967..b2d6e80bbb78 100644
--- a/fs/bcachefs/fs.c
+++ b/fs/bcachefs/fs.c
@@ -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,
POS(ei->v.i_ino, start >> 9), 0);
retry:
+ bch2_trans_begin(&trans);
+
while ((k = bch2_btree_iter_peek(iter)).k &&
!(ret = bkey_err(k)) &&
bkey_cmp(iter->pos, end) < 0) {
diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c
index 5ff8fea80fba..f293876e0bbc 100644
--- a/fs/bcachefs/io.c
+++ b/fs/bcachefs/io.c
@@ -376,14 +376,13 @@ int bch2_fpunch_at(struct btree_trans *trans, struct btree_iter *iter,
struct bkey_s_c k;
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) {
struct disk_reservation disk_res =
bch2_disk_reservation_init(c, 0);
struct bkey_i delete;
- bch2_trans_begin(trans);
-
ret = bkey_err(k);
if (ret)
goto btree_err;
@@ -2278,12 +2277,13 @@ void __bch2_read(struct bch_fs *c, struct bch_read_bio *rbio,
bch2_bkey_buf_init(&sk);
bch2_trans_init(&trans, c, 0, 0);
-retry:
- bch2_trans_begin(&trans);
iter = bch2_trans_get_iter(&trans, BTREE_ID_extents,
POS(inode, bvec_iter.bi_sector),
BTREE_ITER_SLOTS);
+retry:
+ bch2_trans_begin(&trans);
+
while (1) {
unsigned bytes, sectors, offset_into_extent;
enum btree_id data_btree = BTREE_ID_extents;
@@ -2339,19 +2339,20 @@ retry:
swap(bvec_iter.bi_size, 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)
goto retry;
+ bch2_trans_iter_put(&trans, iter);
+ bch2_trans_exit(&trans);
+ bch2_bkey_buf_exit(&sk, c);
+
if (ret) {
bch_err_inum_ratelimited(c, inode,
"read error %i from btree lookup", ret);
rbio->bio.bi_status = BLK_STS_IOERR;
bch2_rbio_done(rbio);
}
- bch2_trans_exit(&trans);
- bch2_bkey_buf_exit(&sk, c);
}
void bch2_fs_io_exit(struct bch_fs *c)
diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c
index 7dea6637ae58..9a423a3e4570 100644
--- a/fs/bcachefs/move.c
+++ b/fs/bcachefs/move.c
@@ -83,7 +83,7 @@ int bch2_migrate_index_update(struct bch_write_op *op)
bool extending = false, should_check_enospc;
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);
ret = bkey_err(k);
@@ -597,6 +597,8 @@ static int __bch2_move_data(struct bch_fs *c,
}
} while (delay);
+ bch2_trans_begin(&trans);
+
k = bch2_btree_iter_peek(iter);
stats->pos = iter->pos;
@@ -652,8 +654,7 @@ static int __bch2_move_data(struct bch_fs *c,
data_cmd, data_opts);
if (ret2) {
if (ret2 == -EINTR) {
- bch2_trans_reset(&trans, 0);
- bch2_trans_cond_resched(&trans);
+ bch2_trans_begin(&trans);
continue;
}
diff --git a/fs/bcachefs/reflink.c b/fs/bcachefs/reflink.c
index 8b168246ca38..3d9c5c5b0eba 100644
--- a/fs/bcachefs/reflink.c
+++ b/fs/bcachefs/reflink.c
@@ -305,12 +305,12 @@ s64 bch2_remap_range(struct bch_fs *c,
dst_done = dst_iter->pos.offset - dst_start.offset;
new_i_size = min(dst_iter->pos.offset << 9, new_i_size);
- bch2_trans_begin(&trans);
-
do {
struct bch_inode_unpacked inode_u;
struct btree_iter *inode_iter;
+ bch2_trans_begin(&trans);
+
inode_iter = bch2_inode_peek(&trans, &inode_u,
dst_start.inode, BTREE_ITER_INTENT);
ret2 = PTR_ERR_OR_ZERO(inode_iter);