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
;
18 char device_set
[MAX_MD_DEVS
];
19 int pers
[MAX_MD_DEVS
];
20 int chunk
[MAX_MD_DEVS
];
21 char *device_names
[MAX_MD_DEVS
];
22 } md_setup_args __initdata
;
25 * Parse the command-line parameters given our kernel, but do not
26 * actually try to invoke the MD device now; that is handled by
27 * md_setup_drive after the low-level disk drivers have initialised.
29 * 27/11/1999: Fixed to work correctly with the 2.3 kernel (which
30 * assigns the task of parsing integer arguments to the
31 * invoked program now). Added ability to initialise all
32 * the MD devices (by specifying multiple "md=" lines)
33 * instead of just one. -- KTK
34 * 18May2000: Added support for persistent-superblock arrays:
35 * md=n,0,factor,fault,device-list uses RAID0 for device n
36 * md=n,-1,factor,fault,device-list uses LINEAR for device n
37 * md=n,device-list reads a RAID superblock from the devices
38 * elements in device-list are read by name_to_kdev_t so can be
39 * a hex number or something like /dev/hda1 /dev/sdb
40 * 2001-06-03: Dave Cinege <dcinege@psychosis.com>
41 * Shifted name_to_kdev_t() and related operations to md_set_drive()
42 * for later execution. Rewrote section to make devfs compatible.
44 static int __init
md_setup(char *str
)
46 int minor
, level
, factor
, fault
, pers
;
50 if (get_option(&str
, &minor
) != 2) { /* MD Number */
51 printk(KERN_WARNING
"md: Too few arguments supplied to md=.\n");
54 if (minor
>= MAX_MD_DEVS
) {
55 printk(KERN_WARNING
"md: md=%d, Minor device number too high.\n", minor
);
57 } else if (md_setup_args
.device_names
[minor
]) {
58 printk(KERN_WARNING
"md: md=%d, Specified more than once. "
59 "Replacing previous definition.\n", minor
);
61 switch (get_option(&str
, &level
)) { /* RAID Personality */
62 case 2: /* could be 0 or -1.. */
63 if (level
== 0 || level
== LEVEL_LINEAR
) {
64 if (get_option(&str
, &factor
) != 2 || /* Chunk Size */
65 get_option(&str
, &fault
) != 2) {
66 printk(KERN_WARNING
"md: Too few arguments supplied to md=.\n");
69 md_setup_args
.pers
[minor
] = level
;
70 md_setup_args
.chunk
[minor
] = 1 << (factor
+12);
82 "md: The kernel has not been configured for raid%d support!\n",
86 md_setup_args
.pers
[minor
] = pers
;
90 case 1: /* the first device is numeric */
94 md_setup_args
.pers
[minor
] = 0;
95 pername
="super-block";
98 printk(KERN_INFO
"md: Will configure md%d (%s) from %s, below.\n",
100 md_setup_args
.device_names
[minor
] = str
;
105 static void __init
md_setup_drive(void)
109 dev_t devices
[MD_SB_DISKS
+1];
111 for (minor
= 0; minor
< MAX_MD_DEVS
; minor
++) {
115 mdu_disk_info_t dinfo
;
116 char name
[16], devfs_name
[16];
118 if (!(devname
= md_setup_args
.device_names
[minor
]))
121 sprintf(name
, "/dev/md%d", minor
);
122 sprintf(devfs_name
, "/dev/md/%d", minor
);
123 create_dev(name
, MKDEV(MD_MAJOR
, minor
), devfs_name
);
124 for (i
= 0; i
< MD_SB_DISKS
&& devname
!= 0; i
++) {
129 p
= strchr(devname
, ',');
133 dev
= name_to_dev_t(devname
);
134 if (strncmp(devname
, "/dev/", 5) == 0)
136 snprintf(comp_name
, 63, "/dev/%s", devname
);
137 if (sys_newstat(comp_name
, &buf
) == 0 &&
138 S_ISBLK(buf
.st_mode
))
141 printk(KERN_WARNING
"md: Unknown device name: %s\n", devname
);
146 md_setup_args
.device_set
[minor
] = 1;
152 if (!md_setup_args
.device_set
[minor
])
155 printk(KERN_INFO
"md: Loading md%d: %s\n", minor
, md_setup_args
.device_names
[minor
]);
157 fd
= open(name
, 0, 0);
159 printk(KERN_ERR
"md: open failed - cannot start array %d\n", minor
);
162 if (sys_ioctl(fd
, SET_ARRAY_INFO
, 0) == -EBUSY
) {
164 "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n",
170 if (md_setup_args
.pers
[minor
]) {
172 mdu_array_info_t ainfo
;
173 ainfo
.level
= pers_to_level(md_setup_args
.pers
[minor
]);
177 while (devices
[ainfo
.raid_disks
])
179 ainfo
.md_minor
=minor
;
180 ainfo
.not_persistent
= 1;
182 ainfo
.state
= (1 << MD_SB_CLEAN
);
184 ainfo
.chunk_size
= md_setup_args
.chunk
[minor
];
185 err
= sys_ioctl(fd
, SET_ARRAY_INFO
, (long)&ainfo
);
186 for (i
= 0; !err
&& i
<= MD_SB_DISKS
; i
++) {
192 dinfo
.state
= (1<<MD_DISK_ACTIVE
)|(1<<MD_DISK_SYNC
);
193 dinfo
.major
= MAJOR(dev
);
194 dinfo
.minor
= MINOR(dev
);
195 err
= sys_ioctl(fd
, ADD_NEW_DISK
, (long)&dinfo
);
199 for (i
= 0; i
<= MD_SB_DISKS
; i
++) {
203 dinfo
.major
= MAJOR(dev
);
204 dinfo
.minor
= MINOR(dev
);
205 sys_ioctl(fd
, ADD_NEW_DISK
, (long)&dinfo
);
209 err
= sys_ioctl(fd
, RUN_ARRAY
, 0);
211 printk(KERN_WARNING
"md: starting md%d failed\n", minor
);
216 static int __init
raid_setup(char *str
)
220 len
= strlen(str
) + 1;
224 char *comma
= strchr(str
+pos
, ',');
227 wlen
= (comma
-str
)-pos
;
228 else wlen
= (len
-1)-pos
;
230 if (!strncmp(str
, "noautodetect", wlen
))
231 raid_noautodetect
= 1;
237 __setup("raid=", raid_setup
);
238 __setup("md=", md_setup
);
240 void __init
md_run_setup(void)
242 create_dev("/dev/md0", MKDEV(MD_MAJOR
, 0), "md/0");
243 if (raid_noautodetect
)
244 printk(KERN_INFO
"md: Skipping autodetection of RAID arrays. (raid=noautodetect)\n");
246 int fd
= open("/dev/md0", 0, 0);
248 sys_ioctl(fd
, RAID_AUTORUN
, 0);