From: Kent Overstreet <koverstreet@xxxxxxxxxx> Signed-off-by: Kent Overstreet <kmo@xxxxxxxxxxxxx> --- drivers/block/nvme-core.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c index ddcb405..e4a9502 100644 --- a/drivers/block/nvme-core.c +++ b/drivers/block/nvme-core.c @@ -465,6 +465,7 @@ static int nvme_split_and_submit(struct bio *bio, struct nvme_queue *nvmeq, static int nvme_map_bio(struct nvme_queue *nvmeq, struct nvme_iod *iod, struct bio *bio, enum dma_data_direction dma_dir, int psegs) { + struct request_queue *q = bdev_get_queue(bio->bi_bdev); struct bio_vec bvec, bvprv; struct bvec_iter iter; struct scatterlist *sg = NULL; @@ -477,26 +478,26 @@ static int nvme_map_bio(struct nvme_queue *nvmeq, struct nvme_iod *iod, (nvmeq->dev->stripe_size - 1)); sg_init_table(iod->sg, psegs); - bio_for_each_segment(bvec, bio, iter) { - if (!first && BIOVEC_PHYS_MERGEABLE(&bvprv, &bvec)) { - sg->length += bvec.bv_len; - } else { - if (!first && BIOVEC_NOT_VIRT_MERGEABLE(&bvprv, &bvec)) - return nvme_split_and_submit(bio, nvmeq, - length); - - sg = sg ? sg + 1 : iod->sg; - sg_set_page(sg, bvec.bv_page, - bvec.bv_len, bvec.bv_offset); - nsegs++; - } - if (split_len - length < bvec.bv_len) - return nvme_split_and_submit(bio, nvmeq, split_len); + iter = bio->bi_iter; + while (iter.bi_size) { + bvec = bio_iovec_iter(bio, iter); + bvec.bv_len = blk_max_segment(q, &bvec); + + if (!first && BIOVEC_NOT_VIRT_MERGEABLE(&bvprv, &bvec)) + return nvme_split_and_submit(bio, nvmeq, length); + + sg = sg ? sg + 1 : iod->sg; + sg_set_page(sg, bvec.bv_page, bvec.bv_len, bvec.bv_offset); + nsegs++; + length += bvec.bv_len; bvprv = bvec; first = 0; + + bio_advance_iter(bio, &iter, bvec.bv_len); } + iod->nents = nsegs; sg_mark_end(sg); if (dma_map_sg(nvmeq->q_dmadev, iod->sg, iod->nents, dma_dir) == 0) -- 1.8.4.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html