drivers/md/dm-linear.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-linear.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-linear.c- Extension
.c- Size
- 5472 bytes
- Lines
- 235
- 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.
- 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.hlinux/module.hlinux/init.hlinux/blkdev.hlinux/bio.hlinux/dax.hlinux/slab.hlinux/device-mapper.h
Detected Declarations
struct linear_cfunction linear_ctrfunction linear_dtrfunction linear_map_sectorfunction linear_mapfunction linear_statusfunction linear_prepare_ioctlfunction linear_report_zonesfunction linear_iterate_devicesfunction linear_dax_direct_accessfunction linear_dax_zero_page_rangefunction linear_dax_recovery_writefunction dm_linear_initfunction dm_linear_exit
Annotated Snippet
struct linear_c {
struct dm_dev *dev;
sector_t start;
};
/*
* Construct a linear mapping: <dev_path> <offset>
*/
static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
{
struct linear_c *lc;
unsigned long long tmp;
char dummy;
int ret;
if (argc != 2) {
ti->error = "Invalid argument count";
return -EINVAL;
}
lc = kmalloc_obj(*lc);
if (lc == NULL) {
ti->error = "Cannot allocate linear context";
return -ENOMEM;
}
ret = -EINVAL;
if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1 || tmp != (sector_t)tmp) {
ti->error = "Invalid device sector";
goto bad;
}
lc->start = tmp;
ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &lc->dev);
if (ret) {
ti->error = "Device lookup failed";
goto bad;
}
ti->num_flush_bios = 1;
ti->num_discard_bios = 1;
ti->num_secure_erase_bios = 1;
ti->num_write_zeroes_bios = 1;
ti->flush_bypasses_map = true;
ti->private = lc;
return 0;
bad:
kfree(lc);
return ret;
}
static void linear_dtr(struct dm_target *ti)
{
struct linear_c *lc = ti->private;
dm_put_device(ti, lc->dev);
kfree(lc);
}
static sector_t linear_map_sector(struct dm_target *ti, sector_t bi_sector)
{
struct linear_c *lc = ti->private;
return lc->start + dm_target_offset(ti, bi_sector);
}
int linear_map(struct dm_target *ti, struct bio *bio)
{
struct linear_c *lc = ti->private;
bio_set_dev(bio, lc->dev->bdev);
bio->bi_iter.bi_sector = linear_map_sector(ti, bio->bi_iter.bi_sector);
return DM_MAPIO_REMAPPED;
}
static void linear_status(struct dm_target *ti, status_type_t type,
unsigned int status_flags, char *result, unsigned int maxlen)
{
struct linear_c *lc = ti->private;
size_t sz = 0;
switch (type) {
case STATUSTYPE_INFO:
result[0] = '\0';
break;
case STATUSTYPE_TABLE:
DMEMIT("%s %llu", lc->dev->name, (unsigned long long)lc->start);
Annotation
- Immediate include surface: `dm.h`, `linux/module.h`, `linux/init.h`, `linux/blkdev.h`, `linux/bio.h`, `linux/dax.h`, `linux/slab.h`, `linux/device-mapper.h`.
- Detected declarations: `struct linear_c`, `function linear_ctr`, `function linear_dtr`, `function linear_map_sector`, `function linear_map`, `function linear_status`, `function linear_prepare_ioctl`, `function linear_report_zones`, `function linear_iterate_devices`, `function linear_dax_direct_access`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: source implementation candidate.
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.