提交 f565913e 编写于 作者: J Jens Axboe

block: convert to using sg helpers

Convert the main rq mapper (blk_rq_map_sg()) to the sg helper setup.
Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
上级 96b418c9
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/blktrace_api.h> #include <linux/blktrace_api.h>
#include <linux/fault-inject.h> #include <linux/fault-inject.h>
#include <linux/scatterlist.h>
/* /*
* for max sense size * for max sense size
...@@ -1318,9 +1319,10 @@ static int blk_hw_contig_segment(struct request_queue *q, struct bio *bio, ...@@ -1318,9 +1319,10 @@ static int blk_hw_contig_segment(struct request_queue *q, struct bio *bio,
* must make sure sg can hold rq->nr_phys_segments entries * must make sure sg can hold rq->nr_phys_segments entries
*/ */
int blk_rq_map_sg(struct request_queue *q, struct request *rq, int blk_rq_map_sg(struct request_queue *q, struct request *rq,
struct scatterlist *sg) struct scatterlist *sglist)
{ {
struct bio_vec *bvec, *bvprv; struct bio_vec *bvec, *bvprv;
struct scatterlist *next_sg, *sg;
struct req_iterator iter; struct req_iterator iter;
int nsegs, cluster; int nsegs, cluster;
...@@ -1331,11 +1333,12 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq, ...@@ -1331,11 +1333,12 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,
* for each bio in rq * for each bio in rq
*/ */
bvprv = NULL; bvprv = NULL;
sg = next_sg = &sglist[0];
rq_for_each_segment(bvec, rq, iter) { rq_for_each_segment(bvec, rq, iter) {
int nbytes = bvec->bv_len; int nbytes = bvec->bv_len;
if (bvprv && cluster) { if (bvprv && cluster) {
if (sg[nsegs - 1].length + nbytes > q->max_segment_size) if (sg->length + nbytes > q->max_segment_size)
goto new_segment; goto new_segment;
if (!BIOVEC_PHYS_MERGEABLE(bvprv, bvec)) if (!BIOVEC_PHYS_MERGEABLE(bvprv, bvec))
...@@ -1343,14 +1346,15 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq, ...@@ -1343,14 +1346,15 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,
if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bvec)) if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bvec))
goto new_segment; goto new_segment;
sg[nsegs - 1].length += nbytes; sg->length += nbytes;
} else { } else {
new_segment: new_segment:
memset(&sg[nsegs],0,sizeof(struct scatterlist)); sg = next_sg;
sg[nsegs].page = bvec->bv_page; next_sg = sg_next(sg);
sg[nsegs].length = nbytes;
sg[nsegs].offset = bvec->bv_offset;
sg->page = bvec->bv_page;
sg->length = nbytes;
sg->offset = bvec->bv_offset;
nsegs++; nsegs++;
} }
bvprv = bvec; bvprv = bvec;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册