1 // SPDX-License-Identifier: GPL-2.0
3 * Many of the syscalls used in this file expect some of the arguments
4 * to be __user pointers not __kernel pointers. To limit the sparse
5 * noise, turn off sparse checking for this file.
9 #warning "Sparse checking disabled for this file"
12 #include <linux/delay.h>
13 #include <linux/raid/md_u.h>
14 #include <linux/raid/md_p.h>
16 #include "do_mounts.h"
19 * When md (and any require personalities) are compiled into the kernel
20 * (not a module), arrays can be assembles are boot time using with AUTODETECT
21 * where specially marked partitions are registered with md_autodetect_dev(),
22 * and with MD_BOOT where devices to be collected are given on the boot line
24 * The code for that is here.
27 #ifdef CONFIG_MD_AUTODETECT
28 static int __initdata raid_noautodetect;
30 static int __initdata raid_noautodetect=1;
32 static int __initdata raid_autopart;
40 } md_setup_args[256] __initdata;
42 static int md_setup_ents __initdata;
45 * Parse the command-line parameters given our kernel, but do not
46 * actually try to invoke the MD device now; that is handled by
47 * md_setup_drive after the low-level disk drivers have initialised.
49 * 27/11/1999: Fixed to work correctly with the 2.3 kernel (which
50 * assigns the task of parsing integer arguments to the
51 * invoked program now). Added ability to initialise all
52 * the MD devices (by specifying multiple "md=" lines)
53 * instead of just one. -- KTK
54 * 18May2000: Added support for persistent-superblock arrays:
55 * md=n,0,factor,fault,device-list uses RAID0 for device n
56 * md=n,-1,factor,fault,device-list uses LINEAR for device n
57 * md=n,device-list reads a RAID superblock from the devices
58 * elements in device-list are read by name_to_kdev_t so can be
59 * a hex number or something like /dev/hda1 /dev/sdb
60 * 2001-06-03: Dave Cinege <dcinege@psychosis.com>
61 * Shifted name_to_kdev_t() and related operations to md_set_drive()
62 * for later execution. Rewrote section to make devfs compatible.
64 static int __init md_setup(char *str)
66 int minor, level, factor, fault, partitioned = 0;
75 if (get_option(&str, &minor) != 2) { /* MD Number */
76 printk(KERN_WARNING "md: Too few arguments supplied to md=.\n");
80 for (ent=0 ; ent< md_setup_ents ; ent++)
81 if (md_setup_args[ent].minor == minor &&
82 md_setup_args[ent].partitioned == partitioned) {
83 printk(KERN_WARNING "md: md=%s%d, Specified more than once. "
84 "Replacing previous definition.\n", partitioned?"d":"", minor);
87 if (ent >= ARRAY_SIZE(md_setup_args)) {
88 printk(KERN_WARNING "md: md=%s%d - too many md initialisations\n", partitioned?"d":"", minor);
91 if (ent >= md_setup_ents)
93 switch (get_option(&str, &level)) { /* RAID level */
94 case 2: /* could be 0 or -1.. */
95 if (level == 0 || level == LEVEL_LINEAR) {
96 if (get_option(&str, &factor) != 2 || /* Chunk Size */
97 get_option(&str, &fault) != 2) {
98 printk(KERN_WARNING "md: Too few arguments supplied to md=.\n");
101 md_setup_args[ent].level = level;
102 md_setup_args[ent].chunk = 1 << (factor+12);
103 if (level == LEVEL_LINEAR)
110 case 1: /* the first device is numeric */
114 md_setup_args[ent].level = LEVEL_NONE;
115 pername="super-block";
118 printk(KERN_INFO "md: Will configure md%d (%s) from %s, below.\n",
119 minor, pername, str);
120 md_setup_args[ent].device_names = str;
121 md_setup_args[ent].partitioned = partitioned;
122 md_setup_args[ent].minor = minor;
127 static void __init md_setup_drive(void)
129 int minor, i, ent, partitioned;
131 dev_t devices[MD_SB_DISKS+1];
133 for (ent = 0; ent < md_setup_ents ; ent++) {
137 mdu_disk_info_t dinfo;
140 minor = md_setup_args[ent].minor;
141 partitioned = md_setup_args[ent].partitioned;
142 devname = md_setup_args[ent].device_names;
144 sprintf(name, "/dev/md%s%d", partitioned?"_d":"", minor);
146 dev = MKDEV(mdp_major, minor << MdpMinorShift);
148 dev = MKDEV(MD_MAJOR, minor);
149 create_dev(name, dev);
150 for (i = 0; i < MD_SB_DISKS && devname != NULL; i++) {
155 p = strchr(devname, ',');
159 dev = name_to_dev_t(devname);
160 if (strncmp(devname, "/dev/", 5) == 0)
162 snprintf(comp_name, 63, "/dev/%s", devname);
163 rdev = bstat(comp_name);
165 dev = new_decode_dev(rdev);
167 printk(KERN_WARNING "md: Unknown device name: %s\n", devname);
180 printk(KERN_INFO "md: Loading md%s%d: %s\n",
181 partitioned ? "_d" : "", minor,
182 md_setup_args[ent].device_names);
184 fd = ksys_open(name, 0, 0);
186 printk(KERN_ERR "md: open failed - cannot start "
190 if (ksys_ioctl(fd, SET_ARRAY_INFO, 0) == -EBUSY) {
192 "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n",
198 if (md_setup_args[ent].level != LEVEL_NONE) {
200 mdu_array_info_t ainfo;
201 ainfo.level = md_setup_args[ent].level;
205 while (devices[ainfo.raid_disks])
207 ainfo.md_minor =minor;
208 ainfo.not_persistent = 1;
210 ainfo.state = (1 << MD_SB_CLEAN);
212 ainfo.chunk_size = md_setup_args[ent].chunk;
213 err = ksys_ioctl(fd, SET_ARRAY_INFO, (long)&ainfo);
214 for (i = 0; !err && i <= MD_SB_DISKS; i++) {
220 dinfo.state = (1<<MD_DISK_ACTIVE)|(1<<MD_DISK_SYNC);
221 dinfo.major = MAJOR(dev);
222 dinfo.minor = MINOR(dev);
223 err = ksys_ioctl(fd, ADD_NEW_DISK,
228 for (i = 0; i <= MD_SB_DISKS; i++) {
232 dinfo.major = MAJOR(dev);
233 dinfo.minor = MINOR(dev);
234 ksys_ioctl(fd, ADD_NEW_DISK, (long)&dinfo);
238 err = ksys_ioctl(fd, RUN_ARRAY, 0);
240 printk(KERN_WARNING "md: starting md%d failed\n", minor);
242 /* reread the partition table.
243 * I (neilb) and not sure why this is needed, but I cannot
244 * boot a kernel with devfs compiled in from partitioned md
248 fd = ksys_open(name, 0, 0);
249 ksys_ioctl(fd, BLKRRPART, 0);
255 static int __init raid_setup(char *str)
259 len = strlen(str) + 1;
263 char *comma = strchr(str+pos, ',');
266 wlen = (comma-str)-pos;
267 else wlen = (len-1)-pos;
269 if (!strncmp(str, "noautodetect", wlen))
270 raid_noautodetect = 1;
271 if (!strncmp(str, "autodetect", wlen))
272 raid_noautodetect = 0;
273 if (strncmp(str, "partitionable", wlen)==0)
275 if (strncmp(str, "part", wlen)==0)
282 __setup("raid=", raid_setup);
283 __setup("md=", md_setup);
285 static void __init autodetect_raid(void)
290 * Since we don't want to detect and use half a raid array, we need to
291 * wait for the known devices to complete their probing
293 printk(KERN_INFO "md: Waiting for all devices to be available before autodetect\n");
294 printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect\n");
296 wait_for_device_probe();
298 fd = ksys_open("/dev/md0", 0, 0);
300 ksys_ioctl(fd, RAID_AUTORUN, raid_autopart);
305 void __init md_run_setup(void)
307 create_dev("/dev/md0", MKDEV(MD_MAJOR, 0));
309 if (raid_noautodetect)
310 printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=autodetect will force)\n");