do_mounts_md.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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], devfs_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. sprintf(devfs_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, devfs_name);
  126. for (i = 0; i < MD_SB_DISKS && devname != 0; 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, "partitionable", wlen)==0)
  234. raid_autopart = 1;
  235. if (strncmp(str, "part", wlen)==0)
  236. raid_autopart = 1;
  237. pos += wlen+1;
  238. }
  239. return 1;
  240. }
  241. __setup("raid=", raid_setup);
  242. __setup("md=", md_setup);
  243. void __init md_run_setup(void)
  244. {
  245. create_dev("/dev/md0", MKDEV(MD_MAJOR, 0), "md/0");
  246. if (raid_noautodetect)
  247. printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=noautodetect)\n");
  248. else {
  249. int fd = sys_open("/dev/md0", 0, 0);
  250. if (fd >= 0) {
  251. sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
  252. sys_close(fd);
  253. }
  254. }
  255. md_setup_drive();
  256. }