diff options
Diffstat (limited to 'drivers/scsi/scsi_lib.c')
-rw-r--r-- | drivers/scsi/scsi_lib.c | 220 |
1 files changed, 65 insertions, 155 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 3d04a9f386a..d6743b959a7 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c | |||
@@ -436,60 +436,16 @@ EXPORT_SYMBOL_GPL(scsi_execute_async); | |||
436 | * | 436 | * |
437 | * Arguments: cmd - command that is ready to be queued. | 437 | * Arguments: cmd - command that is ready to be queued. |
438 | * | 438 | * |
439 | * Returns: Nothing | ||
440 | * | ||
441 | * Notes: This function has the job of initializing a number of | 439 | * Notes: This function has the job of initializing a number of |
442 | * fields related to error handling. Typically this will | 440 | * fields related to error handling. Typically this will |
443 | * be called once for each command, as required. | 441 | * be called once for each command, as required. |
444 | */ | 442 | */ |
445 | static int scsi_init_cmd_errh(struct scsi_cmnd *cmd) | 443 | static void scsi_init_cmd_errh(struct scsi_cmnd *cmd) |
446 | { | 444 | { |
447 | cmd->serial_number = 0; | 445 | cmd->serial_number = 0; |
448 | |||
449 | memset(cmd->sense_buffer, 0, sizeof cmd->sense_buffer); | 446 | memset(cmd->sense_buffer, 0, sizeof cmd->sense_buffer); |
450 | |||
451 | if (cmd->cmd_len == 0) | 447 | if (cmd->cmd_len == 0) |
452 | cmd->cmd_len = COMMAND_SIZE(cmd->cmnd[0]); | 448 | cmd->cmd_len = COMMAND_SIZE(cmd->cmnd[0]); |
453 | |||
454 | /* | ||
455 | * We need saved copies of a number of fields - this is because | ||
456 | * error handling may need to overwrite these with different values | ||
457 | * to run different commands, and once error handling is complete, | ||
458 | * we will need to restore these values prior to running the actual | ||
459 | * command. | ||
460 | */ | ||
461 | cmd->old_use_sg = cmd->use_sg; | ||
462 | cmd->old_cmd_len = cmd->cmd_len; | ||
463 | cmd->sc_old_data_direction = cmd->sc_data_direction; | ||
464 | cmd->old_underflow = cmd->underflow; | ||
465 | memcpy(cmd->data_cmnd, cmd->cmnd, sizeof(cmd->cmnd)); | ||
466 | cmd->buffer = cmd->request_buffer; | ||
467 | cmd->bufflen = cmd->request_bufflen; | ||
468 | |||
469 | return 1; | ||
470 | } | ||
471 | |||
472 | /* | ||
473 | * Function: scsi_setup_cmd_retry() | ||
474 | * | ||
475 | * Purpose: Restore the command state for a retry | ||
476 | * | ||
477 | * Arguments: cmd - command to be restored | ||
478 | * | ||
479 | * Returns: Nothing | ||
480 | * | ||
481 | * Notes: Immediately prior to retrying a command, we need | ||
482 | * to restore certain fields that we saved above. | ||
483 | */ | ||
484 | void scsi_setup_cmd_retry(struct scsi_cmnd *cmd) | ||
485 | { | ||
486 | memcpy(cmd->cmnd, cmd->data_cmnd, sizeof(cmd->data_cmnd)); | ||
487 | cmd->request_buffer = cmd->buffer; | ||
488 | cmd->request_bufflen = cmd->bufflen; | ||
489 | cmd->use_sg = cmd->old_use_sg; | ||
490 | cmd->cmd_len = cmd->old_cmd_len; | ||
491 | cmd->sc_data_direction = cmd->sc_old_data_direction; | ||
492 | cmd->underflow = cmd->old_underflow; | ||
493 | } | 449 | } |
494 | 450 | ||
495 | void scsi_device_unbusy(struct scsi_device *sdev) | 451 | void scsi_device_unbusy(struct scsi_device *sdev) |
@@ -595,7 +551,15 @@ static void scsi_run_queue(struct request_queue *q) | |||
595 | list_del_init(&sdev->starved_entry); | 551 | list_del_init(&sdev->starved_entry); |
596 | spin_unlock_irqrestore(shost->host_lock, flags); | 552 | spin_unlock_irqrestore(shost->host_lock, flags); |
597 | 553 | ||
598 | blk_run_queue(sdev->request_queue); | 554 | |
555 | if (test_bit(QUEUE_FLAG_REENTER, &q->queue_flags) && | ||
556 | !test_and_set_bit(QUEUE_FLAG_REENTER, | ||
557 | &sdev->request_queue->queue_flags)) { | ||
558 | blk_run_queue(sdev->request_queue); | ||
559 | clear_bit(QUEUE_FLAG_REENTER, | ||
560 | &sdev->request_queue->queue_flags); | ||
561 | } else | ||
562 | blk_run_queue(sdev->request_queue); | ||
599 | 563 | ||
600 | spin_lock_irqsave(shost->host_lock, flags); | 564 | spin_lock_irqsave(shost->host_lock, flags); |
601 | if (unlikely(!list_empty(&sdev->starved_entry))) | 565 | if (unlikely(!list_empty(&sdev->starved_entry))) |
@@ -807,22 +771,13 @@ static void scsi_free_sgtable(struct scatterlist *sgl, int index) | |||
807 | */ | 771 | */ |
808 | static void scsi_release_buffers(struct scsi_cmnd *cmd) | 772 | static void scsi_release_buffers(struct scsi_cmnd *cmd) |
809 | { | 773 | { |
810 | struct request *req = cmd->request; | ||
811 | |||
812 | /* | ||
813 | * Free up any indirection buffers we allocated for DMA purposes. | ||
814 | */ | ||
815 | if (cmd->use_sg) | 774 | if (cmd->use_sg) |
816 | scsi_free_sgtable(cmd->request_buffer, cmd->sglist_len); | 775 | scsi_free_sgtable(cmd->request_buffer, cmd->sglist_len); |
817 | else if (cmd->request_buffer != req->buffer) | ||
818 | kfree(cmd->request_buffer); | ||
819 | 776 | ||
820 | /* | 777 | /* |
821 | * Zero these out. They now point to freed memory, and it is | 778 | * Zero these out. They now point to freed memory, and it is |
822 | * dangerous to hang onto the pointers. | 779 | * dangerous to hang onto the pointers. |
823 | */ | 780 | */ |
824 | cmd->buffer = NULL; | ||
825 | cmd->bufflen = 0; | ||
826 | cmd->request_buffer = NULL; | 781 | cmd->request_buffer = NULL; |
827 | cmd->request_bufflen = 0; | 782 | cmd->request_bufflen = 0; |
828 | } | 783 | } |
@@ -855,11 +810,10 @@ static void scsi_release_buffers(struct scsi_cmnd *cmd) | |||
855 | * b) We can just use scsi_requeue_command() here. This would | 810 | * b) We can just use scsi_requeue_command() here. This would |
856 | * be used if we just wanted to retry, for example. | 811 | * be used if we just wanted to retry, for example. |
857 | */ | 812 | */ |
858 | void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | 813 | void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) |
859 | unsigned int block_bytes) | ||
860 | { | 814 | { |
861 | int result = cmd->result; | 815 | int result = cmd->result; |
862 | int this_count = cmd->bufflen; | 816 | int this_count = cmd->request_bufflen; |
863 | request_queue_t *q = cmd->device->request_queue; | 817 | request_queue_t *q = cmd->device->request_queue; |
864 | struct request *req = cmd->request; | 818 | struct request *req = cmd->request; |
865 | int clear_errors = 1; | 819 | int clear_errors = 1; |
@@ -867,28 +821,14 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | |||
867 | int sense_valid = 0; | 821 | int sense_valid = 0; |
868 | int sense_deferred = 0; | 822 | int sense_deferred = 0; |
869 | 823 | ||
870 | /* | 824 | scsi_release_buffers(cmd); |
871 | * Free up any indirection buffers we allocated for DMA purposes. | ||
872 | * For the case of a READ, we need to copy the data out of the | ||
873 | * bounce buffer and into the real buffer. | ||
874 | */ | ||
875 | if (cmd->use_sg) | ||
876 | scsi_free_sgtable(cmd->buffer, cmd->sglist_len); | ||
877 | else if (cmd->buffer != req->buffer) { | ||
878 | if (rq_data_dir(req) == READ) { | ||
879 | unsigned long flags; | ||
880 | char *to = bio_kmap_irq(req->bio, &flags); | ||
881 | memcpy(to, cmd->buffer, cmd->bufflen); | ||
882 | bio_kunmap_irq(to, &flags); | ||
883 | } | ||
884 | kfree(cmd->buffer); | ||
885 | } | ||
886 | 825 | ||
887 | if (result) { | 826 | if (result) { |
888 | sense_valid = scsi_command_normalize_sense(cmd, &sshdr); | 827 | sense_valid = scsi_command_normalize_sense(cmd, &sshdr); |
889 | if (sense_valid) | 828 | if (sense_valid) |
890 | sense_deferred = scsi_sense_is_deferred(&sshdr); | 829 | sense_deferred = scsi_sense_is_deferred(&sshdr); |
891 | } | 830 | } |
831 | |||
892 | if (blk_pc_request(req)) { /* SG_IO ioctl from block level */ | 832 | if (blk_pc_request(req)) { /* SG_IO ioctl from block level */ |
893 | req->errors = result; | 833 | req->errors = result; |
894 | if (result) { | 834 | if (result) { |
@@ -909,99 +849,73 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | |||
909 | } | 849 | } |
910 | 850 | ||
911 | /* | 851 | /* |
912 | * Zero these out. They now point to freed memory, and it is | ||
913 | * dangerous to hang onto the pointers. | ||
914 | */ | ||
915 | cmd->buffer = NULL; | ||
916 | cmd->bufflen = 0; | ||
917 | cmd->request_buffer = NULL; | ||
918 | cmd->request_bufflen = 0; | ||
919 | |||
920 | /* | ||
921 | * Next deal with any sectors which we were able to correctly | 852 | * Next deal with any sectors which we were able to correctly |
922 | * handle. | 853 | * handle. |
923 | */ | 854 | */ |
924 | if (good_bytes >= 0) { | 855 | SCSI_LOG_HLCOMPLETE(1, printk("%ld sectors total, " |
925 | SCSI_LOG_HLCOMPLETE(1, printk("%ld sectors total, %d bytes done.\n", | 856 | "%d bytes done.\n", |
926 | req->nr_sectors, good_bytes)); | 857 | req->nr_sectors, good_bytes)); |
927 | SCSI_LOG_HLCOMPLETE(1, printk("use_sg is %d\n", cmd->use_sg)); | 858 | SCSI_LOG_HLCOMPLETE(1, printk("use_sg is %d\n", cmd->use_sg)); |
928 | 859 | ||
929 | if (clear_errors) | 860 | if (clear_errors) |
930 | req->errors = 0; | 861 | 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 | 862 | ||
943 | /* | 863 | /* A number of bytes were successfully read. If there |
944 | * If the command completed without error, then either | 864 | * are leftovers and there is some kind of error |
945 | * finish off the rest of the command, or start a new one. | 865 | * (result != 0), retry the rest. |
946 | */ | 866 | */ |
947 | if (scsi_end_request(cmd, 1, good_bytes, result == 0) == NULL) | 867 | if (scsi_end_request(cmd, 1, good_bytes, result == 0) == NULL) |
948 | return; | 868 | return; |
949 | } | 869 | |
950 | /* | 870 | /* good_bytes = 0, or (inclusive) there were leftovers and |
951 | * Now, if we were good little boys and girls, Santa left us a request | 871 | * 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 | */ | 872 | */ |
955 | if (sense_valid && !sense_deferred) { | 873 | if (sense_valid && !sense_deferred) { |
956 | switch (sshdr.sense_key) { | 874 | switch (sshdr.sense_key) { |
957 | case UNIT_ATTENTION: | 875 | case UNIT_ATTENTION: |
958 | if (cmd->device->removable) { | 876 | if (cmd->device->removable) { |
959 | /* detected disc change. set a bit | 877 | /* Detected disc change. Set a bit |
960 | * and quietly refuse further access. | 878 | * and quietly refuse further access. |
961 | */ | 879 | */ |
962 | cmd->device->changed = 1; | 880 | cmd->device->changed = 1; |
963 | scsi_end_request(cmd, 0, | 881 | scsi_end_request(cmd, 0, this_count, 1); |
964 | this_count, 1); | ||
965 | return; | 882 | return; |
966 | } else { | 883 | } else { |
967 | /* | 884 | /* Must have been a power glitch, or a |
968 | * Must have been a power glitch, or a | 885 | * bus reset. Could not have been a |
969 | * bus reset. Could not have been a | 886 | * media change, so we just retry the |
970 | * media change, so we just retry the | 887 | * request and see what happens. |
971 | * request and see what happens. | 888 | */ |
972 | */ | ||
973 | scsi_requeue_command(q, cmd); | 889 | scsi_requeue_command(q, cmd); |
974 | return; | 890 | return; |
975 | } | 891 | } |
976 | break; | 892 | break; |
977 | case ILLEGAL_REQUEST: | 893 | case ILLEGAL_REQUEST: |
978 | /* | 894 | /* If we had an ILLEGAL REQUEST returned, then |
979 | * If we had an ILLEGAL REQUEST returned, then we may | 895 | * we may have performed an unsupported |
980 | * have performed an unsupported command. The only | 896 | * command. The only thing this should be |
981 | * thing this should be would be a ten byte read where | 897 | * would be a ten byte read where only a six |
982 | * only a six byte read was supported. Also, on a | 898 | * byte read was supported. Also, on a system |
983 | * system where READ CAPACITY failed, we may have read | 899 | * where READ CAPACITY failed, we may have |
984 | * past the end of the disk. | 900 | * read past the end of the disk. |
985 | */ | 901 | */ |
986 | if ((cmd->device->use_10_for_rw && | 902 | if ((cmd->device->use_10_for_rw && |
987 | sshdr.asc == 0x20 && sshdr.ascq == 0x00) && | 903 | sshdr.asc == 0x20 && sshdr.ascq == 0x00) && |
988 | (cmd->cmnd[0] == READ_10 || | 904 | (cmd->cmnd[0] == READ_10 || |
989 | cmd->cmnd[0] == WRITE_10)) { | 905 | cmd->cmnd[0] == WRITE_10)) { |
990 | cmd->device->use_10_for_rw = 0; | 906 | cmd->device->use_10_for_rw = 0; |
991 | /* | 907 | /* This will cause a retry with a |
992 | * This will cause a retry with a 6-byte | 908 | * 6-byte command. |
993 | * command. | ||
994 | */ | 909 | */ |
995 | scsi_requeue_command(q, cmd); | 910 | scsi_requeue_command(q, cmd); |
996 | result = 0; | 911 | return; |
997 | } else { | 912 | } else { |
998 | scsi_end_request(cmd, 0, this_count, 1); | 913 | scsi_end_request(cmd, 0, this_count, 1); |
999 | return; | 914 | return; |
1000 | } | 915 | } |
1001 | break; | 916 | break; |
1002 | case NOT_READY: | 917 | case NOT_READY: |
1003 | /* | 918 | /* 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. | 919 | * ready, or has a temporary blockage, retry. |
1006 | */ | 920 | */ |
1007 | if (sshdr.asc == 0x04) { | 921 | if (sshdr.asc == 0x04) { |
@@ -1021,7 +935,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | |||
1021 | } | 935 | } |
1022 | if (!(req->flags & REQ_QUIET)) { | 936 | if (!(req->flags & REQ_QUIET)) { |
1023 | scmd_printk(KERN_INFO, cmd, | 937 | scmd_printk(KERN_INFO, cmd, |
1024 | "Device not ready: "); | 938 | "Device not ready: "); |
1025 | scsi_print_sense_hdr("", &sshdr); | 939 | scsi_print_sense_hdr("", &sshdr); |
1026 | } | 940 | } |
1027 | scsi_end_request(cmd, 0, this_count, 1); | 941 | scsi_end_request(cmd, 0, this_count, 1); |
@@ -1029,21 +943,21 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | |||
1029 | case VOLUME_OVERFLOW: | 943 | case VOLUME_OVERFLOW: |
1030 | if (!(req->flags & REQ_QUIET)) { | 944 | if (!(req->flags & REQ_QUIET)) { |
1031 | scmd_printk(KERN_INFO, cmd, | 945 | scmd_printk(KERN_INFO, cmd, |
1032 | "Volume overflow, CDB: "); | 946 | "Volume overflow, CDB: "); |
1033 | __scsi_print_command(cmd->data_cmnd); | 947 | __scsi_print_command(cmd->cmnd); |
1034 | scsi_print_sense("", cmd); | 948 | scsi_print_sense("", cmd); |
1035 | } | 949 | } |
1036 | scsi_end_request(cmd, 0, block_bytes, 1); | 950 | /* See SSC3rXX or current. */ |
951 | scsi_end_request(cmd, 0, this_count, 1); | ||
1037 | return; | 952 | return; |
1038 | default: | 953 | default: |
1039 | break; | 954 | break; |
1040 | } | 955 | } |
1041 | } /* driver byte != 0 */ | 956 | } |
1042 | if (host_byte(result) == DID_RESET) { | 957 | if (host_byte(result) == DID_RESET) { |
1043 | /* | 958 | /* Third party bus reset or reset for error recovery |
1044 | * Third party bus reset or reset for error | 959 | * reasons. Just retry the request and see what |
1045 | * recovery reasons. Just retry the request | 960 | * happens. |
1046 | * and see what happens. | ||
1047 | */ | 961 | */ |
1048 | scsi_requeue_command(q, cmd); | 962 | scsi_requeue_command(q, cmd); |
1049 | return; | 963 | return; |
@@ -1051,21 +965,13 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | |||
1051 | if (result) { | 965 | if (result) { |
1052 | if (!(req->flags & REQ_QUIET)) { | 966 | if (!(req->flags & REQ_QUIET)) { |
1053 | scmd_printk(KERN_INFO, cmd, | 967 | scmd_printk(KERN_INFO, cmd, |
1054 | "SCSI error: return code = 0x%x\n", result); | 968 | "SCSI error: return code = 0x%08x\n", |
1055 | 969 | result); | |
1056 | if (driver_byte(result) & DRIVER_SENSE) | 970 | if (driver_byte(result) & DRIVER_SENSE) |
1057 | scsi_print_sense("", cmd); | 971 | scsi_print_sense("", cmd); |
1058 | } | 972 | } |
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 | } | 973 | } |
974 | scsi_end_request(cmd, 0, this_count, !result); | ||
1069 | } | 975 | } |
1070 | EXPORT_SYMBOL(scsi_io_completion); | 976 | EXPORT_SYMBOL(scsi_io_completion); |
1071 | 977 | ||
@@ -1169,7 +1075,7 @@ static void scsi_blk_pc_done(struct scsi_cmnd *cmd) | |||
1169 | * successfully. Since this is a REQ_BLOCK_PC command the | 1075 | * successfully. Since this is a REQ_BLOCK_PC command the |
1170 | * caller should check the request's errors value | 1076 | * caller should check the request's errors value |
1171 | */ | 1077 | */ |
1172 | scsi_io_completion(cmd, cmd->bufflen, 0); | 1078 | scsi_io_completion(cmd, cmd->request_bufflen); |
1173 | } | 1079 | } |
1174 | 1080 | ||
1175 | static void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd) | 1081 | static void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd) |
@@ -2050,6 +1956,7 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state) | |||
2050 | switch (oldstate) { | 1956 | switch (oldstate) { |
2051 | case SDEV_CREATED: | 1957 | case SDEV_CREATED: |
2052 | case SDEV_RUNNING: | 1958 | case SDEV_RUNNING: |
1959 | case SDEV_QUIESCE: | ||
2053 | case SDEV_OFFLINE: | 1960 | case SDEV_OFFLINE: |
2054 | case SDEV_BLOCK: | 1961 | case SDEV_BLOCK: |
2055 | break; | 1962 | break; |
@@ -2060,6 +1967,9 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state) | |||
2060 | 1967 | ||
2061 | case SDEV_DEL: | 1968 | case SDEV_DEL: |
2062 | switch (oldstate) { | 1969 | switch (oldstate) { |
1970 | case SDEV_CREATED: | ||
1971 | case SDEV_RUNNING: | ||
1972 | case SDEV_OFFLINE: | ||
2063 | case SDEV_CANCEL: | 1973 | case SDEV_CANCEL: |
2064 | break; | 1974 | break; |
2065 | default: | 1975 | default: |