do_mounts_md.c 7.3 KB

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