aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/scsi.c')
-rw-r--r--drivers/scsi/scsi.c92
1 files changed, 17 insertions, 75 deletions
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 762a8797e0be..2ac3cb2b9081 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -291,7 +291,6 @@ struct scsi_cmnd *scsi_get_command(struct scsi_device *dev, gfp_t gfp_mask)
291 unsigned long flags; 291 unsigned long flags;
292 292
293 cmd->device = dev; 293 cmd->device = dev;
294 init_timer(&cmd->eh_timeout);
295 INIT_LIST_HEAD(&cmd->list); 294 INIT_LIST_HEAD(&cmd->list);
296 spin_lock_irqsave(&dev->list_lock, flags); 295 spin_lock_irqsave(&dev->list_lock, flags);
297 list_add_tail(&cmd->list, &dev->cmd_list); 296 list_add_tail(&cmd->list, &dev->cmd_list);
@@ -652,14 +651,19 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
652 unsigned long timeout; 651 unsigned long timeout;
653 int rtn = 0; 652 int rtn = 0;
654 653
654 /*
655 * We will use a queued command if possible, otherwise we will
656 * emulate the queuing and calling of completion function ourselves.
657 */
658 atomic_inc(&cmd->device->iorequest_cnt);
659
655 /* check if the device is still usable */ 660 /* check if the device is still usable */
656 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) { 661 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
657 /* in SDEV_DEL we error all commands. DID_NO_CONNECT 662 /* in SDEV_DEL we error all commands. DID_NO_CONNECT
658 * returns an immediate error upwards, and signals 663 * returns an immediate error upwards, and signals
659 * that the device is no longer present */ 664 * that the device is no longer present */
660 cmd->result = DID_NO_CONNECT << 16; 665 cmd->result = DID_NO_CONNECT << 16;
661 atomic_inc(&cmd->device->iorequest_cnt); 666 scsi_done(cmd);
662 __scsi_done(cmd);
663 /* return 0 (because the command has been processed) */ 667 /* return 0 (because the command has been processed) */
664 goto out; 668 goto out;
665 } 669 }
@@ -673,6 +677,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
673 * occur until the device transitions out of the 677 * occur until the device transitions out of the
674 * suspend state. 678 * suspend state.
675 */ 679 */
680
676 scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY); 681 scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY);
677 682
678 SCSI_LOG_MLQUEUE(3, printk("queuecommand : device blocked \n")); 683 SCSI_LOG_MLQUEUE(3, printk("queuecommand : device blocked \n"));
@@ -715,21 +720,9 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
715 host->resetting = 0; 720 host->resetting = 0;
716 } 721 }
717 722
718 /*
719 * AK: unlikely race here: for some reason the timer could
720 * expire before the serial number is set up below.
721 */
722 scsi_add_timer(cmd, cmd->timeout_per_command, scsi_times_out);
723
724 scsi_log_send(cmd); 723 scsi_log_send(cmd);
725 724
726 /* 725 /*
727 * We will use a queued command if possible, otherwise we will
728 * emulate the queuing and calling of completion function ourselves.
729 */
730 atomic_inc(&cmd->device->iorequest_cnt);
731
732 /*
733 * Before we queue this command, check if the command 726 * Before we queue this command, check if the command
734 * length exceeds what the host adapter can handle. 727 * length exceeds what the host adapter can handle.
735 */ 728 */
@@ -745,6 +738,12 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
745 } 738 }
746 739
747 spin_lock_irqsave(host->host_lock, flags); 740 spin_lock_irqsave(host->host_lock, flags);
741 /*
742 * AK: unlikely race here: for some reason the timer could
743 * expire before the serial number is set up below.
744 *
745 * TODO: kill serial or move to blk layer
746 */
748 scsi_cmd_get_serial(host, cmd); 747 scsi_cmd_get_serial(host, cmd);
749 748
750 if (unlikely(host->shost_state == SHOST_DEL)) { 749 if (unlikely(host->shost_state == SHOST_DEL)) {
@@ -755,12 +754,8 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
755 } 754 }
756 spin_unlock_irqrestore(host->host_lock, flags); 755 spin_unlock_irqrestore(host->host_lock, flags);
757 if (rtn) { 756 if (rtn) {
758 if (scsi_delete_timer(cmd)) { 757 scsi_queue_insert(cmd, (rtn == SCSI_MLQUEUE_DEVICE_BUSY) ?
759 atomic_inc(&cmd->device->iodone_cnt); 758 rtn : SCSI_MLQUEUE_HOST_BUSY);
760 scsi_queue_insert(cmd,
761 (rtn == SCSI_MLQUEUE_DEVICE_BUSY) ?
762 rtn : SCSI_MLQUEUE_HOST_BUSY);
763 }
764 SCSI_LOG_MLQUEUE(3, 759 SCSI_LOG_MLQUEUE(3,
765 printk("queuecommand : request rejected\n")); 760 printk("queuecommand : request rejected\n"));
766 } 761 }
@@ -771,24 +766,6 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
771} 766}
772 767
773/** 768/**
774 * scsi_req_abort_cmd -- Request command recovery for the specified command
775 * @cmd: pointer to the SCSI command of interest
776 *
777 * This function requests that SCSI Core start recovery for the
778 * command by deleting the timer and adding the command to the eh
779 * queue. It can be called by either LLDDs or SCSI Core. LLDDs who
780 * implement their own error recovery MAY ignore the timeout event if
781 * they generated scsi_req_abort_cmd.
782 */
783void scsi_req_abort_cmd(struct scsi_cmnd *cmd)
784{
785 if (!scsi_delete_timer(cmd))
786 return;
787 scsi_times_out(cmd);
788}
789EXPORT_SYMBOL(scsi_req_abort_cmd);
790
791/**
792 * scsi_done - Enqueue the finished SCSI command into the done queue. 769 * scsi_done - Enqueue the finished SCSI command into the done queue.
793 * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives 770 * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives
794 * ownership back to SCSI Core -- i.e. the LLDD has finished with it. 771 * ownership back to SCSI Core -- i.e. the LLDD has finished with it.
@@ -803,42 +780,7 @@ EXPORT_SYMBOL(scsi_req_abort_cmd);
803 */ 780 */
804static void scsi_done(struct scsi_cmnd *cmd) 781static void scsi_done(struct scsi_cmnd *cmd)
805{ 782{
806 /* 783 blk_complete_request(cmd->request);
807 * We don't have to worry about this one timing out anymore.
808 * If we are unable to remove the timer, then the command
809 * has already timed out. In which case, we have no choice but to
810 * let the timeout function run, as we have no idea where in fact
811 * that function could really be. It might be on another processor,
812 * etc, etc.
813 */
814 if (!scsi_delete_timer(cmd))
815 return;
816 __scsi_done(cmd);
817}
818
819/* Private entry to scsi_done() to complete a command when the timer
820 * isn't running --- used by scsi_times_out */
821void __scsi_done(struct scsi_cmnd *cmd)
822{
823 struct request *rq = cmd->request;
824
825 /*
826 * Set the serial numbers back to zero
827 */
828 cmd->serial_number = 0;
829
830 atomic_inc(&cmd->device->iodone_cnt);
831 if (cmd->result)
832 atomic_inc(&cmd->device->ioerr_cnt);
833
834 BUG_ON(!rq);
835
836 /*
837 * The uptodate/nbytes values don't matter, as we allow partial
838 * completes and thus will check this in the softirq callback
839 */
840 rq->completion_data = cmd;
841 blk_complete_request(rq);
842} 784}
843 785
844/* Move this to a header if it becomes more generally useful */ 786/* Move this to a header if it becomes more generally useful */