do_mounts_md.c 8.2 KB

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