diff options
author | Luben Tuikov <ltuikov@yahoo.com> | 2006-06-23 12:39:09 -0400 |
---|---|---|
committer | James Bottomley <jejb@mulgrave.il.steeleye.com> | 2006-06-26 11:00:20 -0400 |
commit | 03aba2f79594ca94d159c8bab454de9bcc385b76 (patch) | |
tree | 5fcd23bfd01c80d356e7cab2f20854513db6b0f7 /drivers/scsi | |
parent | f89d0a4e1d01168f20f9e8273de7dfc094b2a430 (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')
-rw-r--r-- | drivers/scsi/scsi_lib.c | 108 | ||||
-rw-r--r-- | drivers/scsi/sd.c | 143 | ||||
-rw-r--r-- | drivers/scsi/sr.c | 2 |
3 files changed, 105 insertions, 148 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 | */ |
858 | void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | 858 | void 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 | } |
1070 | EXPORT_SYMBOL(scsi_io_completion); | 1046 | EXPORT_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 | ||
1175 | static void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd) | 1151 | static void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd) |
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 354199011246..f899ff0cf005 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c | |||
@@ -891,11 +891,10 @@ static struct block_device_operations sd_fops = { | |||
891 | static void sd_rw_intr(struct scsi_cmnd * SCpnt) | 891 | static void sd_rw_intr(struct scsi_cmnd * SCpnt) |
892 | { | 892 | { |
893 | int result = SCpnt->result; | 893 | int result = SCpnt->result; |
894 | int this_count = SCpnt->request_bufflen; | 894 | unsigned int xfer_size = SCpnt->request_bufflen; |
895 | int good_bytes = (result == 0 ? this_count : 0); | 895 | unsigned int good_bytes = result ? 0 : xfer_size; |
896 | sector_t block_sectors = 1; | 896 | u64 start_lba = SCpnt->request->sector; |
897 | u64 first_err_block; | 897 | u64 bad_lba; |
898 | sector_t error_sector; | ||
899 | struct scsi_sense_hdr sshdr; | 898 | struct scsi_sense_hdr sshdr; |
900 | int sense_valid = 0; | 899 | int sense_valid = 0; |
901 | int sense_deferred = 0; | 900 | int sense_deferred = 0; |
@@ -906,7 +905,6 @@ static void sd_rw_intr(struct scsi_cmnd * SCpnt) | |||
906 | if (sense_valid) | 905 | if (sense_valid) |
907 | sense_deferred = scsi_sense_is_deferred(&sshdr); | 906 | sense_deferred = scsi_sense_is_deferred(&sshdr); |
908 | } | 907 | } |
909 | |||
910 | #ifdef CONFIG_SCSI_LOGGING | 908 | #ifdef CONFIG_SCSI_LOGGING |
911 | SCSI_LOG_HLCOMPLETE(1, printk("sd_rw_intr: %s: res=0x%x\n", | 909 | SCSI_LOG_HLCOMPLETE(1, printk("sd_rw_intr: %s: res=0x%x\n", |
912 | SCpnt->request->rq_disk->disk_name, result)); | 910 | SCpnt->request->rq_disk->disk_name, result)); |
@@ -916,89 +914,72 @@ static void sd_rw_intr(struct scsi_cmnd * SCpnt) | |||
916 | sshdr.sense_key, sshdr.asc, sshdr.ascq)); | 914 | sshdr.sense_key, sshdr.asc, sshdr.ascq)); |
917 | } | 915 | } |
918 | #endif | 916 | #endif |
919 | /* | 917 | if (driver_byte(result) != DRIVER_SENSE && |
920 | Handle MEDIUM ERRORs that indicate partial success. Since this is a | 918 | (!sense_valid || sense_deferred)) |
921 | relatively rare error condition, no care is taken to avoid | 919 | goto out; |
922 | unnecessary additional work such as memcpy's that could be avoided. | ||
923 | */ | ||
924 | if (driver_byte(result) != 0 && | ||
925 | sense_valid && !sense_deferred) { | ||
926 | switch (sshdr.sense_key) { | ||
927 | case MEDIUM_ERROR: | ||
928 | if (!blk_fs_request(SCpnt->request)) | ||
929 | break; | ||
930 | info_valid = scsi_get_sense_info_fld( | ||
931 | SCpnt->sense_buffer, SCSI_SENSE_BUFFERSIZE, | ||
932 | &first_err_block); | ||
933 | /* | ||
934 | * May want to warn and skip if following cast results | ||
935 | * in actual truncation (if sector_t < 64 bits) | ||
936 | */ | ||
937 | error_sector = (sector_t)first_err_block; | ||
938 | if (SCpnt->request->bio != NULL) | ||
939 | block_sectors = bio_sectors(SCpnt->request->bio); | ||
940 | switch (SCpnt->device->sector_size) { | ||
941 | case 1024: | ||
942 | error_sector <<= 1; | ||
943 | if (block_sectors < 2) | ||
944 | block_sectors = 2; | ||
945 | break; | ||
946 | case 2048: | ||
947 | error_sector <<= 2; | ||
948 | if (block_sectors < 4) | ||
949 | block_sectors = 4; | ||
950 | break; | ||
951 | case 4096: | ||
952 | error_sector <<=3; | ||
953 | if (block_sectors < 8) | ||
954 | block_sectors = 8; | ||
955 | break; | ||
956 | case 256: | ||
957 | error_sector >>= 1; | ||
958 | break; | ||
959 | default: | ||
960 | break; | ||
961 | } | ||
962 | 920 | ||
963 | error_sector &= ~(block_sectors - 1); | 921 | switch (sshdr.sense_key) { |
964 | good_bytes = (error_sector - SCpnt->request->sector) << 9; | 922 | case HARDWARE_ERROR: |
965 | if (good_bytes < 0 || good_bytes >= this_count) | 923 | case MEDIUM_ERROR: |
966 | good_bytes = 0; | 924 | if (!blk_fs_request(SCpnt->request)) |
925 | goto out; | ||
926 | info_valid = scsi_get_sense_info_fld(SCpnt->sense_buffer, | ||
927 | SCSI_SENSE_BUFFERSIZE, | ||
928 | &bad_lba); | ||
929 | if (!info_valid) | ||
930 | goto out; | ||
931 | if (xfer_size <= SCpnt->device->sector_size) | ||
932 | goto out; | ||
933 | switch (SCpnt->device->sector_size) { | ||
934 | case 256: | ||
935 | start_lba <<= 1; | ||
967 | break; | 936 | break; |
968 | 937 | case 512: | |
969 | case RECOVERED_ERROR: /* an error occurred, but it recovered */ | ||
970 | case NO_SENSE: /* LLDD got sense data */ | ||
971 | /* | ||
972 | * Inform the user, but make sure that it's not treated | ||
973 | * as a hard error. | ||
974 | */ | ||
975 | scsi_print_sense("sd", SCpnt); | ||
976 | SCpnt->result = 0; | ||
977 | memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); | ||
978 | good_bytes = this_count; | ||
979 | break; | 938 | break; |
980 | 939 | case 1024: | |
981 | case ILLEGAL_REQUEST: | 940 | start_lba >>= 1; |
982 | if (SCpnt->device->use_10_for_rw && | 941 | break; |
983 | (SCpnt->cmnd[0] == READ_10 || | 942 | case 2048: |
984 | SCpnt->cmnd[0] == WRITE_10)) | 943 | start_lba >>= 2; |
985 | SCpnt->device->use_10_for_rw = 0; | 944 | break; |
986 | if (SCpnt->device->use_10_for_ms && | 945 | case 4096: |
987 | (SCpnt->cmnd[0] == MODE_SENSE_10 || | 946 | start_lba >>= 3; |
988 | SCpnt->cmnd[0] == MODE_SELECT_10)) | ||
989 | SCpnt->device->use_10_for_ms = 0; | ||
990 | break; | 947 | break; |
991 | |||
992 | default: | 948 | default: |
949 | /* Print something here with limiting frequency. */ | ||
950 | goto out; | ||
993 | break; | 951 | break; |
994 | } | 952 | } |
953 | /* This computation should always be done in terms of | ||
954 | * the resolution of the device's medium. | ||
955 | */ | ||
956 | good_bytes = (bad_lba - start_lba)*SCpnt->device->sector_size; | ||
957 | break; | ||
958 | case RECOVERED_ERROR: | ||
959 | case NO_SENSE: | ||
960 | /* Inform the user, but make sure that it's not treated | ||
961 | * as a hard error. | ||
962 | */ | ||
963 | scsi_print_sense("sd", SCpnt); | ||
964 | SCpnt->result = 0; | ||
965 | memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); | ||
966 | good_bytes = xfer_size; | ||
967 | break; | ||
968 | case ILLEGAL_REQUEST: | ||
969 | if (SCpnt->device->use_10_for_rw && | ||
970 | (SCpnt->cmnd[0] == READ_10 || | ||
971 | SCpnt->cmnd[0] == WRITE_10)) | ||
972 | SCpnt->device->use_10_for_rw = 0; | ||
973 | if (SCpnt->device->use_10_for_ms && | ||
974 | (SCpnt->cmnd[0] == MODE_SENSE_10 || | ||
975 | SCpnt->cmnd[0] == MODE_SELECT_10)) | ||
976 | SCpnt->device->use_10_for_ms = 0; | ||
977 | break; | ||
978 | default: | ||
979 | break; | ||
995 | } | 980 | } |
996 | /* | 981 | out: |
997 | * This calls the generic completion function, now that we know | 982 | scsi_io_completion(SCpnt, good_bytes); |
998 | * how many actual sectors finished, and how many sectors we need | ||
999 | * to say have failed. | ||
1000 | */ | ||
1001 | scsi_io_completion(SCpnt, good_bytes, block_sectors << 9); | ||
1002 | } | 983 | } |
1003 | 984 | ||
1004 | static int media_not_present(struct scsi_disk *sdkp, | 985 | static int media_not_present(struct scsi_disk *sdkp, |
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index ebf6579ed698..fd94408577e5 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c | |||
@@ -292,7 +292,7 @@ static void rw_intr(struct scsi_cmnd * SCpnt) | |||
292 | * how many actual sectors finished, and how many sectors we need | 292 | * how many actual sectors finished, and how many sectors we need |
293 | * to say have failed. | 293 | * to say have failed. |
294 | */ | 294 | */ |
295 | scsi_io_completion(SCpnt, good_bytes, block_sectors << 9); | 295 | scsi_io_completion(SCpnt, good_bytes); |
296 | } | 296 | } |
297 | 297 | ||
298 | static int sr_init_command(struct scsi_cmnd * SCpnt) | 298 | static int sr_init_command(struct scsi_cmnd * SCpnt) |