dm vdo: add 'log_level' module parameter

Expose control over dm-vdo's log-level in terms of a module param. It
can be read and written via /sys/module/dm_vdo/parameters/log_level.

Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Signed-off-by: Ken Raeburn <raeburn@redhat.com>
Signed-off-by: Matthew Sakai <msakai@redhat.com>
This commit is contained in:
Mike Snitzer 2024-02-10 10:42:00 -06:00
parent a9da0fb6d8
commit 25315e967a
3 changed files with 27 additions and 10 deletions

View File

@ -2905,6 +2905,9 @@ static void __exit vdo_exit(void)
module_init(vdo_init);
module_exit(vdo_exit);
module_param_named(log_level, vdo_log_level, uint, 0644);
MODULE_PARM_DESC(log_level, "Log level for log messages");
MODULE_DESCRIPTION(DM_NAME " target for transparent deduplication");
MODULE_AUTHOR("Red Hat, Inc.");
MODULE_LICENSE("GPL");

View File

@ -49,11 +49,17 @@ static const char *const PRIORITY_STRINGS[] = {
"DEBUG",
};
static int log_level = UDS_LOG_INFO;
int vdo_log_level = UDS_LOG_DEFAULT;
int uds_get_log_level(void)
{
return log_level;
int log_level_latch = READ_ONCE(vdo_log_level);
if (unlikely(log_level_latch > UDS_LOG_MAX)) {
log_level_latch = UDS_LOG_DEFAULT;
WRITE_ONCE(vdo_log_level, log_level_latch);
}
return log_level_latch;
}
int uds_log_string_to_priority(const char *string)

View File

@ -6,20 +6,28 @@
#ifndef UDS_LOGGER_H
#define UDS_LOGGER_H
#include <linux/kern_levels.h>
#include <linux/module.h>
#include <linux/ratelimit.h>
#include <linux/device-mapper.h>
/* Custom logging utilities for UDS */
#define UDS_LOG_EMERG 0
#define UDS_LOG_ALERT 1
#define UDS_LOG_CRIT 2
#define UDS_LOG_ERR 3
#define UDS_LOG_WARNING 4
#define UDS_LOG_NOTICE 5
#define UDS_LOG_INFO 6
#define UDS_LOG_DEBUG 7
enum {
UDS_LOG_EMERG = LOGLEVEL_EMERG,
UDS_LOG_ALERT = LOGLEVEL_ALERT,
UDS_LOG_CRIT = LOGLEVEL_CRIT,
UDS_LOG_ERR = LOGLEVEL_ERR,
UDS_LOG_WARNING = LOGLEVEL_WARNING,
UDS_LOG_NOTICE = LOGLEVEL_NOTICE,
UDS_LOG_INFO = LOGLEVEL_INFO,
UDS_LOG_DEBUG = LOGLEVEL_DEBUG,
UDS_LOG_MAX = UDS_LOG_DEBUG,
UDS_LOG_DEFAULT = UDS_LOG_INFO,
};
extern int vdo_log_level;
#define DM_MSG_PREFIX "vdo"
#define UDS_LOGGING_MODULE_NAME DM_NAME ": " DM_MSG_PREFIX