drivers/md/dm-pcache/cache_dev.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-pcache/cache_dev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-pcache/cache_dev.c- Extension
.c- Size
- 7043 bytes
- Lines
- 304
- 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
linux/blkdev.hlinux/dax.hlinux/vmalloc.hlinux/parser.hcache_dev.hbacking_dev.hcache.hdm_pcache.h
Detected Declarations
function cache_dev_dax_exitfunction build_vmapfunction cache_dev_dax_initfunction cache_dev_zero_rangefunction sb_readfunction sb_writefunction sb_initfunction sb_validatefunction cache_dev_initfunction cache_dev_exitfunction cache_dev_stopfunction cache_dev_startfunction cache_dev_get_empty_segment_id
Annotated Snippet
if (chunk <= 0) {
ret = chunk ? chunk : -EINVAL;
goto out_free;
}
if (!pfn_valid(pfn)) {
ret = -EOPNOTSUPP;
goto out_free;
}
while (chunk-- && i < total_pages) {
pages[i++] = pfn_to_page(pfn);
pfn++;
if (!(i & 15))
cond_resched();
}
} while (i < total_pages);
*vaddr = vmap(pages, total_pages, VM_MAP, PAGE_KERNEL);
if (!*vaddr) {
ret = -ENOMEM;
goto out_free;
}
ret = 0;
out_free:
vfree(pages);
return ret;
}
static int cache_dev_dax_init(struct pcache_cache_dev *cache_dev)
{
struct dm_pcache *pcache = CACHE_DEV_TO_PCACHE(cache_dev);
struct dax_device *dax_dev;
long total_pages, mapped_pages;
u64 bdev_size;
void *vaddr;
int ret;
int id;
unsigned long pfn;
dax_dev = cache_dev->dm_dev->dax_dev;
/* total size check */
bdev_size = bdev_nr_bytes(cache_dev->dm_dev->bdev);
if (bdev_size < PCACHE_CACHE_DEV_SIZE_MIN) {
pcache_dev_err(pcache, "dax device is too small, required at least %llu",
PCACHE_CACHE_DEV_SIZE_MIN);
ret = -ENOSPC;
goto out;
}
total_pages = bdev_size >> PAGE_SHIFT;
/* attempt: direct-map the whole range */
id = dax_read_lock();
mapped_pages = dax_direct_access(dax_dev, 0, total_pages,
DAX_ACCESS, &vaddr, &pfn);
if (mapped_pages < 0) {
pcache_dev_err(pcache, "dax_direct_access failed: %ld\n", mapped_pages);
ret = mapped_pages;
goto unlock;
}
if (!pfn_valid(pfn)) {
ret = -EOPNOTSUPP;
goto unlock;
}
if (mapped_pages == total_pages) {
/* success: contiguous direct mapping */
cache_dev->mapping = vaddr;
} else {
/* need vmap fallback */
ret = build_vmap(dax_dev, total_pages, &vaddr);
if (ret) {
pcache_dev_err(pcache, "vmap fallback failed: %d\n", ret);
goto unlock;
}
cache_dev->mapping = vaddr;
cache_dev->use_vmap = true;
}
dax_read_unlock(id);
return 0;
unlock:
dax_read_unlock(id);
out:
return ret;
}
Annotation
- Immediate include surface: `linux/blkdev.h`, `linux/dax.h`, `linux/vmalloc.h`, `linux/parser.h`, `cache_dev.h`, `backing_dev.h`, `cache.h`, `dm_pcache.h`.
- Detected declarations: `function cache_dev_dax_exit`, `function build_vmap`, `function cache_dev_dax_init`, `function cache_dev_zero_range`, `function sb_read`, `function sb_write`, `function sb_init`, `function sb_validate`, `function cache_dev_init`, `function cache_dev_exit`.
- 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.