2 #include <linux/raid/md.h>
7 * When md (and any require personalities) are compiled into the kernel
8 * (not a module), arrays can be assembles are boot time using with AUTODETECT
9 * where specially marked partitions are registered with md_autodetect_dev(),
10 * and with MD_BOOT where devices to be collected are given on the boot line
12 * The code for that is here.
15 static int __initdata raid_noautodetect
, raid_autopart
;
23 } md_setup_args
[MAX_MD_DEVS
] __initdata
;
25 static int md_setup_ents __initdata
;
29 * Parse the command-line parameters given our kernel, but do not
30 * actually try to invoke the MD device now; that is handled by
31 * md_setup_drive after the low-level disk drivers have initialised.
33 * 27/11/1999: Fixed to work correctly with the 2.3 kernel (which
34 * assigns the task of parsing integer arguments to the
35 * invoked program now). Added ability to initialise all
36 * the MD devices (by specifying multiple "md=" lines)
37 * instead of just one. -- KTK
38 * 18May2000: Added support for persistent-superblock arrays:
39 * md=n,0,factor,fault,device-list uses RAID0 for device n
40 * md=n,-1,factor,fault,device-list uses LINEAR for device n
41 * md=n,device-list reads a RAID superblock from the devices
42 * elements in device-list are read by name_to_kdev_t so can be
43 * a hex number or something like /dev/hda1 /dev/sdb
44 * 2001-06-03: Dave Cinege <dcinege@psychosis.com>
45 * Shifted name_to_kdev_t() and related operations to md_set_drive()
46 * for later execution. Rewrote section to make devfs compatible.
48 static int __init
md_setup(char *str
)
50 int minor
, level
, factor
, fault
, partitioned
= 0;
59 if (get_option(&str
, &minor
) != 2) { /* MD Number */
60 printk(KERN_WARNING
"md: Too few arguments supplied to md=.\n");
64 if (minor
>= MAX_MD_DEVS
) {
65 printk(KERN_WARNING
"md: md=%d, Minor device number too high.\n", minor
);
68 for (ent
=0 ; ent
< md_setup_ents
; ent
++)
69 if (md_setup_args
[ent
].minor
== minor
&&
70 md_setup_args
[ent
].partitioned
== partitioned
) {
71 printk(KERN_WARNING
"md: md=%s%d, Specified more than once. "
72 "Replacing previous definition.\n", partitioned
?"d":"", minor
);
75 if (ent
>= MAX_MD_DEVS
) {
76 printk(KERN_WARNING
"md: md=%s%d - too many md initialisations\n", partitioned
?"d":"", minor
);
79 if (ent
>= md_setup_ents
)
81 switch (get_option(&str
, &level
)) { /* RAID level */
82 case 2: /* could be 0 or -1.. */
83 if (level
== 0 || level
== LEVEL_LINEAR
) {
84 if (get_option(&str
, &factor
) != 2 || /* Chunk Size */
85 get_option(&str
, &fault
) != 2) {
86 printk(KERN_WARNING
"md: Too few arguments supplied to md=.\n");
89 md_setup_args
[ent
].level
= level
;
90 md_setup_args
[ent
].chunk
= 1 << (factor
+12);
91 if (level
== LEVEL_LINEAR
)
98 case 1: /* the first device is numeric */
102 md_setup_args
[ent
].level
= LEVEL_NONE
;
103 pername
="super-block";
106 printk(KERN_INFO
"md: Will configure md%d (%s) from %s, below.\n",
107 minor
, pername
, str
);
108 md_setup_args
[ent
].device_names
= str
;
109 md_setup_args
[ent
].partitioned
= partitioned
;
110 md_setup_args
[ent
].minor
= minor
;
115 #define MdpMinorShift 6
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
;
128 char name
[16], devfs_name
[16];
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
);
135 sprintf(devfs_name
, "/dev/md/%s%d", partitioned
?"d":"", minor
);
137 dev
= MKDEV(mdp_major
, minor
<< MdpMinorShift
);
139 dev
= MKDEV(MD_MAJOR
, minor
);
140 create_dev(name
, dev
, devfs_name
);
141 for (i
= 0; i
< MD_SB_DISKS
&& devname
!= 0; i
++) {
146 p
= strchr(devname
, ',');
150 dev
= name_to_dev_t(devname
);
151 if (strncmp(devname
, "/dev/", 5) == 0)
153 snprintf(comp_name
, 63, "/dev/%s", devname
);
154 rdev
= bstat(comp_name
);
156 dev
= new_decode_dev(rdev
);
158 printk(KERN_WARNING
"md: Unknown device name: %s\n", devname
);
171 printk(KERN_INFO
"md: Loading md%s%d: %s\n",
172 partitioned
? "_d" : "", minor
,
173 md_setup_args
[ent
].device_names
);
175 fd
= sys_open(name
, 0, 0);
177 printk(KERN_ERR
"md: open failed - cannot start "
181 if (sys_ioctl(fd
, SET_ARRAY_INFO
, 0) == -EBUSY
) {
183 "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n",
189 if (md_setup_args
[ent
].level
!= LEVEL_NONE
) {
191 mdu_array_info_t ainfo
;
192 ainfo
.level
= md_setup_args
[ent
].level
;
196 while (devices
[ainfo
.raid_disks
])
198 ainfo
.md_minor
=minor
;
199 ainfo
.not_persistent
= 1;
201 ainfo
.state
= (1 << MD_SB_CLEAN
);
203 ainfo
.chunk_size
= md_setup_args
[ent
].chunk
;
204 err
= sys_ioctl(fd
, SET_ARRAY_INFO
, (long)&ainfo
);
205 for (i
= 0; !err
&& i
<= MD_SB_DISKS
; i
++) {
211 dinfo
.state
= (1<<MD_DISK_ACTIVE
)|(1<<MD_DISK_SYNC
);
212 dinfo
.major
= MAJOR(dev
);
213 dinfo
.minor
= MINOR(dev
);
214 err
= sys_ioctl(fd
, ADD_NEW_DISK
, (long)&dinfo
);
218 for (i
= 0; i
<= MD_SB_DISKS
; i
++) {
222 dinfo
.major
= MAJOR(dev
);
223 dinfo
.minor
= MINOR(dev
);
224 sys_ioctl(fd
, ADD_NEW_DISK
, (long)&dinfo
);
228 err
= sys_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
= sys_open(name
, 0, 0);
239 sys_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
, "partitionable", wlen
)==0)
263 if (strncmp(str
, "part", wlen
)==0)
270 __setup("raid=", raid_setup
);
271 __setup("md=", md_setup
);
273 void __init
md_run_setup(void)
275 create_dev("/dev/md0", MKDEV(MD_MAJOR
, 0), "md/0");
276 if (raid_noautodetect
)
277 printk(KERN_INFO
"md: Skipping autodetection of RAID arrays. (raid=noautodetect)\n");
279 int fd
= sys_open("/dev/md0", 0, 0);
281 sys_ioctl(fd
, RAID_AUTORUN
, raid_autopart
);