mirror of https://github.com/torvalds/linux.git
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>
This commit is contained in:
parent
fd858d1ca9
commit
c66e9708f9
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue