Skip to content

Commit fd858d1

Browse files
Ming Leiaxboe
authored andcommitted
loop: add helper lo_rw_aio_prep()
Add helper lo_rw_aio_prep() to separate the preparation phase(setting up bio vectors and initializing the iocb structure) from the actual I/O execution in the loop block driver. 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 c3e6c11 commit fd858d1

1 file changed

Lines changed: 40 additions & 23 deletions

File tree

drivers/block/loop.c

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -350,21 +350,15 @@ static inline unsigned lo_cmd_nr_bvec(struct loop_cmd *cmd)
350350
return nr_bvec;
351351
}
352352

353-
static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
354-
loff_t pos, int rw)
353+
static int lo_rw_aio_prep(struct loop_device *lo, struct loop_cmd *cmd,
354+
unsigned nr_bvec, loff_t pos)
355355
{
356-
struct iov_iter iter;
357-
struct req_iterator rq_iter;
358-
struct bio_vec *bvec;
359356
struct request *rq = blk_mq_rq_from_pdu(cmd);
360-
struct bio *bio = rq->bio;
361-
struct file *file = lo->lo_backing_file;
362-
struct bio_vec tmp;
363-
unsigned int offset;
364-
int nr_bvec = lo_cmd_nr_bvec(cmd);
365-
int ret;
366357

367358
if (rq->bio != rq->biotail) {
359+
struct req_iterator rq_iter;
360+
struct bio_vec *bvec;
361+
struct bio_vec tmp;
368362

369363
bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec),
370364
GFP_NOIO);
@@ -382,8 +376,42 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
382376
*bvec = tmp;
383377
bvec++;
384378
}
385-
bvec = cmd->bvec;
379+
} else {
380+
cmd->bvec = NULL;
381+
}
382+
383+
cmd->iocb.ki_pos = pos;
384+
cmd->iocb.ki_filp = lo->lo_backing_file;
385+
cmd->iocb.ki_ioprio = req_get_ioprio(rq);
386+
if (cmd->use_aio) {
387+
cmd->iocb.ki_complete = lo_rw_aio_complete;
388+
cmd->iocb.ki_flags = IOCB_DIRECT;
389+
} else {
390+
cmd->iocb.ki_complete = NULL;
391+
cmd->iocb.ki_flags = 0;
392+
}
393+
return 0;
394+
}
395+
396+
static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
397+
loff_t pos, int rw)
398+
{
399+
struct iov_iter iter;
400+
struct bio_vec *bvec;
401+
struct request *rq = blk_mq_rq_from_pdu(cmd);
402+
struct bio *bio = rq->bio;
403+
struct file *file = lo->lo_backing_file;
404+
unsigned int offset;
405+
int nr_bvec = lo_cmd_nr_bvec(cmd);
406+
int ret;
407+
408+
ret = lo_rw_aio_prep(lo, cmd, nr_bvec, pos);
409+
if (unlikely(ret))
410+
return ret;
411+
412+
if (cmd->bvec) {
386413
offset = 0;
414+
bvec = cmd->bvec;
387415
} else {
388416
/*
389417
* Same here, this bio may be started from the middle of the
@@ -398,17 +426,6 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
398426
iov_iter_bvec(&iter, rw, bvec, nr_bvec, blk_rq_bytes(rq));
399427
iter.iov_offset = offset;
400428

401-
cmd->iocb.ki_pos = pos;
402-
cmd->iocb.ki_filp = file;
403-
cmd->iocb.ki_ioprio = req_get_ioprio(rq);
404-
if (cmd->use_aio) {
405-
cmd->iocb.ki_complete = lo_rw_aio_complete;
406-
cmd->iocb.ki_flags = IOCB_DIRECT;
407-
} else {
408-
cmd->iocb.ki_complete = NULL;
409-
cmd->iocb.ki_flags = 0;
410-
}
411-
412429
if (rw == ITER_SOURCE) {
413430
kiocb_start_write(&cmd->iocb);
414431
ret = file->f_op->write_iter(&cmd->iocb, &iter);

0 commit comments

Comments
 (0)