From: Boaz Harrosh <bharrosh@panasas.com>
To: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: linux-scsi <linux-scsi@vger.kernel.org>,
James Bottomley <James.Bottomley@SteelEye.com>
Subject: [PATCH] scsi_debug: convert to use the data buffer accessors and !use_sg cleanup
Date: Wed, 04 Jul 2007 21:28:01 +0300 [thread overview]
Message-ID: <468BE6B1.6040807@panasas.com> (raw)
In-Reply-To: <468BE4CE.80402@panasas.com>
scsi_debug is just a synthetic scsi target that simulate
a scsi device and can inject errors to test the error
handling paths in scsi-ml. As any scsi LLD it is converted
to use the new data accessors.
- Use of new data accessors
- Clean of !use_sg code path.
Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
---
drivers/scsi/scsi_debug.c | 46 +++++++++++++++-----------------------------
1 files changed, 16 insertions(+), 30 deletions(-)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 4cd9c58..1e2d6bb 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -328,7 +328,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
if (done == NULL)
return 0; /* assume mid level reprocessing command */
- SCpnt->resid = 0;
+ scsi_set_resid(SCpnt, 0);
if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmd) {
printk(KERN_INFO "scsi_debug: cmd ");
for (k = 0, len = SCpnt->cmd_len; k < len; ++k)
@@ -597,31 +597,22 @@ static int check_readiness(struct scsi_cmnd * SCpnt, int reset_only,
static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
int arr_len)
{
- int k, req_len, act_len, len, active;
+ int k, req_len, act_len, len, active, sg_count;
void * kaddr;
void * kaddr_off;
struct scatterlist * sgpnt;
- if (0 == scp->request_bufflen)
+ if (0 == scsi_bufflen(scp))
return 0;
- if (NULL == scp->request_buffer)
+ if (NULL == scsi_sglist(scp))
return (DID_ERROR << 16);
if (! ((scp->sc_data_direction == DMA_BIDIRECTIONAL) ||
(scp->sc_data_direction == DMA_FROM_DEVICE)))
return (DID_ERROR << 16);
- if (0 == scp->use_sg) {
- req_len = scp->request_bufflen;
- act_len = (req_len < arr_len) ? req_len : arr_len;
- memcpy(scp->request_buffer, arr, act_len);
- if (scp->resid)
- scp->resid -= act_len;
- else
- scp->resid = req_len - act_len;
- return 0;
- }
- sgpnt = (struct scatterlist *)scp->request_buffer;
+ sg_count = scsi_sg_count(scp);
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, sgpnt, sg_count, k) {
if (active) {
kaddr = (unsigned char *)
kmap_atomic(sgpnt->page, KM_USER0);
@@ -639,10 +630,10 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
}
req_len += sgpnt->length;
}
- if (scp->resid)
- scp->resid -= act_len;
+ if (scsi_get_resid(scp))
+ scsi_set_resid(scp, scsi_get_resid(scp) - act_len);
else
- scp->resid = req_len - act_len;
+ scsi_set_resid(scp, req_len - act_len);
return 0;
}
@@ -650,26 +641,21 @@ static int fill_from_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 k, req_len, len, fin;
+ int k, req_len, len, fin, sg_count;
void * kaddr;
void * kaddr_off;
struct scatterlist * sgpnt;
- if (0 == scp->request_bufflen)
+ if (0 == scsi_bufflen(scp))
return 0;
- if (NULL == scp->request_buffer)
+ if (NULL == scsi_sglist(scp))
return -1;
if (! ((scp->sc_data_direction == DMA_BIDIRECTIONAL) ||
(scp->sc_data_direction == DMA_TO_DEVICE)))
return -1;
- if (0 == scp->use_sg) {
- req_len = scp->request_bufflen;
- len = (req_len < max_arr_len) ? req_len : max_arr_len;
- memcpy(arr, scp->request_buffer, len);
- return len;
- }
- sgpnt = (struct scatterlist *)scp->request_buffer;
- for (k = 0, req_len = 0, fin = 0; k < scp->use_sg; ++k, ++sgpnt) {
+ sg_count = scsi_sg_count(scp);
+ req_len = fin = 0;
+ scsi_for_each_sg(scp, sgpnt, sg_count, k) {
kaddr = (unsigned char *)kmap_atomic(sgpnt->page, KM_USER0);
if (NULL == kaddr)
return -1;
--
1.5.2.2.249.g45fd
next prev parent reply other threads:[~2007-07-04 18:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-04 18:19 Data accessors more patches Boaz Harrosh
2007-07-04 18:24 ` [PATCH] libata-scsi.c: convert to use the data buffer accessors Boaz Harrosh
2007-07-04 18:26 ` [PATCH] scsi.c: " Boaz Harrosh
2007-07-04 18:28 ` Boaz Harrosh [this message]
2007-07-12 13:11 ` [PATCH] microtek.c - use data accessors and !use_sg cleanup Boaz Harrosh
2007-07-12 13:24 ` Boaz Harrosh
2007-07-12 16:58 ` Greg KH
2007-07-12 17:04 ` Boaz Harrosh
2007-07-12 17:05 ` James Bottomley
2007-07-12 18:05 ` Greg KH
2007-07-12 13:29 ` Oliver Neukum
2007-07-12 13:54 ` James Bottomley
2007-07-12 13:56 ` Oliver Neukum
2007-07-12 14:01 ` Boaz Harrosh
2007-07-12 13:58 ` Boaz Harrosh
2007-07-12 13:13 ` Data accessors more patches Boaz Harrosh
2007-07-12 22:37 ` FUJITA Tomonori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=468BE6B1.6040807@panasas.com \
--to=bharrosh@panasas.com \
--cc=James.Bottomley@SteelEye.com \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).