2023-11-17 00:44:01 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/*
|
|
|
|
* Copyright 2023 Red Hat
|
|
|
|
*/
|
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
#ifndef VDO_LOGGER_H
|
|
|
|
#define VDO_LOGGER_H
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-10 16:42:00 +00:00
|
|
|
#include <linux/kern_levels.h>
|
2023-11-17 00:44:01 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ratelimit.h>
|
2024-02-14 23:25:14 +00:00
|
|
|
#include <linux/device-mapper.h>
|
2023-11-17 00:44:01 +00:00
|
|
|
|
|
|
|
/* Custom logging utilities for UDS */
|
|
|
|
|
2024-02-10 16:42:00 +00:00
|
|
|
enum {
|
2024-02-14 15:22:04 +00:00
|
|
|
VDO_LOG_EMERG = LOGLEVEL_EMERG,
|
|
|
|
VDO_LOG_ALERT = LOGLEVEL_ALERT,
|
|
|
|
VDO_LOG_CRIT = LOGLEVEL_CRIT,
|
|
|
|
VDO_LOG_ERR = LOGLEVEL_ERR,
|
|
|
|
VDO_LOG_WARNING = LOGLEVEL_WARNING,
|
|
|
|
VDO_LOG_NOTICE = LOGLEVEL_NOTICE,
|
|
|
|
VDO_LOG_INFO = LOGLEVEL_INFO,
|
|
|
|
VDO_LOG_DEBUG = LOGLEVEL_DEBUG,
|
|
|
|
|
|
|
|
VDO_LOG_MAX = VDO_LOG_DEBUG,
|
|
|
|
VDO_LOG_DEFAULT = VDO_LOG_INFO,
|
2024-02-10 16:42:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern int vdo_log_level;
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 23:25:14 +00:00
|
|
|
#define DM_MSG_PREFIX "vdo"
|
2024-02-14 15:22:04 +00:00
|
|
|
#define VDO_LOGGING_MODULE_NAME DM_NAME ": " DM_MSG_PREFIX
|
2023-11-17 00:44:01 +00:00
|
|
|
|
|
|
|
/* Apply a rate limiter to a log method call. */
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_ratelimit(log_fn, ...) \
|
2023-11-17 00:44:01 +00:00
|
|
|
do { \
|
|
|
|
static DEFINE_RATELIMIT_STATE(_rs, \
|
|
|
|
DEFAULT_RATELIMIT_INTERVAL, \
|
|
|
|
DEFAULT_RATELIMIT_BURST); \
|
|
|
|
if (__ratelimit(&_rs)) { \
|
|
|
|
log_fn(__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
int vdo_get_log_level(void);
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
void vdo_log_embedded_message(int priority, const char *module, const char *prefix,
|
2023-11-17 00:44:01 +00:00
|
|
|
const char *fmt1, va_list args1, const char *fmt2, ...)
|
|
|
|
__printf(4, 0) __printf(6, 7);
|
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
void vdo_log_backtrace(int priority);
|
2023-11-17 00:44:01 +00:00
|
|
|
|
|
|
|
/* All log functions will preserve the caller's value of errno. */
|
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_strerror(priority, errnum, ...) \
|
|
|
|
__vdo_log_strerror(priority, errnum, VDO_LOGGING_MODULE_NAME, __VA_ARGS__)
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
int __vdo_log_strerror(int priority, int errnum, const char *module,
|
2023-11-17 00:44:01 +00:00
|
|
|
const char *format, ...)
|
|
|
|
__printf(4, 5);
|
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
int vdo_vlog_strerror(int priority, int errnum, const char *module, const char *format,
|
2023-11-17 00:44:01 +00:00
|
|
|
va_list args)
|
|
|
|
__printf(4, 0);
|
|
|
|
|
|
|
|
/* Log an error prefixed with the string associated with the errnum. */
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_error_strerror(errnum, ...) \
|
|
|
|
vdo_log_strerror(VDO_LOG_ERR, errnum, __VA_ARGS__)
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_debug_strerror(errnum, ...) \
|
|
|
|
vdo_log_strerror(VDO_LOG_DEBUG, errnum, __VA_ARGS__)
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_info_strerror(errnum, ...) \
|
|
|
|
vdo_log_strerror(VDO_LOG_INFO, errnum, __VA_ARGS__)
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_warning_strerror(errnum, ...) \
|
|
|
|
vdo_log_strerror(VDO_LOG_WARNING, errnum, __VA_ARGS__)
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_fatal_strerror(errnum, ...) \
|
|
|
|
vdo_log_strerror(VDO_LOG_CRIT, errnum, __VA_ARGS__)
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_message(priority, ...) \
|
|
|
|
__vdo_log_message(priority, VDO_LOGGING_MODULE_NAME, __VA_ARGS__)
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
void __vdo_log_message(int priority, const char *module, const char *format, ...)
|
2023-11-17 00:44:01 +00:00
|
|
|
__printf(3, 4);
|
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_debug(...) vdo_log_message(VDO_LOG_DEBUG, __VA_ARGS__)
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_info(...) vdo_log_message(VDO_LOG_INFO, __VA_ARGS__)
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_warning(...) vdo_log_message(VDO_LOG_WARNING, __VA_ARGS__)
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_error(...) vdo_log_message(VDO_LOG_ERR, __VA_ARGS__)
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
#define vdo_log_fatal(...) vdo_log_message(VDO_LOG_CRIT, __VA_ARGS__)
|
2023-11-17 00:44:01 +00:00
|
|
|
|
2024-02-14 15:22:04 +00:00
|
|
|
void vdo_pause_for_logger(void);
|
|
|
|
#endif /* VDO_LOGGER_H */
|