aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/raid5.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/raid5.c')
-rw-r--r--drivers/md/raid5.c1390
1 files changed, 1174 insertions, 216 deletions
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 31843604049c..450066007160 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2,8 +2,11 @@
2 * raid5.c : Multiple Devices driver for Linux 2 * raid5.c : Multiple Devices driver for Linux
3 * Copyright (C) 1996, 1997 Ingo Molnar, Miguel de Icaza, Gadi Oxman 3 * Copyright (C) 1996, 1997 Ingo Molnar, Miguel de Icaza, Gadi Oxman
4 * Copyright (C) 1999, 2000 Ingo Molnar 4 * Copyright (C) 1999, 2000 Ingo Molnar
5 * Copyright (C) 2002, 2003 H. Peter Anvin
5 * 6 *
6 * RAID-5 management functions. 7 * RAID-4/5/6 management functions.
8 * Thanks to Penguin Computing for making the RAID-6 development possible
9 * by donating a test server!
7 * 10 *
8 * This program is free software; you can redistribute it and/or modify 11 * 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 12 * it under the terms of the GNU General Public License as published by
@@ -15,15 +18,38 @@
15 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 */ 19 */
17 20
21/*
22 * BITMAP UNPLUGGING:
23 *
24 * The sequencing for updating the bitmap reliably is a little
25 * subtle (and I got it wrong the first time) so it deserves some
26 * explanation.
27 *
28 * We group bitmap updates into batches. Each batch has a number.
29 * We may write out several batches at once, but that isn't very important.
30 * conf->bm_write is the number of the last batch successfully written.
31 * conf->bm_flush is the number of the last batch that was closed to
32 * new additions.
33 * When we discover that we will need to write to any block in a stripe
34 * (in add_stripe_bio) we update the in-memory bitmap and record in sh->bm_seq
35 * the number of the batch it will be in. This is bm_flush+1.
36 * When we are ready to do a write, if that batch hasn't been written yet,
37 * we plug the array and queue the stripe for later.
38 * When an unplug happens, we increment bm_flush, thus closing the current
39 * batch.
40 * When we notice that bm_flush > bm_write, we write out all pending updates
41 * to the bitmap, and advance bm_write to where bm_flush was.
42 * This may occasionally write a bit out twice, but is sure never to
43 * miss any bits.
44 */
18 45
19#include <linux/config.h>
20#include <linux/module.h> 46#include <linux/module.h>
21#include <linux/slab.h> 47#include <linux/slab.h>
22#include <linux/raid/raid5.h>
23#include <linux/highmem.h> 48#include <linux/highmem.h>
24#include <linux/bitops.h> 49#include <linux/bitops.h>
25#include <linux/kthread.h> 50#include <linux/kthread.h>
26#include <asm/atomic.h> 51#include <asm/atomic.h>
52#include "raid6.h"
27 53
28#include <linux/raid/bitmap.h> 54#include <linux/raid/bitmap.h>
29 55
@@ -68,6 +94,16 @@
68#define __inline__ 94#define __inline__
69#endif 95#endif
70 96
97#if !RAID6_USE_EMPTY_ZERO_PAGE
98/* In .bss so it's zeroed */
99const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256)));
100#endif
101
102static inline int raid6_next_disk(int disk, int raid_disks)
103{
104 disk++;
105 return (disk < raid_disks) ? disk : 0;
106}
71static void print_raid5_conf (raid5_conf_t *conf); 107static void print_raid5_conf (raid5_conf_t *conf);
72 108
73static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh) 109static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
@@ -76,12 +112,14 @@ static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
76 BUG_ON(!list_empty(&sh->lru)); 112 BUG_ON(!list_empty(&sh->lru));
77 BUG_ON(atomic_read(&conf->active_stripes)==0); 113 BUG_ON(atomic_read(&conf->active_stripes)==0);
78 if (test_bit(STRIPE_HANDLE, &sh->state)) { 114 if (test_bit(STRIPE_HANDLE, &sh->state)) {
79 if (test_bit(STRIPE_DELAYED, &sh->state)) 115 if (test_bit(STRIPE_DELAYED, &sh->state)) {
80 list_add_tail(&sh->lru, &conf->delayed_list); 116 list_add_tail(&sh->lru, &conf->delayed_list);
81 else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && 117 blk_plug_device(conf->mddev->queue);
82 conf->seq_write == sh->bm_seq) 118 } else if (test_bit(STRIPE_BIT_DELAY, &sh->state) &&
119 sh->bm_seq - conf->seq_write > 0) {
83 list_add_tail(&sh->lru, &conf->bitmap_list); 120 list_add_tail(&sh->lru, &conf->bitmap_list);
84 else { 121 blk_plug_device(conf->mddev->queue);
122 } else {
85 clear_bit(STRIPE_BIT_DELAY, &sh->state); 123 clear_bit(STRIPE_BIT_DELAY, &sh->state);
86 list_add_tail(&sh->lru, &conf->handle_list); 124 list_add_tail(&sh->lru, &conf->handle_list);
87 } 125 }
@@ -104,7 +142,7 @@ static void release_stripe(struct stripe_head *sh)
104{ 142{
105 raid5_conf_t *conf = sh->raid_conf; 143 raid5_conf_t *conf = sh->raid_conf;
106 unsigned long flags; 144 unsigned long flags;
107 145
108 spin_lock_irqsave(&conf->device_lock, flags); 146 spin_lock_irqsave(&conf->device_lock, flags);
109 __release_stripe(conf, sh); 147 __release_stripe(conf, sh);
110 spin_unlock_irqrestore(&conf->device_lock, flags); 148 spin_unlock_irqrestore(&conf->device_lock, flags);
@@ -117,7 +155,7 @@ static inline void remove_hash(struct stripe_head *sh)
117 hlist_del_init(&sh->hash); 155 hlist_del_init(&sh->hash);
118} 156}
119 157
120static void insert_hash(raid5_conf_t *conf, struct stripe_head *sh) 158static inline void insert_hash(raid5_conf_t *conf, struct stripe_head *sh)
121{ 159{
122 struct hlist_head *hp = stripe_hash(conf, sh->sector); 160 struct hlist_head *hp = stripe_hash(conf, sh->sector);
123 161
@@ -190,7 +228,7 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx, int
190 (unsigned long long)sh->sector); 228 (unsigned long long)sh->sector);
191 229
192 remove_hash(sh); 230 remove_hash(sh);
193 231
194 sh->sector = sector; 232 sh->sector = sector;
195 sh->pd_idx = pd_idx; 233 sh->pd_idx = pd_idx;
196 sh->state = 0; 234 sh->state = 0;
@@ -258,7 +296,7 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
258 < (conf->max_nr_stripes *3/4) 296 < (conf->max_nr_stripes *3/4)
259 || !conf->inactive_blocked), 297 || !conf->inactive_blocked),
260 conf->device_lock, 298 conf->device_lock,
261 unplug_slaves(conf->mddev) 299 raid5_unplug_device(conf->mddev->queue)
262 ); 300 );
263 conf->inactive_blocked = 0; 301 conf->inactive_blocked = 0;
264 } else 302 } else
@@ -269,8 +307,10 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
269 } else { 307 } else {
270 if (!test_bit(STRIPE_HANDLE, &sh->state)) 308 if (!test_bit(STRIPE_HANDLE, &sh->state))
271 atomic_inc(&conf->active_stripes); 309 atomic_inc(&conf->active_stripes);
272 if (!list_empty(&sh->lru)) 310 if (list_empty(&sh->lru) &&
273 list_del_init(&sh->lru); 311 !test_bit(STRIPE_EXPANDING, &sh->state))
312 BUG();
313 list_del_init(&sh->lru);
274 } 314 }
275 } 315 }
276 } while (sh == NULL); 316 } while (sh == NULL);
@@ -321,10 +361,9 @@ static int grow_stripes(raid5_conf_t *conf, int num)
321 return 1; 361 return 1;
322 conf->slab_cache = sc; 362 conf->slab_cache = sc;
323 conf->pool_size = devs; 363 conf->pool_size = devs;
324 while (num--) { 364 while (num--)
325 if (!grow_one_stripe(conf)) 365 if (!grow_one_stripe(conf))
326 return 1; 366 return 1;
327 }
328 return 0; 367 return 0;
329} 368}
330 369
@@ -484,6 +523,8 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
484 raid5_conf_t *conf = sh->raid_conf; 523 raid5_conf_t *conf = sh->raid_conf;
485 int disks = sh->disks, i; 524 int disks = sh->disks, i;
486 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); 525 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags);
526 char b[BDEVNAME_SIZE];
527 mdk_rdev_t *rdev;
487 528
488 if (bi->bi_size) 529 if (bi->bi_size)
489 return 1; 530 return 1;
@@ -531,25 +572,39 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
531 set_bit(R5_UPTODATE, &sh->dev[i].flags); 572 set_bit(R5_UPTODATE, &sh->dev[i].flags);
532#endif 573#endif
533 if (test_bit(R5_ReadError, &sh->dev[i].flags)) { 574 if (test_bit(R5_ReadError, &sh->dev[i].flags)) {
534 printk(KERN_INFO "raid5: read error corrected!!\n"); 575 rdev = conf->disks[i].rdev;
576 printk(KERN_INFO "raid5:%s: read error corrected (%lu sectors at %llu on %s)\n",
577 mdname(conf->mddev), STRIPE_SECTORS,
578 (unsigned long long)sh->sector + rdev->data_offset,
579 bdevname(rdev->bdev, b));
535 clear_bit(R5_ReadError, &sh->dev[i].flags); 580 clear_bit(R5_ReadError, &sh->dev[i].flags);
536 clear_bit(R5_ReWrite, &sh->dev[i].flags); 581 clear_bit(R5_ReWrite, &sh->dev[i].flags);
537 } 582 }
538 if (atomic_read(&conf->disks[i].rdev->read_errors)) 583 if (atomic_read(&conf->disks[i].rdev->read_errors))
539 atomic_set(&conf->disks[i].rdev->read_errors, 0); 584 atomic_set(&conf->disks[i].rdev->read_errors, 0);
540 } else { 585 } else {
586 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
541 int retry = 0; 587 int retry = 0;
588 rdev = conf->disks[i].rdev;
589
542 clear_bit(R5_UPTODATE, &sh->dev[i].flags); 590 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
543 atomic_inc(&conf->disks[i].rdev->read_errors); 591 atomic_inc(&rdev->read_errors);
544 if (conf->mddev->degraded) 592 if (conf->mddev->degraded)
545 printk(KERN_WARNING "raid5: read error not correctable.\n"); 593 printk(KERN_WARNING "raid5:%s: read error not correctable (sector %llu on %s).\n",
594 mdname(conf->mddev),
595 (unsigned long long)sh->sector + rdev->data_offset,
596 bdn);
546 else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) 597 else if (test_bit(R5_ReWrite, &sh->dev[i].flags))
547 /* Oh, no!!! */ 598 /* Oh, no!!! */
548 printk(KERN_WARNING "raid5: read error NOT corrected!!\n"); 599 printk(KERN_WARNING "raid5:%s: read error NOT corrected!! (sector %llu on %s).\n",
549 else if (atomic_read(&conf->disks[i].rdev->read_errors) 600 mdname(conf->mddev),
601 (unsigned long long)sh->sector + rdev->data_offset,
602 bdn);
603 else if (atomic_read(&rdev->read_errors)
550 > conf->max_nr_stripes) 604 > conf->max_nr_stripes)
551 printk(KERN_WARNING 605 printk(KERN_WARNING
552 "raid5: Too many read errors, failing device.\n"); 606 "raid5:%s: Too many read errors, failing device %s.\n",
607 mdname(conf->mddev), bdn);
553 else 608 else
554 retry = 1; 609 retry = 1;
555 if (retry) 610 if (retry)
@@ -557,7 +612,7 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
557 else { 612 else {
558 clear_bit(R5_ReadError, &sh->dev[i].flags); 613 clear_bit(R5_ReadError, &sh->dev[i].flags);
559 clear_bit(R5_ReWrite, &sh->dev[i].flags); 614 clear_bit(R5_ReWrite, &sh->dev[i].flags);
560 md_error(conf->mddev, conf->disks[i].rdev); 615 md_error(conf->mddev, rdev);
561 } 616 }
562 } 617 }
563 rdev_dec_pending(conf->disks[i].rdev, conf->mddev); 618 rdev_dec_pending(conf->disks[i].rdev, conf->mddev);
@@ -631,8 +686,7 @@ static void raid5_build_block (struct stripe_head *sh, int i)
631 dev->req.bi_private = sh; 686 dev->req.bi_private = sh;
632 687
633 dev->flags = 0; 688 dev->flags = 0;
634 if (i != sh->pd_idx) 689 dev->sector = compute_blocknr(sh, i);
635 dev->sector = compute_blocknr(sh, i);
636} 690}
637 691
638static void error(mddev_t *mddev, mdk_rdev_t *rdev) 692static void error(mddev_t *mddev, mdk_rdev_t *rdev)
@@ -659,7 +713,7 @@ static void error(mddev_t *mddev, mdk_rdev_t *rdev)
659 " Operation continuing on %d devices\n", 713 " Operation continuing on %d devices\n",
660 bdevname(rdev->bdev,b), conf->working_disks); 714 bdevname(rdev->bdev,b), conf->working_disks);
661 } 715 }
662} 716}
663 717
664/* 718/*
665 * Input: a 'big' sector number, 719 * Input: a 'big' sector number,
@@ -697,9 +751,12 @@ static sector_t raid5_compute_sector(sector_t r_sector, unsigned int raid_disks,
697 /* 751 /*
698 * Select the parity disk based on the user selected algorithm. 752 * Select the parity disk based on the user selected algorithm.
699 */ 753 */
700 if (conf->level == 4) 754 switch(conf->level) {
755 case 4:
701 *pd_idx = data_disks; 756 *pd_idx = data_disks;
702 else switch (conf->algorithm) { 757 break;
758 case 5:
759 switch (conf->algorithm) {
703 case ALGORITHM_LEFT_ASYMMETRIC: 760 case ALGORITHM_LEFT_ASYMMETRIC:
704 *pd_idx = data_disks - stripe % raid_disks; 761 *pd_idx = data_disks - stripe % raid_disks;
705 if (*dd_idx >= *pd_idx) 762 if (*dd_idx >= *pd_idx)
@@ -721,6 +778,39 @@ static sector_t raid5_compute_sector(sector_t r_sector, unsigned int raid_disks,
721 default: 778 default:
722 printk(KERN_ERR "raid5: unsupported algorithm %d\n", 779 printk(KERN_ERR "raid5: unsupported algorithm %d\n",
723 conf->algorithm); 780 conf->algorithm);
781 }
782 break;
783 case 6:
784
785 /**** FIX THIS ****/
786 switch (conf->algorithm) {
787 case ALGORITHM_LEFT_ASYMMETRIC:
788 *pd_idx = raid_disks - 1 - (stripe % raid_disks);
789 if (*pd_idx == raid_disks-1)
790 (*dd_idx)++; /* Q D D D P */
791 else if (*dd_idx >= *pd_idx)
792 (*dd_idx) += 2; /* D D P Q D */
793 break;
794 case ALGORITHM_RIGHT_ASYMMETRIC:
795 *pd_idx = stripe % raid_disks;
796 if (*pd_idx == raid_disks-1)
797 (*dd_idx)++; /* Q D D D P */
798 else if (*dd_idx >= *pd_idx)
799 (*dd_idx) += 2; /* D D P Q D */
800 break;
801 case ALGORITHM_LEFT_SYMMETRIC:
802 *pd_idx = raid_disks - 1 - (stripe % raid_disks);
803 *dd_idx = (*pd_idx + 2 + *dd_idx) % raid_disks;
804 break;
805 case ALGORITHM_RIGHT_SYMMETRIC:
806 *pd_idx = stripe % raid_disks;
807 *dd_idx = (*pd_idx + 2 + *dd_idx) % raid_disks;
808 break;
809 default:
810 printk (KERN_CRIT "raid6: unsupported algorithm %d\n",
811 conf->algorithm);
812 }
813 break;
724 } 814 }
725 815
726 /* 816 /*
@@ -742,12 +832,17 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i)
742 int chunk_number, dummy1, dummy2, dd_idx = i; 832 int chunk_number, dummy1, dummy2, dd_idx = i;
743 sector_t r_sector; 833 sector_t r_sector;
744 834
835
745 chunk_offset = sector_div(new_sector, sectors_per_chunk); 836 chunk_offset = sector_div(new_sector, sectors_per_chunk);
746 stripe = new_sector; 837 stripe = new_sector;
747 BUG_ON(new_sector != stripe); 838 BUG_ON(new_sector != stripe);
748 839
749 840 if (i == sh->pd_idx)
750 switch (conf->algorithm) { 841 return 0;
842 switch(conf->level) {
843 case 4: break;
844 case 5:
845 switch (conf->algorithm) {
751 case ALGORITHM_LEFT_ASYMMETRIC: 846 case ALGORITHM_LEFT_ASYMMETRIC:
752 case ALGORITHM_RIGHT_ASYMMETRIC: 847 case ALGORITHM_RIGHT_ASYMMETRIC:
753 if (i > sh->pd_idx) 848 if (i > sh->pd_idx)
@@ -761,7 +856,37 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i)
761 break; 856 break;
762 default: 857 default:
763 printk(KERN_ERR "raid5: unsupported algorithm %d\n", 858 printk(KERN_ERR "raid5: unsupported algorithm %d\n",
859 conf->algorithm);
860 }
861 break;
862 case 6:
863 data_disks = raid_disks - 2;
864 if (i == raid6_next_disk(sh->pd_idx, raid_disks))
865 return 0; /* It is the Q disk */
866 switch (conf->algorithm) {
867 case ALGORITHM_LEFT_ASYMMETRIC:
868 case ALGORITHM_RIGHT_ASYMMETRIC:
869 if (sh->pd_idx == raid_disks-1)
870 i--; /* Q D D D P */
871 else if (i > sh->pd_idx)
872 i -= 2; /* D D P Q D */
873 break;
874 case ALGORITHM_LEFT_SYMMETRIC:
875 case ALGORITHM_RIGHT_SYMMETRIC:
876 if (sh->pd_idx == raid_disks-1)
877 i--; /* Q D D D P */
878 else {
879 /* D D P Q D */
880 if (i < sh->pd_idx)
881 i += raid_disks;
882 i -= (sh->pd_idx + 2);
883 }
884 break;
885 default:
886 printk (KERN_CRIT "raid6: unsupported algorithm %d\n",
764 conf->algorithm); 887 conf->algorithm);
888 }
889 break;
765 } 890 }
766 891
767 chunk_number = stripe * data_disks + i; 892 chunk_number = stripe * data_disks + i;
@@ -778,10 +903,11 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i)
778 903
779 904
780/* 905/*
781 * Copy data between a page in the stripe cache, and a bio. 906 * Copy data between a page in the stripe cache, and one or more bion
782 * There are no alignment or size guarantees between the page or the 907 * The page could align with the middle of the bio, or there could be
783 * bio except that there is some overlap. 908 * several bion, each with several bio_vecs, which cover part of the page
784 * All iovecs in the bio must be considered. 909 * Multiple bion are linked together on bi_next. There may be extras
910 * at the end of this list. We ignore them.
785 */ 911 */
786static void copy_data(int frombio, struct bio *bio, 912static void copy_data(int frombio, struct bio *bio,
787 struct page *page, 913 struct page *page,
@@ -810,7 +936,7 @@ static void copy_data(int frombio, struct bio *bio,
810 if (len > 0 && page_offset + len > STRIPE_SIZE) 936 if (len > 0 && page_offset + len > STRIPE_SIZE)
811 clen = STRIPE_SIZE - page_offset; 937 clen = STRIPE_SIZE - page_offset;
812 else clen = len; 938 else clen = len;
813 939
814 if (clen > 0) { 940 if (clen > 0) {
815 char *ba = __bio_kmap_atomic(bio, i, KM_USER0); 941 char *ba = __bio_kmap_atomic(bio, i, KM_USER0);
816 if (frombio) 942 if (frombio)
@@ -862,14 +988,14 @@ static void compute_block(struct stripe_head *sh, int dd_idx)
862 set_bit(R5_UPTODATE, &sh->dev[dd_idx].flags); 988 set_bit(R5_UPTODATE, &sh->dev[dd_idx].flags);
863} 989}
864 990
865static void compute_parity(struct stripe_head *sh, int method) 991static void compute_parity5(struct stripe_head *sh, int method)
866{ 992{
867 raid5_conf_t *conf = sh->raid_conf; 993 raid5_conf_t *conf = sh->raid_conf;
868 int i, pd_idx = sh->pd_idx, disks = sh->disks, count; 994 int i, pd_idx = sh->pd_idx, disks = sh->disks, count;
869 void *ptr[MAX_XOR_BLOCKS]; 995 void *ptr[MAX_XOR_BLOCKS];
870 struct bio *chosen; 996 struct bio *chosen;
871 997
872 PRINTK("compute_parity, stripe %llu, method %d\n", 998 PRINTK("compute_parity5, stripe %llu, method %d\n",
873 (unsigned long long)sh->sector, method); 999 (unsigned long long)sh->sector, method);
874 1000
875 count = 1; 1001 count = 1;
@@ -956,9 +1082,195 @@ static void compute_parity(struct stripe_head *sh, int method)
956 clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); 1082 clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags);
957} 1083}
958 1084
1085static void compute_parity6(struct stripe_head *sh, int method)
1086{
1087 raid6_conf_t *conf = sh->raid_conf;
1088 int i, pd_idx = sh->pd_idx, qd_idx, d0_idx, disks = conf->raid_disks, count;
1089 struct bio *chosen;
1090 /**** FIX THIS: This could be very bad if disks is close to 256 ****/
1091 void *ptrs[disks];
1092
1093 qd_idx = raid6_next_disk(pd_idx, disks);
1094 d0_idx = raid6_next_disk(qd_idx, disks);
1095
1096 PRINTK("compute_parity, stripe %llu, method %d\n",
1097 (unsigned long long)sh->sector, method);
1098
1099 switch(method) {
1100 case READ_MODIFY_WRITE:
1101 BUG(); /* READ_MODIFY_WRITE N/A for RAID-6 */
1102 case RECONSTRUCT_WRITE:
1103 for (i= disks; i-- ;)
1104 if ( i != pd_idx && i != qd_idx && sh->dev[i].towrite ) {
1105 chosen = sh->dev[i].towrite;
1106 sh->dev[i].towrite = NULL;
1107
1108 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
1109 wake_up(&conf->wait_for_overlap);
1110
1111 if (sh->dev[i].written) BUG();
1112 sh->dev[i].written = chosen;
1113 }
1114 break;
1115 case CHECK_PARITY:
1116 BUG(); /* Not implemented yet */
1117 }
1118
1119 for (i = disks; i--;)
1120 if (sh->dev[i].written) {
1121 sector_t sector = sh->dev[i].sector;
1122 struct bio *wbi = sh->dev[i].written;
1123 while (wbi && wbi->bi_sector < sector + STRIPE_SECTORS) {
1124 copy_data(1, wbi, sh->dev[i].page, sector);
1125 wbi = r5_next_bio(wbi, sector);
1126 }
1127
1128 set_bit(R5_LOCKED, &sh->dev[i].flags);
1129 set_bit(R5_UPTODATE, &sh->dev[i].flags);
1130 }
1131
1132// switch(method) {
1133// case RECONSTRUCT_WRITE:
1134// case CHECK_PARITY:
1135// case UPDATE_PARITY:
1136 /* Note that unlike RAID-5, the ordering of the disks matters greatly. */
1137 /* FIX: Is this ordering of drives even remotely optimal? */
1138 count = 0;
1139 i = d0_idx;
1140 do {
1141 ptrs[count++] = page_address(sh->dev[i].page);
1142 if (count <= disks-2 && !test_bit(R5_UPTODATE, &sh->dev[i].flags))
1143 printk("block %d/%d not uptodate on parity calc\n", i,count);
1144 i = raid6_next_disk(i, disks);
1145 } while ( i != d0_idx );
1146// break;
1147// }
1148
1149 raid6_call.gen_syndrome(disks, STRIPE_SIZE, ptrs);
1150
1151 switch(method) {
1152 case RECONSTRUCT_WRITE:
1153 set_bit(R5_UPTODATE, &sh->dev[pd_idx].flags);
1154 set_bit(R5_UPTODATE, &sh->dev[qd_idx].flags);
1155 set_bit(R5_LOCKED, &sh->dev[pd_idx].flags);
1156 set_bit(R5_LOCKED, &sh->dev[qd_idx].flags);
1157 break;
1158 case UPDATE_PARITY:
1159 set_bit(R5_UPTODATE, &sh->dev[pd_idx].flags);
1160 set_bit(R5_UPTODATE, &sh->dev[qd_idx].flags);
1161 break;
1162 }
1163}
1164
1165
1166/* Compute one missing block */
1167static void compute_block_1(struct stripe_head *sh, int dd_idx, int nozero)
1168{
1169 raid6_conf_t *conf = sh->raid_conf;
1170 int i, count, disks = conf->raid_disks;
1171 void *ptr[MAX_XOR_BLOCKS], *p;
1172 int pd_idx = sh->pd_idx;
1173 int qd_idx = raid6_next_disk(pd_idx, disks);
1174
1175 PRINTK("compute_block_1, stripe %llu, idx %d\n",
1176 (unsigned long long)sh->sector, dd_idx);
1177
1178 if ( dd_idx == qd_idx ) {
1179 /* We're actually computing the Q drive */
1180 compute_parity6(sh, UPDATE_PARITY);
1181 } else {
1182 ptr[0] = page_address(sh->dev[dd_idx].page);
1183 if (!nozero) memset(ptr[0], 0, STRIPE_SIZE);
1184 count = 1;
1185 for (i = disks ; i--; ) {
1186 if (i == dd_idx || i == qd_idx)
1187 continue;
1188 p = page_address(sh->dev[i].page);
1189 if (test_bit(R5_UPTODATE, &sh->dev[i].flags))
1190 ptr[count++] = p;
1191 else
1192 printk("compute_block() %d, stripe %llu, %d"
1193 " not present\n", dd_idx,
1194 (unsigned long long)sh->sector, i);
1195
1196 check_xor();
1197 }
1198 if (count != 1)
1199 xor_block(count, STRIPE_SIZE, ptr);
1200 if (!nozero) set_bit(R5_UPTODATE, &sh->dev[dd_idx].flags);
1201 else clear_bit(R5_UPTODATE, &sh->dev[dd_idx].flags);
1202 }
1203}
1204
1205/* Compute two missing blocks */
1206static void compute_block_2(struct stripe_head *sh, int dd_idx1, int dd_idx2)
1207{
1208 raid6_conf_t *conf = sh->raid_conf;
1209 int i, count, disks = conf->raid_disks;
1210 int pd_idx = sh->pd_idx;
1211 int qd_idx = raid6_next_disk(pd_idx, disks);
1212 int d0_idx = raid6_next_disk(qd_idx, disks);
1213 int faila, failb;
1214
1215 /* faila and failb are disk numbers relative to d0_idx */
1216 /* pd_idx become disks-2 and qd_idx become disks-1 */
1217 faila = (dd_idx1 < d0_idx) ? dd_idx1+(disks-d0_idx) : dd_idx1-d0_idx;
1218 failb = (dd_idx2 < d0_idx) ? dd_idx2+(disks-d0_idx) : dd_idx2-d0_idx;
1219
1220 BUG_ON(faila == failb);
1221 if ( failb < faila ) { int tmp = faila; faila = failb; failb = tmp; }
1222
1223 PRINTK("compute_block_2, stripe %llu, idx %d,%d (%d,%d)\n",
1224 (unsigned long long)sh->sector, dd_idx1, dd_idx2, faila, failb);
1225
1226 if ( failb == disks-1 ) {
1227 /* Q disk is one of the missing disks */
1228 if ( faila == disks-2 ) {
1229 /* Missing P+Q, just recompute */
1230 compute_parity6(sh, UPDATE_PARITY);
1231 return;
1232 } else {
1233 /* We're missing D+Q; recompute D from P */
1234 compute_block_1(sh, (dd_idx1 == qd_idx) ? dd_idx2 : dd_idx1, 0);
1235 compute_parity6(sh, UPDATE_PARITY); /* Is this necessary? */
1236 return;
1237 }
1238 }
1239
1240 /* We're missing D+P or D+D; build pointer table */
1241 {
1242 /**** FIX THIS: This could be very bad if disks is close to 256 ****/
1243 void *ptrs[disks];
1244
1245 count = 0;
1246 i = d0_idx;
1247 do {
1248 ptrs[count++] = page_address(sh->dev[i].page);
1249 i = raid6_next_disk(i, disks);
1250 if (i != dd_idx1 && i != dd_idx2 &&
1251 !test_bit(R5_UPTODATE, &sh->dev[i].flags))
1252 printk("compute_2 with missing block %d/%d\n", count, i);
1253 } while ( i != d0_idx );
1254
1255 if ( failb == disks-2 ) {
1256 /* We're missing D+P. */
1257 raid6_datap_recov(disks, STRIPE_SIZE, faila, ptrs);
1258 } else {
1259 /* We're missing D+D. */
1260 raid6_2data_recov(disks, STRIPE_SIZE, faila, failb, ptrs);
1261 }
1262
1263 /* Both the above update both missing blocks */
1264 set_bit(R5_UPTODATE, &sh->dev[dd_idx1].flags);
1265 set_bit(R5_UPTODATE, &sh->dev[dd_idx2].flags);
1266 }
1267}
1268
1269
1270
959/* 1271/*
960 * Each stripe/dev can have one or more bion attached. 1272 * Each stripe/dev can have one or more bion attached.
961 * toread/towrite point to the first in a chain. 1273 * toread/towrite point to the first in a chain.
962 * The bi_next chain must be in order. 1274 * The bi_next chain must be in order.
963 */ 1275 */
964static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, int forwrite) 1276static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, int forwrite)
@@ -1001,9 +1313,9 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
1001 (unsigned long long)sh->sector, dd_idx); 1313 (unsigned long long)sh->sector, dd_idx);
1002 1314
1003 if (conf->mddev->bitmap && firstwrite) { 1315 if (conf->mddev->bitmap && firstwrite) {
1004 sh->bm_seq = conf->seq_write;
1005 bitmap_startwrite(conf->mddev->bitmap, sh->sector, 1316 bitmap_startwrite(conf->mddev->bitmap, sh->sector,
1006 STRIPE_SECTORS, 0); 1317 STRIPE_SECTORS, 0);
1318 sh->bm_seq = conf->seq_flush+1;
1007 set_bit(STRIPE_BIT_DELAY, &sh->state); 1319 set_bit(STRIPE_BIT_DELAY, &sh->state);
1008 } 1320 }
1009 1321
@@ -1031,6 +1343,13 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
1031 1343
1032static void end_reshape(raid5_conf_t *conf); 1344static void end_reshape(raid5_conf_t *conf);
1033 1345
1346static int page_is_zero(struct page *p)
1347{
1348 char *a = page_address(p);
1349 return ((*(u32*)a) == 0 &&
1350 memcmp(a, a+4, STRIPE_SIZE-4)==0);
1351}
1352
1034static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int disks) 1353static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int disks)
1035{ 1354{
1036 int sectors_per_chunk = conf->chunk_size >> 9; 1355 int sectors_per_chunk = conf->chunk_size >> 9;
@@ -1062,7 +1381,7 @@ static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int disks)
1062 * 1381 *
1063 */ 1382 */
1064 1383
1065static void handle_stripe(struct stripe_head *sh) 1384static void handle_stripe5(struct stripe_head *sh)
1066{ 1385{
1067 raid5_conf_t *conf = sh->raid_conf; 1386 raid5_conf_t *conf = sh->raid_conf;
1068 int disks = sh->disks; 1387 int disks = sh->disks;
@@ -1394,7 +1713,7 @@ static void handle_stripe(struct stripe_head *sh)
1394 if (locked == 0 && (rcw == 0 ||rmw == 0) && 1713 if (locked == 0 && (rcw == 0 ||rmw == 0) &&
1395 !test_bit(STRIPE_BIT_DELAY, &sh->state)) { 1714 !test_bit(STRIPE_BIT_DELAY, &sh->state)) {
1396 PRINTK("Computing parity...\n"); 1715 PRINTK("Computing parity...\n");
1397 compute_parity(sh, rcw==0 ? RECONSTRUCT_WRITE : READ_MODIFY_WRITE); 1716 compute_parity5(sh, rcw==0 ? RECONSTRUCT_WRITE : READ_MODIFY_WRITE);
1398 /* now every locked buffer is ready to be written */ 1717 /* now every locked buffer is ready to be written */
1399 for (i=disks; i--;) 1718 for (i=disks; i--;)
1400 if (test_bit(R5_LOCKED, &sh->dev[i].flags)) { 1719 if (test_bit(R5_LOCKED, &sh->dev[i].flags)) {
@@ -1421,13 +1740,10 @@ static void handle_stripe(struct stripe_head *sh)
1421 !test_bit(STRIPE_INSYNC, &sh->state)) { 1740 !test_bit(STRIPE_INSYNC, &sh->state)) {
1422 set_bit(STRIPE_HANDLE, &sh->state); 1741 set_bit(STRIPE_HANDLE, &sh->state);
1423 if (failed == 0) { 1742 if (failed == 0) {
1424 char *pagea;
1425 BUG_ON(uptodate != disks); 1743 BUG_ON(uptodate != disks);
1426 compute_parity(sh, CHECK_PARITY); 1744 compute_parity5(sh, CHECK_PARITY);
1427 uptodate--; 1745 uptodate--;
1428 pagea = page_address(sh->dev[sh->pd_idx].page); 1746 if (page_is_zero(sh->dev[sh->pd_idx].page)) {
1429 if ((*(u32*)pagea) == 0 &&
1430 !memcmp(pagea, pagea+4, STRIPE_SIZE-4)) {
1431 /* parity is correct (on disc, not in buffer any more) */ 1747 /* parity is correct (on disc, not in buffer any more) */
1432 set_bit(STRIPE_INSYNC, &sh->state); 1748 set_bit(STRIPE_INSYNC, &sh->state);
1433 } else { 1749 } else {
@@ -1487,7 +1803,7 @@ static void handle_stripe(struct stripe_head *sh)
1487 /* Need to write out all blocks after computing parity */ 1803 /* Need to write out all blocks after computing parity */
1488 sh->disks = conf->raid_disks; 1804 sh->disks = conf->raid_disks;
1489 sh->pd_idx = stripe_to_pdidx(sh->sector, conf, conf->raid_disks); 1805 sh->pd_idx = stripe_to_pdidx(sh->sector, conf, conf->raid_disks);
1490 compute_parity(sh, RECONSTRUCT_WRITE); 1806 compute_parity5(sh, RECONSTRUCT_WRITE);
1491 for (i= conf->raid_disks; i--;) { 1807 for (i= conf->raid_disks; i--;) {
1492 set_bit(R5_LOCKED, &sh->dev[i].flags); 1808 set_bit(R5_LOCKED, &sh->dev[i].flags);
1493 locked++; 1809 locked++;
@@ -1615,6 +1931,569 @@ static void handle_stripe(struct stripe_head *sh)
1615 } 1931 }
1616} 1932}
1617 1933
1934static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
1935{
1936 raid6_conf_t *conf = sh->raid_conf;
1937 int disks = conf->raid_disks;
1938 struct bio *return_bi= NULL;
1939 struct bio *bi;
1940 int i;
1941 int syncing;
1942 int locked=0, uptodate=0, to_read=0, to_write=0, failed=0, written=0;
1943 int non_overwrite = 0;
1944 int failed_num[2] = {0, 0};
1945 struct r5dev *dev, *pdev, *qdev;
1946 int pd_idx = sh->pd_idx;
1947 int qd_idx = raid6_next_disk(pd_idx, disks);
1948 int p_failed, q_failed;
1949
1950 PRINTK("handling stripe %llu, state=%#lx cnt=%d, pd_idx=%d, qd_idx=%d\n",
1951 (unsigned long long)sh->sector, sh->state, atomic_read(&sh->count),
1952 pd_idx, qd_idx);
1953
1954 spin_lock(&sh->lock);
1955 clear_bit(STRIPE_HANDLE, &sh->state);
1956 clear_bit(STRIPE_DELAYED, &sh->state);
1957
1958 syncing = test_bit(STRIPE_SYNCING, &sh->state);
1959 /* Now to look around and see what can be done */
1960
1961 rcu_read_lock();
1962 for (i=disks; i--; ) {
1963 mdk_rdev_t *rdev;
1964 dev = &sh->dev[i];
1965 clear_bit(R5_Insync, &dev->flags);
1966
1967 PRINTK("check %d: state 0x%lx read %p write %p written %p\n",
1968 i, dev->flags, dev->toread, dev->towrite, dev->written);
1969 /* maybe we can reply to a read */
1970 if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread) {
1971 struct bio *rbi, *rbi2;
1972 PRINTK("Return read for disc %d\n", i);
1973 spin_lock_irq(&conf->device_lock);
1974 rbi = dev->toread;
1975 dev->toread = NULL;
1976 if (test_and_clear_bit(R5_Overlap, &dev->flags))
1977 wake_up(&conf->wait_for_overlap);
1978 spin_unlock_irq(&conf->device_lock);
1979 while (rbi && rbi->bi_sector < dev->sector + STRIPE_SECTORS) {
1980 copy_data(0, rbi, dev->page, dev->sector);
1981 rbi2 = r5_next_bio(rbi, dev->sector);
1982 spin_lock_irq(&conf->device_lock);
1983 if (--rbi->bi_phys_segments == 0) {
1984 rbi->bi_next = return_bi;
1985 return_bi = rbi;
1986 }
1987 spin_unlock_irq(&conf->device_lock);
1988 rbi = rbi2;
1989 }
1990 }
1991
1992 /* now count some things */
1993 if (test_bit(R5_LOCKED, &dev->flags)) locked++;
1994 if (test_bit(R5_UPTODATE, &dev->flags)) uptodate++;
1995
1996
1997 if (dev->toread) to_read++;
1998 if (dev->towrite) {
1999 to_write++;
2000 if (!test_bit(R5_OVERWRITE, &dev->flags))
2001 non_overwrite++;
2002 }
2003 if (dev->written) written++;
2004 rdev = rcu_dereference(conf->disks[i].rdev);
2005 if (!rdev || !test_bit(In_sync, &rdev->flags)) {
2006 /* The ReadError flag will just be confusing now */
2007 clear_bit(R5_ReadError, &dev->flags);
2008 clear_bit(R5_ReWrite, &dev->flags);
2009 }
2010 if (!rdev || !test_bit(In_sync, &rdev->flags)
2011 || test_bit(R5_ReadError, &dev->flags)) {
2012 if ( failed < 2 )
2013 failed_num[failed] = i;
2014 failed++;
2015 } else
2016 set_bit(R5_Insync, &dev->flags);
2017 }
2018 rcu_read_unlock();
2019 PRINTK("locked=%d uptodate=%d to_read=%d"
2020 " to_write=%d failed=%d failed_num=%d,%d\n",
2021 locked, uptodate, to_read, to_write, failed,
2022 failed_num[0], failed_num[1]);
2023 /* check if the array has lost >2 devices and, if so, some requests might
2024 * need to be failed
2025 */
2026 if (failed > 2 && to_read+to_write+written) {
2027 for (i=disks; i--; ) {
2028 int bitmap_end = 0;
2029
2030 if (test_bit(R5_ReadError, &sh->dev[i].flags)) {
2031 mdk_rdev_t *rdev;
2032 rcu_read_lock();
2033 rdev = rcu_dereference(conf->disks[i].rdev);
2034 if (rdev && test_bit(In_sync, &rdev->flags))
2035 /* multiple read failures in one stripe */
2036 md_error(conf->mddev, rdev);
2037 rcu_read_unlock();
2038 }
2039
2040 spin_lock_irq(&conf->device_lock);
2041 /* fail all writes first */
2042 bi = sh->dev[i].towrite;
2043 sh->dev[i].towrite = NULL;
2044 if (bi) { to_write--; bitmap_end = 1; }
2045
2046 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
2047 wake_up(&conf->wait_for_overlap);
2048
2049 while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS){
2050 struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector);
2051 clear_bit(BIO_UPTODATE, &bi->bi_flags);
2052 if (--bi->bi_phys_segments == 0) {
2053 md_write_end(conf->mddev);
2054 bi->bi_next = return_bi;
2055 return_bi = bi;
2056 }
2057 bi = nextbi;
2058 }
2059 /* and fail all 'written' */
2060 bi = sh->dev[i].written;
2061 sh->dev[i].written = NULL;
2062 if (bi) bitmap_end = 1;
2063 while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS) {
2064 struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector);
2065 clear_bit(BIO_UPTODATE, &bi->bi_flags);
2066 if (--bi->bi_phys_segments == 0) {
2067 md_write_end(conf->mddev);
2068 bi->bi_next = return_bi;
2069 return_bi = bi;
2070 }
2071 bi = bi2;
2072 }
2073
2074 /* fail any reads if this device is non-operational */
2075 if (!test_bit(R5_Insync, &sh->dev[i].flags) ||
2076 test_bit(R5_ReadError, &sh->dev[i].flags)) {
2077 bi = sh->dev[i].toread;
2078 sh->dev[i].toread = NULL;
2079 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
2080 wake_up(&conf->wait_for_overlap);
2081 if (bi) to_read--;
2082 while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS){
2083 struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector);
2084 clear_bit(BIO_UPTODATE, &bi->bi_flags);
2085 if (--bi->bi_phys_segments == 0) {
2086 bi->bi_next = return_bi;
2087 return_bi = bi;
2088 }
2089 bi = nextbi;
2090 }
2091 }
2092 spin_unlock_irq(&conf->device_lock);
2093 if (bitmap_end)
2094 bitmap_endwrite(conf->mddev->bitmap, sh->sector,
2095 STRIPE_SECTORS, 0, 0);
2096 }
2097 }
2098 if (failed > 2 && syncing) {
2099 md_done_sync(conf->mddev, STRIPE_SECTORS,0);
2100 clear_bit(STRIPE_SYNCING, &sh->state);
2101 syncing = 0;
2102 }
2103
2104 /*
2105 * might be able to return some write requests if the parity blocks
2106 * are safe, or on a failed drive
2107 */
2108 pdev = &sh->dev[pd_idx];
2109 p_failed = (failed >= 1 && failed_num[0] == pd_idx)
2110 || (failed >= 2 && failed_num[1] == pd_idx);
2111 qdev = &sh->dev[qd_idx];
2112 q_failed = (failed >= 1 && failed_num[0] == qd_idx)
2113 || (failed >= 2 && failed_num[1] == qd_idx);
2114
2115 if ( written &&
2116 ( p_failed || ((test_bit(R5_Insync, &pdev->flags)
2117 && !test_bit(R5_LOCKED, &pdev->flags)
2118 && test_bit(R5_UPTODATE, &pdev->flags))) ) &&
2119 ( q_failed || ((test_bit(R5_Insync, &qdev->flags)
2120 && !test_bit(R5_LOCKED, &qdev->flags)
2121 && test_bit(R5_UPTODATE, &qdev->flags))) ) ) {
2122 /* any written block on an uptodate or failed drive can be
2123 * returned. Note that if we 'wrote' to a failed drive,
2124 * it will be UPTODATE, but never LOCKED, so we don't need
2125 * to test 'failed' directly.
2126 */
2127 for (i=disks; i--; )
2128 if (sh->dev[i].written) {
2129 dev = &sh->dev[i];
2130 if (!test_bit(R5_LOCKED, &dev->flags) &&
2131 test_bit(R5_UPTODATE, &dev->flags) ) {
2132 /* We can return any write requests */
2133 int bitmap_end = 0;
2134 struct bio *wbi, *wbi2;
2135 PRINTK("Return write for stripe %llu disc %d\n",
2136 (unsigned long long)sh->sector, i);
2137 spin_lock_irq(&conf->device_lock);
2138 wbi = dev->written;
2139 dev->written = NULL;
2140 while (wbi && wbi->bi_sector < dev->sector + STRIPE_SECTORS) {
2141 wbi2 = r5_next_bio(wbi, dev->sector);
2142 if (--wbi->bi_phys_segments == 0) {
2143 md_write_end(conf->mddev);
2144 wbi->bi_next = return_bi;
2145 return_bi = wbi;
2146 }
2147 wbi = wbi2;
2148 }
2149 if (dev->towrite == NULL)
2150 bitmap_end = 1;
2151 spin_unlock_irq(&conf->device_lock);
2152 if (bitmap_end)
2153 bitmap_endwrite(conf->mddev->bitmap, sh->sector,
2154 STRIPE_SECTORS,
2155 !test_bit(STRIPE_DEGRADED, &sh->state), 0);
2156 }
2157 }
2158 }
2159
2160 /* Now we might consider reading some blocks, either to check/generate
2161 * parity, or to satisfy requests
2162 * or to load a block that is being partially written.
2163 */
2164 if (to_read || non_overwrite || (to_write && failed) || (syncing && (uptodate < disks))) {
2165 for (i=disks; i--;) {
2166 dev = &sh->dev[i];
2167 if (!test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_UPTODATE, &dev->flags) &&
2168 (dev->toread ||
2169 (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) ||
2170 syncing ||
2171 (failed >= 1 && (sh->dev[failed_num[0]].toread || to_write)) ||
2172 (failed >= 2 && (sh->dev[failed_num[1]].toread || to_write))
2173 )
2174 ) {
2175 /* we would like to get this block, possibly
2176 * by computing it, but we might not be able to
2177 */
2178 if (uptodate == disks-1) {
2179 PRINTK("Computing stripe %llu block %d\n",
2180 (unsigned long long)sh->sector, i);
2181 compute_block_1(sh, i, 0);
2182 uptodate++;
2183 } else if ( uptodate == disks-2 && failed >= 2 ) {
2184 /* Computing 2-failure is *very* expensive; only do it if failed >= 2 */
2185 int other;
2186 for (other=disks; other--;) {
2187 if ( other == i )
2188 continue;
2189 if ( !test_bit(R5_UPTODATE, &sh->dev[other].flags) )
2190 break;
2191 }
2192 BUG_ON(other < 0);
2193 PRINTK("Computing stripe %llu blocks %d,%d\n",
2194 (unsigned long long)sh->sector, i, other);
2195 compute_block_2(sh, i, other);
2196 uptodate += 2;
2197 } else if (test_bit(R5_Insync, &dev->flags)) {
2198 set_bit(R5_LOCKED, &dev->flags);
2199 set_bit(R5_Wantread, &dev->flags);
2200#if 0
2201 /* if I am just reading this block and we don't have
2202 a failed drive, or any pending writes then sidestep the cache */
2203 if (sh->bh_read[i] && !sh->bh_read[i]->b_reqnext &&
2204 ! syncing && !failed && !to_write) {
2205 sh->bh_cache[i]->b_page = sh->bh_read[i]->b_page;
2206 sh->bh_cache[i]->b_data = sh->bh_read[i]->b_data;
2207 }
2208#endif
2209 locked++;
2210 PRINTK("Reading block %d (sync=%d)\n",
2211 i, syncing);
2212 }
2213 }
2214 }
2215 set_bit(STRIPE_HANDLE, &sh->state);
2216 }
2217
2218 /* now to consider writing and what else, if anything should be read */
2219 if (to_write) {
2220 int rcw=0, must_compute=0;
2221 for (i=disks ; i--;) {
2222 dev = &sh->dev[i];
2223 /* Would I have to read this buffer for reconstruct_write */
2224 if (!test_bit(R5_OVERWRITE, &dev->flags)
2225 && i != pd_idx && i != qd_idx
2226 && (!test_bit(R5_LOCKED, &dev->flags)
2227#if 0
2228 || sh->bh_page[i] != bh->b_page
2229#endif
2230 ) &&
2231 !test_bit(R5_UPTODATE, &dev->flags)) {
2232 if (test_bit(R5_Insync, &dev->flags)) rcw++;
2233 else {
2234 PRINTK("raid6: must_compute: disk %d flags=%#lx\n", i, dev->flags);
2235 must_compute++;
2236 }
2237 }
2238 }
2239 PRINTK("for sector %llu, rcw=%d, must_compute=%d\n",
2240 (unsigned long long)sh->sector, rcw, must_compute);
2241 set_bit(STRIPE_HANDLE, &sh->state);
2242
2243 if (rcw > 0)
2244 /* want reconstruct write, but need to get some data */
2245 for (i=disks; i--;) {
2246 dev = &sh->dev[i];
2247 if (!test_bit(R5_OVERWRITE, &dev->flags)
2248 && !(failed == 0 && (i == pd_idx || i == qd_idx))
2249 && !test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_UPTODATE, &dev->flags) &&
2250 test_bit(R5_Insync, &dev->flags)) {
2251 if (test_bit(STRIPE_PREREAD_ACTIVE, &sh->state))
2252 {
2253 PRINTK("Read_old stripe %llu block %d for Reconstruct\n",
2254 (unsigned long long)sh->sector, i);
2255 set_bit(R5_LOCKED, &dev->flags);
2256 set_bit(R5_Wantread, &dev->flags);
2257 locked++;
2258 } else {
2259 PRINTK("Request delayed stripe %llu block %d for Reconstruct\n",
2260 (unsigned long long)sh->sector, i);
2261 set_bit(STRIPE_DELAYED, &sh->state);
2262 set_bit(STRIPE_HANDLE, &sh->state);
2263 }
2264 }
2265 }
2266 /* now if nothing is locked, and if we have enough data, we can start a write request */
2267 if (locked == 0 && rcw == 0 &&
2268 !test_bit(STRIPE_BIT_DELAY, &sh->state)) {
2269 if ( must_compute > 0 ) {
2270 /* We have failed blocks and need to compute them */
2271 switch ( failed ) {
2272 case 0: BUG();
2273 case 1: compute_block_1(sh, failed_num[0], 0); break;
2274 case 2: compute_block_2(sh, failed_num[0], failed_num[1]); break;
2275 default: BUG(); /* This request should have been failed? */
2276 }
2277 }
2278
2279 PRINTK("Computing parity for stripe %llu\n", (unsigned long long)sh->sector);
2280 compute_parity6(sh, RECONSTRUCT_WRITE);
2281 /* now every locked buffer is ready to be written */
2282 for (i=disks; i--;)
2283 if (test_bit(R5_LOCKED, &sh->dev[i].flags)) {
2284 PRINTK("Writing stripe %llu block %d\n",
2285 (unsigned long long)sh->sector, i);
2286 locked++;
2287 set_bit(R5_Wantwrite, &sh->dev[i].flags);
2288 }
2289 /* after a RECONSTRUCT_WRITE, the stripe MUST be in-sync */
2290 set_bit(STRIPE_INSYNC, &sh->state);
2291
2292 if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) {
2293 atomic_dec(&conf->preread_active_stripes);
2294 if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD)
2295 md_wakeup_thread(conf->mddev->thread);
2296 }
2297 }
2298 }
2299
2300 /* maybe we need to check and possibly fix the parity for this stripe
2301 * Any reads will already have been scheduled, so we just see if enough data
2302 * is available
2303 */
2304 if (syncing && locked == 0 && !test_bit(STRIPE_INSYNC, &sh->state)) {
2305 int update_p = 0, update_q = 0;
2306 struct r5dev *dev;
2307
2308 set_bit(STRIPE_HANDLE, &sh->state);
2309
2310 BUG_ON(failed>2);
2311 BUG_ON(uptodate < disks);
2312 /* Want to check and possibly repair P and Q.
2313 * However there could be one 'failed' device, in which
2314 * case we can only check one of them, possibly using the
2315 * other to generate missing data
2316 */
2317
2318 /* If !tmp_page, we cannot do the calculations,
2319 * but as we have set STRIPE_HANDLE, we will soon be called
2320 * by stripe_handle with a tmp_page - just wait until then.
2321 */
2322 if (tmp_page) {
2323 if (failed == q_failed) {
2324 /* The only possible failed device holds 'Q', so it makes
2325 * sense to check P (If anything else were failed, we would
2326 * have used P to recreate it).
2327 */
2328 compute_block_1(sh, pd_idx, 1);
2329 if (!page_is_zero(sh->dev[pd_idx].page)) {
2330 compute_block_1(sh,pd_idx,0);
2331 update_p = 1;
2332 }
2333 }
2334 if (!q_failed && failed < 2) {
2335 /* q is not failed, and we didn't use it to generate
2336 * anything, so it makes sense to check it
2337 */
2338 memcpy(page_address(tmp_page),
2339 page_address(sh->dev[qd_idx].page),
2340 STRIPE_SIZE);
2341 compute_parity6(sh, UPDATE_PARITY);
2342 if (memcmp(page_address(tmp_page),
2343 page_address(sh->dev[qd_idx].page),
2344 STRIPE_SIZE)!= 0) {
2345 clear_bit(STRIPE_INSYNC, &sh->state);
2346 update_q = 1;
2347 }
2348 }
2349 if (update_p || update_q) {
2350 conf->mddev->resync_mismatches += STRIPE_SECTORS;
2351 if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery))
2352 /* don't try to repair!! */
2353 update_p = update_q = 0;
2354 }
2355
2356 /* now write out any block on a failed drive,
2357 * or P or Q if they need it
2358 */
2359
2360 if (failed == 2) {
2361 dev = &sh->dev[failed_num[1]];
2362 locked++;
2363 set_bit(R5_LOCKED, &dev->flags);
2364 set_bit(R5_Wantwrite, &dev->flags);
2365 }
2366 if (failed >= 1) {
2367 dev = &sh->dev[failed_num[0]];
2368 locked++;
2369 set_bit(R5_LOCKED, &dev->flags);
2370 set_bit(R5_Wantwrite, &dev->flags);
2371 }
2372
2373 if (update_p) {
2374 dev = &sh->dev[pd_idx];
2375 locked ++;
2376 set_bit(R5_LOCKED, &dev->flags);
2377 set_bit(R5_Wantwrite, &dev->flags);
2378 }
2379 if (update_q) {
2380 dev = &sh->dev[qd_idx];
2381 locked++;
2382 set_bit(R5_LOCKED, &dev->flags);
2383 set_bit(R5_Wantwrite, &dev->flags);
2384 }
2385 clear_bit(STRIPE_DEGRADED, &sh->state);
2386
2387 set_bit(STRIPE_INSYNC, &sh->state);
2388 }
2389 }
2390
2391 if (syncing && locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) {
2392 md_done_sync(conf->mddev, STRIPE_SECTORS,1);
2393 clear_bit(STRIPE_SYNCING, &sh->state);
2394 }
2395
2396 /* If the failed drives are just a ReadError, then we might need
2397 * to progress the repair/check process
2398 */
2399 if (failed <= 2 && ! conf->mddev->ro)
2400 for (i=0; i<failed;i++) {
2401 dev = &sh->dev[failed_num[i]];
2402 if (test_bit(R5_ReadError, &dev->flags)
2403 && !test_bit(R5_LOCKED, &dev->flags)
2404 && test_bit(R5_UPTODATE, &dev->flags)
2405 ) {
2406 if (!test_bit(R5_ReWrite, &dev->flags)) {
2407 set_bit(R5_Wantwrite, &dev->flags);
2408 set_bit(R5_ReWrite, &dev->flags);
2409 set_bit(R5_LOCKED, &dev->flags);
2410 } else {
2411 /* let's read it back */
2412 set_bit(R5_Wantread, &dev->flags);
2413 set_bit(R5_LOCKED, &dev->flags);
2414 }
2415 }
2416 }
2417 spin_unlock(&sh->lock);
2418
2419 while ((bi=return_bi)) {
2420 int bytes = bi->bi_size;
2421
2422 return_bi = bi->bi_next;
2423 bi->bi_next = NULL;
2424 bi->bi_size = 0;
2425 bi->bi_end_io(bi, bytes, 0);
2426 }
2427 for (i=disks; i-- ;) {
2428 int rw;
2429 struct bio *bi;
2430 mdk_rdev_t *rdev;
2431 if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags))
2432 rw = 1;
2433 else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags))
2434 rw = 0;
2435 else
2436 continue;
2437
2438 bi = &sh->dev[i].req;
2439
2440 bi->bi_rw = rw;
2441 if (rw)
2442 bi->bi_end_io = raid5_end_write_request;
2443 else
2444 bi->bi_end_io = raid5_end_read_request;
2445
2446 rcu_read_lock();
2447 rdev = rcu_dereference(conf->disks[i].rdev);
2448 if (rdev && test_bit(Faulty, &rdev->flags))
2449 rdev = NULL;
2450 if (rdev)
2451 atomic_inc(&rdev->nr_pending);
2452 rcu_read_unlock();
2453
2454 if (rdev) {
2455 if (syncing)
2456 md_sync_acct(rdev->bdev, STRIPE_SECTORS);
2457
2458 bi->bi_bdev = rdev->bdev;
2459 PRINTK("for %llu schedule op %ld on disc %d\n",
2460 (unsigned long long)sh->sector, bi->bi_rw, i);
2461 atomic_inc(&sh->count);
2462 bi->bi_sector = sh->sector + rdev->data_offset;
2463 bi->bi_flags = 1 << BIO_UPTODATE;
2464 bi->bi_vcnt = 1;
2465 bi->bi_max_vecs = 1;
2466 bi->bi_idx = 0;
2467 bi->bi_io_vec = &sh->dev[i].vec;
2468 bi->bi_io_vec[0].bv_len = STRIPE_SIZE;
2469 bi->bi_io_vec[0].bv_offset = 0;
2470 bi->bi_size = STRIPE_SIZE;
2471 bi->bi_next = NULL;
2472 if (rw == WRITE &&
2473 test_bit(R5_ReWrite, &sh->dev[i].flags))
2474 atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
2475 generic_make_request(bi);
2476 } else {
2477 if (rw == 1)
2478 set_bit(STRIPE_DEGRADED, &sh->state);
2479 PRINTK("skip op %ld on disc %d for sector %llu\n",
2480 bi->bi_rw, i, (unsigned long long)sh->sector);
2481 clear_bit(R5_LOCKED, &sh->dev[i].flags);
2482 set_bit(STRIPE_HANDLE, &sh->state);
2483 }
2484 }
2485}
2486
2487static void handle_stripe(struct stripe_head *sh, struct page *tmp_page)
2488{
2489 if (sh->raid_conf->level == 6)
2490 handle_stripe6(sh, tmp_page);
2491 else
2492 handle_stripe5(sh);
2493}
2494
2495
2496
1618static void raid5_activate_delayed(raid5_conf_t *conf) 2497static void raid5_activate_delayed(raid5_conf_t *conf)
1619{ 2498{
1620 if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) { 2499 if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) {
@@ -1718,13 +2597,6 @@ static int raid5_issue_flush(request_queue_t *q, struct gendisk *disk,
1718 return ret; 2597 return ret;
1719} 2598}
1720 2599
1721static inline void raid5_plug_device(raid5_conf_t *conf)
1722{
1723 spin_lock_irq(&conf->device_lock);
1724 blk_plug_device(conf->mddev->queue);
1725 spin_unlock_irq(&conf->device_lock);
1726}
1727
1728static int make_request(request_queue_t *q, struct bio * bi) 2600static int make_request(request_queue_t *q, struct bio * bi)
1729{ 2601{
1730 mddev_t *mddev = q->queuedata; 2602 mddev_t *mddev = q->queuedata;
@@ -1753,7 +2625,7 @@ static int make_request(request_queue_t *q, struct bio * bi)
1753 2625
1754 for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { 2626 for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) {
1755 DEFINE_WAIT(w); 2627 DEFINE_WAIT(w);
1756 int disks; 2628 int disks, data_disks;
1757 2629
1758 retry: 2630 retry:
1759 prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE); 2631 prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE);
@@ -1781,7 +2653,9 @@ static int make_request(request_queue_t *q, struct bio * bi)
1781 } 2653 }
1782 spin_unlock_irq(&conf->device_lock); 2654 spin_unlock_irq(&conf->device_lock);
1783 } 2655 }
1784 new_sector = raid5_compute_sector(logical_sector, disks, disks - 1, 2656 data_disks = disks - conf->max_degraded;
2657
2658 new_sector = raid5_compute_sector(logical_sector, disks, data_disks,
1785 &dd_idx, &pd_idx, conf); 2659 &dd_idx, &pd_idx, conf);
1786 PRINTK("raid5: make_request, sector %llu logical %llu\n", 2660 PRINTK("raid5: make_request, sector %llu logical %llu\n",
1787 (unsigned long long)new_sector, 2661 (unsigned long long)new_sector,
@@ -1832,8 +2706,7 @@ static int make_request(request_queue_t *q, struct bio * bi)
1832 goto retry; 2706 goto retry;
1833 } 2707 }
1834 finish_wait(&conf->wait_for_overlap, &w); 2708 finish_wait(&conf->wait_for_overlap, &w);
1835 raid5_plug_device(conf); 2709 handle_stripe(sh, NULL);
1836 handle_stripe(sh);
1837 release_stripe(sh); 2710 release_stripe(sh);
1838 } else { 2711 } else {
1839 /* cannot get stripe for read-ahead, just give-up */ 2712 /* cannot get stripe for read-ahead, just give-up */
@@ -1849,7 +2722,7 @@ static int make_request(request_queue_t *q, struct bio * bi)
1849 if (remaining == 0) { 2722 if (remaining == 0) {
1850 int bytes = bi->bi_size; 2723 int bytes = bi->bi_size;
1851 2724
1852 if ( bio_data_dir(bi) == WRITE ) 2725 if ( rw == WRITE )
1853 md_write_end(mddev); 2726 md_write_end(mddev);
1854 bi->bi_size = 0; 2727 bi->bi_size = 0;
1855 bi->bi_end_io(bi, bytes, 0); 2728 bi->bi_end_io(bi, bytes, 0);
@@ -1857,17 +2730,141 @@ static int make_request(request_queue_t *q, struct bio * bi)
1857 return 0; 2730 return 0;
1858} 2731}
1859 2732
1860/* FIXME go_faster isn't used */ 2733static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped)
1861static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster)
1862{ 2734{
2735 /* reshaping is quite different to recovery/resync so it is
2736 * handled quite separately ... here.
2737 *
2738 * On each call to sync_request, we gather one chunk worth of
2739 * destination stripes and flag them as expanding.
2740 * Then we find all the source stripes and request reads.
2741 * As the reads complete, handle_stripe will copy the data
2742 * into the destination stripe and release that stripe.
2743 */
1863 raid5_conf_t *conf = (raid5_conf_t *) mddev->private; 2744 raid5_conf_t *conf = (raid5_conf_t *) mddev->private;
1864 struct stripe_head *sh; 2745 struct stripe_head *sh;
1865 int pd_idx; 2746 int pd_idx;
1866 sector_t first_sector, last_sector; 2747 sector_t first_sector, last_sector;
2748 int raid_disks;
2749 int data_disks;
2750 int i;
2751 int dd_idx;
2752 sector_t writepos, safepos, gap;
2753
2754 if (sector_nr == 0 &&
2755 conf->expand_progress != 0) {
2756 /* restarting in the middle, skip the initial sectors */
2757 sector_nr = conf->expand_progress;
2758 sector_div(sector_nr, conf->raid_disks-1);
2759 *skipped = 1;
2760 return sector_nr;
2761 }
2762
2763 /* we update the metadata when there is more than 3Meg
2764 * in the block range (that is rather arbitrary, should
2765 * probably be time based) or when the data about to be
2766 * copied would over-write the source of the data at
2767 * the front of the range.
2768 * i.e. one new_stripe forward from expand_progress new_maps
2769 * to after where expand_lo old_maps to
2770 */
2771 writepos = conf->expand_progress +
2772 conf->chunk_size/512*(conf->raid_disks-1);
2773 sector_div(writepos, conf->raid_disks-1);
2774 safepos = conf->expand_lo;
2775 sector_div(safepos, conf->previous_raid_disks-1);
2776 gap = conf->expand_progress - conf->expand_lo;
2777
2778 if (writepos >= safepos ||
2779 gap > (conf->raid_disks-1)*3000*2 /*3Meg*/) {
2780 /* Cannot proceed until we've updated the superblock... */
2781 wait_event(conf->wait_for_overlap,
2782 atomic_read(&conf->reshape_stripes)==0);
2783 mddev->reshape_position = conf->expand_progress;
2784 mddev->sb_dirty = 1;
2785 md_wakeup_thread(mddev->thread);
2786 wait_event(mddev->sb_wait, mddev->sb_dirty == 0 ||
2787 kthread_should_stop());
2788 spin_lock_irq(&conf->device_lock);
2789 conf->expand_lo = mddev->reshape_position;
2790 spin_unlock_irq(&conf->device_lock);
2791 wake_up(&conf->wait_for_overlap);
2792 }
2793
2794 for (i=0; i < conf->chunk_size/512; i+= STRIPE_SECTORS) {
2795 int j;
2796 int skipped = 0;
2797 pd_idx = stripe_to_pdidx(sector_nr+i, conf, conf->raid_disks);
2798 sh = get_active_stripe(conf, sector_nr+i,
2799 conf->raid_disks, pd_idx, 0);
2800 set_bit(STRIPE_EXPANDING, &sh->state);
2801 atomic_inc(&conf->reshape_stripes);
2802 /* If any of this stripe is beyond the end of the old
2803 * array, then we need to zero those blocks
2804 */
2805 for (j=sh->disks; j--;) {
2806 sector_t s;
2807 if (j == sh->pd_idx)
2808 continue;
2809 s = compute_blocknr(sh, j);
2810 if (s < (mddev->array_size<<1)) {
2811 skipped = 1;
2812 continue;
2813 }
2814 memset(page_address(sh->dev[j].page), 0, STRIPE_SIZE);
2815 set_bit(R5_Expanded, &sh->dev[j].flags);
2816 set_bit(R5_UPTODATE, &sh->dev[j].flags);
2817 }
2818 if (!skipped) {
2819 set_bit(STRIPE_EXPAND_READY, &sh->state);
2820 set_bit(STRIPE_HANDLE, &sh->state);
2821 }
2822 release_stripe(sh);
2823 }
2824 spin_lock_irq(&conf->device_lock);
2825 conf->expand_progress = (sector_nr + i)*(conf->raid_disks-1);
2826 spin_unlock_irq(&conf->device_lock);
2827 /* Ok, those stripe are ready. We can start scheduling
2828 * reads on the source stripes.
2829 * The source stripes are determined by mapping the first and last
2830 * block on the destination stripes.
2831 */
2832 raid_disks = conf->previous_raid_disks;
2833 data_disks = raid_disks - 1;
2834 first_sector =
2835 raid5_compute_sector(sector_nr*(conf->raid_disks-1),
2836 raid_disks, data_disks,
2837 &dd_idx, &pd_idx, conf);
2838 last_sector =
2839 raid5_compute_sector((sector_nr+conf->chunk_size/512)
2840 *(conf->raid_disks-1) -1,
2841 raid_disks, data_disks,
2842 &dd_idx, &pd_idx, conf);
2843 if (last_sector >= (mddev->size<<1))
2844 last_sector = (mddev->size<<1)-1;
2845 while (first_sector <= last_sector) {
2846 pd_idx = stripe_to_pdidx(first_sector, conf, conf->previous_raid_disks);
2847 sh = get_active_stripe(conf, first_sector,
2848 conf->previous_raid_disks, pd_idx, 0);
2849 set_bit(STRIPE_EXPAND_SOURCE, &sh->state);
2850 set_bit(STRIPE_HANDLE, &sh->state);
2851 release_stripe(sh);
2852 first_sector += STRIPE_SECTORS;
2853 }
2854 return conf->chunk_size>>9;
2855}
2856
2857/* FIXME go_faster isn't used */
2858static inline sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster)
2859{
2860 raid5_conf_t *conf = (raid5_conf_t *) mddev->private;
2861 struct stripe_head *sh;
2862 int pd_idx;
1867 int raid_disks = conf->raid_disks; 2863 int raid_disks = conf->raid_disks;
1868 int data_disks = raid_disks-1;
1869 sector_t max_sector = mddev->size << 1; 2864 sector_t max_sector = mddev->size << 1;
1870 int sync_blocks; 2865 int sync_blocks;
2866 int still_degraded = 0;
2867 int i;
1871 2868
1872 if (sector_nr >= max_sector) { 2869 if (sector_nr >= max_sector) {
1873 /* just being told to finish up .. nothing much to do */ 2870 /* just being told to finish up .. nothing much to do */
@@ -1880,134 +2877,22 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1880 if (mddev->curr_resync < max_sector) /* aborted */ 2877 if (mddev->curr_resync < max_sector) /* aborted */
1881 bitmap_end_sync(mddev->bitmap, mddev->curr_resync, 2878 bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
1882 &sync_blocks, 1); 2879 &sync_blocks, 1);
1883 else /* compelted sync */ 2880 else /* completed sync */
1884 conf->fullsync = 0; 2881 conf->fullsync = 0;
1885 bitmap_close_sync(mddev->bitmap); 2882 bitmap_close_sync(mddev->bitmap);
1886 2883
1887 return 0; 2884 return 0;
1888 } 2885 }
1889 2886
1890 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) { 2887 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery))
1891 /* reshaping is quite different to recovery/resync so it is 2888 return reshape_request(mddev, sector_nr, skipped);
1892 * handled quite separately ... here. 2889
1893 * 2890 /* if there is too many failed drives and we are trying
1894 * On each call to sync_request, we gather one chunk worth of
1895 * destination stripes and flag them as expanding.
1896 * Then we find all the source stripes and request reads.
1897 * As the reads complete, handle_stripe will copy the data
1898 * into the destination stripe and release that stripe.
1899 */
1900 int i;
1901 int dd_idx;
1902 sector_t writepos, safepos, gap;
1903
1904 if (sector_nr == 0 &&
1905 conf->expand_progress != 0) {
1906 /* restarting in the middle, skip the initial sectors */
1907 sector_nr = conf->expand_progress;
1908 sector_div(sector_nr, conf->raid_disks-1);
1909 *skipped = 1;
1910 return sector_nr;
1911 }
1912
1913 /* we update the metadata when there is more than 3Meg
1914 * in the block range (that is rather arbitrary, should
1915 * probably be time based) or when the data about to be
1916 * copied would over-write the source of the data at
1917 * the front of the range.
1918 * i.e. one new_stripe forward from expand_progress new_maps
1919 * to after where expand_lo old_maps to
1920 */
1921 writepos = conf->expand_progress +
1922 conf->chunk_size/512*(conf->raid_disks-1);
1923 sector_div(writepos, conf->raid_disks-1);
1924 safepos = conf->expand_lo;
1925 sector_div(safepos, conf->previous_raid_disks-1);
1926 gap = conf->expand_progress - conf->expand_lo;
1927
1928 if (writepos >= safepos ||
1929 gap > (conf->raid_disks-1)*3000*2 /*3Meg*/) {
1930 /* Cannot proceed until we've updated the superblock... */
1931 wait_event(conf->wait_for_overlap,
1932 atomic_read(&conf->reshape_stripes)==0);
1933 mddev->reshape_position = conf->expand_progress;
1934 mddev->sb_dirty = 1;
1935 md_wakeup_thread(mddev->thread);
1936 wait_event(mddev->sb_wait, mddev->sb_dirty == 0 ||
1937 kthread_should_stop());
1938 spin_lock_irq(&conf->device_lock);
1939 conf->expand_lo = mddev->reshape_position;
1940 spin_unlock_irq(&conf->device_lock);
1941 wake_up(&conf->wait_for_overlap);
1942 }
1943
1944 for (i=0; i < conf->chunk_size/512; i+= STRIPE_SECTORS) {
1945 int j;
1946 int skipped = 0;
1947 pd_idx = stripe_to_pdidx(sector_nr+i, conf, conf->raid_disks);
1948 sh = get_active_stripe(conf, sector_nr+i,
1949 conf->raid_disks, pd_idx, 0);
1950 set_bit(STRIPE_EXPANDING, &sh->state);
1951 atomic_inc(&conf->reshape_stripes);
1952 /* If any of this stripe is beyond the end of the old
1953 * array, then we need to zero those blocks
1954 */
1955 for (j=sh->disks; j--;) {
1956 sector_t s;
1957 if (j == sh->pd_idx)
1958 continue;
1959 s = compute_blocknr(sh, j);
1960 if (s < (mddev->array_size<<1)) {
1961 skipped = 1;
1962 continue;
1963 }
1964 memset(page_address(sh->dev[j].page), 0, STRIPE_SIZE);
1965 set_bit(R5_Expanded, &sh->dev[j].flags);
1966 set_bit(R5_UPTODATE, &sh->dev[j].flags);
1967 }
1968 if (!skipped) {
1969 set_bit(STRIPE_EXPAND_READY, &sh->state);
1970 set_bit(STRIPE_HANDLE, &sh->state);
1971 }
1972 release_stripe(sh);
1973 }
1974 spin_lock_irq(&conf->device_lock);
1975 conf->expand_progress = (sector_nr + i)*(conf->raid_disks-1);
1976 spin_unlock_irq(&conf->device_lock);
1977 /* Ok, those stripe are ready. We can start scheduling
1978 * reads on the source stripes.
1979 * The source stripes are determined by mapping the first and last
1980 * block on the destination stripes.
1981 */
1982 raid_disks = conf->previous_raid_disks;
1983 data_disks = raid_disks - 1;
1984 first_sector =
1985 raid5_compute_sector(sector_nr*(conf->raid_disks-1),
1986 raid_disks, data_disks,
1987 &dd_idx, &pd_idx, conf);
1988 last_sector =
1989 raid5_compute_sector((sector_nr+conf->chunk_size/512)
1990 *(conf->raid_disks-1) -1,
1991 raid_disks, data_disks,
1992 &dd_idx, &pd_idx, conf);
1993 if (last_sector >= (mddev->size<<1))
1994 last_sector = (mddev->size<<1)-1;
1995 while (first_sector <= last_sector) {
1996 pd_idx = stripe_to_pdidx(first_sector, conf, conf->previous_raid_disks);
1997 sh = get_active_stripe(conf, first_sector,
1998 conf->previous_raid_disks, pd_idx, 0);
1999 set_bit(STRIPE_EXPAND_SOURCE, &sh->state);
2000 set_bit(STRIPE_HANDLE, &sh->state);
2001 release_stripe(sh);
2002 first_sector += STRIPE_SECTORS;
2003 }
2004 return conf->chunk_size>>9;
2005 }
2006 /* if there is 1 or more failed drives and we are trying
2007 * to resync, then assert that we are finished, because there is 2891 * to resync, then assert that we are finished, because there is
2008 * nothing we can do. 2892 * nothing we can do.
2009 */ 2893 */
2010 if (mddev->degraded >= 1 && test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { 2894 if (mddev->degraded >= conf->max_degraded &&
2895 test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
2011 sector_t rv = (mddev->size << 1) - sector_nr; 2896 sector_t rv = (mddev->size << 1) - sector_nr;
2012 *skipped = 1; 2897 *skipped = 1;
2013 return rv; 2898 return rv;
@@ -2026,17 +2911,26 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
2026 if (sh == NULL) { 2911 if (sh == NULL) {
2027 sh = get_active_stripe(conf, sector_nr, raid_disks, pd_idx, 0); 2912 sh = get_active_stripe(conf, sector_nr, raid_disks, pd_idx, 0);
2028 /* make sure we don't swamp the stripe cache if someone else 2913 /* make sure we don't swamp the stripe cache if someone else
2029 * is trying to get access 2914 * is trying to get access
2030 */ 2915 */
2031 schedule_timeout_uninterruptible(1); 2916 schedule_timeout_uninterruptible(1);
2032 } 2917 }
2033 bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 0); 2918 /* Need to check if array will still be degraded after recovery/resync
2034 spin_lock(&sh->lock); 2919 * We don't need to check the 'failed' flag as when that gets set,
2920 * recovery aborts.
2921 */
2922 for (i=0; i<mddev->raid_disks; i++)
2923 if (conf->disks[i].rdev == NULL)
2924 still_degraded = 1;
2925
2926 bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded);
2927
2928 spin_lock(&sh->lock);
2035 set_bit(STRIPE_SYNCING, &sh->state); 2929 set_bit(STRIPE_SYNCING, &sh->state);
2036 clear_bit(STRIPE_INSYNC, &sh->state); 2930 clear_bit(STRIPE_INSYNC, &sh->state);
2037 spin_unlock(&sh->lock); 2931 spin_unlock(&sh->lock);
2038 2932
2039 handle_stripe(sh); 2933 handle_stripe(sh, NULL);
2040 release_stripe(sh); 2934 release_stripe(sh);
2041 2935
2042 return STRIPE_SECTORS; 2936 return STRIPE_SECTORS;
@@ -2064,7 +2958,7 @@ static void raid5d (mddev_t *mddev)
2064 while (1) { 2958 while (1) {
2065 struct list_head *first; 2959 struct list_head *first;
2066 2960
2067 if (conf->seq_flush - conf->seq_write > 0) { 2961 if (conf->seq_flush != conf->seq_write) {
2068 int seq = conf->seq_flush; 2962 int seq = conf->seq_flush;
2069 spin_unlock_irq(&conf->device_lock); 2963 spin_unlock_irq(&conf->device_lock);
2070 bitmap_unplug(mddev->bitmap); 2964 bitmap_unplug(mddev->bitmap);
@@ -2091,7 +2985,7 @@ static void raid5d (mddev_t *mddev)
2091 spin_unlock_irq(&conf->device_lock); 2985 spin_unlock_irq(&conf->device_lock);
2092 2986
2093 handled++; 2987 handled++;
2094 handle_stripe(sh); 2988 handle_stripe(sh, conf->spare_page);
2095 release_stripe(sh); 2989 release_stripe(sh);
2096 2990
2097 spin_lock_irq(&conf->device_lock); 2991 spin_lock_irq(&conf->device_lock);
@@ -2181,8 +3075,8 @@ static int run(mddev_t *mddev)
2181 struct disk_info *disk; 3075 struct disk_info *disk;
2182 struct list_head *tmp; 3076 struct list_head *tmp;
2183 3077
2184 if (mddev->level != 5 && mddev->level != 4) { 3078 if (mddev->level != 5 && mddev->level != 4 && mddev->level != 6) {
2185 printk(KERN_ERR "raid5: %s: raid level not set to 4/5 (%d)\n", 3079 printk(KERN_ERR "raid5: %s: raid level not set to 4/5/6 (%d)\n",
2186 mdname(mddev), mddev->level); 3080 mdname(mddev), mddev->level);
2187 return -EIO; 3081 return -EIO;
2188 } 3082 }
@@ -2251,6 +3145,11 @@ static int run(mddev_t *mddev)
2251 if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) 3145 if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL)
2252 goto abort; 3146 goto abort;
2253 3147
3148 if (mddev->level == 6) {
3149 conf->spare_page = alloc_page(GFP_KERNEL);
3150 if (!conf->spare_page)
3151 goto abort;
3152 }
2254 spin_lock_init(&conf->device_lock); 3153 spin_lock_init(&conf->device_lock);
2255 init_waitqueue_head(&conf->wait_for_stripe); 3154 init_waitqueue_head(&conf->wait_for_stripe);
2256 init_waitqueue_head(&conf->wait_for_overlap); 3155 init_waitqueue_head(&conf->wait_for_overlap);
@@ -2282,12 +3181,16 @@ static int run(mddev_t *mddev)
2282 } 3181 }
2283 3182
2284 /* 3183 /*
2285 * 0 for a fully functional array, 1 for a degraded array. 3184 * 0 for a fully functional array, 1 or 2 for a degraded array.
2286 */ 3185 */
2287 mddev->degraded = conf->failed_disks = conf->raid_disks - conf->working_disks; 3186 mddev->degraded = conf->failed_disks = conf->raid_disks - conf->working_disks;
2288 conf->mddev = mddev; 3187 conf->mddev = mddev;
2289 conf->chunk_size = mddev->chunk_size; 3188 conf->chunk_size = mddev->chunk_size;
2290 conf->level = mddev->level; 3189 conf->level = mddev->level;
3190 if (conf->level == 6)
3191 conf->max_degraded = 2;
3192 else
3193 conf->max_degraded = 1;
2291 conf->algorithm = mddev->layout; 3194 conf->algorithm = mddev->layout;
2292 conf->max_nr_stripes = NR_STRIPES; 3195 conf->max_nr_stripes = NR_STRIPES;
2293 conf->expand_progress = mddev->reshape_position; 3196 conf->expand_progress = mddev->reshape_position;
@@ -2296,6 +3199,11 @@ static int run(mddev_t *mddev)
2296 mddev->size &= ~(mddev->chunk_size/1024 -1); 3199 mddev->size &= ~(mddev->chunk_size/1024 -1);
2297 mddev->resync_max_sectors = mddev->size << 1; 3200 mddev->resync_max_sectors = mddev->size << 1;
2298 3201
3202 if (conf->level == 6 && conf->raid_disks < 4) {
3203 printk(KERN_ERR "raid6: not enough configured devices for %s (%d, minimum 4)\n",
3204 mdname(mddev), conf->raid_disks);
3205 goto abort;
3206 }
2299 if (!conf->chunk_size || conf->chunk_size % 4) { 3207 if (!conf->chunk_size || conf->chunk_size % 4) {
2300 printk(KERN_ERR "raid5: invalid chunk size %d for %s\n", 3208 printk(KERN_ERR "raid5: invalid chunk size %d for %s\n",
2301 conf->chunk_size, mdname(mddev)); 3209 conf->chunk_size, mdname(mddev));
@@ -2307,14 +3215,14 @@ static int run(mddev_t *mddev)
2307 conf->algorithm, mdname(mddev)); 3215 conf->algorithm, mdname(mddev));
2308 goto abort; 3216 goto abort;
2309 } 3217 }
2310 if (mddev->degraded > 1) { 3218 if (mddev->degraded > conf->max_degraded) {
2311 printk(KERN_ERR "raid5: not enough operational devices for %s" 3219 printk(KERN_ERR "raid5: not enough operational devices for %s"
2312 " (%d/%d failed)\n", 3220 " (%d/%d failed)\n",
2313 mdname(mddev), conf->failed_disks, conf->raid_disks); 3221 mdname(mddev), conf->failed_disks, conf->raid_disks);
2314 goto abort; 3222 goto abort;
2315 } 3223 }
2316 3224
2317 if (mddev->degraded == 1 && 3225 if (mddev->degraded > 0 &&
2318 mddev->recovery_cp != MaxSector) { 3226 mddev->recovery_cp != MaxSector) {
2319 if (mddev->ok_start_degraded) 3227 if (mddev->ok_start_degraded)
2320 printk(KERN_WARNING 3228 printk(KERN_WARNING
@@ -2373,17 +3281,15 @@ static int run(mddev_t *mddev)
2373 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); 3281 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
2374 mddev->sync_thread = md_register_thread(md_do_sync, mddev, 3282 mddev->sync_thread = md_register_thread(md_do_sync, mddev,
2375 "%s_reshape"); 3283 "%s_reshape");
2376 /* FIXME if md_register_thread fails?? */
2377 md_wakeup_thread(mddev->sync_thread);
2378
2379 } 3284 }
2380 3285
2381 /* read-ahead size must cover two whole stripes, which is 3286 /* read-ahead size must cover two whole stripes, which is
2382 * 2 * (n-1) * chunksize where 'n' is the number of raid devices 3287 * 2 * (datadisks) * chunksize where 'n' is the number of raid devices
2383 */ 3288 */
2384 { 3289 {
2385 int stripe = (mddev->raid_disks-1) * mddev->chunk_size 3290 int data_disks = conf->previous_raid_disks - conf->max_degraded;
2386 / PAGE_SIZE; 3291 int stripe = data_disks *
3292 (mddev->chunk_size / PAGE_SIZE);
2387 if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe) 3293 if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe)
2388 mddev->queue->backing_dev_info.ra_pages = 2 * stripe; 3294 mddev->queue->backing_dev_info.ra_pages = 2 * stripe;
2389 } 3295 }
@@ -2393,12 +3299,14 @@ static int run(mddev_t *mddev)
2393 3299
2394 mddev->queue->unplug_fn = raid5_unplug_device; 3300 mddev->queue->unplug_fn = raid5_unplug_device;
2395 mddev->queue->issue_flush_fn = raid5_issue_flush; 3301 mddev->queue->issue_flush_fn = raid5_issue_flush;
2396 mddev->array_size = mddev->size * (conf->previous_raid_disks - 1); 3302 mddev->array_size = mddev->size * (conf->previous_raid_disks -
3303 conf->max_degraded);
2397 3304
2398 return 0; 3305 return 0;
2399abort: 3306abort:
2400 if (conf) { 3307 if (conf) {
2401 print_raid5_conf(conf); 3308 print_raid5_conf(conf);
3309 safe_put_page(conf->spare_page);
2402 kfree(conf->disks); 3310 kfree(conf->disks);
2403 kfree(conf->stripe_hashtbl); 3311 kfree(conf->stripe_hashtbl);
2404 kfree(conf); 3312 kfree(conf);
@@ -2427,23 +3335,23 @@ static int stop(mddev_t *mddev)
2427} 3335}
2428 3336
2429#if RAID5_DEBUG 3337#if RAID5_DEBUG
2430static void print_sh (struct stripe_head *sh) 3338static void print_sh (struct seq_file *seq, struct stripe_head *sh)
2431{ 3339{
2432 int i; 3340 int i;
2433 3341
2434 printk("sh %llu, pd_idx %d, state %ld.\n", 3342 seq_printf(seq, "sh %llu, pd_idx %d, state %ld.\n",
2435 (unsigned long long)sh->sector, sh->pd_idx, sh->state); 3343 (unsigned long long)sh->sector, sh->pd_idx, sh->state);
2436 printk("sh %llu, count %d.\n", 3344 seq_printf(seq, "sh %llu, count %d.\n",
2437 (unsigned long long)sh->sector, atomic_read(&sh->count)); 3345 (unsigned long long)sh->sector, atomic_read(&sh->count));
2438 printk("sh %llu, ", (unsigned long long)sh->sector); 3346 seq_printf(seq, "sh %llu, ", (unsigned long long)sh->sector);
2439 for (i = 0; i < sh->disks; i++) { 3347 for (i = 0; i < sh->disks; i++) {
2440 printk("(cache%d: %p %ld) ", 3348 seq_printf(seq, "(cache%d: %p %ld) ",
2441 i, sh->dev[i].page, sh->dev[i].flags); 3349 i, sh->dev[i].page, sh->dev[i].flags);
2442 } 3350 }
2443 printk("\n"); 3351 seq_printf(seq, "\n");
2444} 3352}
2445 3353
2446static void printall (raid5_conf_t *conf) 3354static void printall (struct seq_file *seq, raid5_conf_t *conf)
2447{ 3355{
2448 struct stripe_head *sh; 3356 struct stripe_head *sh;
2449 struct hlist_node *hn; 3357 struct hlist_node *hn;
@@ -2454,7 +3362,7 @@ static void printall (raid5_conf_t *conf)
2454 hlist_for_each_entry(sh, hn, &conf->stripe_hashtbl[i], hash) { 3362 hlist_for_each_entry(sh, hn, &conf->stripe_hashtbl[i], hash) {
2455 if (sh->raid_conf != conf) 3363 if (sh->raid_conf != conf)
2456 continue; 3364 continue;
2457 print_sh(sh); 3365 print_sh(seq, sh);
2458 } 3366 }
2459 } 3367 }
2460 spin_unlock_irq(&conf->device_lock); 3368 spin_unlock_irq(&conf->device_lock);
@@ -2474,9 +3382,8 @@ static void status (struct seq_file *seq, mddev_t *mddev)
2474 test_bit(In_sync, &conf->disks[i].rdev->flags) ? "U" : "_"); 3382 test_bit(In_sync, &conf->disks[i].rdev->flags) ? "U" : "_");
2475 seq_printf (seq, "]"); 3383 seq_printf (seq, "]");
2476#if RAID5_DEBUG 3384#if RAID5_DEBUG
2477#define D(x) \ 3385 seq_printf (seq, "\n");
2478 seq_printf (seq, "<"#x":%d>", atomic_read(&conf->x)) 3386 printall(seq, conf);
2479 printall(conf);
2480#endif 3387#endif
2481} 3388}
2482 3389
@@ -2560,14 +3467,20 @@ static int raid5_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
2560 int disk; 3467 int disk;
2561 struct disk_info *p; 3468 struct disk_info *p;
2562 3469
2563 if (mddev->degraded > 1) 3470 if (mddev->degraded > conf->max_degraded)
2564 /* no point adding a device */ 3471 /* no point adding a device */
2565 return 0; 3472 return 0;
2566 3473
2567 /* 3474 /*
2568 * find the disk ... 3475 * find the disk ... but prefer rdev->saved_raid_disk
3476 * if possible.
2569 */ 3477 */
2570 for (disk=0; disk < conf->raid_disks; disk++) 3478 if (rdev->saved_raid_disk >= 0 &&
3479 conf->disks[rdev->saved_raid_disk].rdev == NULL)
3480 disk = rdev->saved_raid_disk;
3481 else
3482 disk = 0;
3483 for ( ; disk < conf->raid_disks; disk++)
2571 if ((p=conf->disks + disk)->rdev == NULL) { 3484 if ((p=conf->disks + disk)->rdev == NULL) {
2572 clear_bit(In_sync, &rdev->flags); 3485 clear_bit(In_sync, &rdev->flags);
2573 rdev->raid_disk = disk; 3486 rdev->raid_disk = disk;
@@ -2590,8 +3503,10 @@ static int raid5_resize(mddev_t *mddev, sector_t sectors)
2590 * any io in the removed space completes, but it hardly seems 3503 * any io in the removed space completes, but it hardly seems
2591 * worth it. 3504 * worth it.
2592 */ 3505 */
3506 raid5_conf_t *conf = mddev_to_conf(mddev);
3507
2593 sectors &= ~((sector_t)mddev->chunk_size/512 - 1); 3508 sectors &= ~((sector_t)mddev->chunk_size/512 - 1);
2594 mddev->array_size = (sectors * (mddev->raid_disks-1))>>1; 3509 mddev->array_size = (sectors * (mddev->raid_disks-conf->max_degraded))>>1;
2595 set_capacity(mddev->gendisk, mddev->array_size << 1); 3510 set_capacity(mddev->gendisk, mddev->array_size << 1);
2596 mddev->changed = 1; 3511 mddev->changed = 1;
2597 if (sectors/2 > mddev->size && mddev->recovery_cp == MaxSector) { 3512 if (sectors/2 > mddev->size && mddev->recovery_cp == MaxSector) {
@@ -2680,6 +3595,7 @@ static int raid5_start_reshape(mddev_t *mddev)
2680 set_bit(In_sync, &rdev->flags); 3595 set_bit(In_sync, &rdev->flags);
2681 conf->working_disks++; 3596 conf->working_disks++;
2682 added_devices++; 3597 added_devices++;
3598 rdev->recovery_offset = 0;
2683 sprintf(nm, "rd%d", rdev->raid_disk); 3599 sprintf(nm, "rd%d", rdev->raid_disk);
2684 sysfs_create_link(&mddev->kobj, &rdev->kobj, nm); 3600 sysfs_create_link(&mddev->kobj, &rdev->kobj, nm);
2685 } else 3601 } else
@@ -2731,6 +3647,17 @@ static void end_reshape(raid5_conf_t *conf)
2731 conf->expand_progress = MaxSector; 3647 conf->expand_progress = MaxSector;
2732 spin_unlock_irq(&conf->device_lock); 3648 spin_unlock_irq(&conf->device_lock);
2733 conf->mddev->reshape_position = MaxSector; 3649 conf->mddev->reshape_position = MaxSector;
3650
3651 /* read-ahead size must cover two whole stripes, which is
3652 * 2 * (datadisks) * chunksize where 'n' is the number of raid devices
3653 */
3654 {
3655 int data_disks = conf->previous_raid_disks - conf->max_degraded;
3656 int stripe = data_disks *
3657 (conf->mddev->chunk_size / PAGE_SIZE);
3658 if (conf->mddev->queue->backing_dev_info.ra_pages < 2 * stripe)
3659 conf->mddev->queue->backing_dev_info.ra_pages = 2 * stripe;
3660 }
2734 } 3661 }
2735} 3662}
2736 3663
@@ -2762,6 +3689,23 @@ static void raid5_quiesce(mddev_t *mddev, int state)
2762 } 3689 }
2763} 3690}
2764 3691
3692static struct mdk_personality raid6_personality =
3693{
3694 .name = "raid6",
3695 .level = 6,
3696 .owner = THIS_MODULE,
3697 .make_request = make_request,
3698 .run = run,
3699 .stop = stop,
3700 .status = status,
3701 .error_handler = error,
3702 .hot_add_disk = raid5_add_disk,
3703 .hot_remove_disk= raid5_remove_disk,
3704 .spare_active = raid5_spare_active,
3705 .sync_request = sync_request,
3706 .resize = raid5_resize,
3707 .quiesce = raid5_quiesce,
3708};
2765static struct mdk_personality raid5_personality = 3709static struct mdk_personality raid5_personality =
2766{ 3710{
2767 .name = "raid5", 3711 .name = "raid5",
@@ -2804,6 +3748,12 @@ static struct mdk_personality raid4_personality =
2804 3748
2805static int __init raid5_init(void) 3749static int __init raid5_init(void)
2806{ 3750{
3751 int e;
3752
3753 e = raid6_select_algo();
3754 if ( e )
3755 return e;
3756 register_md_personality(&raid6_personality);
2807 register_md_personality(&raid5_personality); 3757 register_md_personality(&raid5_personality);
2808 register_md_personality(&raid4_personality); 3758 register_md_personality(&raid4_personality);
2809 return 0; 3759 return 0;
@@ -2811,6 +3761,7 @@ static int __init raid5_init(void)
2811 3761
2812static void raid5_exit(void) 3762static void raid5_exit(void)
2813{ 3763{
3764 unregister_md_personality(&raid6_personality);
2814 unregister_md_personality(&raid5_personality); 3765 unregister_md_personality(&raid5_personality);
2815 unregister_md_personality(&raid4_personality); 3766 unregister_md_personality(&raid4_personality);
2816} 3767}
@@ -2823,3 +3774,10 @@ MODULE_ALIAS("md-raid5");
2823MODULE_ALIAS("md-raid4"); 3774MODULE_ALIAS("md-raid4");
2824MODULE_ALIAS("md-level-5"); 3775MODULE_ALIAS("md-level-5");
2825MODULE_ALIAS("md-level-4"); 3776MODULE_ALIAS("md-level-4");
3777MODULE_ALIAS("md-personality-8"); /* RAID6 */
3778MODULE_ALIAS("md-raid6");
3779MODULE_ALIAS("md-level-6");
3780
3781/* This used to be two separate modules, they were: */
3782MODULE_ALIAS("raid5");
3783MODULE_ALIAS("raid6");