[PATCH 4/19] block: convert to using sg helpers

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jens Axboe
Date: Wednesday, May 16, 2007 - 1:32 am

Convert the main rq mapper (blk_rq_map_sg()) to the sg helper setup.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
---
 block/ll_rw_blk.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index 6b5173a..7d801cf 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -30,6 +30,7 @@
 #include <linux/cpu.h>
 #include <linux/blktrace_api.h>
 #include <linux/fault-inject.h>
+#include <linux/scatterlist.h>
 
 /*
  * for max sense size
@@ -1307,9 +1308,11 @@ static int blk_hw_contig_segment(request_queue_t *q, struct bio *bio,
  * map a request to scatterlist, return number of sg entries setup. Caller
  * must make sure sg can hold rq->nr_phys_segments entries
  */
-int blk_rq_map_sg(request_queue_t *q, struct request *rq, struct scatterlist *sg)
+int blk_rq_map_sg(request_queue_t *q, struct request *rq,
+		  struct scatterlist *sglist)
 {
 	struct bio_vec *bvec, *bvprv;
+	struct scatterlist *next_sg, *sg;
 	struct bio *bio;
 	int nsegs, i, cluster;
 
@@ -1320,6 +1323,7 @@ int blk_rq_map_sg(request_queue_t *q, struct request *rq, struct scatterlist *sg
 	 * for each bio in rq
 	 */
 	bvprv = NULL;
+	sg = next_sg = &sglist[0];
 	rq_for_each_bio(bio, rq) {
 		/*
 		 * for each segment in bio
@@ -1328,7 +1332,7 @@ int blk_rq_map_sg(request_queue_t *q, struct request *rq, struct scatterlist *sg
 			int nbytes = bvec->bv_len;
 
 			if (bvprv && cluster) {
-				if (sg[nsegs - 1].length + nbytes > q->max_segment_size)
+				if (sg->length + nbytes > q->max_segment_size)
 					goto new_segment;
 
 				if (!BIOVEC_PHYS_MERGEABLE(bvprv, bvec))
@@ -1336,14 +1340,15 @@ int blk_rq_map_sg(request_queue_t *q, struct request *rq, struct scatterlist *sg
 				if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bvec))
 					goto new_segment;
 
-				sg[nsegs - 1].length += nbytes;
+				sg->length += nbytes;
 			} else {
 new_segment:
-				memset(&sg[nsegs],0,sizeof(struct scatterlist));
-				sg[nsegs].page = bvec->bv_page;
-				sg[nsegs].length = nbytes;
-				sg[nsegs].offset = bvec->bv_offset;
+				sg = next_sg;
+				next_sg = sg_next(sg);
 
+				sg->page = bvec->bv_page;
+				sg->length = nbytes;
+				sg->offset = bvec->bv_offset;
 				nsegs++;
 			}
 			bvprv = bvec;
-- 
1.5.2.rc1

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 3/19] libata: convert to using sg helpers, Jens Axboe, (Wed May 16, 1:32 am)
[PATCH 4/19] block: convert to using sg helpers, Jens Axboe, (Wed May 16, 1:32 am)
[PATCH 5/19] scsi: convert to using sg helpers, Jens Axboe, (Wed May 16, 1:32 am)
[PATCH 8/19] i386: enable sg chaining, Jens Axboe, (Wed May 16, 1:32 am)
[PATCH 9/19] swiotlb: sg chaining support, Jens Axboe, (Wed May 16, 1:32 am)
[PATCH 11/19] x86-64: enable sg chaining, Jens Axboe, (Wed May 16, 1:32 am)
[PATCH 12/19] IA64: sg chaining support, Jens Axboe, (Wed May 16, 1:32 am)
[PATCH 13/19] PPC: sg chaining support, Jens Axboe, (Wed May 16, 1:32 am)
[PATCH 14/19] SPARC: sg chaining support, Jens Axboe, (Wed May 16, 1:32 am)
[PATCH 15/19] SPARC64: sg chaining support, Jens Axboe, (Wed May 16, 1:32 am)
[PATCH 16/19] scsi: simplify scsi_free_sgtable(), Jens Axboe, (Wed May 16, 1:32 am)
[PATCH 19/19] drivers: sg chaining support, Jens Axboe, (Wed May 16, 1:32 am)
Re: [PATCH 5/19] scsi: convert to using sg helpers, Cornelia Huck, (Wed May 16, 4:17 am)
Re: [PATCH 5/19] scsi: convert to using sg helpers, Jens Axboe, (Wed May 16, 4:25 am)