block: loop: pass multi-page bvec to iov_iter
iov_iter is implemented on bvec itererator helpers, so it is safe to pass multi-page bvec to it, and this way is much more efficient than passing one page in each bvec. Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
c3a7ce7380
commit
86af5952a8
|
@ -511,21 +511,22 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
|
||||||
loff_t pos, bool rw)
|
loff_t pos, bool rw)
|
||||||
{
|
{
|
||||||
struct iov_iter iter;
|
struct iov_iter iter;
|
||||||
|
struct req_iterator rq_iter;
|
||||||
struct bio_vec *bvec;
|
struct bio_vec *bvec;
|
||||||
struct request *rq = blk_mq_rq_from_pdu(cmd);
|
struct request *rq = blk_mq_rq_from_pdu(cmd);
|
||||||
struct bio *bio = rq->bio;
|
struct bio *bio = rq->bio;
|
||||||
struct file *file = lo->lo_backing_file;
|
struct file *file = lo->lo_backing_file;
|
||||||
|
struct bio_vec tmp;
|
||||||
unsigned int offset;
|
unsigned int offset;
|
||||||
int segments = 0;
|
int nr_bvec = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (rq->bio != rq->biotail) {
|
rq_for_each_bvec(tmp, rq, rq_iter)
|
||||||
struct req_iterator iter;
|
nr_bvec++;
|
||||||
struct bio_vec tmp;
|
|
||||||
|
|
||||||
__rq_for_each_bio(bio, rq)
|
if (rq->bio != rq->biotail) {
|
||||||
segments += bio_segments(bio);
|
|
||||||
bvec = kmalloc_array(segments, sizeof(struct bio_vec),
|
bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec),
|
||||||
GFP_NOIO);
|
GFP_NOIO);
|
||||||
if (!bvec)
|
if (!bvec)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
@ -534,10 +535,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
|
||||||
/*
|
/*
|
||||||
* The bios of the request may be started from the middle of
|
* The bios of the request may be started from the middle of
|
||||||
* the 'bvec' because of bio splitting, so we can't directly
|
* the 'bvec' because of bio splitting, so we can't directly
|
||||||
* copy bio->bi_iov_vec to new bvec. The rq_for_each_segment
|
* copy bio->bi_iov_vec to new bvec. The rq_for_each_bvec
|
||||||
* API will take care of all details for us.
|
* API will take care of all details for us.
|
||||||
*/
|
*/
|
||||||
rq_for_each_segment(tmp, rq, iter) {
|
rq_for_each_bvec(tmp, rq, rq_iter) {
|
||||||
*bvec = tmp;
|
*bvec = tmp;
|
||||||
bvec++;
|
bvec++;
|
||||||
}
|
}
|
||||||
|
@ -551,11 +552,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
|
||||||
*/
|
*/
|
||||||
offset = bio->bi_iter.bi_bvec_done;
|
offset = bio->bi_iter.bi_bvec_done;
|
||||||
bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
|
bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
|
||||||
segments = bio_segments(bio);
|
|
||||||
}
|
}
|
||||||
atomic_set(&cmd->ref, 2);
|
atomic_set(&cmd->ref, 2);
|
||||||
|
|
||||||
iov_iter_bvec(&iter, rw, bvec, segments, blk_rq_bytes(rq));
|
iov_iter_bvec(&iter, rw, bvec, nr_bvec, blk_rq_bytes(rq));
|
||||||
iter.iov_offset = offset;
|
iter.iov_offset = offset;
|
||||||
|
|
||||||
cmd->iocb.ki_pos = pos;
|
cmd->iocb.ki_pos = pos;
|
||||||
|
|
Loading…
Reference in New Issue