drivers/md/dm-cache-metadata.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-cache-metadata.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-cache-metadata.c- Extension
.c- Size
- 43681 bytes
- Lines
- 1828
- 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.
- 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-cache-metadata.hpersistent-data/dm-array.hpersistent-data/dm-bitset.hpersistent-data/dm-space-map.hpersistent-data/dm-space-map-disk.hpersistent-data/dm-transaction-manager.hlinux/device-mapper.hlinux/refcount.h
Detected Declarations
struct cache_disk_superblockstruct dm_cache_metadataenum superblock_flag_bitsenum mapping_bitsfunction sb_prepare_for_writefunction check_metadata_versionfunction sb_checkfunction superblock_read_lockfunction superblock_lock_zerofunction superblock_lockfunction __superblock_all_zeroesfunction __setup_mapping_infofunction __save_sm_rootfunction __copy_sm_rootfunction separate_dirty_bitsfunction __write_initial_superblockfunction __format_metadatafunction __check_incompat_featuresfunction __open_metadatafunction __open_or_format_metadatafunction __create_persistent_data_objectsfunction __destroy_persistent_data_objectsfunction update_flagsfunction set_clean_shutdownfunction clear_clean_shutdownfunction read_superblock_fieldsfunction __begin_transaction_flagsfunction __begin_transactionfunction __commit_transactionfunction pack_valuefunction unpack_valuefunction list_for_each_entryfunction same_paramsfunction dm_cache_metadata_closefunction block_clean_combined_dirtyfunction blocks_are_clean_combined_dirtyfunction blocks_are_clean_separate_dirtyfunction blocks_are_unmapped_or_cleanfunction cmd_write_lockfunction cmd_read_lockfunction dm_cache_resizefunction dm_cache_discard_bitset_resizefunction __set_discardfunction __clear_discardfunction __discardfunction dm_cache_set_discardfunction __load_discardsfunction dm_cache_load_discards
Annotated Snippet
struct cache_disk_superblock {
__le32 csum;
__le32 flags;
__le64 blocknr;
__u8 uuid[16];
__le64 magic;
__le32 version;
__u8 policy_name[CACHE_POLICY_NAME_SIZE];
__le32 policy_hint_size;
__u8 metadata_space_map_root[SPACE_MAP_ROOT_SIZE];
__le64 mapping_root;
__le64 hint_root;
__le64 discard_root;
__le64 discard_block_size;
__le64 discard_nr_blocks;
__le32 data_block_size;
__le32 metadata_block_size;
__le32 cache_blocks;
__le32 compat_flags;
__le32 compat_ro_flags;
__le32 incompat_flags;
__le32 read_hits;
__le32 read_misses;
__le32 write_hits;
__le32 write_misses;
__le32 policy_version[CACHE_POLICY_VERSION_SIZE];
/*
* Metadata format 2 fields.
*/
__le64 dirty_root;
} __packed;
struct dm_cache_metadata {
refcount_t ref_count;
struct list_head list;
unsigned int version;
struct block_device *bdev;
struct dm_block_manager *bm;
struct dm_space_map *metadata_sm;
struct dm_transaction_manager *tm;
struct dm_array_info info;
struct dm_array_info hint_info;
struct dm_disk_bitset discard_info;
struct rw_semaphore root_lock;
unsigned long flags;
dm_block_t root;
dm_block_t hint_root;
dm_block_t discard_root;
sector_t discard_block_size;
dm_dblock_t discard_nr_blocks;
sector_t data_block_size;
dm_cblock_t cache_blocks;
bool changed:1;
bool clean_when_opened:1;
char policy_name[CACHE_POLICY_NAME_SIZE];
unsigned int policy_version[CACHE_POLICY_VERSION_SIZE];
size_t policy_hint_size;
struct dm_cache_statistics stats;
/*
* Reading the space map root can fail, so we read it into this
* buffer before the superblock is locked and updated.
*/
__u8 metadata_space_map_root[SPACE_MAP_ROOT_SIZE];
/*
* Set if a transaction has to be aborted but the attempt to roll
* back to the previous (good) transaction failed. The only
* metadata operation permissible in this state is the closing of
* the device.
*/
bool fail_io:1;
/*
* Metadata format 2 fields.
Annotation
- Immediate include surface: `dm-cache-metadata.h`, `persistent-data/dm-array.h`, `persistent-data/dm-bitset.h`, `persistent-data/dm-space-map.h`, `persistent-data/dm-space-map-disk.h`, `persistent-data/dm-transaction-manager.h`, `linux/device-mapper.h`, `linux/refcount.h`.
- Detected declarations: `struct cache_disk_superblock`, `struct dm_cache_metadata`, `enum superblock_flag_bits`, `enum mapping_bits`, `function sb_prepare_for_write`, `function check_metadata_version`, `function sb_check`, `function superblock_read_lock`, `function superblock_lock_zero`, `function superblock_lock`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: source 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.