diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2008-11-03 15:56:47 -0500 |
---|---|---|
committer | James Bottomley <James.Bottomley@HansenPartnership.com> | 2008-12-29 12:24:18 -0500 |
commit | b60af5b0adf0da24c673598c8d3fb4d4189a15ce (patch) | |
tree | 95981f6b1fd122c3a751cdb733ce0489a375c8aa /drivers/scsi/scsi_lib.c | |
parent | 67e6d58d812ec3e95918266076d4c836cdec849a (diff) |
[SCSI] simplify scsi_io_completion()
This patch (as1142b) consolidates a lot of repetitious code in
scsi_io_completion(). It also fixes a few comments. Most
importantly, however, it clearly distinguishes among the three sorts
of retries that can be done when a command fails to complete:
Unprepare the request and resubmit it, so that a new
command will be created for it.
Requeue the request directly so that it will be retried
immediately using the same command.
Requeue the request so that it will be retried following
a short delay.
Complete the remainder of the request with an I/O error.
[jejb: Updates
1. For several error conditions, we would now print the sense twice
in slightly different ways, so unify the location of sense
printing.
2. I added more descriptions to actual failure conditions for
better debugging
3. according to spec, ABORTED_COMMAND is supposed to be retried
(except on DIF failure). Our old behaviour of erroring it looks
to be a bug.
4. I'd prefer not to default initialise the action variable because
that ensures that every leg of the error handler has an
associated action and the compiler will warn if someone later
accidentally misses one or removes one.
]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/scsi/scsi_lib.c')
-rw-r--r-- | drivers/scsi/scsi_lib.c | 136 |
1 files changed, 77 insertions, 59 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 148d3af92aef..ecfbbd30dce5 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c | |||
@@ -875,16 +875,24 @@ static void scsi_end_bidi_request(struct scsi_cmnd *cmd) | |||
875 | * (the normal case for most drivers), we don't need | 875 | * (the normal case for most drivers), we don't need |
876 | * the logic to deal with cleaning up afterwards. | 876 | * the logic to deal with cleaning up afterwards. |
877 | * | 877 | * |
878 | * We must do one of several things here: | 878 | * We must call scsi_end_request(). This will finish off |
879 | * | 879 | * the specified number of sectors. If we are done, the |
880 | * a) Call scsi_end_request. This will finish off the | 880 | * command block will be released and the queue function |
881 | * specified number of sectors. If we are done, the | 881 | * will be goosed. If we are not done then we have to |
882 | * command block will be released, and the queue | 882 | * figure out what to do next: |
883 | * function will be goosed. If we are not done, then | 883 | * |
884 | * scsi_end_request will directly goose the queue. | 884 | * a) We can call scsi_requeue_command(). The request |
885 | * | 885 | * will be unprepared and put back on the queue. Then |
886 | * b) We can just use scsi_requeue_command() here. This would | 886 | * a new command will be created for it. This should |
887 | * be used if we just wanted to retry, for example. | 887 | * be used if we made forward progress, or if we want |
888 | * to switch from READ(10) to READ(6) for example. | ||
889 | * | ||
890 | * b) We can call scsi_queue_insert(). The request will | ||
891 | * be put back on the queue and retried using the same | ||
892 | * command as before, possibly after a delay. | ||
893 | * | ||
894 | * c) We can call blk_end_request() with -EIO to fail | ||
895 | * the remainder of the request. | ||
888 | */ | 896 | */ |
889 | void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) | 897 | void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) |
890 | { | 898 | { |
@@ -896,6 +904,9 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) | |||
896 | struct scsi_sense_hdr sshdr; | 904 | struct scsi_sense_hdr sshdr; |
897 | int sense_valid = 0; | 905 | int sense_valid = 0; |
898 | int sense_deferred = 0; | 906 | int sense_deferred = 0; |
907 | enum {ACTION_FAIL, ACTION_REPREP, ACTION_RETRY, | ||
908 | ACTION_DELAYED_RETRY} action; | ||
909 | char *description = NULL; | ||
899 | 910 | ||
900 | if (result) { | 911 | if (result) { |
901 | sense_valid = scsi_command_normalize_sense(cmd, &sshdr); | 912 | sense_valid = scsi_command_normalize_sense(cmd, &sshdr); |
@@ -947,10 +958,13 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) | |||
947 | return; | 958 | return; |
948 | this_count = blk_rq_bytes(req); | 959 | this_count = blk_rq_bytes(req); |
949 | 960 | ||
950 | /* good_bytes = 0, or (inclusive) there were leftovers and | 961 | if (host_byte(result) == DID_RESET) { |
951 | * result = 0, so scsi_end_request couldn't retry. | 962 | /* Third party bus reset or reset for error recovery |
952 | */ | 963 | * reasons. Just retry the command and see what |
953 | if (sense_valid && !sense_deferred) { | 964 | * happens. |
965 | */ | ||
966 | action = ACTION_RETRY; | ||
967 | } else if (sense_valid && !sense_deferred) { | ||
954 | switch (sshdr.sense_key) { | 968 | switch (sshdr.sense_key) { |
955 | case UNIT_ATTENTION: | 969 | case UNIT_ATTENTION: |
956 | if (cmd->device->removable) { | 970 | if (cmd->device->removable) { |
@@ -958,16 +972,15 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) | |||
958 | * and quietly refuse further access. | 972 | * and quietly refuse further access. |
959 | */ | 973 | */ |
960 | cmd->device->changed = 1; | 974 | cmd->device->changed = 1; |
961 | scsi_end_request(cmd, -EIO, this_count, 1); | 975 | description = "Media Changed"; |
962 | return; | 976 | action = ACTION_FAIL; |
963 | } else { | 977 | } else { |
964 | /* Must have been a power glitch, or a | 978 | /* Must have been a power glitch, or a |
965 | * bus reset. Could not have been a | 979 | * bus reset. Could not have been a |
966 | * media change, so we just retry the | 980 | * media change, so we just retry the |
967 | * request and see what happens. | 981 | * command and see what happens. |
968 | */ | 982 | */ |
969 | scsi_requeue_command(q, cmd); | 983 | action = ACTION_RETRY; |
970 | return; | ||
971 | } | 984 | } |
972 | break; | 985 | break; |
973 | case ILLEGAL_REQUEST: | 986 | case ILLEGAL_REQUEST: |
@@ -983,21 +996,18 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) | |||
983 | sshdr.asc == 0x20 && sshdr.ascq == 0x00) && | 996 | sshdr.asc == 0x20 && sshdr.ascq == 0x00) && |
984 | (cmd->cmnd[0] == READ_10 || | 997 | (cmd->cmnd[0] == READ_10 || |
985 | cmd->cmnd[0] == WRITE_10)) { | 998 | cmd->cmnd[0] == WRITE_10)) { |
999 | /* This will issue a new 6-byte command. */ | ||
986 | cmd->device->use_10_for_rw = 0; | 1000 | cmd->device->use_10_for_rw = 0; |
987 | /* This will cause a retry with a | 1001 | action = ACTION_REPREP; |
988 | * 6-byte command. | 1002 | } else |
989 | */ | 1003 | action = ACTION_FAIL; |
990 | scsi_requeue_command(q, cmd); | 1004 | break; |
991 | } else if (sshdr.asc == 0x10) /* DIX */ | ||
992 | scsi_end_request(cmd, -EIO, this_count, 0); | ||
993 | else | ||
994 | scsi_end_request(cmd, -EIO, this_count, 1); | ||
995 | return; | ||
996 | case ABORTED_COMMAND: | 1005 | case ABORTED_COMMAND: |
997 | if (sshdr.asc == 0x10) { /* DIF */ | 1006 | if (sshdr.asc == 0x10) { /* DIF */ |
998 | scsi_end_request(cmd, -EIO, this_count, 0); | 1007 | action = ACTION_FAIL; |
999 | return; | 1008 | description = "Data Integrity Failure"; |
1000 | } | 1009 | } else |
1010 | action = ACTION_RETRY; | ||
1001 | break; | 1011 | break; |
1002 | case NOT_READY: | 1012 | case NOT_READY: |
1003 | /* If the device is in the process of becoming | 1013 | /* If the device is in the process of becoming |
@@ -1012,49 +1022,57 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) | |||
1012 | case 0x07: /* operation in progress */ | 1022 | case 0x07: /* operation in progress */ |
1013 | case 0x08: /* Long write in progress */ | 1023 | case 0x08: /* Long write in progress */ |
1014 | case 0x09: /* self test in progress */ | 1024 | case 0x09: /* self test in progress */ |
1015 | scsi_requeue_command(q, cmd); | 1025 | action = ACTION_DELAYED_RETRY; |
1016 | return; | ||
1017 | default: | ||
1018 | break; | 1026 | break; |
1019 | } | 1027 | } |
1028 | } else { | ||
1029 | description = "Device not ready"; | ||
1030 | action = ACTION_FAIL; | ||
1020 | } | 1031 | } |
1021 | if (!(req->cmd_flags & REQ_QUIET)) | 1032 | break; |
1022 | scsi_cmd_print_sense_hdr(cmd, | ||
1023 | "Device not ready", | ||
1024 | &sshdr); | ||
1025 | |||
1026 | scsi_end_request(cmd, -EIO, this_count, 1); | ||
1027 | return; | ||
1028 | case VOLUME_OVERFLOW: | 1033 | case VOLUME_OVERFLOW: |
1029 | if (!(req->cmd_flags & REQ_QUIET)) { | ||
1030 | scmd_printk(KERN_INFO, cmd, | ||
1031 | "Volume overflow, CDB: "); | ||
1032 | __scsi_print_command(cmd->cmnd); | ||
1033 | scsi_print_sense("", cmd); | ||
1034 | } | ||
1035 | /* See SSC3rXX or current. */ | 1034 | /* See SSC3rXX or current. */ |
1036 | scsi_end_request(cmd, -EIO, this_count, 1); | 1035 | action = ACTION_FAIL; |
1037 | return; | 1036 | break; |
1038 | default: | 1037 | default: |
1038 | description = "Unhandled sense code"; | ||
1039 | action = ACTION_FAIL; | ||
1039 | break; | 1040 | break; |
1040 | } | 1041 | } |
1042 | } else { | ||
1043 | description = "Unhandled error code"; | ||
1044 | action = ACTION_FAIL; | ||
1041 | } | 1045 | } |
1042 | if (host_byte(result) == DID_RESET) { | 1046 | |
1043 | /* Third party bus reset or reset for error recovery | 1047 | switch (action) { |
1044 | * reasons. Just retry the request and see what | 1048 | case ACTION_FAIL: |
1045 | * happens. | 1049 | /* Give up and fail the remainder of the request */ |
1046 | */ | ||
1047 | scsi_requeue_command(q, cmd); | ||
1048 | return; | ||
1049 | } | ||
1050 | if (result) { | ||
1051 | if (!(req->cmd_flags & REQ_QUIET)) { | 1050 | if (!(req->cmd_flags & REQ_QUIET)) { |
1051 | if (description) | ||
1052 | scmd_printk(KERN_INFO, cmd, "%s", | ||
1053 | description); | ||
1052 | scsi_print_result(cmd); | 1054 | scsi_print_result(cmd); |
1053 | if (driver_byte(result) & DRIVER_SENSE) | 1055 | if (driver_byte(result) & DRIVER_SENSE) |
1054 | scsi_print_sense("", cmd); | 1056 | scsi_print_sense("", cmd); |
1055 | } | 1057 | } |
1058 | blk_end_request(req, -EIO, blk_rq_bytes(req)); | ||
1059 | scsi_next_command(cmd); | ||
1060 | break; | ||
1061 | case ACTION_REPREP: | ||
1062 | /* Unprep the request and put it back at the head of the queue. | ||
1063 | * A new command will be prepared and issued. | ||
1064 | */ | ||
1065 | scsi_requeue_command(q, cmd); | ||
1066 | break; | ||
1067 | case ACTION_RETRY: | ||
1068 | /* Retry the same command immediately */ | ||
1069 | scsi_queue_insert(cmd, SCSI_MLQUEUE_EH_RETRY); | ||
1070 | break; | ||
1071 | case ACTION_DELAYED_RETRY: | ||
1072 | /* Retry the same command after a delay */ | ||
1073 | scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY); | ||
1074 | break; | ||
1056 | } | 1075 | } |
1057 | scsi_end_request(cmd, -EIO, this_count, !result); | ||
1058 | } | 1076 | } |
1059 | 1077 | ||
1060 | static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb, | 1078 | static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb, |