ufs: tune bkops while power managment events
[firefly-linux-kernel-4.4.55.git] / drivers / scsi / scsi_error.c
index 7e957918f33f696df38dc58b4ff430d934190de0..6b20ef3fee541db301986add797680cc61626ae3 100644 (file)
@@ -59,11 +59,11 @@ static int scsi_try_to_abort_cmd(struct scsi_host_template *,
 /* called with shost->host_lock held */
 void scsi_eh_wakeup(struct Scsi_Host *shost)
 {
-       if (shost->host_busy == shost->host_failed) {
+       if (atomic_read(&shost->host_busy) == shost->host_failed) {
                trace_scsi_eh_wakeup(shost);
                wake_up_process(shost->ehandler);
-               SCSI_LOG_ERROR_RECOVERY(5,
-                               printk("Waking error handler thread\n"));
+               SCSI_LOG_ERROR_RECOVERY(5, shost_printk(KERN_INFO, shost,
+                       "Waking error handler thread\n"));
        }
 }
 
@@ -193,7 +193,7 @@ scsi_abort_command(struct scsi_cmnd *scmd)
                SCSI_LOG_ERROR_RECOVERY(3,
                        scmd_printk(KERN_INFO, scmd,
                                    "scmd %p previous abort failed\n", scmd));
-               cancel_delayed_work(&scmd->abort_work);
+               BUG_ON(delayed_work_pending(&scmd->abort_work));
                return FAILED;
        }
 
@@ -319,8 +319,8 @@ int scsi_block_when_processing_errors(struct scsi_device *sdev)
 
        online = scsi_device_online(sdev);
 
-       SCSI_LOG_ERROR_RECOVERY(5, printk("%s: rtn: %d\n", __func__,
-                                         online));
+       SCSI_LOG_ERROR_RECOVERY(5, sdev_printk(KERN_INFO, sdev,
+               "%s: rtn: %d\n", __func__, online));
 
        return online;
 }
@@ -365,8 +365,9 @@ static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost,
                }
        }
 
-       SCSI_LOG_ERROR_RECOVERY(2, printk("Total of %d commands on %d"
-                                         " devices require eh work\n",
+       SCSI_LOG_ERROR_RECOVERY(2, shost_printk(KERN_INFO, shost,
+                                  "Total of %d commands on %d"
+                                  " devices require eh work\n",
                                   total_failures, devices_failed));
 }
 #endif
@@ -738,8 +739,8 @@ static void scsi_eh_done(struct scsi_cmnd *scmd)
 {
        struct completion *eh_action;
 
-       SCSI_LOG_ERROR_RECOVERY(3,
-               printk("%s scmd: %p result: %x\n",
+       SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
+                       "%s scmd: %p result: %x\n",
                        __func__, scmd, scmd->result));
 
        eh_action = scmd->device->host->eh_action;
@@ -758,8 +759,8 @@ static int scsi_try_host_reset(struct scsi_cmnd *scmd)
        struct Scsi_Host *host = scmd->device->host;
        struct scsi_host_template *hostt = host->hostt;
 
-       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n",
-                                         __func__));
+       SCSI_LOG_ERROR_RECOVERY(3,
+               shost_printk(KERN_INFO, host, "Snd Host RST\n"));
 
        if (!hostt->eh_host_reset_handler)
                return FAILED;
@@ -788,8 +789,8 @@ static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
        struct Scsi_Host *host = scmd->device->host;
        struct scsi_host_template *hostt = host->hostt;
 
-       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n",
-                                         __func__));
+       SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
+               "%s: Snd Bus RST\n", __func__));
 
        if (!hostt->eh_bus_reset_handler)
                return FAILED;
@@ -1036,8 +1037,8 @@ retry:
 
        scsi_log_completion(scmd, rtn);
 
-       SCSI_LOG_ERROR_RECOVERY(3,
-               printk("%s: scmd: %p, timeleft: %ld\n",
+       SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
+                       "%s: scmd: %p, timeleft: %ld\n",
                        __func__, scmd, timeleft));
 
        /*
@@ -1051,9 +1052,8 @@ retry:
         */
        if (timeleft) {
                rtn = scsi_eh_completed_normally(scmd);
-               SCSI_LOG_ERROR_RECOVERY(3,
-                       printk("%s: scsi_eh_completed_normally %x\n",
-                              __func__, rtn));
+               SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
+                       "%s: scsi_eh_completed_normally %x\n", __func__, rtn));
 
                switch (rtn) {
                case SUCCESS:
@@ -1177,9 +1177,9 @@ int scsi_eh_get_sense(struct list_head *work_q,
                if (rtn != SUCCESS)
                        continue;
 
-               SCSI_LOG_ERROR_RECOVERY(3, printk("sense requested for %p"
-                                                 " result %x\n", scmd,
-                                                 scmd->result));
+               SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
+                       "sense requested for %p result %x\n",
+                       scmd, scmd->result));
                SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense("bh", scmd));
 
                rtn = scsi_decide_disposition(scmd);
@@ -1220,8 +1220,8 @@ retry_tur:
        rtn = scsi_send_eh_cmnd(scmd, tur_command, 6,
                                scmd->device->eh_timeout, 0);
 
-       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n",
-               __func__, scmd, rtn));
+       SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
+               "%s: scmd %p rtn %x\n", __func__, scmd, rtn));
 
        switch (rtn) {
        case NEEDS_RETRY:
@@ -1238,9 +1238,9 @@ retry_tur:
 /**
  * scsi_eh_test_devices - check if devices are responding from error recovery.
  * @cmd_list:  scsi commands in error recovery.
- * @work_q:     queue for commands which still need more error recovery
- * @done_q:     queue for commands which are finished
- * @try_stu:    boolean on if a STU command should be tried in addition to TUR.
+ * @work_q:    queue for commands which still need more error recovery
+ * @done_q:    queue for commands which are finished
+ * @try_stu:   boolean on if a STU command should be tried in addition to TUR.
  *
  * Decription:
  *    Tests if devices are in a working state.  Commands to devices now in
@@ -1323,16 +1323,16 @@ static int scsi_eh_abort_cmds(struct list_head *work_q,
                                             __func__));
                        return list_empty(work_q);
                }
-               SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting cmd:"
-                                                 "0x%p\n", current->comm,
-                                                 scmd));
+               SCSI_LOG_ERROR_RECOVERY(3,
+                       shost_printk(KERN_INFO, shost,
+                                    "%s: aborting cmd: 0x%p\n",
+                                    current->comm, scmd));
                rtn = scsi_try_to_abort_cmd(shost->hostt, scmd);
                if (rtn == FAILED) {
-                       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting"
-                                                         " cmd failed:"
-                                                         "0x%p\n",
-                                                         current->comm,
-                                                         scmd));
+                       SCSI_LOG_ERROR_RECOVERY(3,
+                               shost_printk(KERN_INFO, shost,
+                                            "%s: aborting cmd failed: 0x%p\n",
+                                            current->comm, scmd));
                        list_splice_init(&check_list, work_q);
                        return list_empty(work_q);
                }
@@ -1373,7 +1373,7 @@ static int scsi_eh_try_stu(struct scsi_cmnd *scmd)
  /**
  * scsi_eh_stu - send START_UNIT if needed
  * @shost:     &scsi host being recovered.
- * @work_q:     &list_head for pending commands.
+ * @work_q:    &list_head for pending commands.
  * @done_q:    &list_head for processed commands.
  *
  * Notes:
@@ -1406,8 +1406,10 @@ static int scsi_eh_stu(struct Scsi_Host *shost,
                if (!stu_scmd)
                        continue;
 
-               SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending START_UNIT to sdev:"
-                                                 " 0x%p\n", current->comm, sdev));
+               SCSI_LOG_ERROR_RECOVERY(3,
+                       shost_printk(KERN_INFO, shost,
+                                    "%s: Sending START_UNIT to sdev: 0x%p\n",
+                                    current->comm, sdev));
 
                if (!scsi_eh_try_stu(stu_scmd)) {
                        if (!scsi_device_online(sdev) ||
@@ -1421,8 +1423,9 @@ static int scsi_eh_stu(struct Scsi_Host *shost,
                        }
                } else {
                        SCSI_LOG_ERROR_RECOVERY(3,
-                                               printk("%s: START_UNIT failed to sdev:"
-                                                      " 0x%p\n", current->comm, sdev));
+                               shost_printk(KERN_INFO, shost,
+                                            "%s: START_UNIT failed to sdev:"
+                                            " 0x%p\n", current->comm, sdev));
                }
        }
 
@@ -1433,7 +1436,7 @@ static int scsi_eh_stu(struct Scsi_Host *shost,
 /**
  * scsi_eh_bus_device_reset - send bdr if needed
  * @shost:     scsi host being recovered.
- * @work_q:     &list_head for pending commands.
+ * @work_q:    &list_head for pending commands.
  * @done_q:    &list_head for processed commands.
  *
  * Notes:
@@ -1468,9 +1471,10 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
                if (!bdr_scmd)
                        continue;
 
-               SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending BDR sdev:"
-                                                 " 0x%p\n", current->comm,
-                                                 sdev));
+               SCSI_LOG_ERROR_RECOVERY(3,
+                       shost_printk(KERN_INFO, shost,
+                                    "%s: Sending BDR sdev: 0x%p\n",
+                                    current->comm, sdev));
                rtn = scsi_try_bus_device_reset(bdr_scmd);
                if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
                        if (!scsi_device_online(sdev) ||
@@ -1485,11 +1489,10 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
                                }
                        }
                } else {
-                       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: BDR"
-                                                         " failed sdev:"
-                                                         "0x%p\n",
-                                                         current->comm,
-                                                          sdev));
+                       SCSI_LOG_ERROR_RECOVERY(3,
+                               shost_printk(KERN_INFO, shost,
+                                            "%s: BDR failed sdev: 0x%p\n",
+                                            current->comm, sdev));
                }
        }
 
@@ -1499,7 +1502,7 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
 /**
  * scsi_eh_target_reset - send target reset if needed
  * @shost:     scsi host being recovered.
- * @work_q:     &list_head for pending commands.
+ * @work_q:    &list_head for pending commands.
  * @done_q:    &list_head for processed commands.
  *
  * Notes:
@@ -1533,15 +1536,17 @@ static int scsi_eh_target_reset(struct Scsi_Host *shost,
                scmd = list_entry(tmp_list.next, struct scsi_cmnd, eh_entry);
                id = scmd_id(scmd);
 
-               SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending target reset "
-                                                 "to target %d\n",
-                                                 current->comm, id));
+               SCSI_LOG_ERROR_RECOVERY(3,
+                       shost_printk(KERN_INFO, shost,
+                                    "%s: Sending target reset to target %d\n",
+                                    current->comm, id));
                rtn = scsi_try_target_reset(scmd);
                if (rtn != SUCCESS && rtn != FAST_IO_FAIL)
-                       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Target reset"
-                                                         " failed target: "
-                                                         "%d\n",
-                                                         current->comm, id));
+                       SCSI_LOG_ERROR_RECOVERY(3,
+                               shost_printk(KERN_INFO, shost,
+                                            "%s: Target reset failed"
+                                            " target: %d\n",
+                                            current->comm, id));
                list_for_each_entry_safe(scmd, next, &tmp_list, eh_entry) {
                        if (scmd_id(scmd) != id)
                                continue;
@@ -1562,7 +1567,7 @@ static int scsi_eh_target_reset(struct Scsi_Host *shost,
 /**
  * scsi_eh_bus_reset - send a bus reset
  * @shost:     &scsi host being recovered.
- * @work_q:     &list_head for pending commands.
+ * @work_q:    &list_head for pending commands.
  * @done_q:    &list_head for processed commands.
  */
 static int scsi_eh_bus_reset(struct Scsi_Host *shost,
@@ -1605,9 +1610,10 @@ static int scsi_eh_bus_reset(struct Scsi_Host *shost,
 
                if (!chan_scmd)
                        continue;
-               SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending BRST chan:"
-                                                 " %d\n", current->comm,
-                                                 channel));
+               SCSI_LOG_ERROR_RECOVERY(3,
+                       shost_printk(KERN_INFO, shost,
+                                    "%s: Sending BRST chan: %d\n",
+                                    current->comm, channel));
                rtn = scsi_try_bus_reset(chan_scmd);
                if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
                        list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
@@ -1621,10 +1627,10 @@ static int scsi_eh_bus_reset(struct Scsi_Host *shost,
                                }
                        }
                } else {
-                       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: BRST"
-                                                         " failed chan: %d\n",
-                                                         current->comm,
-                                                         channel));
+                       SCSI_LOG_ERROR_RECOVERY(3,
+                               shost_printk(KERN_INFO, shost,
+                                            "%s: BRST failed chan: %d\n",
+                                            current->comm, channel));
                }
        }
        return scsi_eh_test_devices(&check_list, work_q, done_q, 0);
@@ -1632,10 +1638,12 @@ static int scsi_eh_bus_reset(struct Scsi_Host *shost,
 
 /**
  * scsi_eh_host_reset - send a host reset
- * @work_q:    list_head for processed commands.
- * @done_q:    list_head for processed commands.
+ * @shost:     host to be reset.
+ * @work_q:    &list_head for pending commands.
+ * @done_q:    &list_head for processed commands.
  */
-static int scsi_eh_host_reset(struct list_head *work_q,
+static int scsi_eh_host_reset(struct Scsi_Host *shost,
+                             struct list_head *work_q,
                              struct list_head *done_q)
 {
        struct scsi_cmnd *scmd, *next;
@@ -1646,8 +1654,10 @@ static int scsi_eh_host_reset(struct list_head *work_q,
                scmd = list_entry(work_q->next,
                                  struct scsi_cmnd, eh_entry);
 
-               SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending HRST\n"
-                                                 , current->comm));
+               SCSI_LOG_ERROR_RECOVERY(3,
+                       shost_printk(KERN_INFO, shost,
+                                    "%s: Sending HRST\n",
+                                    current->comm));
 
                rtn = scsi_try_host_reset(scmd);
                if (rtn == SUCCESS) {
@@ -1657,9 +1667,10 @@ static int scsi_eh_host_reset(struct list_head *work_q,
                                        scsi_eh_finish_cmd(scmd, done_q);
                        }
                } else {
-                       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: HRST"
-                                                         " failed\n",
-                                                         current->comm));
+                       SCSI_LOG_ERROR_RECOVERY(3,
+                               shost_printk(KERN_INFO, shost,
+                                            "%s: HRST failed\n",
+                                            current->comm));
                }
        }
        return scsi_eh_test_devices(&check_list, work_q, done_q, 1);
@@ -1667,8 +1678,8 @@ static int scsi_eh_host_reset(struct list_head *work_q,
 
 /**
  * scsi_eh_offline_sdevs - offline scsi devices that fail to recover
- * @work_q:    list_head for processed commands.
- * @done_q:    list_head for processed commands.
+ * @work_q:    &list_head for pending commands.
+ * @done_q:    &list_head for processed commands.
  */
 static void scsi_eh_offline_sdevs(struct list_head *work_q,
                                  struct list_head *done_q)
@@ -1751,9 +1762,8 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
         * up to the top level.
         */
        if (!scsi_device_online(scmd->device)) {
-               SCSI_LOG_ERROR_RECOVERY(5, printk("%s: device offline - report"
-                                                 " as SUCCESS\n",
-                                                 __func__));
+               SCSI_LOG_ERROR_RECOVERY(5, scmd_printk(KERN_INFO, scmd,
+                       "%s: device offline - report as SUCCESS\n", __func__));
                return SUCCESS;
        }
 
@@ -1999,8 +2009,7 @@ static void scsi_restart_operations(struct Scsi_Host *shost)
         * ioctls to queued block devices.
         */
        SCSI_LOG_ERROR_RECOVERY(3,
-               printk("scsi_eh_%d waking up host to restart\n",
-                      shost->host_no));
+               shost_printk(KERN_INFO, shost, "waking up host to restart\n"));
 
        spin_lock_irqsave(shost->host_lock, flags);
        if (scsi_host_set_state(shost, SHOST_RUNNING))
@@ -2035,8 +2044,8 @@ static void scsi_restart_operations(struct Scsi_Host *shost)
 
 /**
  * scsi_eh_ready_devs - check device ready state and recover if not.
- * @shost:     host to be recovered.
- * @work_q:     &list_head for pending commands.
+ * @shost:     host to be recovered.
+ * @work_q:    &list_head for pending commands.
  * @done_q:    &list_head for processed commands.
  */
 void scsi_eh_ready_devs(struct Scsi_Host *shost,
@@ -2047,7 +2056,7 @@ void scsi_eh_ready_devs(struct Scsi_Host *shost,
                if (!scsi_eh_bus_device_reset(shost, work_q, done_q))
                        if (!scsi_eh_target_reset(shost, work_q, done_q))
                                if (!scsi_eh_bus_reset(shost, work_q, done_q))
-                                       if (!scsi_eh_host_reset(work_q, done_q))
+                                       if (!scsi_eh_host_reset(shost, work_q, done_q))
                                                scsi_eh_offline_sdevs(work_q,
                                                                      done_q);
 }
@@ -2066,10 +2075,10 @@ void scsi_eh_flush_done_q(struct list_head *done_q)
                if (scsi_device_online(scmd->device) &&
                    !scsi_noretry_cmd(scmd) &&
                    (++scmd->retries <= scmd->allowed)) {
-                       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: flush"
-                                                         " retry cmd: %p\n",
-                                                         current->comm,
-                                                         scmd));
+                       SCSI_LOG_ERROR_RECOVERY(3,
+                               scmd_printk(KERN_INFO, scmd,
+                                            "%s: flush retry cmd: %p\n",
+                                            current->comm, scmd));
                                scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
                } else {
                        /*
@@ -2079,9 +2088,10 @@ void scsi_eh_flush_done_q(struct list_head *done_q)
                         */
                        if (!scmd->result)
                                scmd->result |= (DRIVER_TIMEOUT << 24);
-                       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: flush finish"
-                                                       " cmd: %p\n",
-                                                       current->comm, scmd));
+                       SCSI_LOG_ERROR_RECOVERY(3,
+                               scmd_printk(KERN_INFO, scmd,
+                                            "%s: flush finish cmd: %p\n",
+                                            current->comm, scmd));
                        scsi_finish_command(scmd);
                }
        }
@@ -2155,19 +2165,22 @@ int scsi_error_handler(void *data)
        while (!kthread_should_stop()) {
                set_current_state(TASK_INTERRUPTIBLE);
                if ((shost->host_failed == 0 && shost->host_eh_scheduled == 0) ||
-                   shost->host_failed != shost->host_busy) {
+                   shost->host_failed != atomic_read(&shost->host_busy)) {
                        SCSI_LOG_ERROR_RECOVERY(1,
-                               printk("scsi_eh_%d: sleeping\n",
-                                       shost->host_no));
+                               shost_printk(KERN_INFO, shost,
+                                            "scsi_eh_%d: sleeping\n",
+                                            shost->host_no));
                        schedule();
                        continue;
                }
 
                __set_current_state(TASK_RUNNING);
                SCSI_LOG_ERROR_RECOVERY(1,
-                       printk("scsi_eh_%d: waking up %d/%d/%d\n",
-                              shost->host_no, shost->host_eh_scheduled,
-                              shost->host_failed, shost->host_busy));
+                       shost_printk(KERN_INFO, shost,
+                                    "scsi_eh_%d: waking up %d/%d/%d\n",
+                                    shost->host_no, shost->host_eh_scheduled,
+                                    shost->host_failed,
+                                    atomic_read(&shost->host_busy)));
 
                /*
                 * We have a host that is failing for some reason.  Figure out
@@ -2201,7 +2214,9 @@ int scsi_error_handler(void *data)
        __set_current_state(TASK_RUNNING);
 
        SCSI_LOG_ERROR_RECOVERY(1,
-               printk("Error handler scsi_eh_%d exiting\n", shost->host_no));
+               shost_printk(KERN_INFO, shost,
+                            "Error handler scsi_eh_%d exiting\n",
+                            shost->host_no));
        shost->ehandler = NULL;
        return 0;
 }
@@ -2362,8 +2377,8 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
         * suspended while we performed the TMF.
         */
        SCSI_LOG_ERROR_RECOVERY(3,
-               printk("%s: waking up host to restart after TMF\n",
-               __func__));
+               shost_printk(KERN_INFO, shost,
+                            "waking up host to restart after TMF\n"));
 
        wake_up(&shost->host_wait);