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/sd.c | |
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/sd.c')
-rw-r--r-- | drivers/scsi/sd.c | 143 |
1 files changed, 62 insertions, 81 deletions
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, |