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