aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi_lib.c
diff options
context:
space:
mode:
authorLuben Tuikov <ltuikov@yahoo.com>2006-06-23 12:39:09 -0400
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2006-06-26 11:00:20 -0400
commit03aba2f79594ca94d159c8bab454de9bcc385b76 (patch)
tree5fcd23bfd01c80d356e7cab2f20854513db6b0f7 /drivers/scsi/scsi_lib.c
parentf89d0a4e1d01168f20f9e8273de7dfc094b2a430 (diff)
[SCSI] sd/scsi_lib simplify sd_rw_intr and scsi_io_completion
This patch simplifies "good_bytes" computation in sd_rw_intr(). sd: "good_bytes" computation is always done in terms of the resolution of the device's medium, since after that it is the number of good bytes we pass around and other layers/contexts (as opposed ot sd) can translate that to their own resolution (block layer:512). It also makes scsi_io_completion() processing more straightforward, eliminating the 3rd argument to the function. It also fixes a couple of bugs like not checking return value, using "break" instead of "return;", etc. I've been running with this patch for some time now on a test (do-it-all) system. Signed-off-by: Luben Tuikov <ltuikov@yahoo.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/scsi_lib.c')
-rw-r--r--drivers/scsi/scsi_lib.c108
1 files changed, 42 insertions, 66 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 3d04a9f386ac..4c4add53d69b 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,72 @@ 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 if (good_bytes > 0) {
925 SCSI_LOG_HLCOMPLETE(1, printk("%ld sectors total, %d bytes done.\n", 924 SCSI_LOG_HLCOMPLETE(1, printk("%ld sectors total, "
925 "%d bytes done.\n",
926 req->nr_sectors, good_bytes)); 926 req->nr_sectors, good_bytes));
927 SCSI_LOG_HLCOMPLETE(1, printk("use_sg is %d\n", cmd->use_sg)); 927 SCSI_LOG_HLCOMPLETE(1, printk("use_sg is %d\n", cmd->use_sg));
928 928
929 if (clear_errors) 929 if (clear_errors)
930 req->errors = 0; 930 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 931
943 /* 932 /* A number of bytes were successfully read. If there
944 * If the command completed without error, then either 933 * is leftovers and there is some kind of error
945 * finish off the rest of the command, or start a new one. 934 * (result != 0), retry the rest.
946 */ 935 */
947 if (scsi_end_request(cmd, 1, good_bytes, result == 0) == NULL) 936 if (scsi_end_request(cmd, 1, good_bytes, !!result) == NULL)
948 return; 937 return;
949 } 938 }
950 /* 939
951 * Now, if we were good little boys and girls, Santa left us a request 940 /* good_bytes = 0, or (inclusive) there were leftovers and
952 * sense buffer. We can extract information from this, so we 941 * result = 0, so scsi_end_request couldn't retry.
953 * can choose a block to remap, etc.
954 */ 942 */
955 if (sense_valid && !sense_deferred) { 943 if (sense_valid && !sense_deferred) {
956 switch (sshdr.sense_key) { 944 switch (sshdr.sense_key) {
957 case UNIT_ATTENTION: 945 case UNIT_ATTENTION:
958 if (cmd->device->removable) { 946 if (cmd->device->removable) {
959 /* detected disc change. set a bit 947 /* Detected disc change. Set a bit
960 * and quietly refuse further access. 948 * and quietly refuse further access.
961 */ 949 */
962 cmd->device->changed = 1; 950 cmd->device->changed = 1;
963 scsi_end_request(cmd, 0, 951 scsi_end_request(cmd, 0, this_count, 1);
964 this_count, 1);
965 return; 952 return;
966 } else { 953 } else {
967 /* 954 /* Must have been a power glitch, or a
968 * Must have been a power glitch, or a 955 * bus reset. Could not have been a
969 * bus reset. Could not have been a 956 * media change, so we just retry the
970 * media change, so we just retry the 957 * request and see what happens.
971 * request and see what happens. 958 */
972 */
973 scsi_requeue_command(q, cmd); 959 scsi_requeue_command(q, cmd);
974 return; 960 return;
975 } 961 }
976 break; 962 break;
977 case ILLEGAL_REQUEST: 963 case ILLEGAL_REQUEST:
978 /* 964 /* If we had an ILLEGAL REQUEST returned, then
979 * If we had an ILLEGAL REQUEST returned, then we may 965 * we may have performed an unsupported
980 * have performed an unsupported command. The only 966 * command. The only thing this should be
981 * thing this should be would be a ten byte read where 967 * would be a ten byte read where only a six
982 * only a six byte read was supported. Also, on a 968 * byte read was supported. Also, on a system
983 * system where READ CAPACITY failed, we may have read 969 * where READ CAPACITY failed, we may have
984 * past the end of the disk. 970 * read past the end of the disk.
985 */ 971 */
986 if ((cmd->device->use_10_for_rw && 972 if ((cmd->device->use_10_for_rw &&
987 sshdr.asc == 0x20 && sshdr.ascq == 0x00) && 973 sshdr.asc == 0x20 && sshdr.ascq == 0x00) &&
988 (cmd->cmnd[0] == READ_10 || 974 (cmd->cmnd[0] == READ_10 ||
989 cmd->cmnd[0] == WRITE_10)) { 975 cmd->cmnd[0] == WRITE_10)) {
990 cmd->device->use_10_for_rw = 0; 976 cmd->device->use_10_for_rw = 0;
991 /* 977 /* This will cause a retry with a
992 * This will cause a retry with a 6-byte 978 * 6-byte command.
993 * command.
994 */ 979 */
995 scsi_requeue_command(q, cmd); 980 scsi_requeue_command(q, cmd);
996 result = 0; 981 return;
997 } else { 982 } else {
998 scsi_end_request(cmd, 0, this_count, 1); 983 scsi_end_request(cmd, 0, this_count, 1);
999 return; 984 return;
1000 } 985 }
1001 break; 986 break;
1002 case NOT_READY: 987 case NOT_READY:
1003 /* 988 /* 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. 989 * ready, or has a temporary blockage, retry.
1006 */ 990 */
1007 if (sshdr.asc == 0x04) { 991 if (sshdr.asc == 0x04) {
@@ -1021,7 +1005,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
1021 } 1005 }
1022 if (!(req->flags & REQ_QUIET)) { 1006 if (!(req->flags & REQ_QUIET)) {
1023 scmd_printk(KERN_INFO, cmd, 1007 scmd_printk(KERN_INFO, cmd,
1024 "Device not ready: "); 1008 "Device not ready: ");
1025 scsi_print_sense_hdr("", &sshdr); 1009 scsi_print_sense_hdr("", &sshdr);
1026 } 1010 }
1027 scsi_end_request(cmd, 0, this_count, 1); 1011 scsi_end_request(cmd, 0, this_count, 1);
@@ -1029,21 +1013,21 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
1029 case VOLUME_OVERFLOW: 1013 case VOLUME_OVERFLOW:
1030 if (!(req->flags & REQ_QUIET)) { 1014 if (!(req->flags & REQ_QUIET)) {
1031 scmd_printk(KERN_INFO, cmd, 1015 scmd_printk(KERN_INFO, cmd,
1032 "Volume overflow, CDB: "); 1016 "Volume overflow, CDB: ");
1033 __scsi_print_command(cmd->data_cmnd); 1017 __scsi_print_command(cmd->data_cmnd);
1034 scsi_print_sense("", cmd); 1018 scsi_print_sense("", cmd);
1035 } 1019 }
1036 scsi_end_request(cmd, 0, block_bytes, 1); 1020 /* See SSC3rXX or current. */
1021 scsi_end_request(cmd, 0, this_count, 1);
1037 return; 1022 return;
1038 default: 1023 default:
1039 break; 1024 break;
1040 } 1025 }
1041 } /* driver byte != 0 */ 1026 }
1042 if (host_byte(result) == DID_RESET) { 1027 if (host_byte(result) == DID_RESET) {
1043 /* 1028 /* Third party bus reset or reset for error recovery
1044 * Third party bus reset or reset for error 1029 * reasons. Just retry the request and see what
1045 * recovery reasons. Just retry the request 1030 * happens.
1046 * and see what happens.
1047 */ 1031 */
1048 scsi_requeue_command(q, cmd); 1032 scsi_requeue_command(q, cmd);
1049 return; 1033 return;
@@ -1051,21 +1035,13 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
1051 if (result) { 1035 if (result) {
1052 if (!(req->flags & REQ_QUIET)) { 1036 if (!(req->flags & REQ_QUIET)) {
1053 scmd_printk(KERN_INFO, cmd, 1037 scmd_printk(KERN_INFO, cmd,
1054 "SCSI error: return code = 0x%x\n", result); 1038 "SCSI error: return code = 0x%08x\n",
1055 1039 result);
1056 if (driver_byte(result) & DRIVER_SENSE) 1040 if (driver_byte(result) & DRIVER_SENSE)
1057 scsi_print_sense("", cmd); 1041 scsi_print_sense("", cmd);
1058 } 1042 }
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 } 1043 }
1044 scsi_end_request(cmd, 0, this_count, !result);
1069} 1045}
1070EXPORT_SYMBOL(scsi_io_completion); 1046EXPORT_SYMBOL(scsi_io_completion);
1071 1047
@@ -1169,7 +1145,7 @@ static void scsi_blk_pc_done(struct scsi_cmnd *cmd)
1169 * successfully. Since this is a REQ_BLOCK_PC command the 1145 * successfully. Since this is a REQ_BLOCK_PC command the
1170 * caller should check the request's errors value 1146 * caller should check the request's errors value
1171 */ 1147 */
1172 scsi_io_completion(cmd, cmd->bufflen, 0); 1148 scsi_io_completion(cmd, cmd->bufflen);
1173} 1149}
1174 1150
1175static void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd) 1151static void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd)