FreeBSD kernel kern code
Private fail(9) Implementation functions
Collaboration diagram for Private fail(9) Implementation functions:

Files

file  kern_fail.c
 

Data Structures

struct  fail_point_entry
 

Macros

#define fp_free(ptr)   free(ptr, M_FAIL_POINT)
 
#define fp_malloc(size, flags)   malloc((size), M_FAIL_POINT, (flags))
 
#define FP_LOCK()   mtx_lock(&g_fp_mtx)
 
#define FP_UNLOCK()   mtx_unlock(&g_fp_mtx)
 
#define MAX_FAIL_POINT_BUF   1023
 

Enumerations

enum  fail_point_t {
  FAIL_POINT_OFF, FAIL_POINT_PANIC, FAIL_POINT_RETURN, FAIL_POINT_BREAK,
  FAIL_POINT_PRINT, FAIL_POINT_SLEEP, FAIL_POINT_NUMTYPES
}
 
enum  { PROB_MAX = 1000000, PROB_DIGITS = 6 }
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static MALLOC_DEFINE (M_FAIL_POINT,"Fail Points","fail points system")
 
 MTX_SYSINIT (g_fp_mtx,&g_fp_mtx,"fail point mtx", MTX_DEF)
 
static void fail_point_sleep (struct fail_point *fp, struct fail_point_entry *ent, int msecs, enum fail_point_return_code *pret)
 
static char * parse_fail_point (struct fail_point_entries *, char *)
 
static char * parse_term (struct fail_point_entries *, char *)
 
static char * parse_number (int *out_units, int *out_decimal, char *)
 
static char * parse_type (struct fail_point_entry *, char *)
 
static void free_entry (struct fail_point_entries *, struct fail_point_entry *)
 
static void clear_entries (struct fail_point_entries *)
 
enum fail_point_return_code fail_point_eval_nontrivial (struct fail_point *fp, int *return_value)
 
static void fail_point_get (struct fail_point *fp, struct sbuf *sb)
 
static int fail_point_set (struct fail_point *fp, char *buf)
 
int fail_point_sysctl (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_NODE (_debug, OID_AUTO, fail_point, CTLFLAG_RW, 0,"fail points")
 

Variables

static struct mtx g_fp_mtx
 
const char *   name
 
int   nmlen
 
struct {
   const char *   name
 
   int   nmlen
 
fail_type_strings []
 
enum fail_point_t fail_point_entry::fe_type
 
int fail_point_entry::fe_arg
 
int fail_point_entry::fe_prob
 
int fail_point_entry::fe_count
 
pid_t fail_point_entry::fe_pid
 

Detailed Description

Private implementations for the actual failpoint code.

Macro Definition Documentation

#define fp_free (   ptr)    free(ptr, M_FAIL_POINT)

Definition at line 73 of file kern_fail.c.

Referenced by clear_entries(), fail_point_destroy(), fail_point_sysctl(), and free_entry().

#define FP_LOCK ( )    mtx_lock(&g_fp_mtx)

Definition at line 78 of file kern_fail.c.

Referenced by fail_point_eval_nontrivial(), fail_point_get(), and fail_point_set().

#define fp_malloc (   size,
  flags 
)    malloc((size), M_FAIL_POINT, (flags))

Definition at line 74 of file kern_fail.c.

Referenced by fail_point_init(), fail_point_sysctl(), and parse_term().

#define FP_UNLOCK ( )    mtx_unlock(&g_fp_mtx)

Definition at line 79 of file kern_fail.c.

Referenced by fail_point_eval_nontrivial(), fail_point_get(), and fail_point_set().

#define MAX_FAIL_POINT_BUF   1023

Definition at line 383 of file kern_fail.c.

Referenced by fail_point_sysctl().

Enumeration Type Documentation

anonymous enum

Defines stating the equivalent of probablilty one (100%)

Enumerator
PROB_MAX 
PROB_DIGITS 

Definition at line 143 of file kern_fail.c.

Failpoint types. Don't change these without changing fail_type_strings in fail.c.

Enumerator
FAIL_POINT_OFF 

don't fail

FAIL_POINT_PANIC 

panic

FAIL_POINT_RETURN 

return an errorcode

FAIL_POINT_BREAK 

break into the debugger

FAIL_POINT_PRINT 

print a message

FAIL_POINT_SLEEP 

sleep for some msecs

FAIL_POINT_NUMTYPES 

Definition at line 86 of file kern_fail.c.

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
static void clear_entries ( struct fail_point_entries *  ents)
static

Internal helper function to clear out all failpoint terms for a single failpoint.

Definition at line 601 of file kern_fail.c.

References fp_free.

Referenced by fail_point_destroy(), and fail_point_set().

Here is the caller graph for this function:

enum fail_point_return_code fail_point_eval_nontrivial ( struct fail_point *  fp,
int *  return_value 
)

This does the real work of evaluating a fail point. If the fail point tells us to return a value, this function returns 1 and fills in 'return_value' (return_value is allowed to be null). If the fail point tells us to panic, we never return. Otherwise we just return 0 after doing some work, which means "keep going".

Definition at line 217 of file kern_fail.c.

References FAIL_POINT_BREAK, FAIL_POINT_OFF, FAIL_POINT_PANIC, FAIL_POINT_PRINT, FAIL_POINT_RETURN, FAIL_POINT_SLEEP, fail_point_sleep(), fail_point_entry::fe_arg, fail_point_entry::fe_count, fail_point_entry::fe_pid, fail_point_entry::fe_prob, fail_point_entry::fe_type, FP_LOCK, FP_UNLOCK, free_entry(), panic(), printf(), and PROB_MAX.

Here is the call graph for this function:

static void fail_point_get ( struct fail_point *  fp,
struct sbuf *  sb 
)
static

Translate internal fail_point structure into human-readable text.

Definition at line 295 of file kern_fail.c.

References fail_type_strings, fail_point_entry::fe_arg, fail_point_entry::fe_count, fail_point_entry::fe_pid, fail_point_entry::fe_prob, fail_point_entry::fe_type, FP_LOCK, FP_UNLOCK, PROB_DIGITS, PROB_MAX, and sbuf_printf().

Referenced by fail_point_sysctl().

Here is the call graph for this function:

Here is the caller graph for this function:

static int fail_point_set ( struct fail_point *  fp,
char *  buf 
)
static

Set an internal fail_point structure from a human-readable failpoint string in a lock-safe manner.

Definition at line 337 of file kern_fail.c.

References clear_entries(), FAIL_POINT_OFF, fail_point_entry::fe_prob, fail_point_entry::fe_type, FP_LOCK, FP_UNLOCK, free_entry(), and parse_fail_point().

Referenced by fail_point_sysctl().

Here is the call graph for this function:

Here is the caller graph for this function:

static void fail_point_sleep ( struct fail_point *  fp,
struct fail_point_entry ent,
int  msecs,
enum fail_point_return_code *  pret 
)
inlinestatic

Definition at line 123 of file kern_fail.c.

References g_fp_mtx, hz, and timeout().

Referenced by fail_point_eval_nontrivial().

Here is the call graph for this function:

Here is the caller graph for this function:

int fail_point_sysctl ( SYSCTL_HANDLER_ARGS  )

Handle kernel failpoint set/get.

Definition at line 389 of file kern_fail.c.

References buf, fail_point_get(), fail_point_set(), fp_free, fp_malloc, MAX_FAIL_POINT_BUF, sbuf_data(), sbuf_delete(), sbuf_finish(), sbuf_len(), sbuf_new(), and sbuf_trim().

Here is the call graph for this function:

static void free_entry ( struct fail_point_entries *  ents,
struct fail_point_entry ent 
)
static

Internal helper function to free an individual failpoint term.

Definition at line 590 of file kern_fail.c.

References fp_free.

Referenced by fail_point_eval_nontrivial(), and fail_point_set().

Here is the caller graph for this function:

static MALLOC_DEFINE ( M_FAIL_POINT  ,
"Fail Points"  ,
"fail points system"   
)
static
MTX_SYSINIT ( g_fp_mtx  ,
g_fp_mtx,
"fail point mtx"  ,
MTX_DEF   
)
static char * parse_fail_point ( struct fail_point_entries *  ents,
char *  p 
)
static

Internal helper function to translate a human-readable failpoint string into a internally-parsable fail_point structure.

Definition at line 431 of file kern_fail.c.

References parse_term().

Referenced by fail_point_set().

Here is the call graph for this function:

Here is the caller graph for this function:

static char * parse_number ( int *  out_units,
int *  out_decimal,
char *  p 
)
static

Internal helper function to parse a numeric for a failpoint term.

Definition at line 528 of file kern_fail.c.

References PROB_DIGITS.

Referenced by parse_term().

Here is the caller graph for this function:

static char * parse_term ( struct fail_point_entries *  ents,
char *  p 
)
static

Internal helper function to parse an individual term from a failpoint.

Definition at line 453 of file kern_fail.c.

References fail_point_entry::fe_arg, fail_point_entry::fe_count, fail_point_entry::fe_pid, fail_point_entry::fe_prob, fp_malloc, parse_number(), parse_type(), PID_STRING, and PROB_MAX.

Referenced by parse_fail_point().

Here is the call graph for this function:

Here is the caller graph for this function:

static char * parse_type ( struct fail_point_entry ent,
char *  beg 
)
static

Internal helper function to parse an individual type for a failpoint term.

Definition at line 571 of file kern_fail.c.

References FAIL_POINT_NUMTYPES, FAIL_POINT_OFF, fail_type_strings, fail_point_entry::fe_type, name, and type.

Referenced by parse_term().

Here is the caller graph for this function:

SYSCTL_NODE ( _debug  ,
OID_AUTO  ,
fail_point  ,
CTLFLAG_RW  ,
,
"fail points"   
)

Variable Documentation

struct { ... } fail_type_strings[]
Initial value:

Referenced by fail_point_get(), and parse_type().

int fail_point_entry::fe_arg

argument to type (e.g. return value)

Definition at line 115 of file kern_fail.c.

Referenced by fail_point_eval_nontrivial(), fail_point_get(), and parse_term().

int fail_point_entry::fe_count

number of times to fire, 0 means always

Definition at line 117 of file kern_fail.c.

Referenced by fail_point_eval_nontrivial(), fail_point_get(), and parse_term().

pid_t fail_point_entry::fe_pid

only fail for this process

Definition at line 118 of file kern_fail.c.

Referenced by fail_point_eval_nontrivial(), fail_point_get(), and parse_term().

int fail_point_entry::fe_prob

likelihood of firing in millionths

Definition at line 116 of file kern_fail.c.

Referenced by fail_point_eval_nontrivial(), fail_point_get(), fail_point_set(), and parse_term().

enum fail_point_t fail_point_entry::fe_type

type of entry

Definition at line 114 of file kern_fail.c.

Referenced by fail_point_eval_nontrivial(), fail_point_get(), fail_point_set(), and parse_type().

struct mtx g_fp_mtx
static

Definition at line 76 of file kern_fail.c.

Referenced by fail_point_sleep().

const { ... } name

Definition at line 97 of file kern_fail.c.

int nmlen

Definition at line 98 of file kern_fail.c.

int { ... } nmlen

Definition at line 98 of file kern_fail.c.