raid0.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*
  2. raid0.c : Multiple Devices driver for Linux
  3. Copyright (C) 1994-96 Marc ZYNGIER
  4. <zyngier@ufr-info-p7.ibp.fr> or
  5. <maz@gloups.fdn.fr>
  6. Copyright (C) 1999, 2000 Ingo Molnar, Red Hat
  7. RAID-0 management functions.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2, or (at your option)
  11. any later version.
  12. You should have received a copy of the GNU General Public License
  13. (for example /usr/src/linux/COPYING); if not, write to the Free
  14. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <linux/blkdev.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/module.h>
  19. #include <linux/slab.h>
  20. #include "md.h"
  21. #include "raid0.h"
  22. #include "raid5.h"
  23. static int raid0_congested(struct mddev *mddev, int bits)
  24. {
  25. struct r0conf *conf = mddev->private;
  26. struct md_rdev **devlist = conf->devlist;
  27. int raid_disks = conf->strip_zone[0].nb_dev;
  28. int i, ret = 0;
  29. for (i = 0; i < raid_disks && !ret ; i++) {
  30. struct request_queue *q = bdev_get_queue(devlist[i]->bdev);
  31. ret |= bdi_congested(&q->backing_dev_info, bits);
  32. }
  33. return ret;
  34. }
  35. /*
  36. * inform the user of the raid configuration
  37. */
  38. static void dump_zones(struct mddev *mddev)
  39. {
  40. int j, k;
  41. sector_t zone_size = 0;
  42. sector_t zone_start = 0;
  43. char b[BDEVNAME_SIZE];
  44. struct r0conf *conf = mddev->private;
  45. int raid_disks = conf->strip_zone[0].nb_dev;
  46. printk(KERN_INFO "md: RAID0 configuration for %s - %d zone%s\n",
  47. mdname(mddev),
  48. conf->nr_strip_zones, conf->nr_strip_zones==1?"":"s");
  49. for (j = 0; j < conf->nr_strip_zones; j++) {
  50. printk(KERN_INFO "md: zone%d=[", j);
  51. for (k = 0; k < conf->strip_zone[j].nb_dev; k++)
  52. printk(KERN_CONT "%s%s", k?"/":"",
  53. bdevname(conf->devlist[j*raid_disks
  54. + k]->bdev, b));
  55. printk(KERN_CONT "]\n");
  56. zone_size = conf->strip_zone[j].zone_end - zone_start;
  57. printk(KERN_INFO " zone-offset=%10lluKB, "
  58. "device-offset=%10lluKB, size=%10lluKB\n",
  59. (unsigned long long)zone_start>>1,
  60. (unsigned long long)conf->strip_zone[j].dev_start>>1,
  61. (unsigned long long)zone_size>>1);
  62. zone_start = conf->strip_zone[j].zone_end;
  63. }
  64. }
  65. static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
  66. {
  67. int i, c, err;
  68. sector_t curr_zone_end, sectors;
  69. struct md_rdev *smallest, *rdev1, *rdev2, *rdev, **dev;
  70. struct strip_zone *zone;
  71. int cnt;
  72. char b[BDEVNAME_SIZE];
  73. char b2[BDEVNAME_SIZE];
  74. struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
  75. unsigned short blksize = 512;
  76. *private_conf = ERR_PTR(-ENOMEM);
  77. if (!conf)
  78. return -ENOMEM;
  79. rdev_for_each(rdev1, mddev) {
  80. pr_debug("md/raid0:%s: looking at %s\n",
  81. mdname(mddev),
  82. bdevname(rdev1->bdev, b));
  83. c = 0;
  84. /* round size to chunk_size */
  85. sectors = rdev1->sectors;
  86. sector_div(sectors, mddev->chunk_sectors);
  87. rdev1->sectors = sectors * mddev->chunk_sectors;
  88. blksize = max(blksize, queue_logical_block_size(
  89. rdev1->bdev->bd_disk->queue));
  90. rdev_for_each(rdev2, mddev) {
  91. pr_debug("md/raid0:%s: comparing %s(%llu)"
  92. " with %s(%llu)\n",
  93. mdname(mddev),
  94. bdevname(rdev1->bdev,b),
  95. (unsigned long long)rdev1->sectors,
  96. bdevname(rdev2->bdev,b2),
  97. (unsigned long long)rdev2->sectors);
  98. if (rdev2 == rdev1) {
  99. pr_debug("md/raid0:%s: END\n",
  100. mdname(mddev));
  101. break;
  102. }
  103. if (rdev2->sectors == rdev1->sectors) {
  104. /*
  105. * Not unique, don't count it as a new
  106. * group
  107. */
  108. pr_debug("md/raid0:%s: EQUAL\n",
  109. mdname(mddev));
  110. c = 1;
  111. break;
  112. }
  113. pr_debug("md/raid0:%s: NOT EQUAL\n",
  114. mdname(mddev));
  115. }
  116. if (!c) {
  117. pr_debug("md/raid0:%s: ==> UNIQUE\n",
  118. mdname(mddev));
  119. conf->nr_strip_zones++;
  120. pr_debug("md/raid0:%s: %d zones\n",
  121. mdname(mddev), conf->nr_strip_zones);
  122. }
  123. }
  124. pr_debug("md/raid0:%s: FINAL %d zones\n",
  125. mdname(mddev), conf->nr_strip_zones);
  126. /*
  127. * now since we have the hard sector sizes, we can make sure
  128. * chunk size is a multiple of that sector size
  129. */
  130. if ((mddev->chunk_sectors << 9) % blksize) {
  131. printk(KERN_ERR "md/raid0:%s: chunk_size of %d not multiple of block size %d\n",
  132. mdname(mddev),
  133. mddev->chunk_sectors << 9, blksize);
  134. err = -EINVAL;
  135. goto abort;
  136. }
  137. err = -ENOMEM;
  138. conf->strip_zone = kzalloc(sizeof(struct strip_zone)*
  139. conf->nr_strip_zones, GFP_KERNEL);
  140. if (!conf->strip_zone)
  141. goto abort;
  142. conf->devlist = kzalloc(sizeof(struct md_rdev*)*
  143. conf->nr_strip_zones*mddev->raid_disks,
  144. GFP_KERNEL);
  145. if (!conf->devlist)
  146. goto abort;
  147. /* The first zone must contain all devices, so here we check that
  148. * there is a proper alignment of slots to devices and find them all
  149. */
  150. zone = &conf->strip_zone[0];
  151. cnt = 0;
  152. smallest = NULL;
  153. dev = conf->devlist;
  154. err = -EINVAL;
  155. rdev_for_each(rdev1, mddev) {
  156. int j = rdev1->raid_disk;
  157. if (mddev->level == 10) {
  158. /* taking over a raid10-n2 array */
  159. j /= 2;
  160. rdev1->new_raid_disk = j;
  161. }
  162. if (mddev->level == 1) {
  163. /* taiking over a raid1 array-
  164. * we have only one active disk
  165. */
  166. j = 0;
  167. rdev1->new_raid_disk = j;
  168. }
  169. if (j < 0) {
  170. printk(KERN_ERR
  171. "md/raid0:%s: remove inactive devices before converting to RAID0\n",
  172. mdname(mddev));
  173. goto abort;
  174. }
  175. if (j >= mddev->raid_disks) {
  176. printk(KERN_ERR "md/raid0:%s: bad disk number %d - "
  177. "aborting!\n", mdname(mddev), j);
  178. goto abort;
  179. }
  180. if (dev[j]) {
  181. printk(KERN_ERR "md/raid0:%s: multiple devices for %d - "
  182. "aborting!\n", mdname(mddev), j);
  183. goto abort;
  184. }
  185. dev[j] = rdev1;
  186. if (!smallest || (rdev1->sectors < smallest->sectors))
  187. smallest = rdev1;
  188. cnt++;
  189. }
  190. if (cnt != mddev->raid_disks) {
  191. printk(KERN_ERR "md/raid0:%s: too few disks (%d of %d) - "
  192. "aborting!\n", mdname(mddev), cnt, mddev->raid_disks);
  193. goto abort;
  194. }
  195. zone->nb_dev = cnt;
  196. zone->zone_end = smallest->sectors * cnt;
  197. curr_zone_end = zone->zone_end;
  198. /* now do the other zones */
  199. for (i = 1; i < conf->nr_strip_zones; i++)
  200. {
  201. int j;
  202. zone = conf->strip_zone + i;
  203. dev = conf->devlist + i * mddev->raid_disks;
  204. pr_debug("md/raid0:%s: zone %d\n", mdname(mddev), i);
  205. zone->dev_start = smallest->sectors;
  206. smallest = NULL;
  207. c = 0;
  208. for (j=0; j<cnt; j++) {
  209. rdev = conf->devlist[j];
  210. if (rdev->sectors <= zone->dev_start) {
  211. pr_debug("md/raid0:%s: checking %s ... nope\n",
  212. mdname(mddev),
  213. bdevname(rdev->bdev, b));
  214. continue;
  215. }
  216. pr_debug("md/raid0:%s: checking %s ..."
  217. " contained as device %d\n",
  218. mdname(mddev),
  219. bdevname(rdev->bdev, b), c);
  220. dev[c] = rdev;
  221. c++;
  222. if (!smallest || rdev->sectors < smallest->sectors) {
  223. smallest = rdev;
  224. pr_debug("md/raid0:%s: (%llu) is smallest!.\n",
  225. mdname(mddev),
  226. (unsigned long long)rdev->sectors);
  227. }
  228. }
  229. zone->nb_dev = c;
  230. sectors = (smallest->sectors - zone->dev_start) * c;
  231. pr_debug("md/raid0:%s: zone->nb_dev: %d, sectors: %llu\n",
  232. mdname(mddev),
  233. zone->nb_dev, (unsigned long long)sectors);
  234. curr_zone_end += sectors;
  235. zone->zone_end = curr_zone_end;
  236. pr_debug("md/raid0:%s: current zone start: %llu\n",
  237. mdname(mddev),
  238. (unsigned long long)smallest->sectors);
  239. }
  240. pr_debug("md/raid0:%s: done.\n", mdname(mddev));
  241. *private_conf = conf;
  242. return 0;
  243. abort:
  244. kfree(conf->strip_zone);
  245. kfree(conf->devlist);
  246. kfree(conf);
  247. *private_conf = ERR_PTR(err);
  248. return err;
  249. }
  250. /* Find the zone which holds a particular offset
  251. * Update *sectorp to be an offset in that zone
  252. */
  253. static struct strip_zone *find_zone(struct r0conf *conf,
  254. sector_t *sectorp)
  255. {
  256. int i;
  257. struct strip_zone *z = conf->strip_zone;
  258. sector_t sector = *sectorp;
  259. for (i = 0; i < conf->nr_strip_zones; i++)
  260. if (sector < z[i].zone_end) {
  261. if (i)
  262. *sectorp = sector - z[i-1].zone_end;
  263. return z + i;
  264. }
  265. BUG();
  266. }
  267. /*
  268. * remaps the bio to the target device. we separate two flows.
  269. * power 2 flow and a general flow for the sake of performance
  270. */
  271. static struct md_rdev *map_sector(struct mddev *mddev, struct strip_zone *zone,
  272. sector_t sector, sector_t *sector_offset)
  273. {
  274. unsigned int sect_in_chunk;
  275. sector_t chunk;
  276. struct r0conf *conf = mddev->private;
  277. int raid_disks = conf->strip_zone[0].nb_dev;
  278. unsigned int chunk_sects = mddev->chunk_sectors;
  279. if (is_power_of_2(chunk_sects)) {
  280. int chunksect_bits = ffz(~chunk_sects);
  281. /* find the sector offset inside the chunk */
  282. sect_in_chunk = sector & (chunk_sects - 1);
  283. sector >>= chunksect_bits;
  284. /* chunk in zone */
  285. chunk = *sector_offset;
  286. /* quotient is the chunk in real device*/
  287. sector_div(chunk, zone->nb_dev << chunksect_bits);
  288. } else{
  289. sect_in_chunk = sector_div(sector, chunk_sects);
  290. chunk = *sector_offset;
  291. sector_div(chunk, chunk_sects * zone->nb_dev);
  292. }
  293. /*
  294. * position the bio over the real device
  295. * real sector = chunk in device + starting of zone
  296. * + the position in the chunk
  297. */
  298. *sector_offset = (chunk * chunk_sects) + sect_in_chunk;
  299. return conf->devlist[(zone - conf->strip_zone)*raid_disks
  300. + sector_div(sector, zone->nb_dev)];
  301. }
  302. static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disks)
  303. {
  304. sector_t array_sectors = 0;
  305. struct md_rdev *rdev;
  306. WARN_ONCE(sectors || raid_disks,
  307. "%s does not support generic reshape\n", __func__);
  308. rdev_for_each(rdev, mddev)
  309. array_sectors += (rdev->sectors &
  310. ~(sector_t)(mddev->chunk_sectors-1));
  311. return array_sectors;
  312. }
  313. static void raid0_free(struct mddev *mddev, void *priv);
  314. static int raid0_run(struct mddev *mddev)
  315. {
  316. struct r0conf *conf;
  317. int ret;
  318. if (mddev->chunk_sectors == 0) {
  319. printk(KERN_ERR "md/raid0:%s: chunk size must be set.\n",
  320. mdname(mddev));
  321. return -EINVAL;
  322. }
  323. if (md_check_no_bitmap(mddev))
  324. return -EINVAL;
  325. /* if private is not null, we are here after takeover */
  326. if (mddev->private == NULL) {
  327. ret = create_strip_zones(mddev, &conf);
  328. if (ret < 0)
  329. return ret;
  330. mddev->private = conf;
  331. }
  332. conf = mddev->private;
  333. if (mddev->queue) {
  334. struct md_rdev *rdev;
  335. bool discard_supported = false;
  336. blk_queue_max_hw_sectors(mddev->queue, mddev->chunk_sectors);
  337. blk_queue_max_write_same_sectors(mddev->queue, mddev->chunk_sectors);
  338. blk_queue_max_discard_sectors(mddev->queue, mddev->chunk_sectors);
  339. blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9);
  340. blk_queue_io_opt(mddev->queue,
  341. (mddev->chunk_sectors << 9) * mddev->raid_disks);
  342. rdev_for_each(rdev, mddev) {
  343. disk_stack_limits(mddev->gendisk, rdev->bdev,
  344. rdev->data_offset << 9);
  345. if (blk_queue_discard(bdev_get_queue(rdev->bdev)))
  346. discard_supported = true;
  347. }
  348. if (!discard_supported)
  349. queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, mddev->queue);
  350. else
  351. queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mddev->queue);
  352. }
  353. /* calculate array device size */
  354. md_set_array_sectors(mddev, raid0_size(mddev, 0, 0));
  355. printk(KERN_INFO "md/raid0:%s: md_size is %llu sectors.\n",
  356. mdname(mddev),
  357. (unsigned long long)mddev->array_sectors);
  358. if (mddev->queue) {
  359. /* calculate the max read-ahead size.
  360. * For read-ahead of large files to be effective, we need to
  361. * readahead at least twice a whole stripe. i.e. number of devices
  362. * multiplied by chunk size times 2.
  363. * If an individual device has an ra_pages greater than the
  364. * chunk size, then we will not drive that device as hard as it
  365. * wants. We consider this a configuration error: a larger
  366. * chunksize should be used in that case.
  367. */
  368. int stripe = mddev->raid_disks *
  369. (mddev->chunk_sectors << 9) / PAGE_SIZE;
  370. if (mddev->queue->backing_dev_info.ra_pages < 2* stripe)
  371. mddev->queue->backing_dev_info.ra_pages = 2* stripe;
  372. }
  373. dump_zones(mddev);
  374. ret = md_integrity_register(mddev);
  375. return ret;
  376. }
  377. static void raid0_free(struct mddev *mddev, void *priv)
  378. {
  379. struct r0conf *conf = priv;
  380. kfree(conf->strip_zone);
  381. kfree(conf->devlist);
  382. kfree(conf);
  383. }
  384. /*
  385. * Is io distribute over 1 or more chunks ?
  386. */
  387. static inline int is_io_in_chunk_boundary(struct mddev *mddev,
  388. unsigned int chunk_sects, struct bio *bio)
  389. {
  390. if (likely(is_power_of_2(chunk_sects))) {
  391. return chunk_sects >=
  392. ((bio->bi_iter.bi_sector & (chunk_sects-1))
  393. + bio_sectors(bio));
  394. } else{
  395. sector_t sector = bio->bi_iter.bi_sector;
  396. return chunk_sects >= (sector_div(sector, chunk_sects)
  397. + bio_sectors(bio));
  398. }
  399. }
  400. static void raid0_make_request(struct mddev *mddev, struct bio *bio)
  401. {
  402. struct strip_zone *zone;
  403. struct md_rdev *tmp_dev;
  404. struct bio *split;
  405. if (unlikely(bio->bi_opf & REQ_PREFLUSH)) {
  406. md_flush_request(mddev, bio);
  407. return;
  408. }
  409. do {
  410. sector_t sector = bio->bi_iter.bi_sector;
  411. unsigned chunk_sects = mddev->chunk_sectors;
  412. unsigned sectors = chunk_sects -
  413. (likely(is_power_of_2(chunk_sects))
  414. ? (sector & (chunk_sects-1))
  415. : sector_div(sector, chunk_sects));
  416. /* Restore due to sector_div */
  417. sector = bio->bi_iter.bi_sector;
  418. if (sectors < bio_sectors(bio)) {
  419. split = bio_split(bio, sectors, GFP_NOIO, fs_bio_set);
  420. bio_chain(split, bio);
  421. } else {
  422. split = bio;
  423. }
  424. zone = find_zone(mddev->private, &sector);
  425. tmp_dev = map_sector(mddev, zone, sector, &sector);
  426. split->bi_bdev = tmp_dev->bdev;
  427. split->bi_iter.bi_sector = sector + zone->dev_start +
  428. tmp_dev->data_offset;
  429. if (unlikely((bio_op(split) == REQ_OP_DISCARD) &&
  430. !blk_queue_discard(bdev_get_queue(split->bi_bdev)))) {
  431. /* Just ignore it */
  432. bio_endio(split);
  433. } else
  434. generic_make_request(split);
  435. } while (split != bio);
  436. }
  437. static void raid0_status(struct seq_file *seq, struct mddev *mddev)
  438. {
  439. seq_printf(seq, " %dk chunks", mddev->chunk_sectors / 2);
  440. return;
  441. }
  442. static void *raid0_takeover_raid45(struct mddev *mddev)
  443. {
  444. struct md_rdev *rdev;
  445. struct r0conf *priv_conf;
  446. if (mddev->degraded != 1) {
  447. printk(KERN_ERR "md/raid0:%s: raid5 must be degraded! Degraded disks: %d\n",
  448. mdname(mddev),
  449. mddev->degraded);
  450. return ERR_PTR(-EINVAL);
  451. }
  452. rdev_for_each(rdev, mddev) {
  453. /* check slot number for a disk */
  454. if (rdev->raid_disk == mddev->raid_disks-1) {
  455. printk(KERN_ERR "md/raid0:%s: raid5 must have missing parity disk!\n",
  456. mdname(mddev));
  457. return ERR_PTR(-EINVAL);
  458. }
  459. rdev->sectors = mddev->dev_sectors;
  460. }
  461. /* Set new parameters */
  462. mddev->new_level = 0;
  463. mddev->new_layout = 0;
  464. mddev->new_chunk_sectors = mddev->chunk_sectors;
  465. mddev->raid_disks--;
  466. mddev->delta_disks = -1;
  467. /* make sure it will be not marked as dirty */
  468. mddev->recovery_cp = MaxSector;
  469. create_strip_zones(mddev, &priv_conf);
  470. return priv_conf;
  471. }
  472. static void *raid0_takeover_raid10(struct mddev *mddev)
  473. {
  474. struct r0conf *priv_conf;
  475. /* Check layout:
  476. * - far_copies must be 1
  477. * - near_copies must be 2
  478. * - disks number must be even
  479. * - all mirrors must be already degraded
  480. */
  481. if (mddev->layout != ((1 << 8) + 2)) {
  482. printk(KERN_ERR "md/raid0:%s:: Raid0 cannot takeover layout: 0x%x\n",
  483. mdname(mddev),
  484. mddev->layout);
  485. return ERR_PTR(-EINVAL);
  486. }
  487. if (mddev->raid_disks & 1) {
  488. printk(KERN_ERR "md/raid0:%s: Raid0 cannot takeover Raid10 with odd disk number.\n",
  489. mdname(mddev));
  490. return ERR_PTR(-EINVAL);
  491. }
  492. if (mddev->degraded != (mddev->raid_disks>>1)) {
  493. printk(KERN_ERR "md/raid0:%s: All mirrors must be already degraded!\n",
  494. mdname(mddev));
  495. return ERR_PTR(-EINVAL);
  496. }
  497. /* Set new parameters */
  498. mddev->new_level = 0;
  499. mddev->new_layout = 0;
  500. mddev->new_chunk_sectors = mddev->chunk_sectors;
  501. mddev->delta_disks = - mddev->raid_disks / 2;
  502. mddev->raid_disks += mddev->delta_disks;
  503. mddev->degraded = 0;
  504. /* make sure it will be not marked as dirty */
  505. mddev->recovery_cp = MaxSector;
  506. create_strip_zones(mddev, &priv_conf);
  507. return priv_conf;
  508. }
  509. static void *raid0_takeover_raid1(struct mddev *mddev)
  510. {
  511. struct r0conf *priv_conf;
  512. int chunksect;
  513. /* Check layout:
  514. * - (N - 1) mirror drives must be already faulty
  515. */
  516. if ((mddev->raid_disks - 1) != mddev->degraded) {
  517. printk(KERN_ERR "md/raid0:%s: (N - 1) mirrors drives must be already faulty!\n",
  518. mdname(mddev));
  519. return ERR_PTR(-EINVAL);
  520. }
  521. /*
  522. * a raid1 doesn't have the notion of chunk size, so
  523. * figure out the largest suitable size we can use.
  524. */
  525. chunksect = 64 * 2; /* 64K by default */
  526. /* The array must be an exact multiple of chunksize */
  527. while (chunksect && (mddev->array_sectors & (chunksect - 1)))
  528. chunksect >>= 1;
  529. if ((chunksect << 9) < PAGE_SIZE)
  530. /* array size does not allow a suitable chunk size */
  531. return ERR_PTR(-EINVAL);
  532. /* Set new parameters */
  533. mddev->new_level = 0;
  534. mddev->new_layout = 0;
  535. mddev->new_chunk_sectors = chunksect;
  536. mddev->chunk_sectors = chunksect;
  537. mddev->delta_disks = 1 - mddev->raid_disks;
  538. mddev->raid_disks = 1;
  539. /* make sure it will be not marked as dirty */
  540. mddev->recovery_cp = MaxSector;
  541. create_strip_zones(mddev, &priv_conf);
  542. return priv_conf;
  543. }
  544. static void *raid0_takeover(struct mddev *mddev)
  545. {
  546. /* raid0 can take over:
  547. * raid4 - if all data disks are active.
  548. * raid5 - providing it is Raid4 layout and one disk is faulty
  549. * raid10 - assuming we have all necessary active disks
  550. * raid1 - with (N -1) mirror drives faulty
  551. */
  552. if (mddev->bitmap) {
  553. printk(KERN_ERR "md/raid0: %s: cannot takeover array with bitmap\n",
  554. mdname(mddev));
  555. return ERR_PTR(-EBUSY);
  556. }
  557. if (mddev->level == 4)
  558. return raid0_takeover_raid45(mddev);
  559. if (mddev->level == 5) {
  560. if (mddev->layout == ALGORITHM_PARITY_N)
  561. return raid0_takeover_raid45(mddev);
  562. printk(KERN_ERR "md/raid0:%s: Raid can only takeover Raid5 with layout: %d\n",
  563. mdname(mddev), ALGORITHM_PARITY_N);
  564. }
  565. if (mddev->level == 10)
  566. return raid0_takeover_raid10(mddev);
  567. if (mddev->level == 1)
  568. return raid0_takeover_raid1(mddev);
  569. printk(KERN_ERR "Takeover from raid%i to raid0 not supported\n",
  570. mddev->level);
  571. return ERR_PTR(-EINVAL);
  572. }
  573. static void raid0_quiesce(struct mddev *mddev, int state)
  574. {
  575. }
  576. static struct md_personality raid0_personality=
  577. {
  578. .name = "raid0",
  579. .level = 0,
  580. .owner = THIS_MODULE,
  581. .make_request = raid0_make_request,
  582. .run = raid0_run,
  583. .free = raid0_free,
  584. .status = raid0_status,
  585. .size = raid0_size,
  586. .takeover = raid0_takeover,
  587. .quiesce = raid0_quiesce,
  588. .congested = raid0_congested,
  589. };
  590. static int __init raid0_init (void)
  591. {
  592. return register_md_personality (&raid0_personality);
  593. }
  594. static void raid0_exit (void)
  595. {
  596. unregister_md_personality (&raid0_personality);
  597. }
  598. module_init(raid0_init);
  599. module_exit(raid0_exit);
  600. MODULE_LICENSE("GPL");
  601. MODULE_DESCRIPTION("RAID0 (striping) personality for MD");
  602. MODULE_ALIAS("md-personality-2"); /* RAID0 */
  603. MODULE_ALIAS("md-raid0");
  604. MODULE_ALIAS("md-level-0");