Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2#include <linux/kernel.h>
  3#include <linux/blkdev.h>
  4#include <linux/init.h>
  5#include <linux/mount.h>
  6#include <linux/major.h>
  7#include <linux/delay.h>
  8#include <linux/init_syscalls.h>
  9#include <linux/raid/detect.h>
 10#include <linux/raid/md_u.h>
 11#include <linux/raid/md_p.h>
 12#include "md.h"
 13
 14/*
 15 * When md (and any require personalities) are compiled into the kernel
 16 * (not a module), arrays can be assembles are boot time using with AUTODETECT
 17 * where specially marked partitions are registered with md_autodetect_dev(),
 18 * and with MD_BOOT where devices to be collected are given on the boot line
 19 * with md=.....
 20 * The code for that is here.
 21 */
 22
 23#ifdef CONFIG_MD_AUTODETECT
 24static int __initdata raid_noautodetect;
 25#else
 26static int __initdata raid_noautodetect=1;
 27#endif
 28static int __initdata raid_autopart;
 29
 30static struct md_setup_args {
 31	int minor;
 32	int partitioned;
 33	int level;
 34	int chunk;
 35	char *device_names;
 36} md_setup_args[256] __initdata;
 37
 38static int md_setup_ents __initdata;
 39
 40/*
 41 * Parse the command-line parameters given our kernel, but do not
 42 * actually try to invoke the MD device now; that is handled by
 43 * md_setup_drive after the low-level disk drivers have initialised.
 44 *
 45 * 27/11/1999: Fixed to work correctly with the 2.3 kernel (which
 46 *             assigns the task of parsing integer arguments to the
 47 *             invoked program now).  Added ability to initialise all
 48 *             the MD devices (by specifying multiple "md=" lines)
 49 *             instead of just one.  -- KTK
 50 * 18May2000: Added support for persistent-superblock arrays:
 51 *             md=n,0,factor,fault,device-list   uses RAID0 for device n
 
 52 *             md=n,device-list      reads a RAID superblock from the devices
 53 *             elements in device-list are read by name_to_kdev_t so can be
 54 *             a hex number or something like /dev/hda1 /dev/sdb
 55 * 2001-06-03: Dave Cinege <dcinege@psychosis.com>
 56 *		Shifted name_to_kdev_t() and related operations to md_set_drive()
 57 *		for later execution. Rewrote section to make devfs compatible.
 58 */
 59static int __init md_setup(char *str)
 60{
 61	int minor, level, factor, fault, partitioned = 0;
 62	char *pername = "";
 63	char *str1;
 64	int ent;
 65
 66	if (*str == 'd') {
 67		partitioned = 1;
 68		str++;
 69	}
 70	if (get_option(&str, &minor) != 2) {	/* MD Number */
 71		printk(KERN_WARNING "md: Too few arguments supplied to md=.\n");
 72		return 0;
 73	}
 74	str1 = str;
 75	for (ent=0 ; ent< md_setup_ents ; ent++)
 76		if (md_setup_args[ent].minor == minor &&
 77		    md_setup_args[ent].partitioned == partitioned) {
 78			printk(KERN_WARNING "md: md=%s%d, Specified more than once. "
 79			       "Replacing previous definition.\n", partitioned?"d":"", minor);
 80			break;
 81		}
 82	if (ent >= ARRAY_SIZE(md_setup_args)) {
 83		printk(KERN_WARNING "md: md=%s%d - too many md initialisations\n", partitioned?"d":"", minor);
 84		return 0;
 85	}
 86	if (ent >= md_setup_ents)
 87		md_setup_ents++;
 88	switch (get_option(&str, &level)) {	/* RAID level */
 89	case 2: /* could be 0 or -1.. */
 90		if (level == 0) {
 91			if (get_option(&str, &factor) != 2 ||	/* Chunk Size */
 92					get_option(&str, &fault) != 2) {
 93				printk(KERN_WARNING "md: Too few arguments supplied to md=.\n");
 94				return 0;
 95			}
 96			md_setup_args[ent].level = level;
 97			md_setup_args[ent].chunk = 1 << (factor+12);
 98			pername = "raid0";
 
 
 
 99			break;
100		}
101		fallthrough;
102	case 1: /* the first device is numeric */
103		str = str1;
104		fallthrough;
105	case 0:
106		md_setup_args[ent].level = LEVEL_NONE;
107		pername="super-block";
108	}
109
110	printk(KERN_INFO "md: Will configure md%d (%s) from %s, below.\n",
111		minor, pername, str);
112	md_setup_args[ent].device_names = str;
113	md_setup_args[ent].partitioned = partitioned;
114	md_setup_args[ent].minor = minor;
115
116	return 1;
117}
118
119static void __init md_setup_drive(struct md_setup_args *args)
120{
121	char *devname = args->device_names;
122	dev_t devices[MD_SB_DISKS + 1], mdev;
123	struct mdu_array_info_s ainfo = { };
124	struct mddev *mddev;
125	int err = 0, i;
126	char name[16];
127
128	if (args->partitioned) {
129		mdev = MKDEV(mdp_major, args->minor << MdpMinorShift);
130		sprintf(name, "md_d%d", args->minor);
131	} else {
132		mdev = MKDEV(MD_MAJOR, args->minor);
133		sprintf(name, "md%d", args->minor);
134	}
135
136	for (i = 0; i < MD_SB_DISKS && devname != NULL; i++) {
137		struct kstat stat;
138		char *p;
139		char comp_name[64];
140		dev_t dev;
141
142		p = strchr(devname, ',');
143		if (p)
144			*p++ = 0;
145
146		if (early_lookup_bdev(devname, &dev))
147			dev = 0;
148		if (strncmp(devname, "/dev/", 5) == 0)
149			devname += 5;
150		snprintf(comp_name, 63, "/dev/%s", devname);
151		if (init_stat(comp_name, &stat, 0) == 0 && S_ISBLK(stat.mode))
152			dev = new_decode_dev(stat.rdev);
153		if (!dev) {
154			pr_warn("md: Unknown device name: %s\n", devname);
155			break;
156		}
157
158		devices[i] = dev;
159		devname = p;
160	}
161	devices[i] = 0;
162
163	if (!i)
164		return;
165
166	pr_info("md: Loading %s: %s\n", name, args->device_names);
167
168	mddev = md_alloc(mdev, name);
169	if (IS_ERR(mddev)) {
170		pr_err("md: md_alloc failed - cannot start array %s\n", name);
171		return;
172	}
173
174	err = mddev_suspend_and_lock(mddev);
175	if (err) {
176		pr_err("md: failed to lock array %s\n", name);
177		goto out_mddev_put;
178	}
179
180	if (!list_empty(&mddev->disks) || mddev->raid_disks) {
181		pr_warn("md: Ignoring %s, already autodetected. (Use raid=noautodetect)\n",
182		       name);
183		goto out_unlock;
184	}
185
186	if (args->level != LEVEL_NONE) {
187		/* non-persistent */
188		ainfo.level = args->level;
189		ainfo.md_minor = args->minor;
190		ainfo.not_persistent = 1;
191		ainfo.state = (1 << MD_SB_CLEAN);
192		ainfo.chunk_size = args->chunk;
193		while (devices[ainfo.raid_disks])
194			ainfo.raid_disks++;
195	}
196
197	err = md_set_array_info(mddev, &ainfo);
198
199	for (i = 0; i <= MD_SB_DISKS && devices[i]; i++) {
200		struct mdu_disk_info_s dinfo = {
201			.major	= MAJOR(devices[i]),
202			.minor	= MINOR(devices[i]),
203		};
204
205		if (args->level != LEVEL_NONE) {
206			dinfo.number = i;
207			dinfo.raid_disk = i;
208			dinfo.state =
209				(1 << MD_DISK_ACTIVE) | (1 << MD_DISK_SYNC);
210		}
211
212		md_add_new_disk(mddev, &dinfo);
213	}
214
215	if (!err)
216		err = do_md_run(mddev);
217	if (err)
218		pr_warn("md: starting %s failed\n", name);
219out_unlock:
220	mddev_unlock_and_resume(mddev);
221out_mddev_put:
222	mddev_put(mddev);
223}
224
225static int __init raid_setup(char *str)
226{
227	int len, pos;
228
229	len = strlen(str) + 1;
230	pos = 0;
231
232	while (pos < len) {
233		char *comma = strchr(str+pos, ',');
234		int wlen;
235		if (comma)
236			wlen = (comma-str)-pos;
237		else	wlen = (len-1)-pos;
238
239		if (!strncmp(str, "noautodetect", wlen))
240			raid_noautodetect = 1;
241		if (!strncmp(str, "autodetect", wlen))
242			raid_noautodetect = 0;
243		if (strncmp(str, "partitionable", wlen)==0)
244			raid_autopart = 1;
245		if (strncmp(str, "part", wlen)==0)
246			raid_autopart = 1;
247		pos += wlen+1;
248	}
249	return 1;
250}
251
252__setup("raid=", raid_setup);
253__setup("md=", md_setup);
254
255static void __init autodetect_raid(void)
256{
257	/*
258	 * Since we don't want to detect and use half a raid array, we need to
259	 * wait for the known devices to complete their probing
260	 */
261	printk(KERN_INFO "md: Waiting for all devices to be available before autodetect\n");
262	printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect\n");
263
264	wait_for_device_probe();
265	md_autostart_arrays(raid_autopart);
266}
267
268void __init md_run_setup(void)
269{
270	int ent;
271
272	if (raid_noautodetect)
273		printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=autodetect will force)\n");
274	else
275		autodetect_raid();
276
277	for (ent = 0; ent < md_setup_ents; ent++)
278		md_setup_drive(&md_setup_args[ent]);
279}
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0
  2#include <linux/kernel.h>
  3#include <linux/blkdev.h>
  4#include <linux/init.h>
  5#include <linux/mount.h>
  6#include <linux/major.h>
  7#include <linux/delay.h>
  8#include <linux/init_syscalls.h>
  9#include <linux/raid/detect.h>
 10#include <linux/raid/md_u.h>
 11#include <linux/raid/md_p.h>
 12#include "md.h"
 13
 14/*
 15 * When md (and any require personalities) are compiled into the kernel
 16 * (not a module), arrays can be assembles are boot time using with AUTODETECT
 17 * where specially marked partitions are registered with md_autodetect_dev(),
 18 * and with MD_BOOT where devices to be collected are given on the boot line
 19 * with md=.....
 20 * The code for that is here.
 21 */
 22
 23#ifdef CONFIG_MD_AUTODETECT
 24static int __initdata raid_noautodetect;
 25#else
 26static int __initdata raid_noautodetect=1;
 27#endif
 28static int __initdata raid_autopart;
 29
 30static struct md_setup_args {
 31	int minor;
 32	int partitioned;
 33	int level;
 34	int chunk;
 35	char *device_names;
 36} md_setup_args[256] __initdata;
 37
 38static int md_setup_ents __initdata;
 39
 40/*
 41 * Parse the command-line parameters given our kernel, but do not
 42 * actually try to invoke the MD device now; that is handled by
 43 * md_setup_drive after the low-level disk drivers have initialised.
 44 *
 45 * 27/11/1999: Fixed to work correctly with the 2.3 kernel (which
 46 *             assigns the task of parsing integer arguments to the
 47 *             invoked program now).  Added ability to initialise all
 48 *             the MD devices (by specifying multiple "md=" lines)
 49 *             instead of just one.  -- KTK
 50 * 18May2000: Added support for persistent-superblock arrays:
 51 *             md=n,0,factor,fault,device-list   uses RAID0 for device n
 52 *             md=n,-1,factor,fault,device-list  uses LINEAR for device n
 53 *             md=n,device-list      reads a RAID superblock from the devices
 54 *             elements in device-list are read by name_to_kdev_t so can be
 55 *             a hex number or something like /dev/hda1 /dev/sdb
 56 * 2001-06-03: Dave Cinege <dcinege@psychosis.com>
 57 *		Shifted name_to_kdev_t() and related operations to md_set_drive()
 58 *		for later execution. Rewrote section to make devfs compatible.
 59 */
 60static int __init md_setup(char *str)
 61{
 62	int minor, level, factor, fault, partitioned = 0;
 63	char *pername = "";
 64	char *str1;
 65	int ent;
 66
 67	if (*str == 'd') {
 68		partitioned = 1;
 69		str++;
 70	}
 71	if (get_option(&str, &minor) != 2) {	/* MD Number */
 72		printk(KERN_WARNING "md: Too few arguments supplied to md=.\n");
 73		return 0;
 74	}
 75	str1 = str;
 76	for (ent=0 ; ent< md_setup_ents ; ent++)
 77		if (md_setup_args[ent].minor == minor &&
 78		    md_setup_args[ent].partitioned == partitioned) {
 79			printk(KERN_WARNING "md: md=%s%d, Specified more than once. "
 80			       "Replacing previous definition.\n", partitioned?"d":"", minor);
 81			break;
 82		}
 83	if (ent >= ARRAY_SIZE(md_setup_args)) {
 84		printk(KERN_WARNING "md: md=%s%d - too many md initialisations\n", partitioned?"d":"", minor);
 85		return 0;
 86	}
 87	if (ent >= md_setup_ents)
 88		md_setup_ents++;
 89	switch (get_option(&str, &level)) {	/* RAID level */
 90	case 2: /* could be 0 or -1.. */
 91		if (level == 0 || level == LEVEL_LINEAR) {
 92			if (get_option(&str, &factor) != 2 ||	/* Chunk Size */
 93					get_option(&str, &fault) != 2) {
 94				printk(KERN_WARNING "md: Too few arguments supplied to md=.\n");
 95				return 0;
 96			}
 97			md_setup_args[ent].level = level;
 98			md_setup_args[ent].chunk = 1 << (factor+12);
 99			if (level ==  LEVEL_LINEAR)
100				pername = "linear";
101			else
102				pername = "raid0";
103			break;
104		}
105		fallthrough;
106	case 1: /* the first device is numeric */
107		str = str1;
108		fallthrough;
109	case 0:
110		md_setup_args[ent].level = LEVEL_NONE;
111		pername="super-block";
112	}
113
114	printk(KERN_INFO "md: Will configure md%d (%s) from %s, below.\n",
115		minor, pername, str);
116	md_setup_args[ent].device_names = str;
117	md_setup_args[ent].partitioned = partitioned;
118	md_setup_args[ent].minor = minor;
119
120	return 1;
121}
122
123static void __init md_setup_drive(struct md_setup_args *args)
124{
125	char *devname = args->device_names;
126	dev_t devices[MD_SB_DISKS + 1], mdev;
127	struct mdu_array_info_s ainfo = { };
128	struct mddev *mddev;
129	int err = 0, i;
130	char name[16];
131
132	if (args->partitioned) {
133		mdev = MKDEV(mdp_major, args->minor << MdpMinorShift);
134		sprintf(name, "md_d%d", args->minor);
135	} else {
136		mdev = MKDEV(MD_MAJOR, args->minor);
137		sprintf(name, "md%d", args->minor);
138	}
139
140	for (i = 0; i < MD_SB_DISKS && devname != NULL; i++) {
141		struct kstat stat;
142		char *p;
143		char comp_name[64];
144		dev_t dev;
145
146		p = strchr(devname, ',');
147		if (p)
148			*p++ = 0;
149
150		if (early_lookup_bdev(devname, &dev))
151			dev = 0;
152		if (strncmp(devname, "/dev/", 5) == 0)
153			devname += 5;
154		snprintf(comp_name, 63, "/dev/%s", devname);
155		if (init_stat(comp_name, &stat, 0) == 0 && S_ISBLK(stat.mode))
156			dev = new_decode_dev(stat.rdev);
157		if (!dev) {
158			pr_warn("md: Unknown device name: %s\n", devname);
159			break;
160		}
161
162		devices[i] = dev;
163		devname = p;
164	}
165	devices[i] = 0;
166
167	if (!i)
168		return;
169
170	pr_info("md: Loading %s: %s\n", name, args->device_names);
171
172	mddev = md_alloc(mdev, name);
173	if (IS_ERR(mddev)) {
174		pr_err("md: md_alloc failed - cannot start array %s\n", name);
175		return;
176	}
177
178	err = mddev_suspend_and_lock(mddev);
179	if (err) {
180		pr_err("md: failed to lock array %s\n", name);
181		goto out_mddev_put;
182	}
183
184	if (!list_empty(&mddev->disks) || mddev->raid_disks) {
185		pr_warn("md: Ignoring %s, already autodetected. (Use raid=noautodetect)\n",
186		       name);
187		goto out_unlock;
188	}
189
190	if (args->level != LEVEL_NONE) {
191		/* non-persistent */
192		ainfo.level = args->level;
193		ainfo.md_minor = args->minor;
194		ainfo.not_persistent = 1;
195		ainfo.state = (1 << MD_SB_CLEAN);
196		ainfo.chunk_size = args->chunk;
197		while (devices[ainfo.raid_disks])
198			ainfo.raid_disks++;
199	}
200
201	err = md_set_array_info(mddev, &ainfo);
202
203	for (i = 0; i <= MD_SB_DISKS && devices[i]; i++) {
204		struct mdu_disk_info_s dinfo = {
205			.major	= MAJOR(devices[i]),
206			.minor	= MINOR(devices[i]),
207		};
208
209		if (args->level != LEVEL_NONE) {
210			dinfo.number = i;
211			dinfo.raid_disk = i;
212			dinfo.state =
213				(1 << MD_DISK_ACTIVE) | (1 << MD_DISK_SYNC);
214		}
215
216		md_add_new_disk(mddev, &dinfo);
217	}
218
219	if (!err)
220		err = do_md_run(mddev);
221	if (err)
222		pr_warn("md: starting %s failed\n", name);
223out_unlock:
224	mddev_unlock_and_resume(mddev);
225out_mddev_put:
226	mddev_put(mddev);
227}
228
229static int __init raid_setup(char *str)
230{
231	int len, pos;
232
233	len = strlen(str) + 1;
234	pos = 0;
235
236	while (pos < len) {
237		char *comma = strchr(str+pos, ',');
238		int wlen;
239		if (comma)
240			wlen = (comma-str)-pos;
241		else	wlen = (len-1)-pos;
242
243		if (!strncmp(str, "noautodetect", wlen))
244			raid_noautodetect = 1;
245		if (!strncmp(str, "autodetect", wlen))
246			raid_noautodetect = 0;
247		if (strncmp(str, "partitionable", wlen)==0)
248			raid_autopart = 1;
249		if (strncmp(str, "part", wlen)==0)
250			raid_autopart = 1;
251		pos += wlen+1;
252	}
253	return 1;
254}
255
256__setup("raid=", raid_setup);
257__setup("md=", md_setup);
258
259static void __init autodetect_raid(void)
260{
261	/*
262	 * Since we don't want to detect and use half a raid array, we need to
263	 * wait for the known devices to complete their probing
264	 */
265	printk(KERN_INFO "md: Waiting for all devices to be available before autodetect\n");
266	printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect\n");
267
268	wait_for_device_probe();
269	md_autostart_arrays(raid_autopart);
270}
271
272void __init md_run_setup(void)
273{
274	int ent;
275
276	if (raid_noautodetect)
277		printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=autodetect will force)\n");
278	else
279		autodetect_raid();
280
281	for (ent = 0; ent < md_setup_ents; ent++)
282		md_setup_drive(&md_setup_args[ent]);
283}