aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi_lib.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2009-05-07 09:24:37 -0400
committerJens Axboe <jens.axboe@oracle.com>2009-05-11 03:50:53 -0400
commitc3a4d78c580de4edc9ef0f7c59812fb02ceb037f (patch)
tree916ca44287100707508678e2cc0eff0c43b9ca39 /drivers/scsi/scsi_lib.c
parent9720aef2539c10e3a872e9a92beec225030d99db (diff)
block: add rq->resid_len
rq->data_len served two purposes - the length of data buffer on issue and the residual count on completion. This duality creates some headaches. First of all, block layer and low level drivers can't really determine what rq->data_len contains while a request is executing. It could be the total request length or it coulde be anything else one of the lower layers is using to keep track of residual count. This complicates things because blk_rq_bytes() and thus [__]blk_end_request_all() relies on rq->data_len for PC commands. Drivers which want to report residual count should first cache the total request length, update rq->data_len and then complete the request with the cached data length. Secondly, it makes requests default to reporting full residual count, ie. reporting that no data transfer occurred. The residual count is an exception not the norm; however, the driver should clear rq->data_len to zero to signify the normal cases while leaving it alone means no data transfer occurred at all. This reverse default behavior complicates code unnecessarily and renders block PC on some drivers (ide-tape/floppy) unuseable. This patch adds rq->resid_len which is used only for residual count. While at it, remove now unnecessasry blk_rq_bytes() caching in ide_pc_intr() as rq->data_len is not changed anymore. Boaz : spotted missing conversion in osd Sergei : spotted too early conversion to blk_rq_bytes() in ide-tape [ Impact: cleanup residual count handling, report 0 resid by default ] Signed-off-by: Tejun Heo <tj@kernel.org> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Cc: Borislav Petkov <petkovbb@googlemail.com> Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com> Cc: Mike Miller <mike.miller@hp.com> Cc: Eric Moore <Eric.Moore@lsi.com> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Doug Gilbert <dgilbert@interlog.com> Cc: Mike Miller <mike.miller@hp.com> Cc: Eric Moore <Eric.Moore@lsi.com> Cc: Darrick J. Wong <djwong@us.ibm.com> Cc: Pete Zaitcev <zaitcev@redhat.com> Cc: Boaz Harrosh <bharrosh@panasas.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'drivers/scsi/scsi_lib.c')
-rw-r--r--drivers/scsi/scsi_lib.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index aa9fc572e45f..7d49ef589f33 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -240,11 +240,11 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
240 * is invalid. Prevent the garbage from being misinterpreted 240 * is invalid. Prevent the garbage from being misinterpreted
241 * and prevent security leaks by zeroing out the excess data. 241 * and prevent security leaks by zeroing out the excess data.
242 */ 242 */
243 if (unlikely(req->data_len > 0 && req->data_len <= bufflen)) 243 if (unlikely(req->resid_len > 0 && req->resid_len <= bufflen))
244 memset(buffer + (bufflen - req->data_len), 0, req->data_len); 244 memset(buffer + (bufflen - req->resid_len), 0, req->resid_len);
245 245
246 if (resid) 246 if (resid)
247 *resid = req->data_len; 247 *resid = req->resid_len;
248 ret = req->errors; 248 ret = req->errors;
249 out: 249 out:
250 blk_put_request(req); 250 blk_put_request(req);
@@ -549,7 +549,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
549 int leftover = (req->hard_nr_sectors << 9); 549 int leftover = (req->hard_nr_sectors << 9);
550 550
551 if (blk_pc_request(req)) 551 if (blk_pc_request(req))
552 leftover = req->data_len; 552 leftover = req->resid_len;
553 553
554 /* kill remainder if no retrys */ 554 /* kill remainder if no retrys */
555 if (error && scsi_noretry_cmd(cmd)) 555 if (error && scsi_noretry_cmd(cmd))
@@ -673,11 +673,11 @@ void scsi_release_buffers(struct scsi_cmnd *cmd)
673EXPORT_SYMBOL(scsi_release_buffers); 673EXPORT_SYMBOL(scsi_release_buffers);
674 674
675/* 675/*
676 * Bidi commands Must be complete as a whole, both sides at once. 676 * Bidi commands Must be complete as a whole, both sides at once. If
677 * If part of the bytes were written and lld returned 677 * part of the bytes were written and lld returned scsi_in()->resid
678 * scsi_in()->resid and/or scsi_out()->resid this information will be left 678 * and/or scsi_out()->resid this information will be left in
679 * in req->data_len and req->next_rq->data_len. The upper-layer driver can 679 * req->resid_len and req->next_rq->resid_len. The upper-layer driver
680 * decide what to do with this information. 680 * can decide what to do with this information.
681 */ 681 */
682static void scsi_end_bidi_request(struct scsi_cmnd *cmd) 682static void scsi_end_bidi_request(struct scsi_cmnd *cmd)
683{ 683{
@@ -685,8 +685,8 @@ static void scsi_end_bidi_request(struct scsi_cmnd *cmd)
685 unsigned int dlen = req->data_len; 685 unsigned int dlen = req->data_len;
686 unsigned int next_dlen = req->next_rq->data_len; 686 unsigned int next_dlen = req->next_rq->data_len;
687 687
688 req->data_len = scsi_out(cmd)->resid; 688 req->resid_len = scsi_out(cmd)->resid;
689 req->next_rq->data_len = scsi_in(cmd)->resid; 689 req->next_rq->resid_len = scsi_in(cmd)->resid;
690 690
691 /* The req and req->next_rq have not been completed */ 691 /* The req and req->next_rq have not been completed */
692 BUG_ON(blk_end_bidi_request(req, 0, dlen, next_dlen)); 692 BUG_ON(blk_end_bidi_request(req, 0, dlen, next_dlen));
@@ -778,7 +778,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
778 scsi_end_bidi_request(cmd); 778 scsi_end_bidi_request(cmd);
779 return; 779 return;
780 } 780 }
781 req->data_len = scsi_get_resid(cmd); 781 req->resid_len = scsi_get_resid(cmd);
782 } 782 }
783 783
784 BUG_ON(blk_bidi_rq(req)); /* bidi not support for !blk_pc_request yet */ 784 BUG_ON(blk_bidi_rq(req)); /* bidi not support for !blk_pc_request yet */