RAS daemon internal API¶
Environment and common types¶
-
static void ras_trim(char *s, bool remove_commas)¶
trim leading and trailing whitespace in-place
Parameters
char *sstring to trim
bool remove_commasremove a pair of surrounding double quotes when true
-
int ras_set_env(const char *fname)¶
parse a configuration file and set environment variables
Parameters
const char *fnamepath to the configuration file
Description
The accepted format is KEY=value. Empty lines and lines starting with
# or ; are ignored. Spaces and tabs are allowed around keys and
values. Existing environment variables are left unchanged.
Return
0 - the configuration file was processed
-1 - the file could not be opened or a line had an empty key
-
ARRAY_SIZE¶
ARRAY_SIZE (arr)
get the number of elements in array arr
Parameters
arrarray to be sized
-
static inline size_t strscpy(char *dst, const char *src, size_t dsize)¶
safe implementation of strcpy, with a buffer size
Parameters
char *dstdestination buffer
const char *srcsource buffer
size_t dsizesize of the destination buffer
Description
Copy string up to dsize-1 characters. String will end with a ‘0’ character at the end.
Return
number of copied non-null characters - src and its null byte fit in dst
(size_t)-E2BIG- src did not fit in dsize bytes
-
static inline size_t strscat(char *dst, const char *src, size_t dsize)¶
safe implementation of strcat, with a buffer size
Parameters
char *dstdestination buffer
const char *srcsource buffer
size_t dsizesize of the destination buffer
Description
Append string until dst is up to dsize-1 characters. String will end with a ‘0’ character at the end.
Return
resulting string length - src, including its null byte, fit in dst
(size_t)-E2BIG- the concatenated string did not fit in dsize bytes
-
container_of¶
container_of (ptr, type, member)
cast a member of a structure out to the containing structure
Parameters
ptrthe pointer to the member.
typethe type of the container struct this is embedded in.
memberthe name of the member within the struct.
Description
WARNING: any const qualifier of ptr is lost.
-
const char *ras_uuid_str(const char *uuid, enum ras_uuid_byte_order order)¶
format a binary UUID
Parameters
const char *uuid16-byte UUID
enum ras_uuid_byte_order orderbyte order of the UUID fields
Return
a pointer to a static 36-character UUID string. The returned buffer is overwritten by the next call.
-
loglevel_str¶
const char *loglevel_str[] = { [LOGLEVEL_EMERG] = "[EMERG]", [LOGLEVEL_ALERT] = "[ALERT]", [LOGLEVEL_CRIT] = "[CRIT]", [LOGLEVEL_ERR] = "[ERROR]", [LOGLEVEL_WARNING] = "[WARNING]", [LOGLEVEL_NOTICE] = "[NOTICE]", [LOGLEVEL_INFO] = "[INFO]", [LOGLEVEL_DEBUG] = "[DEBUG]", };display labels indexed by rasdaemon log severity
Initialization
default:
{ [LOGLEVEL_EMERG] = "[EMERG]", [LOGLEVEL_ALERT] = "[ALERT]", [LOGLEVEL_CRIT] = "[CRIT]", [LOGLEVEL_ERR] = "[ERROR]", [LOGLEVEL_WARNING] = "[WARNING]", [LOGLEVEL_NOTICE] = "[NOTICE]", [LOGLEVEL_INFO] = "[INFO]", [LOGLEVEL_DEBUG] = "[DEBUG]", };
Module and event registries¶
-
enum init_level¶
module initialization and cleanup order
Constants
DB_MODULEdatabase backends
BASE_EVENT_MODULEbase event decoders and table owners
SUB_EVENT_MODULEdecoders which depend on base event modules
ACTIONS_MODULEconsumers of decoded events
ACTIONS_SUB_MODULEconsumer modules that depend on a base consumer
MAX_LEVELSnumber of initialization levels
Description
Initialization proceeds from DB_MODULE to ACTIONS_MODULE. Process-wide cleanup visits the levels in reverse order.
-
struct ras_module_entry¶
immutable module registration descriptor
Definition:
struct ras_module_entry { const char *name; enum init_level level; int (*init)(struct ras_module_ctx *ctx); void (*cleanup)(struct ras_module_ctx *ctx); };
Members
nameunique module name
levelinitialization level
initoptional initialization callback
cleanupoptional cleanup callback
Description
The descriptor must have static lifetime. On a successful init, cleanup receives the same context and must release all module-owned resources.
-
struct ras_module_ctx¶
runtime context owned by the module registry
Definition:
struct ras_module_ctx { const struct ras_module_entry *entry; struct ras_events *ras; void *priv; };
Members
entrystatic module descriptor
rasevent-loop context supplied during initialization
privmodule-private state managed by the callbacks
-
enum test_group¶
independently selectable unit-test families
Constants
TEST_GROUP_COREgeneric core tests
TEST_GROUP_EVENTSarchitecture-independent event tests
TEST_GROUP_X86_EVENTSx86 event tests
TEST_GROUP_ARM_EVENTSArm event tests
TEST_GROUP_RISCV_EVENTSRISC-V event tests
TEST_GROUP_ACTIONSevent-consumer tests
TEST_GROUP_DATABASEgeneric database tests
TEST_GROUP_DB_SQLITE3SQLite tests
TEST_GROUP_DB_MYSQLMySQL/MariaDB tests
TEST_GROUP_DB_POSTGRESQLPostgreSQL tests
TEST_GROUP_MODULESmodule-registry tests
TEST_GROUP_MAXnumber of test groups
-
struct ras_module_entry_runtime¶
mutable state for a registered module
Definition:
struct ras_module_entry_runtime { struct ras_module_ctx ctx; bool is_enabled; LIST_ENTRY(ras_module_entry_runtime) node; };
Members
ctxcallback context
is_enabledwhether initialization completed successfully
nodelink in ras_modules
-
ras_modules¶
static struct module_list ras_modules = LIST_HEAD_INITIALIZER(ras_modules);registered modules sorted by name
Initialization
default:
LIST_HEAD_INITIALIZER(ras_modules);
-
struct module_test_runtime¶
one registered unit-test callback
Definition:
struct module_test_runtime { enum test_group group; int (*run)(void); unsigned int priority; LIST_ENTRY(module_test_runtime) node; };
Members
groupselectable test family
runcallback returning zero on success
priorityascending execution order
nodelink in module_tests
-
module_tests¶
static struct module_test_list module_tests = LIST_HEAD_INITIALIZER(module_tests);registered unit tests sorted by priority
Initialization
default:
LIST_HEAD_INITIALIZER(module_tests);
-
static void module_tests_unregister(void)¶
release unit-test registry wrappers at exit
Parameters
voidno arguments
-
int module_register(const struct ras_module_entry *entry)¶
register a static module descriptor
Parameters
const struct ras_module_entry *entrydescriptor which remains valid for the process lifetime
Description
Registration is constructor-safe but not thread-safe. Entries are kept in name order, and duplicate names are rejected.
Return
0 - the module was registered
-EINVAL - entry or its name is NULL
-EEXIST - the module name is already registered
-ENOMEM - wrapper allocation or exit-handler registration failed
-
bool modules_have_sql_backend(void)¶
test whether a database module is active
Parameters
voidno arguments
Return
true if an enabled module has level DB_MODULE.
-
void modules_cleanup_type(enum init_level level)¶
clean all active modules at one level
Parameters
enum init_level levellevel to clean
Description
Cleanup callbacks run in module-name order. Context pointers are cleared after each callback, allowing the module to be initialized again.
-
static void cleanup_modules(void)¶
clean all module levels in reverse order
Parameters
voidno arguments
-
int module_init(struct ras_events *ras, const char *name)¶
initialize one named module
Parameters
struct ras_events *rasevent-loop context, possibly NULL in isolated tests
const char *nameregistered module name
Return
0 - the module initialized successfully or was already active
-EINVAL - name is NULL
-ENOENT - name is not registered
otherwise - the module initialization callback’s error
-
int module_cleanup(const char *name)¶
clean one active named module
Parameters
const char *nameregistered module name
Return
0 - the active module was cleaned
-EINVAL - name is NULL
-ENOENT - no active module has name
-
int modules_init(struct ras_events *ras)¶
initialize every registered module in level order
Parameters
struct ras_events *rasevent-loop context shared with module callbacks
Description
A failing module is left disabled while initialization continues. Already active modules are skipped.
Return
always 0; individual module failures are logged.
-
bool module_is_enabled(const char *name)¶
query a module’s runtime state
Parameters
const char *namemodule name
Return
true if the named module is registered and active.
-
bool module_is_registered(const char *name)¶
query whether a module name exists
Parameters
const char *namemodule name
Return
true if registered; false for NULL or an unknown name.
-
void modules_unregister(void)¶
clean modules and release registry wrappers
Parameters
voidno arguments
Description
Called automatically at process exit. Static descriptors are not freed.
-
int module_test_register(enum test_group group, int (*run)(void), unsigned int priority)¶
add a unit-test callback
Parameters
enum test_group grouptest family
int (*run)(void)callback returning zero on success
unsigned int priorityascending order within the registry
Return
0 - the callback was registered
-EINVAL - group or run is invalid
-EEXIST - run is already registered
-ENOMEM - exit-handler registration or wrapper allocation failed
-
bool module_test_group_is_registered(enum test_group group)¶
test whether a group has callbacks
Parameters
enum test_group groupgroup to query
Return
true when at least one callback belongs to group.
-
int module_test_group_run(enum test_group group)¶
execute all callbacks in a test group
Parameters
enum test_group groupgroup to run
Return
number of callbacks which reported failure.
-
struct ras_module_ctx *module_test_context(const char *name)¶
expose a module context to unit tests
Parameters
const char *nameregistered module name
Return
registry-owned context, or NULL for NULL/unknown names.
-
enum ras_event_id¶
decoded event payload types
Constants
MC_EVENTmemory-controller event
MCE_EVENTx86 machine-check event
AER_EVENTPCIe AER event
NON_STANDARD_EVENTnon-standard CPER event
ARM_EVENTArm processor error event
EXTLOG_EVENTextended machine-check log event
DEVLINK_EVENTdevlink health event
DISKERROR_EVENTblock I/O error event
MF_EVENTmemory-failure event
SIGNAL_EVENTfatal-signal event
CXL_POISON_EVENTCXL poison-list event
CXL_AER_UE_EVENTCXL uncorrectable AER event
CXL_AER_CE_EVENTCXL correctable AER event
CXL_OVERFLOW_EVENTCXL overflow event
CXL_GENERIC_EVENTgeneric CXL event
CXL_GENERAL_MEDIA_EVENTCXL general-media event
CXL_DRAM_EVENTCXL DRAM event
CXL_MEMORY_MODULE_EVENTCXL memory-module event
CXL_MEMORY_SPARING_EVENTCXL memory-sparing event
RERI_EVENTRISC-V RERI event
NR_EVENTSnumber of event identifiers
-
record_function¶
Typedef: persist one decoded event
Syntax
int record_function (struct ras_events *ras, void *event)
Parameters
struct ras_events *rasevent-loop and database context
void *eventconcrete payload selected by the event descriptor
Return
0 on success or the recorder/backend-specific nonzero error on failure.
-
enum ras_event_consumer_priority¶
event-consumer delivery order
Constants
PRI_CPU_ISOLATIONCPU offlining/isolation actions
PRI_MEM_ISOLATIONpage and row isolation actions
PRI_POISON_PAGEpoison-page accounting
PRI_PLATFORM_ACTIONplatform-specific actions
PRI_REPORTINGexternal reporting
PRI_DB_RECORDdatabase persistence
PRI_NORMALconsumers without ordering constraints
-
struct ras_event_consumer¶
immutable decoded-event consumer
Definition:
struct ras_event_consumer { const char *name; enum ras_event_consumer_priority priority; uint64_t events; int (*consume)(struct ras_events *ras, int event, void *data); };
Members
nameunique diagnostic name and equal-priority ordering key
prioritydelivery priority
eventsbitmap of accepted enum ras_event_id values
consumesynchronous callback; the publisher retains payload ownership
-
struct ras_event_entry¶
immutable trace-event registration descriptor
Definition:
struct ras_event_entry { const char *group; const char *event; tep_event_handler_func handler; const char *filter; const char *(*filter_cb)(struct ras_events *ras); int (*prepare)(struct ras_events *ras); void (*enabled)(struct ras_events *ras); void (*trigger_setup)(void); int id; int order; record_function record; #ifdef HAVE_UNITTEST; enum test_group test_group; int (*test)(void); unsigned int test_priority; #endif; };
Members
grouptrace-event subsystem name
eventtrace-event name
handlerlibtraceevent callback
filterfixed kernel filter string, or NULL
filter_cboptional callback producing a kernel filter string
prepareoptional per-event preparation callback
enabledoptional callback after successful event enablement
trigger_setupoptional trace-trigger configuration callback
iddecoded enum ras_event_id
orderascending handler registration order
recordoptional database recorder
test_groupunit-test family when unit tests are enabled
testoptional unit-test callback
test_priorityascending test execution order
Description
Descriptors have static lifetime. Callback resources are owned by their module and must remain valid until ras_events_cleanup().
-
struct ras_events¶
process-wide tracing and database state
Definition:
struct ras_events { char tracing[MAX_PATH + 1]; struct tep_handle *pevent; int page_size; unsigned use_uptime: 1; unsigned record_events: 1; time_t uptime_diff; struct ras_db *db; void *db_priv; int db_ref_count; unsigned int num_events; pthread_mutex_t db_lock; struct mce_priv *mce_priv; int socketfd; int daemon_active_fd; struct tep_event_filter *filters[NR_EVENTS]; };
Members
tracingmounted tracefs/debugfs tracing directory
peventshared trace-event parser
page_sizekernel tracing page size
use_uptimetimestamps use uptime rather than wall clock
record_eventsdatabase recording is requested
uptime_diffwall-clock offset from monotonic uptime
dbactive backend connection
db_privbackend-private per-session data
db_ref_countnumber of matching db_open() references
num_eventsnumber of decoded events
db_lockserializes legacy per-CPU database recorder access
mce_privx86 MCE decoder state
socketfdABRT reporting socket
daemon_active_fdlock file descriptor proving daemon ownership
filtersinstalled filters indexed by enum ras_event_id
-
struct pthread_data¶
state for one legacy per-CPU reader thread
Definition:
struct pthread_data { pthread_t thread; struct tep_handle *pevent; struct ras_events *ras; int cpu; };
Members
threadPOSIX thread identifier
peventthread-local event parser
rasshared process context
cpulogical CPU read by this thread
-
enum hw_event_mc_err_type¶
memory-controller error classifications
Constants
HW_EVENT_ERR_CORRECTEDcorrected error
HW_EVENT_ERR_UNCORRECTEDuncorrected non-fatal error
HW_EVENT_ERR_DEFERREDdeferred error
HW_EVENT_ERR_FATALfatal error
HW_EVENT_ERR_INFOinformational event
-
enum hw_event_aer_err_type¶
PCIe AER classifications
Constants
HW_EVENT_AER_UNCORRECTED_NON_FATALuncorrectable non-fatal event
HW_EVENT_AER_UNCORRECTED_FATALuncorrectable fatal event
HW_EVENT_AER_CORRECTEDcorrected event
-
enum ghes_severity¶
ACPI GHES severity values
Constants
GHES_SEV_NOno severity
GHES_SEV_CORRECTEDcorrected error
GHES_SEV_RECOVERABLErecoverable error
GHES_SEV_PANICfatal error
-
struct ras_event_consumer_runtime¶
registry wrapper for a consumer
Definition:
struct ras_event_consumer_runtime { const struct ras_event_consumer *consumer; LIST_ENTRY(ras_event_consumer_runtime) node; };
Members
consumerstatic consumer descriptor
nodelink in event_consumers
-
event_consumers¶
static struct ras_event_consumer_list event_consumers = LIST_HEAD_INITIALIZER(event_consumers);consumers ordered by priority and name
Initialization
default:
LIST_HEAD_INITIALIZER(event_consumers);
-
static void ras_event_consumers_unregister(void)¶
free registry wrappers at process exit
Parameters
voidno arguments
-
int ras_event_consumer_register(const struct ras_event_consumer *consumer)¶
register an immutable event consumer
Parameters
const struct ras_event_consumer *consumerstatic descriptor
Description
Registration occurs during constructors and is not thread-safe. Consumers are ordered by ascending priority and then name.
Return
0 - the consumer was registered
-EINVAL - consumer or one of its required fields is invalid
-EEXIST - its descriptor or name is already registered
-ENOMEM - wrapper allocation or exit-handler registration failed
-
int ras_event_consumer_unregister(const struct ras_event_consumer *consumer)¶
remove a registered consumer
Parameters
const struct ras_event_consumer *consumerdescriptor previously passed to ras_event_consumer_register()
Return
0 - the consumer was unregistered
-EINVAL - consumer is NULL
-ENOENT - consumer is not registered
-
int ras_event_publish(struct ras_events *ras, int event, void *data)¶
synchronously deliver a decoded event
Parameters
struct ras_events *rasevent-loop context
int eventevent identifier from enum ras_event_id
void *datapublisher-owned event payload
Description
Every interested consumer runs even if an earlier consumer fails. data is valid only for the duration of this call. Callers must serialize publishing if a consumer requires it.
Return
0 - every interested consumer succeeded
-EINVAL - ras, data, or event is invalid
otherwise - the first consumer error in delivery order
-
choices_disable¶
char *choices_disable;comma/space-separated events disabled by config
-
user_hz¶
long user_hz;userspace clock ticks per second
-
struct ras_event_runtime¶
registry wrapper for an event descriptor
Definition:
struct ras_event_runtime { const struct ras_event_entry *entry; LIST_ENTRY(ras_event_runtime) node; };
Members
entrystatic event descriptor
nodelink in ras_event_handlers
-
ras_event_handlers¶
static struct ras_event_list ras_event_handlers = LIST_HEAD_INITIALIZER(ras_event_handlers);event descriptors in preparation order
Initialization
default:
LIST_HEAD_INITIALIZER(ras_event_handlers);
-
static int get_mountdir_by_type(char *mount_type, char *tracing_dir, size_t len)¶
find a mounted filesystem by type
Parameters
char *mount_typefilesystem type from /proc/mounts
char *tracing_dirdestination for the mount path
size_t lensize of tracing_dir
Return
0 - a matching mount was found and copied to tracing_dir
-ENOENT - no mount has mount_type
otherwise - a negative errno value from opening /proc/mounts
-
static int get_debugfs_dir(char *tracing_dir, size_t len)¶
locate the debugfs mount
Parameters
char *tracing_dirdestination path
size_t lendestination size
Return
0 on success or a negative errno value from get_mountdir_by_type().
-
static int get_tracefs_dir(char *tracing_dir, size_t len)¶
locate the tracefs mount
Parameters
char *tracing_dirdestination path
size_t lendestination size
Return
0 on success or a negative errno value from get_mountdir_by_type().
-
static int wait_access(char *path, int ms)¶
wait for a tracefs node to appear
Parameters
char *pathnode path
int msmaximum wait in milliseconds
Return
0 - path became accessible
-1 - the timeout expired
-
static int open_trace(struct ras_events *ras, char *name, int flags)¶
open a node relative to the tracing directory
Parameters
struct ras_events *rasinitialized tracing context
char *namerelative tracefs path
int flagsopen(2) flags
Return
nonnegative - an open file descriptor
-E2BIG - the constructed path did not fit
-1 - the trace node did not appear before the timeout
otherwise - a negative errno value from open(2)
-
static int get_tracing_dir(struct ras_events *ras)¶
locate or create rasdaemon’s tracing instance
Parameters
struct ras_events *rascontext receiving the path
Description
Prefers tracefs and falls back to debugfs/tracing. When trace instances are
supported, creates or reuses the rasdaemon instance.
Return
0 - ras->tracing contains the usable tracing directory
-E2BIG - the constructed path did not fit
-EINVAL - the directory could not be opened or the instance created
otherwise - a negative mount-discovery error
-
static bool is_disabled_event(const char *group, const char *event)¶
check the configured trace-event deny list
Parameters
const char *grouptrace subsystem
const char *eventtrace event name
Return
true if the exact group:event name is disabled.
-
bool ras_events_test_is_disabled(const char *group, const char *event)¶
unit-test access to is_disabled_event()
Parameters
const char *grouptrace subsystem
const char *eventtrace event name
Return
true if disabled by choices_disable.
-
static int __toggle_ras_mc_event(struct ras_events *ras, const char *group, const char *event, int enable)¶
enable or disable one kernel trace event
Parameters
struct ras_events *rastracing context
const char *grouptrace subsystem
const char *eventtrace event name
int enablenonzero to enable unless configured disabled
Return
0 - the event state was written successfully
-EIO - write(2) reported that no bytes were written
otherwise - a negative/open failure or the write(2) failure value
-
int toggle_ras_mc_event(int enable)¶
toggle every registered RAS trace event
Parameters
int enablenonzero to enable events, zero to disable them
Return
0 - every registered event was toggled
-EINVAL - tracing setup or at least one event toggle failed
otherwise - the negative allocation errno from calloc(3)
-
static int filter_ras_mc_event(struct ras_events *ras, const char *group, const char *event, const char *filter_str)¶
install a kernel-side trace-event filter
Parameters
struct ras_events *rastracing context
const char *grouptrace subsystem
const char *eventtrace event name
const char *filter_strkernel filter expression
Return
0 - the filter was written successfully
-EIO - write(2) reported that no bytes were written
otherwise - a negative/open failure or the write(2) failure value
-
int ras_event_filter(struct ras_events *ras, const char *group, const char *event, const char *filter)¶
install a kernel filter for a registered event
Parameters
struct ras_events *rastracing context
const char *grouptrace subsystem
const char *eventtrace event name
const char *filterkernel filter expression
Return
the result of installing filter through filter_ras_mc_event().
-
static int get_pagesize(struct ras_events *ras, struct tep_handle *pevent)¶
parse the trace ring-buffer page header
Parameters
struct ras_events *rastracing context
struct tep_handle *peventevent parser receiving header metadata
Return
4096, after parsing the page header when it is available.
-
static void parse_ras_data(struct pthread_data *pdata, struct kbuffer *kbuf, void *data, unsigned long long time_stamp)¶
dispatch one raw ring-buffer record
Parameters
struct pthread_data *pdatareader state
struct kbuffer *kbufloaded kernel ring buffer
void *datacurrent record payload
unsigned long long time_stamprecord timestamp
-
static int get_num_cpus(struct ras_events *ras)¶
obtain the number of online logical CPUs
Parameters
struct ras_events *rastracing context (unused)
Return
the positive number of online logical CPUs. Failure triggers an assertion.
-
static int set_buffer_percent(struct ras_events *ras, int percent)¶
configure the trace-buffer poll wake threshold
Parameters
struct ras_events *rastracing context
int percentpercentage written to tracefs
Return
0 - the percentage was written
-EINVAL - the node could not be opened or written
-
static int read_ras_event_all_cpus(struct pthread_data *pdata, unsigned int n_cpus)¶
poll all per-CPU trace pipes in one thread
Parameters
struct pthread_data *pdataarray containing at least n_cpus reader contexts
unsigned int n_cpusnumber of CPU pipes
Description
SIGINT, SIGTERM, SIGHUP, and SIGQUIT are blocked while polling and restored before return. All file descriptors and buffers are released on every path.
Return
0 - an expected shutdown signal was received
LEGACY_KERNEL - polling appears unsupported and callers should fall back
-ENOMEM - a page or kernel-buffer decoder could not be allocated
-EINVAL - a polling, read, or setup failure occurred
-
static int read_ras_event(int fd, struct pthread_data *pdata, struct kbuffer *kbuf, void *page)¶
read one legacy per-CPU trace pipe indefinitely
Parameters
int fdtrace_pipe_raw descriptor
struct pthread_data *pdataCPU reader state
struct kbuffer *kbufreusable kernel-buffer decoder
void *pagereusable page-sized input buffer
Description
Cancellation is disabled while the shared database lock is held.
Return
-EINVAL on read failure; otherwise the loop does not return.
-
struct reader_cleanup¶
cancellation-owned per-CPU reader resources
Definition:
struct reader_cleanup { struct pthread_data *pdata; struct kbuffer *kbuf; void *page; int fd; };
Members
pdatareader state
kbufkernel-buffer decoder
pageraw input allocation
fdtrace pipe descriptor
-
static void cleanup_ras_events_cpu(void *arg)¶
pthread cleanup handler for a CPU reader
Parameters
void *argstruct reader_cleanup pointer
-
static void *handle_ras_events_cpu(void *priv)¶
legacy reader thread entry point
Parameters
void *privstruct pthread_data pointer
Return
always NULL after its cleanup handler releases reader resources.
-
static int select_tracing_timestamp(struct ras_events *ras)¶
prefer the trace uptime clock
Parameters
struct ras_events *rascontext receiving clock-selection state
Description
Unsupported or unwritable uptime clocks are nonfatal and retain the kernel default. /proc/uptime is used to compute the wall-clock offset.
Return
0 - uptime was selected or the kernel clock was retained as a fallback
-EINVAL - trace_clock could not be opened/read or clock data was malformed
-
static bool check_event_exist(struct ras_events *ras, const char *group, const char *event)¶
test for an event directory in tracefs
Parameters
struct ras_events *rastracing context
const char *grouptrace subsystem
const char *eventtrace event name
Return
true when the directory exists.
-
static void ras_events_unregister(void)¶
release event-registry wrappers at process exit
Parameters
voidno arguments
-
int ras_event_record(struct ras_events *ras, int event_id, void *data)¶
invoke the recorder registered for an event type
Parameters
struct ras_events *rasevent/database context
int event_idenum ras_event_id
void *dataconcrete event payload
Return
0 - a matching event has no recorder or its recorder succeeded
-EINVAL - ras, data, or event_id is invalid
-ENOENT - no registered descriptor has event_id
otherwise - the matching recorder’s error
-
static const struct ras_event_entry *ras_event_test_find(const char *group, const char *name)¶
locate an event descriptor for unit tests
Parameters
const char *grouptrace subsystem
const char *nametrace event name
Return
registry-owned descriptor or NULL.
-
tep_event_handler_func ras_event_test_handler(const char *group, const char *event)¶
resolve a registered trace callback for tests
Parameters
const char *grouptrace subsystem
const char *eventtrace event name
Return
handler callback or NULL when not registered.
-
int ras_event_register(const struct ras_event_entry *entry)¶
register a static trace-event descriptor
Parameters
const struct ras_event_entry *entrydescriptor with process lifetime
Description
Entries are sorted by ras_event_entry.order, group, and event. Registration is constructor-safe but not thread-safe. Associated tests are registered as part of the same operation.
Return
0 - the event and any associated test were registered
-EINVAL - entry or one of its required fields is invalid
-EEXIST - its trace pair or associated test callback is already registered
-ENOMEM - wrapper allocation or exit-handler registration failed
otherwise - the associated test-registration error
-
static int add_event_handler(struct ras_events *ras, struct tep_handle *pevent, unsigned int page_size, const char *group, const char *event, tep_event_handler_func func, const char *filter_str, int id)¶
parse, register, filter, and enable one trace event
Parameters
struct ras_events *rastracing context
struct tep_handle *peventevent parser
unsigned int page_sizeinitial format-read allocation size
const char *grouptrace subsystem
const char *eventtrace event name
tep_event_handler_func funclibtraceevent callback
const char *filter_stroptional userspace filter expression
int idenum ras_event_id used to store the allocated filter
Return
0 - the handler was registered and its trace event enabled
EVENT_DISABLED - its format node is absent or it is configured off
-EOVERFLOW - the dynamically grown format buffer would overflow
otherwise - a negative discovery, I/O, parsing, filter, or enable error
Description
A filter stored in ras is freed by ras_events_cleanup().
-
int ras_events_prepare(struct ras_events *ras, int record_events)¶
initialize tracing and all registered event handlers
Parameters
struct ras_events *raszero-initialized process context
int record_eventsenable database recording consumers
Description
The caller owns ras and must call ras_events_cleanup() after a successful call, including if a later database/module initialization step fails. Individual unsupported events are logged and skipped.
Return
0 - basic preparation completed; unsupported individual events were skipped
otherwise - a negative tracing-setup or parser-allocation error
-
void ras_events_cleanup(struct ras_events *ras)¶
release resources allocated during event preparation
Parameters
struct ras_events *rasprocess context, or NULL
Description
The operation is idempotent after initialization and clears owned pointers. It does not free ras or clean module-owned resources.
-
int handle_ras_events(struct ras_events *ras)¶
run the trace reader until shutdown or failure
Parameters
struct ras_events *rassuccessfully prepared event context
Description
Modern kernels use a single polling reader. Kernels without working poll support fall back to one cancellable thread per CPU; handler/database access is serialized in that mode. This function always calls ras_events_cleanup() before returning.
Return
0 - polling stopped due to an expected shutdown signal
-EINVAL - ras is invalid, no events were enabled, or polling failed
-ENOMEM - per-CPU reader state could not be allocated
LEGACY_KERNEL - all fallback reader threads exited without setup failure
otherwise - a negated pthread initialization or creation error
Core utilities¶
-
struct field¶
decode an indexed bit field
Definition:
struct field { unsigned int start_bit; char **str; unsigned int stringlen; };
Members
start_bitleast-significant bit of the field
strstrings indexed by the decoded value
stringlennumber of entries in str
-
struct numfield¶
decode a numeric bit field
Definition:
struct numfield { unsigned int start, end; char *name; char *fmt; int force; };
Members
startleast-significant bit of the field
endmost-significant bit of the field
namelabel written before the value
fmtprintf format for the value
forceemit the field even when its value is zero
-
static inline int test_prefix(int nr, uint32_t value)¶
test whether a value has a unary prefix
Parameters
int nrnumber of low-order bits below the prefix
uint32_t valuevalue to inspect
Return
nonzero when shifting value by nr produces one.
-
unsigned int bitfield_msg(char *buf, size_t len, const char *const *bitarray, unsigned int array_len, unsigned int bit_offset, unsigned int ignore_bits, uint64_t status)¶
format the names of set bits
Parameters
char *bufdestination buffer
size_t lensize of buf
const char * const *bitarrayarray mapping bit positions to names
unsigned int array_lennumber of entries in bitarray
unsigned int bit_offsetposition of the first described bit in status
unsigned int ignore_bitsmask which suppresses output when any masked bit is set
uint64_t statusvalue to decode
Description
Unknown set bits are formatted as BITn. Output is truncated before a
name which does not fit, and buf is always terminated when len is nonzero.
Return
number of bytes written, excluding the terminating null byte.
-
static uint64_t bitmask(uint64_t i)¶
produce a mask covering a zero-based maximum value
Parameters
uint64_t imaximum value to represent
Return
the smallest all-ones mask greater than or equal to i.
-
void decode_bitfield(struct mce_event *e, uint64_t status, struct field *fields)¶
append decoded symbolic fields to an MCE event
Parameters
struct mce_event *eevent receiving decoded messages
uint64_t statusmachine-check status value
struct field *fieldsnull-terminated field description array
-
void decode_numfield(struct mce_event *e, uint64_t status, struct numfield *fields)¶
append decoded numeric fields to an MCE event
Parameters
struct mce_event *eevent receiving decoded messages
uint64_t statusmachine-check status value
struct numfield *fieldsnull-terminated numeric field description array
-
struct queue_node¶
one time-stamped queue entry
Definition:
struct queue_node { time_t time; unsigned int value; struct queue_node *next; };
Members
timeentry timestamp
valuecaller-owned numeric value
nextnext entry, or NULL at the tail
-
struct link_queue¶
FIFO queue of struct queue_node objects
Definition:
struct link_queue { struct queue_node *head; struct queue_node *tail; int size; };
Members
headfirst entry, or NULL when empty
taillast entry, or NULL when empty
sizecurrent number of entries
-
int is_empty(struct link_queue *queue)¶
test whether a queue has no entries
Parameters
struct link_queue *queuequeue to inspect, or NULL
Return
nonzero when queue is NULL or empty.
-
struct link_queue *init_queue(void)¶
allocate an empty queue
Parameters
voidno arguments
Return
a queue owned by the caller, or NULL on allocation failure.
-
void clear_queue(struct link_queue *queue)¶
free every node in a queue
Parameters
struct link_queue *queuequeue to empty, or NULL
Description
The queue object remains valid and can be reused.
-
void free_queue(struct link_queue *queue)¶
destroy a queue and all its nodes
Parameters
struct link_queue *queuequeue to destroy, or NULL
-
void push(struct link_queue *queue, struct queue_node *node)¶
append a node to a queue
Parameters
struct link_queue *queuevalid queue
struct queue_node *nodedetached node whose ownership transfers to queue
Description
Both arguments must be non-NULL.
-
int pop(struct link_queue *queue)¶
remove and free the first queue node
Parameters
struct link_queue *queuequeue to modify
Return
0 - the first node was removed and freed
-1 - queue is NULL or empty
-
struct queue_node *front(struct link_queue *queue)¶
obtain the first queue node without removing it
Parameters
struct link_queue *queuequeue to inspect
Return
a queue-owned node, or NULL if queue is NULL or empty.
-
struct queue_node *node_create(time_t time, unsigned int value)¶
allocate a detached queue node
Parameters
time_t timetimestamp stored in the node
unsigned int valuenumeric value stored in the node
Return
a caller-owned node, or NULL on allocation failure.
-
struct rb_node¶
intrusive red-black tree node
Definition:
struct rb_node { unsigned long rb_parent_color; #define RB_RED 0; #define RB_BLACK 1; struct rb_node *rb_right; struct rb_node *rb_left; };
Members
rb_parent_colorpacked parent pointer and color bits
rb_rightright child
rb_leftleft child
-
struct rb_root¶
red-black tree root
Definition:
struct rb_root { struct rb_node *rb_node; };
Members
rb_noderoot node, or NULL for an empty tree
-
static inline void rb_set_parent(struct rb_node *rb, struct rb_node *p)¶
update a node’s parent without changing its color
Parameters
struct rb_node *rbnode to update
struct rb_node *pnew parent, or NULL
-
static inline void rb_set_color(struct rb_node *rb, int color)¶
update a node’s color without changing its parent
Parameters
struct rb_node *rbnode to update
int colorRB_RED or RB_BLACK
-
static inline void rb_link_node(struct rb_node *node, struct rb_node *parent, struct rb_node **rb_link)¶
attach an unbalanced red-black tree leaf
Parameters
struct rb_node *nodedetached node to initialize
struct rb_node *parentparent selected by the caller’s ordered search
struct rb_node **rb_linkchild link in parent, or root link, receiving node
Description
Call rb_insert_color() after linking to restore tree invariants.
-
static void __rb_rotate_left(struct rb_node *node, struct rb_root *root)¶
rotate a subtree left during rebalancing
Parameters
struct rb_node *nodesubtree root
struct rb_root *roottree root
-
static void __rb_rotate_right(struct rb_node *node, struct rb_root *root)¶
rotate a subtree right during rebalancing
Parameters
struct rb_node *nodesubtree root
struct rb_root *roottree root
Parameters
struct rb_node *nodenode previously attached with rb_link_node()
struct rb_root *roottree root
-
static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, struct rb_root *root)¶
restore red-black invariants after deletion
Parameters
struct rb_node *nodereplacement child, possibly NULL
struct rb_node *parentparent of node
struct rb_root *roottree root
Parameters
struct rb_node *nodelinked node to remove
struct rb_root *roottree root
Description
The caller retains ownership of node.
Parameters
const struct rb_root *roottree root
Return
first node, or NULL when empty.
Parameters
const struct rb_root *roottree root
Return
last node, or NULL when empty.
Parameters
const struct rb_node *nodelinked tree node
Return
next node, or NULL at the end/detached marker.
Parameters
const struct rb_node *nodelinked tree node
Return
previous node, or NULL at the beginning/detached marker.
-
void rb_replace_node(struct rb_node *victim, struct rb_node *new, struct rb_root *root)¶
replace a node without rebalancing
Parameters
struct rb_node *victimlinked node to replace
struct rb_node *newdetached replacement node
struct rb_root *roottree root
Description
The replacement inherits all links and color. The caller retains victim.
-
stdout_is_vt¶
static bool stdout_is_vt = false;whether standard output is attached to a terminal
Initialization
default:
false;
-
mock_output¶
bool mock_output = false;redirect log output to the in-memory test buffer
Initialization
default:
false;
-
mock_log_buf¶
char *mock_log_buf = NULL;dynamically allocated test log buffer
Initialization
default:
NULL;
-
mock_log_len¶
size_t mock_log_len = 0;number of bytes stored in mock_log_buf
Initialization
default:
0;
-
reset_color¶
const char *reset_color = "";terminal escape used to reset log colors
Initialization
default:
"";
-
void ras_logger_clean(void)¶
release the in-memory test log buffer
Parameters
voidno arguments
-
void ras_logger_flush(void)¶
write and release the in-memory test log buffer
Parameters
voidno arguments
-
enum ansi_color¶
symbolic terminal colors
Constants
GREENgreen text
REDred text
YELLOWyellow text
RESETterminal default
ANSI_MAX_COLORSnumber of symbolic colors
codes
codesis the static table of terminal escapes indexed by syslog severity.
-
const char *log_color(int color)¶
obtain the terminal escape for a log severity
Parameters
int colorsyslog severity
Return
an escape sequence when standard output is a terminal and color is a valid syslog severity up to LOG_DEBUG; otherwise an empty string.
ras_logger_init
ras_logger_init()is the static constructor which initializes terminal color state before main().
-
struct event_trigger¶
event-specific external trigger setup
Definition:
struct event_trigger { const char *name; void (*setup)(void); };
Members
nameevent name
setupcallback which configures the trigger
-
void run_trigger(const char *trigger, char *argv[], char **env, const char *reporter)¶
synchronously execute an external event reporter
Parameters
const char *triggerexecutable path
char *argv[]null-terminated argument vector
char **envnull-terminated environment vector
const char *reporterreporter name used in diagnostics
Description
The parent waits for the child. Fork and child-status failures are logged; they are not returned to the caller.
-
const char *trigger_check(const char *s)¶
resolve and validate a trigger executable
Parameters
const char *strigger name or path
Description
When TRIGGER_DIR is set, the returned path is newly allocated and lives
for the remainder of the process. Otherwise the return value aliases s.
Return
an executable, readable path, or NULL if validation fails.
Process entry point¶
rasdaemon_conf
rasdaemon_confis the static default configuration file path.
-
argp_program_version¶
const char *argp_program_version = PROG_NAME " " VERSION;version string exposed by argp
Initialization
default:
PROG_NAME " " VERSION;
-
argp_program_bug_address¶
const char *argp_program_bug_address = "Mauro Carvalho Chehab <mchehab@kernel.org>";maintainer address exposed by argp
Initialization
default:
"Mauro Carvalho Chehab <mchehab**kernel.org**>";
-
struct arguments¶
parsed command-line state
Definition:
struct arguments { int record_events; int enable_ras; int foreground; int offline; char *cfg_file; };
Members
record_eventsdatabase recording request count
enable_raspositive to enable or negative to disable tracing
foregroundnonzero to avoid daemonizing
offlinenonzero to decode a supplied offline MCE
cfg_fileexplicit environment configuration path
-
enum OFFLINE_ARG_KEYS¶
argp keys for offline MCE fields
Constants
SMCAenable AMD SMCA decoding
MODELCPU model
FAMILYCPU family
BANK_NUMmachine-check bank
IPID_REGSMCA IPID register
STATUS_REGmachine-check status register
SYNDROME_REGSMCA syndrome register
-
event¶
struct ras_mc_offline_event event;command-line offline MCE payload
-
static error_t parse_opt(int k, char *arg, struct argp_state *state)¶
parse top-level rasdaemon options
Parameters
int kargp option key
char *argoptional argument text
struct argp_state *stateargp parser state containing struct arguments
Return
0 - the option was handled
ARGP_ERR_UNKNOWN - k is not a top-level option
-
static error_t parse_opt_offline(int key, char *arg, struct argp_state *state)¶
parse offline MCE register options
Parameters
int keyargp option key
char *argregister value text
struct argp_state *stateargp parser state (unused)
Return
0 - the option was handled
ARGP_ERR_UNKNOWN - key is not an offline-MCE option
-
int main(int argc, char *argv[])¶
rasdaemon process entry point
Parameters
int argcargument count
char *argv[]argument vector
Description
Initializes modules, tracing, and the optional database session in ownership order. Cleanup reverses that order after event handling ends.
Return
EXIT_SUCCESS - the requested operation completed
EXIT_FAILURE - initialization or database setup/cleanup failed
-1 - argp did not produce a valid post-parse argument index
-errno- the main RAS context could not be allocated
Database API¶
-
enum db_field_type¶
Supported database column types
Constants
DB_TYPE_SERIALAuto-increment integer
DB_TYPE_INT3232-bit signed integer
DB_TYPE_INT6464-bit signed integer
DB_TYPE_TIMESTAMPISO timestamp (string or numeric value)
DB_TYPE_TEXTVariable-length string
DB_TYPE_BLOBBinary data
-
static inline const char *env_or(const char *name, const char *def)¶
ancillary routine to get an environment with a default value
Parameters
const char *namename of the variable
const char *defdefault value
Return
a nonempty environment value, otherwise def. The environment owns a value returned from getenv(3).
-
static inline int env_or_bool(const char *name, int def)¶
get a boolean from an environment variable
Parameters
const char *namename of the variable
int defdefault value (0 or 1)
Return
def - the environment variable is unset or empty
false - its value is
0,false, ornotrue - it has any other nonempty value
-
static inline int env_or_int(const char *name, int def)¶
get an integer from an environment variable
Parameters
const char *namename of the variable
int defdefault value
Return
the parsed nonzero integer, or def when unset, empty, nonnumeric, or parsed as zero.
-
struct db_fields¶
Definition of a single column in a table descriptor
Definition:
struct db_fields { const char *name; enum db_field_type type; bool is_pk; bool create_index; };
Members
nameColumn name identifier
typeData type enumeration for binding logic
is_pkTrue if this field is the primary key (affects SQL generation)
create_indexTrue if an index should be created for this field
-
struct db_table_descriptor¶
Metadata describing a database table schema
Definition:
struct db_table_descriptor { const char *name; const struct db_fields *fields; size_t num_fields; };
Members
nameName of the table in the database
fieldsArray of column definitions
num_fieldsTotal count of columns in the array
-
struct db_desc_and_stmt¶
A table descriptor and its prepared statement
Definition:
struct db_desc_and_stmt { const struct db_table_descriptor *desc; struct ras_stmt *stmt; };
Members
descDatabase table schema
stmtStorage for the prepared insert statement
-
struct db_backend¶
Specify what DB backend will be used
Definition:
struct db_backend { const char *name; void *conn_parms; };
Members
nameName of backend driver
conn_parmsBackend-specific connection parameters
-
int db_backend_enable(const char *name)¶
select backend to use
Parameters
const char *namename of the backend. NULL to allow selecting via env vars
Return
0 - database support is disabled or the backend was selected
-1 - the requested backend is unavailable
-
const char *db_list_available_backends(void)¶
list registered database backends
Parameters
voidno arguments
Description
The returned process-global buffer is overwritten by later calls and is not safe for concurrent use.
Return
a comma-separated list of backend names, or an empty string when none are registered or database support is disabled.
-
int ras_db_table_register(struct ras_module_ctx *ctx, struct db_desc_and_stmt *entry)¶
Register one module-owned table pair
Parameters
struct ras_module_ctx *ctxOwning module context
struct db_desc_and_stmt *entryDescriptor and statement pair that remains valid until unregistered
Description
Registration does not open the table. The owner must keep entry and its descriptor alive until ras_db_table_unregister().
Return
0 - database support is disabled or the table was registered
-EINVAL - ctx, entry, or entry->desc is NULL
-EEXIST - the entry or its descriptor is already registered
-ENOMEM - registry-wrapper allocation failed
-
void ras_db_table_unregister(struct ras_module_ctx *ctx)¶
Remove every table pair owned by a module
Parameters
struct ras_module_ctx *ctxOwning module context
Description
The owner must finalize its statements before calling this function.
-
ras_db_table_test_callback¶
Typedef: visit a registered table descriptor
Syntax
int ras_db_table_test_callback (const struct db_table_descriptor *desc, void *data)
Parameters
const struct db_table_descriptor *descregistry-owned persistent descriptor
void *datacaller context
Return
0 - continue iteration
nonzero - stop iteration and return this value to the caller
-
int ras_db_table_test_foreach(ras_db_table_test_callback callback, void *data)¶
visit each registered table in order
Parameters
ras_db_table_test_callback callbackvisitor callback
void *dataopaque caller context
Description
Available only to unit-test builds. The registry remains owner of every descriptor and must not be modified from the callback.
Return
0 - database support is disabled or every callback invocation succeeded
-EINVAL - callback is NULL while database support is enabled
otherwise - the first nonzero callback result
-
int db_bind(const struct db_table_descriptor *db_tab, struct ras_stmt *stmt, int pos, uint64_t value, int len)¶
Bind one field value to a prepared statement
Parameters
const struct db_table_descriptor *db_tabDatabase table descriptor
struct ras_stmt *stmtStatement handle provided by the backend
int posStarting position index placeholder (starts with 1)
uint64_t valuePointer to raw data buffer containing all field values
int lenLength of the buffer (optional, depends on implementation)
Return
0 - database support/backend is disabled or the value was bound
-1 - pos does not identify a non-serial field
-EINVAL - stmt is NULL while a backend is active
otherwise - the backend binding error
-
const char *db_get_sql_type(enum db_field_type type, bool is_pk)¶
Return SQL column type string for a given field type
Parameters
enum db_field_type typeField type descriptor from the enum db_field_type
bool is_pkTrue if the column is declared as primary key in SQL
Return
a backend-owned SQL type string, such as TEXT or BLOB; an empty
string when database support or an active backend is absent.
-
int db_eval_stmt(struct ras_stmt *stmt, const char *tab_name)¶
Execute a prepared SQL statement
Parameters
struct ras_stmt *stmtPrepared statement handle to execute
const char *tab_nameName of the table whose data should be read/written
Return
0 - database support/backend is disabled or execution succeeded
-EINVAL - stmt is NULL while a backend is active
otherwise - the backend execution error
-
int db_create_table(struct ras_db *db, const struct db_table_descriptor *db_tab)¶
Create a new database table from its descriptor
Parameters
struct ras_db *dbDatabase connection handle (opaque)
const struct db_table_descriptor *db_tabTable descriptor containing the schema to create
Return
0 when database support/backend is disabled or on success; otherwise the backend table-creation error.
-
int db_alter_table(struct ras_db *db, struct ras_stmt **stmt, const struct db_table_descriptor *db_tab)¶
Modify an existing database table structure
Parameters
struct ras_db *dbDatabase connection handle (opaque)
struct ras_stmt **stmtOutput pointer for a prepared statement describing the change
const struct db_table_descriptor *db_tabTable descriptor containing the new schema to apply
Return
0 when database support/backend is disabled or on success; otherwise the backend table-alteration error.
-
int db_prepare_insert_stmt(struct ras_db *db, struct ras_stmt **stmt, const struct db_table_descriptor *db_tab)¶
Prepare a generic SQL statement for execution
Parameters
struct ras_db *dbDatabase connection handle (opaque)
struct ras_stmt **stmtOutput pointer for the prepared statement handle
const struct db_table_descriptor *db_tabTable descriptor providing context for the query
Return
0 when database support/backend is disabled or on success; otherwise the backend statement-preparation error.
-
int db_exec_sql(struct ras_db *db, const char *sql)¶
Execute a SQL statement
Parameters
struct ras_db *dbDatabase connection handle
const char *sqlSQL command to execute
Return
0 when database support/backend is disabled or on success; otherwise the backend execution error.
-
int db_finalize(struct ras_stmt *stmt)¶
Finalize and release resources for a prepared statement
Parameters
struct ras_stmt *stmtPrepared statement handle to finalize
Return
0 when database support/backend is disabled, stmt is NULL, or finalization succeeds; otherwise the backend finalization error.
-
int db_cpu_finalize(unsigned int cpu, struct ras_stmt *stmt, const char *name)¶
CPU-local cleanup of a prepared statement resource
Parameters
unsigned int cpuLogical CPU number for per-CPU bookkeeping (opaque)
struct ras_stmt *stmtPrepared statement handle to finalize
const char *nameName string for the resource being cleaned up
Return
0 when database support/backend is disabled or on success; otherwise the backend finalization error.
-
int db_open(struct db_backend *backend, unsigned int cpu, struct ras_events *ras, size_t size_priv)¶
Open and initialize a database connection
Parameters
struct db_backend *backendExplicit backend for tests, or NULL for the selected backend
unsigned int cpuLogical CPU number for per-CPU bookkeeping (opaque)
struct ras_events *rasRAS events context (opaque)
size_t size_privOptional private allocation size; zero allocates no private data
Description
Opens the process-wide backend on the first reference. Further matching calls increment a reference count; the final db_close() releases it.
Return
0 - database support is disabled, the session opened, or its reference count was incremented
-EINVAL - ras is NULL or no backend was explicitly/implicitly selected
-ENOMEM - size_priv bytes could not be allocated
-1 - the selected backend is unavailable or its open callback failed
otherwise - the table-opening error after the backend connection opened
-
int db_close(unsigned int cpu, struct ras_events *ras)¶
Close and release resources of an open database connection
Parameters
unsigned int cpuLogical CPU number for per-CPU bookkeeping (opaque)
struct ras_events *rasRAS events context (opaque)
Return
0 - database support/backend is disabled, a reference remains, or the final close succeeded
-EINVAL - db_close() has no matching open reference
-1 - table finalization failed and the backend close succeeded
otherwise - the backend close error
-
selected_backend¶
static const char *selected_backend = NULL;name selected for the next implicit db_open()
Initialization
default:
NULL;
-
ras_db_ops¶
static const struct ras_db_backend_ops *ras_db_ops = NULL;operations for the currently open process-wide backend
Initialization
default:
NULL;
-
struct ras_db_backend_runtime¶
registry wrapper for a database backend
Definition:
struct ras_db_backend_runtime { const struct ras_db_backend_entry *entry; LIST_ENTRY(ras_db_backend_runtime) node; };
Members
entrystatic backend descriptor
nodelink in ras_db_backends
-
ras_db_backends¶
static struct ras_db_backend_list ras_db_backends = LIST_HEAD_INITIALIZER(ras_db_backends);registered database backends sorted by name
Initialization
default:
LIST_HEAD_INITIALIZER(ras_db_backends);
-
rasdaemon_hostname¶
const char *rasdaemon_hostname = "";hostname attached to remote database records
Initialization
default:
"";
-
rasdaemon_hostname_buf¶
static char rasdaemon_hostname_buf[256];storage for the system hostname
-
add_hostname¶
static bool add_hostname = false;whether the active backend needs a hostname column
Initialization
default:
false;
-
int db_backend_register(struct ras_db_backend_entry *entry)¶
register a static database backend descriptor
Parameters
struct ras_db_backend_entry *entrycomplete descriptor which remains valid until unregistered
Description
Registration is performed by module initialization and is not thread-safe. Backends are sorted by name and duplicate names are rejected.
Return
0 - the backend was registered
-EINVAL - entry or its required operations are incomplete
-EEXIST - its name is already registered
-ENOMEM - registry-wrapper allocation failed
-
int db_backend_unregister(struct ras_db_backend_entry *entry)¶
remove a database backend descriptor
Parameters
struct ras_db_backend_entry *entrydescriptor previously registered
Return
0 - the backend was unregistered
-EINVAL - entry is NULL
-EBUSY - entry is the active backend
-ENOENT - entry is not registered
-
bool db_backend_is_registered(const char *name)¶
query a database backend name
Parameters
const char *namebackend name
Return
true when registered; false for NULL or an unknown name.
-
static void db_get_rasdaemon_hostname(void)¶
initialize the remote-record hostname
Parameters
voidno arguments
Description
RASDAEMON_HOSTNAME takes precedence over gethostname(). The resulting process-lifetime string is stored in rasdaemon_hostname.
-
static int db_bind_type(struct ras_stmt *stmt, const enum db_field_type type, int pos, uint64_t value, int len)¶
bind a value with an explicit portable field type
Parameters
struct ras_stmt *stmtactive prepared statement
const enum db_field_type typeportable field type
int posone-based placeholder position
uint64_t valuescalar value or pointer encoded as uint64_t
int lenbyte length for variable-sized data
Return
0 - no backend is active or the value was bound
-EINVAL - stmt is NULL while a backend is active
otherwise - the backend binding error
-
struct db_mysql_conn_params¶
MySQL/MariaDB connection parameters
Definition:
struct db_mysql_conn_params { const char *host; unsigned int port; const char *user; const char *password; const char *database; const char *socket; unsigned int connect_timeout; bool use_ssl; };
Members
hostHostname or IP. NULL or empty for a local Unix socket.
portTCP port (default 3306). Ignored for local socket.
userUsername (default “rasdaemon”).
passwordPassword (default NULL / empty).
databaseDatabase name (default “rasdaemon”).
socketUnix socket path for local connections (default “/var/lib/mysql/mysql.sock”).
connect_timeoutConnection timeout in seconds.
use_sslWhether TLS is enabled for the connection.
-
struct db_postgresql_conn_params¶
PostgreSQL connection parameters
Definition:
struct db_postgresql_conn_params { const char *host; unsigned int port; const char *user; const char *password; const char *schema; const char *database; unsigned int connect_timeout; bool use_ssl; const char *sslmode; };
Members
hostHostname or IP. NULL or empty for a local Unix socket.
portTCP port (default 5432). Ignored for local socket.
userUsername (default “rasdaemon”).
passwordPassword (default NULL / empty).
schemaSchema to be used (default “rasdaemon”).
databaseDatabase name (default “rasdaemon”).
connect_timeoutConnection timeout in seconds.
use_sslWhether TLS is enabled for the connection.
sslmodelibpq TLS policy string.