do_mounts_md.c 7.3 KB

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