do_mounts_md.c 7.6 KB

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