drivers/md/dm-cache-policy.c

Source file repositories/reference/linux-study-clean/drivers/md/dm-cache-policy.c

File Facts

System
Linux kernel
Corpus path
drivers/md/dm-cache-policy.c
Extension
.c
Size
3743 bytes
Lines
175
Domain
Driver Families
Bucket
drivers/md
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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 (C) 2012 Red Hat. All rights reserved.
 *
 * This file is released under the GPL.
 */

#include "dm-cache-policy-internal.h"
#include "dm.h"

#include <linux/module.h>
#include <linux/slab.h>

/*----------------------------------------------------------------*/

#define DM_MSG_PREFIX "cache-policy"

static DEFINE_SPINLOCK(register_lock);
static LIST_HEAD(register_list);

static struct dm_cache_policy_type *__find_policy(const char *name)
{
	struct dm_cache_policy_type *t;

	list_for_each_entry(t, &register_list, list)
		if (!strcmp(t->name, name))
			return t;

	return NULL;
}

static struct dm_cache_policy_type *__get_policy_once(const char *name)
{
	struct dm_cache_policy_type *t = __find_policy(name);

	if (t && !try_module_get(t->owner)) {
		DMWARN("couldn't get module %s", name);
		t = ERR_PTR(-EINVAL);
	}

	return t;
}

static struct dm_cache_policy_type *get_policy_once(const char *name)
{
	struct dm_cache_policy_type *t;

	spin_lock(&register_lock);
	t = __get_policy_once(name);
	spin_unlock(&register_lock);

	return t;
}

static struct dm_cache_policy_type *get_policy(const char *name)
{
	struct dm_cache_policy_type *t;

	t = get_policy_once(name);
	if (IS_ERR(t))
		return NULL;

	if (t)
		return t;

	request_module("dm-cache-%s", name);

	t = get_policy_once(name);
	if (IS_ERR(t))
		return NULL;

	return t;
}

static void put_policy(struct dm_cache_policy_type *t)
{
	module_put(t->owner);
}

int dm_cache_policy_register(struct dm_cache_policy_type *type)
{
	int r;

	/* One size fits all for now */
	if (type->hint_size != 0 && type->hint_size != 4) {
		DMWARN("hint size must be 0 or 4 but %llu supplied.", (unsigned long long) type->hint_size);
		return -EINVAL;
	}

	spin_lock(&register_lock);

Annotation

Implementation Notes