raid0.c 19 KB

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