[PATCH] clean up ip2 glue (not yet ported tho)
[linux-2.6/history.git] / init / do_mounts_md.c
bloba3444e771718fa5c2ca46a339f953cd9a3105ef8
2 #include <linux/raid/md.h>
4 #include "do_mounts.h"
6 /*
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
11 * with md=.....
12 * The code for that is here.
15 static int __initdata raid_noautodetect;
17 static struct {
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;
47 char *pername = "";
48 char *str1 = str;
50 if (get_option(&str, &minor) != 2) { /* MD Number */
51 printk(KERN_WARNING "md: Too few arguments supplied to md=.\n");
52 return 0;
54 if (minor >= MAX_MD_DEVS) {
55 printk(KERN_WARNING "md: md=%d, Minor device number too high.\n", minor);
56 return 0;
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");
67 return 0;
69 md_setup_args.pers[minor] = level;
70 md_setup_args.chunk[minor] = 1 << (factor+12);
71 switch(level) {
72 case LEVEL_LINEAR:
73 pers = LINEAR;
74 pername = "linear";
75 break;
76 case 0:
77 pers = RAID0;
78 pername = "raid0";
79 break;
80 default:
81 printk(KERN_WARNING
82 "md: The kernel has not been configured for raid%d support!\n",
83 level);
84 return 0;
86 md_setup_args.pers[minor] = pers;
87 break;
89 /* FALL THROUGH */
90 case 1: /* the first device is numeric */
91 str = str1;
92 /* FALL THROUGH */
93 case 0:
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",
99 minor, pername, str);
100 md_setup_args.device_names[minor] = str;
102 return 1;
105 static void __init md_setup_drive(void)
107 int minor, i;
108 dev_t dev;
109 dev_t devices[MD_SB_DISKS+1];
111 for (minor = 0; minor < MAX_MD_DEVS; minor++) {
112 int fd;
113 int err = 0;
114 char *devname;
115 mdu_disk_info_t dinfo;
116 char name[16], devfs_name[16];
118 if (!(devname = md_setup_args.device_names[minor]))
119 continue;
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++) {
125 char *p;
126 char comp_name[64];
127 struct stat buf;
129 p = strchr(devname, ',');
130 if (p)
131 *p++ = 0;
133 dev = name_to_dev_t(devname);
134 if (strncmp(devname, "/dev/", 5) == 0)
135 devname += 5;
136 snprintf(comp_name, 63, "/dev/%s", devname);
137 if (sys_newstat(comp_name, &buf) == 0 &&
138 S_ISBLK(buf.st_mode))
139 dev = buf.st_rdev;
140 if (!dev) {
141 printk(KERN_WARNING "md: Unknown device name: %s\n", devname);
142 break;
145 devices[i] = dev;
146 md_setup_args.device_set[minor] = 1;
148 devname = p;
150 devices[i] = 0;
152 if (!md_setup_args.device_set[minor])
153 continue;
155 printk(KERN_INFO "md: Loading md%d: %s\n", minor, md_setup_args.device_names[minor]);
157 fd = open(name, 0, 0);
158 if (fd < 0) {
159 printk(KERN_ERR "md: open failed - cannot start array %d\n", minor);
160 continue;
162 if (sys_ioctl(fd, SET_ARRAY_INFO, 0) == -EBUSY) {
163 printk(KERN_WARNING
164 "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n",
165 minor);
166 close(fd);
167 continue;
170 if (md_setup_args.pers[minor]) {
171 /* non-persistent */
172 mdu_array_info_t ainfo;
173 ainfo.level = pers_to_level(md_setup_args.pers[minor]);
174 ainfo.size = 0;
175 ainfo.nr_disks =0;
176 ainfo.raid_disks =0;
177 while (devices[ainfo.raid_disks])
178 ainfo.raid_disks++;
179 ainfo.md_minor =minor;
180 ainfo.not_persistent = 1;
182 ainfo.state = (1 << MD_SB_CLEAN);
183 ainfo.layout = 0;
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++) {
187 dev = devices[i];
188 if (!dev)
189 break;
190 dinfo.number = i;
191 dinfo.raid_disk = 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);
197 } else {
198 /* persistent */
199 for (i = 0; i <= MD_SB_DISKS; i++) {
200 dev = devices[i];
201 if (!dev)
202 break;
203 dinfo.major = MAJOR(dev);
204 dinfo.minor = MINOR(dev);
205 sys_ioctl(fd, ADD_NEW_DISK, (long)&dinfo);
208 if (!err)
209 err = sys_ioctl(fd, RUN_ARRAY, 0);
210 if (err)
211 printk(KERN_WARNING "md: starting md%d failed\n", minor);
212 close(fd);
216 static int __init raid_setup(char *str)
218 int len, pos;
220 len = strlen(str) + 1;
221 pos = 0;
223 while (pos < len) {
224 char *comma = strchr(str+pos, ',');
225 int wlen;
226 if (comma)
227 wlen = (comma-str)-pos;
228 else wlen = (len-1)-pos;
230 if (!strncmp(str, "noautodetect", wlen))
231 raid_noautodetect = 1;
232 pos += wlen+1;
234 return 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");
245 else {
246 int fd = open("/dev/md0", 0, 0);
247 if (fd >= 0) {
248 sys_ioctl(fd, RAID_AUTORUN, 0);
249 close(fd);
252 md_setup_drive();