do_mounts_md.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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[MAX_MD_DEVS] __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. if (minor >= MAX_MD_DEVS) {
  57. printk(KERN_WARNING "md: md=%d, Minor device number too high.\n", minor);
  58. return 0;
  59. }
  60. for (ent=0 ; ent< md_setup_ents ; ent++)
  61. if (md_setup_args[ent].minor == minor &&
  62. md_setup_args[ent].partitioned == partitioned) {
  63. printk(KERN_WARNING "md: md=%s%d, Specified more than once. "
  64. "Replacing previous definition.\n", partitioned?"d":"", minor);
  65. break;
  66. }
  67. if (ent >= MAX_MD_DEVS) {
  68. printk(KERN_WARNING "md: md=%s%d - too many md initialisations\n", partitioned?"d":"", minor);
  69. return 0;
  70. }
  71. if (ent >= md_setup_ents)
  72. md_setup_ents++;
  73. switch (get_option(&str, &level)) { /* RAID level */
  74. case 2: /* could be 0 or -1.. */
  75. if (level == 0 || level == LEVEL_LINEAR) {
  76. if (get_option(&str, &factor) != 2 || /* Chunk Size */
  77. get_option(&str, &fault) != 2) {
  78. printk(KERN_WARNING "md: Too few arguments supplied to md=.\n");
  79. return 0;
  80. }
  81. md_setup_args[ent].level = level;
  82. md_setup_args[ent].chunk = 1 << (factor+12);
  83. if (level == LEVEL_LINEAR)
  84. pername = "linear";
  85. else
  86. pername = "raid0";
  87. break;
  88. }
  89. /* FALL THROUGH */
  90. case 1: /* the first device is numeric */
  91. str = str1;
  92. /* FALL THROUGH */
  93. case 0:
  94. md_setup_args[ent].level = LEVEL_NONE;
  95. pername="super-block";
  96. }
  97. printk(KERN_INFO "md: Will configure md%d (%s) from %s, below.\n",
  98. minor, pername, str);
  99. md_setup_args[ent].device_names = str;
  100. md_setup_args[ent].partitioned = partitioned;
  101. md_setup_args[ent].minor = minor;
  102. return 1;
  103. }
  104. #define MdpMinorShift 6
  105. static void __init md_setup_drive(void)
  106. {
  107. int minor, i, ent, partitioned;
  108. dev_t dev;
  109. dev_t devices[MD_SB_DISKS+1];
  110. for (ent = 0; ent < md_setup_ents ; ent++) {
  111. int fd;
  112. int err = 0;
  113. char *devname;
  114. mdu_disk_info_t dinfo;
  115. char name[16];
  116. minor = md_setup_args[ent].minor;
  117. partitioned = md_setup_args[ent].partitioned;
  118. devname = md_setup_args[ent].device_names;
  119. sprintf(name, "/dev/md%s%d", partitioned?"_d":"", minor);
  120. if (partitioned)
  121. dev = MKDEV(mdp_major, minor << MdpMinorShift);
  122. else
  123. dev = MKDEV(MD_MAJOR, minor);
  124. create_dev(name, dev);
  125. for (i = 0; i < MD_SB_DISKS && devname != 0; i++) {
  126. char *p;
  127. char comp_name[64];
  128. u32 rdev;
  129. p = strchr(devname, ',');
  130. if (p)
  131. *p++ = 0;
  132. dev = name_to_dev_t(devname);
  133. if (strncmp(devname, "/dev/", 5) == 0)
  134. devname += 5;
  135. snprintf(comp_name, 63, "/dev/%s", devname);
  136. rdev = bstat(comp_name);
  137. if (rdev)
  138. dev = new_decode_dev(rdev);
  139. if (!dev) {
  140. printk(KERN_WARNING "md: Unknown device name: %s\n", devname);
  141. break;
  142. }
  143. devices[i] = dev;
  144. devname = p;
  145. }
  146. devices[i] = 0;
  147. if (!i)
  148. continue;
  149. printk(KERN_INFO "md: Loading md%s%d: %s\n",
  150. partitioned ? "_d" : "", minor,
  151. md_setup_args[ent].device_names);
  152. fd = sys_open(name, 0, 0);
  153. if (fd < 0) {
  154. printk(KERN_ERR "md: open failed - cannot start "
  155. "array %s\n", name);
  156. continue;
  157. }
  158. if (sys_ioctl(fd, SET_ARRAY_INFO, 0) == -EBUSY) {
  159. printk(KERN_WARNING
  160. "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n",
  161. minor);
  162. sys_close(fd);
  163. continue;
  164. }
  165. if (md_setup_args[ent].level != LEVEL_NONE) {
  166. /* non-persistent */
  167. mdu_array_info_t ainfo;
  168. ainfo.level = md_setup_args[ent].level;
  169. ainfo.size = 0;
  170. ainfo.nr_disks =0;
  171. ainfo.raid_disks =0;
  172. while (devices[ainfo.raid_disks])
  173. ainfo.raid_disks++;
  174. ainfo.md_minor =minor;
  175. ainfo.not_persistent = 1;
  176. ainfo.state = (1 << MD_SB_CLEAN);
  177. ainfo.layout = 0;
  178. ainfo.chunk_size = md_setup_args[ent].chunk;
  179. err = sys_ioctl(fd, SET_ARRAY_INFO, (long)&ainfo);
  180. for (i = 0; !err && i <= MD_SB_DISKS; i++) {
  181. dev = devices[i];
  182. if (!dev)
  183. break;
  184. dinfo.number = i;
  185. dinfo.raid_disk = i;
  186. dinfo.state = (1<<MD_DISK_ACTIVE)|(1<<MD_DISK_SYNC);
  187. dinfo.major = MAJOR(dev);
  188. dinfo.minor = MINOR(dev);
  189. err = sys_ioctl(fd, ADD_NEW_DISK, (long)&dinfo);
  190. }
  191. } else {
  192. /* persistent */
  193. for (i = 0; i <= MD_SB_DISKS; i++) {
  194. dev = devices[i];
  195. if (!dev)
  196. break;
  197. dinfo.major = MAJOR(dev);
  198. dinfo.minor = MINOR(dev);
  199. sys_ioctl(fd, ADD_NEW_DISK, (long)&dinfo);
  200. }
  201. }
  202. if (!err)
  203. err = sys_ioctl(fd, RUN_ARRAY, 0);
  204. if (err)
  205. printk(KERN_WARNING "md: starting md%d failed\n", minor);
  206. else {
  207. /* reread the partition table.
  208. * I (neilb) and not sure why this is needed, but I cannot
  209. * boot a kernel with devfs compiled in from partitioned md
  210. * array without it
  211. */
  212. sys_close(fd);
  213. fd = sys_open(name, 0, 0);
  214. sys_ioctl(fd, BLKRRPART, 0);
  215. }
  216. sys_close(fd);
  217. }
  218. }
  219. static int __init raid_setup(char *str)
  220. {
  221. int len, pos;
  222. len = strlen(str) + 1;
  223. pos = 0;
  224. while (pos < len) {
  225. char *comma = strchr(str+pos, ',');
  226. int wlen;
  227. if (comma)
  228. wlen = (comma-str)-pos;
  229. else wlen = (len-1)-pos;
  230. if (!strncmp(str, "noautodetect", wlen))
  231. raid_noautodetect = 1;
  232. if (strncmp(str, "partitionable", wlen)==0)
  233. raid_autopart = 1;
  234. if (strncmp(str, "part", wlen)==0)
  235. raid_autopart = 1;
  236. pos += wlen+1;
  237. }
  238. return 1;
  239. }
  240. __setup("raid=", raid_setup);
  241. __setup("md=", md_setup);
  242. void __init md_run_setup(void)
  243. {
  244. create_dev("/dev/md0", MKDEV(MD_MAJOR, 0));
  245. if (raid_noautodetect)
  246. printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=noautodetect)\n");
  247. else {
  248. int fd = sys_open("/dev/md0", 0, 0);
  249. if (fd >= 0) {
  250. sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
  251. sys_close(fd);
  252. }
  253. }
  254. md_setup_drive();
  255. }