Skip to content

Commit bc85dc5

Browse files
author
Christoph Hellwig
committed
scsi: remove scsi_end_request
By folding scsi_end_request into its only caller we can significantly clean up the completion logic. We can use simple goto labels now to only have a single place to finish or requeue command there instead of the previous convoluted logic. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Nicholas Bellinger <nab@linux-iscsi.org> Reviewed-by: Mike Christie <michaelc@cs.wisc.edu> Reviewed-by: Hannes Reinecke <hare@suse.de>
1 parent c682adf commit bc85dc5

File tree

1 file changed

+32
-82
lines changed

1 file changed

+32
-82
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 32 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -512,66 +512,6 @@ void scsi_run_host_queues(struct Scsi_Host *shost)
512512
scsi_run_queue(sdev->request_queue);
513513
}
514514

515-
/*
516-
* Function: scsi_end_request()
517-
*
518-
* Purpose: Post-processing of completed commands (usually invoked at end
519-
* of upper level post-processing and scsi_io_completion).
520-
*
521-
* Arguments: cmd - command that is complete.
522-
* error - 0 if I/O indicates success, < 0 for I/O error.
523-
* bytes - number of bytes of completed I/O
524-
* requeue - indicates whether we should requeue leftovers.
525-
*
526-
* Lock status: Assumed that lock is not held upon entry.
527-
*
528-
* Returns: cmd if requeue required, NULL otherwise.
529-
*
530-
* Notes: This is called for block device requests in order to
531-
* mark some number of sectors as complete.
532-
*
533-
* We are guaranteeing that the request queue will be goosed
534-
* at some point during this call.
535-
* Notes: If cmd was requeued, upon return it will be a stale pointer.
536-
*/
537-
static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
538-
int bytes, int requeue)
539-
{
540-
struct request_queue *q = cmd->device->request_queue;
541-
struct request *req = cmd->request;
542-
543-
/*
544-
* If there are blocks left over at the end, set up the command
545-
* to queue the remainder of them.
546-
*/
547-
if (blk_end_request(req, error, bytes)) {
548-
/* kill remainder if no retrys */
549-
if (error && scsi_noretry_cmd(cmd))
550-
blk_end_request_all(req, error);
551-
else {
552-
if (requeue) {
553-
/*
554-
* Bleah. Leftovers again. Stick the
555-
* leftovers in the front of the
556-
* queue, and goose the queue again.
557-
*/
558-
scsi_release_buffers(cmd);
559-
scsi_requeue_command(q, cmd);
560-
cmd = NULL;
561-
}
562-
return cmd;
563-
}
564-
}
565-
566-
/*
567-
* This will goose the queue request function at the end, so we don't
568-
* need to worry about launching another command.
569-
*/
570-
scsi_release_buffers(cmd);
571-
scsi_next_command(cmd);
572-
return NULL;
573-
}
574-
575515
static inline unsigned int scsi_sgtable_index(unsigned short nents)
576516
{
577517
unsigned int index;
@@ -717,16 +657,9 @@ static int __scsi_error_from_host_byte(struct scsi_cmnd *cmd, int result)
717657
*
718658
* Returns: Nothing
719659
*
720-
* Notes: This function is matched in terms of capabilities to
721-
* the function that created the scatter-gather list.
722-
* In other words, if there are no bounce buffers
723-
* (the normal case for most drivers), we don't need
724-
* the logic to deal with cleaning up afterwards.
725-
*
726-
* We must call scsi_end_request(). This will finish off
727-
* the specified number of sectors. If we are done, the
728-
* command block will be released and the queue function
729-
* will be goosed. If we are not done then we have to
660+
* Notes: We will finish off the specified number of sectors. If we
661+
* are done, the command block will be released and the queue
662+
* function will be goosed. If we are not done then we have to
730663
* figure out what to do next:
731664
*
732665
* a) We can call scsi_requeue_command(). The request
@@ -735,7 +668,7 @@ static int __scsi_error_from_host_byte(struct scsi_cmnd *cmd, int result)
735668
* be used if we made forward progress, or if we want
736669
* to switch from READ(10) to READ(6) for example.
737670
*
738-
* b) We can call scsi_queue_insert(). The request will
671+
* b) We can call __scsi_queue_insert(). The request will
739672
* be put back on the queue and retried using the same
740673
* command as before, possibly after a delay.
741674
*
@@ -794,6 +727,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
794727

795728
scsi_release_buffers(cmd);
796729
scsi_release_bidi_buffers(cmd);
730+
797731
blk_end_request_all(req, 0);
798732

799733
scsi_next_command(cmd);
@@ -833,12 +767,25 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
833767
}
834768

835769
/*
836-
* A number of bytes were successfully read. If there
837-
* are leftovers and there is some kind of error
838-
* (result != 0), retry the rest.
770+
* If we finished all bytes in the request we are done now.
839771
*/
840-
if (scsi_end_request(cmd, error, good_bytes, result == 0) == NULL)
841-
return;
772+
if (!blk_end_request(req, error, good_bytes))
773+
goto next_command;
774+
775+
/*
776+
* Kill remainder if no retrys.
777+
*/
778+
if (error && scsi_noretry_cmd(cmd)) {
779+
blk_end_request_all(req, error);
780+
goto next_command;
781+
}
782+
783+
/*
784+
* If there had been no error, but we have leftover bytes in the
785+
* requeues just queue the command up again.
786+
*/
787+
if (result == 0)
788+
goto requeue;
842789

843790
error = __scsi_error_from_host_byte(cmd, result);
844791

@@ -966,7 +913,6 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
966913
switch (action) {
967914
case ACTION_FAIL:
968915
/* Give up and fail the remainder of the request */
969-
scsi_release_buffers(cmd);
970916
if (!(req->cmd_flags & REQ_QUIET)) {
971917
if (description)
972918
scmd_printk(KERN_INFO, cmd, "%s\n",
@@ -976,12 +922,11 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
976922
scsi_print_sense("", cmd);
977923
scsi_print_command(cmd);
978924
}
979-
if (blk_end_request_err(req, error))
980-
scsi_requeue_command(q, cmd);
981-
else
982-
scsi_next_command(cmd);
983-
break;
925+
if (!blk_end_request_err(req, error))
926+
goto next_command;
927+
/*FALLTHRU*/
984928
case ACTION_REPREP:
929+
requeue:
985930
/* Unprep the request and put it back at the head of the queue.
986931
* A new command will be prepared and issued.
987932
*/
@@ -997,6 +942,11 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
997942
__scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY, 0);
998943
break;
999944
}
945+
return;
946+
947+
next_command:
948+
scsi_release_buffers(cmd);
949+
scsi_next_command(cmd);
1000950
}
1001951

1002952
static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,

0 commit comments

Comments
 (0)