~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/scsi/scsi_eh.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/scsi/scsi_eh.rst (Version linux-6.12-rc7) and /Documentation/scsi/scsi_eh.rst (Version linux-5.18.19)


  1 .. SPDX-License-Identifier: GPL-2.0                 1 .. SPDX-License-Identifier: GPL-2.0
  2                                                     2 
  3 =======                                             3 =======
  4 SCSI EH                                             4 SCSI EH
  5 =======                                             5 =======
  6                                                     6 
  7 This document describes SCSI midlayer error ha      7 This document describes SCSI midlayer error handling infrastructure.
  8 Please refer to Documentation/scsi/scsi_mid_lo      8 Please refer to Documentation/scsi/scsi_mid_low_api.rst for more
  9 information regarding SCSI midlayer.                9 information regarding SCSI midlayer.
 10                                                    10 
 11 .. TABLE OF CONTENTS                               11 .. TABLE OF CONTENTS
 12                                                    12 
 13    [1] How SCSI commands travel through the mi     13    [1] How SCSI commands travel through the midlayer and to EH
 14        [1-1] struct scsi_cmnd                      14        [1-1] struct scsi_cmnd
 15        [1-2] How do scmd's get completed?          15        [1-2] How do scmd's get completed?
 16         [1-2-1] Completing a scmd w/ scsi_done     16         [1-2-1] Completing a scmd w/ scsi_done
 17         [1-2-2] Completing a scmd w/ timeout       17         [1-2-2] Completing a scmd w/ timeout
 18        [1-3] How EH takes over                     18        [1-3] How EH takes over
 19    [2] How SCSI EH works                           19    [2] How SCSI EH works
 20        [2-1] EH through fine-grained callbacks     20        [2-1] EH through fine-grained callbacks
 21         [2-1-1] Overview                           21         [2-1-1] Overview
 22         [2-1-2] Flow of scmds through EH           22         [2-1-2] Flow of scmds through EH
 23         [2-1-3] Flow of control                    23         [2-1-3] Flow of control
 24        [2-2] EH through transportt->eh_strateg     24        [2-2] EH through transportt->eh_strategy_handler()
 25         [2-2-1] Pre transportt->eh_strategy_ha     25         [2-2-1] Pre transportt->eh_strategy_handler() SCSI midlayer conditions
 26         [2-2-2] Post transportt->eh_strategy_h     26         [2-2-2] Post transportt->eh_strategy_handler() SCSI midlayer conditions
 27         [2-2-3] Things to consider                 27         [2-2-3] Things to consider
 28                                                    28 
 29                                                    29 
 30 1. How SCSI commands travel through the midlay     30 1. How SCSI commands travel through the midlayer and to EH
 31 ==============================================     31 ==========================================================
 32                                                    32 
 33 1.1 struct scsi_cmnd                               33 1.1 struct scsi_cmnd
 34 --------------------                               34 --------------------
 35                                                    35 
 36 Each SCSI command is represented with struct s     36 Each SCSI command is represented with struct scsi_cmnd (== scmd).  A
 37 scmd has two list_head's to link itself into l     37 scmd has two list_head's to link itself into lists.  The two are
 38 scmd->list and scmd->eh_entry.  The former is      38 scmd->list and scmd->eh_entry.  The former is used for free list or
 39 per-device allocated scmd list and not of much     39 per-device allocated scmd list and not of much interest to this EH
 40 discussion.  The latter is used for completion     40 discussion.  The latter is used for completion and EH lists and unless
 41 otherwise stated scmds are always linked using     41 otherwise stated scmds are always linked using scmd->eh_entry in this
 42 discussion.                                        42 discussion.
 43                                                    43 
 44                                                    44 
 45 1.2 How do scmd's get completed?                   45 1.2 How do scmd's get completed?
 46 --------------------------------                   46 --------------------------------
 47                                                    47 
 48 Once LLDD gets hold of a scmd, either the LLDD     48 Once LLDD gets hold of a scmd, either the LLDD will complete the
 49 command by calling scsi_done callback passed f     49 command by calling scsi_done callback passed from midlayer when
 50 invoking hostt->queuecommand() or the block la     50 invoking hostt->queuecommand() or the block layer will time it out.
 51                                                    51 
 52                                                    52 
 53 1.2.1 Completing a scmd w/ scsi_done               53 1.2.1 Completing a scmd w/ scsi_done
 54 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^               54 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 55                                                    55 
 56 For all non-EH commands, scsi_done() is the co     56 For all non-EH commands, scsi_done() is the completion callback.  It
 57 just calls blk_complete_request() to delete th     57 just calls blk_complete_request() to delete the block layer timer and
 58 raise SCSI_SOFTIRQ                                 58 raise SCSI_SOFTIRQ
 59                                                    59 
 60 SCSI_SOFTIRQ handler scsi_softirq calls scsi_d     60 SCSI_SOFTIRQ handler scsi_softirq calls scsi_decide_disposition() to
 61 determine what to do with the command.  scsi_d     61 determine what to do with the command.  scsi_decide_disposition()
 62 looks at the scmd->result value and sense data     62 looks at the scmd->result value and sense data to determine what to do
 63 with the command.                                  63 with the command.
 64                                                    64 
 65  - SUCCESS                                         65  - SUCCESS
 66                                                    66 
 67         scsi_finish_command() is invoked for t     67         scsi_finish_command() is invoked for the command.  The
 68         function does some maintenance chores      68         function does some maintenance chores and then calls
 69         scsi_io_completion() to finish the I/O     69         scsi_io_completion() to finish the I/O.
 70         scsi_io_completion() then notifies the     70         scsi_io_completion() then notifies the block layer on
 71         the completed request by calling blk_e     71         the completed request by calling blk_end_request and
 72         friends or figures out what to do with     72         friends or figures out what to do with the remainder
 73         of the data in case of an error.           73         of the data in case of an error.
 74                                                    74 
 75  - NEEDS_RETRY                                     75  - NEEDS_RETRY
 76                                                    76 
 77  - ADD_TO_MLQUEUE                                  77  - ADD_TO_MLQUEUE
 78                                                    78 
 79         scmd is requeued to blk queue.             79         scmd is requeued to blk queue.
 80                                                    80 
 81  - otherwise                                       81  - otherwise
 82                                                    82 
 83         scsi_eh_scmd_add(scmd) is invoked for      83         scsi_eh_scmd_add(scmd) is invoked for the command.  See
 84         [1-3] for details of this function.        84         [1-3] for details of this function.
 85                                                    85 
 86                                                    86 
 87 1.2.2 Completing a scmd w/ timeout                 87 1.2.2 Completing a scmd w/ timeout
 88 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                 88 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 89                                                    89 
 90 The timeout handler is scsi_timeout().  When a !!  90 The timeout handler is scsi_times_out().  When a timeout occurs, this
                                                   >>  91 function
 91                                                    92 
 92  1. invokes optional hostt->eh_timed_out() cal     93  1. invokes optional hostt->eh_timed_out() callback.  Return value can
 93     be one of                                      94     be one of
 94                                                    95 
 95     - SCSI_EH_RESET_TIMER                      !!  96     - BLK_EH_RESET_TIMER
 96         This indicates that more time is requi     97         This indicates that more time is required to finish the
 97         command.  Timer is restarted.              98         command.  Timer is restarted.
 98                                                    99 
 99     - SCSI_EH_NOT_HANDLED                      !! 100     - BLK_EH_DONE
100         eh_timed_out() callback did not handle    101         eh_timed_out() callback did not handle the command.
101         Step #2 is taken.                         102         Step #2 is taken.
102                                                << 
103     - SCSI_EH_DONE                             << 
104         eh_timed_out() completed the command.  << 
105                                                   103 
106  2. scsi_abort_command() is invoked to schedul    104  2. scsi_abort_command() is invoked to schedule an asynchronous abort which may
107     issue a retry scmd->allowed + 1 times.  As    105     issue a retry scmd->allowed + 1 times.  Asynchronous aborts are not invoked
108     for commands for which the SCSI_EH_ABORT_S    106     for commands for which the SCSI_EH_ABORT_SCHEDULED flag is set (this
109     indicates that the command already had bee    107     indicates that the command already had been aborted once, and this is a
110     retry which failed), when retries are exce    108     retry which failed), when retries are exceeded, or when the EH deadline is
111     expired. In these cases Step #3 is taken.     109     expired. In these cases Step #3 is taken.
112                                                   110 
113  3. scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD)    111  3. scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD) is invoked for the
114     command.  See [1-4] for more information.     112     command.  See [1-4] for more information.
115                                                   113 
116 1.3 Asynchronous command aborts                   114 1.3 Asynchronous command aborts
117 -------------------------------                   115 -------------------------------
118                                                   116 
119  After a timeout occurs a command abort is sch    117  After a timeout occurs a command abort is scheduled from
120  scsi_abort_command(). If the abort is success    118  scsi_abort_command(). If the abort is successful the command
121  will either be retried (if the number of retr    119  will either be retried (if the number of retries is not exhausted)
122  or terminated with DID_TIME_OUT.                 120  or terminated with DID_TIME_OUT.
123                                                   121 
124  Otherwise scsi_eh_scmd_add() is invoked for t    122  Otherwise scsi_eh_scmd_add() is invoked for the command.
125  See [1-4] for more information.                  123  See [1-4] for more information.
126                                                   124 
127 1.4 How EH takes over                             125 1.4 How EH takes over
128 ---------------------                             126 ---------------------
129                                                   127 
130 scmds enter EH via scsi_eh_scmd_add(), which d    128 scmds enter EH via scsi_eh_scmd_add(), which does the following.
131                                                   129 
132  1. Links scmd->eh_entry to shost->eh_cmd_q       130  1. Links scmd->eh_entry to shost->eh_cmd_q
133                                                   131 
134  2. Sets SHOST_RECOVERY bit in shost->shost_st    132  2. Sets SHOST_RECOVERY bit in shost->shost_state
135                                                   133 
136  3. Increments shost->host_failed                 134  3. Increments shost->host_failed
137                                                   135 
138  4. Wakes up SCSI EH thread if shost->host_bus    136  4. Wakes up SCSI EH thread if shost->host_busy == shost->host_failed
139                                                   137 
140 As can be seen above, once any scmd is added t    138 As can be seen above, once any scmd is added to shost->eh_cmd_q,
141 SHOST_RECOVERY shost_state bit is turned on.      139 SHOST_RECOVERY shost_state bit is turned on.  This prevents any new
142 scmd to be issued from blk queue to the host;     140 scmd to be issued from blk queue to the host; eventually, all scmds on
143 the host either complete normally, fail and ge    141 the host either complete normally, fail and get added to eh_cmd_q, or
144 time out and get added to shost->eh_cmd_q.        142 time out and get added to shost->eh_cmd_q.
145                                                   143 
146 If all scmds either complete or fail, the numb    144 If all scmds either complete or fail, the number of in-flight scmds
147 becomes equal to the number of failed scmds -     145 becomes equal to the number of failed scmds - i.e. shost->host_busy ==
148 shost->host_failed.  This wakes up SCSI EH thr    146 shost->host_failed.  This wakes up SCSI EH thread.  So, once woken up,
149 SCSI EH thread can expect that all in-flight c    147 SCSI EH thread can expect that all in-flight commands have failed and
150 are linked on shost->eh_cmd_q.                    148 are linked on shost->eh_cmd_q.
151                                                   149 
152 Note that this does not mean lower layers are     150 Note that this does not mean lower layers are quiescent.  If a LLDD
153 completed a scmd with error status, the LLDD a    151 completed a scmd with error status, the LLDD and lower layers are
154 assumed to forget about the scmd at that point    152 assumed to forget about the scmd at that point.  However, if a scmd
155 has timed out, unless hostt->eh_timed_out() ma    153 has timed out, unless hostt->eh_timed_out() made lower layers forget
156 about the scmd, which currently no LLDD does,     154 about the scmd, which currently no LLDD does, the command is still
157 active as long as lower layers are concerned a    155 active as long as lower layers are concerned and completion could
158 occur at any time.  Of course, all such comple    156 occur at any time.  Of course, all such completions are ignored as the
159 timer has already expired.                        157 timer has already expired.
160                                                   158 
161 We'll talk about how SCSI EH takes actions to     159 We'll talk about how SCSI EH takes actions to abort - make LLDD
162 forget about - timed out scmds later.             160 forget about - timed out scmds later.
163                                                   161 
164                                                   162 
165 2. How SCSI EH works                              163 2. How SCSI EH works
166 ====================                              164 ====================
167                                                   165 
168 LLDD's can implement SCSI EH actions in one of    166 LLDD's can implement SCSI EH actions in one of the following two
169 ways.                                             167 ways.
170                                                   168 
171  - Fine-grained EH callbacks                      169  - Fine-grained EH callbacks
172         LLDD can implement fine-grained EH cal    170         LLDD can implement fine-grained EH callbacks and let SCSI
173         midlayer drive error handling and call    171         midlayer drive error handling and call appropriate callbacks.
174         This will be discussed further in [2-1    172         This will be discussed further in [2-1].
175                                                   173 
176  - eh_strategy_handler() callback                 174  - eh_strategy_handler() callback
177         This is one big callback which should     175         This is one big callback which should perform whole error
178         handling.  As such, it should do all c    176         handling.  As such, it should do all chores the SCSI midlayer
179         performs during recovery.  This will b    177         performs during recovery.  This will be discussed in [2-2].
180                                                   178 
181 Once recovery is complete, SCSI EH resumes nor    179 Once recovery is complete, SCSI EH resumes normal operation by
182 calling scsi_restart_operations(), which          180 calling scsi_restart_operations(), which
183                                                   181 
184  1. Checks if door locking is needed and locks    182  1. Checks if door locking is needed and locks door.
185                                                   183 
186  2. Clears SHOST_RECOVERY shost_state bit         184  2. Clears SHOST_RECOVERY shost_state bit
187                                                   185 
188  3. Wakes up waiters on shost->host_wait.  Thi    186  3. Wakes up waiters on shost->host_wait.  This occurs if someone
189     calls scsi_block_when_processing_errors()     187     calls scsi_block_when_processing_errors() on the host.
190     (*QUESTION* why is it needed?  All operati    188     (*QUESTION* why is it needed?  All operations will be blocked
191     anyway after it reaches blk queue.)           189     anyway after it reaches blk queue.)
192                                                   190 
193  4. Kicks queues in all devices on the host in    191  4. Kicks queues in all devices on the host in the asses
194                                                   192 
195                                                   193 
196 2.1 EH through fine-grained callbacks             194 2.1 EH through fine-grained callbacks
197 -------------------------------------             195 -------------------------------------
198                                                   196 
199 2.1.1 Overview                                    197 2.1.1 Overview
200 ^^^^^^^^^^^^^^                                    198 ^^^^^^^^^^^^^^
201                                                   199 
202 If eh_strategy_handler() is not present, SCSI     200 If eh_strategy_handler() is not present, SCSI midlayer takes charge
203 of driving error handling.  EH's goals are two    201 of driving error handling.  EH's goals are two - make LLDD, host and
204 device forget about timed out scmds and make t    202 device forget about timed out scmds and make them ready for new
205 commands.  A scmd is said to be recovered if t    203 commands.  A scmd is said to be recovered if the scmd is forgotten by
206 lower layers and lower layers are ready to pro    204 lower layers and lower layers are ready to process or fail the scmd
207 again.                                            205 again.
208                                                   206 
209 To achieve these goals, EH performs recovery a    207 To achieve these goals, EH performs recovery actions with increasing
210 severity.  Some actions are performed by issui    208 severity.  Some actions are performed by issuing SCSI commands and
211 others are performed by invoking one of the fo    209 others are performed by invoking one of the following fine-grained
212 hostt EH callbacks.  Callbacks may be omitted     210 hostt EH callbacks.  Callbacks may be omitted and omitted ones are
213 considered to fail always.                        211 considered to fail always.
214                                                   212 
215 ::                                                213 ::
216                                                   214 
217     int (* eh_abort_handler)(struct scsi_cmnd     215     int (* eh_abort_handler)(struct scsi_cmnd *);
218     int (* eh_device_reset_handler)(struct scs    216     int (* eh_device_reset_handler)(struct scsi_cmnd *);
219     int (* eh_bus_reset_handler)(struct scsi_c    217     int (* eh_bus_reset_handler)(struct scsi_cmnd *);
220     int (* eh_host_reset_handler)(struct scsi_    218     int (* eh_host_reset_handler)(struct scsi_cmnd *);
221                                                   219 
222 Higher-severity actions are taken only when lo    220 Higher-severity actions are taken only when lower-severity actions
223 cannot recover some of failed scmds.  Also, no    221 cannot recover some of failed scmds.  Also, note that failure of the
224 highest-severity action means EH failure and r    222 highest-severity action means EH failure and results in offlining of
225 all unrecovered devices.                          223 all unrecovered devices.
226                                                   224 
227 During recovery, the following rules are follo    225 During recovery, the following rules are followed
228                                                   226 
229  - Recovery actions are performed on failed sc    227  - Recovery actions are performed on failed scmds on the to do list,
230    eh_work_q.  If a recovery action succeeds f    228    eh_work_q.  If a recovery action succeeds for a scmd, recovered
231    scmds are removed from eh_work_q.              229    scmds are removed from eh_work_q.
232                                                   230 
233    Note that single recovery action on a scmd     231    Note that single recovery action on a scmd can recover multiple
234    scmds.  e.g. resetting a device recovers al    232    scmds.  e.g. resetting a device recovers all failed scmds on the
235    device.                                        233    device.
236                                                   234 
237  - Higher severity actions are taken iff eh_wo    235  - Higher severity actions are taken iff eh_work_q is not empty after
238    lower severity actions are complete.           236    lower severity actions are complete.
239                                                   237 
240  - EH reuses failed scmds to issue commands fo    238  - EH reuses failed scmds to issue commands for recovery.  For
241    timed-out scmds, SCSI EH ensures that LLDD     239    timed-out scmds, SCSI EH ensures that LLDD forgets about a scmd
242    before reusing it for EH commands.             240    before reusing it for EH commands.
243                                                   241 
244 When a scmd is recovered, the scmd is moved fr    242 When a scmd is recovered, the scmd is moved from eh_work_q to EH
245 local eh_done_q using scsi_eh_finish_cmd().  A    243 local eh_done_q using scsi_eh_finish_cmd().  After all scmds are
246 recovered (eh_work_q is empty), scsi_eh_flush_    244 recovered (eh_work_q is empty), scsi_eh_flush_done_q() is invoked to
247 either retry or error-finish (notify upper lay    245 either retry or error-finish (notify upper layer of failure) recovered
248 scmds.                                            246 scmds.
249                                                   247 
250 scmds are retried iff its sdev is still online    248 scmds are retried iff its sdev is still online (not offlined during
251 EH), REQ_FAILFAST is not set and ++scmd->retri    249 EH), REQ_FAILFAST is not set and ++scmd->retries is less than
252 scmd->allowed.                                    250 scmd->allowed.
253                                                   251 
254                                                   252 
255 2.1.2 Flow of scmds through EH                    253 2.1.2 Flow of scmds through EH
256 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                    254 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
257                                                   255 
258  1. Error completion / time out                   256  1. Error completion / time out
259                                                   257 
260     :ACTION: scsi_eh_scmd_add() is invoked for    258     :ACTION: scsi_eh_scmd_add() is invoked for scmd
261                                                   259 
262         - add scmd to shost->eh_cmd_q             260         - add scmd to shost->eh_cmd_q
263         - set SHOST_RECOVERY                      261         - set SHOST_RECOVERY
264         - shost->host_failed++                    262         - shost->host_failed++
265                                                   263 
266     :LOCKING: shost->host_lock                    264     :LOCKING: shost->host_lock
267                                                   265 
268  2. EH starts                                     266  2. EH starts
269                                                   267 
270     :ACTION: move all scmds to EH's local eh_w    268     :ACTION: move all scmds to EH's local eh_work_q.  shost->eh_cmd_q
271              is cleared.                          269              is cleared.
272                                                   270 
273     :LOCKING: shost->host_lock (not strictly n    271     :LOCKING: shost->host_lock (not strictly necessary, just for
274              consistency)                         272              consistency)
275                                                   273 
276  3. scmd recovered                                274  3. scmd recovered
277                                                   275 
278     :ACTION: scsi_eh_finish_cmd() is invoked t    276     :ACTION: scsi_eh_finish_cmd() is invoked to EH-finish scmd
279                                                   277 
280         - scsi_setup_cmd_retry()                  278         - scsi_setup_cmd_retry()
281         - move from local eh_work_q to local e    279         - move from local eh_work_q to local eh_done_q
282                                                   280 
283     :LOCKING: none                                281     :LOCKING: none
284                                                   282 
285     :CONCURRENCY: at most one thread per separ    283     :CONCURRENCY: at most one thread per separate eh_work_q to
286                   keep queue manipulation lock    284                   keep queue manipulation lockless
287                                                   285 
288  4. EH completes                                  286  4. EH completes
289                                                   287 
290     :ACTION: scsi_eh_flush_done_q() retries sc    288     :ACTION: scsi_eh_flush_done_q() retries scmds or notifies upper
291              layer of failure. May be called c    289              layer of failure. May be called concurrently but must have
292              a no more than one thread per sep    290              a no more than one thread per separate eh_work_q to
293              manipulate the queue locklessly      291              manipulate the queue locklessly
294                                                   292 
295              - scmd is removed from eh_done_q     293              - scmd is removed from eh_done_q and scmd->eh_entry is cleared
296              - if retry is necessary, scmd is     294              - if retry is necessary, scmd is requeued using
297                scsi_queue_insert()                295                scsi_queue_insert()
298              - otherwise, scsi_finish_command(    296              - otherwise, scsi_finish_command() is invoked for scmd
299              - zero shost->host_failed            297              - zero shost->host_failed
300                                                   298 
301     :LOCKING: queue or finish function perform    299     :LOCKING: queue or finish function performs appropriate locking
302                                                   300 
303                                                   301 
304 2.1.3 Flow of control                             302 2.1.3 Flow of control
305 ^^^^^^^^^^^^^^^^^^^^^^                            303 ^^^^^^^^^^^^^^^^^^^^^^
306                                                   304 
307  EH through fine-grained callbacks start from     305  EH through fine-grained callbacks start from scsi_unjam_host().
308                                                   306 
309 ``scsi_unjam_host``                               307 ``scsi_unjam_host``
310                                                   308 
311     1. Lock shost->host_lock, splice_init shos    309     1. Lock shost->host_lock, splice_init shost->eh_cmd_q into local
312        eh_work_q and unlock host_lock.  Note t    310        eh_work_q and unlock host_lock.  Note that shost->eh_cmd_q is
313        cleared by this action.                    311        cleared by this action.
314                                                   312 
315     2. Invoke scsi_eh_get_sense.                  313     2. Invoke scsi_eh_get_sense.
316                                                   314 
317     ``scsi_eh_get_sense``                         315     ``scsi_eh_get_sense``
318                                                   316 
319         This action is taken for each error-co    317         This action is taken for each error-completed
320         (!SCSI_EH_CANCEL_CMD) commands without    318         (!SCSI_EH_CANCEL_CMD) commands without valid sense data.  Most
321         SCSI transports/LLDDs automatically ac    319         SCSI transports/LLDDs automatically acquire sense data on
322         command failures (autosense).  Autosen    320         command failures (autosense).  Autosense is recommended for
323         performance reasons and as sense infor    321         performance reasons and as sense information could get out of
324         sync between occurrence of CHECK CONDI    322         sync between occurrence of CHECK CONDITION and this action.
325                                                   323 
326         Note that if autosense is not supporte    324         Note that if autosense is not supported, scmd->sense_buffer
327         contains invalid sense data when error    325         contains invalid sense data when error-completing the scmd
328         with scsi_done().  scsi_decide_disposi    326         with scsi_done().  scsi_decide_disposition() always returns
329         FAILED in such cases thus invoking SCS    327         FAILED in such cases thus invoking SCSI EH.  When the scmd
330         reaches here, sense data is acquired a    328         reaches here, sense data is acquired and
331         scsi_decide_disposition() is called ag    329         scsi_decide_disposition() is called again.
332                                                   330 
333         1. Invoke scsi_request_sense() which i    331         1. Invoke scsi_request_sense() which issues REQUEST_SENSE
334            command.  If fails, no action.  Not    332            command.  If fails, no action.  Note that taking no action
335            causes higher-severity recovery to     333            causes higher-severity recovery to be taken for the scmd.
336                                                   334 
337         2. Invoke scsi_decide_disposition() on    335         2. Invoke scsi_decide_disposition() on the scmd
338                                                   336 
339            - SUCCESS                              337            - SUCCESS
340                 scmd->retries is set to scmd->    338                 scmd->retries is set to scmd->allowed preventing
341                 scsi_eh_flush_done_q() from re    339                 scsi_eh_flush_done_q() from retrying the scmd and
342                 scsi_eh_finish_cmd() is invoke    340                 scsi_eh_finish_cmd() is invoked.
343                                                   341 
344            - NEEDS_RETRY                          342            - NEEDS_RETRY
345                 scsi_eh_finish_cmd() invoked      343                 scsi_eh_finish_cmd() invoked
346                                                   344 
347            - otherwise                            345            - otherwise
348                 No action.                        346                 No action.
349                                                   347 
350     3. If !list_empty(&eh_work_q), invoke scsi    348     3. If !list_empty(&eh_work_q), invoke scsi_eh_abort_cmds().
351                                                   349 
352     ``scsi_eh_abort_cmds``                        350     ``scsi_eh_abort_cmds``
353                                                   351 
354         This action is taken for each timed ou    352         This action is taken for each timed out command when
355         no_async_abort is enabled in the host     353         no_async_abort is enabled in the host template.
356         hostt->eh_abort_handler() is invoked f    354         hostt->eh_abort_handler() is invoked for each scmd.  The
357         handler returns SUCCESS if it has succ    355         handler returns SUCCESS if it has succeeded to make LLDD and
358         all related hardware forget about the     356         all related hardware forget about the scmd.
359                                                   357 
360         If a timedout scmd is successfully abo    358         If a timedout scmd is successfully aborted and the sdev is
361         either offline or ready, scsi_eh_finis    359         either offline or ready, scsi_eh_finish_cmd() is invoked for
362         the scmd.  Otherwise, the scmd is left    360         the scmd.  Otherwise, the scmd is left in eh_work_q for
363         higher-severity actions.                  361         higher-severity actions.
364                                                   362 
365         Note that both offline and ready statu    363         Note that both offline and ready status mean that the sdev is
366         ready to process new scmds, where proc    364         ready to process new scmds, where processing also implies
367         immediate failing; thus, if a sdev is     365         immediate failing; thus, if a sdev is in one of the two
368         states, no further recovery action is     366         states, no further recovery action is needed.
369                                                   367 
370         Device readiness is tested using scsi_    368         Device readiness is tested using scsi_eh_tur() which issues
371         TEST_UNIT_READY command.  Note that th    369         TEST_UNIT_READY command.  Note that the scmd must have been
372         aborted successfully before reusing it    370         aborted successfully before reusing it for TEST_UNIT_READY.
373                                                   371 
374     4. If !list_empty(&eh_work_q), invoke scsi    372     4. If !list_empty(&eh_work_q), invoke scsi_eh_ready_devs()
375                                                   373 
376     ``scsi_eh_ready_devs``                        374     ``scsi_eh_ready_devs``
377                                                   375 
378         This function takes four increasingly     376         This function takes four increasingly more severe measures to
379         make failed sdevs ready for new comman    377         make failed sdevs ready for new commands.
380                                                   378 
381         1. Invoke scsi_eh_stu()                   379         1. Invoke scsi_eh_stu()
382                                                   380 
383         ``scsi_eh_stu``                           381         ``scsi_eh_stu``
384                                                   382 
385             For each sdev which has failed scm    383             For each sdev which has failed scmds with valid sense data
386             of which scsi_check_sense()'s verd    384             of which scsi_check_sense()'s verdict is FAILED,
387             START_STOP_UNIT command is issued     385             START_STOP_UNIT command is issued w/ start=1.  Note that
388             as we explicitly choose error-comp    386             as we explicitly choose error-completed scmds, it is known
389             that lower layers have forgotten a    387             that lower layers have forgotten about the scmd and we can
390             reuse it for STU.                     388             reuse it for STU.
391                                                   389 
392             If STU succeeds and the sdev is ei    390             If STU succeeds and the sdev is either offline or ready,
393             all failed scmds on the sdev are E    391             all failed scmds on the sdev are EH-finished with
394             scsi_eh_finish_cmd().                 392             scsi_eh_finish_cmd().
395                                                   393 
396             *NOTE* If hostt->eh_abort_handler(    394             *NOTE* If hostt->eh_abort_handler() isn't implemented or
397             failed, we may still have timed ou    395             failed, we may still have timed out scmds at this point
398             and STU doesn't make lower layers     396             and STU doesn't make lower layers forget about those
399             scmds.  Yet, this function EH-fini    397             scmds.  Yet, this function EH-finish all scmds on the sdev
400             if STU succeeds leaving lower laye    398             if STU succeeds leaving lower layers in an inconsistent
401             state.  It seems that STU action s    399             state.  It seems that STU action should be taken only when
402             a sdev has no timed out scmd.         400             a sdev has no timed out scmd.
403                                                   401 
404         2. If !list_empty(&eh_work_q), invoke     402         2. If !list_empty(&eh_work_q), invoke scsi_eh_bus_device_reset().
405                                                   403 
406         ``scsi_eh_bus_device_reset``              404         ``scsi_eh_bus_device_reset``
407                                                   405 
408             This action is very similar to scs    406             This action is very similar to scsi_eh_stu() except that,
409             instead of issuing STU, hostt->eh_    407             instead of issuing STU, hostt->eh_device_reset_handler()
410             is used.  Also, as we're not issui    408             is used.  Also, as we're not issuing SCSI commands and
411             resetting clears all scmds on the     409             resetting clears all scmds on the sdev, there is no need
412             to choose error-completed scmds.      410             to choose error-completed scmds.
413                                                   411 
414         3. If !list_empty(&eh_work_q), invoke     412         3. If !list_empty(&eh_work_q), invoke scsi_eh_bus_reset()
415                                                   413 
416         ``scsi_eh_bus_reset``                     414         ``scsi_eh_bus_reset``
417                                                   415 
418             hostt->eh_bus_reset_handler() is i    416             hostt->eh_bus_reset_handler() is invoked for each channel
419             with failed scmds.  If bus reset s    417             with failed scmds.  If bus reset succeeds, all failed
420             scmds on all ready or offline sdev    418             scmds on all ready or offline sdevs on the channel are
421             EH-finished.                          419             EH-finished.
422                                                   420 
423         4. If !list_empty(&eh_work_q), invoke     421         4. If !list_empty(&eh_work_q), invoke scsi_eh_host_reset()
424                                                   422 
425         ``scsi_eh_host_reset``                    423         ``scsi_eh_host_reset``
426                                                   424 
427             This is the last resort.  hostt->e    425             This is the last resort.  hostt->eh_host_reset_handler()
428             is invoked.  If host reset succeed    426             is invoked.  If host reset succeeds, all failed scmds on
429             all ready or offline sdevs on the     427             all ready or offline sdevs on the host are EH-finished.
430                                                   428 
431         5. If !list_empty(&eh_work_q), invoke     429         5. If !list_empty(&eh_work_q), invoke scsi_eh_offline_sdevs()
432                                                   430 
433         ``scsi_eh_offline_sdevs``                 431         ``scsi_eh_offline_sdevs``
434                                                   432 
435             Take all sdevs which still have un    433             Take all sdevs which still have unrecovered scmds offline
436             and EH-finish the scmds.              434             and EH-finish the scmds.
437                                                   435 
438     5. Invoke scsi_eh_flush_done_q().             436     5. Invoke scsi_eh_flush_done_q().
439                                                   437 
440         ``scsi_eh_flush_done_q``                  438         ``scsi_eh_flush_done_q``
441                                                   439 
442             At this point all scmds are recove    440             At this point all scmds are recovered (or given up) and
443             put on eh_done_q by scsi_eh_finish    441             put on eh_done_q by scsi_eh_finish_cmd().  This function
444             flushes eh_done_q by either retryi    442             flushes eh_done_q by either retrying or notifying upper
445             layer of failure of the scmds.        443             layer of failure of the scmds.
446                                                   444 
447                                                   445 
448 2.2 EH through transportt->eh_strategy_handler    446 2.2 EH through transportt->eh_strategy_handler()
449 ----------------------------------------------    447 ------------------------------------------------
450                                                   448 
451 transportt->eh_strategy_handler() is invoked i    449 transportt->eh_strategy_handler() is invoked in the place of
452 scsi_unjam_host() and it is responsible for wh    450 scsi_unjam_host() and it is responsible for whole recovery process.
453 On completion, the handler should have made lo    451 On completion, the handler should have made lower layers forget about
454 all failed scmds and either ready for new comm    452 all failed scmds and either ready for new commands or offline.  Also,
455 it should perform SCSI EH maintenance chores t    453 it should perform SCSI EH maintenance chores to maintain integrity of
456 SCSI midlayer.  IOW, of the steps described in    454 SCSI midlayer.  IOW, of the steps described in [2-1-2], all steps
457 except for #1 must be implemented by eh_strate    455 except for #1 must be implemented by eh_strategy_handler().
458                                                   456 
459                                                   457 
460 2.2.1 Pre transportt->eh_strategy_handler() SC    458 2.2.1 Pre transportt->eh_strategy_handler() SCSI midlayer conditions
461 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    459 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
462                                                   460 
463  The following conditions are true on entry to    461  The following conditions are true on entry to the handler.
464                                                   462 
465  - Each failed scmd's eh_flags field is set ap    463  - Each failed scmd's eh_flags field is set appropriately.
466                                                   464 
467  - Each failed scmd is linked on scmd->eh_cmd_    465  - Each failed scmd is linked on scmd->eh_cmd_q by scmd->eh_entry.
468                                                   466 
469  - SHOST_RECOVERY is set.                         467  - SHOST_RECOVERY is set.
470                                                   468 
471  - shost->host_failed == shost->host_busy         469  - shost->host_failed == shost->host_busy
472                                                   470 
473                                                   471 
474 2.2.2 Post transportt->eh_strategy_handler() S    472 2.2.2 Post transportt->eh_strategy_handler() SCSI midlayer conditions
475 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    473 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
476                                                   474 
477  The following conditions must be true on exit    475  The following conditions must be true on exit from the handler.
478                                                   476 
479  - shost->host_failed is zero.                    477  - shost->host_failed is zero.
480                                                   478 
481  - Each scmd is in such a state that scsi_setu    479  - Each scmd is in such a state that scsi_setup_cmd_retry() on the
482    scmd doesn't make any difference.              480    scmd doesn't make any difference.
483                                                   481 
484  - shost->eh_cmd_q is cleared.                    482  - shost->eh_cmd_q is cleared.
485                                                   483 
486  - Each scmd->eh_entry is cleared.                484  - Each scmd->eh_entry is cleared.
487                                                   485 
488  - Either scsi_queue_insert() or scsi_finish_c    486  - Either scsi_queue_insert() or scsi_finish_command() is called on
489    each scmd.  Note that the handler is free t    487    each scmd.  Note that the handler is free to use scmd->retries and
490    ->allowed to limit the number of retries.      488    ->allowed to limit the number of retries.
491                                                   489 
492                                                   490 
493 2.2.3 Things to consider                          491 2.2.3 Things to consider
494 ^^^^^^^^^^^^^^^^^^^^^^^^                          492 ^^^^^^^^^^^^^^^^^^^^^^^^
495                                                   493 
496  - Know that timed out scmds are still active     494  - Know that timed out scmds are still active on lower layers.  Make
497    lower layers forget about them before doing    495    lower layers forget about them before doing anything else with
498    those scmds.                                   496    those scmds.
499                                                   497 
500  - For consistency, when accessing/modifying s    498  - For consistency, when accessing/modifying shost data structure,
501    grab shost->host_lock.                         499    grab shost->host_lock.
502                                                   500 
503  - On completion, each failed sdev must have f    501  - On completion, each failed sdev must have forgotten about all
504    active scmds.                                  502    active scmds.
505                                                   503 
506  - On completion, each failed sdev must be rea    504  - On completion, each failed sdev must be ready for new commands or
507    offline.                                       505    offline.
508                                                   506 
509                                                   507 
510 Tejun Heo                                         508 Tejun Heo
511 htejun@gmail.com                                  509 htejun@gmail.com
512                                                   510 
513 11th September 2005                               511 11th September 2005
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php