1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/delay.h>
3 #include <linux/raid/md_u.h>
4 #include <linux/raid/md_p.h>
9 * When md (and any require personalities) are compiled into the kernel
10 * (not a module), arrays can be assembles are boot time using with AUTODETECT
11 * where specially marked partitions are registered with md_autodetect_dev(),
12 * and with MD_BOOT where devices to be collected are given on the boot line
14 * The code for that is here.
17 #ifdef CONFIG_MD_AUTODETECT
18 static int __initdata raid_noautodetect
;
20 static int __initdata raid_noautodetect
=1;
22 static int __initdata raid_autopart
;
30 } md_setup_args
[256] __initdata
;
32 static int md_setup_ents __initdata
;
35 * Parse the command-line parameters given our kernel, but do not
36 * actually try to invoke the MD device now; that is handled by
37 * md_setup_drive after the low-level disk drivers have initialised.
39 * 27/11/1999: Fixed to work correctly with the 2.3 kernel (which
40 * assigns the task of parsing integer arguments to the
41 * invoked program now). Added ability to initialise all
42 * the MD devices (by specifying multiple "md=" lines)
43 * instead of just one. -- KTK
44 * 18May2000: Added support for persistent-superblock arrays:
45 * md=n,0,factor,fault,device-list uses RAID0 for device n
46 * md=n,-1,factor,fault,device-list uses LINEAR for device n
47 * md=n,device-list reads a RAID superblock from the devices
48 * elements in device-list are read by name_to_kdev_t so can be
49 * a hex number or something like /dev/hda1 /dev/sdb
50 * 2001-06-03: Dave Cinege <dcinege@psychosis.com>
51 * Shifted name_to_kdev_t() and related operations to md_set_drive()
52 * for later execution. Rewrote section to make devfs compatible.
54 static int __init
md_setup(char *str
)
56 int minor
, level
, factor
, fault
, partitioned
= 0;
65 if (get_option(&str
, &minor
) != 2) { /* MD Number */
66 printk(KERN_WARNING
"md: Too few arguments supplied to md=.\n");
70 for (ent
=0 ; ent
< md_setup_ents
; ent
++)
71 if (md_setup_args
[ent
].minor
== minor
&&
72 md_setup_args
[ent
].partitioned
== partitioned
) {
73 printk(KERN_WARNING
"md: md=%s%d, Specified more than once. "
74 "Replacing previous definition.\n", partitioned
?"d":"", minor
);
77 if (ent
>= ARRAY_SIZE(md_setup_args
)) {
78 printk(KERN_WARNING
"md: md=%s%d - too many md initialisations\n", partitioned
?"d":"", minor
);
81 if (ent
>= md_setup_ents
)
83 switch (get_option(&str
, &level
)) { /* RAID level */
84 case 2: /* could be 0 or -1.. */
85 if (level
== 0 || level
== LEVEL_LINEAR
) {
86 if (get_option(&str
, &factor
) != 2 || /* Chunk Size */
87 get_option(&str
, &fault
) != 2) {
88 printk(KERN_WARNING
"md: Too few arguments supplied to md=.\n");
91 md_setup_args
[ent
].level
= level
;
92 md_setup_args
[ent
].chunk
= 1 << (factor
+12);
93 if (level
== LEVEL_LINEAR
)
100 case 1: /* the first device is numeric */
104 md_setup_args
[ent
].level
= LEVEL_NONE
;
105 pername
="super-block";
108 printk(KERN_INFO
"md: Will configure md%d (%s) from %s, below.\n",
109 minor
, pername
, str
);
110 md_setup_args
[ent
].device_names
= str
;
111 md_setup_args
[ent
].partitioned
= partitioned
;
112 md_setup_args
[ent
].minor
= minor
;
117 static void __init
md_setup_drive(void)
119 int minor
, i
, ent
, partitioned
;
121 dev_t devices
[MD_SB_DISKS
+1];
123 for (ent
= 0; ent
< md_setup_ents
; ent
++) {
127 mdu_disk_info_t dinfo
;
130 minor
= md_setup_args
[ent
].minor
;
131 partitioned
= md_setup_args
[ent
].partitioned
;
132 devname
= md_setup_args
[ent
].device_names
;
134 sprintf(name
, "/dev/md%s%d", partitioned
?"_d":"", minor
);
136 dev
= MKDEV(mdp_major
, minor
<< MdpMinorShift
);
138 dev
= MKDEV(MD_MAJOR
, minor
);
139 create_dev(name
, dev
);
140 for (i
= 0; i
< MD_SB_DISKS
&& devname
!= NULL
; i
++) {
145 p
= strchr(devname
, ',');
149 dev
= name_to_dev_t(devname
);
150 if (strncmp(devname
, "/dev/", 5) == 0)
152 snprintf(comp_name
, 63, "/dev/%s", devname
);
153 rdev
= bstat(comp_name
);
155 dev
= new_decode_dev(rdev
);
157 printk(KERN_WARNING
"md: Unknown device name: %s\n", devname
);
170 printk(KERN_INFO
"md: Loading md%s%d: %s\n",
171 partitioned
? "_d" : "", minor
,
172 md_setup_args
[ent
].device_names
);
174 fd
= ksys_open(name
, 0, 0);
176 printk(KERN_ERR
"md: open failed - cannot start "
180 if (ksys_ioctl(fd
, SET_ARRAY_INFO
, 0) == -EBUSY
) {
182 "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n",
188 if (md_setup_args
[ent
].level
!= LEVEL_NONE
) {
190 mdu_array_info_t ainfo
;
191 ainfo
.level
= md_setup_args
[ent
].level
;
195 while (devices
[ainfo
.raid_disks
])
197 ainfo
.md_minor
=minor
;
198 ainfo
.not_persistent
= 1;
200 ainfo
.state
= (1 << MD_SB_CLEAN
);
202 ainfo
.chunk_size
= md_setup_args
[ent
].chunk
;
203 err
= ksys_ioctl(fd
, SET_ARRAY_INFO
, (long)&ainfo
);
204 for (i
= 0; !err
&& i
<= MD_SB_DISKS
; i
++) {
210 dinfo
.state
= (1<<MD_DISK_ACTIVE
)|(1<<MD_DISK_SYNC
);
211 dinfo
.major
= MAJOR(dev
);
212 dinfo
.minor
= MINOR(dev
);
213 err
= ksys_ioctl(fd
, ADD_NEW_DISK
,
218 for (i
= 0; i
<= MD_SB_DISKS
; i
++) {
222 dinfo
.major
= MAJOR(dev
);
223 dinfo
.minor
= MINOR(dev
);
224 ksys_ioctl(fd
, ADD_NEW_DISK
, (long)&dinfo
);
228 err
= ksys_ioctl(fd
, RUN_ARRAY
, 0);
230 printk(KERN_WARNING
"md: starting md%d failed\n", minor
);
232 /* reread the partition table.
233 * I (neilb) and not sure why this is needed, but I cannot
234 * boot a kernel with devfs compiled in from partitioned md
238 fd
= ksys_open(name
, 0, 0);
239 ksys_ioctl(fd
, BLKRRPART
, 0);
245 static int __init
raid_setup(char *str
)
249 len
= strlen(str
) + 1;
253 char *comma
= strchr(str
+pos
, ',');
256 wlen
= (comma
-str
)-pos
;
257 else wlen
= (len
-1)-pos
;
259 if (!strncmp(str
, "noautodetect", wlen
))
260 raid_noautodetect
= 1;
261 if (!strncmp(str
, "autodetect", wlen
))
262 raid_noautodetect
= 0;
263 if (strncmp(str
, "partitionable", wlen
)==0)
265 if (strncmp(str
, "part", wlen
)==0)
272 __setup("raid=", raid_setup
);
273 __setup("md=", md_setup
);
275 static void __init
autodetect_raid(void)
280 * Since we don't want to detect and use half a raid array, we need to
281 * wait for the known devices to complete their probing
283 printk(KERN_INFO
"md: Waiting for all devices to be available before autodetect\n");
284 printk(KERN_INFO
"md: If you don't use raid, use raid=noautodetect\n");
286 wait_for_device_probe();
288 fd
= ksys_open("/dev/md0", 0, 0);
290 ksys_ioctl(fd
, RAID_AUTORUN
, raid_autopart
);
295 void __init
md_run_setup(void)
297 create_dev("/dev/md0", MKDEV(MD_MAJOR
, 0));
299 if (raid_noautodetect
)
300 printk(KERN_INFO
"md: Skipping autodetection of RAID arrays. (raid=autodetect will force)\n");