aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/scsi_lib.c')
-rw-r--r--drivers/scsi/scsi_lib.c124
1 files changed, 51 insertions, 73 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 3d04a9f386ac..08af9aae7df3 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -855,8 +855,7 @@ static void scsi_release_buffers(struct scsi_cmnd *cmd)
855 * b) We can just use scsi_requeue_command() here. This would 855 * b) We can just use scsi_requeue_command() here. This would
856 * be used if we just wanted to retry, for example. 856 * be used if we just wanted to retry, for example.
857 */ 857 */
858void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, 858void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
859 unsigned int block_bytes)
860{ 859{
861 int result = cmd->result; 860 int result = cmd->result;
862 int this_count = cmd->bufflen; 861 int this_count = cmd->bufflen;
@@ -921,87 +920,70 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
921 * Next deal with any sectors which we were able to correctly 920 * Next deal with any sectors which we were able to correctly
922 * handle. 921 * handle.
923 */ 922 */
924 if (good_bytes >= 0) { 923 SCSI_LOG_HLCOMPLETE(1, printk("%ld sectors total, "
925 SCSI_LOG_HLCOMPLETE(1, printk("%ld sectors total, %d bytes done.\n", 924 "%d bytes done.\n",
926 req->nr_sectors, good_bytes)); 925 req->nr_sectors, good_bytes));
927 SCSI_LOG_HLCOMPLETE(1, printk("use_sg is %d\n", cmd->use_sg)); 926 SCSI_LOG_HLCOMPLETE(1, printk("use_sg is %d\n", cmd->use_sg));
928 927
929 if (clear_errors) 928 if (clear_errors)
930 req->errors = 0; 929 req->errors = 0;
931 /*
932 * If multiple sectors are requested in one buffer, then
933 * they will have been finished off by the first command.
934 * If not, then we have a multi-buffer command.
935 *
936 * If block_bytes != 0, it means we had a medium error
937 * of some sort, and that we want to mark some number of
938 * sectors as not uptodate. Thus we want to inhibit
939 * requeueing right here - we will requeue down below
940 * when we handle the bad sectors.
941 */
942 930
943 /* 931 /* A number of bytes were successfully read. If there
944 * If the command completed without error, then either 932 * are leftovers and there is some kind of error
945 * finish off the rest of the command, or start a new one. 933 * (result != 0), retry the rest.
946 */ 934 */
947 if (scsi_end_request(cmd, 1, good_bytes, result == 0) == NULL) 935 if (scsi_end_request(cmd, 1, good_bytes, result == 0) == NULL)
948 return; 936 return;
949 } 937
950 /* 938 /* good_bytes = 0, or (inclusive) there were leftovers and
951 * Now, if we were good little boys and girls, Santa left us a request 939 * result = 0, so scsi_end_request couldn't retry.
952 * sense buffer. We can extract information from this, so we
953 * can choose a block to remap, etc.
954 */ 940 */
955 if (sense_valid && !sense_deferred) { 941 if (sense_valid && !sense_deferred) {
956 switch (sshdr.sense_key) { 942 switch (sshdr.sense_key) {
957 case UNIT_ATTENTION: 943 case UNIT_ATTENTION:
958 if (cmd->device->removable) { 944 if (cmd->device->removable) {
959 /* detected disc change. set a bit 945 /* Detected disc change. Set a bit
960 * and quietly refuse further access. 946 * and quietly refuse further access.
961 */ 947 */
962 cmd->device->changed = 1; 948 cmd->device->changed = 1;
963 scsi_end_request(cmd, 0, 949 scsi_end_request(cmd, 0, this_count, 1);
964 this_count, 1);
965 return; 950 return;
966 } else { 951 } else {
967 /* 952 /* Must have been a power glitch, or a
968 * Must have been a power glitch, or a 953 * bus reset. Could not have been a
969 * bus reset. Could not have been a 954 * media change, so we just retry the
970 * media change, so we just retry the 955 * request and see what happens.
971 * request and see what happens. 956 */
972 */
973 scsi_requeue_command(q, cmd); 957 scsi_requeue_command(q, cmd);
974 return; 958 return;
975 } 959 }
976 break; 960 break;
977 case ILLEGAL_REQUEST: 961 case ILLEGAL_REQUEST:
978 /* 962 /* If we had an ILLEGAL REQUEST returned, then
979 * If we had an ILLEGAL REQUEST returned, then we may 963 * we may have performed an unsupported
980 * have performed an unsupported command. The only 964 * command. The only thing this should be
981 * thing this should be would be a ten byte read where 965 * would be a ten byte read where only a six
982 * only a six byte read was supported. Also, on a 966 * byte read was supported. Also, on a system
983 * system where READ CAPACITY failed, we may have read 967 * where READ CAPACITY failed, we may have
984 * past the end of the disk. 968 * read past the end of the disk.
985 */ 969 */
986 if ((cmd->device->use_10_for_rw && 970 if ((cmd->device->use_10_for_rw &&
987 sshdr.asc == 0x20 && sshdr.ascq == 0x00) && 971 sshdr.asc == 0x20 && sshdr.ascq == 0x00) &&
988 (cmd->cmnd[0] == READ_10 || 972 (cmd->cmnd[0] == READ_10 ||
989 cmd->cmnd[0] == WRITE_10)) { 973 cmd->cmnd[0] == WRITE_10)) {
990 cmd->device->use_10_for_rw = 0; 974 cmd->device->use_10_for_rw = 0;
991 /* 975 /* This will cause a retry with a
992 * This will cause a retry with a 6-byte 976 * 6-byte command.
993 * command.
994 */ 977 */
995 scsi_requeue_command(q, cmd); 978 scsi_requeue_command(q, cmd);
996 result = 0; 979 return;
997 } else { 980 } else {
998 scsi_end_request(cmd, 0, this_count, 1); 981 scsi_end_request(cmd, 0, this_count, 1);
999 return; 982 return;
1000 } 983 }
1001 break; 984 break;
1002 case NOT_READY: 985 case NOT_READY:
1003 /* 986 /* If the device is in the process of becoming
1004 * If the device is in the process of becoming
1005 * ready, or has a temporary blockage, retry. 987 * ready, or has a temporary blockage, retry.
1006 */ 988 */
1007 if (sshdr.asc == 0x04) { 989 if (sshdr.asc == 0x04) {
@@ -1021,7 +1003,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
1021 } 1003 }
1022 if (!(req->flags & REQ_QUIET)) { 1004 if (!(req->flags & REQ_QUIET)) {
1023 scmd_printk(KERN_INFO, cmd, 1005 scmd_printk(KERN_INFO, cmd,
1024 "Device not ready: "); 1006 "Device not ready: ");
1025 scsi_print_sense_hdr("", &sshdr); 1007 scsi_print_sense_hdr("", &sshdr);
1026 } 1008 }
1027 scsi_end_request(cmd, 0, this_count, 1); 1009 scsi_end_request(cmd, 0, this_count, 1);
@@ -1029,21 +1011,21 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
1029 case VOLUME_OVERFLOW: 1011 case VOLUME_OVERFLOW:
1030 if (!(req->flags & REQ_QUIET)) { 1012 if (!(req->flags & REQ_QUIET)) {
1031 scmd_printk(KERN_INFO, cmd, 1013 scmd_printk(KERN_INFO, cmd,
1032 "Volume overflow, CDB: "); 1014 "Volume overflow, CDB: ");
1033 __scsi_print_command(cmd->data_cmnd); 1015 __scsi_print_command(cmd->data_cmnd);
1034 scsi_print_sense("", cmd); 1016 scsi_print_sense("", cmd);
1035 } 1017 }
1036 scsi_end_request(cmd, 0, block_bytes, 1); 1018 /* See SSC3rXX or current. */
1019 scsi_end_request(cmd, 0, this_count, 1);
1037 return; 1020 return;
1038 default: 1021 default:
1039 break; 1022 break;
1040 } 1023 }
1041 } /* driver byte != 0 */ 1024 }
1042 if (host_byte(result) == DID_RESET) { 1025 if (host_byte(result) == DID_RESET) {
1043 /* 1026 /* Third party bus reset or reset for error recovery
1044 * Third party bus reset or reset for error 1027 * reasons. Just retry the request and see what
1045 * recovery reasons. Just retry the request 1028 * happens.
1046 * and see what happens.
1047 */ 1029 */
1048 scsi_requeue_command(q, cmd); 1030 scsi_requeue_command(q, cmd);
1049 return; 1031 return;
@@ -1051,21 +1033,13 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
1051 if (result) { 1033 if (result) {
1052 if (!(req->flags & REQ_QUIET)) { 1034 if (!(req->flags & REQ_QUIET)) {
1053 scmd_printk(KERN_INFO, cmd, 1035 scmd_printk(KERN_INFO, cmd,
1054 "SCSI error: return code = 0x%x\n", result); 1036 "SCSI error: return code = 0x%08x\n",
1055 1037 result);
1056 if (driver_byte(result) & DRIVER_SENSE) 1038 if (driver_byte(result) & DRIVER_SENSE)
1057 scsi_print_sense("", cmd); 1039 scsi_print_sense("", cmd);
1058 } 1040 }
1059 /*
1060 * Mark a single buffer as not uptodate. Queue the remainder.
1061 * We sometimes get this cruft in the event that a medium error
1062 * isn't properly reported.
1063 */
1064 block_bytes = req->hard_cur_sectors << 9;
1065 if (!block_bytes)
1066 block_bytes = req->data_len;
1067 scsi_end_request(cmd, 0, block_bytes, 1);
1068 } 1041 }
1042 scsi_end_request(cmd, 0, this_count, !result);
1069} 1043}
1070EXPORT_SYMBOL(scsi_io_completion); 1044EXPORT_SYMBOL(scsi_io_completion);
1071 1045
@@ -1169,7 +1143,7 @@ static void scsi_blk_pc_done(struct scsi_cmnd *cmd)
1169 * successfully. Since this is a REQ_BLOCK_PC command the 1143 * successfully. Since this is a REQ_BLOCK_PC command the
1170 * caller should check the request's errors value 1144 * caller should check the request's errors value
1171 */ 1145 */
1172 scsi_io_completion(cmd, cmd->bufflen, 0); 1146 scsi_io_completion(cmd, cmd->bufflen);
1173} 1147}
1174 1148
1175static void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd) 1149static void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd)
@@ -2050,6 +2024,7 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)
2050 switch (oldstate) { 2024 switch (oldstate) {
2051 case SDEV_CREATED: 2025 case SDEV_CREATED:
2052 case SDEV_RUNNING: 2026 case SDEV_RUNNING:
2027 case SDEV_QUIESCE:
2053 case SDEV_OFFLINE: 2028 case SDEV_OFFLINE:
2054 case SDEV_BLOCK: 2029 case SDEV_BLOCK:
2055 break; 2030 break;
@@ -2060,6 +2035,9 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)
2060 2035
2061 case SDEV_DEL: 2036 case SDEV_DEL:
2062 switch (oldstate) { 2037 switch (oldstate) {
2038 case SDEV_CREATED:
2039 case SDEV_RUNNING:
2040 case SDEV_OFFLINE:
2063 case SDEV_CANCEL: 2041 case SDEV_CANCEL:
2064 break; 2042 break;
2065 default: 2043 default: