]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: rbio_init() cleanup
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 15 Jan 2025 17:59:43 +0000 (12:59 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 15 Mar 2025 01:02:11 +0000 (21:02 -0400)
Move more initialization to rbio_init(), to assist in further cleanups.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs-io-buffered.c
fs/bcachefs/fs-io-direct.c
fs/bcachefs/io_read.c
fs/bcachefs/io_read.h
fs/bcachefs/move.c

index dc00edfefc911626ced641a36e880a09be043b4d..0ec2eebdeffa54284b70eb2290f376990bff3413 100644 (file)
@@ -163,8 +163,6 @@ static void bchfs_read(struct btree_trans *trans,
                BCH_READ_may_promote;
        int ret = 0;
 
-       rbio->c = c;
-       rbio->start_time = local_clock();
        rbio->subvol = inum.subvol;
 
        bch2_bkey_buf_init(&sk);
@@ -290,12 +288,13 @@ void bch2_readahead(struct readahead_control *ractl)
                struct bch_read_bio *rbio =
                        rbio_init(bio_alloc_bioset(NULL, n, REQ_OP_READ,
                                                   GFP_KERNEL, &c->bio_read),
-                                 opts);
+                                 c,
+                                 opts,
+                                 bch2_readpages_end_io);
 
                readpage_iter_advance(&readpages_iter);
 
                rbio->bio.bi_iter.bi_sector = folio_sector(folio);
-               rbio->bio.bi_end_io = bch2_readpages_end_io;
                BUG_ON(!bio_add_folio(&rbio->bio, folio, folio_size(folio), 0));
 
                bchfs_read(trans, rbio, inode_inum(inode),
@@ -333,10 +332,10 @@ int bch2_read_single_folio(struct folio *folio, struct address_space *mapping)
        bch2_inode_opts_get(&opts, c, &inode->ei_inode);
 
        rbio = rbio_init(bio_alloc_bioset(NULL, 1, REQ_OP_READ, GFP_KERNEL, &c->bio_read),
-                        opts);
+                        c,
+                        opts,
+                        bch2_read_single_folio_end_io);
        rbio->bio.bi_private = &done;
-       rbio->bio.bi_end_io = bch2_read_single_folio_end_io;
-
        rbio->bio.bi_opf = REQ_OP_READ|REQ_SYNC;
        rbio->bio.bi_iter.bi_sector = folio_sector(folio);
        BUG_ON(!bio_add_folio(&rbio->bio, folio, folio_size(folio), 0));
index d2f2cbaba7a8a2956642c7486c0568266427327e..535bc5fcbcc09c3b01596bd73aae46ca32ed25fd 100644 (file)
@@ -73,6 +73,7 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter)
        struct blk_plug plug;
        loff_t offset = req->ki_pos;
        bool sync = is_sync_kiocb(req);
+       bool split = false;
        size_t shorten;
        ssize_t ret;
 
@@ -99,8 +100,6 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter)
                               GFP_KERNEL,
                               &c->dio_read_bioset);
 
-       bio->bi_end_io = bch2_direct_IO_read_endio;
-
        dio = container_of(bio, struct dio_read, rbio.bio);
        closure_init(&dio->cl, NULL);
 
@@ -133,12 +132,13 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter)
 
        goto start;
        while (iter->count) {
+               split = true;
+
                bio = bio_alloc_bioset(NULL,
                                       bio_iov_vecs_to_alloc(iter, BIO_MAX_VECS),
                                       REQ_OP_READ,
                                       GFP_KERNEL,
                                       &c->bio_read);
-               bio->bi_end_io          = bch2_direct_IO_read_split_endio;
 start:
                bio->bi_opf             = REQ_OP_READ|REQ_SYNC;
                bio->bi_iter.bi_sector  = offset >> 9;
@@ -160,7 +160,15 @@ start:
                if (iter->count)
                        closure_get(&dio->cl);
 
-               bch2_read(c, rbio_init(bio, opts), inode_inum(inode));
+               struct bch_read_bio *rbio =
+                       rbio_init(bio,
+                                 c,
+                                 opts,
+                                 split
+                                 ? bch2_direct_IO_read_split_endio
+                                 : bch2_direct_IO_read_endio);
+
+               bch2_read(c, rbio, inode_inum(inode));
        }
 
        blk_finish_plug(&plug);
index 3b474c679fb49e83d08282b85a4a8a46d689f6a7..aa6536d8c62ed6ff3166e928adb77c3d8a478fe0 100644 (file)
@@ -171,13 +171,12 @@ static struct promote_op *__promote_alloc(struct btree_trans *trans,
                                          struct bkey_s_c k,
                                          struct bpos pos,
                                          struct extent_ptr_decoded *pick,
-                                         struct bch_io_opts opts,
                                          unsigned sectors,
+                                         struct bch_read_bio *orig,
                                          struct bch_read_bio **rbio,
                                          struct bch_io_failures *failed)
 {
        struct bch_fs *c = trans->c;
-       struct bch_read_bio *orig = *rbio;
        struct promote_op *op = NULL;
        struct bio *bio;
        unsigned pages = DIV_ROUND_UP(sectors, PAGE_SECTORS);
@@ -230,11 +229,11 @@ static struct promote_op *__promote_alloc(struct btree_trans *trans,
        struct data_update_opts update_opts = {};
 
        if (!have_io_error(failed)) {
-               update_opts.target = opts.promote_target;
+               update_opts.target = orig->opts.promote_target;
                update_opts.extra_replicas = 1;
                update_opts.write_flags = BCH_WRITE_alloc_nowait|BCH_WRITE_cached;
        } else {
-               update_opts.target = opts.foreground_target;
+               update_opts.target = orig->opts.foreground_target;
 
                struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
                unsigned ptr_bit = 1;
@@ -247,7 +246,7 @@ static struct promote_op *__promote_alloc(struct btree_trans *trans,
 
        ret = bch2_data_update_init(trans, NULL, NULL, &op->write,
                        writepoint_hashed((unsigned long) current),
-                       opts,
+                       orig->opts,
                        update_opts,
                        btree_id, k);
        /*
@@ -279,8 +278,8 @@ static struct promote_op *promote_alloc(struct btree_trans *trans,
                                        struct bvec_iter iter,
                                        struct bkey_s_c k,
                                        struct extent_ptr_decoded *pick,
-                                       struct bch_io_opts opts,
                                        unsigned flags,
+                                       struct bch_read_bio *orig,
                                        struct bch_read_bio **rbio,
                                        bool *bounce,
                                        bool *read_full,
@@ -304,7 +303,7 @@ static struct promote_op *promote_alloc(struct btree_trans *trans,
        struct promote_op *promote;
        int ret;
 
-       ret = should_promote(c, k, pos, opts, flags, failed);
+       ret = should_promote(c, k, pos, orig->opts, flags, failed);
        if (ret)
                goto nopromote;
 
@@ -312,7 +311,7 @@ static struct promote_op *promote_alloc(struct btree_trans *trans,
                                  k.k->type == KEY_TYPE_reflink_v
                                  ? BTREE_ID_reflink
                                  : BTREE_ID_extents,
-                                 k, pos, pick, opts, sectors, rbio, failed);
+                                 k, pos, pick, sectors, orig, rbio, failed);
        ret = PTR_ERR_OR_ZERO(promote);
        if (ret)
                goto nopromote;
@@ -989,7 +988,7 @@ retry_pick:
        }
 
        if (orig->opts.promote_target || have_io_error(failed))
-               promote = promote_alloc(trans, iter, k, &pick, orig->opts, flags,
+               promote = promote_alloc(trans, iter, k, &pick, flags, orig,
                                        &rbio, &bounce, &read_full, failed);
 
        if (!read_full) {
@@ -1054,7 +1053,6 @@ get_bio:
 
        EBUG_ON(bio_sectors(&rbio->bio) != pick.crc.compressed_size);
 
-       rbio->c                 = c;
        rbio->submit_time       = local_clock();
        if (!rbio->split)
                rbio->end_io    = orig->bio.bi_end_io;
index 11fdf73a38b1dd07d6923c10671c2ab27d769312..5be4f4b35568e9fcec87820bba102054cd942cf5 100644 (file)
@@ -152,8 +152,6 @@ static inline void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio,
 
        BUG_ON(rbio->_state);
 
-       rbio->c = c;
-       rbio->start_time = local_clock();
        rbio->subvol = inum.subvol;
 
        __bch2_read(c, rbio, rbio->bio.bi_iter, inum, &failed,
@@ -162,12 +160,12 @@ static inline void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio,
                    BCH_READ_user_mapped);
 }
 
-
 static inline struct bch_read_bio *rbio_init_fragment(struct bio *bio,
                                                      struct bch_read_bio *orig)
 {
        struct bch_read_bio *rbio = to_rbio(bio);
 
+       rbio->c         = orig->c;
        rbio->_state    = 0;
        rbio->split     = true;
        rbio->parent    = orig;
@@ -177,13 +175,18 @@ static inline struct bch_read_bio *rbio_init_fragment(struct bio *bio,
 }
 
 static inline struct bch_read_bio *rbio_init(struct bio *bio,
-                                            struct bch_io_opts opts)
+                                            struct bch_fs *c,
+                                            struct bch_io_opts opts,
+                                            bio_end_io_t end_io)
 {
        struct bch_read_bio *rbio = to_rbio(bio);
 
-       rbio->_state    = 0;
-       rbio->promote   = NULL;
-       rbio->opts      = opts;
+       rbio->start_time        = local_clock();
+       rbio->c                 = c;
+       rbio->_state            = 0;
+       rbio->promote           = NULL;
+       rbio->opts              = opts;
+       rbio->bio.bi_end_io     = end_io;
        return rbio;
 }
 
index 70304d7c234a635432293521790049d913338a72..b8ac6dd2847112c9843d68854f2490fa6490835a 100644 (file)
@@ -307,8 +307,6 @@ int bch2_move_extent(struct moving_context *ctxt,
                                 GFP_KERNEL))
                goto err_free;
 
-       io->rbio.c              = c;
-       io->rbio.opts           = io_opts;
        bio_init(&io->rbio.bio, NULL, io->bi_inline_vecs, pages, 0);
        io->rbio.bio.bi_vcnt = pages;
        io->rbio.bio.bi_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0);
@@ -316,7 +314,11 @@ int bch2_move_extent(struct moving_context *ctxt,
 
        io->rbio.bio.bi_opf             = REQ_OP_READ;
        io->rbio.bio.bi_iter.bi_sector  = bkey_start_offset(k.k);
-       io->rbio.bio.bi_end_io          = move_read_endio;
+
+       rbio_init(&io->rbio.bio,
+                 c,
+                 io_opts,
+                 move_read_endio);
 
        ret = bch2_data_update_init(trans, iter, ctxt, &io->write, ctxt->wp,
                                    io_opts, data_opts, iter->btree_id, k);