]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
loop: add lo_submit_rw_aio()
authorMing Lei <ming.lei@redhat.com>
Wed, 15 Oct 2025 11:07:28 +0000 (19:07 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 18 Nov 2025 13:49:51 +0000 (06:49 -0700)
Refactor lo_rw_aio() by extracting the I/O submission logic into a new
helper function lo_submit_rw_aio(). This further improves code organization
by separating the I/O preparation, submission, and completion handling into
distinct phases.

Prepare for using NOWAIT to improve loop performance.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/loop.c

index c0d8d290cb780704f951e316b39e7a30ae4919ba..a494a93ed2b105dabd938a9def05fa4845951a39 100644 (file)
@@ -393,38 +393,32 @@ static int lo_rw_aio_prep(struct loop_device *lo, struct loop_cmd *cmd,
        return 0;
 }
 
-static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
-                    loff_t pos, int rw)
+static int lo_submit_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
+                           int nr_bvec, int rw)
 {
-       struct iov_iter iter;
-       struct bio_vec *bvec;
        struct request *rq = blk_mq_rq_from_pdu(cmd);
-       struct bio *bio = rq->bio;
        struct file *file = lo->lo_backing_file;
-       unsigned int offset;
-       int nr_bvec = lo_cmd_nr_bvec(cmd);
+       struct iov_iter iter;
        int ret;
 
-       ret = lo_rw_aio_prep(lo, cmd, nr_bvec, pos);
-       if (unlikely(ret))
-               return ret;
-
        if (cmd->bvec) {
-               offset = 0;
-               bvec = cmd->bvec;
+               iov_iter_bvec(&iter, rw, cmd->bvec, nr_bvec, blk_rq_bytes(rq));
+               iter.iov_offset = 0;
        } else {
+               struct bio *bio = rq->bio;
+               struct bio_vec *bvec = __bvec_iter_bvec(bio->bi_io_vec,
+                               bio->bi_iter);
+
                /*
                 * Same here, this bio may be started from the middle of the
                 * 'bvec' because of bio splitting, so offset from the bvec
                 * must be passed to iov iterator
                 */
-               offset = bio->bi_iter.bi_bvec_done;
-               bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
+               iov_iter_bvec(&iter, rw, bvec, nr_bvec, blk_rq_bytes(rq));
+               iter.iov_offset = bio->bi_iter.bi_bvec_done;
        }
        atomic_set(&cmd->ref, 2);
 
-       iov_iter_bvec(&iter, rw, bvec, nr_bvec, blk_rq_bytes(rq));
-       iter.iov_offset = offset;
 
        if (rw == ITER_SOURCE) {
                kiocb_start_write(&cmd->iocb);
@@ -433,7 +427,20 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
                ret = file->f_op->read_iter(&cmd->iocb, &iter);
 
        lo_rw_aio_do_completion(cmd);
+       return ret;
+}
+
+static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
+                    loff_t pos, int rw)
+{
+       int nr_bvec = lo_cmd_nr_bvec(cmd);
+       int ret;
+
+       ret = lo_rw_aio_prep(lo, cmd, nr_bvec, pos);
+       if (unlikely(ret))
+               return ret;
 
+       ret = lo_submit_rw_aio(lo, cmd, nr_bvec, rw);
        if (ret != -EIOCBQUEUED)
                lo_rw_aio_complete(&cmd->iocb, ret);
        return -EIOCBQUEUED;