drivers/md/dm-vdo/logger.c

Source file repositories/reference/linux-study-clean/drivers/md/dm-vdo/logger.c

File Facts

System
Linux kernel
Corpus path
drivers/md/dm-vdo/logger.c
Extension
.c
Size
5923 bytes
Lines
240
Domain
Driver Families
Bucket
drivers/md
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright 2023 Red Hat
 */

#include "logger.h"

#include <asm/current.h>
#include <linux/delay.h>
#include <linux/hardirq.h>
#include <linux/module.h>
#include <linux/printk.h>
#include <linux/sched.h>

#include "errors.h"
#include "thread-device.h"
#include "thread-utils.h"

int vdo_log_level = VDO_LOG_DEFAULT;

int vdo_get_log_level(void)
{
	int log_level_latch = READ_ONCE(vdo_log_level);

	if (unlikely(log_level_latch > VDO_LOG_MAX)) {
		log_level_latch = VDO_LOG_DEFAULT;
		WRITE_ONCE(vdo_log_level, log_level_latch);
	}
	return log_level_latch;
}

static const char *get_current_interrupt_type(void)
{
	if (in_nmi())
		return "NMI";

	if (in_hardirq())
		return "HI";

	if (in_softirq())
		return "SI";

	return "INTR";
}

/**
 * emit_log_message_to_kernel() - Emit a log message to the kernel at the specified priority.
 *
 * @priority: The priority at which to log the message
 * @fmt: The format string of the message
 */
static void emit_log_message_to_kernel(int priority, const char *fmt, ...)
{
	va_list args;
	struct va_format vaf;

	if (priority > vdo_get_log_level())
		return;

	va_start(args, fmt);
	vaf.fmt = fmt;
	vaf.va = &args;

	switch (priority) {
	case VDO_LOG_EMERG:
	case VDO_LOG_ALERT:
	case VDO_LOG_CRIT:
		pr_crit("%pV", &vaf);
		break;
	case VDO_LOG_ERR:
		pr_err("%pV", &vaf);
		break;
	case VDO_LOG_WARNING:
		pr_warn("%pV", &vaf);
		break;
	case VDO_LOG_NOTICE:
	case VDO_LOG_INFO:
		pr_info("%pV", &vaf);
		break;
	case VDO_LOG_DEBUG:
		pr_debug("%pV", &vaf);
		break;
	default:
		printk(KERN_DEFAULT "%pV", &vaf);
		break;
	}

	va_end(args);
}

Annotation

Implementation Notes