drivers/md/dm-pcache/cache_key.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-pcache/cache_key.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-pcache/cache_key.c- Extension
.c- Size
- 25406 bytes
- Lines
- 890
- 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
cache.hbacking_dev.hcache_dev.hdm_pcache.h
Detected Declarations
function cache_key_initfunction cache_key_getfunction cache_key_destroyfunction cache_key_putfunction cache_pos_advancefunction cache_key_encodefunction cache_key_decodefunction append_last_ksetfunction cache_kset_closefunction cache_key_appendfunction cache_subtree_walkfunction keyfunction keyfunction fixup_overlap_containedfunction fixup_overlap_headfunction cache_key_insertfunction list_for_each_entry_safefunction clean_fnfunction cache_key_appendfunction kset_replayfunction cache_replayfunction cache_tree_initfunction cache_tree_clearfunction cache_tree_exit
Annotated Snippet
if (!next_seg) {
ret = -EBUSY;
goto out;
}
/* clear outdated kset in next seg */
memcpy_flushcache(next_seg->segment.data, &pcache_empty_kset,
sizeof(struct pcache_cache_kset_onmedia));
append_last_kset(cache, next_seg->cache_seg_id);
cache->key_head.cache_seg = next_seg;
cache->key_head.seg_off = 0;
goto again;
}
kset_onmedia->magic = PCACHE_KSET_MAGIC;
kset_onmedia->crc = cache_kset_crc(kset_onmedia);
/* clear outdated kset after current kset */
memcpy_flushcache(get_key_head_addr(cache) + kset_onmedia_size, &pcache_empty_kset,
sizeof(struct pcache_cache_kset_onmedia));
/* write current kset into segment */
memcpy_flushcache(get_key_head_addr(cache), kset_onmedia, kset_onmedia_size);
pmem_wmb();
/* reset kset_onmedia */
memset(kset_onmedia, 0, sizeof(struct pcache_cache_kset_onmedia));
cache_pos_advance(&cache->key_head, kset_onmedia_size);
ret = 0;
out:
spin_unlock(&cache->key_head_lock);
return ret;
}
/**
* cache_key_append - Append a cache key to the related kset.
* @cache: Pointer to the pcache_cache structure.
* @key: Pointer to the cache key structure to append.
* @force_close: Need to close current kset if true.
*
* This function appends a cache key to the appropriate kset. If the kset
* is full, it closes the kset. If not, it queues a flush work to write
* the kset to media.
*
* Returns 0 on success, or a negative error code on failure.
*/
int cache_key_append(struct pcache_cache *cache, struct pcache_cache_key *key, bool force_close)
{
struct pcache_cache_kset *kset;
struct pcache_cache_kset_onmedia *kset_onmedia;
struct pcache_cache_key_onmedia *key_onmedia;
u32 kset_id = get_kset_id(cache, key->off);
int ret = 0;
kset = get_kset(cache, kset_id);
kset_onmedia = &kset->kset_onmedia;
spin_lock(&kset->kset_lock);
key_onmedia = &kset_onmedia->data[kset_onmedia->key_num];
cache_key_encode(cache, key_onmedia, key);
/* Check if the current kset has reached the maximum number of keys */
if (++kset_onmedia->key_num == PCACHE_KSET_KEYS_MAX || force_close) {
/* If full, close the kset */
ret = cache_kset_close(cache, kset);
if (ret) {
kset_onmedia->key_num--;
goto out;
}
} else {
/* If not full, queue a delayed work to flush the kset */
queue_delayed_work(cache_get_wq(cache), &kset->flush_work, 1 * HZ);
}
out:
spin_unlock(&kset->kset_lock);
return ret;
}
/**
* cache_subtree_walk - Traverse the cache tree.
* @ctx: Pointer to the context structure for traversal.
*
* This function traverses the cache tree starting from the specified node.
* It calls the appropriate callback functions based on the relationships
* between the keys in the cache tree.
*
* Returns 0 on success, or a negative error code on failure.
*/
Annotation
- Immediate include surface: `cache.h`, `backing_dev.h`, `cache_dev.h`, `dm_pcache.h`.
- Detected declarations: `function cache_key_init`, `function cache_key_get`, `function cache_key_destroy`, `function cache_key_put`, `function cache_pos_advance`, `function cache_key_encode`, `function cache_key_decode`, `function append_last_kset`, `function cache_kset_close`, `function cache_key_append`.
- 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.