drivers/md/dm-region-hash.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-region-hash.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-region-hash.c- Extension
.c- Size
- 18589 bytes
- Lines
- 728
- 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
linux/dm-dirty-log.hlinux/dm-region-hash.hlinux/ctype.hlinux/init.hlinux/module.hlinux/slab.hlinux/vmalloc.hdm.h
Detected Declarations
struct dm_region_hashstruct dm_regionfunction dm_rh_sector_to_regionfunction dm_rh_region_to_sectorfunction dm_rh_bio_to_regionfunction dm_rh_get_region_keyfunction dm_rh_get_region_sizefunction dm_region_hash_createfunction dm_region_hash_destroyfunction list_for_each_entry_safefunction rh_hashfunction __rh_insertfunction dm_rh_get_statefunction complete_resync_workfunction mirrorfunction dm_rh_update_statesfunction list_for_each_entry_safefunction list_for_each_entry_safefunction rh_incfunction dm_rh_inc_pendingfunction dm_rh_decfunction __rh_recovery_preparefunction dm_rh_recovery_preparefunction dm_rh_recovery_endfunction dm_rh_recovery_in_flightfunction dm_rh_flushfunction dm_rh_delayfunction dm_rh_stop_recoveryfunction dm_rh_start_recoveryexport dm_rh_region_to_sectorexport dm_rh_bio_to_regionexport dm_rh_region_contextexport dm_rh_get_region_keyexport dm_rh_get_region_sizeexport dm_region_hash_createexport dm_region_hash_destroyexport dm_rh_dirty_logexport dm_rh_get_stateexport dm_rh_mark_nosyncexport dm_rh_update_statesexport dm_rh_inc_pendingexport dm_rh_decexport dm_rh_recovery_prepareexport dm_rh_recovery_startexport dm_rh_recovery_endexport dm_rh_recovery_in_flightexport dm_rh_flushexport dm_rh_delay
Annotated Snippet
struct dm_region_hash {
uint32_t region_size;
unsigned int region_shift;
/* holds persistent region state */
struct dm_dirty_log *log;
/* hash table */
rwlock_t hash_lock;
unsigned int mask;
unsigned int nr_buckets;
unsigned int prime;
unsigned int shift;
struct list_head *buckets;
/*
* If there was a flush failure no regions can be marked clean.
*/
int flush_failure;
unsigned int max_recovery; /* Max # of regions to recover in parallel */
spinlock_t region_lock;
atomic_t recovery_in_flight;
struct list_head clean_regions;
struct list_head quiesced_regions;
struct list_head recovered_regions;
struct list_head failed_recovered_regions;
struct semaphore recovery_count;
mempool_t region_pool;
void *context;
sector_t target_begin;
/* Callback function to schedule bios writes */
void (*dispatch_bios)(void *context, struct bio_list *bios);
/* Callback function to wakeup callers worker thread. */
void (*wakeup_workers)(void *context);
/* Callback function to wakeup callers recovery waiters. */
void (*wakeup_all_recovery_waiters)(void *context);
};
struct dm_region {
struct dm_region_hash *rh; /* FIXME: can we get rid of this ? */
region_t key;
int state;
struct list_head hash_list;
struct list_head list;
atomic_t pending;
struct bio_list delayed_bios;
};
/*
* Conversion fns
*/
static region_t dm_rh_sector_to_region(struct dm_region_hash *rh, sector_t sector)
{
return sector >> rh->region_shift;
}
sector_t dm_rh_region_to_sector(struct dm_region_hash *rh, region_t region)
{
return region << rh->region_shift;
}
EXPORT_SYMBOL_GPL(dm_rh_region_to_sector);
region_t dm_rh_bio_to_region(struct dm_region_hash *rh, struct bio *bio)
{
return dm_rh_sector_to_region(rh, bio->bi_iter.bi_sector -
rh->target_begin);
}
EXPORT_SYMBOL_GPL(dm_rh_bio_to_region);
void *dm_rh_region_context(struct dm_region *reg)
{
return reg->rh->context;
}
EXPORT_SYMBOL_GPL(dm_rh_region_context);
region_t dm_rh_get_region_key(struct dm_region *reg)
{
return reg->key;
}
EXPORT_SYMBOL_GPL(dm_rh_get_region_key);
Annotation
- Immediate include surface: `linux/dm-dirty-log.h`, `linux/dm-region-hash.h`, `linux/ctype.h`, `linux/init.h`, `linux/module.h`, `linux/slab.h`, `linux/vmalloc.h`, `dm.h`.
- Detected declarations: `struct dm_region_hash`, `struct dm_region`, `function dm_rh_sector_to_region`, `function dm_rh_region_to_sector`, `function dm_rh_bio_to_region`, `function dm_rh_get_region_key`, `function dm_rh_get_region_size`, `function dm_region_hash_create`, `function dm_region_hash_destroy`, `function list_for_each_entry_safe`.
- 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.