[SCSI] use scmd_id(), scmd_channel() throughout code
[deliverable/linux.git] / drivers / scsi / scsi_error.c
index ae28bcb79242d9d961fa4b520c15e7a6d4050c45..0c5b02d4c7f85dc963181baa0e3583fe52a1e262 100644 (file)
@@ -50,7 +50,7 @@
 void scsi_eh_wakeup(struct Scsi_Host *shost)
 {
        if (shost->host_busy == shost->host_failed) {
-               up(shost->eh_wait);
+               wake_up_process(shost->ehandler);
                SCSI_LOG_ERROR_RECOVERY(5,
                                printk("Waking error handler thread\n"));
        }
@@ -68,19 +68,24 @@ int scsi_eh_scmd_add(struct scsi_cmnd *scmd, int eh_flag)
 {
        struct Scsi_Host *shost = scmd->device->host;
        unsigned long flags;
+       int ret = 0;
 
-       if (shost->eh_wait == NULL)
+       if (!shost->ehandler)
                return 0;
 
        spin_lock_irqsave(shost->host_lock, flags);
+       if (scsi_host_set_state(shost, SHOST_RECOVERY))
+               if (scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY))
+                       goto out_unlock;
 
+       ret = 1;
        scmd->eh_eflags |= eh_flag;
        list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q);
-       scsi_host_set_state(shost, SHOST_RECOVERY);
        shost->host_failed++;
        scsi_eh_wakeup(shost);
+ out_unlock:
        spin_unlock_irqrestore(shost->host_lock, flags);
-       return 1;
+       return ret;
 }
 
 /**
@@ -176,8 +181,8 @@ void scsi_times_out(struct scsi_cmnd *scmd)
                }
 
        if (unlikely(!scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD))) {
-               panic("Error handler thread not present at %p %p %s %d",
-                     scmd, scmd->device->host, __FILE__, __LINE__);
+               scmd->result |= DID_TIME_OUT << 16;
+               __scsi_done(scmd);
        }
 }
 
@@ -196,8 +201,7 @@ int scsi_block_when_processing_errors(struct scsi_device *sdev)
 {
        int online;
 
-       wait_event(sdev->host->host_wait, (sdev->host->shost_state !=
-                                          SHOST_RECOVERY));
+       wait_event(sdev->host->host_wait, !scsi_host_in_recovery(sdev->host));
 
        online = scsi_device_online(sdev);
 
@@ -237,11 +241,10 @@ static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost,
 
                if (cmd_cancel || cmd_failed) {
                        SCSI_LOG_ERROR_RECOVERY(3,
-                               printk("%s: %d:%d:%d:%d cmds failed: %d,"
-                                      " cancel: %d\n",
-                                      __FUNCTION__, shost->host_no,
-                                      sdev->channel, sdev->id, sdev->lun,
-                                      cmd_failed, cmd_cancel));
+                               sdev_printk(KERN_INFO, sdev,
+                                           "%s: cmds failed: %d, cancel: %d\n",
+                                           __FUNCTION__, cmd_failed,
+                                           cmd_cancel));
                        cmd_cancel = 0;
                        cmd_failed = 0;
                        ++devices_failed;
@@ -670,10 +673,9 @@ static int scsi_eh_get_sense(struct list_head *work_q,
                    SCSI_SENSE_VALID(scmd))
                        continue;
 
-               SCSI_LOG_ERROR_RECOVERY(2, printk("%s: requesting sense"
-                                                 " for id: %d\n",
-                                                 current->comm,
-                                                 scmd->device->id));
+               SCSI_LOG_ERROR_RECOVERY(2, scmd_printk(KERN_INFO, scmd,
+                                                 "%s: requesting sense\n",
+                                                 current->comm));
                rtn = scsi_request_sense(scmd);
                if (rtn != SUCCESS)
                        continue;
@@ -1031,7 +1033,8 @@ static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
                if (!scmd->device->host->hostt->skip_settle_delay)
                        ssleep(BUS_RESET_SETTLE_TIME);
                spin_lock_irqsave(scmd->device->host->host_lock, flags);
-               scsi_report_bus_reset(scmd->device->host, scmd->device->channel);
+               scsi_report_bus_reset(scmd->device->host,
+                                     scmd_channel(scmd));
                spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
        }
 
@@ -1059,7 +1062,8 @@ static int scsi_try_host_reset(struct scsi_cmnd *scmd)
                if (!scmd->device->host->hostt->skip_settle_delay)
                        ssleep(HOST_RESET_SETTLE_TIME);
                spin_lock_irqsave(scmd->device->host->host_lock, flags);
-               scsi_report_bus_reset(scmd->device->host, scmd->device->channel);
+               scsi_report_bus_reset(scmd->device->host,
+                                     scmd_channel(scmd));
                spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
        }
 
@@ -1089,7 +1093,7 @@ static int scsi_eh_bus_reset(struct Scsi_Host *shost,
        for (channel = 0; channel <= shost->max_channel; channel++) {
                chan_scmd = NULL;
                list_for_each_entry(scmd, work_q, eh_entry) {
-                       if (channel == scmd->device->channel) {
+                       if (channel == scmd_channel(scmd)) {
                                chan_scmd = scmd;
                                break;
                                /*
@@ -1107,7 +1111,7 @@ static int scsi_eh_bus_reset(struct Scsi_Host *shost,
                rtn = scsi_try_bus_reset(chan_scmd);
                if (rtn == SUCCESS) {
                        list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
-                               if (channel == scmd->device->channel)
+                               if (channel == scmd_channel(scmd))
                                        if (!scsi_device_online(scmd->device) ||
                                            !scsi_eh_tur(scmd))
                                                scsi_eh_finish_cmd(scmd,
@@ -1170,13 +1174,9 @@ static void scsi_eh_offline_sdevs(struct list_head *work_q,
        struct scsi_cmnd *scmd, *next;
 
        list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
-               printk(KERN_INFO "scsi: Device offlined - not"
-                               " ready after error recovery: host"
-                               " %d channel %d id %d lun %d\n",
-                               scmd->device->host->host_no,
-                               scmd->device->channel,
-                               scmd->device->id,
-                               scmd->device->lun);
+               sdev_printk(KERN_INFO, scmd->device,
+                           "scsi: Device offlined - not"
+                           " ready after error recovery\n");
                scsi_device_set_state(scmd->device, SDEV_OFFLINE);
                if (scmd->eh_eflags & SCSI_EH_CANCEL_CMD) {
                        /*
@@ -1338,10 +1338,8 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
                return SUCCESS;
 
        case RESERVATION_CONFLICT:
-               printk(KERN_INFO "scsi: reservation conflict: host"
-                                " %d channel %d id %d lun %d\n",
-                      scmd->device->host->host_no, scmd->device->channel,
-                      scmd->device->id, scmd->device->lun);
+               sdev_printk(KERN_INFO, scmd->device,
+                           "reservation conflict\n");
                return SUCCESS; /* causes immediate i/o error */
        default:
                return FAILED;
@@ -1441,6 +1439,7 @@ static void scsi_eh_lock_door(struct scsi_device *sdev)
 static void scsi_restart_operations(struct Scsi_Host *shost)
 {
        struct scsi_device *sdev;
+       unsigned long flags;
 
        /*
         * If the door was locked, we need to insert a door lock request
@@ -1460,7 +1459,11 @@ static void scsi_restart_operations(struct Scsi_Host *shost)
        SCSI_LOG_ERROR_RECOVERY(3, printk("%s: waking up host to restart\n",
                                          __FUNCTION__));
 
-       scsi_host_set_state(shost, SHOST_RUNNING);
+       spin_lock_irqsave(shost->host_lock, flags);
+       if (scsi_host_set_state(shost, SHOST_RUNNING))
+               if (scsi_host_set_state(shost, SHOST_CANCEL))
+                       BUG_ON(scsi_host_set_state(shost, SHOST_DEL));
+       spin_unlock_irqrestore(shost->host_lock, flags);
 
        wake_up(&shost->host_wait);
 
@@ -1582,40 +1585,31 @@ int scsi_error_handler(void *data)
 {
        struct Scsi_Host *shost = (struct Scsi_Host *) data;
        int rtn;
-       DECLARE_MUTEX_LOCKED(sem);
 
        current->flags |= PF_NOFREEZE;
-       shost->eh_wait = &sem;
 
+       
        /*
-        * Wake up the thread that created us.
+        * Note - we always use TASK_INTERRUPTIBLE even if the module
+        * was loaded as part of the kernel.  The reason is that
+        * UNINTERRUPTIBLE would cause this thread to be counted in
+        * the load average as a running process, and an interruptible
+        * wait doesn't.
         */
-       SCSI_LOG_ERROR_RECOVERY(3, printk("Wake up parent of"
-                                         " scsi_eh_%d\n",shost->host_no));
-
-       while (1) {
-               /*
-                * If we get a signal, it means we are supposed to go
-                * away and die.  This typically happens if the user is
-                * trying to unload a module.
-                */
-               SCSI_LOG_ERROR_RECOVERY(1, printk("Error handler"
-                                                 " scsi_eh_%d"
-                                                 " sleeping\n",shost->host_no));
-
-               /*
-                * Note - we always use down_interruptible with the semaphore
-                * even if the module was loaded as part of the kernel.  The
-                * reason is that down() will cause this thread to be counted
-                * in the load average as a running process, and down
-                * interruptible doesn't.  Given that we need to allow this
-                * thread to die if the driver was loaded as a module, using
-                * semaphores isn't unreasonable.
-                */
-               down_interruptible(&sem);
-               if (kthread_should_stop())
-                       break;
+       set_current_state(TASK_INTERRUPTIBLE);
+       while (!kthread_should_stop()) {
+               if (shost->host_failed == 0 ||
+                   shost->host_failed != shost->host_busy) {
+                       SCSI_LOG_ERROR_RECOVERY(1, printk("Error handler"
+                                                         " scsi_eh_%d"
+                                                         " sleeping\n",
+                                                         shost->host_no));
+                       schedule();
+                       set_current_state(TASK_INTERRUPTIBLE);
+                       continue;
+               }
 
+               __set_current_state(TASK_RUNNING);
                SCSI_LOG_ERROR_RECOVERY(1, printk("Error handler"
                                                  " scsi_eh_%d waking"
                                                  " up\n",shost->host_no));
@@ -1642,16 +1636,18 @@ int scsi_error_handler(void *data)
                 * which are still online.
                 */
                scsi_restart_operations(shost);
-
+               set_current_state(TASK_INTERRUPTIBLE);
        }
 
+       __set_current_state(TASK_RUNNING);
+
        SCSI_LOG_ERROR_RECOVERY(1, printk("Error handler scsi_eh_%d"
                                          " exiting\n",shost->host_no));
 
        /*
         * Make sure that nobody tries to wake us up again.
         */
-       shost->eh_wait = NULL;
+       shost->ehandler = NULL;
        return 0;
 }
 
@@ -1681,7 +1677,7 @@ void scsi_report_bus_reset(struct Scsi_Host *shost, int channel)
        struct scsi_device *sdev;
 
        __shost_for_each_device(sdev, shost) {
-               if (channel == sdev->channel) {
+               if (channel == sdev_channel(sdev)) {
                        sdev->was_reset = 1;
                        sdev->expecting_cc_ua = 1;
                }
@@ -1716,8 +1712,8 @@ void scsi_report_device_reset(struct Scsi_Host *shost, int channel, int target)
        struct scsi_device *sdev;
 
        __shost_for_each_device(sdev, shost) {
-               if (channel == sdev->channel &&
-                   target == sdev->id) {
+               if (channel == sdev_channel(sdev) &&
+                   target == sdev_id(sdev)) {
                        sdev->was_reset = 1;
                        sdev->expecting_cc_ua = 1;
                }
@@ -1822,12 +1818,16 @@ EXPORT_SYMBOL(scsi_reset_provider);
 int scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
                          struct scsi_sense_hdr *sshdr)
 {
-       if (!sense_buffer || !sb_len || (sense_buffer[0] & 0x70) != 0x70)
+       if (!sense_buffer || !sb_len)
                return 0;
 
        memset(sshdr, 0, sizeof(struct scsi_sense_hdr));
 
        sshdr->response_code = (sense_buffer[0] & 0x7f);
+
+       if (!scsi_sense_valid(sshdr))
+               return 0;
+
        if (sshdr->response_code >= 0x72) {
                /*
                 * descriptor format
This page took 0.037741 seconds and 5 git commands to generate.