2 raid0.c : Multiple Devices driver for Linux
3 Copyright (C) 1994-96 Marc ZYNGIER
4 <zyngier@ufr-info-p7.ibp.fr> or
6 Copyright (C) 1999, 2000 Ingo Molnar, Red Hat
8 RAID-0 management functions.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 You should have received a copy of the GNU General Public License
16 (for example /usr/src/linux/COPYING); if not, write to the Free
17 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <linux/blkdev.h>
21 #include <linux/seq_file.h>
22 #include <linux/module.h>
23 #include <linux/slab.h>
24 #include <trace/events/block.h>
29 static int default_layout = 0;
30 module_param(default_layout, int, 0644);
32 #define UNSUPPORTED_MDDEV_FLAGS \
33 ((1L << MD_HAS_JOURNAL) | \
34 (1L << MD_JOURNAL_CLEAN) | \
35 (1L << MD_FAILFAST_SUPPORTED) |\
36 (1L << MD_HAS_PPL) | \
37 (1L << MD_HAS_MULTIPLE_PPLS))
39 static int raid0_congested(struct mddev *mddev, int bits)
41 struct r0conf *conf = mddev->private;
42 struct md_rdev **devlist = conf->devlist;
43 int raid_disks = conf->strip_zone[0].nb_dev;
46 for (i = 0; i < raid_disks && !ret ; i++) {
47 struct request_queue *q = bdev_get_queue(devlist[i]->bdev);
49 ret |= bdi_congested(q->backing_dev_info, bits);
55 * inform the user of the raid configuration
57 static void dump_zones(struct mddev *mddev)
60 sector_t zone_size = 0;
61 sector_t zone_start = 0;
62 char b[BDEVNAME_SIZE];
63 struct r0conf *conf = mddev->private;
64 int raid_disks = conf->strip_zone[0].nb_dev;
65 pr_debug("md: RAID0 configuration for %s - %d zone%s\n",
67 conf->nr_strip_zones, conf->nr_strip_zones==1?"":"s");
68 for (j = 0; j < conf->nr_strip_zones; j++) {
72 for (k = 0; k < conf->strip_zone[j].nb_dev; k++)
73 len += scnprintf(line+len, 200-len, "%s%s", k?"/":"",
74 bdevname(conf->devlist[j*raid_disks
76 pr_debug("md: zone%d=[%s]\n", j, line);
78 zone_size = conf->strip_zone[j].zone_end - zone_start;
79 pr_debug(" zone-offset=%10lluKB, device-offset=%10lluKB, size=%10lluKB\n",
80 (unsigned long long)zone_start>>1,
81 (unsigned long long)conf->strip_zone[j].dev_start>>1,
82 (unsigned long long)zone_size>>1);
83 zone_start = conf->strip_zone[j].zone_end;
87 static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
90 sector_t curr_zone_end, sectors;
91 struct md_rdev *smallest, *rdev1, *rdev2, *rdev, **dev;
92 struct strip_zone *zone;
94 char b[BDEVNAME_SIZE];
95 char b2[BDEVNAME_SIZE];
96 struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
97 unsigned blksize = 512;
99 *private_conf = ERR_PTR(-ENOMEM);
102 rdev_for_each(rdev1, mddev) {
103 pr_debug("md/raid0:%s: looking at %s\n",
105 bdevname(rdev1->bdev, b));
108 /* round size to chunk_size */
109 sectors = rdev1->sectors;
110 sector_div(sectors, mddev->chunk_sectors);
111 rdev1->sectors = sectors * mddev->chunk_sectors;
113 blksize = max(blksize, queue_logical_block_size(
114 rdev1->bdev->bd_disk->queue));
116 rdev_for_each(rdev2, mddev) {
117 pr_debug("md/raid0:%s: comparing %s(%llu)"
120 bdevname(rdev1->bdev,b),
121 (unsigned long long)rdev1->sectors,
122 bdevname(rdev2->bdev,b2),
123 (unsigned long long)rdev2->sectors);
124 if (rdev2 == rdev1) {
125 pr_debug("md/raid0:%s: END\n",
129 if (rdev2->sectors == rdev1->sectors) {
131 * Not unique, don't count it as a new
134 pr_debug("md/raid0:%s: EQUAL\n",
139 pr_debug("md/raid0:%s: NOT EQUAL\n",
143 pr_debug("md/raid0:%s: ==> UNIQUE\n",
145 conf->nr_strip_zones++;
146 pr_debug("md/raid0:%s: %d zones\n",
147 mdname(mddev), conf->nr_strip_zones);
150 pr_debug("md/raid0:%s: FINAL %d zones\n",
151 mdname(mddev), conf->nr_strip_zones);
154 * now since we have the hard sector sizes, we can make sure
155 * chunk size is a multiple of that sector size
157 if ((mddev->chunk_sectors << 9) % blksize) {
158 pr_warn("md/raid0:%s: chunk_size of %d not multiple of block size %d\n",
160 mddev->chunk_sectors << 9, blksize);
166 conf->strip_zone = kcalloc(conf->nr_strip_zones,
167 sizeof(struct strip_zone),
169 if (!conf->strip_zone)
171 conf->devlist = kzalloc(array3_size(sizeof(struct md_rdev *),
172 conf->nr_strip_zones,
178 /* The first zone must contain all devices, so here we check that
179 * there is a proper alignment of slots to devices and find them all
181 zone = &conf->strip_zone[0];
186 rdev_for_each(rdev1, mddev) {
187 int j = rdev1->raid_disk;
189 if (mddev->level == 10) {
190 /* taking over a raid10-n2 array */
192 rdev1->new_raid_disk = j;
195 if (mddev->level == 1) {
196 /* taiking over a raid1 array-
197 * we have only one active disk
200 rdev1->new_raid_disk = j;
204 pr_warn("md/raid0:%s: remove inactive devices before converting to RAID0\n",
208 if (j >= mddev->raid_disks) {
209 pr_warn("md/raid0:%s: bad disk number %d - aborting!\n",
214 pr_warn("md/raid0:%s: multiple devices for %d - aborting!\n",
220 if (!smallest || (rdev1->sectors < smallest->sectors))
224 if (cnt != mddev->raid_disks) {
225 pr_warn("md/raid0:%s: too few disks (%d of %d) - aborting!\n",
226 mdname(mddev), cnt, mddev->raid_disks);
230 zone->zone_end = smallest->sectors * cnt;
232 curr_zone_end = zone->zone_end;
234 /* now do the other zones */
235 for (i = 1; i < conf->nr_strip_zones; i++)
239 zone = conf->strip_zone + i;
240 dev = conf->devlist + i * mddev->raid_disks;
242 pr_debug("md/raid0:%s: zone %d\n", mdname(mddev), i);
243 zone->dev_start = smallest->sectors;
247 for (j=0; j<cnt; j++) {
248 rdev = conf->devlist[j];
249 if (rdev->sectors <= zone->dev_start) {
250 pr_debug("md/raid0:%s: checking %s ... nope\n",
252 bdevname(rdev->bdev, b));
255 pr_debug("md/raid0:%s: checking %s ..."
256 " contained as device %d\n",
258 bdevname(rdev->bdev, b), c);
261 if (!smallest || rdev->sectors < smallest->sectors) {
263 pr_debug("md/raid0:%s: (%llu) is smallest!.\n",
265 (unsigned long long)rdev->sectors);
270 sectors = (smallest->sectors - zone->dev_start) * c;
271 pr_debug("md/raid0:%s: zone->nb_dev: %d, sectors: %llu\n",
273 zone->nb_dev, (unsigned long long)sectors);
275 curr_zone_end += sectors;
276 zone->zone_end = curr_zone_end;
278 pr_debug("md/raid0:%s: current zone start: %llu\n",
280 (unsigned long long)smallest->sectors);
283 if (conf->nr_strip_zones == 1 || conf->strip_zone[1].nb_dev == 1) {
284 conf->layout = RAID0_ORIG_LAYOUT;
285 } else if (mddev->layout == RAID0_ORIG_LAYOUT ||
286 mddev->layout == RAID0_ALT_MULTIZONE_LAYOUT) {
287 conf->layout = mddev->layout;
288 } else if (default_layout == RAID0_ORIG_LAYOUT ||
289 default_layout == RAID0_ALT_MULTIZONE_LAYOUT) {
290 conf->layout = default_layout;
292 pr_err("md/raid0:%s: cannot assemble multi-zone RAID0 with default_layout setting\n",
294 pr_err("md/raid0: please set raid0.default_layout to 1 or 2\n");
299 if (conf->layout == RAID0_ORIG_LAYOUT) {
300 for (i = 1; i < conf->nr_strip_zones; i++) {
301 sector_t first_sector = conf->strip_zone[i-1].zone_end;
303 sector_div(first_sector, mddev->chunk_sectors);
304 zone = conf->strip_zone + i;
305 /* disk_shift is first disk index used in the zone */
306 zone->disk_shift = sector_div(first_sector,
311 pr_debug("md/raid0:%s: done.\n", mdname(mddev));
312 *private_conf = conf;
316 kfree(conf->strip_zone);
317 kfree(conf->devlist);
319 *private_conf = ERR_PTR(err);
323 /* Find the zone which holds a particular offset
324 * Update *sectorp to be an offset in that zone
326 static struct strip_zone *find_zone(struct r0conf *conf,
330 struct strip_zone *z = conf->strip_zone;
331 sector_t sector = *sectorp;
333 for (i = 0; i < conf->nr_strip_zones; i++)
334 if (sector < z[i].zone_end) {
336 *sectorp = sector - z[i-1].zone_end;
343 * remaps the bio to the target device. we separate two flows.
344 * power 2 flow and a general flow for the sake of performance
346 static struct md_rdev *map_sector(struct mddev *mddev, struct strip_zone *zone,
347 sector_t sector, sector_t *sector_offset)
349 unsigned int sect_in_chunk;
351 struct r0conf *conf = mddev->private;
352 int raid_disks = conf->strip_zone[0].nb_dev;
353 unsigned int chunk_sects = mddev->chunk_sectors;
355 if (is_power_of_2(chunk_sects)) {
356 int chunksect_bits = ffz(~chunk_sects);
357 /* find the sector offset inside the chunk */
358 sect_in_chunk = sector & (chunk_sects - 1);
359 sector >>= chunksect_bits;
361 chunk = *sector_offset;
362 /* quotient is the chunk in real device*/
363 sector_div(chunk, zone->nb_dev << chunksect_bits);
365 sect_in_chunk = sector_div(sector, chunk_sects);
366 chunk = *sector_offset;
367 sector_div(chunk, chunk_sects * zone->nb_dev);
370 * position the bio over the real device
371 * real sector = chunk in device + starting of zone
372 * + the position in the chunk
374 *sector_offset = (chunk * chunk_sects) + sect_in_chunk;
375 return conf->devlist[(zone - conf->strip_zone)*raid_disks
376 + sector_div(sector, zone->nb_dev)];
379 static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disks)
381 sector_t array_sectors = 0;
382 struct md_rdev *rdev;
384 WARN_ONCE(sectors || raid_disks,
385 "%s does not support generic reshape\n", __func__);
387 rdev_for_each(rdev, mddev)
388 array_sectors += (rdev->sectors &
389 ~(sector_t)(mddev->chunk_sectors-1));
391 return array_sectors;
394 static void raid0_free(struct mddev *mddev, void *priv);
396 static int raid0_run(struct mddev *mddev)
401 if (mddev->chunk_sectors == 0) {
402 pr_warn("md/raid0:%s: chunk size must be set.\n", mdname(mddev));
405 if (md_check_no_bitmap(mddev))
408 /* if private is not null, we are here after takeover */
409 if (mddev->private == NULL) {
410 ret = create_strip_zones(mddev, &conf);
413 mddev->private = conf;
415 conf = mddev->private;
417 struct md_rdev *rdev;
418 bool discard_supported = false;
420 blk_queue_max_hw_sectors(mddev->queue, mddev->chunk_sectors);
421 blk_queue_max_write_same_sectors(mddev->queue, mddev->chunk_sectors);
422 blk_queue_max_write_zeroes_sectors(mddev->queue, mddev->chunk_sectors);
423 blk_queue_max_discard_sectors(mddev->queue, UINT_MAX);
425 blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9);
426 blk_queue_io_opt(mddev->queue,
427 (mddev->chunk_sectors << 9) * mddev->raid_disks);
429 rdev_for_each(rdev, mddev) {
430 disk_stack_limits(mddev->gendisk, rdev->bdev,
431 rdev->data_offset << 9);
432 if (blk_queue_discard(bdev_get_queue(rdev->bdev)))
433 discard_supported = true;
435 if (!discard_supported)
436 blk_queue_flag_clear(QUEUE_FLAG_DISCARD, mddev->queue);
438 blk_queue_flag_set(QUEUE_FLAG_DISCARD, mddev->queue);
441 /* calculate array device size */
442 md_set_array_sectors(mddev, raid0_size(mddev, 0, 0));
444 pr_debug("md/raid0:%s: md_size is %llu sectors.\n",
446 (unsigned long long)mddev->array_sectors);
449 /* calculate the max read-ahead size.
450 * For read-ahead of large files to be effective, we need to
451 * readahead at least twice a whole stripe. i.e. number of devices
452 * multiplied by chunk size times 2.
453 * If an individual device has an ra_pages greater than the
454 * chunk size, then we will not drive that device as hard as it
455 * wants. We consider this a configuration error: a larger
456 * chunksize should be used in that case.
458 int stripe = mddev->raid_disks *
459 (mddev->chunk_sectors << 9) / PAGE_SIZE;
460 if (mddev->queue->backing_dev_info->ra_pages < 2* stripe)
461 mddev->queue->backing_dev_info->ra_pages = 2* stripe;
466 ret = md_integrity_register(mddev);
471 static void raid0_free(struct mddev *mddev, void *priv)
473 struct r0conf *conf = priv;
475 kfree(conf->strip_zone);
476 kfree(conf->devlist);
481 * Is io distribute over 1 or more chunks ?
483 static inline int is_io_in_chunk_boundary(struct mddev *mddev,
484 unsigned int chunk_sects, struct bio *bio)
486 if (likely(is_power_of_2(chunk_sects))) {
487 return chunk_sects >=
488 ((bio->bi_iter.bi_sector & (chunk_sects-1))
491 sector_t sector = bio->bi_iter.bi_sector;
492 return chunk_sects >= (sector_div(sector, chunk_sects)
498 * Convert disk_index to the disk order in which it is read/written.
499 * For example, if we have 4 disks, they are numbered 0,1,2,3. If we
500 * write the disks starting at disk 3, then the read/write order would
501 * be disk 3, then 0, then 1, and then disk 2 and we want map_disk_shift()
502 * to map the disks as follows 0,1,2,3 => 1,2,3,0. So disk 0 would map
503 * to 1, 1 to 2, 2 to 3, and 3 to 0. That way we can compare disks in
504 * that 'output' space to understand the read/write disk ordering.
506 static int map_disk_shift(int disk_index, int num_disks, int disk_shift)
508 return ((disk_index + num_disks - disk_shift) % num_disks);
511 static void raid0_handle_discard(struct mddev *mddev, struct bio *bio)
513 struct r0conf *conf = mddev->private;
514 struct strip_zone *zone;
515 sector_t start = bio->bi_iter.bi_sector;
517 unsigned int stripe_size;
518 sector_t first_stripe_index, last_stripe_index;
519 sector_t start_disk_offset;
520 unsigned int start_disk_index;
521 sector_t end_disk_offset;
522 unsigned int end_disk_index;
524 sector_t orig_start, orig_end;
527 zone = find_zone(conf, &start);
529 if (bio_end_sector(bio) > zone->zone_end) {
530 struct bio *split = bio_split(bio,
531 zone->zone_end - bio->bi_iter.bi_sector, GFP_NOIO,
533 bio_chain(split, bio);
534 generic_make_request(bio);
536 end = zone->zone_end;
538 end = bio_end_sector(bio);
541 if (zone != conf->strip_zone)
542 end = end - zone[-1].zone_end;
544 /* Now start and end is the offset in zone */
545 stripe_size = zone->nb_dev * mddev->chunk_sectors;
547 first_stripe_index = start;
548 sector_div(first_stripe_index, stripe_size);
549 last_stripe_index = end;
550 sector_div(last_stripe_index, stripe_size);
552 /* In the first zone the original and alternate layouts are the same */
553 if ((conf->layout == RAID0_ORIG_LAYOUT) && (zone != conf->strip_zone)) {
554 sector_div(orig_start, mddev->chunk_sectors);
555 start_disk_index = sector_div(orig_start, zone->nb_dev);
556 start_disk_index = map_disk_shift(start_disk_index,
559 sector_div(orig_end, mddev->chunk_sectors);
560 end_disk_index = sector_div(orig_end, zone->nb_dev);
561 end_disk_index = map_disk_shift(end_disk_index,
562 zone->nb_dev, zone->disk_shift);
564 start_disk_index = (int)(start - first_stripe_index * stripe_size) /
565 mddev->chunk_sectors;
566 end_disk_index = (int)(end - last_stripe_index * stripe_size) /
567 mddev->chunk_sectors;
569 start_disk_offset = ((int)(start - first_stripe_index * stripe_size) %
570 mddev->chunk_sectors) +
571 first_stripe_index * mddev->chunk_sectors;
572 end_disk_offset = ((int)(end - last_stripe_index * stripe_size) %
573 mddev->chunk_sectors) +
574 last_stripe_index * mddev->chunk_sectors;
576 for (disk = 0; disk < zone->nb_dev; disk++) {
577 sector_t dev_start, dev_end;
578 struct bio *discard_bio = NULL;
579 struct md_rdev *rdev;
582 compare_disk = map_disk_shift(disk, zone->nb_dev,
585 if (compare_disk < start_disk_index)
586 dev_start = (first_stripe_index + 1) *
587 mddev->chunk_sectors;
588 else if (compare_disk > start_disk_index)
589 dev_start = first_stripe_index * mddev->chunk_sectors;
591 dev_start = start_disk_offset;
593 if (compare_disk < end_disk_index)
594 dev_end = (last_stripe_index + 1) * mddev->chunk_sectors;
595 else if (compare_disk > end_disk_index)
596 dev_end = last_stripe_index * mddev->chunk_sectors;
598 dev_end = end_disk_offset;
600 if (dev_end <= dev_start)
603 rdev = conf->devlist[(zone - conf->strip_zone) *
604 conf->strip_zone[0].nb_dev + disk];
605 if (__blkdev_issue_discard(rdev->bdev,
606 dev_start + zone->dev_start + rdev->data_offset,
607 dev_end - dev_start, GFP_NOIO, 0, &discard_bio) ||
610 bio_chain(discard_bio, bio);
611 bio_clone_blkcg_association(discard_bio, bio);
613 trace_block_bio_remap(bdev_get_queue(rdev->bdev),
614 discard_bio, disk_devt(mddev->gendisk),
615 bio->bi_iter.bi_sector);
616 bio_clear_flag(bio, BIO_QUEUE_ENTERED);
617 generic_make_request(discard_bio);
622 static bool raid0_make_request(struct mddev *mddev, struct bio *bio)
624 struct r0conf *conf = mddev->private;
625 struct strip_zone *zone;
626 struct md_rdev *tmp_dev;
629 sector_t orig_sector;
630 unsigned chunk_sects;
633 if (unlikely(bio->bi_opf & REQ_PREFLUSH)
634 && md_flush_request(mddev, bio))
637 if (unlikely((bio_op(bio) == REQ_OP_DISCARD))) {
638 raid0_handle_discard(mddev, bio);
642 bio_sector = bio->bi_iter.bi_sector;
644 chunk_sects = mddev->chunk_sectors;
646 sectors = chunk_sects -
647 (likely(is_power_of_2(chunk_sects))
648 ? (sector & (chunk_sects-1))
649 : sector_div(sector, chunk_sects));
651 /* Restore due to sector_div */
654 if (sectors < bio_sectors(bio)) {
655 struct bio *split = bio_split(bio, sectors, GFP_NOIO,
657 bio_chain(split, bio);
658 generic_make_request(bio);
662 orig_sector = sector;
663 zone = find_zone(mddev->private, §or);
664 switch (conf->layout) {
665 case RAID0_ORIG_LAYOUT:
666 tmp_dev = map_sector(mddev, zone, orig_sector, §or);
668 case RAID0_ALT_MULTIZONE_LAYOUT:
669 tmp_dev = map_sector(mddev, zone, sector, §or);
672 WARN(1, "md/raid0:%s: Invalid layout\n", mdname(mddev));
677 bio_set_dev(bio, tmp_dev->bdev);
678 bio->bi_iter.bi_sector = sector + zone->dev_start +
679 tmp_dev->data_offset;
682 trace_block_bio_remap(bio->bi_disk->queue, bio,
683 disk_devt(mddev->gendisk), bio_sector);
684 mddev_check_writesame(mddev, bio);
685 mddev_check_write_zeroes(mddev, bio);
686 bio_clear_flag(bio, BIO_QUEUE_ENTERED);
687 generic_make_request(bio);
691 static void raid0_status(struct seq_file *seq, struct mddev *mddev)
693 seq_printf(seq, " %dk chunks", mddev->chunk_sectors / 2);
697 static void *raid0_takeover_raid45(struct mddev *mddev)
699 struct md_rdev *rdev;
700 struct r0conf *priv_conf;
702 if (mddev->degraded != 1) {
703 pr_warn("md/raid0:%s: raid5 must be degraded! Degraded disks: %d\n",
706 return ERR_PTR(-EINVAL);
709 rdev_for_each(rdev, mddev) {
710 /* check slot number for a disk */
711 if (rdev->raid_disk == mddev->raid_disks-1) {
712 pr_warn("md/raid0:%s: raid5 must have missing parity disk!\n",
714 return ERR_PTR(-EINVAL);
716 rdev->sectors = mddev->dev_sectors;
719 /* Set new parameters */
720 mddev->new_level = 0;
721 mddev->new_layout = 0;
722 mddev->new_chunk_sectors = mddev->chunk_sectors;
724 mddev->delta_disks = -1;
725 /* make sure it will be not marked as dirty */
726 mddev->recovery_cp = MaxSector;
727 mddev_clear_unsupported_flags(mddev, UNSUPPORTED_MDDEV_FLAGS);
729 create_strip_zones(mddev, &priv_conf);
734 static void *raid0_takeover_raid10(struct mddev *mddev)
736 struct r0conf *priv_conf;
739 * - far_copies must be 1
740 * - near_copies must be 2
741 * - disks number must be even
742 * - all mirrors must be already degraded
744 if (mddev->layout != ((1 << 8) + 2)) {
745 pr_warn("md/raid0:%s:: Raid0 cannot takeover layout: 0x%x\n",
748 return ERR_PTR(-EINVAL);
750 if (mddev->raid_disks & 1) {
751 pr_warn("md/raid0:%s: Raid0 cannot takeover Raid10 with odd disk number.\n",
753 return ERR_PTR(-EINVAL);
755 if (mddev->degraded != (mddev->raid_disks>>1)) {
756 pr_warn("md/raid0:%s: All mirrors must be already degraded!\n",
758 return ERR_PTR(-EINVAL);
761 /* Set new parameters */
762 mddev->new_level = 0;
763 mddev->new_layout = 0;
764 mddev->new_chunk_sectors = mddev->chunk_sectors;
765 mddev->delta_disks = - mddev->raid_disks / 2;
766 mddev->raid_disks += mddev->delta_disks;
768 /* make sure it will be not marked as dirty */
769 mddev->recovery_cp = MaxSector;
770 mddev_clear_unsupported_flags(mddev, UNSUPPORTED_MDDEV_FLAGS);
772 create_strip_zones(mddev, &priv_conf);
776 static void *raid0_takeover_raid1(struct mddev *mddev)
778 struct r0conf *priv_conf;
782 * - (N - 1) mirror drives must be already faulty
784 if ((mddev->raid_disks - 1) != mddev->degraded) {
785 pr_err("md/raid0:%s: (N - 1) mirrors drives must be already faulty!\n",
787 return ERR_PTR(-EINVAL);
791 * a raid1 doesn't have the notion of chunk size, so
792 * figure out the largest suitable size we can use.
794 chunksect = 64 * 2; /* 64K by default */
796 /* The array must be an exact multiple of chunksize */
797 while (chunksect && (mddev->array_sectors & (chunksect - 1)))
800 if ((chunksect << 9) < PAGE_SIZE)
801 /* array size does not allow a suitable chunk size */
802 return ERR_PTR(-EINVAL);
804 /* Set new parameters */
805 mddev->new_level = 0;
806 mddev->new_layout = 0;
807 mddev->new_chunk_sectors = chunksect;
808 mddev->chunk_sectors = chunksect;
809 mddev->delta_disks = 1 - mddev->raid_disks;
810 mddev->raid_disks = 1;
811 /* make sure it will be not marked as dirty */
812 mddev->recovery_cp = MaxSector;
813 mddev_clear_unsupported_flags(mddev, UNSUPPORTED_MDDEV_FLAGS);
815 create_strip_zones(mddev, &priv_conf);
819 static void *raid0_takeover(struct mddev *mddev)
821 /* raid0 can take over:
822 * raid4 - if all data disks are active.
823 * raid5 - providing it is Raid4 layout and one disk is faulty
824 * raid10 - assuming we have all necessary active disks
825 * raid1 - with (N -1) mirror drives faulty
829 pr_warn("md/raid0: %s: cannot takeover array with bitmap\n",
831 return ERR_PTR(-EBUSY);
833 if (mddev->level == 4)
834 return raid0_takeover_raid45(mddev);
836 if (mddev->level == 5) {
837 if (mddev->layout == ALGORITHM_PARITY_N)
838 return raid0_takeover_raid45(mddev);
840 pr_warn("md/raid0:%s: Raid can only takeover Raid5 with layout: %d\n",
841 mdname(mddev), ALGORITHM_PARITY_N);
844 if (mddev->level == 10)
845 return raid0_takeover_raid10(mddev);
847 if (mddev->level == 1)
848 return raid0_takeover_raid1(mddev);
850 pr_warn("Takeover from raid%i to raid0 not supported\n",
853 return ERR_PTR(-EINVAL);
856 static void raid0_quiesce(struct mddev *mddev, int quiesce)
860 static struct md_personality raid0_personality=
864 .owner = THIS_MODULE,
865 .make_request = raid0_make_request,
868 .status = raid0_status,
870 .takeover = raid0_takeover,
871 .quiesce = raid0_quiesce,
872 .congested = raid0_congested,
875 static int __init raid0_init (void)
877 return register_md_personality (&raid0_personality);
880 static void raid0_exit (void)
882 unregister_md_personality (&raid0_personality);
885 module_init(raid0_init);
886 module_exit(raid0_exit);
887 MODULE_LICENSE("GPL");
888 MODULE_DESCRIPTION("RAID0 (striping) personality for MD");
889 MODULE_ALIAS("md-personality-2"); /* RAID0 */
890 MODULE_ALIAS("md-raid0");
891 MODULE_ALIAS("md-level-0");