diff options
author | Jens Axboe <jens.axboe@oracle.com> | 2007-10-16 05:08:49 -0400 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2007-10-16 05:08:49 -0400 |
commit | c6132da1704be252ee6c923f47501083d835c238 (patch) | |
tree | aa031c9091be1713e903be7ddc1ec8a03348d24f | |
parent | f565913ef8a8d0cfa46a1faaf8340cc357a46f3a (diff) |
scsi: convert to using sg helpers
This converts the SCSI mid layer to using the sg helpers for looking up
sg elements, instead of doing it manually.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
-rw-r--r-- | drivers/scsi/scsi_lib.c | 22 | ||||
-rw-r--r-- | include/scsi/scsi_cmnd.h | 3 |
2 files changed, 15 insertions, 10 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 207f1aa08869..960f949b8f8f 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/pci.h> | 17 | #include <linux/pci.h> |
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/hardirq.h> | 19 | #include <linux/hardirq.h> |
20 | #include <linux/scatterlist.h> | ||
20 | 21 | ||
21 | #include <scsi/scsi.h> | 22 | #include <scsi/scsi.h> |
22 | #include <scsi/scsi_cmnd.h> | 23 | #include <scsi/scsi_cmnd.h> |
@@ -289,14 +290,16 @@ static int scsi_req_map_sg(struct request *rq, struct scatterlist *sgl, | |||
289 | struct request_queue *q = rq->q; | 290 | struct request_queue *q = rq->q; |
290 | int nr_pages = (bufflen + sgl[0].offset + PAGE_SIZE - 1) >> PAGE_SHIFT; | 291 | int nr_pages = (bufflen + sgl[0].offset + PAGE_SIZE - 1) >> PAGE_SHIFT; |
291 | unsigned int data_len = bufflen, len, bytes, off; | 292 | unsigned int data_len = bufflen, len, bytes, off; |
293 | struct scatterlist *sg; | ||
292 | struct page *page; | 294 | struct page *page; |
293 | struct bio *bio = NULL; | 295 | struct bio *bio = NULL; |
294 | int i, err, nr_vecs = 0; | 296 | int i, err, nr_vecs = 0; |
295 | 297 | ||
296 | for (i = 0; i < nsegs; i++) { | 298 | for_each_sg(sgl, sg, nsegs, i) { |
297 | page = sgl[i].page; | 299 | page = sg->page; |
298 | off = sgl[i].offset; | 300 | off = sg->offset; |
299 | len = sgl[i].length; | 301 | len = sg->length; |
302 | data_len += len; | ||
300 | 303 | ||
301 | while (len > 0 && data_len > 0) { | 304 | while (len > 0 && data_len > 0) { |
302 | /* | 305 | /* |
@@ -2193,18 +2196,19 @@ EXPORT_SYMBOL_GPL(scsi_target_unblock); | |||
2193 | * | 2196 | * |
2194 | * Returns virtual address of the start of the mapped page | 2197 | * Returns virtual address of the start of the mapped page |
2195 | */ | 2198 | */ |
2196 | void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count, | 2199 | void *scsi_kmap_atomic_sg(struct scatterlist *sgl, int sg_count, |
2197 | size_t *offset, size_t *len) | 2200 | size_t *offset, size_t *len) |
2198 | { | 2201 | { |
2199 | int i; | 2202 | int i; |
2200 | size_t sg_len = 0, len_complete = 0; | 2203 | size_t sg_len = 0, len_complete = 0; |
2204 | struct scatterlist *sg; | ||
2201 | struct page *page; | 2205 | struct page *page; |
2202 | 2206 | ||
2203 | WARN_ON(!irqs_disabled()); | 2207 | WARN_ON(!irqs_disabled()); |
2204 | 2208 | ||
2205 | for (i = 0; i < sg_count; i++) { | 2209 | for_each_sg(sgl, sg, sg_count, i) { |
2206 | len_complete = sg_len; /* Complete sg-entries */ | 2210 | len_complete = sg_len; /* Complete sg-entries */ |
2207 | sg_len += sg[i].length; | 2211 | sg_len += sg->length; |
2208 | if (sg_len > *offset) | 2212 | if (sg_len > *offset) |
2209 | break; | 2213 | break; |
2210 | } | 2214 | } |
@@ -2218,10 +2222,10 @@ void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count, | |||
2218 | } | 2222 | } |
2219 | 2223 | ||
2220 | /* Offset starting from the beginning of first page in this sg-entry */ | 2224 | /* Offset starting from the beginning of first page in this sg-entry */ |
2221 | *offset = *offset - len_complete + sg[i].offset; | 2225 | *offset = *offset - len_complete + sg->offset; |
2222 | 2226 | ||
2223 | /* Assumption: contiguous pages can be accessed as "page + i" */ | 2227 | /* Assumption: contiguous pages can be accessed as "page + i" */ |
2224 | page = nth_page(sg[i].page, (*offset >> PAGE_SHIFT)); | 2228 | page = nth_page(sg->page, (*offset >> PAGE_SHIFT)); |
2225 | *offset &= ~PAGE_MASK; | 2229 | *offset &= ~PAGE_MASK; |
2226 | 2230 | ||
2227 | /* Bytes in this sg-entry from *offset to the end of the page */ | 2231 | /* Bytes in this sg-entry from *offset to the end of the page */ |
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 65ab5145a09b..3b0bb6680e62 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <linux/list.h> | 5 | #include <linux/list.h> |
6 | #include <linux/types.h> | 6 | #include <linux/types.h> |
7 | #include <linux/timer.h> | 7 | #include <linux/timer.h> |
8 | #include <linux/scatterlist.h> | ||
8 | 9 | ||
9 | struct request; | 10 | struct request; |
10 | struct scatterlist; | 11 | struct scatterlist; |
@@ -148,6 +149,6 @@ static inline int scsi_get_resid(struct scsi_cmnd *cmd) | |||
148 | } | 149 | } |
149 | 150 | ||
150 | #define scsi_for_each_sg(cmd, sg, nseg, __i) \ | 151 | #define scsi_for_each_sg(cmd, sg, nseg, __i) \ |
151 | for (__i = 0, sg = scsi_sglist(cmd); __i < (nseg); __i++, (sg)++) | 152 | for_each_sg(scsi_sglist(cmd), sg, nseg, __i) |
152 | 153 | ||
153 | #endif /* _SCSI_SCSI_CMND_H */ | 154 | #endif /* _SCSI_SCSI_CMND_H */ |