Blame view

init/do_mounts_md.c 7.94 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
f8b77d393   Alexey Dobriyan   init/do_mounts_md...
2
  #include <linux/delay.h>
bff61975b   NeilBrown   md: move lots of ...
3
4
  #include <linux/raid/md_u.h>
  #include <linux/raid/md_p.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
7
8
9
10
11
12
13
14
15
  
  #include "do_mounts.h"
  
  /*
   * When md (and any require personalities) are compiled into the kernel
   * (not a module), arrays can be assembles are boot time using with AUTODETECT
   * where specially marked partitions are registered with md_autodetect_dev(),
   * and with MD_BOOT where devices to be collected are given on the boot line
   * with md=.....
   * The code for that is here.
   */
a364092a4   Arjan van de Ven   raid: make RAID a...
16
17
18
19
20
21
  #ifdef CONFIG_MD_AUTODETECT
  static int __initdata raid_noautodetect;
  #else
  static int __initdata raid_noautodetect=1;
  #endif
  static int __initdata raid_autopart;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
23
24
25
  
  static struct {
  	int minor;
  	int partitioned;
2604b703b   NeilBrown   [PATCH] md: remov...
26
  	int level;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
28
  	int chunk;
  	char *device_names;
e8703fe1f   NeilBrown   [PATCH] md: remov...
29
  } md_setup_args[256] __initdata;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
31
  
  static int md_setup_ents __initdata;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  /*
   * Parse the command-line parameters given our kernel, but do not
   * actually try to invoke the MD device now; that is handled by
   * md_setup_drive after the low-level disk drivers have initialised.
   *
   * 27/11/1999: Fixed to work correctly with the 2.3 kernel (which
   *             assigns the task of parsing integer arguments to the
   *             invoked program now).  Added ability to initialise all
   *             the MD devices (by specifying multiple "md=" lines)
   *             instead of just one.  -- KTK
   * 18May2000: Added support for persistent-superblock arrays:
   *             md=n,0,factor,fault,device-list   uses RAID0 for device n
   *             md=n,-1,factor,fault,device-list  uses LINEAR for device n
   *             md=n,device-list      reads a RAID superblock from the devices
   *             elements in device-list are read by name_to_kdev_t so can be
   *             a hex number or something like /dev/hda1 /dev/sdb
   * 2001-06-03: Dave Cinege <dcinege@psychosis.com>
   *		Shifted name_to_kdev_t() and related operations to md_set_drive()
   *		for later execution. Rewrote section to make devfs compatible.
   */
  static int __init md_setup(char *str)
  {
2604b703b   NeilBrown   [PATCH] md: remov...
54
  	int minor, level, factor, fault, partitioned = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  	char *pername = "";
  	char *str1;
  	int ent;
  
  	if (*str == 'd') {
  		partitioned = 1;
  		str++;
  	}
  	if (get_option(&str, &minor) != 2) {	/* MD Number */
  		printk(KERN_WARNING "md: Too few arguments supplied to md=.
  ");
  		return 0;
  	}
  	str1 = str;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
70
71
72
73
74
75
76
  	for (ent=0 ; ent< md_setup_ents ; ent++)
  		if (md_setup_args[ent].minor == minor &&
  		    md_setup_args[ent].partitioned == partitioned) {
  			printk(KERN_WARNING "md: md=%s%d, Specified more than once. "
  			       "Replacing previous definition.
  ", partitioned?"d":"", minor);
  			break;
  		}
e8703fe1f   NeilBrown   [PATCH] md: remov...
77
  	if (ent >= ARRAY_SIZE(md_setup_args)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
79
80
81
82
83
  		printk(KERN_WARNING "md: md=%s%d - too many md initialisations
  ", partitioned?"d":"", minor);
  		return 0;
  	}
  	if (ent >= md_setup_ents)
  		md_setup_ents++;
2604b703b   NeilBrown   [PATCH] md: remov...
84
  	switch (get_option(&str, &level)) {	/* RAID level */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
86
87
88
89
90
91
92
  	case 2: /* could be 0 or -1.. */
  		if (level == 0 || level == LEVEL_LINEAR) {
  			if (get_option(&str, &factor) != 2 ||	/* Chunk Size */
  					get_option(&str, &fault) != 2) {
  				printk(KERN_WARNING "md: Too few arguments supplied to md=.
  ");
  				return 0;
  			}
2604b703b   NeilBrown   [PATCH] md: remov...
93
  			md_setup_args[ent].level = level;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
  			md_setup_args[ent].chunk = 1 << (factor+12);
2604b703b   NeilBrown   [PATCH] md: remov...
95
  			if (level ==  LEVEL_LINEAR)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
  				pername = "linear";
2604b703b   NeilBrown   [PATCH] md: remov...
97
  			else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
  				pername = "raid0";
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99
100
101
102
103
104
105
  			break;
  		}
  		/* FALL THROUGH */
  	case 1: /* the first device is numeric */
  		str = str1;
  		/* FALL THROUGH */
  	case 0:
2604b703b   NeilBrown   [PATCH] md: remov...
106
  		md_setup_args[ent].level = LEVEL_NONE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107
108
109
110
111
112
113
114
115
116
117
118
  		pername="super-block";
  	}
  
  	printk(KERN_INFO "md: Will configure md%d (%s) from %s, below.
  ",
  		minor, pername, str);
  	md_setup_args[ent].device_names = str;
  	md_setup_args[ent].partitioned = partitioned;
  	md_setup_args[ent].minor = minor;
  
  	return 1;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
120
121
122
123
124
125
126
127
128
129
  static void __init md_setup_drive(void)
  {
  	int minor, i, ent, partitioned;
  	dev_t dev;
  	dev_t devices[MD_SB_DISKS+1];
  
  	for (ent = 0; ent < md_setup_ents ; ent++) {
  		int fd;
  		int err = 0;
  		char *devname;
  		mdu_disk_info_t dinfo;
bdaf85293   Greg Kroah-Hartman   [PATCH] devfs: Re...
130
  		char name[16];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131
132
133
134
135
136
  
  		minor = md_setup_args[ent].minor;
  		partitioned = md_setup_args[ent].partitioned;
  		devname = md_setup_args[ent].device_names;
  
  		sprintf(name, "/dev/md%s%d", partitioned?"_d":"", minor);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
137
138
139
140
  		if (partitioned)
  			dev = MKDEV(mdp_major, minor << MdpMinorShift);
  		else
  			dev = MKDEV(MD_MAJOR, minor);
bdaf85293   Greg Kroah-Hartman   [PATCH] devfs: Re...
141
  		create_dev(name, dev);
d613c3e2d   Harvey Harrison   init: fix integer...
142
  		for (i = 0; i < MD_SB_DISKS && devname != NULL; i++) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
  			char *p;
  			char comp_name[64];
  			u32 rdev;
  
  			p = strchr(devname, ',');
  			if (p)
  				*p++ = 0;
  
  			dev = name_to_dev_t(devname);
  			if (strncmp(devname, "/dev/", 5) == 0)
  				devname += 5;
  			snprintf(comp_name, 63, "/dev/%s", devname);
  			rdev = bstat(comp_name);
  			if (rdev)
  				dev = new_decode_dev(rdev);
  			if (!dev) {
  				printk(KERN_WARNING "md: Unknown device name: %s
  ", devname);
  				break;
  			}
  
  			devices[i] = dev;
  
  			devname = p;
  		}
  		devices[i] = 0;
  
  		if (!i)
  			continue;
  
  		printk(KERN_INFO "md: Loading md%s%d: %s
  ",
  			partitioned ? "_d" : "", minor,
  			md_setup_args[ent].device_names);
bae217ea8   Dominik Brodowski   fs: add ksys_open...
177
  		fd = ksys_open(name, 0, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178
179
180
181
182
183
  		if (fd < 0) {
  			printk(KERN_ERR "md: open failed - cannot start "
  					"array %s
  ", name);
  			continue;
  		}
cbb60b924   Dominik Brodowski   fs: add ksys_ioct...
184
  		if (ksys_ioctl(fd, SET_ARRAY_INFO, 0) == -EBUSY) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
185
186
187
188
  			printk(KERN_WARNING
  			       "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)
  ",
  			       minor);
2ca2a09d6   Dominik Brodowski   fs: add ksys_clos...
189
  			ksys_close(fd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
190
191
  			continue;
  		}
2604b703b   NeilBrown   [PATCH] md: remov...
192
  		if (md_setup_args[ent].level != LEVEL_NONE) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
193
194
  			/* non-persistent */
  			mdu_array_info_t ainfo;
2604b703b   NeilBrown   [PATCH] md: remov...
195
  			ainfo.level = md_setup_args[ent].level;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
196
197
198
199
200
201
202
203
204
205
206
  			ainfo.size = 0;
  			ainfo.nr_disks =0;
  			ainfo.raid_disks =0;
  			while (devices[ainfo.raid_disks])
  				ainfo.raid_disks++;
  			ainfo.md_minor =minor;
  			ainfo.not_persistent = 1;
  
  			ainfo.state = (1 << MD_SB_CLEAN);
  			ainfo.layout = 0;
  			ainfo.chunk_size = md_setup_args[ent].chunk;
cbb60b924   Dominik Brodowski   fs: add ksys_ioct...
207
  			err = ksys_ioctl(fd, SET_ARRAY_INFO, (long)&ainfo);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208
209
210
211
212
213
214
215
216
  			for (i = 0; !err && i <= MD_SB_DISKS; i++) {
  				dev = devices[i];
  				if (!dev)
  					break;
  				dinfo.number = i;
  				dinfo.raid_disk = i;
  				dinfo.state = (1<<MD_DISK_ACTIVE)|(1<<MD_DISK_SYNC);
  				dinfo.major = MAJOR(dev);
  				dinfo.minor = MINOR(dev);
cbb60b924   Dominik Brodowski   fs: add ksys_ioct...
217
218
  				err = ksys_ioctl(fd, ADD_NEW_DISK,
  						 (long)&dinfo);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
219
220
221
222
223
224
225
226
227
  			}
  		} else {
  			/* persistent */
  			for (i = 0; i <= MD_SB_DISKS; i++) {
  				dev = devices[i];
  				if (!dev)
  					break;
  				dinfo.major = MAJOR(dev);
  				dinfo.minor = MINOR(dev);
cbb60b924   Dominik Brodowski   fs: add ksys_ioct...
228
  				ksys_ioctl(fd, ADD_NEW_DISK, (long)&dinfo);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
229
230
231
  			}
  		}
  		if (!err)
cbb60b924   Dominik Brodowski   fs: add ksys_ioct...
232
  			err = ksys_ioctl(fd, RUN_ARRAY, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
233
234
235
236
237
238
239
240
241
  		if (err)
  			printk(KERN_WARNING "md: starting md%d failed
  ", minor);
  		else {
  			/* reread the partition table.
  			 * I (neilb) and not sure why this is needed, but I cannot
  			 * boot a kernel with devfs compiled in from partitioned md
  			 * array without it
  			 */
2ca2a09d6   Dominik Brodowski   fs: add ksys_clos...
242
  			ksys_close(fd);
bae217ea8   Dominik Brodowski   fs: add ksys_open...
243
  			fd = ksys_open(name, 0, 0);
cbb60b924   Dominik Brodowski   fs: add ksys_ioct...
244
  			ksys_ioctl(fd, BLKRRPART, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
245
  		}
2ca2a09d6   Dominik Brodowski   fs: add ksys_clos...
246
  		ksys_close(fd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
  	}
  }
  
  static int __init raid_setup(char *str)
  {
  	int len, pos;
  
  	len = strlen(str) + 1;
  	pos = 0;
  
  	while (pos < len) {
  		char *comma = strchr(str+pos, ',');
  		int wlen;
  		if (comma)
  			wlen = (comma-str)-pos;
  		else	wlen = (len-1)-pos;
  
  		if (!strncmp(str, "noautodetect", wlen))
  			raid_noautodetect = 1;
a364092a4   Arjan van de Ven   raid: make RAID a...
266
267
  		if (!strncmp(str, "autodetect", wlen))
  			raid_noautodetect = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
268
269
270
271
272
273
274
275
276
277
278
  		if (strncmp(str, "partitionable", wlen)==0)
  			raid_autopart = 1;
  		if (strncmp(str, "part", wlen)==0)
  			raid_autopart = 1;
  		pos += wlen+1;
  	}
  	return 1;
  }
  
  __setup("raid=", raid_setup);
  __setup("md=", md_setup);
ff083c837   Mike Frysinger   autodetect_raid: ...
279
  static void __init autodetect_raid(void)
82cbc11a4   Ingo Molnar   warning: fix init...
280
281
282
283
284
285
286
287
288
289
290
  {
  	int fd;
  
  	/*
  	 * Since we don't want to detect and use half a raid array, we need to
  	 * wait for the known devices to complete their probing
  	 */
  	printk(KERN_INFO "md: Waiting for all devices to be available before autodetect
  ");
  	printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect
  ");
216773a78   Arjan van de Ven   Consolidate drive...
291
292
  
  	wait_for_device_probe();
bae217ea8   Dominik Brodowski   fs: add ksys_open...
293
  	fd = ksys_open("/dev/md0", 0, 0);
82cbc11a4   Ingo Molnar   warning: fix init...
294
  	if (fd >= 0) {
cbb60b924   Dominik Brodowski   fs: add ksys_ioct...
295
  		ksys_ioctl(fd, RAID_AUTORUN, raid_autopart);
2ca2a09d6   Dominik Brodowski   fs: add ksys_clos...
296
  		ksys_close(fd);
82cbc11a4   Ingo Molnar   warning: fix init...
297
298
  	}
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
299
300
  void __init md_run_setup(void)
  {
bdaf85293   Greg Kroah-Hartman   [PATCH] devfs: Re...
301
  	create_dev("/dev/md0", MKDEV(MD_MAJOR, 0));
589f800bb   Arjan van de Ven   fastboot: make th...
302

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
303
  	if (raid_noautodetect)
a364092a4   Arjan van de Ven   raid: make RAID a...
304
305
  		printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=autodetect will force)
  ");
82cbc11a4   Ingo Molnar   warning: fix init...
306
307
  	else
  		autodetect_raid();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
308
309
  	md_setup_drive();
  }