Motr  M0
finject.c File Reference
#include <stdio.h>
#include "lib/errno.h"
#include "lib/memory.h"
#include "lib/mutex.h"
#include "lib/misc.h"
#include "lib/assert.h"
#include "lib/tlist.h"
#include "lib/finject.h"
#include "lib/finject_internal.h"
#include "motr/magic.h"
#include "lib/trace.h"
Include dependency graph for finject.c:

Go to the source code of this file.

Data Structures

struct  fi_dynamic_id
 

Macros

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_LIB
 

Enumerations

enum  { FI_STATES_ARRAY_SIZE = 64 * 1024 }
 

Functions

 M0_TL_DESCR_DEFINE (fi_dynamic_ids, "finject_dynamic_id", static, struct fi_dynamic_id, fdi_tlink, fdi_magic, M0_FI_DYNAMIC_ID_MAGIC, M0_FI_DYNAMIC_ID_HEAD_MAGIC)
 
 M0_TL_DEFINE (fi_dynamic_ids, static, struct fi_dynamic_id)
 
M0_INTERNAL const struct m0_fi_fpoint_statem0_fi_states_get (void)
 
M0_INTERNAL uint32_t m0_fi_states_get_free_idx (void)
 
static uint32_t fi_state_idx (const struct m0_fi_fpoint_state *s)
 
static void fi_state_info_init (struct m0_fi_fpoint_state_info *si)
 
M0_INTERNAL void m0_fi_states_get_state_info (const struct m0_fi_fpoint_state *s, struct m0_fi_fpoint_state_info *si)
 
M0_INTERNAL int m0_fi_add_dyn_id (char *str)
 
static void fi_dynamic_ids_fini (void)
 
M0_INTERNAL void fi_states_init (void)
 
M0_INTERNAL void fi_states_fini (void)
 
static bool fi_fpoint_id_eq (const struct m0_fi_fpoint_id *id1, const struct m0_fi_fpoint_id *id2)
 
static struct m0_fi_fpoint_state__fi_state_find (const struct m0_fi_fpoint_id *fp_id)
 
static struct m0_fi_fpoint_statefi_state_find (struct m0_fi_fpoint_id *fp_id)
 
static struct m0_fi_fpoint_statefi_state_alloc (struct m0_fi_fpoint_id *id)
 
static bool fi_state_always (struct m0_fi_fpoint_state *fps)
 
static void fi_disable_state (struct m0_fi_fpoint_state *fps)
 
static bool fi_state_oneshot (struct m0_fi_fpoint_state *fps)
 
M0_INTERNAL uint32_t fi_random (void)
 
static bool fi_state_random (struct m0_fi_fpoint_state *fps)
 
static bool fi_state_off_n_on_m (struct m0_fi_fpoint_state *fps)
 
static bool fi_state_user_func (struct m0_fi_fpoint_state *fps)
 
M0_INTERNAL const char * m0_fi_fpoint_type_name (enum m0_fi_fpoint_type type)
 
M0_INTERNAL enum m0_fi_fpoint_type m0_fi_fpoint_type_from_str (const char *type_name)
 
static void fi_enable_state (struct m0_fi_fpoint_state *fp_state, const struct m0_fi_fpoint_data *fp_data)
 
void m0_fi_register (struct m0_fi_fault_point *fp)
 
bool m0_fi_enabled (struct m0_fi_fpoint_state *fps)
 
M0_INTERNAL void m0_fi_enable_generic (const char *fp_func, const char *fp_tag, const struct m0_fi_fpoint_data *fp_data)
 
M0_INTERNAL void m0_fi_disable (const char *fp_func, const char *fp_tag)
 

Variables

struct m0_fi_fpoint_state fi_states [FI_STATES_ARRAY_SIZE]
 
uint32_t fi_states_free_idx
 
struct m0_mutex fi_states_mutex
 
static struct m0_tl fi_dynamic_ids
 
const char * m0_fi_states_headline []
 
const char m0_fi_states_print_format []
 
static const char * fi_type_names [M0_FI_TYPES_NR]
 
static const fp_state_func_t fi_trigger_funcs [M0_FI_TYPES_NR]
 

Macro Definition Documentation

◆ M0_TRACE_SUBSYSTEM

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_LIB

Definition at line 41 of file finject.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FI_STATES_ARRAY_SIZE 

Definition at line 44 of file finject.c.

Function Documentation

◆ __fi_state_find()

static struct m0_fi_fpoint_state* __fi_state_find ( const struct m0_fi_fpoint_id fp_id)
static

Searches for m0_fi_fpoint_state structure in global fi_states array by fault point ID.

Parameters
fp_idPointer to fault point ID
Returns
Pointer to m0_fi_fpoint_state object, which has fps_id equal to the provided fp_id, if any
NULL, if no such state object exists

Definition at line 241 of file finject.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fi_disable_state()

static void fi_disable_state ( struct m0_fi_fpoint_state fps)
static

Helper function for m0_fi_disable()

Definition at line 411 of file finject.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fi_dynamic_ids_fini()

static void fi_dynamic_ids_fini ( void  )
static

Definition at line 187 of file finject.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fi_enable_state()

static void fi_enable_state ( struct m0_fi_fpoint_state fp_state,
const struct m0_fi_fpoint_data fp_data 
)
static

Helper function for m0_fi_enable_generic()

Definition at line 388 of file finject.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fi_fpoint_id_eq()

static bool fi_fpoint_id_eq ( const struct m0_fi_fpoint_id id1,
const struct m0_fi_fpoint_id id2 
)
inlinestatic

Checks equality of two fault point ids.

Parameters
id1Pointer to first ID
id2Pointer to second ID
Returns
true, if provided IDs are equal
false otherwise

Definition at line 223 of file finject.c.

Here is the caller graph for this function:

◆ fi_random()

M0_INTERNAL uint32_t fi_random ( void  )

Returns random value in range [0..FI_RAND_PROB_SCALE]

Definition at line 56 of file finject_init.c.

Here is the caller graph for this function:

◆ fi_state_alloc()

static struct m0_fi_fpoint_state* fi_state_alloc ( struct m0_fi_fpoint_id id)
static

"Allocates" and initializes state structure in fi_states array.

Definition at line 273 of file finject.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fi_state_always()

static bool fi_state_always ( struct m0_fi_fpoint_state fps)
static

Triggering algorithm for M0_FI_ALWAYS type

Definition at line 289 of file finject.c.

◆ fi_state_find()

static struct m0_fi_fpoint_state* fi_state_find ( struct m0_fi_fpoint_id fp_id)
inlinestatic

A wrapper around __fi_state_find(), which uses fi_states_mutex mutex to prevent potential changes of fi_states array from other threads.

See also
__fi_state_find()

Definition at line 259 of file finject.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fi_state_idx()

static uint32_t fi_state_idx ( const struct m0_fi_fpoint_state s)
inlinestatic

Definition at line 100 of file finject.c.

Here is the caller graph for this function:

◆ fi_state_info_init()

static void fi_state_info_init ( struct m0_fi_fpoint_state_info si)
static

Definition at line 105 of file finject.c.

Here is the caller graph for this function:

◆ fi_state_off_n_on_m()

static bool fi_state_off_n_on_m ( struct m0_fi_fpoint_state fps)
static

Triggering algorithm for M0_FI_OFF_N_ON_M type

Definition at line 318 of file finject.c.

Here is the call graph for this function:

◆ fi_state_oneshot()

static bool fi_state_oneshot ( struct m0_fi_fpoint_state fps)
static

Triggering algorithm for M0_FI_ONESHOT type

Definition at line 299 of file finject.c.

Here is the call graph for this function:

◆ fi_state_random()

static bool fi_state_random ( struct m0_fi_fpoint_state fps)
static

Triggering algorithm for M0_FI_RANDOM type

Definition at line 310 of file finject.c.

Here is the call graph for this function:

◆ fi_state_user_func()

static bool fi_state_user_func ( struct m0_fi_fpoint_state fps)
static

Triggering algorithm for M0_FI_FUNC type

Definition at line 343 of file finject.c.

◆ fi_states_fini()

M0_INTERNAL void fi_states_fini ( void  )

Definition at line 204 of file finject.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fi_states_init()

M0_INTERNAL void fi_states_init ( void  )

Definition at line 199 of file finject.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_fi_add_dyn_id()

M0_INTERNAL int m0_fi_add_dyn_id ( char *  str)

Add a dynamically allocated fault point ID string to persistent storage, which will be cleaned during m0_fi_fini() execution.

This function aimed to be used together with m0_fi_enable_xxx() functions.

Definition at line 171 of file finject.c.

Here is the call graph for this function:

◆ m0_fi_fpoint_type_name()

M0_INTERNAL const char* m0_fi_fpoint_type_name ( enum m0_fi_fpoint_type  type)

Returns the name of fault point type

Definition at line 357 of file finject.c.

Here is the caller graph for this function:

◆ m0_fi_states_get()

M0_INTERNAL const struct m0_fi_fpoint_state* m0_fi_states_get ( void  )

A read-only "getter" of global fi_states array, which stores all FP states.

The fi_states array is a private data of lib/finject.c and it should not be modified by external code. This function deliberately returns a const pointer to emphasize this. The main purpose of this function is to provide the FP states information to m0ctl driver, which displays it via debugfs.

Returns
A constant pointer to global fi_states array.

Definition at line 88 of file finject.c.

Here is the caller graph for this function:

◆ m0_fi_states_get_free_idx()

M0_INTERNAL uint32_t m0_fi_states_get_free_idx ( void  )

A read-only "getter" of global fi_states_free_idx index of fi_states array.

Returns
Current value of fi_states_free_idx variable.

Definition at line 94 of file finject.c.

Here is the caller graph for this function:

◆ m0_fi_states_get_state_info()

M0_INTERNAL void m0_fi_states_get_state_info ( const struct m0_fi_fpoint_state s,
struct m0_fi_fpoint_state_info si 
)

Fills m0_fi_fpoint_state_info structure.

Definition at line 123 of file finject.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ M0_TL_DEFINE()

M0_TL_DEFINE ( fi_dynamic_ids  ,
static  ,
struct fi_dynamic_id   
)

◆ M0_TL_DESCR_DEFINE()

M0_TL_DESCR_DEFINE ( fi_dynamic_ids  ,
"finject_dynamic_id"  ,
static  ,
struct fi_dynamic_id  ,
fdi_tlink  ,
fdi_magic  ,
M0_FI_DYNAMIC_ID_MAGIC  ,
M0_FI_DYNAMIC_ID_HEAD_MAGIC   
)

Variable Documentation

◆ fi_dynamic_ids

struct m0_tl fi_dynamic_ids
static

A storage for fault point ID strings, which are allocated dynamically in runtime.

Almost always ID string is a C string-literal with a static storage duration. But in some rare cases ID strings need to be allocated dynamically (for example when enabling FP via debugfs). To prevent memleaks in such cases, all dynamically allocated ID strings are stored in this linked list, using m0_fi_add_dyn_id(), which is cleaned in fi_states_fini().

Definition at line 74 of file finject.c.

◆ fi_states

Definition at line 48 of file finject.c.

◆ fi_states_free_idx

uint32_t fi_states_free_idx

Definition at line 49 of file finject.c.

◆ fi_states_mutex

struct m0_mutex fi_states_mutex

Definition at line 50 of file finject.c.

◆ fi_trigger_funcs

const fp_state_func_t fi_trigger_funcs[M0_FI_TYPES_NR]
static
Initial value:
= {
}
static bool fi_state_always(struct m0_fi_fpoint_state *fps)
Definition: finject.c:289
static bool fi_state_random(struct m0_fi_fpoint_state *fps)
Definition: finject.c:310
static bool fi_state_user_func(struct m0_fi_fpoint_state *fps)
Definition: finject.c:343
static bool fi_state_off_n_on_m(struct m0_fi_fpoint_state *fps)
Definition: finject.c:318
static bool fi_state_oneshot(struct m0_fi_fpoint_state *fps)
Definition: finject.c:299

Definition at line 377 of file finject.c.

◆ fi_type_names

const char* fi_type_names[M0_FI_TYPES_NR]
static
Initial value:
= {
[M0_FI_ALWAYS] = "always",
[M0_FI_ONESHOT] = "oneshot",
[M0_FI_RANDOM] = "random",
[M0_FI_OFF_N_ON_M] = "off_n_on_m",
[M0_FI_FUNC] = "user_func",
}

Definition at line 348 of file finject.c.

◆ m0_fi_states_headline

const char* m0_fi_states_headline[]
Initial value:
= {
" Idx | Enb |TotHits|TotTrig|Hits|Trig| Type | Data | Module | File name | Line | Func name | Tag\n",
"-----+-----+-------+-------+----+----+----------+----------+--------+----------------------------------------+------+-----------------------------------+----------\n",
}

Definition at line 77 of file finject.c.

◆ m0_fi_states_print_format

const char m0_fi_states_print_format[]
Initial value:
=
" %-3u %c %-7u %-7u %-4u %-4u %-10s %-10s %-8s %-40s %-4u %-35s %s\n"

Definition at line 83 of file finject.c.