FreeBSD kernel kern code
|
Files | |
file | kern_fail.c |
Data Structures | |
struct | fail_point_entry |
struct | fail_point_setting |
Macros | |
#define | fp_free(ptr) free(ptr, M_FAIL_POINT) |
#define | fp_malloc(size, flags) malloc((size), M_FAIL_POINT, (flags)) |
#define | fs_free(ptr) fp_free(ptr) |
#define | fs_malloc() |
#define | FP_SLEEP_CHANNEL(fp) (void*)(fp) |
#define | FP_PAUSE_CHANNEL(fp) __DEVOLATILE(void*, &fp->fp_setting) |
#define | FP_MAX_ENTRY_COUNT 20 |
#define | FE_COUNT_UNTRACKED (INT_MIN) |
#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_PAUSE , FAIL_POINT_YIELD , FAIL_POINT_DELAY , FAIL_POINT_NUMTYPES , FAIL_POINT_INVALID = -1 } |
enum | { PROB_MAX = 1000000 , PROB_DIGITS = 6 } |
Functions | |
__FBSDID ("$FreeBSD$") | |
static | MALLOC_DEFINE (M_FAIL_POINT, "Fail Points", "fail points system") |
int | fail_sysctl_drain_func (void *, const char *, int) |
TAILQ_HEAD (fail_point_entry_queue, fail_point_entry) | |
STAILQ_HEAD (fail_point_setting_garbage, fail_point_setting) | |
MTX_SYSINIT (mtx_garbage_list, &mtx_garbage_list, "fail point garbage mtx", MTX_SPIN) | |
SX_SYSINIT (sx_fp_set, &sx_fp_set, "fail point set sx") | |
static struct fail_point_setting * | fail_point_setting_get_ref (struct fail_point *fp) |
static void | fail_point_setting_release_ref (struct fail_point *fp) |
static struct fail_point_setting * | fail_point_setting_new (struct fail_point *) |
static void | fail_point_setting_destroy (struct fail_point_setting *fp_setting) |
static struct fail_point_entry * | fail_point_entry_new (struct fail_point_setting *) |
static void | fail_point_entry_destroy (struct fail_point_entry *fp_entry) |
static void | fail_point_setting_garbage_append (struct fail_point_setting *fp_setting) |
static struct fail_point_setting * | fail_point_swap_settings (struct fail_point *fp, struct fail_point_setting *fp_setting_new) |
static void | fail_point_garbage_collect (void) |
static void | fail_point_eval_swap_out (struct fail_point *fp, struct fail_point_setting *fp_setting) |
bool | fail_point_is_off (struct fail_point *fp) |
static void | fail_point_drain (struct fail_point *fp, int expected_ref) |
static void | fail_point_pause (struct fail_point *fp, enum fail_point_return_code *pret, struct mtx *mtx_sleep) |
static void | fail_point_sleep (struct fail_point *fp, int msecs, enum fail_point_return_code *pret) |
static char * | parse_fail_point (struct fail_point_setting *, char *) |
static char * | parse_term (struct fail_point_setting *, char *) |
static char * | parse_number (int *out_units, int *out_decimal, char *) |
static char * | parse_type (struct fail_point_entry *, char *) |
void | fail_point_alloc_callout (struct fail_point *fp) |
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, bool verbose) |
static int | fail_point_set (struct fail_point *fp, char *buf) |
int | fail_point_sysctl (SYSCTL_HANDLER_ARGS) |
int | fail_point_sysctl_status (SYSCTL_HANDLER_ARGS) |
SYSCTL_NODE (_debug, OID_AUTO, fail_point, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "fail points") | |
static int | sysctl_test_fail_point (SYSCTL_HANDLER_ARGS) |
SYSCTL_OID (_debug_fail_point, OID_AUTO, test_trigger_fail_point, CTLTYPE_STRING|CTLFLAG_RD|CTLFLAG_NEEDGIANT, NULL, 0, sysctl_test_fail_point, "A", "Trigger test fail points") | |
Variables | |
static struct fail_point_setting_garbage | fp_setting_garbage |
static struct mtx | mtx_garbage_list |
static struct sx | sx_fp_set |
const char * name | |
int nmlen | |
struct { | |
const char * name | |
int nmlen | |
} | fail_type_strings [] |
volatile bool | fail_point_entry::fe_stale |
enum fail_point_t | fail_point_entry::fe_type |
int | fail_point_entry::fe_arg |
int | fail_point_entry::fe_prob |
int32_t | fail_point_entry::fe_count |
pid_t | fail_point_entry::fe_pid |
struct fail_point * | fail_point_entry::fe_parent |
Private implementations for the actual failpoint code.
#define FE_COUNT_UNTRACKED (INT_MIN) |
Definition at line 160 of file kern_fail.c.
#define fp_free | ( | ptr | ) | free(ptr, M_FAIL_POINT) |
Definition at line 83 of file kern_fail.c.
Definition at line 84 of file kern_fail.c.
#define FP_MAX_ENTRY_COUNT 20 |
Don't allow more than this many entries in a fail point set by sysctl. The 99.99...% case is to have 1 entry. I can't imagine having this many entries, so it should not limit us. Saves on re-mallocs while holding a non-sleepable lock.
Definition at line 103 of file kern_fail.c.
#define FP_PAUSE_CHANNEL | ( | fp | ) | __DEVOLATILE(void*, &fp->fp_setting) |
Definition at line 95 of file kern_fail.c.
#define FP_SLEEP_CHANNEL | ( | fp | ) | (void*)(fp) |
These define the wchans that are used for sleeping, pausing respectively. They are chosen arbitrarily but need to be distinct to the failpoint and the sleep/pause distinction.
Definition at line 94 of file kern_fail.c.
#define fs_free | ( | ptr | ) | fp_free(ptr) |
Definition at line 85 of file kern_fail.c.
#define fs_malloc | ( | ) |
Definition at line 86 of file kern_fail.c.
#define MAX_FAIL_POINT_BUF 1023 |
Definition at line 862 of file kern_fail.c.
anonymous enum |
Defines stating the equivalent of probablilty one (100%)
Enumerator | |
---|---|
PROB_MAX | |
PROB_DIGITS |
Definition at line 187 of file kern_fail.c.
enum fail_point_t |
Failpoint types. Don't change these without changing fail_type_strings in fail.c.
Definition at line 130 of file kern_fail.c.
__FBSDID | ( | "$FreeBSD$" | ) |
void fail_point_alloc_callout | ( | struct fail_point * | fp | ) |
This assumes that calls to fail_point_use_timeout_path() will not race.
Definition at line 499 of file kern_fail.c.
References callout_init(), and fp_malloc.
|
inlinestatic |
We have unpaused all threads; so we will wait no longer than the time taken for the longest remaining sleep, or the length of time of a long-running code block.
Definition at line 392 of file kern_fail.c.
References fail_point_swap_settings(), FP_PAUSE_CHANNEL, hz, and wakeup().
Referenced by fail_point_destroy().
|
static |
Definition at line 295 of file kern_fail.c.
References fp_free.
Referenced by fail_point_setting_destroy().
|
static |
Definition at line 277 of file kern_fail.c.
References fail_point_entry::fe_count, FE_COUNT_UNTRACKED, fail_point_entry::fe_parent, fail_point_entry::fe_pid, fail_point_entry::fe_prob, fp_malloc, and PROB_MAX.
Referenced by parse_term().
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".
Pausing is inherently strange with multiple entries given our design. That is because some entries could be unreachable, for instance in cases like: pause->return. We can never reach the return entry. The sysctl layer actually truncates all entries after a pause for this reason.
Definition at line 547 of file kern_fail.c.
References count, FAIL_POINT_BREAK, FAIL_POINT_DELAY, fail_point_eval_swap_out(), fail_point_is_off(), FAIL_POINT_PANIC, FAIL_POINT_PAUSE, fail_point_pause(), FAIL_POINT_PRINT, FAIL_POINT_RETURN, fail_point_setting_get_ref(), fail_point_setting_release_ref(), FAIL_POINT_SLEEP, fail_point_sleep(), FAIL_POINT_YIELD, fail_point_entry::fe_arg, fail_point_entry::fe_count, FE_COUNT_UNTRACKED, fail_point_entry::fe_pid, fail_point_entry::fe_prob, fail_point_entry::fe_stale, fail_point_entry::fe_type, kern_yield(), panic(), printf(), and PROB_MAX.
|
inlinestatic |
Definition at line 348 of file kern_fail.c.
References fail_point_swap_settings().
Referenced by fail_point_eval_nontrivial().
|
static |
We will transfer the entries to free to fp_ents_free_list while holding the spin mutex, then free it after we drop the lock. This avoids triggering witness due to sleepable mutexes in the memory allocator.
Definition at line 359 of file kern_fail.c.
References fail_point_setting_destroy(), fp_setting_garbage, and mtx_garbage_list.
Referenced by fail_point_destroy(), fail_point_sysctl(), and fail_point_sysctl_status().
|
static |
Translate internal fail_point structure into human-readable text.
Definition at line 665 of file kern_fail.c.
References FAIL_POINT_INVALID, fail_point_setting_get_ref(), fail_point_setting_release_ref(), 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_stale, fail_point_entry::fe_type, fp_free, fp_malloc, FP_MAX_ENTRY_COUNT, FP_PAUSE_CHANNEL, FP_SLEEP_CHANNEL, PROB_DIGITS, PROB_MAX, and sbuf_printf().
Referenced by fail_point_sysctl(), and fail_point_sysctl_status().
bool fail_point_is_off | ( | struct fail_point * | fp | ) |
Definition at line 221 of file kern_fail.c.
References fail_point_setting_get_ref(), fail_point_setting_release_ref(), and fail_point_entry::fe_stale.
Referenced by fail_point_eval_nontrivial().
|
inlinestatic |
Definition at line 412 of file kern_fail.c.
References FP_PAUSE_CHANNEL.
Referenced by fail_point_eval_nontrivial().
|
static |
Set an internal fail_point structure from a human-readable failpoint string in a lock-safe manner.
ref protects our new malloc'd stuff from being garbage collected before we link it.
Transfer the entries we are going to keep to a new list. Get rid of useless zero probability entries, and entries with hit count 0. If 'off' is present, and it has no hit count set, then all entries after it are discarded since they are unreachable.
If this fail point is annotated as being in a non-sleepable ctx, convert sleep to delay and convert the msec argument to usecs.
Definition at line 762 of file kern_fail.c.
References buf, FAIL_POINT_DELAY, FAIL_POINT_OFF, FAIL_POINT_PAUSE, fail_point_setting_destroy(), fail_point_setting_get_ref(), fail_point_setting_new(), fail_point_setting_release_ref(), FAIL_POINT_SLEEP, fail_point_swap_settings(), fail_type_strings, fail_point_entry::fe_arg, fail_point_entry::fe_count, FE_COUNT_UNTRACKED, fail_point_entry::fe_prob, fail_point_entry::fe_type, fp_free, FP_PAUSE_CHANNEL, fp_setting_garbage, parse_fail_point(), printf(), and wakeup().
Referenced by fail_point_sysctl().
|
static |
Definition at line 262 of file kern_fail.c.
References fail_point_entry_destroy(), and fs_free.
Referenced by fail_point_garbage_collect(), and fail_point_set().
|
inlinestatic |
Definition at line 325 of file kern_fail.c.
References fp_setting_garbage, and mtx_garbage_list.
Referenced by fail_point_setting_new().
|
inlinestatic |
Definition at line 303 of file kern_fail.c.
Referenced by fail_point_eval_nontrivial(), fail_point_get(), fail_point_is_off(), and fail_point_set().
|
static |
Definition at line 246 of file kern_fail.c.
References fail_point_setting_garbage_append(), and fs_malloc.
Referenced by fail_point_set().
|
inlinestatic |
Definition at line 316 of file kern_fail.c.
Referenced by fail_point_eval_nontrivial(), fail_point_get(), fail_point_is_off(), and fail_point_set().
|
inlinestatic |
Definition at line 426 of file kern_fail.c.
References FP_SLEEP_CHANNEL, and hz.
Referenced by fail_point_eval_nontrivial().
|
inlinestatic |
Definition at line 336 of file kern_fail.c.
Referenced by fail_point_drain(), fail_point_eval_swap_out(), and fail_point_set().
int fail_point_sysctl | ( | SYSCTL_HANDLER_ARGS | ) |
Handle kernel failpoint set/get.
Lock protects any new entries from being garbage collected before we can link them to the fail point.
Definition at line 868 of file kern_fail.c.
References buf, fail_point_garbage_collect(), fail_point_get(), fail_point_set(), fail_sysctl_drain_func(), fp_free, fp_malloc, MAX_FAIL_POINT_BUF, sbuf_delete(), sbuf_finish(), sbuf_new(), sbuf_set_drain(), and sx_fp_set.
int fail_point_sysctl_status | ( | SYSCTL_HANDLER_ARGS | ) |
Lock protects any new entries from being garbage collected before we can link them to the fail point.
Definition at line 924 of file kern_fail.c.
References fail_point_garbage_collect(), fail_point_get(), fail_sysctl_drain_func(), sbuf_delete(), sbuf_finish(), sbuf_new(), sbuf_set_drain(), and sx_fp_set.
int fail_sysctl_drain_func | ( | void * | sysctl_args, |
const char * | buf, | ||
int | len | ||
) |
Definition at line 955 of file kern_fail.c.
References buf.
Referenced by fail_point_sysctl(), and fail_point_sysctl_status().
|
static |
MTX_SYSINIT | ( | mtx_garbage_list | , |
& | mtx_garbage_list, | ||
"fail point garbage mtx" | , | ||
MTX_SPIN | |||
) |
|
static |
Internal helper function to translate a human-readable failpoint string into a internally-parsable fail_point structure.
Definition at line 975 of file kern_fail.c.
References FP_MAX_ENTRY_COUNT, and parse_term().
Referenced by fail_point_set().
|
static |
Internal helper function to parse a numeric for a failpoint term.
<number> :: <integer> [ "." <integer> ] | "." <integer>
Definition at line 1074 of file kern_fail.c.
References PROB_DIGITS.
Referenced by parse_term().
|
static |
Internal helper function to parse an individual term from a failpoint.
Definition at line 1002 of file kern_fail.c.
References fail_point_entry_new(), fail_point_entry::fe_arg, fail_point_entry::fe_count, fail_point_entry::fe_pid, fail_point_entry::fe_prob, parse_number(), parse_type(), PID_STRING, and PROB_MAX.
Referenced by parse_fail_point().
|
static |
Internal helper function to parse an individual type for a failpoint term.
Definition at line 1117 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().
STAILQ_HEAD | ( | fail_point_setting_garbage | , |
fail_point_setting | |||
) |
fp entries garbage list; outstanding entries are cleaned up in the garbage collector
SYSCTL_NODE | ( | _debug | , |
OID_AUTO | , | ||
fail_point | , | ||
CTLFLAG_RW| | CTLFLAG_MPSAFE, | ||
0 | , | ||
"fail points" | |||
) |
SYSCTL_OID | ( | _debug_fail_point | , |
OID_AUTO | , | ||
test_trigger_fail_point | , | ||
CTLTYPE_STRING|CTLFLAG_RD| | CTLFLAG_NEEDGIANT, | ||
NULL | , | ||
0 | , | ||
sysctl_test_fail_point | , | ||
"A" | , | ||
"Trigger test fail points" | |||
) |
|
static |
Definition at line 1138 of file kern_fail.c.
TAILQ_HEAD | ( | fail_point_entry_queue | , |
fail_point_entry | |||
) |
struct { ... } fail_type_strings[] |
Referenced by fail_point_get(), fail_point_set(), and parse_type().
int fail_point_entry::fe_arg |
argument to type (e.g. return value)
Definition at line 169 of file kern_fail.c.
Referenced by fail_point_eval_nontrivial(), fail_point_get(), fail_point_set(), and parse_term().
int32_t fail_point_entry::fe_count |
number of times to fire, -1 means infinite
Definition at line 171 of file kern_fail.c.
Referenced by fail_point_entry_new(), fail_point_eval_nontrivial(), fail_point_get(), fail_point_set(), and parse_term().
struct fail_point* fail_point_entry::fe_parent |
pid_t fail_point_entry::fe_pid |
only fail for this process
Definition at line 172 of file kern_fail.c.
Referenced by fail_point_entry_new(), fail_point_eval_nontrivial(), fail_point_get(), and parse_term().
int fail_point_entry::fe_prob |
likelihood of firing in millionths
Definition at line 170 of file kern_fail.c.
Referenced by fail_point_entry_new(), fail_point_eval_nontrivial(), fail_point_get(), fail_point_set(), and parse_term().
volatile bool fail_point_entry::fe_stale |
Definition at line 167 of file kern_fail.c.
Referenced by fail_point_eval_nontrivial(), fail_point_get(), and fail_point_is_off().
enum fail_point_t fail_point_entry::fe_type |
type of entry
Definition at line 168 of file kern_fail.c.
Referenced by fail_point_eval_nontrivial(), fail_point_get(), fail_point_set(), and parse_type().
|
static |
Definition at line 116 of file kern_fail.c.
Referenced by fail_point_garbage_collect(), fail_point_set(), and fail_point_setting_garbage_append().
|
static |
Definition at line 118 of file kern_fail.c.
Referenced by fail_point_garbage_collect(), and fail_point_setting_garbage_append().
const char * name |
Definition at line 145 of file kern_fail.c.
Referenced by _eventhandler_find_list(), _getenv_dynamic(), _getenv_dynamic_locked(), _getenv_static(), _getenv_static_from(), _gtaskqueue_create(), _gtaskqueue_start_threads(), _mtx_init(), _rw_init_flags(), _taskqueue_create(), _taskqueue_start_threads(), accept1(), accept_filt_del(), accept_filt_get(), bus_generic_add_child(), busdma_bufalloc_create(), cache_get_hash(), chglimit(), coredump(), corefile_open(), corefile_open_last(), ctty_clone(), dev_stdclone(), device_add_child(), device_add_child_ordered(), device_log(), device_lookup_by_name(), device_print_prettyname(), device_printf(), elf_hash(), epoch_alloc(), et_find(), eventhandler_create_list(), eventhandler_find_list(), eventhandler_find_or_create_list(), eventhandler_register(), eventhandler_register_internal(), fail_point_init(), firmware_register(), getenv_array(), getenv_bool(), getenv_int(), getenv_int64(), getenv_is_false(), getenv_is_true(), getenv_long(), getenv_quad(), getenv_string(), getenv_uint(), getenv_uint64(), getenv_ulong(), getjailname(), gtaskqueue_create_fast(), gtaskqueue_start_threads(), imgact_binmisc_disable_entry(), imgact_binmisc_enable_entry(), imgact_binmisc_find_entry(), imgact_binmisc_lookup_entry(), imgact_binmisc_remove_entry(), intr_event_add_handler(), intr_setup_irq(), intrcnt_setname(), isrc_add_handler(), isrc_update_name(), ithread_create(), kdb_dbbe_select(), kenv_acquire(), kern___sysctlbyname(), kern_accept(), kern_accept4(), kern_fpathconf(), kern_getenv(), kern_getsockopt(), kern_jail_get(), kern_jail_set(), kern_pathconf(), kern_setenv(), kern_setsockopt(), kern_unsetenv(), kernel_sysctl(), kernel_sysctlbyname(), ksem_create(), ktls_alloc_thread(), link_elf_lookup_debug_symbol(), link_elf_lookup_set(), link_elf_lookup_symbol(), link_elf_lookup_symbol1(), linker_file_lookup_set(), linker_file_lookup_symbol(), linker_file_lookup_symbol_internal(), linker_lookup_file(), linker_search_kld(), lock_init(), loginclass_find(), loginclass_lookup(), make_device(), mallocinit(), modlist_lookup(), modlist_lookup2(), module_lookupbyname(), mount_arg(), mount_argb(), mount_argf(), mount_argsu(), mqfs_create_file(), mqfs_create_node(), mqfs_search(), name2oid(), parse_dir_ask(), parse_mountroot_options(), parse_type(), pmc_soft_namecleanup(), preload_delete_name(), preload_search_by_name(), prison_add_allow(), prison_find_name(), prison_name(), pts_alloc_external(), res_find(), resource_disabled(), resource_find(), resource_find_dev(), resource_find_match(), resource_int_value(), resource_list_print_type(), resource_long_value(), resource_string_value(), resource_unset_value(), rm_init(), rm_init_flags(), rms_init(), setenv_static(), shm_init(), smr_create(), stack_print_ddb(), stack_symbol_ddb(), stats_tpl_fetch_allocid(), stats_v1_tpl_alloc(), swi_add(), sys___sysctl(), sys_kenv(), sys_modfind(), sys_modstat(), sys_thr_set_name(), sysctl_add_oid(), sysctl_debug_witness_channel(), sysctl_devices(), sysctl_find_oid(), sysctl_find_oidname(), sysctl_kern_function_list_iterate(), sysctl_kern_proc(), sysctl_kern_proc_args(), sysctl_kern_proc_auxv(), sysctl_kern_proc_cwd(), sysctl_kern_proc_env(), sysctl_kern_proc_filedesc(), sysctl_kern_proc_iterate(), sysctl_kern_proc_osrel(), sysctl_kern_proc_ps_strings(), sysctl_kern_proc_rlimit(), sysctl_kern_proc_sigfastblk(), sysctl_kern_proc_sigtramp(), sysctl_kern_proc_sv_name(), sysctl_kern_proc_umask(), sysctl_kern_proc_vm_layout(), sysctl_kern_proc_vmmap(), sysctl_remove_name(), sysctl_rename_oid(), sysctl_rman(), sysctl_sysctl_name(), sysctl_sysctl_next(), sysctl_sysctl_next_action(), sysctl_sysctl_next_node(), TAILQ_HEAD(), taskqgroup_attach(), taskqgroup_attach_cpu(), taskqgroup_create(), taskqueue_create(), taskqueue_create_fast(), taskqueue_start_threads(), taskqueue_start_threads_cpuset(), taskqueue_start_threads_in_proc(), terminal_maketty(), testenv(), tty_makedevf(), ttyconsdev_select(), umtx_cleanup_rb_list(), userland_sysctl(), vfs_byname(), vfs_byname_locked(), vfs_copyopt(), vfs_deleteopt(), vfs_flagopt(), vfs_getopt(), vfs_getopt_pos(), vfs_getopt_size(), vfs_getopts(), vfs_scanopt(), vfs_setopt(), vfs_setopt_part(), vfs_setopts(), vfs_sysctl(), vmem_create(), and vmem_init().
const char* { ... } ::name |
Definition at line 145 of file kern_fail.c.
int nmlen |
Definition at line 146 of file kern_fail.c.
int { ... } ::nmlen |
Definition at line 146 of file kern_fail.c.
|
static |
Definition at line 122 of file kern_fail.c.
Referenced by fail_point_destroy(), fail_point_sysctl(), and fail_point_sysctl_status().