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>
This commit is contained in:
parent
f565913ef8
commit
c6132da170
@ -17,6 +17,7 @@
|
|||||||
#include <linux/pci.h>
|
#include <linux/pci.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/hardirq.h>
|
#include <linux/hardirq.h>
|
||||||
|
#include <linux/scatterlist.h>
|
||||||
|
|
||||||
#include <scsi/scsi.h>
|
#include <scsi/scsi.h>
|
||||||
#include <scsi/scsi_cmnd.h>
|
#include <scsi/scsi_cmnd.h>
|
||||||
@ -289,14 +290,16 @@ static int scsi_req_map_sg(struct request *rq, struct scatterlist *sgl,
|
|||||||
struct request_queue *q = rq->q;
|
struct request_queue *q = rq->q;
|
||||||
int nr_pages = (bufflen + sgl[0].offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
int nr_pages = (bufflen + sgl[0].offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
||||||
unsigned int data_len = bufflen, len, bytes, off;
|
unsigned int data_len = bufflen, len, bytes, off;
|
||||||
|
struct scatterlist *sg;
|
||||||
struct page *page;
|
struct page *page;
|
||||||
struct bio *bio = NULL;
|
struct bio *bio = NULL;
|
||||||
int i, err, nr_vecs = 0;
|
int i, err, nr_vecs = 0;
|
||||||
|
|
||||||
for (i = 0; i < nsegs; i++) {
|
for_each_sg(sgl, sg, nsegs, i) {
|
||||||
page = sgl[i].page;
|
page = sg->page;
|
||||||
off = sgl[i].offset;
|
off = sg->offset;
|
||||||
len = sgl[i].length;
|
len = sg->length;
|
||||||
|
data_len += len;
|
||||||
|
|
||||||
while (len > 0 && data_len > 0) {
|
while (len > 0 && data_len > 0) {
|
||||||
/*
|
/*
|
||||||
@ -2193,18 +2196,19 @@ EXPORT_SYMBOL_GPL(scsi_target_unblock);
|
|||||||
*
|
*
|
||||||
* Returns virtual address of the start of the mapped page
|
* Returns virtual address of the start of the mapped page
|
||||||
*/
|
*/
|
||||||
void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
|
void *scsi_kmap_atomic_sg(struct scatterlist *sgl, int sg_count,
|
||||||
size_t *offset, size_t *len)
|
size_t *offset, size_t *len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
size_t sg_len = 0, len_complete = 0;
|
size_t sg_len = 0, len_complete = 0;
|
||||||
|
struct scatterlist *sg;
|
||||||
struct page *page;
|
struct page *page;
|
||||||
|
|
||||||
WARN_ON(!irqs_disabled());
|
WARN_ON(!irqs_disabled());
|
||||||
|
|
||||||
for (i = 0; i < sg_count; i++) {
|
for_each_sg(sgl, sg, sg_count, i) {
|
||||||
len_complete = sg_len; /* Complete sg-entries */
|
len_complete = sg_len; /* Complete sg-entries */
|
||||||
sg_len += sg[i].length;
|
sg_len += sg->length;
|
||||||
if (sg_len > *offset)
|
if (sg_len > *offset)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2218,10 +2222,10 @@ void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Offset starting from the beginning of first page in this sg-entry */
|
/* Offset starting from the beginning of first page in this sg-entry */
|
||||||
*offset = *offset - len_complete + sg[i].offset;
|
*offset = *offset - len_complete + sg->offset;
|
||||||
|
|
||||||
/* Assumption: contiguous pages can be accessed as "page + i" */
|
/* Assumption: contiguous pages can be accessed as "page + i" */
|
||||||
page = nth_page(sg[i].page, (*offset >> PAGE_SHIFT));
|
page = nth_page(sg->page, (*offset >> PAGE_SHIFT));
|
||||||
*offset &= ~PAGE_MASK;
|
*offset &= ~PAGE_MASK;
|
||||||
|
|
||||||
/* Bytes in this sg-entry from *offset to the end of the page */
|
/* Bytes in this sg-entry from *offset to the end of the page */
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <linux/timer.h>
|
#include <linux/timer.h>
|
||||||
|
#include <linux/scatterlist.h>
|
||||||
|
|
||||||
struct request;
|
struct request;
|
||||||
struct scatterlist;
|
struct scatterlist;
|
||||||
@ -148,6 +149,6 @@ static inline int scsi_get_resid(struct scsi_cmnd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define scsi_for_each_sg(cmd, sg, nseg, __i) \
|
#define scsi_for_each_sg(cmd, sg, nseg, __i) \
|
||||||
for (__i = 0, sg = scsi_sglist(cmd); __i < (nseg); __i++, (sg)++)
|
for_each_sg(scsi_sglist(cmd), sg, nseg, __i)
|
||||||
|
|
||||||
#endif /* _SCSI_SCSI_CMND_H */
|
#endif /* _SCSI_SCSI_CMND_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user