Commit 7e759572 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bchfs_read(): call trans_begin() on every loop iter

Same as the recent change for __bch2_read(); also, kill now unnecessary
btree_trans_too_many_iters() calls.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 804baca7
...@@ -151,7 +151,6 @@ static void bchfs_read(struct btree_trans *trans, ...@@ -151,7 +151,6 @@ static void bchfs_read(struct btree_trans *trans,
struct bkey_buf sk; struct bkey_buf sk;
int flags = BCH_READ_RETRY_IF_STALE| int flags = BCH_READ_RETRY_IF_STALE|
BCH_READ_MAY_PROMOTE; BCH_READ_MAY_PROMOTE;
u32 snapshot;
int ret = 0; int ret = 0;
rbio->c = c; rbio->c = c;
...@@ -159,29 +158,23 @@ static void bchfs_read(struct btree_trans *trans, ...@@ -159,29 +158,23 @@ static void bchfs_read(struct btree_trans *trans,
rbio->subvol = inum.subvol; rbio->subvol = inum.subvol;
bch2_bkey_buf_init(&sk); bch2_bkey_buf_init(&sk);
retry:
bch2_trans_begin(trans); bch2_trans_begin(trans);
iter = (struct btree_iter) { NULL };
ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot);
if (ret)
goto err;
bch2_trans_iter_init(trans, &iter, BTREE_ID_extents, bch2_trans_iter_init(trans, &iter, BTREE_ID_extents,
SPOS(inum.inum, rbio->bio.bi_iter.bi_sector, snapshot), POS(inum.inum, rbio->bio.bi_iter.bi_sector),
BTREE_ITER_slots); BTREE_ITER_slots);
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;
enum btree_id data_btree = BTREE_ID_extents; enum btree_id data_btree = BTREE_ID_extents;
/* bch2_trans_begin(trans);
* read_extent -> io_time_reset may cause a transaction restart
* without returning an error, we need to check for that here: u32 snapshot;
*/ ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot);
ret = bch2_trans_relock(trans);
if (ret) if (ret)
break; goto err;
bch2_btree_iter_set_snapshot(&iter, snapshot);
bch2_btree_iter_set_pos(&iter, bch2_btree_iter_set_pos(&iter,
POS(inum.inum, rbio->bio.bi_iter.bi_sector)); POS(inum.inum, rbio->bio.bi_iter.bi_sector));
...@@ -189,7 +182,7 @@ static void bchfs_read(struct btree_trans *trans, ...@@ -189,7 +182,7 @@ static void bchfs_read(struct btree_trans *trans,
k = bch2_btree_iter_peek_slot(&iter); k = bch2_btree_iter_peek_slot(&iter);
ret = bkey_err(k); ret = bkey_err(k);
if (ret) if (ret)
break; goto err;
offset_into_extent = iter.pos.offset - offset_into_extent = iter.pos.offset -
bkey_start_offset(k.k); bkey_start_offset(k.k);
...@@ -200,7 +193,7 @@ static void bchfs_read(struct btree_trans *trans, ...@@ -200,7 +193,7 @@ static void bchfs_read(struct btree_trans *trans,
ret = bch2_read_indirect_extent(trans, &data_btree, ret = bch2_read_indirect_extent(trans, &data_btree,
&offset_into_extent, &sk); &offset_into_extent, &sk);
if (ret) if (ret)
break; goto err;
k = bkey_i_to_s_c(sk.k); k = bkey_i_to_s_c(sk.k);
...@@ -210,7 +203,7 @@ static void bchfs_read(struct btree_trans *trans, ...@@ -210,7 +203,7 @@ static void bchfs_read(struct btree_trans *trans,
ret = readpage_bio_extend(trans, readpages_iter, &rbio->bio, sectors, ret = readpage_bio_extend(trans, readpages_iter, &rbio->bio, sectors,
extent_partial_reads_expensive(k)); extent_partial_reads_expensive(k));
if (ret) if (ret)
break; goto err;
} }
bytes = min(sectors, bio_sectors(&rbio->bio)) << 9; bytes = min(sectors, bio_sectors(&rbio->bio)) << 9;
...@@ -229,17 +222,13 @@ static void bchfs_read(struct btree_trans *trans, ...@@ -229,17 +222,13 @@ static void bchfs_read(struct btree_trans *trans,
swap(rbio->bio.bi_iter.bi_size, bytes); swap(rbio->bio.bi_iter.bi_size, bytes);
bio_advance(&rbio->bio, bytes); bio_advance(&rbio->bio, bytes);
err:
ret = btree_trans_too_many_iters(trans); if (ret &&
if (ret) !bch2_err_matches(ret, BCH_ERR_transaction_restart))
break; break;
} }
err:
bch2_trans_iter_exit(trans, &iter); bch2_trans_iter_exit(trans, &iter);
if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
goto retry;
if (ret) { if (ret) {
bch_err_inum_offset_ratelimited(c, bch_err_inum_offset_ratelimited(c,
iter.pos.inode, iter.pos.inode,
......
...@@ -1214,10 +1214,6 @@ void __bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, ...@@ -1214,10 +1214,6 @@ 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);
ret = btree_trans_too_many_iters(trans);
if (ret)
goto err;
err: err:
if (ret && if (ret &&
!bch2_err_matches(ret, BCH_ERR_transaction_restart) && !bch2_err_matches(ret, BCH_ERR_transaction_restart) &&
......
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