drivers/md/persistent-data/dm-space-map-metadata.c
Source file repositories/reference/linux-study-clean/drivers/md/persistent-data/dm-space-map-metadata.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/persistent-data/dm-space-map-metadata.c- Extension
.c- Size
- 17976 bytes
- Lines
- 847
- 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.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
dm-space-map.hdm-space-map-common.hdm-space-map-metadata.hlinux/list.hlinux/slab.hlinux/device-mapper.hlinux/kernel.h
Detected Declarations
struct thresholdstruct block_opstruct bop_ring_bufferstruct sm_metadataenum block_op_typefunction threshold_initfunction set_thresholdfunction below_thresholdfunction threshold_already_triggeredfunction check_thresholdfunction brb_initfunction brb_emptyfunction brb_nextfunction brb_pushfunction brb_peekfunction brb_popfunction add_bopfunction commit_bopfunction infunction apply_bopsfunction outfunction outfunction recursingfunction sm_metadata_destroyfunction sm_metadata_get_nr_blocksfunction sm_metadata_get_nr_freefunction sm_metadata_get_countfunction sm_metadata_count_is_more_than_onefunction sm_metadata_set_countfunction sm_metadata_inc_blocksfunction sm_metadata_dec_blocksfunction sm_metadata_new_block_function sm_metadata_new_blockfunction sm_metadata_commitfunction sm_metadata_register_threshold_callbackfunction sm_metadata_root_sizefunction sm_metadata_copy_rootfunction sm_bootstrap_destroyfunction sm_bootstrap_get_nr_blocksfunction sm_bootstrap_get_nr_freefunction sm_bootstrap_get_countfunction sm_bootstrap_count_is_more_than_onefunction sm_bootstrap_set_countfunction sm_bootstrap_new_blockfunction sm_bootstrap_inc_blocksfunction sm_bootstrap_dec_blocksfunction sm_bootstrap_commitfunction sm_bootstrap_root_size
Annotated Snippet
struct threshold {
bool threshold_set;
bool value_set;
dm_block_t threshold;
dm_block_t current_value;
dm_sm_threshold_fn fn;
void *context;
};
static void threshold_init(struct threshold *t)
{
t->threshold_set = false;
t->value_set = false;
}
static void set_threshold(struct threshold *t, dm_block_t value,
dm_sm_threshold_fn fn, void *context)
{
t->threshold_set = true;
t->threshold = value;
t->fn = fn;
t->context = context;
}
static bool below_threshold(struct threshold *t, dm_block_t value)
{
return t->threshold_set && value <= t->threshold;
}
static bool threshold_already_triggered(struct threshold *t)
{
return t->value_set && below_threshold(t, t->current_value);
}
static void check_threshold(struct threshold *t, dm_block_t value)
{
if (below_threshold(t, value) &&
!threshold_already_triggered(t))
t->fn(t->context);
t->value_set = true;
t->current_value = value;
}
/*----------------------------------------------------------------*/
/*
* Space map interface.
*
* The low level disk format is written using the standard btree and
* transaction manager. This means that performing disk operations may
* cause us to recurse into the space map in order to allocate new blocks.
* For this reason we have a pool of pre-allocated blocks large enough to
* service any metadata_ll_disk operation.
*/
/*
* FIXME: we should calculate this based on the size of the device.
* Only the metadata space map needs this functionality.
*/
#define MAX_RECURSIVE_ALLOCATIONS 1024
enum block_op_type {
BOP_INC,
BOP_DEC
};
struct block_op {
enum block_op_type type;
dm_block_t b;
dm_block_t e;
};
struct bop_ring_buffer {
unsigned int begin;
unsigned int end;
struct block_op bops[MAX_RECURSIVE_ALLOCATIONS + 1];
};
static void brb_init(struct bop_ring_buffer *brb)
{
brb->begin = 0;
brb->end = 0;
}
static bool brb_empty(struct bop_ring_buffer *brb)
{
return brb->begin == brb->end;
}
Annotation
- Immediate include surface: `dm-space-map.h`, `dm-space-map-common.h`, `dm-space-map-metadata.h`, `linux/list.h`, `linux/slab.h`, `linux/device-mapper.h`, `linux/kernel.h`.
- Detected declarations: `struct threshold`, `struct block_op`, `struct bop_ring_buffer`, `struct sm_metadata`, `enum block_op_type`, `function threshold_init`, `function set_threshold`, `function below_threshold`, `function threshold_already_triggered`, `function check_threshold`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: source implementation candidate.
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.