do_mounts_md.c 7.9 KB

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