drivers/md/dm-vdo/message-stats.c

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

File Facts

System
Linux kernel
Corpus path
drivers/md/dm-vdo/message-stats.c
Extension
.c
Size
20502 bytes
Lines
481
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 "dedupe.h"
#include "indexer.h"
#include "logger.h"
#include "memory-alloc.h"
#include "message-stats.h"
#include "statistics.h"
#include "thread-device.h"
#include "vdo.h"

static void write_u64(char *prefix, u64 value, char *suffix, char **buf,
		      unsigned int *maxlen)
{
	int count;

	count = scnprintf(*buf, *maxlen, "%s%llu%s", prefix == NULL ? "" : prefix,
			  value, suffix == NULL ? "" : suffix);
	*buf += count;
	*maxlen -= count;
}

static void write_u32(char *prefix, u32 value, char *suffix, char **buf,
		      unsigned int *maxlen)
{
	int count;

	count = scnprintf(*buf, *maxlen, "%s%u%s", prefix == NULL ? "" : prefix,
			  value, suffix == NULL ? "" : suffix);
	*buf += count;
	*maxlen -= count;
}

static void write_block_count_t(char *prefix, block_count_t value, char *suffix,
				char **buf, unsigned int *maxlen)
{
	int count;

	count = scnprintf(*buf, *maxlen, "%s%llu%s", prefix == NULL ? "" : prefix,
			  value, suffix == NULL ? "" : suffix);
	*buf += count;
	*maxlen -= count;
}

static void write_string(char *prefix, char *value, char *suffix, char **buf,
			 unsigned int *maxlen)
{
	int count;

	count = scnprintf(*buf, *maxlen, "%s%s%s", prefix == NULL ? "" : prefix,
			  value, suffix == NULL ? "" : suffix);
	*buf += count;
	*maxlen -= count;
}

static void write_bool(char *prefix, bool value, char *suffix, char **buf,
		       unsigned int *maxlen)
{
	int count;

	count = scnprintf(*buf, *maxlen, "%s%d%s", prefix == NULL ? "" : prefix,
			  value, suffix == NULL ? "" : suffix);
	*buf += count;
	*maxlen -= count;
}

static void write_u8(char *prefix, u8 value, char *suffix, char **buf,
		     unsigned int *maxlen)
{
	int count;

	count = scnprintf(*buf, *maxlen, "%s%u%s", prefix == NULL ? "" : prefix,
			  value, suffix == NULL ? "" : suffix);
	*buf += count;
	*maxlen -= count;
}

static void write_block_allocator_statistics(char *prefix,
					     struct block_allocator_statistics *stats,
					     char *suffix, char **buf,
					     unsigned int *maxlen)
{
	write_string(prefix, "{ ", NULL, buf, maxlen);
	/* The total number of slabs from which blocks may be allocated */
	write_u64("slabCount : ", stats->slab_count, ", ", buf, maxlen);
	/* The total number of slabs from which blocks have ever been allocated */
	write_u64("slabsOpened : ", stats->slabs_opened, ", ", buf, maxlen);

Annotation

Implementation Notes