raid0.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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 <trace/events/block.h>
  21. #include "md.h"
  22. #include "raid0.h"
  23. #include "raid5.h"
  24. static int raid0_congested(struct mddev *mddev, int bits)
  25. {
  26. struct r0conf *conf = mddev->private;
  27. struct md_rdev **devlist = conf->devlist;
  28. int raid_disks = conf->strip_zone[0].nb_dev;
  29. int i, ret = 0;
  30. for (i = 0; i < raid_disks && !ret ; i++) {
  31. struct request_queue *q = bdev_get_queue(devlist[i]->bdev);
  32. ret |= bdi_congested(&q->backing_dev_info, bits);
  33. }
  34. return ret;
  35. }
  36. /*
  37. * inform the user of the raid configuration
  38. */
  39. static void dump_zones(struct mddev *mddev)
  40. {
  41. int j, k;
  42. sector_t zone_size = 0;
  43. sector_t zone_start = 0;
  44. char b[BDEVNAME_SIZE];
  45. struct r0conf *conf = mddev->private;
  46. int raid_disks = conf->strip_zone[0].nb_dev;
  47. pr_debug("md: RAID0 configuration for %s - %d zone%s\n",
  48. mdname(mddev),
  49. conf->nr_strip_zones, conf->nr_strip_zones==1?"":"s");
  50. for (j = 0; j < conf->nr_strip_zones; j++) {
  51. char line[200];
  52. int len = 0;
  53. for (k = 0; k < conf->strip_zone[j].nb_dev; k++)
  54. len += snprintf(line+len, 200-len, "%s%s", k?"/":"",
  55. bdevname(conf->devlist[j*raid_disks
  56. + k]->bdev, b));
  57. pr_debug("md: zone%d=[%s]\n", j, line);
  58. zone_size = conf->strip_zone[j].zone_end - zone_start;
  59. pr_debug(" zone-offset=%10lluKB, device-offset=%10lluKB, size=%10lluKB\n",
  60. (unsigned long long)zone_start>>1,
  61. (unsigned long long)conf->strip_zone[j].dev_start>>1,
  62. (unsigned long long)zone_size>>1);
  63. zone_start = conf->strip_zone[j].zone_end;
  64. }
  65. }
  66. static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
  67. {
  68. int i, c, err;
  69. sector_t curr_zone_end, sectors;
  70. struct md_rdev *smallest, *rdev1, *rdev2, *rdev, **dev;
  71. struct strip_zone *zone;
  72. int cnt;
  73. char b[BDEVNAME_SIZE];
  74. char b2[BDEVNAME_SIZE];
  75. struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
  76. unsigned short blksize = 512;
  77. *private_conf = ERR_PTR(-ENOMEM);
  78. if (!conf)
  79. return -ENOMEM;
  80. rdev_for_each(rdev1, mddev) {
  81. pr_debug("md/raid0:%s: looking at %s\n",
  82. mdname(mddev),
  83. bdevname(rdev1->bdev, b));
  84. c = 0;
  85. /* round size to chunk_size */
  86. sectors = rdev1->sectors;
  87. sector_div(sectors, mddev->chunk_sectors);
  88. rdev1->sectors = sectors * mddev->chunk_sectors;
  89. blksize = max(blksize, queue_logical_block_size(
  90. rdev1->bdev->bd_disk->queue));
  91. rdev_for_each(rdev2, mddev) {
  92. pr_debug("md/raid0:%s: comparing %s(%llu)"
  93. " with %s(%llu)\n",
  94. mdname(mddev),
  95. bdevname(rdev1->bdev,b),
  96. (unsigned long long)rdev1->sectors,
  97. bdevname(rdev2->bdev,b2),
  98. (unsigned long long)rdev2->sectors);
  99. if (rdev2 == rdev1) {
  100. pr_debug("md/raid0:%s: END\n",
  101. mdname(mddev));
  102. break;
  103. }
  104. if (rdev2->sectors == rdev1->sectors) {
  105. /*
  106. * Not unique, don't count it as a new
  107. * group
  108. */
  109. pr_debug("md/raid0:%s: EQUAL\n",
  110. mdname(mddev));
  111. c = 1;
  112. break;
  113. }
  114. pr_debug("md/raid0:%s: NOT EQUAL\n",
  115. mdname(mddev));
  116. }
  117. if (!c) {
  118. pr_debug("md/raid0:%s: ==> UNIQUE\n",
  119. mdname(mddev));
  120. conf->nr_strip_zones++;
  121. pr_debug("md/raid0:%s: %d zones\n",
  122. mdname(mddev), conf->nr_strip_zones);
  123. }
  124. }
  125. pr_debug("md/raid0:%s: FINAL %d zones\n",
  126. mdname(mddev), conf->nr_strip_zones);
  127. /*
  128. * now since we have the hard sector sizes, we can make sure
  129. * chunk size is a multiple of that sector size
  130. */
  131. if ((mddev->chunk_sectors << 9) % blksize) {
  132. pr_warn("md/raid0:%s: chunk_size of %d not multiple of block size %d\n",
  133. mdname(mddev),
  134. mddev->chunk_sectors << 9, blksize);
  135. err = -EINVAL;
  136. goto abort;
  137. }
  138. err = -ENOMEM;
  139. conf->strip_zone = kzalloc(sizeof(struct strip_zone)*
  140. conf->nr_strip_zones, GFP_KERNEL);
  141. if (!conf->strip_zone)
  142. goto abort;
  143. conf->devlist = kzalloc(sizeof(struct md_rdev*)*
  144. conf->nr_strip_zones*mddev->raid_disks,
  145. GFP_KERNEL);
  146. if (!conf->devlist)
  147. goto abort;
  148. /* The first zone must contain all devices, so here we check that
  149. * there is a proper alignment of slots to devices and find them all
  150. */
  151. zone = &conf->strip_zone[0];
  152. cnt = 0;
  153. smallest = NULL;
  154. dev = conf->devlist;
  155. err = -EINVAL;
  156. rdev_for_each(rdev1, mddev) {
  157. int j = rdev1->raid_disk;
  158. if (mddev->level == 10) {
  159. /* taking over a raid10-n2 array */
  160. j /= 2;
  161. rdev1->new_raid_disk = j;
  162. }
  163. if (mddev->level == 1) {
  164. /* taiking over a raid1 array-
  165. * we have only one active disk
  166. */
  167. j = 0;
  168. rdev1->new_raid_disk = j;
  169. }
  170. if (j < 0) {
  171. pr_warn("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. pr_warn("md/raid0:%s: bad disk number %d - aborting!\n",
  177. mdname(mddev), j);
  178. goto abort;
  179. }
  180. if (dev[j]) {
  181. pr_warn("md/raid0:%s: multiple devices for %d - aborting!\n",
  182. 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. pr_warn("md/raid0:%s: too few disks (%d of %d) - aborting!\n",
  192. 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. pr_warn("md/raid0:%s: chunk size must be set.\n", mdname(mddev));
  320. return -EINVAL;
  321. }
  322. if (md_check_no_bitmap(mddev))
  323. return -EINVAL;
  324. /* if private is not null, we are here after takeover */
  325. if (mddev->private == NULL) {
  326. ret = create_strip_zones(mddev, &conf);
  327. if (ret < 0)
  328. return ret;
  329. mddev->private = conf;
  330. }
  331. conf = mddev->private;
  332. if (mddev->queue) {
  333. struct md_rdev *rdev;
  334. bool discard_supported = false;
  335. blk_queue_max_hw_sectors(mddev->queue, mddev->chunk_sectors);
  336. blk_queue_max_write_same_sectors(mddev->queue, mddev->chunk_sectors);
  337. blk_queue_max_discard_sectors(mddev->queue, mddev->chunk_sectors);
  338. blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9);
  339. blk_queue_io_opt(mddev->queue,
  340. (mddev->chunk_sectors << 9) * mddev->raid_disks);
  341. rdev_for_each(rdev, mddev) {
  342. disk_stack_limits(mddev->gendisk, rdev->bdev,
  343. rdev->data_offset << 9);
  344. if (blk_queue_discard(bdev_get_queue(rdev->bdev)))
  345. discard_supported = true;
  346. }
  347. if (!discard_supported)
  348. queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, mddev->queue);
  349. else
  350. queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mddev->queue);
  351. }
  352. /* calculate array device size */
  353. md_set_array_sectors(mddev, raid0_size(mddev, 0, 0));
  354. pr_debug("md/raid0:%s: md_size is %llu sectors.\n",
  355. mdname(mddev),
  356. (unsigned long long)mddev->array_sectors);
  357. if (mddev->queue) {
  358. /* calculate the max read-ahead size.
  359. * For read-ahead of large files to be effective, we need to
  360. * readahead at least twice a whole stripe. i.e. number of devices
  361. * multiplied by chunk size times 2.
  362. * If an individual device has an ra_pages greater than the
  363. * chunk size, then we will not drive that device as hard as it
  364. * wants. We consider this a configuration error: a larger
  365. * chunksize should be used in that case.
  366. */
  367. int stripe = mddev->raid_disks *
  368. (mddev->chunk_sectors << 9) / PAGE_SIZE;
  369. if (mddev->queue->backing_dev_info.ra_pages < 2* stripe)
  370. mddev->queue->backing_dev_info.ra_pages = 2* stripe;
  371. }
  372. dump_zones(mddev);
  373. ret = md_integrity_register(mddev);
  374. return ret;
  375. }
  376. static void raid0_free(struct mddev *mddev, void *priv)
  377. {
  378. struct r0conf *conf = priv;
  379. kfree(conf->strip_zone);
  380. kfree(conf->devlist);
  381. kfree(conf);
  382. }
  383. /*
  384. * Is io distribute over 1 or more chunks ?
  385. */
  386. static inline int is_io_in_chunk_boundary(struct mddev *mddev,
  387. unsigned int chunk_sects, struct bio *bio)
  388. {
  389. if (likely(is_power_of_2(chunk_sects))) {
  390. return chunk_sects >=
  391. ((bio->bi_iter.bi_sector & (chunk_sects-1))
  392. + bio_sectors(bio));
  393. } else{
  394. sector_t sector = bio->bi_iter.bi_sector;
  395. return chunk_sects >= (sector_div(sector, chunk_sects)
  396. + bio_sectors(bio));
  397. }
  398. }
  399. static void raid0_make_request(struct mddev *mddev, struct bio *bio)
  400. {
  401. struct strip_zone *zone;
  402. struct md_rdev *tmp_dev;
  403. struct bio *split;
  404. if (unlikely(bio->bi_opf & REQ_PREFLUSH)) {
  405. md_flush_request(mddev, bio);
  406. return;
  407. }
  408. do {
  409. sector_t bio_sector = bio->bi_iter.bi_sector;
  410. sector_t sector = bio_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_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. if (mddev->gendisk)
  435. trace_block_bio_remap(bdev_get_queue(split->bi_bdev),
  436. split, disk_devt(mddev->gendisk),
  437. bio_sector);
  438. generic_make_request(split);
  439. }
  440. } while (split != bio);
  441. }
  442. static void raid0_status(struct seq_file *seq, struct mddev *mddev)
  443. {
  444. seq_printf(seq, " %dk chunks", mddev->chunk_sectors / 2);
  445. return;
  446. }
  447. static void *raid0_takeover_raid45(struct mddev *mddev)
  448. {
  449. struct md_rdev *rdev;
  450. struct r0conf *priv_conf;
  451. if (mddev->degraded != 1) {
  452. pr_warn("md/raid0:%s: raid5 must be degraded! Degraded disks: %d\n",
  453. mdname(mddev),
  454. mddev->degraded);
  455. return ERR_PTR(-EINVAL);
  456. }
  457. rdev_for_each(rdev, mddev) {
  458. /* check slot number for a disk */
  459. if (rdev->raid_disk == mddev->raid_disks-1) {
  460. pr_warn("md/raid0:%s: raid5 must have missing parity disk!\n",
  461. mdname(mddev));
  462. return ERR_PTR(-EINVAL);
  463. }
  464. rdev->sectors = mddev->dev_sectors;
  465. }
  466. /* Set new parameters */
  467. mddev->new_level = 0;
  468. mddev->new_layout = 0;
  469. mddev->new_chunk_sectors = mddev->chunk_sectors;
  470. mddev->raid_disks--;
  471. mddev->delta_disks = -1;
  472. /* make sure it will be not marked as dirty */
  473. mddev->recovery_cp = MaxSector;
  474. clear_bit(MD_HAS_JOURNAL, &mddev->flags);
  475. clear_bit(MD_JOURNAL_CLEAN, &mddev->flags);
  476. create_strip_zones(mddev, &priv_conf);
  477. return priv_conf;
  478. }
  479. static void *raid0_takeover_raid10(struct mddev *mddev)
  480. {
  481. struct r0conf *priv_conf;
  482. /* Check layout:
  483. * - far_copies must be 1
  484. * - near_copies must be 2
  485. * - disks number must be even
  486. * - all mirrors must be already degraded
  487. */
  488. if (mddev->layout != ((1 << 8) + 2)) {
  489. pr_warn("md/raid0:%s:: Raid0 cannot takeover layout: 0x%x\n",
  490. mdname(mddev),
  491. mddev->layout);
  492. return ERR_PTR(-EINVAL);
  493. }
  494. if (mddev->raid_disks & 1) {
  495. pr_warn("md/raid0:%s: Raid0 cannot takeover Raid10 with odd disk number.\n",
  496. mdname(mddev));
  497. return ERR_PTR(-EINVAL);
  498. }
  499. if (mddev->degraded != (mddev->raid_disks>>1)) {
  500. pr_warn("md/raid0:%s: All mirrors must be already degraded!\n",
  501. mdname(mddev));
  502. return ERR_PTR(-EINVAL);
  503. }
  504. /* Set new parameters */
  505. mddev->new_level = 0;
  506. mddev->new_layout = 0;
  507. mddev->new_chunk_sectors = mddev->chunk_sectors;
  508. mddev->delta_disks = - mddev->raid_disks / 2;
  509. mddev->raid_disks += mddev->delta_disks;
  510. mddev->degraded = 0;
  511. /* make sure it will be not marked as dirty */
  512. mddev->recovery_cp = MaxSector;
  513. clear_bit(MD_FAILFAST_SUPPORTED, &mddev->flags);
  514. create_strip_zones(mddev, &priv_conf);
  515. return priv_conf;
  516. }
  517. static void *raid0_takeover_raid1(struct mddev *mddev)
  518. {
  519. struct r0conf *priv_conf;
  520. int chunksect;
  521. /* Check layout:
  522. * - (N - 1) mirror drives must be already faulty
  523. */
  524. if ((mddev->raid_disks - 1) != mddev->degraded) {
  525. pr_err("md/raid0:%s: (N - 1) mirrors drives must be already faulty!\n",
  526. mdname(mddev));
  527. return ERR_PTR(-EINVAL);
  528. }
  529. /*
  530. * a raid1 doesn't have the notion of chunk size, so
  531. * figure out the largest suitable size we can use.
  532. */
  533. chunksect = 64 * 2; /* 64K by default */
  534. /* The array must be an exact multiple of chunksize */
  535. while (chunksect && (mddev->array_sectors & (chunksect - 1)))
  536. chunksect >>= 1;
  537. if ((chunksect << 9) < PAGE_SIZE)
  538. /* array size does not allow a suitable chunk size */
  539. return ERR_PTR(-EINVAL);
  540. /* Set new parameters */
  541. mddev->new_level = 0;
  542. mddev->new_layout = 0;
  543. mddev->new_chunk_sectors = chunksect;
  544. mddev->chunk_sectors = chunksect;
  545. mddev->delta_disks = 1 - mddev->raid_disks;
  546. mddev->raid_disks = 1;
  547. /* make sure it will be not marked as dirty */
  548. mddev->recovery_cp = MaxSector;
  549. clear_bit(MD_FAILFAST_SUPPORTED, &mddev->flags);
  550. create_strip_zones(mddev, &priv_conf);
  551. return priv_conf;
  552. }
  553. static void *raid0_takeover(struct mddev *mddev)
  554. {
  555. /* raid0 can take over:
  556. * raid4 - if all data disks are active.
  557. * raid5 - providing it is Raid4 layout and one disk is faulty
  558. * raid10 - assuming we have all necessary active disks
  559. * raid1 - with (N -1) mirror drives faulty
  560. */
  561. if (mddev->bitmap) {
  562. pr_warn("md/raid0: %s: cannot takeover array with bitmap\n",
  563. mdname(mddev));
  564. return ERR_PTR(-EBUSY);
  565. }
  566. if (mddev->level == 4)
  567. return raid0_takeover_raid45(mddev);
  568. if (mddev->level == 5) {
  569. if (mddev->layout == ALGORITHM_PARITY_N)
  570. return raid0_takeover_raid45(mddev);
  571. pr_warn("md/raid0:%s: Raid can only takeover Raid5 with layout: %d\n",
  572. mdname(mddev), ALGORITHM_PARITY_N);
  573. }
  574. if (mddev->level == 10)
  575. return raid0_takeover_raid10(mddev);
  576. if (mddev->level == 1)
  577. return raid0_takeover_raid1(mddev);
  578. pr_warn("Takeover from raid%i to raid0 not supported\n",
  579. mddev->level);
  580. return ERR_PTR(-EINVAL);
  581. }
  582. static void raid0_quiesce(struct mddev *mddev, int state)
  583. {
  584. }
  585. static struct md_personality raid0_personality=
  586. {
  587. .name = "raid0",
  588. .level = 0,
  589. .owner = THIS_MODULE,
  590. .make_request = raid0_make_request,
  591. .run = raid0_run,
  592. .free = raid0_free,
  593. .status = raid0_status,
  594. .size = raid0_size,
  595. .takeover = raid0_takeover,
  596. .quiesce = raid0_quiesce,
  597. .congested = raid0_congested,
  598. };
  599. static int __init raid0_init (void)
  600. {
  601. return register_md_personality (&raid0_personality);
  602. }
  603. static void raid0_exit (void)
  604. {
  605. unregister_md_personality (&raid0_personality);
  606. }
  607. module_init(raid0_init);
  608. module_exit(raid0_exit);
  609. MODULE_LICENSE("GPL");
  610. MODULE_DESCRIPTION("RAID0 (striping) personality for MD");
  611. MODULE_ALIAS("md-personality-2"); /* RAID0 */
  612. MODULE_ALIAS("md-raid0");
  613. MODULE_ALIAS("md-level-0");