Skip to content

Commit c66e970

Browse files
Ming Leiaxboe
authored andcommitted
loop: add lo_submit_rw_aio()
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>
1 parent fd858d1 commit c66e970

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

drivers/block/loop.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -393,38 +393,32 @@ static int lo_rw_aio_prep(struct loop_device *lo, struct loop_cmd *cmd,
393393
return 0;
394394
}
395395

396-
static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
397-
loff_t pos, int rw)
396+
static int lo_submit_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
397+
int nr_bvec, int rw)
398398
{
399-
struct iov_iter iter;
400-
struct bio_vec *bvec;
401399
struct request *rq = blk_mq_rq_from_pdu(cmd);
402-
struct bio *bio = rq->bio;
403400
struct file *file = lo->lo_backing_file;
404-
unsigned int offset;
405-
int nr_bvec = lo_cmd_nr_bvec(cmd);
401+
struct iov_iter iter;
406402
int ret;
407403

408-
ret = lo_rw_aio_prep(lo, cmd, nr_bvec, pos);
409-
if (unlikely(ret))
410-
return ret;
411-
412404
if (cmd->bvec) {
413-
offset = 0;
414-
bvec = cmd->bvec;
405+
iov_iter_bvec(&iter, rw, cmd->bvec, nr_bvec, blk_rq_bytes(rq));
406+
iter.iov_offset = 0;
415407
} else {
408+
struct bio *bio = rq->bio;
409+
struct bio_vec *bvec = __bvec_iter_bvec(bio->bi_io_vec,
410+
bio->bi_iter);
411+
416412
/*
417413
* Same here, this bio may be started from the middle of the
418414
* 'bvec' because of bio splitting, so offset from the bvec
419415
* must be passed to iov iterator
420416
*/
421-
offset = bio->bi_iter.bi_bvec_done;
422-
bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
417+
iov_iter_bvec(&iter, rw, bvec, nr_bvec, blk_rq_bytes(rq));
418+
iter.iov_offset = bio->bi_iter.bi_bvec_done;
423419
}
424420
atomic_set(&cmd->ref, 2);
425421

426-
iov_iter_bvec(&iter, rw, bvec, nr_bvec, blk_rq_bytes(rq));
427-
iter.iov_offset = offset;
428422

429423
if (rw == ITER_SOURCE) {
430424
kiocb_start_write(&cmd->iocb);
@@ -433,7 +427,20 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
433427
ret = file->f_op->read_iter(&cmd->iocb, &iter);
434428

435429
lo_rw_aio_do_completion(cmd);
430+
return ret;
431+
}
432+
433+
static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
434+
loff_t pos, int rw)
435+
{
436+
int nr_bvec = lo_cmd_nr_bvec(cmd);
437+
int ret;
438+
439+
ret = lo_rw_aio_prep(lo, cmd, nr_bvec, pos);
440+
if (unlikely(ret))
441+
return ret;
436442

443+
ret = lo_submit_rw_aio(lo, cmd, nr_bvec, rw);
437444
if (ret != -EIOCBQUEUED)
438445
lo_rw_aio_complete(&cmd->iocb, ret);
439446
return -EIOCBQUEUED;

0 commit comments

Comments
 (0)