xref: /freebsd/share/man/man9/fail.9 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1cfeb7489SZachary Loafman.\"
23cf556f0SRyan Libby.\" Copyright (c) 2009-2019 Dell EMC Isilon http://www.isilon.com/
3cfeb7489SZachary Loafman.\"
4cfeb7489SZachary Loafman.\" Redistribution and use in source and binary forms, with or without
5cfeb7489SZachary Loafman.\" modification, are permitted provided that the following conditions
6cfeb7489SZachary Loafman.\" are met:
7cfeb7489SZachary Loafman.\" 1. Redistributions of source code must retain the above copyright
8cfeb7489SZachary Loafman.\"    notice(s), this list of conditions and the following disclaimer as
9cfeb7489SZachary Loafman.\"    the first lines of this file unmodified other than the possible
10cfeb7489SZachary Loafman.\"    addition of one or more copyright notices.
11cfeb7489SZachary Loafman.\" 2. Redistributions in binary form must reproduce the above copyright
12cfeb7489SZachary Loafman.\"    notice(s), this list of conditions and the following disclaimer in the
13cfeb7489SZachary Loafman.\"    documentation and/or other materials provided with the distribution.
14cfeb7489SZachary Loafman.\"
15cfeb7489SZachary Loafman.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
16cfeb7489SZachary Loafman.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17cfeb7489SZachary Loafman.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18cfeb7489SZachary Loafman.\" DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
19cfeb7489SZachary Loafman.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20cfeb7489SZachary Loafman.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21cfeb7489SZachary Loafman.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22cfeb7489SZachary Loafman.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23cfeb7489SZachary Loafman.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24cfeb7489SZachary Loafman.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25cfeb7489SZachary Loafman.\" DAMAGE.
26cfeb7489SZachary Loafman.\"
273cf556f0SRyan Libby.Dd June 6, 2019
28cfeb7489SZachary Loafman.Dt FAIL 9
29cfeb7489SZachary Loafman.Os
30cfeb7489SZachary Loafman.Sh NAME
313cf556f0SRyan Libby.Nm DEBUG_FP ,
32cfeb7489SZachary Loafman.Nm KFAIL_POINT_CODE ,
3370e20d4eSConrad Meyer.Nm KFAIL_POINT_CODE_FLAGS ,
3470e20d4eSConrad Meyer.Nm KFAIL_POINT_CODE_COND ,
353cf556f0SRyan Libby.Nm KFAIL_POINT_ERROR ,
363cf556f0SRyan Libby.Nm KFAIL_POINT_EVAL ,
373cf556f0SRyan Libby.Nm KFAIL_POINT_DECLARE ,
383cf556f0SRyan Libby.Nm KFAIL_POINT_DEFINE ,
393cf556f0SRyan Libby.Nm KFAIL_POINT_GOTO ,
40cfeb7489SZachary Loafman.Nm KFAIL_POINT_RETURN ,
41cfeb7489SZachary Loafman.Nm KFAIL_POINT_RETURN_VOID ,
4270e20d4eSConrad Meyer.Nm KFAIL_POINT_SLEEP_CALLBACKS ,
433cf556f0SRyan Libby.Nm fail_point
44cfeb7489SZachary Loafman.Nd fail points
45cfeb7489SZachary Loafman.Sh SYNOPSIS
46cfeb7489SZachary Loafman.In sys/fail.h
47cfeb7489SZachary Loafman.Fn KFAIL_POINT_CODE "parent" "name" "code"
4870e20d4eSConrad Meyer.Fn KFAIL_POINT_CODE_FLAGS "parent" "name" "flags" "code"
4970e20d4eSConrad Meyer.Fn KFAIL_POINT_CODE_COND "parent" "name" "cond" "flags" "code"
503cf556f0SRyan Libby.Fn KFAIL_POINT_ERROR "parent" "name" "error_var"
513cf556f0SRyan Libby.Fn KFAIL_POINT_EVAL "name" "code"
523cf556f0SRyan Libby.Fn KFAIL_POINT_DECLARE "name"
533cf556f0SRyan Libby.Fn KFAIL_POINT_DEFINE "parent" "name" "flags"
543cf556f0SRyan Libby.Fn KFAIL_POINT_GOTO "parent" "name" "error_var" "label"
55cfeb7489SZachary Loafman.Fn KFAIL_POINT_RETURN "parent" "name"
56cfeb7489SZachary Loafman.Fn KFAIL_POINT_RETURN_VOID "parent" "name"
5770e20d4eSConrad Meyer.Fn KFAIL_POINT_SLEEP_CALLBACKS "parent" "name" "pre_func" "pre_arg" "post_func" "post_arg" "code"
58cfeb7489SZachary Loafman.Sh DESCRIPTION
59cfeb7489SZachary LoafmanFail points are used to add code points where errors may be injected
60eae608efSZachary Loafmanin a user controlled fashion.
61eae608efSZachary LoafmanFail points provide a convenient wrapper around user-provided error
62eae608efSZachary Loafmaninjection code, providing a
63eae608efSZachary Loafman.Xr sysctl 9
64eae608efSZachary LoafmanMIB, and a parser for that MIB that describes how the error
65cfeb7489SZachary Loafmaninjection code should fire.
66cfeb7489SZachary Loafman.Pp
67cfeb7489SZachary LoafmanThe base fail point macro is
68cfeb7489SZachary Loafman.Fn KFAIL_POINT_CODE
69cfeb7489SZachary Loafmanwhere
70cfeb7489SZachary Loafman.Fa parent
71cfeb7489SZachary Loafmanis a sysctl tree (frequently
72cfeb7489SZachary Loafman.Sy DEBUG_FP
73cfeb7489SZachary Loafmanfor kernel fail points, but various subsystems may wish to provide
74cfeb7489SZachary Loafmantheir own fail point trees), and
75cfeb7489SZachary Loafman.Fa name
76cfeb7489SZachary Loafmanis the name of the MIB in that tree, and
77cfeb7489SZachary Loafman.Fa code
78eae608efSZachary Loafmanis the error injection code.
79eae608efSZachary LoafmanThe
80cfeb7489SZachary Loafman.Fa code
81cfeb7489SZachary Loafmanargument does not require braces, but it is considered good style to
82eae608efSZachary Loafmanuse braces for any multi-line code arguments.
83eae608efSZachary LoafmanInside the
84cfeb7489SZachary Loafman.Fa code
85cfeb7489SZachary Loafmanargument, the evaluation of
86cfeb7489SZachary Loafman.Sy RETURN_VALUE
87cfeb7489SZachary Loafmanis derived from the
88cfeb7489SZachary Loafman.Fn return
89eae608efSZachary Loafmanvalue set in the sysctl MIB.
9070e20d4eSConrad Meyer.Pp
9170e20d4eSConrad MeyerAdditionally,
9270e20d4eSConrad Meyer.Fn KFAIL_POINT_CODE_FLAGS
9370e20d4eSConrad Meyerprovides a
9470e20d4eSConrad Meyer.Fa flags
9570e20d4eSConrad Meyerargument which controls the fail point's behaviour.
9670e20d4eSConrad MeyerThis can be used to e.g., mark the fail point's context as non-sleepable,
9770e20d4eSConrad Meyerwhich causes the
9870e20d4eSConrad Meyer.Sy sleep
9970e20d4eSConrad Meyeraction to be coerced to a busy wait.
10070e20d4eSConrad MeyerThe supported flags are:
10170e20d4eSConrad Meyer.Bl -ohang -offset indent
10270e20d4eSConrad Meyer.It FAIL_POINT_USE_TIMEOUT_PATH
10370e20d4eSConrad MeyerRather than sleeping on a
10470e20d4eSConrad Meyer.Fn sleep
10570e20d4eSConrad Meyercall, just fire the post-sleep function after a timeout fires.
10670e20d4eSConrad Meyer.It FAIL_POINT_NONSLEEPABLE
10770e20d4eSConrad MeyerMark the fail point as being in a non-sleepable context, which coerces
10870e20d4eSConrad Meyer.Fn sleep
10970e20d4eSConrad Meyercalls to
11070e20d4eSConrad Meyer.Fn delay
11170e20d4eSConrad Meyercalls.
11270e20d4eSConrad Meyer.El
11370e20d4eSConrad Meyer.Pp
11470e20d4eSConrad MeyerLikewise,
11570e20d4eSConrad Meyer.Fn KFAIL_POINT_CODE_COND
11670e20d4eSConrad Meyersupplies a
11770e20d4eSConrad Meyer.Fa cond
11870e20d4eSConrad Meyerargument, which allows you to set the condition under which the fail point's
11970e20d4eSConrad Meyercode may fire.
12070e20d4eSConrad MeyerThis is equivalent to:
12170e20d4eSConrad Meyer.Bd -literal
12270e20d4eSConrad Meyer	if (cond)
12370e20d4eSConrad Meyer		KFAIL_POINT_CODE_FLAGS(...);
12470e20d4eSConrad Meyer
12570e20d4eSConrad Meyer.Ed
126eae608efSZachary LoafmanSee
127aa8775c6SChristian Brueffer.Sx SYSCTL VARIABLES
128cfeb7489SZachary Loafmanbelow.
129cfeb7489SZachary Loafman.Pp
130cfeb7489SZachary LoafmanThe remaining
131cfeb7489SZachary Loafman.Fn KFAIL_POINT_*
132cfeb7489SZachary Loafmanmacros are wrappers around common error injection paths:
13363d46d1dSUlrich Spörlein.Bl -inset
134cfeb7489SZachary Loafman.It Fn KFAIL_POINT_RETURN parent name
135cfeb7489SZachary Loafmanis the equivalent of
136cfeb7489SZachary Loafman.Sy KFAIL_POINT_CODE(..., return RETURN_VALUE)
137cfeb7489SZachary Loafman.It Fn KFAIL_POINT_RETURN_VOID parent name
138cfeb7489SZachary Loafmanis the equivalent of
139cfeb7489SZachary Loafman.Sy KFAIL_POINT_CODE(..., return)
140cfeb7489SZachary Loafman.It Fn KFAIL_POINT_ERROR parent name error_var
141cfeb7489SZachary Loafmanis the equivalent of
142cfeb7489SZachary Loafman.Sy KFAIL_POINT_CODE(..., error_var = RETURN_VALUE)
143cfeb7489SZachary Loafman.It Fn KFAIL_POINT_GOTO parent name error_var label
144cfeb7489SZachary Loafmanis the equivalent of
14563d46d1dSUlrich Spörlein.Sy KFAIL_POINT_CODE(..., { error_var = RETURN_VALUE; goto label;})
146cfeb7489SZachary Loafman.El
1473cf556f0SRyan Libby.Pp
1483cf556f0SRyan LibbyYou can also introduce fail points by separating the declaration,
1493cf556f0SRyan Libbydefinition, and evaluation portions.
1503cf556f0SRyan Libby.Bl -inset
1513cf556f0SRyan Libby.It Fn KFAIL_POINT_DECLARE name
1523cf556f0SRyan Libbyis used to declare the
1533cf556f0SRyan Libby.Sy fail_point
1543cf556f0SRyan Libbystruct.
1553cf556f0SRyan Libby.It Fn KFAIL_POINT_DEFINE parent name flags
1563cf556f0SRyan Libbydefines and initializes the
1573cf556f0SRyan Libby.Sy fail_point
1583cf556f0SRyan Libbyand sets up its
1593cf556f0SRyan Libby.Xr sysctl 9 .
1603cf556f0SRyan Libby.It Fn KFAIL_POINT_EVAL name code
1613cf556f0SRyan Libbyis used at the point that the fail point is executed.
1623cf556f0SRyan Libby.El
163cfeb7489SZachary Loafman.Sh SYSCTL VARIABLES
164cfeb7489SZachary LoafmanThe
165cfeb7489SZachary Loafman.Fn KFAIL_POINT_*
166eae608efSZachary Loafmanmacros add sysctl MIBs where specified.
167eae608efSZachary LoafmanMany base kernel MIBs can be found in the
168cfeb7489SZachary Loafman.Sy debug.fail_point
169cfeb7489SZachary Loafmantree (referenced in code by
170aa8775c6SChristian Brueffer.Sy DEBUG_FP ) .
171cfeb7489SZachary Loafman.Pp
17270e20d4eSConrad MeyerThe sysctl variable may be set in a number of ways:
173aa8775c6SChristian Brueffer.Bd -literal
17470e20d4eSConrad Meyer  [<pct>%][<cnt>*]<type>[(args...)][-><more terms>]
175aa8775c6SChristian Brueffer.Ed
176cfeb7489SZachary Loafman.Pp
17770e20d4eSConrad MeyerThe <type> argument specifies which action to take; it can be one of:
178cfeb7489SZachary Loafman.Bl -tag -width ".Dv return"
179cfeb7489SZachary Loafman.It Sy off
180cfeb7489SZachary LoafmanTake no action (does not trigger fail point code)
181cfeb7489SZachary Loafman.It Sy return
182cfeb7489SZachary LoafmanTrigger fail point code with specified argument
183cfeb7489SZachary Loafman.It Sy sleep
184cfeb7489SZachary LoafmanSleep the specified number of milliseconds
185cfeb7489SZachary Loafman.It Sy panic
186cfeb7489SZachary LoafmanPanic
187cfeb7489SZachary Loafman.It Sy break
188eae608efSZachary LoafmanBreak into the debugger, or trap if there is no debugger support
189cfeb7489SZachary Loafman.It Sy print
190cfeb7489SZachary LoafmanPrint that the fail point executed
19170e20d4eSConrad Meyer.It Sy pause
19270e20d4eSConrad MeyerThreads sleep at the fail point until the fail point is set to
19370e20d4eSConrad Meyer.Sy off
19470e20d4eSConrad Meyer.It Sy yield
19570e20d4eSConrad MeyerThread yields the cpu when the fail point is evaluated
19670e20d4eSConrad Meyer.It Sy delay
19770e20d4eSConrad MeyerSimilar to sleep, but busy waits the cpu.
19870e20d4eSConrad Meyer(Useful in non-sleepable contexts.)
199cfeb7489SZachary Loafman.El
200cfeb7489SZachary Loafman.Pp
20170e20d4eSConrad MeyerThe <pct>% and <cnt>* modifiers prior to <type> control when
202eae608efSZachary Loafman<type> is executed.
20370e20d4eSConrad MeyerThe <pct>% form (e.g. "1.2%") can be used to specify a
204eae608efSZachary Loafmanprobability that <type> will execute.
20570e20d4eSConrad MeyerThis is a decimal in the range (0, 100] which can specify up to
20670e20d4eSConrad Meyer1/10,000% precision.
20770e20d4eSConrad MeyerThe <cnt>* form (e.g. "5*") can be used to specify the number of
208eae608efSZachary Loafmantimes <type> should be executed before this <term> is disabled.
209eae608efSZachary LoafmanOnly the last probability and the last count are used if multiple
210eae608efSZachary Loafmanare specified, i.e. "1.2%2%" is the same as "2%".
211eae608efSZachary LoafmanWhen both a probability and a count are specified, the probability
212eae608efSZachary Loafmanis evaluated before the count, i.e. "2%5*" means "2% of the time,
213eae608efSZachary Loafmanbut only 5 times total".
214cfeb7489SZachary Loafman.Pp
215eae608efSZachary LoafmanThe operator -> can be used to express cascading terms.
216aa8775c6SChristian BruefferIf you specify <term1>-><term2>, it means that if <term1> does not
217aa8775c6SChristian Brueffer.Ql execute ,
218aa8775c6SChristian Brueffer<term2> is evaluated.
219*501de9c0SGordon BerglingFor the purpose of this operator, the
220*501de9c0SGordon Bergling.Fn return
221*501de9c0SGordon Berglingand
222*501de9c0SGordon Bergling.Fn print
223*501de9c0SGordon Berglingoperators are the only types that cascade.
224*501de9c0SGordon BerglingA
225*501de9c0SGordon Bergling.Fn return
226*501de9c0SGordon Berglingterm only cascades if the code executes, and a
227*501de9c0SGordon Bergling.Fn print
228eae608efSZachary Loafmanterm only cascades when passed a non-zero argument.
229b5bd50aeSMatthew D FlemingA pid can optionally be specified.
230b5bd50aeSMatthew D FlemingThe fail point term is only executed when invoked by a process with a
231b5bd50aeSMatthew D Flemingmatching p_pid.
232cfeb7489SZachary Loafman.Sh EXAMPLES
233ecb0bac9SGlen Barber.Bl -tag -width Sy
234cfeb7489SZachary Loafman.It Sy sysctl debug.fail_point.foobar="2.1%return(5)"
235cfeb7489SZachary Loafman21/1000ths of the time, execute
236cfeb7489SZachary Loafman.Fa code
237cfeb7489SZachary Loafmanwith RETURN_VALUE set to 5.
238cfeb7489SZachary Loafman.It Sy sysctl debug.fail_point.foobar="2%return(5)->5%return(22)"
239eae608efSZachary Loafman2/100ths of the time, execute
240cfeb7489SZachary Loafman.Fa code
241eae608efSZachary Loafmanwith RETURN_VALUE set to 5.
242aa8775c6SChristian BruefferIf that does not happen, 5% of the time execute
243cfeb7489SZachary Loafman.Fa code
244cfeb7489SZachary Loafmanwith RETURN_VALUE set to 22.
245cfeb7489SZachary Loafman.It Sy sysctl debug.fail_point.foobar="5*return(5)->0.1%return(22)"
246eae608efSZachary LoafmanFor 5 times, return 5.
247eae608efSZachary LoafmanAfter that, 1/1000th of the time, return 22.
248cfeb7489SZachary Loafman.It Sy sysctl debug.fail_point.foobar="0.1%5*return(5)"
249eae608efSZachary LoafmanReturn 5 for 1 in 1000 executions, but only 5 times total.
250cfeb7489SZachary Loafman.It Sy sysctl debug.fail_point.foobar="1%*sleep(50)"
251eae608efSZachary Loafman1/100th of the time, sleep 50ms.
252b5bd50aeSMatthew D Fleming.It Sy sysctl debug.fail_point.foobar="1*return(5)[pid 1234]"
253b5bd50aeSMatthew D FlemingReturn 5 once, when pid 1234 executes the fail point.
254cfeb7489SZachary Loafman.El
2550afc94c1SUlrich Spörlein.Sh AUTHORS
2560afc94c1SUlrich Spörlein.An -nosplit
2570afc94c1SUlrich SpörleinThis manual page was written by
25870e20d4eSConrad Meyer.Pp
25970e20d4eSConrad Meyer.An Matthew Bryan Aq Mt matthew.bryan@isilon.com
26070e20d4eSConrad Meyerand
26170e20d4eSConrad Meyer.Pp
2628a7314fcSBaptiste Daroussin.An Zach Loafman Aq Mt zml@FreeBSD.org .
263cfeb7489SZachary Loafman.Sh CAVEATS
264aa8775c6SChristian BruefferIt is easy to shoot yourself in the foot by setting fail points too
265eae608efSZachary Loafmanaggressively or setting too many in combination.
266eae608efSZachary LoafmanFor example, forcing
267cfeb7489SZachary Loafman.Fn malloc
268cfeb7489SZachary Loafmanto fail consistently is potentially harmful to uptime.
269cfeb7489SZachary Loafman.Pp
270cfeb7489SZachary LoafmanThe
271cfeb7489SZachary Loafman.Fn sleep
272eae608efSZachary Loafmansysctl setting may not be appropriate in all situations.
273eae608efSZachary LoafmanCurrently,
274cfeb7489SZachary Loafman.Fn fail_point_eval
275cfeb7489SZachary Loafmandoes not verify whether the context is appropriate for calling
276cfeb7489SZachary Loafman.Fn msleep .
27770e20d4eSConrad MeyerYou can force it to evaluate a
27870e20d4eSConrad Meyer.Sy sleep
27970e20d4eSConrad Meyeraction as a
28070e20d4eSConrad Meyer.Sy delay
28170e20d4eSConrad Meyeraction by specifying the
28270e20d4eSConrad Meyer.Sy FAIL_POINT_NONSLEEPABLE
28370e20d4eSConrad Meyerflag at the point the fail point is declared.
284