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.
- 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
dm-cache-policy-internal.hdm.hlinux/module.hlinux/slab.h
Detected Declarations
function put_policyfunction dm_cache_policy_registerfunction dm_cache_policy_unregisterfunction dm_cache_policy_destroyfunction dm_cache_policy_get_hint_sizeexport dm_cache_policy_registerexport dm_cache_policy_unregisterexport dm_cache_policy_createexport dm_cache_policy_destroyexport dm_cache_policy_get_nameexport dm_cache_policy_get_versionexport dm_cache_policy_get_hint_size
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, ®ister_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(®ister_lock);
t = __get_policy_once(name);
spin_unlock(®ister_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(®ister_lock);
Annotation
- Immediate include surface: `dm-cache-policy-internal.h`, `dm.h`, `linux/module.h`, `linux/slab.h`.
- Detected declarations: `function put_policy`, `function dm_cache_policy_register`, `function dm_cache_policy_unregister`, `function dm_cache_policy_destroy`, `function dm_cache_policy_get_hint_size`, `export dm_cache_policy_register`, `export dm_cache_policy_unregister`, `export dm_cache_policy_create`, `export dm_cache_policy_destroy`, `export dm_cache_policy_get_name`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.