Commit 21a61829 authored by FUJITA Tomonori's avatar FUJITA Tomonori Committed by James Bottomley

[SCSI] scsi_debug: use sg buffer copy helper functions

Signed-off-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Douglas Gilbert <dougg@torque.net>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
parent 9ac16b61
...@@ -591,81 +591,37 @@ static int check_readiness(struct scsi_cmnd * SCpnt, int reset_only, ...@@ -591,81 +591,37 @@ static int check_readiness(struct scsi_cmnd * SCpnt, int reset_only,
} }
/* Returns 0 if ok else (DID_ERROR << 16). Sets scp->resid . */ /* Returns 0 if ok else (DID_ERROR << 16). Sets scp->resid . */
static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, static int fill_from_dev_buffer(struct scsi_cmnd *scp, unsigned char *arr,
int arr_len) int arr_len)
{ {
int k, req_len, act_len, len, active; int act_len;
void * kaddr;
void * kaddr_off;
struct scatterlist *sg;
struct scsi_data_buffer *sdb = scsi_in(scp); struct scsi_data_buffer *sdb = scsi_in(scp);
if (!sdb->length) if (!sdb->length)
return 0; return 0;
if (!sdb->table.sgl)
return (DID_ERROR << 16);
if (!(scsi_bidi_cmnd(scp) || scp->sc_data_direction == DMA_FROM_DEVICE)) if (!(scsi_bidi_cmnd(scp) || scp->sc_data_direction == DMA_FROM_DEVICE))
return (DID_ERROR << 16); return (DID_ERROR << 16);
active = 1;
req_len = act_len = 0; act_len = sg_copy_from_buffer(sdb->table.sgl, sdb->table.nents,
for_each_sg(sdb->table.sgl, sg, sdb->table.nents, k) { arr, arr_len);
if (active) {
kaddr = (unsigned char *)
kmap_atomic(sg_page(sg), KM_USER0);
if (NULL == kaddr)
return (DID_ERROR << 16);
kaddr_off = (unsigned char *)kaddr + sg->offset;
len = sg->length;
if ((req_len + len) > arr_len) {
active = 0;
len = arr_len - req_len;
}
memcpy(kaddr_off, arr + req_len, len);
kunmap_atomic(kaddr, KM_USER0);
act_len += len;
}
req_len += sg->length;
}
if (sdb->resid) if (sdb->resid)
sdb->resid -= act_len; sdb->resid -= act_len;
else else
sdb->resid = req_len - act_len; sdb->resid = scsi_bufflen(scp) - act_len;
return 0; return 0;
} }
/* Returns number of bytes fetched into 'arr' or -1 if error. */ /* Returns number of bytes fetched into 'arr' or -1 if error. */
static int fetch_to_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, static int fetch_to_dev_buffer(struct scsi_cmnd *scp, unsigned char *arr,
int max_arr_len) int arr_len)
{ {
int k, req_len, len, fin; if (!scsi_bufflen(scp))
void * kaddr;
void * kaddr_off;
struct scatterlist * sg;
if (0 == scsi_bufflen(scp))
return 0; return 0;
if (NULL == scsi_sglist(scp))
return -1;
if (!(scsi_bidi_cmnd(scp) || scp->sc_data_direction == DMA_TO_DEVICE)) if (!(scsi_bidi_cmnd(scp) || scp->sc_data_direction == DMA_TO_DEVICE))
return -1; return -1;
req_len = fin = 0;
scsi_for_each_sg(scp, sg, scsi_sg_count(scp), k) { return scsi_sg_copy_to_buffer(scp, arr, arr_len);
kaddr = (unsigned char *)kmap_atomic(sg_page(sg), KM_USER0);
if (NULL == kaddr)
return -1;
kaddr_off = (unsigned char *)kaddr + sg->offset;
len = sg->length;
if ((req_len + len) > max_arr_len) {
len = max_arr_len - req_len;
fin = 1;
}
memcpy(arr + req_len, kaddr_off, len);
kunmap_atomic(kaddr, KM_USER0);
if (fin)
return req_len + len;
req_len += sg->length;
}
return req_len;
} }
...@@ -1965,16 +1921,7 @@ static int resp_xdwriteread(struct scsi_cmnd *scp, unsigned long long lba, ...@@ -1965,16 +1921,7 @@ static int resp_xdwriteread(struct scsi_cmnd *scp, unsigned long long lba,
if (!buf) if (!buf)
return ret; return ret;
offset = 0; scsi_sg_copy_to_buffer(scp, buf, scsi_bufflen(scp));
scsi_for_each_sg(scp, sg, scsi_sg_count(scp), i) {
kaddr = (unsigned char *)kmap_atomic(sg_page(sg), KM_USER0);
if (!kaddr)
goto out;
memcpy(buf + offset, kaddr + sg->offset, sg->length);
offset += sg->length;
kunmap_atomic(kaddr, KM_USER0);
}
offset = 0; offset = 0;
for_each_sg(sdb->table.sgl, sg, sdb->table.nents, i) { for_each_sg(sdb->table.sgl, sg, sdb->table.nents, i) {
......
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