drivers/md/dm-bio-prison-v2.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-bio-prison-v2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-bio-prison-v2.c- Extension
.c- Size
- 8222 bytes
- Lines
- 365
- 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.
- 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.hdm-bio-prison-v2.hlinux/spinlock.hlinux/mempool.hlinux/module.hlinux/slab.hlinux/rwsem.h
Detected Declarations
struct dm_bio_prison_v2function dm_bio_prison_destroy_v2function dm_bio_prison_free_cell_v2function __setup_new_cellfunction cmp_keysfunction __find_or_insertfunction __getfunction dm_cell_get_v2function __putfunction dm_cell_put_v2function __lockfunction dm_cell_lock_v2function __quiescefunction dm_cell_quiesce_v2function __promotefunction dm_cell_lock_promote_v2function __unlockfunction dm_cell_unlock_v2function dm_bio_prison_init_v2function dm_bio_prison_exit_v2export dm_bio_prison_create_v2export dm_bio_prison_destroy_v2export dm_bio_prison_alloc_cell_v2export dm_bio_prison_free_cell_v2export dm_cell_get_v2export dm_cell_put_v2export dm_cell_lock_v2export dm_cell_quiesce_v2export dm_cell_lock_promote_v2export dm_cell_unlock_v2
Annotated Snippet
struct dm_bio_prison_v2 {
struct workqueue_struct *wq;
spinlock_t lock;
struct rb_root cells;
mempool_t cell_pool;
};
static struct kmem_cache *_cell_cache;
/*----------------------------------------------------------------*/
/*
* @nr_cells should be the number of cells you want in use _concurrently_.
* Don't confuse it with the number of distinct keys.
*/
struct dm_bio_prison_v2 *dm_bio_prison_create_v2(struct workqueue_struct *wq)
{
struct dm_bio_prison_v2 *prison = kzalloc_obj(*prison);
int ret;
if (!prison)
return NULL;
prison->wq = wq;
spin_lock_init(&prison->lock);
ret = mempool_init_slab_pool(&prison->cell_pool, MIN_CELLS, _cell_cache);
if (ret) {
kfree(prison);
return NULL;
}
prison->cells = RB_ROOT;
return prison;
}
EXPORT_SYMBOL_GPL(dm_bio_prison_create_v2);
void dm_bio_prison_destroy_v2(struct dm_bio_prison_v2 *prison)
{
mempool_exit(&prison->cell_pool);
kfree(prison);
}
EXPORT_SYMBOL_GPL(dm_bio_prison_destroy_v2);
struct dm_bio_prison_cell_v2 *dm_bio_prison_alloc_cell_v2(struct dm_bio_prison_v2 *prison, gfp_t gfp)
{
return mempool_alloc(&prison->cell_pool, gfp);
}
EXPORT_SYMBOL_GPL(dm_bio_prison_alloc_cell_v2);
void dm_bio_prison_free_cell_v2(struct dm_bio_prison_v2 *prison,
struct dm_bio_prison_cell_v2 *cell)
{
mempool_free(cell, &prison->cell_pool);
}
EXPORT_SYMBOL_GPL(dm_bio_prison_free_cell_v2);
static void __setup_new_cell(struct dm_cell_key_v2 *key,
struct dm_bio_prison_cell_v2 *cell)
{
memset(cell, 0, sizeof(*cell));
memcpy(&cell->key, key, sizeof(cell->key));
bio_list_init(&cell->bios);
}
static int cmp_keys(struct dm_cell_key_v2 *lhs,
struct dm_cell_key_v2 *rhs)
{
if (lhs->virtual < rhs->virtual)
return -1;
if (lhs->virtual > rhs->virtual)
return 1;
if (lhs->dev < rhs->dev)
return -1;
if (lhs->dev > rhs->dev)
return 1;
if (lhs->block_end <= rhs->block_begin)
return -1;
if (lhs->block_begin >= rhs->block_end)
return 1;
return 0;
}
Annotation
- Immediate include surface: `dm.h`, `dm-bio-prison-v2.h`, `linux/spinlock.h`, `linux/mempool.h`, `linux/module.h`, `linux/slab.h`, `linux/rwsem.h`.
- Detected declarations: `struct dm_bio_prison_v2`, `function dm_bio_prison_destroy_v2`, `function dm_bio_prison_free_cell_v2`, `function __setup_new_cell`, `function cmp_keys`, `function __find_or_insert`, `function __get`, `function dm_cell_get_v2`, `function __put`, `function dm_cell_put_v2`.
- 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.