Commit 852e034d authored by Jens Axboe's avatar Jens Axboe

scsi_debug: support sg chaining

Signed-off-by: default avatarDouglas Gilbert <dougg@torque.net>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 87260216
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/scatterlist.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include "scsi.h" #include "scsi.h"
...@@ -600,7 +601,7 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, ...@@ -600,7 +601,7 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
int k, req_len, act_len, len, active; int k, req_len, act_len, len, active;
void * kaddr; void * kaddr;
void * kaddr_off; void * kaddr_off;
struct scatterlist * sgpnt; struct scatterlist * sg;
if (0 == scp->request_bufflen) if (0 == scp->request_bufflen)
return 0; return 0;
...@@ -619,16 +620,16 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, ...@@ -619,16 +620,16 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
scp->resid = req_len - act_len; scp->resid = req_len - act_len;
return 0; return 0;
} }
sgpnt = (struct scatterlist *)scp->request_buffer;
active = 1; active = 1;
for (k = 0, req_len = 0, act_len = 0; k < scp->use_sg; ++k, ++sgpnt) { req_len = act_len = 0;
scsi_for_each_sg(scp, sg, scp->use_sg, k) {
if (active) { if (active) {
kaddr = (unsigned char *) kaddr = (unsigned char *)
kmap_atomic(sgpnt->page, KM_USER0); kmap_atomic(sg->page, KM_USER0);
if (NULL == kaddr) if (NULL == kaddr)
return (DID_ERROR << 16); return (DID_ERROR << 16);
kaddr_off = (unsigned char *)kaddr + sgpnt->offset; kaddr_off = (unsigned char *)kaddr + sg->offset;
len = sgpnt->length; len = sg->length;
if ((req_len + len) > arr_len) { if ((req_len + len) > arr_len) {
active = 0; active = 0;
len = arr_len - req_len; len = arr_len - req_len;
...@@ -637,7 +638,7 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, ...@@ -637,7 +638,7 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
kunmap_atomic(kaddr, KM_USER0); kunmap_atomic(kaddr, KM_USER0);
act_len += len; act_len += len;
} }
req_len += sgpnt->length; req_len += sg->length;
} }
if (scp->resid) if (scp->resid)
scp->resid -= act_len; scp->resid -= act_len;
...@@ -653,7 +654,7 @@ static int fetch_to_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, ...@@ -653,7 +654,7 @@ static int fetch_to_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
int k, req_len, len, fin; int k, req_len, len, fin;
void * kaddr; void * kaddr;
void * kaddr_off; void * kaddr_off;
struct scatterlist * sgpnt; struct scatterlist * sg;
if (0 == scp->request_bufflen) if (0 == scp->request_bufflen)
return 0; return 0;
...@@ -668,13 +669,14 @@ static int fetch_to_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, ...@@ -668,13 +669,14 @@ static int fetch_to_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
memcpy(arr, scp->request_buffer, len); memcpy(arr, scp->request_buffer, len);
return len; return len;
} }
sgpnt = (struct scatterlist *)scp->request_buffer; sg = scsi_sglist(scp);
for (k = 0, req_len = 0, fin = 0; k < scp->use_sg; ++k, ++sgpnt) { req_len = fin = 0;
kaddr = (unsigned char *)kmap_atomic(sgpnt->page, KM_USER0); for (k = 0; k < scp->use_sg; ++k, sg = sg_next(sg)) {
kaddr = (unsigned char *)kmap_atomic(sg->page, KM_USER0);
if (NULL == kaddr) if (NULL == kaddr)
return -1; return -1;
kaddr_off = (unsigned char *)kaddr + sgpnt->offset; kaddr_off = (unsigned char *)kaddr + sg->offset;
len = sgpnt->length; len = sg->length;
if ((req_len + len) > max_arr_len) { if ((req_len + len) > max_arr_len) {
len = max_arr_len - req_len; len = max_arr_len - req_len;
fin = 1; fin = 1;
...@@ -683,7 +685,7 @@ static int fetch_to_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, ...@@ -683,7 +685,7 @@ static int fetch_to_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
kunmap_atomic(kaddr, KM_USER0); kunmap_atomic(kaddr, KM_USER0);
if (fin) if (fin)
return req_len + len; return req_len + len;
req_len += sgpnt->length; req_len += sg->length;
} }
return req_len; return req_len;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment