From: Kent Overstreet Date: Mon, 10 Mar 2025 17:33:41 +0000 (-0400) Subject: bcachefs: __bch2_read() now takes a btree_trans X-Git-Tag: v6.15-rc1~146^2~42 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=35de2abc22274689e78a6582c6b4439db30673ef;p=thirdparty%2Fkernel%2Flinux.git bcachefs: __bch2_read() now takes a btree_trans Next patch will be checking if the extent we're reading from matches the IO failure we saw before marking the failure. For this to work, __bch2_read() needs to take the same transaction context that bch2_rbio_retry() uses to do that check. Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/io_read.c b/fs/bcachefs/io_read.c index a4a61bce076a6..ce197b5bda9d1 100644 --- a/fs/bcachefs/io_read.c +++ b/fs/bcachefs/io_read.c @@ -428,13 +428,13 @@ static void bch2_rbio_done(struct bch_read_bio *rbio) bio_endio(&rbio->bio); } -static noinline int bch2_read_retry_nodecode(struct bch_fs *c, struct bch_read_bio *rbio, - struct bvec_iter bvec_iter, - struct bch_io_failures *failed, - unsigned flags) +static noinline int bch2_read_retry_nodecode(struct btree_trans *trans, + struct bch_read_bio *rbio, + struct bvec_iter bvec_iter, + struct bch_io_failures *failed, + unsigned flags) { struct data_update *u = container_of(rbio, struct data_update, rbio); - struct btree_trans *trans = bch2_trans_get(c); retry: bch2_trans_begin(trans); @@ -470,8 +470,6 @@ err: } BUG_ON(atomic_read(&rbio->bio.__bi_remaining) != 1); - bch2_trans_put(trans); - return ret; } @@ -487,6 +485,7 @@ static void bch2_rbio_retry(struct work_struct *work) .inum = rbio->read_pos.inode, }; struct bch_io_failures failed = { .nr = 0 }; + struct btree_trans *trans = bch2_trans_get(c); trace_io_read_retry(&rbio->bio); this_cpu_add(c->counters[BCH_COUNTER_io_read_retry], @@ -512,8 +511,8 @@ static void bch2_rbio_retry(struct work_struct *work) flags |= BCH_READ_must_clone; int ret = rbio->data_update - ? bch2_read_retry_nodecode(c, rbio, iter, &failed, flags) - : __bch2_read(c, rbio, iter, inum, &failed, flags); + ? bch2_read_retry_nodecode(trans, rbio, iter, &failed, flags) + : __bch2_read(trans, rbio, iter, inum, &failed, flags); if (ret) { rbio->ret = ret; @@ -521,7 +520,7 @@ static void bch2_rbio_retry(struct work_struct *work) } else { struct printbuf buf = PRINTBUF; - bch2_trans_do(c, + lockrestart_do(trans, bch2_inum_offset_err_msg_trans(trans, &buf, (subvol_inum) { subvol, read_pos.inode }, read_pos.offset << 9)); @@ -534,6 +533,7 @@ static void bch2_rbio_retry(struct work_struct *work) } bch2_rbio_done(rbio); + bch2_trans_put(trans); } static void bch2_rbio_error(struct bch_read_bio *rbio, @@ -1256,11 +1256,11 @@ out_read_done: return 0; } -int __bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, - struct bvec_iter bvec_iter, subvol_inum inum, - struct bch_io_failures *failed, unsigned flags) +int __bch2_read(struct btree_trans *trans, struct bch_read_bio *rbio, + struct bvec_iter bvec_iter, subvol_inum inum, + struct bch_io_failures *failed, unsigned flags) { - struct btree_trans *trans = bch2_trans_get(c); + struct bch_fs *c = trans->c; struct btree_iter iter; struct bkey_buf sk; struct bkey_s_c k; @@ -1357,9 +1357,7 @@ err: bch2_rbio_done(rbio); } - bch2_trans_put(trans); bch2_bkey_buf_exit(&sk, c); - return ret; } diff --git a/fs/bcachefs/io_read.h b/fs/bcachefs/io_read.h index 559d8986d84c1..cd21950417f64 100644 --- a/fs/bcachefs/io_read.h +++ b/fs/bcachefs/io_read.h @@ -3,6 +3,7 @@ #define _BCACHEFS_IO_READ_H #include "bkey_buf.h" +#include "btree_iter.h" #include "reflink.h" struct bch_read_bio { @@ -140,7 +141,7 @@ static inline void bch2_read_extent(struct btree_trans *trans, data_btree, k, offset_into_extent, NULL, flags, -1); } -int __bch2_read(struct bch_fs *, struct bch_read_bio *, struct bvec_iter, +int __bch2_read(struct btree_trans *, struct bch_read_bio *, struct bvec_iter, subvol_inum, struct bch_io_failures *, unsigned flags); static inline void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, @@ -150,10 +151,11 @@ static inline void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, rbio->subvol = inum.subvol; - __bch2_read(c, rbio, rbio->bio.bi_iter, inum, NULL, - BCH_READ_retry_if_stale| - BCH_READ_may_promote| - BCH_READ_user_mapped); + bch2_trans_run(c, + __bch2_read(trans, rbio, rbio->bio.bi_iter, inum, NULL, + BCH_READ_retry_if_stale| + BCH_READ_may_promote| + BCH_READ_user_mapped)); } static inline struct bch_read_bio *rbio_init_fragment(struct bio *bio,