drivers/md/persistent-data/dm-space-map-common.c
Source file repositories/reference/linux-study-clean/drivers/md/persistent-data/dm-space-map-common.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/persistent-data/dm-space-map-common.c- Extension
.c- Size
- 28195 bytes
- Lines
- 1266
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
dm-space-map-common.hdm-transaction-manager.hdm-btree-internal.hdm-persistent-data-internal.hlinux/bitops.hlinux/device-mapper.h
Detected Declarations
struct inc_contextfunction Copyrightfunction index_checkfunction dm_bitmap_prepare_for_writefunction dm_bitmap_checkfunction dm_bitmap_word_usedfunction sm_lookup_bitmapfunction sm_set_bitmapfunction sm_find_freefunction sm_ll_initfunction sm_ll_extendfunction sm_ll_lookup_bitmapfunction sm_ll_lookup_big_ref_countfunction sm_ll_lookupfunction sm_ll_find_free_blockfunction sm_ll_find_common_free_blockfunction sm_ll_insertfunction init_inc_contextfunction exit_inc_contextfunction reset_inc_contextfunction contains_keyfunction __sm_ll_inc_overflowfunction sm_ll_inc_overflowfunction shadow_bitmapfunction dm_tm_shadow_blockfunction sm_ll_inc_bitmapfunction __sm_ll_incfunction sm_ll_incfunction __sm_ll_del_overflowfunction __sm_ll_dec_overflowfunction sm_ll_dec_overflowfunction sm_ll_dec_bitmapfunction __sm_ll_decfunction sm_ll_decfunction sm_ll_commitfunction metadata_ll_load_iefunction metadata_ll_save_iefunction metadata_ll_init_indexfunction metadata_ll_openfunction metadata_ll_max_entriesfunction metadata_ll_commitfunction sm_ll_new_metadatafunction sm_ll_open_metadatafunction ie_cache_writebackfunction hash_indexfunction disk_ll_load_iefunction disk_ll_save_iefunction disk_ll_init_index
Annotated Snippet
struct inc_context {
struct disk_index_entry ie_disk;
struct dm_block *bitmap_block;
void *bitmap;
struct dm_block *overflow_leaf;
};
static inline void init_inc_context(struct inc_context *ic)
{
ic->bitmap_block = NULL;
ic->bitmap = NULL;
ic->overflow_leaf = NULL;
}
static inline void exit_inc_context(struct ll_disk *ll, struct inc_context *ic)
{
if (ic->bitmap_block)
dm_tm_unlock(ll->tm, ic->bitmap_block);
if (ic->overflow_leaf)
dm_tm_unlock(ll->tm, ic->overflow_leaf);
}
static inline void reset_inc_context(struct ll_disk *ll, struct inc_context *ic)
{
exit_inc_context(ll, ic);
init_inc_context(ic);
}
/*
* Confirms a btree node contains a particular key at an index.
*/
static bool contains_key(struct btree_node *n, uint64_t key, int index)
{
return index >= 0 &&
index < le32_to_cpu(n->header.nr_entries) &&
le64_to_cpu(n->keys[index]) == key;
}
static int __sm_ll_inc_overflow(struct ll_disk *ll, dm_block_t b, struct inc_context *ic)
{
int r;
int index;
struct btree_node *n;
__le32 *v_ptr;
uint32_t rc;
/*
* bitmap_block needs to be unlocked because getting the
* overflow_leaf may need to allocate, and thus use the space map.
*/
reset_inc_context(ll, ic);
r = btree_get_overwrite_leaf(&ll->ref_count_info, ll->ref_count_root,
b, &index, &ll->ref_count_root, &ic->overflow_leaf);
if (r < 0)
return r;
n = dm_block_data(ic->overflow_leaf);
if (!contains_key(n, b, index)) {
DMERR("overflow btree is missing an entry");
return -EINVAL;
}
v_ptr = value_ptr(n, index);
rc = le32_to_cpu(*v_ptr) + 1;
*v_ptr = cpu_to_le32(rc);
return 0;
}
static int sm_ll_inc_overflow(struct ll_disk *ll, dm_block_t b, struct inc_context *ic)
{
int index;
struct btree_node *n;
__le32 *v_ptr;
uint32_t rc;
/*
* Do we already have the correct overflow leaf?
*/
if (ic->overflow_leaf) {
n = dm_block_data(ic->overflow_leaf);
index = lower_bound(n, b);
if (contains_key(n, b, index)) {
v_ptr = value_ptr(n, index);
rc = le32_to_cpu(*v_ptr) + 1;
*v_ptr = cpu_to_le32(rc);
Annotation
- Immediate include surface: `dm-space-map-common.h`, `dm-transaction-manager.h`, `dm-btree-internal.h`, `dm-persistent-data-internal.h`, `linux/bitops.h`, `linux/device-mapper.h`.
- Detected declarations: `struct inc_context`, `function Copyright`, `function index_check`, `function dm_bitmap_prepare_for_write`, `function dm_bitmap_check`, `function dm_bitmap_word_used`, `function sm_lookup_bitmap`, `function sm_set_bitmap`, `function sm_find_free`, `function sm_ll_init`.
- 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.