drivers/md/md-autodetect.c
Source file repositories/reference/linux-study-clean/drivers/md/md-autodetect.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/md-autodetect.c- Extension
.c- Size
- 7532 bytes
- Lines
- 284
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/blkdev.hlinux/init.hlinux/mount.hlinux/major.hlinux/delay.hlinux/init_syscalls.hlinux/raid/detect.hlinux/raid/md_u.hlinux/raid/md_p.hmd.h
Detected Declarations
function devicesfunction md_setup_drivefunction raid_setupfunction autodetect_raidfunction md_run_setup
Annotated Snippet
if (level == 0 || level == LEVEL_LINEAR) {
if (get_option(&str, &factor) != 2 || /* Chunk Size */
get_option(&str, &fault) != 2) {
printk(KERN_WARNING "md: Too few arguments supplied to md=.\n");
return 0;
}
md_setup_args[ent].level = level;
md_setup_args[ent].chunk = 1 << (factor+12);
if (level == LEVEL_LINEAR)
pername = "linear";
else
pername = "raid0";
break;
}
fallthrough;
case 1: /* the first device is numeric */
str = str1;
fallthrough;
case 0:
md_setup_args[ent].level = LEVEL_NONE;
pername="super-block";
}
printk(KERN_INFO "md: Will configure md%d (%s) from %s, below.\n",
minor, pername, str);
md_setup_args[ent].device_names = str;
md_setup_args[ent].partitioned = partitioned;
md_setup_args[ent].minor = minor;
return 1;
}
static void __init md_setup_drive(struct md_setup_args *args)
{
char *devname = args->device_names;
dev_t devices[MD_SB_DISKS + 1], mdev;
struct mdu_array_info_s ainfo = { };
struct mddev *mddev;
int err = 0, i;
char name[16];
if (args->partitioned) {
mdev = MKDEV(mdp_major, args->minor << MdpMinorShift);
sprintf(name, "md_d%d", args->minor);
} else {
mdev = MKDEV(MD_MAJOR, args->minor);
sprintf(name, "md%d", args->minor);
}
for (i = 0; i < MD_SB_DISKS && devname != NULL; i++) {
struct kstat stat;
char *p;
char comp_name[64];
dev_t dev;
p = strchr(devname, ',');
if (p)
*p++ = 0;
if (early_lookup_bdev(devname, &dev))
dev = 0;
if (strncmp(devname, "/dev/", 5) == 0)
devname += 5;
snprintf(comp_name, 63, "/dev/%s", devname);
if (init_stat(comp_name, &stat, 0) == 0 && S_ISBLK(stat.mode))
dev = new_decode_dev(stat.rdev);
if (!dev) {
pr_warn("md: Unknown device name: %s\n", devname);
break;
}
devices[i] = dev;
devname = p;
}
devices[i] = 0;
if (!i)
return;
pr_info("md: Loading %s: %s\n", name, args->device_names);
mddev = md_alloc(mdev, name);
if (IS_ERR(mddev)) {
pr_err("md: md_alloc failed - cannot start array %s\n", name);
return;
}
err = mddev_suspend_and_lock(mddev);
if (err) {
pr_err("md: failed to lock array %s\n", name);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/blkdev.h`, `linux/init.h`, `linux/mount.h`, `linux/major.h`, `linux/delay.h`, `linux/init_syscalls.h`, `linux/raid/detect.h`.
- Detected declarations: `function devices`, `function md_setup_drive`, `function raid_setup`, `function autodetect_raid`, `function md_run_setup`.
- 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.