Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] md: merge raid5 and raid6 code

There is a lot of commonality between raid5.c and raid6main.c. This patches
merges both into one module called raid456. This saves a lot of code, and
paves the way for online raid5->raid6 migrations.

There is still duplication, e.g. between handle_stripe5 and handle_stripe6.
This will probably be cleaned up later.

Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

NeilBrown and committed by
Linus Torvalds
16a53ecc 16f17b39

+1003 -2527
+12 -26
drivers/md/Kconfig
··· 104 104 105 105 If unsure, say Y. 106 106 107 - config MD_RAID5 108 - tristate "RAID-4/RAID-5 mode" 107 + config MD_RAID456 108 + tristate "RAID-4/RAID-5/RAID-6 mode" 109 109 depends on BLK_DEV_MD 110 110 ---help--- 111 111 A RAID-5 set of N drives with a capacity of C MB per drive provides ··· 116 116 while a RAID-5 set distributes the parity across the drives in one 117 117 of the available parity distribution methods. 118 118 119 + A RAID-6 set of N drives with a capacity of C MB per drive 120 + provides the capacity of C * (N - 2) MB, and protects 121 + against a failure of any two drives. For a given sector 122 + (row) number, (N - 2) drives contain data sectors, and two 123 + drives contains two independent redundancy syndromes. Like 124 + RAID-5, RAID-6 distributes the syndromes across the drives 125 + in one of the available parity distribution methods. 126 + 119 127 Information about Software RAID on Linux is contained in the 120 128 Software-RAID mini-HOWTO, available from 121 129 <http://www.tldp.org/docs.html#howto>. There you will also 122 130 learn where to get the supporting user space utilities raidtools. 123 131 124 - If you want to use such a RAID-4/RAID-5 set, say Y. To 132 + If you want to use such a RAID-4/RAID-5/RAID-6 set, say Y. To 125 133 compile this code as a module, choose M here: the module 126 - will be called raid5. 134 + will be called raid456. 127 135 128 136 If unsure, say Y. 129 137 ··· 161 153 Note: The array can only be expanded, not contracted. 162 154 There should be enough spares already present to make the new 163 155 array workable. 164 - 165 - config MD_RAID6 166 - tristate "RAID-6 mode" 167 - depends on BLK_DEV_MD 168 - ---help--- 169 - A RAID-6 set of N drives with a capacity of C MB per drive 170 - provides the capacity of C * (N - 2) MB, and protects 171 - against a failure of any two drives. For a given sector 172 - (row) number, (N - 2) drives contain data sectors, and two 173 - drives contains two independent redundancy syndromes. Like 174 - RAID-5, RAID-6 distributes the syndromes across the drives 175 - in one of the available parity distribution methods. 176 - 177 - RAID-6 requires mdadm-1.5.0 or later, available at: 178 - 179 - ftp://ftp.kernel.org/pub/linux/utils/raid/mdadm/ 180 - 181 - If you want to use such a RAID-6 set, say Y. To compile 182 - this code as a module, choose M here: the module will be 183 - called raid6. 184 - 185 - If unsure, say Y. 186 156 187 157 config MD_MULTIPATH 188 158 tristate "Multipath I/O support"
+2 -3
drivers/md/Makefile
··· 8 8 dm-snapshot-objs := dm-snap.o dm-exception-store.o 9 9 dm-mirror-objs := dm-log.o dm-raid1.o 10 10 md-mod-objs := md.o bitmap.o 11 - raid6-objs := raid6main.o raid6algos.o raid6recov.o raid6tables.o \ 11 + raid456-objs := raid5.o raid6algos.o raid6recov.o raid6tables.o \ 12 12 raid6int1.o raid6int2.o raid6int4.o \ 13 13 raid6int8.o raid6int16.o raid6int32.o \ 14 14 raid6altivec1.o raid6altivec2.o raid6altivec4.o \ ··· 25 25 obj-$(CONFIG_MD_RAID0) += raid0.o 26 26 obj-$(CONFIG_MD_RAID1) += raid1.o 27 27 obj-$(CONFIG_MD_RAID10) += raid10.o 28 - obj-$(CONFIG_MD_RAID5) += raid5.o xor.o 29 - obj-$(CONFIG_MD_RAID6) += raid6.o xor.o 28 + obj-$(CONFIG_MD_RAID456) += raid456.o xor.o 30 29 obj-$(CONFIG_MD_MULTIPATH) += multipath.o 31 30 obj-$(CONFIG_MD_FAULTY) += faulty.o 32 31 obj-$(CONFIG_BLK_DEV_MD) += md-mod.o
+988 -71
drivers/md/raid5.c
··· 2 2 * raid5.c : Multiple Devices driver for Linux 3 3 * Copyright (C) 1996, 1997 Ingo Molnar, Miguel de Icaza, Gadi Oxman 4 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 11 * This program is free software; you can redistribute it and/or modify 9 12 * it under the terms of the GNU General Public License as published by ··· 22 19 #include <linux/config.h> 23 20 #include <linux/module.h> 24 21 #include <linux/slab.h> 25 - #include <linux/raid/raid5.h> 26 22 #include <linux/highmem.h> 27 23 #include <linux/bitops.h> 28 24 #include <linux/kthread.h> 29 25 #include <asm/atomic.h> 26 + #include "raid6.h" 30 27 31 28 #include <linux/raid/bitmap.h> 32 29 ··· 71 68 #define __inline__ 72 69 #endif 73 70 71 + #if !RAID6_USE_EMPTY_ZERO_PAGE 72 + /* In .bss so it's zeroed */ 73 + const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256))); 74 + #endif 75 + 76 + static inline int raid6_next_disk(int disk, int raid_disks) 77 + { 78 + disk++; 79 + return (disk < raid_disks) ? disk : 0; 80 + } 74 81 static void print_raid5_conf (raid5_conf_t *conf); 75 82 76 83 static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh) ··· 117 104 { 118 105 raid5_conf_t *conf = sh->raid_conf; 119 106 unsigned long flags; 120 - 107 + 121 108 spin_lock_irqsave(&conf->device_lock, flags); 122 109 __release_stripe(conf, sh); 123 110 spin_unlock_irqrestore(&conf->device_lock, flags); ··· 130 117 hlist_del_init(&sh->hash); 131 118 } 132 119 133 - static void insert_hash(raid5_conf_t *conf, struct stripe_head *sh) 120 + static inline void insert_hash(raid5_conf_t *conf, struct stripe_head *sh) 134 121 { 135 122 struct hlist_head *hp = stripe_hash(conf, sh->sector); 136 123 ··· 203 190 (unsigned long long)sh->sector); 204 191 205 192 remove_hash(sh); 206 - 193 + 207 194 sh->sector = sector; 208 195 sh->pd_idx = pd_idx; 209 196 sh->state = 0; ··· 282 269 } else { 283 270 if (!test_bit(STRIPE_HANDLE, &sh->state)) 284 271 atomic_inc(&conf->active_stripes); 285 - if (!list_empty(&sh->lru)) 286 - list_del_init(&sh->lru); 272 + if (list_empty(&sh->lru)) 273 + BUG(); 274 + list_del_init(&sh->lru); 287 275 } 288 276 } 289 277 } while (sh == NULL); ··· 335 321 return 1; 336 322 conf->slab_cache = sc; 337 323 conf->pool_size = devs; 338 - while (num--) { 324 + while (num--) 339 325 if (!grow_one_stripe(conf)) 340 326 return 1; 341 - } 342 327 return 0; 343 328 } 344 329 ··· 644 631 dev->req.bi_private = sh; 645 632 646 633 dev->flags = 0; 647 - if (i != sh->pd_idx) 648 - dev->sector = compute_blocknr(sh, i); 634 + dev->sector = compute_blocknr(sh, i); 649 635 } 650 636 651 637 static void error(mddev_t *mddev, mdk_rdev_t *rdev) ··· 671 659 " Operation continuing on %d devices\n", 672 660 bdevname(rdev->bdev,b), conf->working_disks); 673 661 } 674 - } 662 + } 675 663 676 664 /* 677 665 * Input: a 'big' sector number, ··· 709 697 /* 710 698 * Select the parity disk based on the user selected algorithm. 711 699 */ 712 - if (conf->level == 4) 700 + switch(conf->level) { 701 + case 4: 713 702 *pd_idx = data_disks; 714 - else switch (conf->algorithm) { 703 + break; 704 + case 5: 705 + switch (conf->algorithm) { 715 706 case ALGORITHM_LEFT_ASYMMETRIC: 716 707 *pd_idx = data_disks - stripe % raid_disks; 717 708 if (*dd_idx >= *pd_idx) ··· 736 721 default: 737 722 printk(KERN_ERR "raid5: unsupported algorithm %d\n", 738 723 conf->algorithm); 724 + } 725 + break; 726 + case 6: 727 + 728 + /**** FIX THIS ****/ 729 + switch (conf->algorithm) { 730 + case ALGORITHM_LEFT_ASYMMETRIC: 731 + *pd_idx = raid_disks - 1 - (stripe % raid_disks); 732 + if (*pd_idx == raid_disks-1) 733 + (*dd_idx)++; /* Q D D D P */ 734 + else if (*dd_idx >= *pd_idx) 735 + (*dd_idx) += 2; /* D D P Q D */ 736 + break; 737 + case ALGORITHM_RIGHT_ASYMMETRIC: 738 + *pd_idx = stripe % raid_disks; 739 + if (*pd_idx == raid_disks-1) 740 + (*dd_idx)++; /* Q D D D P */ 741 + else if (*dd_idx >= *pd_idx) 742 + (*dd_idx) += 2; /* D D P Q D */ 743 + break; 744 + case ALGORITHM_LEFT_SYMMETRIC: 745 + *pd_idx = raid_disks - 1 - (stripe % raid_disks); 746 + *dd_idx = (*pd_idx + 2 + *dd_idx) % raid_disks; 747 + break; 748 + case ALGORITHM_RIGHT_SYMMETRIC: 749 + *pd_idx = stripe % raid_disks; 750 + *dd_idx = (*pd_idx + 2 + *dd_idx) % raid_disks; 751 + break; 752 + default: 753 + printk (KERN_CRIT "raid6: unsupported algorithm %d\n", 754 + conf->algorithm); 755 + } 756 + break; 739 757 } 740 758 741 759 /* ··· 790 742 int chunk_number, dummy1, dummy2, dd_idx = i; 791 743 sector_t r_sector; 792 744 745 + 793 746 chunk_offset = sector_div(new_sector, sectors_per_chunk); 794 747 stripe = new_sector; 795 748 BUG_ON(new_sector != stripe); 796 749 797 - 798 - switch (conf->algorithm) { 750 + if (i == sh->pd_idx) 751 + return 0; 752 + switch(conf->level) { 753 + case 4: break; 754 + case 5: 755 + switch (conf->algorithm) { 799 756 case ALGORITHM_LEFT_ASYMMETRIC: 800 757 case ALGORITHM_RIGHT_ASYMMETRIC: 801 758 if (i > sh->pd_idx) ··· 814 761 break; 815 762 default: 816 763 printk(KERN_ERR "raid5: unsupported algorithm %d\n", 764 + conf->algorithm); 765 + } 766 + break; 767 + case 6: 768 + data_disks = raid_disks - 2; 769 + if (i == raid6_next_disk(sh->pd_idx, raid_disks)) 770 + return 0; /* It is the Q disk */ 771 + switch (conf->algorithm) { 772 + case ALGORITHM_LEFT_ASYMMETRIC: 773 + case ALGORITHM_RIGHT_ASYMMETRIC: 774 + if (sh->pd_idx == raid_disks-1) 775 + i--; /* Q D D D P */ 776 + else if (i > sh->pd_idx) 777 + i -= 2; /* D D P Q D */ 778 + break; 779 + case ALGORITHM_LEFT_SYMMETRIC: 780 + case ALGORITHM_RIGHT_SYMMETRIC: 781 + if (sh->pd_idx == raid_disks-1) 782 + i--; /* Q D D D P */ 783 + else { 784 + /* D D P Q D */ 785 + if (i < sh->pd_idx) 786 + i += raid_disks; 787 + i -= (sh->pd_idx + 2); 788 + } 789 + break; 790 + default: 791 + printk (KERN_CRIT "raid6: unsupported algorithm %d\n", 817 792 conf->algorithm); 793 + } 794 + break; 818 795 } 819 796 820 797 chunk_number = stripe * data_disks + i; ··· 861 778 862 779 863 780 /* 864 - * Copy data between a page in the stripe cache, and a bio. 865 - * There are no alignment or size guarantees between the page or the 866 - * bio except that there is some overlap. 867 - * All iovecs in the bio must be considered. 781 + * Copy data between a page in the stripe cache, and one or more bion 782 + * The page could align with the middle of the bio, or there could be 783 + * several bion, each with several bio_vecs, which cover part of the page 784 + * Multiple bion are linked together on bi_next. There may be extras 785 + * at the end of this list. We ignore them. 868 786 */ 869 787 static void copy_data(int frombio, struct bio *bio, 870 788 struct page *page, ··· 894 810 if (len > 0 && page_offset + len > STRIPE_SIZE) 895 811 clen = STRIPE_SIZE - page_offset; 896 812 else clen = len; 897 - 813 + 898 814 if (clen > 0) { 899 815 char *ba = __bio_kmap_atomic(bio, i, KM_USER0); 900 816 if (frombio) ··· 946 862 set_bit(R5_UPTODATE, &sh->dev[dd_idx].flags); 947 863 } 948 864 949 - static void compute_parity(struct stripe_head *sh, int method) 865 + static void compute_parity5(struct stripe_head *sh, int method) 950 866 { 951 867 raid5_conf_t *conf = sh->raid_conf; 952 868 int i, pd_idx = sh->pd_idx, disks = sh->disks, count; 953 869 void *ptr[MAX_XOR_BLOCKS]; 954 870 struct bio *chosen; 955 871 956 - PRINTK("compute_parity, stripe %llu, method %d\n", 872 + PRINTK("compute_parity5, stripe %llu, method %d\n", 957 873 (unsigned long long)sh->sector, method); 958 874 959 875 count = 1; ··· 1040 956 clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); 1041 957 } 1042 958 959 + static void compute_parity6(struct stripe_head *sh, int method) 960 + { 961 + raid6_conf_t *conf = sh->raid_conf; 962 + int i, pd_idx = sh->pd_idx, qd_idx, d0_idx, disks = conf->raid_disks, count; 963 + struct bio *chosen; 964 + /**** FIX THIS: This could be very bad if disks is close to 256 ****/ 965 + void *ptrs[disks]; 966 + 967 + qd_idx = raid6_next_disk(pd_idx, disks); 968 + d0_idx = raid6_next_disk(qd_idx, disks); 969 + 970 + PRINTK("compute_parity, stripe %llu, method %d\n", 971 + (unsigned long long)sh->sector, method); 972 + 973 + switch(method) { 974 + case READ_MODIFY_WRITE: 975 + BUG(); /* READ_MODIFY_WRITE N/A for RAID-6 */ 976 + case RECONSTRUCT_WRITE: 977 + for (i= disks; i-- ;) 978 + if ( i != pd_idx && i != qd_idx && sh->dev[i].towrite ) { 979 + chosen = sh->dev[i].towrite; 980 + sh->dev[i].towrite = NULL; 981 + 982 + if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 983 + wake_up(&conf->wait_for_overlap); 984 + 985 + if (sh->dev[i].written) BUG(); 986 + sh->dev[i].written = chosen; 987 + } 988 + break; 989 + case CHECK_PARITY: 990 + BUG(); /* Not implemented yet */ 991 + } 992 + 993 + for (i = disks; i--;) 994 + if (sh->dev[i].written) { 995 + sector_t sector = sh->dev[i].sector; 996 + struct bio *wbi = sh->dev[i].written; 997 + while (wbi && wbi->bi_sector < sector + STRIPE_SECTORS) { 998 + copy_data(1, wbi, sh->dev[i].page, sector); 999 + wbi = r5_next_bio(wbi, sector); 1000 + } 1001 + 1002 + set_bit(R5_LOCKED, &sh->dev[i].flags); 1003 + set_bit(R5_UPTODATE, &sh->dev[i].flags); 1004 + } 1005 + 1006 + // switch(method) { 1007 + // case RECONSTRUCT_WRITE: 1008 + // case CHECK_PARITY: 1009 + // case UPDATE_PARITY: 1010 + /* Note that unlike RAID-5, the ordering of the disks matters greatly. */ 1011 + /* FIX: Is this ordering of drives even remotely optimal? */ 1012 + count = 0; 1013 + i = d0_idx; 1014 + do { 1015 + ptrs[count++] = page_address(sh->dev[i].page); 1016 + if (count <= disks-2 && !test_bit(R5_UPTODATE, &sh->dev[i].flags)) 1017 + printk("block %d/%d not uptodate on parity calc\n", i,count); 1018 + i = raid6_next_disk(i, disks); 1019 + } while ( i != d0_idx ); 1020 + // break; 1021 + // } 1022 + 1023 + raid6_call.gen_syndrome(disks, STRIPE_SIZE, ptrs); 1024 + 1025 + switch(method) { 1026 + case RECONSTRUCT_WRITE: 1027 + set_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); 1028 + set_bit(R5_UPTODATE, &sh->dev[qd_idx].flags); 1029 + set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); 1030 + set_bit(R5_LOCKED, &sh->dev[qd_idx].flags); 1031 + break; 1032 + case UPDATE_PARITY: 1033 + set_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); 1034 + set_bit(R5_UPTODATE, &sh->dev[qd_idx].flags); 1035 + break; 1036 + } 1037 + } 1038 + 1039 + 1040 + /* Compute one missing block */ 1041 + static void compute_block_1(struct stripe_head *sh, int dd_idx, int nozero) 1042 + { 1043 + raid6_conf_t *conf = sh->raid_conf; 1044 + int i, count, disks = conf->raid_disks; 1045 + void *ptr[MAX_XOR_BLOCKS], *p; 1046 + int pd_idx = sh->pd_idx; 1047 + int qd_idx = raid6_next_disk(pd_idx, disks); 1048 + 1049 + PRINTK("compute_block_1, stripe %llu, idx %d\n", 1050 + (unsigned long long)sh->sector, dd_idx); 1051 + 1052 + if ( dd_idx == qd_idx ) { 1053 + /* We're actually computing the Q drive */ 1054 + compute_parity6(sh, UPDATE_PARITY); 1055 + } else { 1056 + ptr[0] = page_address(sh->dev[dd_idx].page); 1057 + if (!nozero) memset(ptr[0], 0, STRIPE_SIZE); 1058 + count = 1; 1059 + for (i = disks ; i--; ) { 1060 + if (i == dd_idx || i == qd_idx) 1061 + continue; 1062 + p = page_address(sh->dev[i].page); 1063 + if (test_bit(R5_UPTODATE, &sh->dev[i].flags)) 1064 + ptr[count++] = p; 1065 + else 1066 + printk("compute_block() %d, stripe %llu, %d" 1067 + " not present\n", dd_idx, 1068 + (unsigned long long)sh->sector, i); 1069 + 1070 + check_xor(); 1071 + } 1072 + if (count != 1) 1073 + xor_block(count, STRIPE_SIZE, ptr); 1074 + if (!nozero) set_bit(R5_UPTODATE, &sh->dev[dd_idx].flags); 1075 + else clear_bit(R5_UPTODATE, &sh->dev[dd_idx].flags); 1076 + } 1077 + } 1078 + 1079 + /* Compute two missing blocks */ 1080 + static void compute_block_2(struct stripe_head *sh, int dd_idx1, int dd_idx2) 1081 + { 1082 + raid6_conf_t *conf = sh->raid_conf; 1083 + int i, count, disks = conf->raid_disks; 1084 + int pd_idx = sh->pd_idx; 1085 + int qd_idx = raid6_next_disk(pd_idx, disks); 1086 + int d0_idx = raid6_next_disk(qd_idx, disks); 1087 + int faila, failb; 1088 + 1089 + /* faila and failb are disk numbers relative to d0_idx */ 1090 + /* pd_idx become disks-2 and qd_idx become disks-1 */ 1091 + faila = (dd_idx1 < d0_idx) ? dd_idx1+(disks-d0_idx) : dd_idx1-d0_idx; 1092 + failb = (dd_idx2 < d0_idx) ? dd_idx2+(disks-d0_idx) : dd_idx2-d0_idx; 1093 + 1094 + BUG_ON(faila == failb); 1095 + if ( failb < faila ) { int tmp = faila; faila = failb; failb = tmp; } 1096 + 1097 + PRINTK("compute_block_2, stripe %llu, idx %d,%d (%d,%d)\n", 1098 + (unsigned long long)sh->sector, dd_idx1, dd_idx2, faila, failb); 1099 + 1100 + if ( failb == disks-1 ) { 1101 + /* Q disk is one of the missing disks */ 1102 + if ( faila == disks-2 ) { 1103 + /* Missing P+Q, just recompute */ 1104 + compute_parity6(sh, UPDATE_PARITY); 1105 + return; 1106 + } else { 1107 + /* We're missing D+Q; recompute D from P */ 1108 + compute_block_1(sh, (dd_idx1 == qd_idx) ? dd_idx2 : dd_idx1, 0); 1109 + compute_parity6(sh, UPDATE_PARITY); /* Is this necessary? */ 1110 + return; 1111 + } 1112 + } 1113 + 1114 + /* We're missing D+P or D+D; build pointer table */ 1115 + { 1116 + /**** FIX THIS: This could be very bad if disks is close to 256 ****/ 1117 + void *ptrs[disks]; 1118 + 1119 + count = 0; 1120 + i = d0_idx; 1121 + do { 1122 + ptrs[count++] = page_address(sh->dev[i].page); 1123 + i = raid6_next_disk(i, disks); 1124 + if (i != dd_idx1 && i != dd_idx2 && 1125 + !test_bit(R5_UPTODATE, &sh->dev[i].flags)) 1126 + printk("compute_2 with missing block %d/%d\n", count, i); 1127 + } while ( i != d0_idx ); 1128 + 1129 + if ( failb == disks-2 ) { 1130 + /* We're missing D+P. */ 1131 + raid6_datap_recov(disks, STRIPE_SIZE, faila, ptrs); 1132 + } else { 1133 + /* We're missing D+D. */ 1134 + raid6_2data_recov(disks, STRIPE_SIZE, faila, failb, ptrs); 1135 + } 1136 + 1137 + /* Both the above update both missing blocks */ 1138 + set_bit(R5_UPTODATE, &sh->dev[dd_idx1].flags); 1139 + set_bit(R5_UPTODATE, &sh->dev[dd_idx2].flags); 1140 + } 1141 + } 1142 + 1143 + 1144 + 1043 1145 /* 1044 1146 * Each stripe/dev can have one or more bion attached. 1045 - * toread/towrite point to the first in a chain. 1147 + * toread/towrite point to the first in a chain. 1046 1148 * The bi_next chain must be in order. 1047 1149 */ 1048 1150 static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, int forwrite) ··· 1301 1031 1302 1032 static void end_reshape(raid5_conf_t *conf); 1303 1033 1034 + static int page_is_zero(struct page *p) 1035 + { 1036 + char *a = page_address(p); 1037 + return ((*(u32*)a) == 0 && 1038 + memcmp(a, a+4, STRIPE_SIZE-4)==0); 1039 + } 1040 + 1304 1041 static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int disks) 1305 1042 { 1306 1043 int sectors_per_chunk = conf->chunk_size >> 9; ··· 1339 1062 * 1340 1063 */ 1341 1064 1342 - static void handle_stripe(struct stripe_head *sh) 1065 + static void handle_stripe5(struct stripe_head *sh) 1343 1066 { 1344 1067 raid5_conf_t *conf = sh->raid_conf; 1345 1068 int disks = sh->disks; ··· 1671 1394 if (locked == 0 && (rcw == 0 ||rmw == 0) && 1672 1395 !test_bit(STRIPE_BIT_DELAY, &sh->state)) { 1673 1396 PRINTK("Computing parity...\n"); 1674 - compute_parity(sh, rcw==0 ? RECONSTRUCT_WRITE : READ_MODIFY_WRITE); 1397 + compute_parity5(sh, rcw==0 ? RECONSTRUCT_WRITE : READ_MODIFY_WRITE); 1675 1398 /* now every locked buffer is ready to be written */ 1676 1399 for (i=disks; i--;) 1677 1400 if (test_bit(R5_LOCKED, &sh->dev[i].flags)) { ··· 1698 1421 !test_bit(STRIPE_INSYNC, &sh->state)) { 1699 1422 set_bit(STRIPE_HANDLE, &sh->state); 1700 1423 if (failed == 0) { 1701 - char *pagea; 1702 1424 BUG_ON(uptodate != disks); 1703 - compute_parity(sh, CHECK_PARITY); 1425 + compute_parity5(sh, CHECK_PARITY); 1704 1426 uptodate--; 1705 - pagea = page_address(sh->dev[sh->pd_idx].page); 1706 - if ((*(u32*)pagea) == 0 && 1707 - !memcmp(pagea, pagea+4, STRIPE_SIZE-4)) { 1427 + if (page_is_zero(sh->dev[sh->pd_idx].page)) { 1708 1428 /* parity is correct (on disc, not in buffer any more) */ 1709 1429 set_bit(STRIPE_INSYNC, &sh->state); 1710 1430 } else { ··· 1761 1487 /* Need to write out all blocks after computing parity */ 1762 1488 sh->disks = conf->raid_disks; 1763 1489 sh->pd_idx = stripe_to_pdidx(sh->sector, conf, conf->raid_disks); 1764 - compute_parity(sh, RECONSTRUCT_WRITE); 1490 + compute_parity5(sh, RECONSTRUCT_WRITE); 1765 1491 for (i= conf->raid_disks; i--;) { 1766 1492 set_bit(R5_LOCKED, &sh->dev[i].flags); 1767 1493 locked++; ··· 1888 1614 } 1889 1615 } 1890 1616 } 1617 + 1618 + static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page) 1619 + { 1620 + raid6_conf_t *conf = sh->raid_conf; 1621 + int disks = conf->raid_disks; 1622 + struct bio *return_bi= NULL; 1623 + struct bio *bi; 1624 + int i; 1625 + int syncing; 1626 + int locked=0, uptodate=0, to_read=0, to_write=0, failed=0, written=0; 1627 + int non_overwrite = 0; 1628 + int failed_num[2] = {0, 0}; 1629 + struct r5dev *dev, *pdev, *qdev; 1630 + int pd_idx = sh->pd_idx; 1631 + int qd_idx = raid6_next_disk(pd_idx, disks); 1632 + int p_failed, q_failed; 1633 + 1634 + PRINTK("handling stripe %llu, state=%#lx cnt=%d, pd_idx=%d, qd_idx=%d\n", 1635 + (unsigned long long)sh->sector, sh->state, atomic_read(&sh->count), 1636 + pd_idx, qd_idx); 1637 + 1638 + spin_lock(&sh->lock); 1639 + clear_bit(STRIPE_HANDLE, &sh->state); 1640 + clear_bit(STRIPE_DELAYED, &sh->state); 1641 + 1642 + syncing = test_bit(STRIPE_SYNCING, &sh->state); 1643 + /* Now to look around and see what can be done */ 1644 + 1645 + rcu_read_lock(); 1646 + for (i=disks; i--; ) { 1647 + mdk_rdev_t *rdev; 1648 + dev = &sh->dev[i]; 1649 + clear_bit(R5_Insync, &dev->flags); 1650 + 1651 + PRINTK("check %d: state 0x%lx read %p write %p written %p\n", 1652 + i, dev->flags, dev->toread, dev->towrite, dev->written); 1653 + /* maybe we can reply to a read */ 1654 + if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread) { 1655 + struct bio *rbi, *rbi2; 1656 + PRINTK("Return read for disc %d\n", i); 1657 + spin_lock_irq(&conf->device_lock); 1658 + rbi = dev->toread; 1659 + dev->toread = NULL; 1660 + if (test_and_clear_bit(R5_Overlap, &dev->flags)) 1661 + wake_up(&conf->wait_for_overlap); 1662 + spin_unlock_irq(&conf->device_lock); 1663 + while (rbi && rbi->bi_sector < dev->sector + STRIPE_SECTORS) { 1664 + copy_data(0, rbi, dev->page, dev->sector); 1665 + rbi2 = r5_next_bio(rbi, dev->sector); 1666 + spin_lock_irq(&conf->device_lock); 1667 + if (--rbi->bi_phys_segments == 0) { 1668 + rbi->bi_next = return_bi; 1669 + return_bi = rbi; 1670 + } 1671 + spin_unlock_irq(&conf->device_lock); 1672 + rbi = rbi2; 1673 + } 1674 + } 1675 + 1676 + /* now count some things */ 1677 + if (test_bit(R5_LOCKED, &dev->flags)) locked++; 1678 + if (test_bit(R5_UPTODATE, &dev->flags)) uptodate++; 1679 + 1680 + 1681 + if (dev->toread) to_read++; 1682 + if (dev->towrite) { 1683 + to_write++; 1684 + if (!test_bit(R5_OVERWRITE, &dev->flags)) 1685 + non_overwrite++; 1686 + } 1687 + if (dev->written) written++; 1688 + rdev = rcu_dereference(conf->disks[i].rdev); 1689 + if (!rdev || !test_bit(In_sync, &rdev->flags)) { 1690 + /* The ReadError flag will just be confusing now */ 1691 + clear_bit(R5_ReadError, &dev->flags); 1692 + clear_bit(R5_ReWrite, &dev->flags); 1693 + } 1694 + if (!rdev || !test_bit(In_sync, &rdev->flags) 1695 + || test_bit(R5_ReadError, &dev->flags)) { 1696 + if ( failed < 2 ) 1697 + failed_num[failed] = i; 1698 + failed++; 1699 + } else 1700 + set_bit(R5_Insync, &dev->flags); 1701 + } 1702 + rcu_read_unlock(); 1703 + PRINTK("locked=%d uptodate=%d to_read=%d" 1704 + " to_write=%d failed=%d failed_num=%d,%d\n", 1705 + locked, uptodate, to_read, to_write, failed, 1706 + failed_num[0], failed_num[1]); 1707 + /* check if the array has lost >2 devices and, if so, some requests might 1708 + * need to be failed 1709 + */ 1710 + if (failed > 2 && to_read+to_write+written) { 1711 + for (i=disks; i--; ) { 1712 + int bitmap_end = 0; 1713 + 1714 + if (test_bit(R5_ReadError, &sh->dev[i].flags)) { 1715 + mdk_rdev_t *rdev; 1716 + rcu_read_lock(); 1717 + rdev = rcu_dereference(conf->disks[i].rdev); 1718 + if (rdev && test_bit(In_sync, &rdev->flags)) 1719 + /* multiple read failures in one stripe */ 1720 + md_error(conf->mddev, rdev); 1721 + rcu_read_unlock(); 1722 + } 1723 + 1724 + spin_lock_irq(&conf->device_lock); 1725 + /* fail all writes first */ 1726 + bi = sh->dev[i].towrite; 1727 + sh->dev[i].towrite = NULL; 1728 + if (bi) { to_write--; bitmap_end = 1; } 1729 + 1730 + if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 1731 + wake_up(&conf->wait_for_overlap); 1732 + 1733 + while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS){ 1734 + struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); 1735 + clear_bit(BIO_UPTODATE, &bi->bi_flags); 1736 + if (--bi->bi_phys_segments == 0) { 1737 + md_write_end(conf->mddev); 1738 + bi->bi_next = return_bi; 1739 + return_bi = bi; 1740 + } 1741 + bi = nextbi; 1742 + } 1743 + /* and fail all 'written' */ 1744 + bi = sh->dev[i].written; 1745 + sh->dev[i].written = NULL; 1746 + if (bi) bitmap_end = 1; 1747 + while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS) { 1748 + struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); 1749 + clear_bit(BIO_UPTODATE, &bi->bi_flags); 1750 + if (--bi->bi_phys_segments == 0) { 1751 + md_write_end(conf->mddev); 1752 + bi->bi_next = return_bi; 1753 + return_bi = bi; 1754 + } 1755 + bi = bi2; 1756 + } 1757 + 1758 + /* fail any reads if this device is non-operational */ 1759 + if (!test_bit(R5_Insync, &sh->dev[i].flags) || 1760 + test_bit(R5_ReadError, &sh->dev[i].flags)) { 1761 + bi = sh->dev[i].toread; 1762 + sh->dev[i].toread = NULL; 1763 + if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 1764 + wake_up(&conf->wait_for_overlap); 1765 + if (bi) to_read--; 1766 + while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS){ 1767 + struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); 1768 + clear_bit(BIO_UPTODATE, &bi->bi_flags); 1769 + if (--bi->bi_phys_segments == 0) { 1770 + bi->bi_next = return_bi; 1771 + return_bi = bi; 1772 + } 1773 + bi = nextbi; 1774 + } 1775 + } 1776 + spin_unlock_irq(&conf->device_lock); 1777 + if (bitmap_end) 1778 + bitmap_endwrite(conf->mddev->bitmap, sh->sector, 1779 + STRIPE_SECTORS, 0, 0); 1780 + } 1781 + } 1782 + if (failed > 2 && syncing) { 1783 + md_done_sync(conf->mddev, STRIPE_SECTORS,0); 1784 + clear_bit(STRIPE_SYNCING, &sh->state); 1785 + syncing = 0; 1786 + } 1787 + 1788 + /* 1789 + * might be able to return some write requests if the parity blocks 1790 + * are safe, or on a failed drive 1791 + */ 1792 + pdev = &sh->dev[pd_idx]; 1793 + p_failed = (failed >= 1 && failed_num[0] == pd_idx) 1794 + || (failed >= 2 && failed_num[1] == pd_idx); 1795 + qdev = &sh->dev[qd_idx]; 1796 + q_failed = (failed >= 1 && failed_num[0] == qd_idx) 1797 + || (failed >= 2 && failed_num[1] == qd_idx); 1798 + 1799 + if ( written && 1800 + ( p_failed || ((test_bit(R5_Insync, &pdev->flags) 1801 + && !test_bit(R5_LOCKED, &pdev->flags) 1802 + && test_bit(R5_UPTODATE, &pdev->flags))) ) && 1803 + ( q_failed || ((test_bit(R5_Insync, &qdev->flags) 1804 + && !test_bit(R5_LOCKED, &qdev->flags) 1805 + && test_bit(R5_UPTODATE, &qdev->flags))) ) ) { 1806 + /* any written block on an uptodate or failed drive can be 1807 + * returned. Note that if we 'wrote' to a failed drive, 1808 + * it will be UPTODATE, but never LOCKED, so we don't need 1809 + * to test 'failed' directly. 1810 + */ 1811 + for (i=disks; i--; ) 1812 + if (sh->dev[i].written) { 1813 + dev = &sh->dev[i]; 1814 + if (!test_bit(R5_LOCKED, &dev->flags) && 1815 + test_bit(R5_UPTODATE, &dev->flags) ) { 1816 + /* We can return any write requests */ 1817 + int bitmap_end = 0; 1818 + struct bio *wbi, *wbi2; 1819 + PRINTK("Return write for stripe %llu disc %d\n", 1820 + (unsigned long long)sh->sector, i); 1821 + spin_lock_irq(&conf->device_lock); 1822 + wbi = dev->written; 1823 + dev->written = NULL; 1824 + while (wbi && wbi->bi_sector < dev->sector + STRIPE_SECTORS) { 1825 + wbi2 = r5_next_bio(wbi, dev->sector); 1826 + if (--wbi->bi_phys_segments == 0) { 1827 + md_write_end(conf->mddev); 1828 + wbi->bi_next = return_bi; 1829 + return_bi = wbi; 1830 + } 1831 + wbi = wbi2; 1832 + } 1833 + if (dev->towrite == NULL) 1834 + bitmap_end = 1; 1835 + spin_unlock_irq(&conf->device_lock); 1836 + if (bitmap_end) 1837 + bitmap_endwrite(conf->mddev->bitmap, sh->sector, 1838 + STRIPE_SECTORS, 1839 + !test_bit(STRIPE_DEGRADED, &sh->state), 0); 1840 + } 1841 + } 1842 + } 1843 + 1844 + /* Now we might consider reading some blocks, either to check/generate 1845 + * parity, or to satisfy requests 1846 + * or to load a block that is being partially written. 1847 + */ 1848 + if (to_read || non_overwrite || (to_write && failed) || (syncing && (uptodate < disks))) { 1849 + for (i=disks; i--;) { 1850 + dev = &sh->dev[i]; 1851 + if (!test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_UPTODATE, &dev->flags) && 1852 + (dev->toread || 1853 + (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || 1854 + syncing || 1855 + (failed >= 1 && (sh->dev[failed_num[0]].toread || to_write)) || 1856 + (failed >= 2 && (sh->dev[failed_num[1]].toread || to_write)) 1857 + ) 1858 + ) { 1859 + /* we would like to get this block, possibly 1860 + * by computing it, but we might not be able to 1861 + */ 1862 + if (uptodate == disks-1) { 1863 + PRINTK("Computing stripe %llu block %d\n", 1864 + (unsigned long long)sh->sector, i); 1865 + compute_block_1(sh, i, 0); 1866 + uptodate++; 1867 + } else if ( uptodate == disks-2 && failed >= 2 ) { 1868 + /* Computing 2-failure is *very* expensive; only do it if failed >= 2 */ 1869 + int other; 1870 + for (other=disks; other--;) { 1871 + if ( other == i ) 1872 + continue; 1873 + if ( !test_bit(R5_UPTODATE, &sh->dev[other].flags) ) 1874 + break; 1875 + } 1876 + BUG_ON(other < 0); 1877 + PRINTK("Computing stripe %llu blocks %d,%d\n", 1878 + (unsigned long long)sh->sector, i, other); 1879 + compute_block_2(sh, i, other); 1880 + uptodate += 2; 1881 + } else if (test_bit(R5_Insync, &dev->flags)) { 1882 + set_bit(R5_LOCKED, &dev->flags); 1883 + set_bit(R5_Wantread, &dev->flags); 1884 + #if 0 1885 + /* if I am just reading this block and we don't have 1886 + a failed drive, or any pending writes then sidestep the cache */ 1887 + if (sh->bh_read[i] && !sh->bh_read[i]->b_reqnext && 1888 + ! syncing && !failed && !to_write) { 1889 + sh->bh_cache[i]->b_page = sh->bh_read[i]->b_page; 1890 + sh->bh_cache[i]->b_data = sh->bh_read[i]->b_data; 1891 + } 1892 + #endif 1893 + locked++; 1894 + PRINTK("Reading block %d (sync=%d)\n", 1895 + i, syncing); 1896 + } 1897 + } 1898 + } 1899 + set_bit(STRIPE_HANDLE, &sh->state); 1900 + } 1901 + 1902 + /* now to consider writing and what else, if anything should be read */ 1903 + if (to_write) { 1904 + int rcw=0, must_compute=0; 1905 + for (i=disks ; i--;) { 1906 + dev = &sh->dev[i]; 1907 + /* Would I have to read this buffer for reconstruct_write */ 1908 + if (!test_bit(R5_OVERWRITE, &dev->flags) 1909 + && i != pd_idx && i != qd_idx 1910 + && (!test_bit(R5_LOCKED, &dev->flags) 1911 + #if 0 1912 + || sh->bh_page[i] != bh->b_page 1913 + #endif 1914 + ) && 1915 + !test_bit(R5_UPTODATE, &dev->flags)) { 1916 + if (test_bit(R5_Insync, &dev->flags)) rcw++; 1917 + else { 1918 + PRINTK("raid6: must_compute: disk %d flags=%#lx\n", i, dev->flags); 1919 + must_compute++; 1920 + } 1921 + } 1922 + } 1923 + PRINTK("for sector %llu, rcw=%d, must_compute=%d\n", 1924 + (unsigned long long)sh->sector, rcw, must_compute); 1925 + set_bit(STRIPE_HANDLE, &sh->state); 1926 + 1927 + if (rcw > 0) 1928 + /* want reconstruct write, but need to get some data */ 1929 + for (i=disks; i--;) { 1930 + dev = &sh->dev[i]; 1931 + if (!test_bit(R5_OVERWRITE, &dev->flags) 1932 + && !(failed == 0 && (i == pd_idx || i == qd_idx)) 1933 + && !test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_UPTODATE, &dev->flags) && 1934 + test_bit(R5_Insync, &dev->flags)) { 1935 + if (test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) 1936 + { 1937 + PRINTK("Read_old stripe %llu block %d for Reconstruct\n", 1938 + (unsigned long long)sh->sector, i); 1939 + set_bit(R5_LOCKED, &dev->flags); 1940 + set_bit(R5_Wantread, &dev->flags); 1941 + locked++; 1942 + } else { 1943 + PRINTK("Request delayed stripe %llu block %d for Reconstruct\n", 1944 + (unsigned long long)sh->sector, i); 1945 + set_bit(STRIPE_DELAYED, &sh->state); 1946 + set_bit(STRIPE_HANDLE, &sh->state); 1947 + } 1948 + } 1949 + } 1950 + /* now if nothing is locked, and if we have enough data, we can start a write request */ 1951 + if (locked == 0 && rcw == 0 && 1952 + !test_bit(STRIPE_BIT_DELAY, &sh->state)) { 1953 + if ( must_compute > 0 ) { 1954 + /* We have failed blocks and need to compute them */ 1955 + switch ( failed ) { 1956 + case 0: BUG(); 1957 + case 1: compute_block_1(sh, failed_num[0], 0); break; 1958 + case 2: compute_block_2(sh, failed_num[0], failed_num[1]); break; 1959 + default: BUG(); /* This request should have been failed? */ 1960 + } 1961 + } 1962 + 1963 + PRINTK("Computing parity for stripe %llu\n", (unsigned long long)sh->sector); 1964 + compute_parity6(sh, RECONSTRUCT_WRITE); 1965 + /* now every locked buffer is ready to be written */ 1966 + for (i=disks; i--;) 1967 + if (test_bit(R5_LOCKED, &sh->dev[i].flags)) { 1968 + PRINTK("Writing stripe %llu block %d\n", 1969 + (unsigned long long)sh->sector, i); 1970 + locked++; 1971 + set_bit(R5_Wantwrite, &sh->dev[i].flags); 1972 + } 1973 + /* after a RECONSTRUCT_WRITE, the stripe MUST be in-sync */ 1974 + set_bit(STRIPE_INSYNC, &sh->state); 1975 + 1976 + if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { 1977 + atomic_dec(&conf->preread_active_stripes); 1978 + if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) 1979 + md_wakeup_thread(conf->mddev->thread); 1980 + } 1981 + } 1982 + } 1983 + 1984 + /* maybe we need to check and possibly fix the parity for this stripe 1985 + * Any reads will already have been scheduled, so we just see if enough data 1986 + * is available 1987 + */ 1988 + if (syncing && locked == 0 && !test_bit(STRIPE_INSYNC, &sh->state)) { 1989 + int update_p = 0, update_q = 0; 1990 + struct r5dev *dev; 1991 + 1992 + set_bit(STRIPE_HANDLE, &sh->state); 1993 + 1994 + BUG_ON(failed>2); 1995 + BUG_ON(uptodate < disks); 1996 + /* Want to check and possibly repair P and Q. 1997 + * However there could be one 'failed' device, in which 1998 + * case we can only check one of them, possibly using the 1999 + * other to generate missing data 2000 + */ 2001 + 2002 + /* If !tmp_page, we cannot do the calculations, 2003 + * but as we have set STRIPE_HANDLE, we will soon be called 2004 + * by stripe_handle with a tmp_page - just wait until then. 2005 + */ 2006 + if (tmp_page) { 2007 + if (failed == q_failed) { 2008 + /* The only possible failed device holds 'Q', so it makes 2009 + * sense to check P (If anything else were failed, we would 2010 + * have used P to recreate it). 2011 + */ 2012 + compute_block_1(sh, pd_idx, 1); 2013 + if (!page_is_zero(sh->dev[pd_idx].page)) { 2014 + compute_block_1(sh,pd_idx,0); 2015 + update_p = 1; 2016 + } 2017 + } 2018 + if (!q_failed && failed < 2) { 2019 + /* q is not failed, and we didn't use it to generate 2020 + * anything, so it makes sense to check it 2021 + */ 2022 + memcpy(page_address(tmp_page), 2023 + page_address(sh->dev[qd_idx].page), 2024 + STRIPE_SIZE); 2025 + compute_parity6(sh, UPDATE_PARITY); 2026 + if (memcmp(page_address(tmp_page), 2027 + page_address(sh->dev[qd_idx].page), 2028 + STRIPE_SIZE)!= 0) { 2029 + clear_bit(STRIPE_INSYNC, &sh->state); 2030 + update_q = 1; 2031 + } 2032 + } 2033 + if (update_p || update_q) { 2034 + conf->mddev->resync_mismatches += STRIPE_SECTORS; 2035 + if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) 2036 + /* don't try to repair!! */ 2037 + update_p = update_q = 0; 2038 + } 2039 + 2040 + /* now write out any block on a failed drive, 2041 + * or P or Q if they need it 2042 + */ 2043 + 2044 + if (failed == 2) { 2045 + dev = &sh->dev[failed_num[1]]; 2046 + locked++; 2047 + set_bit(R5_LOCKED, &dev->flags); 2048 + set_bit(R5_Wantwrite, &dev->flags); 2049 + } 2050 + if (failed >= 1) { 2051 + dev = &sh->dev[failed_num[0]]; 2052 + locked++; 2053 + set_bit(R5_LOCKED, &dev->flags); 2054 + set_bit(R5_Wantwrite, &dev->flags); 2055 + } 2056 + 2057 + if (update_p) { 2058 + dev = &sh->dev[pd_idx]; 2059 + locked ++; 2060 + set_bit(R5_LOCKED, &dev->flags); 2061 + set_bit(R5_Wantwrite, &dev->flags); 2062 + } 2063 + if (update_q) { 2064 + dev = &sh->dev[qd_idx]; 2065 + locked++; 2066 + set_bit(R5_LOCKED, &dev->flags); 2067 + set_bit(R5_Wantwrite, &dev->flags); 2068 + } 2069 + clear_bit(STRIPE_DEGRADED, &sh->state); 2070 + 2071 + set_bit(STRIPE_INSYNC, &sh->state); 2072 + } 2073 + } 2074 + 2075 + if (syncing && locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) { 2076 + md_done_sync(conf->mddev, STRIPE_SECTORS,1); 2077 + clear_bit(STRIPE_SYNCING, &sh->state); 2078 + } 2079 + 2080 + /* If the failed drives are just a ReadError, then we might need 2081 + * to progress the repair/check process 2082 + */ 2083 + if (failed <= 2 && ! conf->mddev->ro) 2084 + for (i=0; i<failed;i++) { 2085 + dev = &sh->dev[failed_num[i]]; 2086 + if (test_bit(R5_ReadError, &dev->flags) 2087 + && !test_bit(R5_LOCKED, &dev->flags) 2088 + && test_bit(R5_UPTODATE, &dev->flags) 2089 + ) { 2090 + if (!test_bit(R5_ReWrite, &dev->flags)) { 2091 + set_bit(R5_Wantwrite, &dev->flags); 2092 + set_bit(R5_ReWrite, &dev->flags); 2093 + set_bit(R5_LOCKED, &dev->flags); 2094 + } else { 2095 + /* let's read it back */ 2096 + set_bit(R5_Wantread, &dev->flags); 2097 + set_bit(R5_LOCKED, &dev->flags); 2098 + } 2099 + } 2100 + } 2101 + spin_unlock(&sh->lock); 2102 + 2103 + while ((bi=return_bi)) { 2104 + int bytes = bi->bi_size; 2105 + 2106 + return_bi = bi->bi_next; 2107 + bi->bi_next = NULL; 2108 + bi->bi_size = 0; 2109 + bi->bi_end_io(bi, bytes, 0); 2110 + } 2111 + for (i=disks; i-- ;) { 2112 + int rw; 2113 + struct bio *bi; 2114 + mdk_rdev_t *rdev; 2115 + if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) 2116 + rw = 1; 2117 + else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) 2118 + rw = 0; 2119 + else 2120 + continue; 2121 + 2122 + bi = &sh->dev[i].req; 2123 + 2124 + bi->bi_rw = rw; 2125 + if (rw) 2126 + bi->bi_end_io = raid5_end_write_request; 2127 + else 2128 + bi->bi_end_io = raid5_end_read_request; 2129 + 2130 + rcu_read_lock(); 2131 + rdev = rcu_dereference(conf->disks[i].rdev); 2132 + if (rdev && test_bit(Faulty, &rdev->flags)) 2133 + rdev = NULL; 2134 + if (rdev) 2135 + atomic_inc(&rdev->nr_pending); 2136 + rcu_read_unlock(); 2137 + 2138 + if (rdev) { 2139 + if (syncing) 2140 + md_sync_acct(rdev->bdev, STRIPE_SECTORS); 2141 + 2142 + bi->bi_bdev = rdev->bdev; 2143 + PRINTK("for %llu schedule op %ld on disc %d\n", 2144 + (unsigned long long)sh->sector, bi->bi_rw, i); 2145 + atomic_inc(&sh->count); 2146 + bi->bi_sector = sh->sector + rdev->data_offset; 2147 + bi->bi_flags = 1 << BIO_UPTODATE; 2148 + bi->bi_vcnt = 1; 2149 + bi->bi_max_vecs = 1; 2150 + bi->bi_idx = 0; 2151 + bi->bi_io_vec = &sh->dev[i].vec; 2152 + bi->bi_io_vec[0].bv_len = STRIPE_SIZE; 2153 + bi->bi_io_vec[0].bv_offset = 0; 2154 + bi->bi_size = STRIPE_SIZE; 2155 + bi->bi_next = NULL; 2156 + if (rw == WRITE && 2157 + test_bit(R5_ReWrite, &sh->dev[i].flags)) 2158 + atomic_add(STRIPE_SECTORS, &rdev->corrected_errors); 2159 + generic_make_request(bi); 2160 + } else { 2161 + if (rw == 1) 2162 + set_bit(STRIPE_DEGRADED, &sh->state); 2163 + PRINTK("skip op %ld on disc %d for sector %llu\n", 2164 + bi->bi_rw, i, (unsigned long long)sh->sector); 2165 + clear_bit(R5_LOCKED, &sh->dev[i].flags); 2166 + set_bit(STRIPE_HANDLE, &sh->state); 2167 + } 2168 + } 2169 + } 2170 + 2171 + static void handle_stripe(struct stripe_head *sh, struct page *tmp_page) 2172 + { 2173 + if (sh->raid_conf->level == 6) 2174 + handle_stripe6(sh, tmp_page); 2175 + else 2176 + handle_stripe5(sh); 2177 + } 2178 + 2179 + 1891 2180 1892 2181 static void raid5_activate_delayed(raid5_conf_t *conf) 1893 2182 { ··· 2590 1753 2591 1754 for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { 2592 1755 DEFINE_WAIT(w); 2593 - int disks; 1756 + int disks, data_disks; 2594 1757 2595 1758 retry: 2596 1759 prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE); ··· 2618 1781 } 2619 1782 spin_unlock_irq(&conf->device_lock); 2620 1783 } 2621 - new_sector = raid5_compute_sector(logical_sector, disks, disks - 1, 1784 + data_disks = disks - conf->max_degraded; 1785 + 1786 + new_sector = raid5_compute_sector(logical_sector, disks, data_disks, 2622 1787 &dd_idx, &pd_idx, conf); 2623 1788 PRINTK("raid5: make_request, sector %llu logical %llu\n", 2624 1789 (unsigned long long)new_sector, ··· 2672 1833 } 2673 1834 finish_wait(&conf->wait_for_overlap, &w); 2674 1835 raid5_plug_device(conf); 2675 - handle_stripe(sh); 1836 + handle_stripe(sh, NULL); 2676 1837 release_stripe(sh); 2677 1838 } else { 2678 1839 /* cannot get stripe for read-ahead, just give-up */ ··· 2688 1849 if (remaining == 0) { 2689 1850 int bytes = bi->bi_size; 2690 1851 2691 - if ( bio_data_dir(bi) == WRITE ) 1852 + if ( rw == WRITE ) 2692 1853 md_write_end(mddev); 2693 1854 bi->bi_size = 0; 2694 1855 bi->bi_end_io(bi, bytes, 0); ··· 2704 1865 int pd_idx; 2705 1866 sector_t first_sector, last_sector; 2706 1867 int raid_disks = conf->raid_disks; 2707 - int data_disks = raid_disks-1; 1868 + int data_disks = raid_disks - conf->max_degraded; 2708 1869 sector_t max_sector = mddev->size << 1; 2709 1870 int sync_blocks; 1871 + int still_degraded = 0; 1872 + int i; 2710 1873 2711 1874 if (sector_nr >= max_sector) { 2712 1875 /* just being told to finish up .. nothing much to do */ ··· 2721 1880 if (mddev->curr_resync < max_sector) /* aborted */ 2722 1881 bitmap_end_sync(mddev->bitmap, mddev->curr_resync, 2723 1882 &sync_blocks, 1); 2724 - else /* compelted sync */ 1883 + else /* completed sync */ 2725 1884 conf->fullsync = 0; 2726 1885 bitmap_close_sync(mddev->bitmap); 2727 1886 ··· 2844 2003 } 2845 2004 return conf->chunk_size>>9; 2846 2005 } 2847 - /* if there is 1 or more failed drives and we are trying 2006 + /* if there is too many failed drives and we are trying 2848 2007 * to resync, then assert that we are finished, because there is 2849 2008 * nothing we can do. 2850 2009 */ 2851 - if (mddev->degraded >= 1 && test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { 2010 + if (mddev->degraded >= (data_disks - raid_disks) && 2011 + test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { 2852 2012 sector_t rv = (mddev->size << 1) - sector_nr; 2853 2013 *skipped = 1; 2854 2014 return rv; ··· 2868 2026 if (sh == NULL) { 2869 2027 sh = get_active_stripe(conf, sector_nr, raid_disks, pd_idx, 0); 2870 2028 /* make sure we don't swamp the stripe cache if someone else 2871 - * is trying to get access 2029 + * is trying to get access 2872 2030 */ 2873 2031 schedule_timeout_uninterruptible(1); 2874 2032 } 2875 - bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 0); 2876 - spin_lock(&sh->lock); 2033 + /* Need to check if array will still be degraded after recovery/resync 2034 + * We don't need to check the 'failed' flag as when that gets set, 2035 + * recovery aborts. 2036 + */ 2037 + for (i=0; i<mddev->raid_disks; i++) 2038 + if (conf->disks[i].rdev == NULL) 2039 + still_degraded = 1; 2040 + 2041 + bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded); 2042 + 2043 + spin_lock(&sh->lock); 2877 2044 set_bit(STRIPE_SYNCING, &sh->state); 2878 2045 clear_bit(STRIPE_INSYNC, &sh->state); 2879 2046 spin_unlock(&sh->lock); 2880 2047 2881 - handle_stripe(sh); 2048 + handle_stripe(sh, NULL); 2882 2049 release_stripe(sh); 2883 2050 2884 2051 return STRIPE_SECTORS; ··· 2942 2091 spin_unlock_irq(&conf->device_lock); 2943 2092 2944 2093 handled++; 2945 - handle_stripe(sh); 2094 + handle_stripe(sh, conf->spare_page); 2946 2095 release_stripe(sh); 2947 2096 2948 2097 spin_lock_irq(&conf->device_lock); ··· 3032 2181 struct disk_info *disk; 3033 2182 struct list_head *tmp; 3034 2183 3035 - if (mddev->level != 5 && mddev->level != 4) { 3036 - printk(KERN_ERR "raid5: %s: raid level not set to 4/5 (%d)\n", 2184 + if (mddev->level != 5 && mddev->level != 4 && mddev->level != 6) { 2185 + printk(KERN_ERR "raid5: %s: raid level not set to 4/5/6 (%d)\n", 3037 2186 mdname(mddev), mddev->level); 3038 2187 return -EIO; 3039 2188 } ··· 3102 2251 if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) 3103 2252 goto abort; 3104 2253 2254 + if (mddev->level == 6) { 2255 + conf->spare_page = alloc_page(GFP_KERNEL); 2256 + if (!conf->spare_page) 2257 + goto abort; 2258 + } 3105 2259 spin_lock_init(&conf->device_lock); 3106 2260 init_waitqueue_head(&conf->wait_for_stripe); 3107 2261 init_waitqueue_head(&conf->wait_for_overlap); ··· 3138 2282 } 3139 2283 3140 2284 /* 3141 - * 0 for a fully functional array, 1 for a degraded array. 2285 + * 0 for a fully functional array, 1 or 2 for a degraded array. 3142 2286 */ 3143 2287 mddev->degraded = conf->failed_disks = conf->raid_disks - conf->working_disks; 3144 2288 conf->mddev = mddev; 3145 2289 conf->chunk_size = mddev->chunk_size; 3146 2290 conf->level = mddev->level; 2291 + if (conf->level == 6) 2292 + conf->max_degraded = 2; 2293 + else 2294 + conf->max_degraded = 1; 3147 2295 conf->algorithm = mddev->layout; 3148 2296 conf->max_nr_stripes = NR_STRIPES; 3149 2297 conf->expand_progress = mddev->reshape_position; ··· 3156 2296 mddev->size &= ~(mddev->chunk_size/1024 -1); 3157 2297 mddev->resync_max_sectors = mddev->size << 1; 3158 2298 2299 + if (conf->level == 6 && conf->raid_disks < 4) { 2300 + printk(KERN_ERR "raid6: not enough configured devices for %s (%d, minimum 4)\n", 2301 + mdname(mddev), conf->raid_disks); 2302 + goto abort; 2303 + } 3159 2304 if (!conf->chunk_size || conf->chunk_size % 4) { 3160 2305 printk(KERN_ERR "raid5: invalid chunk size %d for %s\n", 3161 2306 conf->chunk_size, mdname(mddev)); ··· 3172 2307 conf->algorithm, mdname(mddev)); 3173 2308 goto abort; 3174 2309 } 3175 - if (mddev->degraded > 1) { 2310 + if (mddev->degraded > conf->max_degraded) { 3176 2311 printk(KERN_ERR "raid5: not enough operational devices for %s" 3177 2312 " (%d/%d failed)\n", 3178 2313 mdname(mddev), conf->failed_disks, conf->raid_disks); 3179 2314 goto abort; 3180 2315 } 3181 2316 3182 - if (mddev->degraded == 1 && 2317 + if (mddev->degraded > 0 && 3183 2318 mddev->recovery_cp != MaxSector) { 3184 2319 if (mddev->ok_start_degraded) 3185 2320 printk(KERN_WARNING ··· 3244 2379 } 3245 2380 3246 2381 /* read-ahead size must cover two whole stripes, which is 3247 - * 2 * (n-1) * chunksize where 'n' is the number of raid devices 2382 + * 2 * (datadisks) * chunksize where 'n' is the number of raid devices 3248 2383 */ 3249 2384 { 3250 - int stripe = (mddev->raid_disks-1) * 2385 + int data_disks = conf->previous_raid_disks - conf->max_degraded; 2386 + int stripe = data_disks * 3251 2387 (mddev->chunk_size / PAGE_SIZE); 3252 2388 if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe) 3253 2389 mddev->queue->backing_dev_info.ra_pages = 2 * stripe; ··· 3259 2393 3260 2394 mddev->queue->unplug_fn = raid5_unplug_device; 3261 2395 mddev->queue->issue_flush_fn = raid5_issue_flush; 3262 - mddev->array_size = mddev->size * (conf->previous_raid_disks - 1); 2396 + mddev->array_size = mddev->size * (conf->previous_raid_disks - 2397 + conf->max_degraded); 3263 2398 3264 2399 return 0; 3265 2400 abort: 3266 2401 if (conf) { 3267 2402 print_raid5_conf(conf); 2403 + safe_put_page(conf->spare_page); 3268 2404 kfree(conf->disks); 3269 2405 kfree(conf->stripe_hashtbl); 3270 2406 kfree(conf); ··· 3295 2427 } 3296 2428 3297 2429 #if RAID5_DEBUG 3298 - static void print_sh (struct stripe_head *sh) 2430 + static void print_sh (struct seq_file *seq, struct stripe_head *sh) 3299 2431 { 3300 2432 int i; 3301 2433 3302 - printk("sh %llu, pd_idx %d, state %ld.\n", 3303 - (unsigned long long)sh->sector, sh->pd_idx, sh->state); 3304 - printk("sh %llu, count %d.\n", 3305 - (unsigned long long)sh->sector, atomic_read(&sh->count)); 3306 - printk("sh %llu, ", (unsigned long long)sh->sector); 2434 + seq_printf(seq, "sh %llu, pd_idx %d, state %ld.\n", 2435 + (unsigned long long)sh->sector, sh->pd_idx, sh->state); 2436 + seq_printf(seq, "sh %llu, count %d.\n", 2437 + (unsigned long long)sh->sector, atomic_read(&sh->count)); 2438 + seq_printf(seq, "sh %llu, ", (unsigned long long)sh->sector); 3307 2439 for (i = 0; i < sh->disks; i++) { 3308 - printk("(cache%d: %p %ld) ", 3309 - i, sh->dev[i].page, sh->dev[i].flags); 2440 + seq_printf(seq, "(cache%d: %p %ld) ", 2441 + i, sh->dev[i].page, sh->dev[i].flags); 3310 2442 } 3311 - printk("\n"); 2443 + seq_printf(seq, "\n"); 3312 2444 } 3313 2445 3314 - static void printall (raid5_conf_t *conf) 2446 + static void printall (struct seq_file *seq, raid5_conf_t *conf) 3315 2447 { 3316 2448 struct stripe_head *sh; 3317 2449 struct hlist_node *hn; ··· 3322 2454 hlist_for_each_entry(sh, hn, &conf->stripe_hashtbl[i], hash) { 3323 2455 if (sh->raid_conf != conf) 3324 2456 continue; 3325 - print_sh(sh); 2457 + print_sh(seq, sh); 3326 2458 } 3327 2459 } 3328 2460 spin_unlock_irq(&conf->device_lock); ··· 3342 2474 test_bit(In_sync, &conf->disks[i].rdev->flags) ? "U" : "_"); 3343 2475 seq_printf (seq, "]"); 3344 2476 #if RAID5_DEBUG 3345 - #define D(x) \ 3346 - seq_printf (seq, "<"#x":%d>", atomic_read(&conf->x)) 3347 - printall(conf); 2477 + seq_printf (seq, "\n"); 2478 + printall(seq, conf); 3348 2479 #endif 3349 2480 } 3350 2481 ··· 3427 2560 int disk; 3428 2561 struct disk_info *p; 3429 2562 3430 - if (mddev->degraded > 1) 2563 + if (mddev->degraded > conf->max_degraded) 3431 2564 /* no point adding a device */ 3432 2565 return 0; 3433 2566 3434 2567 /* 3435 - * find the disk ... 2568 + * find the disk ... but prefer rdev->saved_raid_disk 2569 + * if possible. 3436 2570 */ 3437 - for (disk=0; disk < conf->raid_disks; disk++) 2571 + if (rdev->saved_raid_disk >= 0 && 2572 + conf->disks[rdev->saved_raid_disk].rdev == NULL) 2573 + disk = rdev->saved_raid_disk; 2574 + else 2575 + disk = 0; 2576 + for ( ; disk < conf->raid_disks; disk++) 3438 2577 if ((p=conf->disks + disk)->rdev == NULL) { 3439 2578 clear_bit(In_sync, &rdev->flags); 3440 2579 rdev->raid_disk = disk; ··· 3463 2590 * any io in the removed space completes, but it hardly seems 3464 2591 * worth it. 3465 2592 */ 2593 + raid5_conf_t *conf = mddev_to_conf(mddev); 2594 + 3466 2595 sectors &= ~((sector_t)mddev->chunk_size/512 - 1); 3467 - mddev->array_size = (sectors * (mddev->raid_disks-1))>>1; 2596 + mddev->array_size = (sectors * (mddev->raid_disks-conf->max_degraded))>>1; 3468 2597 set_capacity(mddev->gendisk, mddev->array_size << 1); 3469 2598 mddev->changed = 1; 3470 2599 if (sectors/2 > mddev->size && mddev->recovery_cp == MaxSector) { ··· 3606 2731 conf->expand_progress = MaxSector; 3607 2732 spin_unlock_irq(&conf->device_lock); 3608 2733 conf->mddev->reshape_position = MaxSector; 2734 + 2735 + /* read-ahead size must cover two whole stripes, which is 2736 + * 2 * (datadisks) * chunksize where 'n' is the number of raid devices 2737 + */ 2738 + { 2739 + int data_disks = conf->previous_raid_disks - conf->max_degraded; 2740 + int stripe = data_disks * 2741 + (conf->mddev->chunk_size / PAGE_SIZE); 2742 + if (conf->mddev->queue->backing_dev_info.ra_pages < 2 * stripe) 2743 + conf->mddev->queue->backing_dev_info.ra_pages = 2 * stripe; 2744 + } 3609 2745 } 3610 2746 } 3611 2747 ··· 3648 2762 } 3649 2763 } 3650 2764 2765 + static struct mdk_personality raid6_personality = 2766 + { 2767 + .name = "raid6", 2768 + .level = 6, 2769 + .owner = THIS_MODULE, 2770 + .make_request = make_request, 2771 + .run = run, 2772 + .stop = stop, 2773 + .status = status, 2774 + .error_handler = error, 2775 + .hot_add_disk = raid5_add_disk, 2776 + .hot_remove_disk= raid5_remove_disk, 2777 + .spare_active = raid5_spare_active, 2778 + .sync_request = sync_request, 2779 + .resize = raid5_resize, 2780 + .quiesce = raid5_quiesce, 2781 + }; 3651 2782 static struct mdk_personality raid5_personality = 3652 2783 { 3653 2784 .name = "raid5", ··· 3707 2804 3708 2805 static int __init raid5_init(void) 3709 2806 { 2807 + int e; 2808 + 2809 + e = raid6_select_algo(); 2810 + if ( e ) 2811 + return e; 2812 + register_md_personality(&raid6_personality); 3710 2813 register_md_personality(&raid5_personality); 3711 2814 register_md_personality(&raid4_personality); 3712 2815 return 0; ··· 3720 2811 3721 2812 static void raid5_exit(void) 3722 2813 { 2814 + unregister_md_personality(&raid6_personality); 3723 2815 unregister_md_personality(&raid5_personality); 3724 2816 unregister_md_personality(&raid4_personality); 3725 2817 } ··· 3733 2823 MODULE_ALIAS("md-raid4"); 3734 2824 MODULE_ALIAS("md-level-5"); 3735 2825 MODULE_ALIAS("md-level-4"); 2826 + MODULE_ALIAS("md-personality-8"); /* RAID6 */ 2827 + MODULE_ALIAS("md-raid6"); 2828 + MODULE_ALIAS("md-level-6"); 2829 + 2830 + /* This used to be two separate modules, they were: */ 2831 + MODULE_ALIAS("raid5"); 2832 + MODULE_ALIAS("raid6");
-2427
drivers/md/raid6main.c
··· 1 - /* 2 - * raid6main.c : Multiple Devices driver for Linux 3 - * Copyright (C) 1996, 1997 Ingo Molnar, Miguel de Icaza, Gadi Oxman 4 - * Copyright (C) 1999, 2000 Ingo Molnar 5 - * Copyright (C) 2002, 2003 H. Peter Anvin 6 - * 7 - * RAID-6 management functions. This code is derived from raid5.c. 8 - * Last merge from raid5.c bkcvs version 1.79 (kernel 2.6.1). 9 - * 10 - * Thanks to Penguin Computing for making the RAID-6 development possible 11 - * by donating a test server! 12 - * 13 - * This program is free software; you can redistribute it and/or modify 14 - * it under the terms of the GNU General Public License as published by 15 - * the Free Software Foundation; either version 2, or (at your option) 16 - * any later version. 17 - * 18 - * You should have received a copy of the GNU General Public License 19 - * (for example /usr/src/linux/COPYING); if not, write to the Free 20 - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 - */ 22 - 23 - 24 - #include <linux/config.h> 25 - #include <linux/module.h> 26 - #include <linux/slab.h> 27 - #include <linux/highmem.h> 28 - #include <linux/bitops.h> 29 - #include <asm/atomic.h> 30 - #include "raid6.h" 31 - 32 - #include <linux/raid/bitmap.h> 33 - 34 - /* 35 - * Stripe cache 36 - */ 37 - 38 - #define NR_STRIPES 256 39 - #define STRIPE_SIZE PAGE_SIZE 40 - #define STRIPE_SHIFT (PAGE_SHIFT - 9) 41 - #define STRIPE_SECTORS (STRIPE_SIZE>>9) 42 - #define IO_THRESHOLD 1 43 - #define NR_HASH (PAGE_SIZE / sizeof(struct hlist_head)) 44 - #define HASH_MASK (NR_HASH - 1) 45 - 46 - #define stripe_hash(conf, sect) (&((conf)->stripe_hashtbl[((sect) >> STRIPE_SHIFT) & HASH_MASK])) 47 - 48 - /* bio's attached to a stripe+device for I/O are linked together in bi_sector 49 - * order without overlap. There may be several bio's per stripe+device, and 50 - * a bio could span several devices. 51 - * When walking this list for a particular stripe+device, we must never proceed 52 - * beyond a bio that extends past this device, as the next bio might no longer 53 - * be valid. 54 - * This macro is used to determine the 'next' bio in the list, given the sector 55 - * of the current stripe+device 56 - */ 57 - #define r5_next_bio(bio, sect) ( ( (bio)->bi_sector + ((bio)->bi_size>>9) < sect + STRIPE_SECTORS) ? (bio)->bi_next : NULL) 58 - /* 59 - * The following can be used to debug the driver 60 - */ 61 - #define RAID6_DEBUG 0 /* Extremely verbose printk */ 62 - #define RAID6_PARANOIA 1 /* Check spinlocks */ 63 - #define RAID6_DUMPSTATE 0 /* Include stripe cache state in /proc/mdstat */ 64 - #if RAID6_PARANOIA && defined(CONFIG_SMP) 65 - # define CHECK_DEVLOCK() assert_spin_locked(&conf->device_lock) 66 - #else 67 - # define CHECK_DEVLOCK() 68 - #endif 69 - 70 - #define PRINTK(x...) ((void)(RAID6_DEBUG && printk(KERN_DEBUG x))) 71 - #if RAID6_DEBUG 72 - #undef inline 73 - #undef __inline__ 74 - #define inline 75 - #define __inline__ 76 - #endif 77 - 78 - #if !RAID6_USE_EMPTY_ZERO_PAGE 79 - /* In .bss so it's zeroed */ 80 - const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256))); 81 - #endif 82 - 83 - static inline int raid6_next_disk(int disk, int raid_disks) 84 - { 85 - disk++; 86 - return (disk < raid_disks) ? disk : 0; 87 - } 88 - 89 - static void print_raid6_conf (raid6_conf_t *conf); 90 - 91 - static void __release_stripe(raid6_conf_t *conf, struct stripe_head *sh) 92 - { 93 - if (atomic_dec_and_test(&sh->count)) { 94 - BUG_ON(!list_empty(&sh->lru)); 95 - BUG_ON(atomic_read(&conf->active_stripes)==0); 96 - if (test_bit(STRIPE_HANDLE, &sh->state)) { 97 - if (test_bit(STRIPE_DELAYED, &sh->state)) 98 - list_add_tail(&sh->lru, &conf->delayed_list); 99 - else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && 100 - conf->seq_write == sh->bm_seq) 101 - list_add_tail(&sh->lru, &conf->bitmap_list); 102 - else { 103 - clear_bit(STRIPE_BIT_DELAY, &sh->state); 104 - list_add_tail(&sh->lru, &conf->handle_list); 105 - } 106 - md_wakeup_thread(conf->mddev->thread); 107 - } else { 108 - if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { 109 - atomic_dec(&conf->preread_active_stripes); 110 - if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) 111 - md_wakeup_thread(conf->mddev->thread); 112 - } 113 - list_add_tail(&sh->lru, &conf->inactive_list); 114 - atomic_dec(&conf->active_stripes); 115 - if (!conf->inactive_blocked || 116 - atomic_read(&conf->active_stripes) < (conf->max_nr_stripes*3/4)) 117 - wake_up(&conf->wait_for_stripe); 118 - } 119 - } 120 - } 121 - static void release_stripe(struct stripe_head *sh) 122 - { 123 - raid6_conf_t *conf = sh->raid_conf; 124 - unsigned long flags; 125 - 126 - spin_lock_irqsave(&conf->device_lock, flags); 127 - __release_stripe(conf, sh); 128 - spin_unlock_irqrestore(&conf->device_lock, flags); 129 - } 130 - 131 - static inline void remove_hash(struct stripe_head *sh) 132 - { 133 - PRINTK("remove_hash(), stripe %llu\n", (unsigned long long)sh->sector); 134 - 135 - hlist_del_init(&sh->hash); 136 - } 137 - 138 - static inline void insert_hash(raid6_conf_t *conf, struct stripe_head *sh) 139 - { 140 - struct hlist_head *hp = stripe_hash(conf, sh->sector); 141 - 142 - PRINTK("insert_hash(), stripe %llu\n", (unsigned long long)sh->sector); 143 - 144 - CHECK_DEVLOCK(); 145 - hlist_add_head(&sh->hash, hp); 146 - } 147 - 148 - 149 - /* find an idle stripe, make sure it is unhashed, and return it. */ 150 - static struct stripe_head *get_free_stripe(raid6_conf_t *conf) 151 - { 152 - struct stripe_head *sh = NULL; 153 - struct list_head *first; 154 - 155 - CHECK_DEVLOCK(); 156 - if (list_empty(&conf->inactive_list)) 157 - goto out; 158 - first = conf->inactive_list.next; 159 - sh = list_entry(first, struct stripe_head, lru); 160 - list_del_init(first); 161 - remove_hash(sh); 162 - atomic_inc(&conf->active_stripes); 163 - out: 164 - return sh; 165 - } 166 - 167 - static void shrink_buffers(struct stripe_head *sh, int num) 168 - { 169 - struct page *p; 170 - int i; 171 - 172 - for (i=0; i<num ; i++) { 173 - p = sh->dev[i].page; 174 - if (!p) 175 - continue; 176 - sh->dev[i].page = NULL; 177 - put_page(p); 178 - } 179 - } 180 - 181 - static int grow_buffers(struct stripe_head *sh, int num) 182 - { 183 - int i; 184 - 185 - for (i=0; i<num; i++) { 186 - struct page *page; 187 - 188 - if (!(page = alloc_page(GFP_KERNEL))) { 189 - return 1; 190 - } 191 - sh->dev[i].page = page; 192 - } 193 - return 0; 194 - } 195 - 196 - static void raid6_build_block (struct stripe_head *sh, int i); 197 - 198 - static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx) 199 - { 200 - raid6_conf_t *conf = sh->raid_conf; 201 - int disks = conf->raid_disks, i; 202 - 203 - BUG_ON(atomic_read(&sh->count) != 0); 204 - BUG_ON(test_bit(STRIPE_HANDLE, &sh->state)); 205 - 206 - CHECK_DEVLOCK(); 207 - PRINTK("init_stripe called, stripe %llu\n", 208 - (unsigned long long)sh->sector); 209 - 210 - remove_hash(sh); 211 - 212 - sh->sector = sector; 213 - sh->pd_idx = pd_idx; 214 - sh->state = 0; 215 - 216 - for (i=disks; i--; ) { 217 - struct r5dev *dev = &sh->dev[i]; 218 - 219 - if (dev->toread || dev->towrite || dev->written || 220 - test_bit(R5_LOCKED, &dev->flags)) { 221 - PRINTK("sector=%llx i=%d %p %p %p %d\n", 222 - (unsigned long long)sh->sector, i, dev->toread, 223 - dev->towrite, dev->written, 224 - test_bit(R5_LOCKED, &dev->flags)); 225 - BUG(); 226 - } 227 - dev->flags = 0; 228 - raid6_build_block(sh, i); 229 - } 230 - insert_hash(conf, sh); 231 - } 232 - 233 - static struct stripe_head *__find_stripe(raid6_conf_t *conf, sector_t sector) 234 - { 235 - struct stripe_head *sh; 236 - struct hlist_node *hn; 237 - 238 - CHECK_DEVLOCK(); 239 - PRINTK("__find_stripe, sector %llu\n", (unsigned long long)sector); 240 - hlist_for_each_entry (sh, hn, stripe_hash(conf, sector), hash) 241 - if (sh->sector == sector) 242 - return sh; 243 - PRINTK("__stripe %llu not in cache\n", (unsigned long long)sector); 244 - return NULL; 245 - } 246 - 247 - static void unplug_slaves(mddev_t *mddev); 248 - 249 - static struct stripe_head *get_active_stripe(raid6_conf_t *conf, sector_t sector, 250 - int pd_idx, int noblock) 251 - { 252 - struct stripe_head *sh; 253 - 254 - PRINTK("get_stripe, sector %llu\n", (unsigned long long)sector); 255 - 256 - spin_lock_irq(&conf->device_lock); 257 - 258 - do { 259 - wait_event_lock_irq(conf->wait_for_stripe, 260 - conf->quiesce == 0, 261 - conf->device_lock, /* nothing */); 262 - sh = __find_stripe(conf, sector); 263 - if (!sh) { 264 - if (!conf->inactive_blocked) 265 - sh = get_free_stripe(conf); 266 - if (noblock && sh == NULL) 267 - break; 268 - if (!sh) { 269 - conf->inactive_blocked = 1; 270 - wait_event_lock_irq(conf->wait_for_stripe, 271 - !list_empty(&conf->inactive_list) && 272 - (atomic_read(&conf->active_stripes) 273 - < (conf->max_nr_stripes *3/4) 274 - || !conf->inactive_blocked), 275 - conf->device_lock, 276 - unplug_slaves(conf->mddev); 277 - ); 278 - conf->inactive_blocked = 0; 279 - } else 280 - init_stripe(sh, sector, pd_idx); 281 - } else { 282 - if (atomic_read(&sh->count)) { 283 - BUG_ON(!list_empty(&sh->lru)); 284 - } else { 285 - if (!test_bit(STRIPE_HANDLE, &sh->state)) 286 - atomic_inc(&conf->active_stripes); 287 - BUG_ON(list_empty(&sh->lru)); 288 - list_del_init(&sh->lru); 289 - } 290 - } 291 - } while (sh == NULL); 292 - 293 - if (sh) 294 - atomic_inc(&sh->count); 295 - 296 - spin_unlock_irq(&conf->device_lock); 297 - return sh; 298 - } 299 - 300 - static int grow_one_stripe(raid6_conf_t *conf) 301 - { 302 - struct stripe_head *sh; 303 - sh = kmem_cache_alloc(conf->slab_cache, GFP_KERNEL); 304 - if (!sh) 305 - return 0; 306 - memset(sh, 0, sizeof(*sh) + (conf->raid_disks-1)*sizeof(struct r5dev)); 307 - sh->raid_conf = conf; 308 - spin_lock_init(&sh->lock); 309 - 310 - if (grow_buffers(sh, conf->raid_disks)) { 311 - shrink_buffers(sh, conf->raid_disks); 312 - kmem_cache_free(conf->slab_cache, sh); 313 - return 0; 314 - } 315 - /* we just created an active stripe so... */ 316 - atomic_set(&sh->count, 1); 317 - atomic_inc(&conf->active_stripes); 318 - INIT_LIST_HEAD(&sh->lru); 319 - release_stripe(sh); 320 - return 1; 321 - } 322 - 323 - static int grow_stripes(raid6_conf_t *conf, int num) 324 - { 325 - kmem_cache_t *sc; 326 - int devs = conf->raid_disks; 327 - 328 - sprintf(conf->cache_name[0], "raid6/%s", mdname(conf->mddev)); 329 - 330 - sc = kmem_cache_create(conf->cache_name[0], 331 - sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), 332 - 0, 0, NULL, NULL); 333 - if (!sc) 334 - return 1; 335 - conf->slab_cache = sc; 336 - while (num--) 337 - if (!grow_one_stripe(conf)) 338 - return 1; 339 - return 0; 340 - } 341 - 342 - static int drop_one_stripe(raid6_conf_t *conf) 343 - { 344 - struct stripe_head *sh; 345 - spin_lock_irq(&conf->device_lock); 346 - sh = get_free_stripe(conf); 347 - spin_unlock_irq(&conf->device_lock); 348 - if (!sh) 349 - return 0; 350 - BUG_ON(atomic_read(&sh->count)); 351 - shrink_buffers(sh, conf->raid_disks); 352 - kmem_cache_free(conf->slab_cache, sh); 353 - atomic_dec(&conf->active_stripes); 354 - return 1; 355 - } 356 - 357 - static void shrink_stripes(raid6_conf_t *conf) 358 - { 359 - while (drop_one_stripe(conf)) 360 - ; 361 - 362 - if (conf->slab_cache) 363 - kmem_cache_destroy(conf->slab_cache); 364 - conf->slab_cache = NULL; 365 - } 366 - 367 - static int raid6_end_read_request(struct bio * bi, unsigned int bytes_done, 368 - int error) 369 - { 370 - struct stripe_head *sh = bi->bi_private; 371 - raid6_conf_t *conf = sh->raid_conf; 372 - int disks = conf->raid_disks, i; 373 - int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); 374 - 375 - if (bi->bi_size) 376 - return 1; 377 - 378 - for (i=0 ; i<disks; i++) 379 - if (bi == &sh->dev[i].req) 380 - break; 381 - 382 - PRINTK("end_read_request %llu/%d, count: %d, uptodate %d.\n", 383 - (unsigned long long)sh->sector, i, atomic_read(&sh->count), 384 - uptodate); 385 - if (i == disks) { 386 - BUG(); 387 - return 0; 388 - } 389 - 390 - if (uptodate) { 391 - #if 0 392 - struct bio *bio; 393 - unsigned long flags; 394 - spin_lock_irqsave(&conf->device_lock, flags); 395 - /* we can return a buffer if we bypassed the cache or 396 - * if the top buffer is not in highmem. If there are 397 - * multiple buffers, leave the extra work to 398 - * handle_stripe 399 - */ 400 - buffer = sh->bh_read[i]; 401 - if (buffer && 402 - (!PageHighMem(buffer->b_page) 403 - || buffer->b_page == bh->b_page ) 404 - ) { 405 - sh->bh_read[i] = buffer->b_reqnext; 406 - buffer->b_reqnext = NULL; 407 - } else 408 - buffer = NULL; 409 - spin_unlock_irqrestore(&conf->device_lock, flags); 410 - if (sh->bh_page[i]==bh->b_page) 411 - set_buffer_uptodate(bh); 412 - if (buffer) { 413 - if (buffer->b_page != bh->b_page) 414 - memcpy(buffer->b_data, bh->b_data, bh->b_size); 415 - buffer->b_end_io(buffer, 1); 416 - } 417 - #else 418 - set_bit(R5_UPTODATE, &sh->dev[i].flags); 419 - #endif 420 - if (test_bit(R5_ReadError, &sh->dev[i].flags)) { 421 - printk(KERN_INFO "raid6: read error corrected!!\n"); 422 - clear_bit(R5_ReadError, &sh->dev[i].flags); 423 - clear_bit(R5_ReWrite, &sh->dev[i].flags); 424 - } 425 - if (atomic_read(&conf->disks[i].rdev->read_errors)) 426 - atomic_set(&conf->disks[i].rdev->read_errors, 0); 427 - } else { 428 - int retry = 0; 429 - clear_bit(R5_UPTODATE, &sh->dev[i].flags); 430 - atomic_inc(&conf->disks[i].rdev->read_errors); 431 - if (conf->mddev->degraded) 432 - printk(KERN_WARNING "raid6: read error not correctable.\n"); 433 - else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) 434 - /* Oh, no!!! */ 435 - printk(KERN_WARNING "raid6: read error NOT corrected!!\n"); 436 - else if (atomic_read(&conf->disks[i].rdev->read_errors) 437 - > conf->max_nr_stripes) 438 - printk(KERN_WARNING 439 - "raid6: Too many read errors, failing device.\n"); 440 - else 441 - retry = 1; 442 - if (retry) 443 - set_bit(R5_ReadError, &sh->dev[i].flags); 444 - else { 445 - clear_bit(R5_ReadError, &sh->dev[i].flags); 446 - clear_bit(R5_ReWrite, &sh->dev[i].flags); 447 - md_error(conf->mddev, conf->disks[i].rdev); 448 - } 449 - } 450 - rdev_dec_pending(conf->disks[i].rdev, conf->mddev); 451 - #if 0 452 - /* must restore b_page before unlocking buffer... */ 453 - if (sh->bh_page[i] != bh->b_page) { 454 - bh->b_page = sh->bh_page[i]; 455 - bh->b_data = page_address(bh->b_page); 456 - clear_buffer_uptodate(bh); 457 - } 458 - #endif 459 - clear_bit(R5_LOCKED, &sh->dev[i].flags); 460 - set_bit(STRIPE_HANDLE, &sh->state); 461 - release_stripe(sh); 462 - return 0; 463 - } 464 - 465 - static int raid6_end_write_request (struct bio *bi, unsigned int bytes_done, 466 - int error) 467 - { 468 - struct stripe_head *sh = bi->bi_private; 469 - raid6_conf_t *conf = sh->raid_conf; 470 - int disks = conf->raid_disks, i; 471 - unsigned long flags; 472 - int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); 473 - 474 - if (bi->bi_size) 475 - return 1; 476 - 477 - for (i=0 ; i<disks; i++) 478 - if (bi == &sh->dev[i].req) 479 - break; 480 - 481 - PRINTK("end_write_request %llu/%d, count %d, uptodate: %d.\n", 482 - (unsigned long long)sh->sector, i, atomic_read(&sh->count), 483 - uptodate); 484 - if (i == disks) { 485 - BUG(); 486 - return 0; 487 - } 488 - 489 - spin_lock_irqsave(&conf->device_lock, flags); 490 - if (!uptodate) 491 - md_error(conf->mddev, conf->disks[i].rdev); 492 - 493 - rdev_dec_pending(conf->disks[i].rdev, conf->mddev); 494 - 495 - clear_bit(R5_LOCKED, &sh->dev[i].flags); 496 - set_bit(STRIPE_HANDLE, &sh->state); 497 - __release_stripe(conf, sh); 498 - spin_unlock_irqrestore(&conf->device_lock, flags); 499 - return 0; 500 - } 501 - 502 - 503 - static sector_t compute_blocknr(struct stripe_head *sh, int i); 504 - 505 - static void raid6_build_block (struct stripe_head *sh, int i) 506 - { 507 - struct r5dev *dev = &sh->dev[i]; 508 - int pd_idx = sh->pd_idx; 509 - int qd_idx = raid6_next_disk(pd_idx, sh->raid_conf->raid_disks); 510 - 511 - bio_init(&dev->req); 512 - dev->req.bi_io_vec = &dev->vec; 513 - dev->req.bi_vcnt++; 514 - dev->req.bi_max_vecs++; 515 - dev->vec.bv_page = dev->page; 516 - dev->vec.bv_len = STRIPE_SIZE; 517 - dev->vec.bv_offset = 0; 518 - 519 - dev->req.bi_sector = sh->sector; 520 - dev->req.bi_private = sh; 521 - 522 - dev->flags = 0; 523 - if (i != pd_idx && i != qd_idx) 524 - dev->sector = compute_blocknr(sh, i); 525 - } 526 - 527 - static void error(mddev_t *mddev, mdk_rdev_t *rdev) 528 - { 529 - char b[BDEVNAME_SIZE]; 530 - raid6_conf_t *conf = (raid6_conf_t *) mddev->private; 531 - PRINTK("raid6: error called\n"); 532 - 533 - if (!test_bit(Faulty, &rdev->flags)) { 534 - mddev->sb_dirty = 1; 535 - if (test_bit(In_sync, &rdev->flags)) { 536 - conf->working_disks--; 537 - mddev->degraded++; 538 - conf->failed_disks++; 539 - clear_bit(In_sync, &rdev->flags); 540 - /* 541 - * if recovery was running, make sure it aborts. 542 - */ 543 - set_bit(MD_RECOVERY_ERR, &mddev->recovery); 544 - } 545 - set_bit(Faulty, &rdev->flags); 546 - printk (KERN_ALERT 547 - "raid6: Disk failure on %s, disabling device." 548 - " Operation continuing on %d devices\n", 549 - bdevname(rdev->bdev,b), conf->working_disks); 550 - } 551 - } 552 - 553 - /* 554 - * Input: a 'big' sector number, 555 - * Output: index of the data and parity disk, and the sector # in them. 556 - */ 557 - static sector_t raid6_compute_sector(sector_t r_sector, unsigned int raid_disks, 558 - unsigned int data_disks, unsigned int * dd_idx, 559 - unsigned int * pd_idx, raid6_conf_t *conf) 560 - { 561 - long stripe; 562 - unsigned long chunk_number; 563 - unsigned int chunk_offset; 564 - sector_t new_sector; 565 - int sectors_per_chunk = conf->chunk_size >> 9; 566 - 567 - /* First compute the information on this sector */ 568 - 569 - /* 570 - * Compute the chunk number and the sector offset inside the chunk 571 - */ 572 - chunk_offset = sector_div(r_sector, sectors_per_chunk); 573 - chunk_number = r_sector; 574 - if ( r_sector != chunk_number ) { 575 - printk(KERN_CRIT "raid6: ERROR: r_sector = %llu, chunk_number = %lu\n", 576 - (unsigned long long)r_sector, (unsigned long)chunk_number); 577 - BUG(); 578 - } 579 - 580 - /* 581 - * Compute the stripe number 582 - */ 583 - stripe = chunk_number / data_disks; 584 - 585 - /* 586 - * Compute the data disk and parity disk indexes inside the stripe 587 - */ 588 - *dd_idx = chunk_number % data_disks; 589 - 590 - /* 591 - * Select the parity disk based on the user selected algorithm. 592 - */ 593 - 594 - /**** FIX THIS ****/ 595 - switch (conf->algorithm) { 596 - case ALGORITHM_LEFT_ASYMMETRIC: 597 - *pd_idx = raid_disks - 1 - (stripe % raid_disks); 598 - if (*pd_idx == raid_disks-1) 599 - (*dd_idx)++; /* Q D D D P */ 600 - else if (*dd_idx >= *pd_idx) 601 - (*dd_idx) += 2; /* D D P Q D */ 602 - break; 603 - case ALGORITHM_RIGHT_ASYMMETRIC: 604 - *pd_idx = stripe % raid_disks; 605 - if (*pd_idx == raid_disks-1) 606 - (*dd_idx)++; /* Q D D D P */ 607 - else if (*dd_idx >= *pd_idx) 608 - (*dd_idx) += 2; /* D D P Q D */ 609 - break; 610 - case ALGORITHM_LEFT_SYMMETRIC: 611 - *pd_idx = raid_disks - 1 - (stripe % raid_disks); 612 - *dd_idx = (*pd_idx + 2 + *dd_idx) % raid_disks; 613 - break; 614 - case ALGORITHM_RIGHT_SYMMETRIC: 615 - *pd_idx = stripe % raid_disks; 616 - *dd_idx = (*pd_idx + 2 + *dd_idx) % raid_disks; 617 - break; 618 - default: 619 - printk (KERN_CRIT "raid6: unsupported algorithm %d\n", 620 - conf->algorithm); 621 - } 622 - 623 - PRINTK("raid6: chunk_number = %lu, pd_idx = %u, dd_idx = %u\n", 624 - chunk_number, *pd_idx, *dd_idx); 625 - 626 - /* 627 - * Finally, compute the new sector number 628 - */ 629 - new_sector = (sector_t) stripe * sectors_per_chunk + chunk_offset; 630 - return new_sector; 631 - } 632 - 633 - 634 - static sector_t compute_blocknr(struct stripe_head *sh, int i) 635 - { 636 - raid6_conf_t *conf = sh->raid_conf; 637 - int raid_disks = conf->raid_disks, data_disks = raid_disks - 2; 638 - sector_t new_sector = sh->sector, check; 639 - int sectors_per_chunk = conf->chunk_size >> 9; 640 - sector_t stripe; 641 - int chunk_offset; 642 - int chunk_number, dummy1, dummy2, dd_idx = i; 643 - sector_t r_sector; 644 - int i0 = i; 645 - 646 - chunk_offset = sector_div(new_sector, sectors_per_chunk); 647 - stripe = new_sector; 648 - if ( new_sector != stripe ) { 649 - printk(KERN_CRIT "raid6: ERROR: new_sector = %llu, stripe = %lu\n", 650 - (unsigned long long)new_sector, (unsigned long)stripe); 651 - BUG(); 652 - } 653 - 654 - switch (conf->algorithm) { 655 - case ALGORITHM_LEFT_ASYMMETRIC: 656 - case ALGORITHM_RIGHT_ASYMMETRIC: 657 - if (sh->pd_idx == raid_disks-1) 658 - i--; /* Q D D D P */ 659 - else if (i > sh->pd_idx) 660 - i -= 2; /* D D P Q D */ 661 - break; 662 - case ALGORITHM_LEFT_SYMMETRIC: 663 - case ALGORITHM_RIGHT_SYMMETRIC: 664 - if (sh->pd_idx == raid_disks-1) 665 - i--; /* Q D D D P */ 666 - else { 667 - /* D D P Q D */ 668 - if (i < sh->pd_idx) 669 - i += raid_disks; 670 - i -= (sh->pd_idx + 2); 671 - } 672 - break; 673 - default: 674 - printk (KERN_CRIT "raid6: unsupported algorithm %d\n", 675 - conf->algorithm); 676 - } 677 - 678 - PRINTK("raid6: compute_blocknr: pd_idx = %u, i0 = %u, i = %u\n", sh->pd_idx, i0, i); 679 - 680 - chunk_number = stripe * data_disks + i; 681 - r_sector = (sector_t)chunk_number * sectors_per_chunk + chunk_offset; 682 - 683 - check = raid6_compute_sector (r_sector, raid_disks, data_disks, &dummy1, &dummy2, conf); 684 - if (check != sh->sector || dummy1 != dd_idx || dummy2 != sh->pd_idx) { 685 - printk(KERN_CRIT "raid6: compute_blocknr: map not correct\n"); 686 - return 0; 687 - } 688 - return r_sector; 689 - } 690 - 691 - 692 - 693 - /* 694 - * Copy data between a page in the stripe cache, and one or more bion 695 - * The page could align with the middle of the bio, or there could be 696 - * several bion, each with several bio_vecs, which cover part of the page 697 - * Multiple bion are linked together on bi_next. There may be extras 698 - * at the end of this list. We ignore them. 699 - */ 700 - static void copy_data(int frombio, struct bio *bio, 701 - struct page *page, 702 - sector_t sector) 703 - { 704 - char *pa = page_address(page); 705 - struct bio_vec *bvl; 706 - int i; 707 - int page_offset; 708 - 709 - if (bio->bi_sector >= sector) 710 - page_offset = (signed)(bio->bi_sector - sector) * 512; 711 - else 712 - page_offset = (signed)(sector - bio->bi_sector) * -512; 713 - bio_for_each_segment(bvl, bio, i) { 714 - int len = bio_iovec_idx(bio,i)->bv_len; 715 - int clen; 716 - int b_offset = 0; 717 - 718 - if (page_offset < 0) { 719 - b_offset = -page_offset; 720 - page_offset += b_offset; 721 - len -= b_offset; 722 - } 723 - 724 - if (len > 0 && page_offset + len > STRIPE_SIZE) 725 - clen = STRIPE_SIZE - page_offset; 726 - else clen = len; 727 - 728 - if (clen > 0) { 729 - char *ba = __bio_kmap_atomic(bio, i, KM_USER0); 730 - if (frombio) 731 - memcpy(pa+page_offset, ba+b_offset, clen); 732 - else 733 - memcpy(ba+b_offset, pa+page_offset, clen); 734 - __bio_kunmap_atomic(ba, KM_USER0); 735 - } 736 - if (clen < len) /* hit end of page */ 737 - break; 738 - page_offset += len; 739 - } 740 - } 741 - 742 - #define check_xor() do { \ 743 - if (count == MAX_XOR_BLOCKS) { \ 744 - xor_block(count, STRIPE_SIZE, ptr); \ 745 - count = 1; \ 746 - } \ 747 - } while(0) 748 - 749 - /* Compute P and Q syndromes */ 750 - static void compute_parity(struct stripe_head *sh, int method) 751 - { 752 - raid6_conf_t *conf = sh->raid_conf; 753 - int i, pd_idx = sh->pd_idx, qd_idx, d0_idx, disks = conf->raid_disks, count; 754 - struct bio *chosen; 755 - /**** FIX THIS: This could be very bad if disks is close to 256 ****/ 756 - void *ptrs[disks]; 757 - 758 - qd_idx = raid6_next_disk(pd_idx, disks); 759 - d0_idx = raid6_next_disk(qd_idx, disks); 760 - 761 - PRINTK("compute_parity, stripe %llu, method %d\n", 762 - (unsigned long long)sh->sector, method); 763 - 764 - switch(method) { 765 - case READ_MODIFY_WRITE: 766 - BUG(); /* READ_MODIFY_WRITE N/A for RAID-6 */ 767 - case RECONSTRUCT_WRITE: 768 - for (i= disks; i-- ;) 769 - if ( i != pd_idx && i != qd_idx && sh->dev[i].towrite ) { 770 - chosen = sh->dev[i].towrite; 771 - sh->dev[i].towrite = NULL; 772 - 773 - if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 774 - wake_up(&conf->wait_for_overlap); 775 - 776 - BUG_ON(sh->dev[i].written); 777 - sh->dev[i].written = chosen; 778 - } 779 - break; 780 - case CHECK_PARITY: 781 - BUG(); /* Not implemented yet */ 782 - } 783 - 784 - for (i = disks; i--;) 785 - if (sh->dev[i].written) { 786 - sector_t sector = sh->dev[i].sector; 787 - struct bio *wbi = sh->dev[i].written; 788 - while (wbi && wbi->bi_sector < sector + STRIPE_SECTORS) { 789 - copy_data(1, wbi, sh->dev[i].page, sector); 790 - wbi = r5_next_bio(wbi, sector); 791 - } 792 - 793 - set_bit(R5_LOCKED, &sh->dev[i].flags); 794 - set_bit(R5_UPTODATE, &sh->dev[i].flags); 795 - } 796 - 797 - // switch(method) { 798 - // case RECONSTRUCT_WRITE: 799 - // case CHECK_PARITY: 800 - // case UPDATE_PARITY: 801 - /* Note that unlike RAID-5, the ordering of the disks matters greatly. */ 802 - /* FIX: Is this ordering of drives even remotely optimal? */ 803 - count = 0; 804 - i = d0_idx; 805 - do { 806 - ptrs[count++] = page_address(sh->dev[i].page); 807 - if (count <= disks-2 && !test_bit(R5_UPTODATE, &sh->dev[i].flags)) 808 - printk("block %d/%d not uptodate on parity calc\n", i,count); 809 - i = raid6_next_disk(i, disks); 810 - } while ( i != d0_idx ); 811 - // break; 812 - // } 813 - 814 - raid6_call.gen_syndrome(disks, STRIPE_SIZE, ptrs); 815 - 816 - switch(method) { 817 - case RECONSTRUCT_WRITE: 818 - set_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); 819 - set_bit(R5_UPTODATE, &sh->dev[qd_idx].flags); 820 - set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); 821 - set_bit(R5_LOCKED, &sh->dev[qd_idx].flags); 822 - break; 823 - case UPDATE_PARITY: 824 - set_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); 825 - set_bit(R5_UPTODATE, &sh->dev[qd_idx].flags); 826 - break; 827 - } 828 - } 829 - 830 - /* Compute one missing block */ 831 - static void compute_block_1(struct stripe_head *sh, int dd_idx, int nozero) 832 - { 833 - raid6_conf_t *conf = sh->raid_conf; 834 - int i, count, disks = conf->raid_disks; 835 - void *ptr[MAX_XOR_BLOCKS], *p; 836 - int pd_idx = sh->pd_idx; 837 - int qd_idx = raid6_next_disk(pd_idx, disks); 838 - 839 - PRINTK("compute_block_1, stripe %llu, idx %d\n", 840 - (unsigned long long)sh->sector, dd_idx); 841 - 842 - if ( dd_idx == qd_idx ) { 843 - /* We're actually computing the Q drive */ 844 - compute_parity(sh, UPDATE_PARITY); 845 - } else { 846 - ptr[0] = page_address(sh->dev[dd_idx].page); 847 - if (!nozero) memset(ptr[0], 0, STRIPE_SIZE); 848 - count = 1; 849 - for (i = disks ; i--; ) { 850 - if (i == dd_idx || i == qd_idx) 851 - continue; 852 - p = page_address(sh->dev[i].page); 853 - if (test_bit(R5_UPTODATE, &sh->dev[i].flags)) 854 - ptr[count++] = p; 855 - else 856 - printk("compute_block() %d, stripe %llu, %d" 857 - " not present\n", dd_idx, 858 - (unsigned long long)sh->sector, i); 859 - 860 - check_xor(); 861 - } 862 - if (count != 1) 863 - xor_block(count, STRIPE_SIZE, ptr); 864 - if (!nozero) set_bit(R5_UPTODATE, &sh->dev[dd_idx].flags); 865 - else clear_bit(R5_UPTODATE, &sh->dev[dd_idx].flags); 866 - } 867 - } 868 - 869 - /* Compute two missing blocks */ 870 - static void compute_block_2(struct stripe_head *sh, int dd_idx1, int dd_idx2) 871 - { 872 - raid6_conf_t *conf = sh->raid_conf; 873 - int i, count, disks = conf->raid_disks; 874 - int pd_idx = sh->pd_idx; 875 - int qd_idx = raid6_next_disk(pd_idx, disks); 876 - int d0_idx = raid6_next_disk(qd_idx, disks); 877 - int faila, failb; 878 - 879 - /* faila and failb are disk numbers relative to d0_idx */ 880 - /* pd_idx become disks-2 and qd_idx become disks-1 */ 881 - faila = (dd_idx1 < d0_idx) ? dd_idx1+(disks-d0_idx) : dd_idx1-d0_idx; 882 - failb = (dd_idx2 < d0_idx) ? dd_idx2+(disks-d0_idx) : dd_idx2-d0_idx; 883 - 884 - BUG_ON(faila == failb); 885 - if ( failb < faila ) { int tmp = faila; faila = failb; failb = tmp; } 886 - 887 - PRINTK("compute_block_2, stripe %llu, idx %d,%d (%d,%d)\n", 888 - (unsigned long long)sh->sector, dd_idx1, dd_idx2, faila, failb); 889 - 890 - if ( failb == disks-1 ) { 891 - /* Q disk is one of the missing disks */ 892 - if ( faila == disks-2 ) { 893 - /* Missing P+Q, just recompute */ 894 - compute_parity(sh, UPDATE_PARITY); 895 - return; 896 - } else { 897 - /* We're missing D+Q; recompute D from P */ 898 - compute_block_1(sh, (dd_idx1 == qd_idx) ? dd_idx2 : dd_idx1, 0); 899 - compute_parity(sh, UPDATE_PARITY); /* Is this necessary? */ 900 - return; 901 - } 902 - } 903 - 904 - /* We're missing D+P or D+D; build pointer table */ 905 - { 906 - /**** FIX THIS: This could be very bad if disks is close to 256 ****/ 907 - void *ptrs[disks]; 908 - 909 - count = 0; 910 - i = d0_idx; 911 - do { 912 - ptrs[count++] = page_address(sh->dev[i].page); 913 - i = raid6_next_disk(i, disks); 914 - if (i != dd_idx1 && i != dd_idx2 && 915 - !test_bit(R5_UPTODATE, &sh->dev[i].flags)) 916 - printk("compute_2 with missing block %d/%d\n", count, i); 917 - } while ( i != d0_idx ); 918 - 919 - if ( failb == disks-2 ) { 920 - /* We're missing D+P. */ 921 - raid6_datap_recov(disks, STRIPE_SIZE, faila, ptrs); 922 - } else { 923 - /* We're missing D+D. */ 924 - raid6_2data_recov(disks, STRIPE_SIZE, faila, failb, ptrs); 925 - } 926 - 927 - /* Both the above update both missing blocks */ 928 - set_bit(R5_UPTODATE, &sh->dev[dd_idx1].flags); 929 - set_bit(R5_UPTODATE, &sh->dev[dd_idx2].flags); 930 - } 931 - } 932 - 933 - 934 - /* 935 - * Each stripe/dev can have one or more bion attached. 936 - * toread/towrite point to the first in a chain. 937 - * The bi_next chain must be in order. 938 - */ 939 - static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, int forwrite) 940 - { 941 - struct bio **bip; 942 - raid6_conf_t *conf = sh->raid_conf; 943 - int firstwrite=0; 944 - 945 - PRINTK("adding bh b#%llu to stripe s#%llu\n", 946 - (unsigned long long)bi->bi_sector, 947 - (unsigned long long)sh->sector); 948 - 949 - 950 - spin_lock(&sh->lock); 951 - spin_lock_irq(&conf->device_lock); 952 - if (forwrite) { 953 - bip = &sh->dev[dd_idx].towrite; 954 - if (*bip == NULL && sh->dev[dd_idx].written == NULL) 955 - firstwrite = 1; 956 - } else 957 - bip = &sh->dev[dd_idx].toread; 958 - while (*bip && (*bip)->bi_sector < bi->bi_sector) { 959 - if ((*bip)->bi_sector + ((*bip)->bi_size >> 9) > bi->bi_sector) 960 - goto overlap; 961 - bip = &(*bip)->bi_next; 962 - } 963 - if (*bip && (*bip)->bi_sector < bi->bi_sector + ((bi->bi_size)>>9)) 964 - goto overlap; 965 - 966 - BUG_ON(*bip && bi->bi_next && (*bip) != bi->bi_next); 967 - if (*bip) 968 - bi->bi_next = *bip; 969 - *bip = bi; 970 - bi->bi_phys_segments ++; 971 - spin_unlock_irq(&conf->device_lock); 972 - spin_unlock(&sh->lock); 973 - 974 - PRINTK("added bi b#%llu to stripe s#%llu, disk %d.\n", 975 - (unsigned long long)bi->bi_sector, 976 - (unsigned long long)sh->sector, dd_idx); 977 - 978 - if (conf->mddev->bitmap && firstwrite) { 979 - sh->bm_seq = conf->seq_write; 980 - bitmap_startwrite(conf->mddev->bitmap, sh->sector, 981 - STRIPE_SECTORS, 0); 982 - set_bit(STRIPE_BIT_DELAY, &sh->state); 983 - } 984 - 985 - if (forwrite) { 986 - /* check if page is covered */ 987 - sector_t sector = sh->dev[dd_idx].sector; 988 - for (bi=sh->dev[dd_idx].towrite; 989 - sector < sh->dev[dd_idx].sector + STRIPE_SECTORS && 990 - bi && bi->bi_sector <= sector; 991 - bi = r5_next_bio(bi, sh->dev[dd_idx].sector)) { 992 - if (bi->bi_sector + (bi->bi_size>>9) >= sector) 993 - sector = bi->bi_sector + (bi->bi_size>>9); 994 - } 995 - if (sector >= sh->dev[dd_idx].sector + STRIPE_SECTORS) 996 - set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags); 997 - } 998 - return 1; 999 - 1000 - overlap: 1001 - set_bit(R5_Overlap, &sh->dev[dd_idx].flags); 1002 - spin_unlock_irq(&conf->device_lock); 1003 - spin_unlock(&sh->lock); 1004 - return 0; 1005 - } 1006 - 1007 - 1008 - static int page_is_zero(struct page *p) 1009 - { 1010 - char *a = page_address(p); 1011 - return ((*(u32*)a) == 0 && 1012 - memcmp(a, a+4, STRIPE_SIZE-4)==0); 1013 - } 1014 - /* 1015 - * handle_stripe - do things to a stripe. 1016 - * 1017 - * We lock the stripe and then examine the state of various bits 1018 - * to see what needs to be done. 1019 - * Possible results: 1020 - * return some read request which now have data 1021 - * return some write requests which are safely on disc 1022 - * schedule a read on some buffers 1023 - * schedule a write of some buffers 1024 - * return confirmation of parity correctness 1025 - * 1026 - * Parity calculations are done inside the stripe lock 1027 - * buffers are taken off read_list or write_list, and bh_cache buffers 1028 - * get BH_Lock set before the stripe lock is released. 1029 - * 1030 - */ 1031 - 1032 - static void handle_stripe(struct stripe_head *sh, struct page *tmp_page) 1033 - { 1034 - raid6_conf_t *conf = sh->raid_conf; 1035 - int disks = conf->raid_disks; 1036 - struct bio *return_bi= NULL; 1037 - struct bio *bi; 1038 - int i; 1039 - int syncing; 1040 - int locked=0, uptodate=0, to_read=0, to_write=0, failed=0, written=0; 1041 - int non_overwrite = 0; 1042 - int failed_num[2] = {0, 0}; 1043 - struct r5dev *dev, *pdev, *qdev; 1044 - int pd_idx = sh->pd_idx; 1045 - int qd_idx = raid6_next_disk(pd_idx, disks); 1046 - int p_failed, q_failed; 1047 - 1048 - PRINTK("handling stripe %llu, state=%#lx cnt=%d, pd_idx=%d, qd_idx=%d\n", 1049 - (unsigned long long)sh->sector, sh->state, atomic_read(&sh->count), 1050 - pd_idx, qd_idx); 1051 - 1052 - spin_lock(&sh->lock); 1053 - clear_bit(STRIPE_HANDLE, &sh->state); 1054 - clear_bit(STRIPE_DELAYED, &sh->state); 1055 - 1056 - syncing = test_bit(STRIPE_SYNCING, &sh->state); 1057 - /* Now to look around and see what can be done */ 1058 - 1059 - rcu_read_lock(); 1060 - for (i=disks; i--; ) { 1061 - mdk_rdev_t *rdev; 1062 - dev = &sh->dev[i]; 1063 - clear_bit(R5_Insync, &dev->flags); 1064 - 1065 - PRINTK("check %d: state 0x%lx read %p write %p written %p\n", 1066 - i, dev->flags, dev->toread, dev->towrite, dev->written); 1067 - /* maybe we can reply to a read */ 1068 - if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread) { 1069 - struct bio *rbi, *rbi2; 1070 - PRINTK("Return read for disc %d\n", i); 1071 - spin_lock_irq(&conf->device_lock); 1072 - rbi = dev->toread; 1073 - dev->toread = NULL; 1074 - if (test_and_clear_bit(R5_Overlap, &dev->flags)) 1075 - wake_up(&conf->wait_for_overlap); 1076 - spin_unlock_irq(&conf->device_lock); 1077 - while (rbi && rbi->bi_sector < dev->sector + STRIPE_SECTORS) { 1078 - copy_data(0, rbi, dev->page, dev->sector); 1079 - rbi2 = r5_next_bio(rbi, dev->sector); 1080 - spin_lock_irq(&conf->device_lock); 1081 - if (--rbi->bi_phys_segments == 0) { 1082 - rbi->bi_next = return_bi; 1083 - return_bi = rbi; 1084 - } 1085 - spin_unlock_irq(&conf->device_lock); 1086 - rbi = rbi2; 1087 - } 1088 - } 1089 - 1090 - /* now count some things */ 1091 - if (test_bit(R5_LOCKED, &dev->flags)) locked++; 1092 - if (test_bit(R5_UPTODATE, &dev->flags)) uptodate++; 1093 - 1094 - 1095 - if (dev->toread) to_read++; 1096 - if (dev->towrite) { 1097 - to_write++; 1098 - if (!test_bit(R5_OVERWRITE, &dev->flags)) 1099 - non_overwrite++; 1100 - } 1101 - if (dev->written) written++; 1102 - rdev = rcu_dereference(conf->disks[i].rdev); 1103 - if (!rdev || !test_bit(In_sync, &rdev->flags)) { 1104 - /* The ReadError flag will just be confusing now */ 1105 - clear_bit(R5_ReadError, &dev->flags); 1106 - clear_bit(R5_ReWrite, &dev->flags); 1107 - } 1108 - if (!rdev || !test_bit(In_sync, &rdev->flags) 1109 - || test_bit(R5_ReadError, &dev->flags)) { 1110 - if ( failed < 2 ) 1111 - failed_num[failed] = i; 1112 - failed++; 1113 - } else 1114 - set_bit(R5_Insync, &dev->flags); 1115 - } 1116 - rcu_read_unlock(); 1117 - PRINTK("locked=%d uptodate=%d to_read=%d" 1118 - " to_write=%d failed=%d failed_num=%d,%d\n", 1119 - locked, uptodate, to_read, to_write, failed, 1120 - failed_num[0], failed_num[1]); 1121 - /* check if the array has lost >2 devices and, if so, some requests might 1122 - * need to be failed 1123 - */ 1124 - if (failed > 2 && to_read+to_write+written) { 1125 - for (i=disks; i--; ) { 1126 - int bitmap_end = 0; 1127 - 1128 - if (test_bit(R5_ReadError, &sh->dev[i].flags)) { 1129 - mdk_rdev_t *rdev; 1130 - rcu_read_lock(); 1131 - rdev = rcu_dereference(conf->disks[i].rdev); 1132 - if (rdev && test_bit(In_sync, &rdev->flags)) 1133 - /* multiple read failures in one stripe */ 1134 - md_error(conf->mddev, rdev); 1135 - rcu_read_unlock(); 1136 - } 1137 - 1138 - spin_lock_irq(&conf->device_lock); 1139 - /* fail all writes first */ 1140 - bi = sh->dev[i].towrite; 1141 - sh->dev[i].towrite = NULL; 1142 - if (bi) { to_write--; bitmap_end = 1; } 1143 - 1144 - if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 1145 - wake_up(&conf->wait_for_overlap); 1146 - 1147 - while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS){ 1148 - struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); 1149 - clear_bit(BIO_UPTODATE, &bi->bi_flags); 1150 - if (--bi->bi_phys_segments == 0) { 1151 - md_write_end(conf->mddev); 1152 - bi->bi_next = return_bi; 1153 - return_bi = bi; 1154 - } 1155 - bi = nextbi; 1156 - } 1157 - /* and fail all 'written' */ 1158 - bi = sh->dev[i].written; 1159 - sh->dev[i].written = NULL; 1160 - if (bi) bitmap_end = 1; 1161 - while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS) { 1162 - struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); 1163 - clear_bit(BIO_UPTODATE, &bi->bi_flags); 1164 - if (--bi->bi_phys_segments == 0) { 1165 - md_write_end(conf->mddev); 1166 - bi->bi_next = return_bi; 1167 - return_bi = bi; 1168 - } 1169 - bi = bi2; 1170 - } 1171 - 1172 - /* fail any reads if this device is non-operational */ 1173 - if (!test_bit(R5_Insync, &sh->dev[i].flags) || 1174 - test_bit(R5_ReadError, &sh->dev[i].flags)) { 1175 - bi = sh->dev[i].toread; 1176 - sh->dev[i].toread = NULL; 1177 - if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 1178 - wake_up(&conf->wait_for_overlap); 1179 - if (bi) to_read--; 1180 - while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS){ 1181 - struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); 1182 - clear_bit(BIO_UPTODATE, &bi->bi_flags); 1183 - if (--bi->bi_phys_segments == 0) { 1184 - bi->bi_next = return_bi; 1185 - return_bi = bi; 1186 - } 1187 - bi = nextbi; 1188 - } 1189 - } 1190 - spin_unlock_irq(&conf->device_lock); 1191 - if (bitmap_end) 1192 - bitmap_endwrite(conf->mddev->bitmap, sh->sector, 1193 - STRIPE_SECTORS, 0, 0); 1194 - } 1195 - } 1196 - if (failed > 2 && syncing) { 1197 - md_done_sync(conf->mddev, STRIPE_SECTORS,0); 1198 - clear_bit(STRIPE_SYNCING, &sh->state); 1199 - syncing = 0; 1200 - } 1201 - 1202 - /* 1203 - * might be able to return some write requests if the parity blocks 1204 - * are safe, or on a failed drive 1205 - */ 1206 - pdev = &sh->dev[pd_idx]; 1207 - p_failed = (failed >= 1 && failed_num[0] == pd_idx) 1208 - || (failed >= 2 && failed_num[1] == pd_idx); 1209 - qdev = &sh->dev[qd_idx]; 1210 - q_failed = (failed >= 1 && failed_num[0] == qd_idx) 1211 - || (failed >= 2 && failed_num[1] == qd_idx); 1212 - 1213 - if ( written && 1214 - ( p_failed || ((test_bit(R5_Insync, &pdev->flags) 1215 - && !test_bit(R5_LOCKED, &pdev->flags) 1216 - && test_bit(R5_UPTODATE, &pdev->flags))) ) && 1217 - ( q_failed || ((test_bit(R5_Insync, &qdev->flags) 1218 - && !test_bit(R5_LOCKED, &qdev->flags) 1219 - && test_bit(R5_UPTODATE, &qdev->flags))) ) ) { 1220 - /* any written block on an uptodate or failed drive can be 1221 - * returned. Note that if we 'wrote' to a failed drive, 1222 - * it will be UPTODATE, but never LOCKED, so we don't need 1223 - * to test 'failed' directly. 1224 - */ 1225 - for (i=disks; i--; ) 1226 - if (sh->dev[i].written) { 1227 - dev = &sh->dev[i]; 1228 - if (!test_bit(R5_LOCKED, &dev->flags) && 1229 - test_bit(R5_UPTODATE, &dev->flags) ) { 1230 - /* We can return any write requests */ 1231 - int bitmap_end = 0; 1232 - struct bio *wbi, *wbi2; 1233 - PRINTK("Return write for stripe %llu disc %d\n", 1234 - (unsigned long long)sh->sector, i); 1235 - spin_lock_irq(&conf->device_lock); 1236 - wbi = dev->written; 1237 - dev->written = NULL; 1238 - while (wbi && wbi->bi_sector < dev->sector + STRIPE_SECTORS) { 1239 - wbi2 = r5_next_bio(wbi, dev->sector); 1240 - if (--wbi->bi_phys_segments == 0) { 1241 - md_write_end(conf->mddev); 1242 - wbi->bi_next = return_bi; 1243 - return_bi = wbi; 1244 - } 1245 - wbi = wbi2; 1246 - } 1247 - if (dev->towrite == NULL) 1248 - bitmap_end = 1; 1249 - spin_unlock_irq(&conf->device_lock); 1250 - if (bitmap_end) 1251 - bitmap_endwrite(conf->mddev->bitmap, sh->sector, 1252 - STRIPE_SECTORS, 1253 - !test_bit(STRIPE_DEGRADED, &sh->state), 0); 1254 - } 1255 - } 1256 - } 1257 - 1258 - /* Now we might consider reading some blocks, either to check/generate 1259 - * parity, or to satisfy requests 1260 - * or to load a block that is being partially written. 1261 - */ 1262 - if (to_read || non_overwrite || (to_write && failed) || (syncing && (uptodate < disks))) { 1263 - for (i=disks; i--;) { 1264 - dev = &sh->dev[i]; 1265 - if (!test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_UPTODATE, &dev->flags) && 1266 - (dev->toread || 1267 - (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || 1268 - syncing || 1269 - (failed >= 1 && (sh->dev[failed_num[0]].toread || to_write)) || 1270 - (failed >= 2 && (sh->dev[failed_num[1]].toread || to_write)) 1271 - ) 1272 - ) { 1273 - /* we would like to get this block, possibly 1274 - * by computing it, but we might not be able to 1275 - */ 1276 - if (uptodate == disks-1) { 1277 - PRINTK("Computing stripe %llu block %d\n", 1278 - (unsigned long long)sh->sector, i); 1279 - compute_block_1(sh, i, 0); 1280 - uptodate++; 1281 - } else if ( uptodate == disks-2 && failed >= 2 ) { 1282 - /* Computing 2-failure is *very* expensive; only do it if failed >= 2 */ 1283 - int other; 1284 - for (other=disks; other--;) { 1285 - if ( other == i ) 1286 - continue; 1287 - if ( !test_bit(R5_UPTODATE, &sh->dev[other].flags) ) 1288 - break; 1289 - } 1290 - BUG_ON(other < 0); 1291 - PRINTK("Computing stripe %llu blocks %d,%d\n", 1292 - (unsigned long long)sh->sector, i, other); 1293 - compute_block_2(sh, i, other); 1294 - uptodate += 2; 1295 - } else if (test_bit(R5_Insync, &dev->flags)) { 1296 - set_bit(R5_LOCKED, &dev->flags); 1297 - set_bit(R5_Wantread, &dev->flags); 1298 - #if 0 1299 - /* if I am just reading this block and we don't have 1300 - a failed drive, or any pending writes then sidestep the cache */ 1301 - if (sh->bh_read[i] && !sh->bh_read[i]->b_reqnext && 1302 - ! syncing && !failed && !to_write) { 1303 - sh->bh_cache[i]->b_page = sh->bh_read[i]->b_page; 1304 - sh->bh_cache[i]->b_data = sh->bh_read[i]->b_data; 1305 - } 1306 - #endif 1307 - locked++; 1308 - PRINTK("Reading block %d (sync=%d)\n", 1309 - i, syncing); 1310 - } 1311 - } 1312 - } 1313 - set_bit(STRIPE_HANDLE, &sh->state); 1314 - } 1315 - 1316 - /* now to consider writing and what else, if anything should be read */ 1317 - if (to_write) { 1318 - int rcw=0, must_compute=0; 1319 - for (i=disks ; i--;) { 1320 - dev = &sh->dev[i]; 1321 - /* Would I have to read this buffer for reconstruct_write */ 1322 - if (!test_bit(R5_OVERWRITE, &dev->flags) 1323 - && i != pd_idx && i != qd_idx 1324 - && (!test_bit(R5_LOCKED, &dev->flags) 1325 - #if 0 1326 - || sh->bh_page[i] != bh->b_page 1327 - #endif 1328 - ) && 1329 - !test_bit(R5_UPTODATE, &dev->flags)) { 1330 - if (test_bit(R5_Insync, &dev->flags)) rcw++; 1331 - else { 1332 - PRINTK("raid6: must_compute: disk %d flags=%#lx\n", i, dev->flags); 1333 - must_compute++; 1334 - } 1335 - } 1336 - } 1337 - PRINTK("for sector %llu, rcw=%d, must_compute=%d\n", 1338 - (unsigned long long)sh->sector, rcw, must_compute); 1339 - set_bit(STRIPE_HANDLE, &sh->state); 1340 - 1341 - if (rcw > 0) 1342 - /* want reconstruct write, but need to get some data */ 1343 - for (i=disks; i--;) { 1344 - dev = &sh->dev[i]; 1345 - if (!test_bit(R5_OVERWRITE, &dev->flags) 1346 - && !(failed == 0 && (i == pd_idx || i == qd_idx)) 1347 - && !test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_UPTODATE, &dev->flags) && 1348 - test_bit(R5_Insync, &dev->flags)) { 1349 - if (test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) 1350 - { 1351 - PRINTK("Read_old stripe %llu block %d for Reconstruct\n", 1352 - (unsigned long long)sh->sector, i); 1353 - set_bit(R5_LOCKED, &dev->flags); 1354 - set_bit(R5_Wantread, &dev->flags); 1355 - locked++; 1356 - } else { 1357 - PRINTK("Request delayed stripe %llu block %d for Reconstruct\n", 1358 - (unsigned long long)sh->sector, i); 1359 - set_bit(STRIPE_DELAYED, &sh->state); 1360 - set_bit(STRIPE_HANDLE, &sh->state); 1361 - } 1362 - } 1363 - } 1364 - /* now if nothing is locked, and if we have enough data, we can start a write request */ 1365 - if (locked == 0 && rcw == 0 && 1366 - !test_bit(STRIPE_BIT_DELAY, &sh->state)) { 1367 - if ( must_compute > 0 ) { 1368 - /* We have failed blocks and need to compute them */ 1369 - switch ( failed ) { 1370 - case 0: BUG(); 1371 - case 1: compute_block_1(sh, failed_num[0], 0); break; 1372 - case 2: compute_block_2(sh, failed_num[0], failed_num[1]); break; 1373 - default: BUG(); /* This request should have been failed? */ 1374 - } 1375 - } 1376 - 1377 - PRINTK("Computing parity for stripe %llu\n", (unsigned long long)sh->sector); 1378 - compute_parity(sh, RECONSTRUCT_WRITE); 1379 - /* now every locked buffer is ready to be written */ 1380 - for (i=disks; i--;) 1381 - if (test_bit(R5_LOCKED, &sh->dev[i].flags)) { 1382 - PRINTK("Writing stripe %llu block %d\n", 1383 - (unsigned long long)sh->sector, i); 1384 - locked++; 1385 - set_bit(R5_Wantwrite, &sh->dev[i].flags); 1386 - } 1387 - /* after a RECONSTRUCT_WRITE, the stripe MUST be in-sync */ 1388 - set_bit(STRIPE_INSYNC, &sh->state); 1389 - 1390 - if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { 1391 - atomic_dec(&conf->preread_active_stripes); 1392 - if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) 1393 - md_wakeup_thread(conf->mddev->thread); 1394 - } 1395 - } 1396 - } 1397 - 1398 - /* maybe we need to check and possibly fix the parity for this stripe 1399 - * Any reads will already have been scheduled, so we just see if enough data 1400 - * is available 1401 - */ 1402 - if (syncing && locked == 0 && !test_bit(STRIPE_INSYNC, &sh->state)) { 1403 - int update_p = 0, update_q = 0; 1404 - struct r5dev *dev; 1405 - 1406 - set_bit(STRIPE_HANDLE, &sh->state); 1407 - 1408 - BUG_ON(failed>2); 1409 - BUG_ON(uptodate < disks); 1410 - /* Want to check and possibly repair P and Q. 1411 - * However there could be one 'failed' device, in which 1412 - * case we can only check one of them, possibly using the 1413 - * other to generate missing data 1414 - */ 1415 - 1416 - /* If !tmp_page, we cannot do the calculations, 1417 - * but as we have set STRIPE_HANDLE, we will soon be called 1418 - * by stripe_handle with a tmp_page - just wait until then. 1419 - */ 1420 - if (tmp_page) { 1421 - if (failed == q_failed) { 1422 - /* The only possible failed device holds 'Q', so it makes 1423 - * sense to check P (If anything else were failed, we would 1424 - * have used P to recreate it). 1425 - */ 1426 - compute_block_1(sh, pd_idx, 1); 1427 - if (!page_is_zero(sh->dev[pd_idx].page)) { 1428 - compute_block_1(sh,pd_idx,0); 1429 - update_p = 1; 1430 - } 1431 - } 1432 - if (!q_failed && failed < 2) { 1433 - /* q is not failed, and we didn't use it to generate 1434 - * anything, so it makes sense to check it 1435 - */ 1436 - memcpy(page_address(tmp_page), 1437 - page_address(sh->dev[qd_idx].page), 1438 - STRIPE_SIZE); 1439 - compute_parity(sh, UPDATE_PARITY); 1440 - if (memcmp(page_address(tmp_page), 1441 - page_address(sh->dev[qd_idx].page), 1442 - STRIPE_SIZE)!= 0) { 1443 - clear_bit(STRIPE_INSYNC, &sh->state); 1444 - update_q = 1; 1445 - } 1446 - } 1447 - if (update_p || update_q) { 1448 - conf->mddev->resync_mismatches += STRIPE_SECTORS; 1449 - if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) 1450 - /* don't try to repair!! */ 1451 - update_p = update_q = 0; 1452 - } 1453 - 1454 - /* now write out any block on a failed drive, 1455 - * or P or Q if they need it 1456 - */ 1457 - 1458 - if (failed == 2) { 1459 - dev = &sh->dev[failed_num[1]]; 1460 - locked++; 1461 - set_bit(R5_LOCKED, &dev->flags); 1462 - set_bit(R5_Wantwrite, &dev->flags); 1463 - } 1464 - if (failed >= 1) { 1465 - dev = &sh->dev[failed_num[0]]; 1466 - locked++; 1467 - set_bit(R5_LOCKED, &dev->flags); 1468 - set_bit(R5_Wantwrite, &dev->flags); 1469 - } 1470 - 1471 - if (update_p) { 1472 - dev = &sh->dev[pd_idx]; 1473 - locked ++; 1474 - set_bit(R5_LOCKED, &dev->flags); 1475 - set_bit(R5_Wantwrite, &dev->flags); 1476 - } 1477 - if (update_q) { 1478 - dev = &sh->dev[qd_idx]; 1479 - locked++; 1480 - set_bit(R5_LOCKED, &dev->flags); 1481 - set_bit(R5_Wantwrite, &dev->flags); 1482 - } 1483 - clear_bit(STRIPE_DEGRADED, &sh->state); 1484 - 1485 - set_bit(STRIPE_INSYNC, &sh->state); 1486 - } 1487 - } 1488 - 1489 - if (syncing && locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) { 1490 - md_done_sync(conf->mddev, STRIPE_SECTORS,1); 1491 - clear_bit(STRIPE_SYNCING, &sh->state); 1492 - } 1493 - 1494 - /* If the failed drives are just a ReadError, then we might need 1495 - * to progress the repair/check process 1496 - */ 1497 - if (failed <= 2 && ! conf->mddev->ro) 1498 - for (i=0; i<failed;i++) { 1499 - dev = &sh->dev[failed_num[i]]; 1500 - if (test_bit(R5_ReadError, &dev->flags) 1501 - && !test_bit(R5_LOCKED, &dev->flags) 1502 - && test_bit(R5_UPTODATE, &dev->flags) 1503 - ) { 1504 - if (!test_bit(R5_ReWrite, &dev->flags)) { 1505 - set_bit(R5_Wantwrite, &dev->flags); 1506 - set_bit(R5_ReWrite, &dev->flags); 1507 - set_bit(R5_LOCKED, &dev->flags); 1508 - } else { 1509 - /* let's read it back */ 1510 - set_bit(R5_Wantread, &dev->flags); 1511 - set_bit(R5_LOCKED, &dev->flags); 1512 - } 1513 - } 1514 - } 1515 - spin_unlock(&sh->lock); 1516 - 1517 - while ((bi=return_bi)) { 1518 - int bytes = bi->bi_size; 1519 - 1520 - return_bi = bi->bi_next; 1521 - bi->bi_next = NULL; 1522 - bi->bi_size = 0; 1523 - bi->bi_end_io(bi, bytes, 0); 1524 - } 1525 - for (i=disks; i-- ;) { 1526 - int rw; 1527 - struct bio *bi; 1528 - mdk_rdev_t *rdev; 1529 - if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) 1530 - rw = 1; 1531 - else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) 1532 - rw = 0; 1533 - else 1534 - continue; 1535 - 1536 - bi = &sh->dev[i].req; 1537 - 1538 - bi->bi_rw = rw; 1539 - if (rw) 1540 - bi->bi_end_io = raid6_end_write_request; 1541 - else 1542 - bi->bi_end_io = raid6_end_read_request; 1543 - 1544 - rcu_read_lock(); 1545 - rdev = rcu_dereference(conf->disks[i].rdev); 1546 - if (rdev && test_bit(Faulty, &rdev->flags)) 1547 - rdev = NULL; 1548 - if (rdev) 1549 - atomic_inc(&rdev->nr_pending); 1550 - rcu_read_unlock(); 1551 - 1552 - if (rdev) { 1553 - if (syncing) 1554 - md_sync_acct(rdev->bdev, STRIPE_SECTORS); 1555 - 1556 - bi->bi_bdev = rdev->bdev; 1557 - PRINTK("for %llu schedule op %ld on disc %d\n", 1558 - (unsigned long long)sh->sector, bi->bi_rw, i); 1559 - atomic_inc(&sh->count); 1560 - bi->bi_sector = sh->sector + rdev->data_offset; 1561 - bi->bi_flags = 1 << BIO_UPTODATE; 1562 - bi->bi_vcnt = 1; 1563 - bi->bi_max_vecs = 1; 1564 - bi->bi_idx = 0; 1565 - bi->bi_io_vec = &sh->dev[i].vec; 1566 - bi->bi_io_vec[0].bv_len = STRIPE_SIZE; 1567 - bi->bi_io_vec[0].bv_offset = 0; 1568 - bi->bi_size = STRIPE_SIZE; 1569 - bi->bi_next = NULL; 1570 - if (rw == WRITE && 1571 - test_bit(R5_ReWrite, &sh->dev[i].flags)) 1572 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors); 1573 - generic_make_request(bi); 1574 - } else { 1575 - if (rw == 1) 1576 - set_bit(STRIPE_DEGRADED, &sh->state); 1577 - PRINTK("skip op %ld on disc %d for sector %llu\n", 1578 - bi->bi_rw, i, (unsigned long long)sh->sector); 1579 - clear_bit(R5_LOCKED, &sh->dev[i].flags); 1580 - set_bit(STRIPE_HANDLE, &sh->state); 1581 - } 1582 - } 1583 - } 1584 - 1585 - static void raid6_activate_delayed(raid6_conf_t *conf) 1586 - { 1587 - if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) { 1588 - while (!list_empty(&conf->delayed_list)) { 1589 - struct list_head *l = conf->delayed_list.next; 1590 - struct stripe_head *sh; 1591 - sh = list_entry(l, struct stripe_head, lru); 1592 - list_del_init(l); 1593 - clear_bit(STRIPE_DELAYED, &sh->state); 1594 - if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) 1595 - atomic_inc(&conf->preread_active_stripes); 1596 - list_add_tail(&sh->lru, &conf->handle_list); 1597 - } 1598 - } 1599 - } 1600 - 1601 - static void activate_bit_delay(raid6_conf_t *conf) 1602 - { 1603 - /* device_lock is held */ 1604 - struct list_head head; 1605 - list_add(&head, &conf->bitmap_list); 1606 - list_del_init(&conf->bitmap_list); 1607 - while (!list_empty(&head)) { 1608 - struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru); 1609 - list_del_init(&sh->lru); 1610 - atomic_inc(&sh->count); 1611 - __release_stripe(conf, sh); 1612 - } 1613 - } 1614 - 1615 - static void unplug_slaves(mddev_t *mddev) 1616 - { 1617 - raid6_conf_t *conf = mddev_to_conf(mddev); 1618 - int i; 1619 - 1620 - rcu_read_lock(); 1621 - for (i=0; i<mddev->raid_disks; i++) { 1622 - mdk_rdev_t *rdev = rcu_dereference(conf->disks[i].rdev); 1623 - if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) { 1624 - request_queue_t *r_queue = bdev_get_queue(rdev->bdev); 1625 - 1626 - atomic_inc(&rdev->nr_pending); 1627 - rcu_read_unlock(); 1628 - 1629 - if (r_queue->unplug_fn) 1630 - r_queue->unplug_fn(r_queue); 1631 - 1632 - rdev_dec_pending(rdev, mddev); 1633 - rcu_read_lock(); 1634 - } 1635 - } 1636 - rcu_read_unlock(); 1637 - } 1638 - 1639 - static void raid6_unplug_device(request_queue_t *q) 1640 - { 1641 - mddev_t *mddev = q->queuedata; 1642 - raid6_conf_t *conf = mddev_to_conf(mddev); 1643 - unsigned long flags; 1644 - 1645 - spin_lock_irqsave(&conf->device_lock, flags); 1646 - 1647 - if (blk_remove_plug(q)) { 1648 - conf->seq_flush++; 1649 - raid6_activate_delayed(conf); 1650 - } 1651 - md_wakeup_thread(mddev->thread); 1652 - 1653 - spin_unlock_irqrestore(&conf->device_lock, flags); 1654 - 1655 - unplug_slaves(mddev); 1656 - } 1657 - 1658 - static int raid6_issue_flush(request_queue_t *q, struct gendisk *disk, 1659 - sector_t *error_sector) 1660 - { 1661 - mddev_t *mddev = q->queuedata; 1662 - raid6_conf_t *conf = mddev_to_conf(mddev); 1663 - int i, ret = 0; 1664 - 1665 - rcu_read_lock(); 1666 - for (i=0; i<mddev->raid_disks && ret == 0; i++) { 1667 - mdk_rdev_t *rdev = rcu_dereference(conf->disks[i].rdev); 1668 - if (rdev && !test_bit(Faulty, &rdev->flags)) { 1669 - struct block_device *bdev = rdev->bdev; 1670 - request_queue_t *r_queue = bdev_get_queue(bdev); 1671 - 1672 - if (!r_queue->issue_flush_fn) 1673 - ret = -EOPNOTSUPP; 1674 - else { 1675 - atomic_inc(&rdev->nr_pending); 1676 - rcu_read_unlock(); 1677 - ret = r_queue->issue_flush_fn(r_queue, bdev->bd_disk, 1678 - error_sector); 1679 - rdev_dec_pending(rdev, mddev); 1680 - rcu_read_lock(); 1681 - } 1682 - } 1683 - } 1684 - rcu_read_unlock(); 1685 - return ret; 1686 - } 1687 - 1688 - static inline void raid6_plug_device(raid6_conf_t *conf) 1689 - { 1690 - spin_lock_irq(&conf->device_lock); 1691 - blk_plug_device(conf->mddev->queue); 1692 - spin_unlock_irq(&conf->device_lock); 1693 - } 1694 - 1695 - static int make_request (request_queue_t *q, struct bio * bi) 1696 - { 1697 - mddev_t *mddev = q->queuedata; 1698 - raid6_conf_t *conf = mddev_to_conf(mddev); 1699 - const unsigned int raid_disks = conf->raid_disks; 1700 - const unsigned int data_disks = raid_disks - 2; 1701 - unsigned int dd_idx, pd_idx; 1702 - sector_t new_sector; 1703 - sector_t logical_sector, last_sector; 1704 - struct stripe_head *sh; 1705 - const int rw = bio_data_dir(bi); 1706 - 1707 - if (unlikely(bio_barrier(bi))) { 1708 - bio_endio(bi, bi->bi_size, -EOPNOTSUPP); 1709 - return 0; 1710 - } 1711 - 1712 - md_write_start(mddev, bi); 1713 - 1714 - disk_stat_inc(mddev->gendisk, ios[rw]); 1715 - disk_stat_add(mddev->gendisk, sectors[rw], bio_sectors(bi)); 1716 - 1717 - logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1); 1718 - last_sector = bi->bi_sector + (bi->bi_size>>9); 1719 - 1720 - bi->bi_next = NULL; 1721 - bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ 1722 - 1723 - for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { 1724 - DEFINE_WAIT(w); 1725 - 1726 - new_sector = raid6_compute_sector(logical_sector, 1727 - raid_disks, data_disks, &dd_idx, &pd_idx, conf); 1728 - 1729 - PRINTK("raid6: make_request, sector %llu logical %llu\n", 1730 - (unsigned long long)new_sector, 1731 - (unsigned long long)logical_sector); 1732 - 1733 - retry: 1734 - prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE); 1735 - sh = get_active_stripe(conf, new_sector, pd_idx, (bi->bi_rw&RWA_MASK)); 1736 - if (sh) { 1737 - if (!add_stripe_bio(sh, bi, dd_idx, (bi->bi_rw&RW_MASK))) { 1738 - /* Add failed due to overlap. Flush everything 1739 - * and wait a while 1740 - */ 1741 - raid6_unplug_device(mddev->queue); 1742 - release_stripe(sh); 1743 - schedule(); 1744 - goto retry; 1745 - } 1746 - finish_wait(&conf->wait_for_overlap, &w); 1747 - raid6_plug_device(conf); 1748 - handle_stripe(sh, NULL); 1749 - release_stripe(sh); 1750 - } else { 1751 - /* cannot get stripe for read-ahead, just give-up */ 1752 - clear_bit(BIO_UPTODATE, &bi->bi_flags); 1753 - finish_wait(&conf->wait_for_overlap, &w); 1754 - break; 1755 - } 1756 - 1757 - } 1758 - spin_lock_irq(&conf->device_lock); 1759 - if (--bi->bi_phys_segments == 0) { 1760 - int bytes = bi->bi_size; 1761 - 1762 - if (rw == WRITE ) 1763 - md_write_end(mddev); 1764 - bi->bi_size = 0; 1765 - bi->bi_end_io(bi, bytes, 0); 1766 - } 1767 - spin_unlock_irq(&conf->device_lock); 1768 - return 0; 1769 - } 1770 - 1771 - /* FIXME go_faster isn't used */ 1772 - static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster) 1773 - { 1774 - raid6_conf_t *conf = (raid6_conf_t *) mddev->private; 1775 - struct stripe_head *sh; 1776 - int sectors_per_chunk = conf->chunk_size >> 9; 1777 - sector_t x; 1778 - unsigned long stripe; 1779 - int chunk_offset; 1780 - int dd_idx, pd_idx; 1781 - sector_t first_sector; 1782 - int raid_disks = conf->raid_disks; 1783 - int data_disks = raid_disks - 2; 1784 - sector_t max_sector = mddev->size << 1; 1785 - int sync_blocks; 1786 - int still_degraded = 0; 1787 - int i; 1788 - 1789 - if (sector_nr >= max_sector) { 1790 - /* just being told to finish up .. nothing much to do */ 1791 - unplug_slaves(mddev); 1792 - 1793 - if (mddev->curr_resync < max_sector) /* aborted */ 1794 - bitmap_end_sync(mddev->bitmap, mddev->curr_resync, 1795 - &sync_blocks, 1); 1796 - else /* completed sync */ 1797 - conf->fullsync = 0; 1798 - bitmap_close_sync(mddev->bitmap); 1799 - 1800 - return 0; 1801 - } 1802 - /* if there are 2 or more failed drives and we are trying 1803 - * to resync, then assert that we are finished, because there is 1804 - * nothing we can do. 1805 - */ 1806 - if (mddev->degraded >= 2 && test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { 1807 - sector_t rv = (mddev->size << 1) - sector_nr; 1808 - *skipped = 1; 1809 - return rv; 1810 - } 1811 - if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) && 1812 - !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) && 1813 - !conf->fullsync && sync_blocks >= STRIPE_SECTORS) { 1814 - /* we can skip this block, and probably more */ 1815 - sync_blocks /= STRIPE_SECTORS; 1816 - *skipped = 1; 1817 - return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */ 1818 - } 1819 - 1820 - x = sector_nr; 1821 - chunk_offset = sector_div(x, sectors_per_chunk); 1822 - stripe = x; 1823 - BUG_ON(x != stripe); 1824 - 1825 - first_sector = raid6_compute_sector((sector_t)stripe*data_disks*sectors_per_chunk 1826 - + chunk_offset, raid_disks, data_disks, &dd_idx, &pd_idx, conf); 1827 - sh = get_active_stripe(conf, sector_nr, pd_idx, 1); 1828 - if (sh == NULL) { 1829 - sh = get_active_stripe(conf, sector_nr, pd_idx, 0); 1830 - /* make sure we don't swamp the stripe cache if someone else 1831 - * is trying to get access 1832 - */ 1833 - schedule_timeout_uninterruptible(1); 1834 - } 1835 - /* Need to check if array will still be degraded after recovery/resync 1836 - * We don't need to check the 'failed' flag as when that gets set, 1837 - * recovery aborts. 1838 - */ 1839 - for (i=0; i<mddev->raid_disks; i++) 1840 - if (conf->disks[i].rdev == NULL) 1841 - still_degraded = 1; 1842 - 1843 - bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded); 1844 - 1845 - spin_lock(&sh->lock); 1846 - set_bit(STRIPE_SYNCING, &sh->state); 1847 - clear_bit(STRIPE_INSYNC, &sh->state); 1848 - spin_unlock(&sh->lock); 1849 - 1850 - handle_stripe(sh, NULL); 1851 - release_stripe(sh); 1852 - 1853 - return STRIPE_SECTORS; 1854 - } 1855 - 1856 - /* 1857 - * This is our raid6 kernel thread. 1858 - * 1859 - * We scan the hash table for stripes which can be handled now. 1860 - * During the scan, completed stripes are saved for us by the interrupt 1861 - * handler, so that they will not have to wait for our next wakeup. 1862 - */ 1863 - static void raid6d (mddev_t *mddev) 1864 - { 1865 - struct stripe_head *sh; 1866 - raid6_conf_t *conf = mddev_to_conf(mddev); 1867 - int handled; 1868 - 1869 - PRINTK("+++ raid6d active\n"); 1870 - 1871 - md_check_recovery(mddev); 1872 - 1873 - handled = 0; 1874 - spin_lock_irq(&conf->device_lock); 1875 - while (1) { 1876 - struct list_head *first; 1877 - 1878 - if (conf->seq_flush - conf->seq_write > 0) { 1879 - int seq = conf->seq_flush; 1880 - spin_unlock_irq(&conf->device_lock); 1881 - bitmap_unplug(mddev->bitmap); 1882 - spin_lock_irq(&conf->device_lock); 1883 - conf->seq_write = seq; 1884 - activate_bit_delay(conf); 1885 - } 1886 - 1887 - if (list_empty(&conf->handle_list) && 1888 - atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD && 1889 - !blk_queue_plugged(mddev->queue) && 1890 - !list_empty(&conf->delayed_list)) 1891 - raid6_activate_delayed(conf); 1892 - 1893 - if (list_empty(&conf->handle_list)) 1894 - break; 1895 - 1896 - first = conf->handle_list.next; 1897 - sh = list_entry(first, struct stripe_head, lru); 1898 - 1899 - list_del_init(first); 1900 - atomic_inc(&sh->count); 1901 - BUG_ON(atomic_read(&sh->count)!= 1); 1902 - spin_unlock_irq(&conf->device_lock); 1903 - 1904 - handled++; 1905 - handle_stripe(sh, conf->spare_page); 1906 - release_stripe(sh); 1907 - 1908 - spin_lock_irq(&conf->device_lock); 1909 - } 1910 - PRINTK("%d stripes handled\n", handled); 1911 - 1912 - spin_unlock_irq(&conf->device_lock); 1913 - 1914 - unplug_slaves(mddev); 1915 - 1916 - PRINTK("--- raid6d inactive\n"); 1917 - } 1918 - 1919 - static ssize_t 1920 - raid6_show_stripe_cache_size(mddev_t *mddev, char *page) 1921 - { 1922 - raid6_conf_t *conf = mddev_to_conf(mddev); 1923 - if (conf) 1924 - return sprintf(page, "%d\n", conf->max_nr_stripes); 1925 - else 1926 - return 0; 1927 - } 1928 - 1929 - static ssize_t 1930 - raid6_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len) 1931 - { 1932 - raid6_conf_t *conf = mddev_to_conf(mddev); 1933 - char *end; 1934 - int new; 1935 - if (len >= PAGE_SIZE) 1936 - return -EINVAL; 1937 - if (!conf) 1938 - return -ENODEV; 1939 - 1940 - new = simple_strtoul(page, &end, 10); 1941 - if (!*page || (*end && *end != '\n') ) 1942 - return -EINVAL; 1943 - if (new <= 16 || new > 32768) 1944 - return -EINVAL; 1945 - while (new < conf->max_nr_stripes) { 1946 - if (drop_one_stripe(conf)) 1947 - conf->max_nr_stripes--; 1948 - else 1949 - break; 1950 - } 1951 - while (new > conf->max_nr_stripes) { 1952 - if (grow_one_stripe(conf)) 1953 - conf->max_nr_stripes++; 1954 - else break; 1955 - } 1956 - return len; 1957 - } 1958 - 1959 - static struct md_sysfs_entry 1960 - raid6_stripecache_size = __ATTR(stripe_cache_size, S_IRUGO | S_IWUSR, 1961 - raid6_show_stripe_cache_size, 1962 - raid6_store_stripe_cache_size); 1963 - 1964 - static ssize_t 1965 - stripe_cache_active_show(mddev_t *mddev, char *page) 1966 - { 1967 - raid6_conf_t *conf = mddev_to_conf(mddev); 1968 - if (conf) 1969 - return sprintf(page, "%d\n", atomic_read(&conf->active_stripes)); 1970 - else 1971 - return 0; 1972 - } 1973 - 1974 - static struct md_sysfs_entry 1975 - raid6_stripecache_active = __ATTR_RO(stripe_cache_active); 1976 - 1977 - static struct attribute *raid6_attrs[] = { 1978 - &raid6_stripecache_size.attr, 1979 - &raid6_stripecache_active.attr, 1980 - NULL, 1981 - }; 1982 - static struct attribute_group raid6_attrs_group = { 1983 - .name = NULL, 1984 - .attrs = raid6_attrs, 1985 - }; 1986 - 1987 - static int run(mddev_t *mddev) 1988 - { 1989 - raid6_conf_t *conf; 1990 - int raid_disk, memory; 1991 - mdk_rdev_t *rdev; 1992 - struct disk_info *disk; 1993 - struct list_head *tmp; 1994 - 1995 - if (mddev->level != 6) { 1996 - PRINTK("raid6: %s: raid level not set to 6 (%d)\n", mdname(mddev), mddev->level); 1997 - return -EIO; 1998 - } 1999 - 2000 - mddev->private = kzalloc(sizeof (raid6_conf_t), GFP_KERNEL); 2001 - if ((conf = mddev->private) == NULL) 2002 - goto abort; 2003 - conf->disks = kzalloc(mddev->raid_disks * sizeof(struct disk_info), 2004 - GFP_KERNEL); 2005 - if (!conf->disks) 2006 - goto abort; 2007 - 2008 - conf->mddev = mddev; 2009 - 2010 - if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) 2011 - goto abort; 2012 - 2013 - conf->spare_page = alloc_page(GFP_KERNEL); 2014 - if (!conf->spare_page) 2015 - goto abort; 2016 - 2017 - spin_lock_init(&conf->device_lock); 2018 - init_waitqueue_head(&conf->wait_for_stripe); 2019 - init_waitqueue_head(&conf->wait_for_overlap); 2020 - INIT_LIST_HEAD(&conf->handle_list); 2021 - INIT_LIST_HEAD(&conf->delayed_list); 2022 - INIT_LIST_HEAD(&conf->bitmap_list); 2023 - INIT_LIST_HEAD(&conf->inactive_list); 2024 - atomic_set(&conf->active_stripes, 0); 2025 - atomic_set(&conf->preread_active_stripes, 0); 2026 - 2027 - PRINTK("raid6: run(%s) called.\n", mdname(mddev)); 2028 - 2029 - ITERATE_RDEV(mddev,rdev,tmp) { 2030 - raid_disk = rdev->raid_disk; 2031 - if (raid_disk >= mddev->raid_disks 2032 - || raid_disk < 0) 2033 - continue; 2034 - disk = conf->disks + raid_disk; 2035 - 2036 - disk->rdev = rdev; 2037 - 2038 - if (test_bit(In_sync, &rdev->flags)) { 2039 - char b[BDEVNAME_SIZE]; 2040 - printk(KERN_INFO "raid6: device %s operational as raid" 2041 - " disk %d\n", bdevname(rdev->bdev,b), 2042 - raid_disk); 2043 - conf->working_disks++; 2044 - } 2045 - } 2046 - 2047 - conf->raid_disks = mddev->raid_disks; 2048 - 2049 - /* 2050 - * 0 for a fully functional array, 1 or 2 for a degraded array. 2051 - */ 2052 - mddev->degraded = conf->failed_disks = conf->raid_disks - conf->working_disks; 2053 - conf->mddev = mddev; 2054 - conf->chunk_size = mddev->chunk_size; 2055 - conf->level = mddev->level; 2056 - conf->algorithm = mddev->layout; 2057 - conf->max_nr_stripes = NR_STRIPES; 2058 - 2059 - /* device size must be a multiple of chunk size */ 2060 - mddev->size &= ~(mddev->chunk_size/1024 -1); 2061 - mddev->resync_max_sectors = mddev->size << 1; 2062 - 2063 - if (conf->raid_disks < 4) { 2064 - printk(KERN_ERR "raid6: not enough configured devices for %s (%d, minimum 4)\n", 2065 - mdname(mddev), conf->raid_disks); 2066 - goto abort; 2067 - } 2068 - if (!conf->chunk_size || conf->chunk_size % 4) { 2069 - printk(KERN_ERR "raid6: invalid chunk size %d for %s\n", 2070 - conf->chunk_size, mdname(mddev)); 2071 - goto abort; 2072 - } 2073 - if (conf->algorithm > ALGORITHM_RIGHT_SYMMETRIC) { 2074 - printk(KERN_ERR 2075 - "raid6: unsupported parity algorithm %d for %s\n", 2076 - conf->algorithm, mdname(mddev)); 2077 - goto abort; 2078 - } 2079 - if (mddev->degraded > 2) { 2080 - printk(KERN_ERR "raid6: not enough operational devices for %s" 2081 - " (%d/%d failed)\n", 2082 - mdname(mddev), conf->failed_disks, conf->raid_disks); 2083 - goto abort; 2084 - } 2085 - 2086 - if (mddev->degraded > 0 && 2087 - mddev->recovery_cp != MaxSector) { 2088 - if (mddev->ok_start_degraded) 2089 - printk(KERN_WARNING "raid6: starting dirty degraded array:%s" 2090 - "- data corruption possible.\n", 2091 - mdname(mddev)); 2092 - else { 2093 - printk(KERN_ERR "raid6: cannot start dirty degraded array" 2094 - " for %s\n", mdname(mddev)); 2095 - goto abort; 2096 - } 2097 - } 2098 - 2099 - { 2100 - mddev->thread = md_register_thread(raid6d, mddev, "%s_raid6"); 2101 - if (!mddev->thread) { 2102 - printk(KERN_ERR 2103 - "raid6: couldn't allocate thread for %s\n", 2104 - mdname(mddev)); 2105 - goto abort; 2106 - } 2107 - } 2108 - 2109 - memory = conf->max_nr_stripes * (sizeof(struct stripe_head) + 2110 - conf->raid_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; 2111 - if (grow_stripes(conf, conf->max_nr_stripes)) { 2112 - printk(KERN_ERR 2113 - "raid6: couldn't allocate %dkB for buffers\n", memory); 2114 - shrink_stripes(conf); 2115 - md_unregister_thread(mddev->thread); 2116 - goto abort; 2117 - } else 2118 - printk(KERN_INFO "raid6: allocated %dkB for %s\n", 2119 - memory, mdname(mddev)); 2120 - 2121 - if (mddev->degraded == 0) 2122 - printk(KERN_INFO "raid6: raid level %d set %s active with %d out of %d" 2123 - " devices, algorithm %d\n", conf->level, mdname(mddev), 2124 - mddev->raid_disks-mddev->degraded, mddev->raid_disks, 2125 - conf->algorithm); 2126 - else 2127 - printk(KERN_ALERT "raid6: raid level %d set %s active with %d" 2128 - " out of %d devices, algorithm %d\n", conf->level, 2129 - mdname(mddev), mddev->raid_disks - mddev->degraded, 2130 - mddev->raid_disks, conf->algorithm); 2131 - 2132 - print_raid6_conf(conf); 2133 - 2134 - /* read-ahead size must cover two whole stripes, which is 2135 - * 2 * (n-2) * chunksize where 'n' is the number of raid devices 2136 - */ 2137 - { 2138 - int stripe = (mddev->raid_disks-2) * 2139 - (mddev->chunk_size / PAGE_SIZE); 2140 - if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe) 2141 - mddev->queue->backing_dev_info.ra_pages = 2 * stripe; 2142 - } 2143 - 2144 - /* Ok, everything is just fine now */ 2145 - sysfs_create_group(&mddev->kobj, &raid6_attrs_group); 2146 - 2147 - mddev->array_size = mddev->size * (mddev->raid_disks - 2); 2148 - 2149 - mddev->queue->unplug_fn = raid6_unplug_device; 2150 - mddev->queue->issue_flush_fn = raid6_issue_flush; 2151 - return 0; 2152 - abort: 2153 - if (conf) { 2154 - print_raid6_conf(conf); 2155 - safe_put_page(conf->spare_page); 2156 - kfree(conf->stripe_hashtbl); 2157 - kfree(conf->disks); 2158 - kfree(conf); 2159 - } 2160 - mddev->private = NULL; 2161 - printk(KERN_ALERT "raid6: failed to run raid set %s\n", mdname(mddev)); 2162 - return -EIO; 2163 - } 2164 - 2165 - 2166 - 2167 - static int stop (mddev_t *mddev) 2168 - { 2169 - raid6_conf_t *conf = (raid6_conf_t *) mddev->private; 2170 - 2171 - md_unregister_thread(mddev->thread); 2172 - mddev->thread = NULL; 2173 - shrink_stripes(conf); 2174 - kfree(conf->stripe_hashtbl); 2175 - blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ 2176 - sysfs_remove_group(&mddev->kobj, &raid6_attrs_group); 2177 - kfree(conf); 2178 - mddev->private = NULL; 2179 - return 0; 2180 - } 2181 - 2182 - #if RAID6_DUMPSTATE 2183 - static void print_sh (struct seq_file *seq, struct stripe_head *sh) 2184 - { 2185 - int i; 2186 - 2187 - seq_printf(seq, "sh %llu, pd_idx %d, state %ld.\n", 2188 - (unsigned long long)sh->sector, sh->pd_idx, sh->state); 2189 - seq_printf(seq, "sh %llu, count %d.\n", 2190 - (unsigned long long)sh->sector, atomic_read(&sh->count)); 2191 - seq_printf(seq, "sh %llu, ", (unsigned long long)sh->sector); 2192 - for (i = 0; i < sh->raid_conf->raid_disks; i++) { 2193 - seq_printf(seq, "(cache%d: %p %ld) ", 2194 - i, sh->dev[i].page, sh->dev[i].flags); 2195 - } 2196 - seq_printf(seq, "\n"); 2197 - } 2198 - 2199 - static void printall (struct seq_file *seq, raid6_conf_t *conf) 2200 - { 2201 - struct stripe_head *sh; 2202 - struct hlist_node *hn; 2203 - int i; 2204 - 2205 - spin_lock_irq(&conf->device_lock); 2206 - for (i = 0; i < NR_HASH; i++) { 2207 - sh = conf->stripe_hashtbl[i]; 2208 - hlist_for_each_entry(sh, hn, &conf->stripe_hashtbl[i], hash) { 2209 - if (sh->raid_conf != conf) 2210 - continue; 2211 - print_sh(seq, sh); 2212 - } 2213 - } 2214 - spin_unlock_irq(&conf->device_lock); 2215 - } 2216 - #endif 2217 - 2218 - static void status (struct seq_file *seq, mddev_t *mddev) 2219 - { 2220 - raid6_conf_t *conf = (raid6_conf_t *) mddev->private; 2221 - int i; 2222 - 2223 - seq_printf (seq, " level %d, %dk chunk, algorithm %d", mddev->level, mddev->chunk_size >> 10, mddev->layout); 2224 - seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->working_disks); 2225 - for (i = 0; i < conf->raid_disks; i++) 2226 - seq_printf (seq, "%s", 2227 - conf->disks[i].rdev && 2228 - test_bit(In_sync, &conf->disks[i].rdev->flags) ? "U" : "_"); 2229 - seq_printf (seq, "]"); 2230 - #if RAID6_DUMPSTATE 2231 - seq_printf (seq, "\n"); 2232 - printall(seq, conf); 2233 - #endif 2234 - } 2235 - 2236 - static void print_raid6_conf (raid6_conf_t *conf) 2237 - { 2238 - int i; 2239 - struct disk_info *tmp; 2240 - 2241 - printk("RAID6 conf printout:\n"); 2242 - if (!conf) { 2243 - printk("(conf==NULL)\n"); 2244 - return; 2245 - } 2246 - printk(" --- rd:%d wd:%d fd:%d\n", conf->raid_disks, 2247 - conf->working_disks, conf->failed_disks); 2248 - 2249 - for (i = 0; i < conf->raid_disks; i++) { 2250 - char b[BDEVNAME_SIZE]; 2251 - tmp = conf->disks + i; 2252 - if (tmp->rdev) 2253 - printk(" disk %d, o:%d, dev:%s\n", 2254 - i, !test_bit(Faulty, &tmp->rdev->flags), 2255 - bdevname(tmp->rdev->bdev,b)); 2256 - } 2257 - } 2258 - 2259 - static int raid6_spare_active(mddev_t *mddev) 2260 - { 2261 - int i; 2262 - raid6_conf_t *conf = mddev->private; 2263 - struct disk_info *tmp; 2264 - 2265 - for (i = 0; i < conf->raid_disks; i++) { 2266 - tmp = conf->disks + i; 2267 - if (tmp->rdev 2268 - && !test_bit(Faulty, &tmp->rdev->flags) 2269 - && !test_bit(In_sync, &tmp->rdev->flags)) { 2270 - mddev->degraded--; 2271 - conf->failed_disks--; 2272 - conf->working_disks++; 2273 - set_bit(In_sync, &tmp->rdev->flags); 2274 - } 2275 - } 2276 - print_raid6_conf(conf); 2277 - return 0; 2278 - } 2279 - 2280 - static int raid6_remove_disk(mddev_t *mddev, int number) 2281 - { 2282 - raid6_conf_t *conf = mddev->private; 2283 - int err = 0; 2284 - mdk_rdev_t *rdev; 2285 - struct disk_info *p = conf->disks + number; 2286 - 2287 - print_raid6_conf(conf); 2288 - rdev = p->rdev; 2289 - if (rdev) { 2290 - if (test_bit(In_sync, &rdev->flags) || 2291 - atomic_read(&rdev->nr_pending)) { 2292 - err = -EBUSY; 2293 - goto abort; 2294 - } 2295 - p->rdev = NULL; 2296 - synchronize_rcu(); 2297 - if (atomic_read(&rdev->nr_pending)) { 2298 - /* lost the race, try later */ 2299 - err = -EBUSY; 2300 - p->rdev = rdev; 2301 - } 2302 - } 2303 - 2304 - abort: 2305 - 2306 - print_raid6_conf(conf); 2307 - return err; 2308 - } 2309 - 2310 - static int raid6_add_disk(mddev_t *mddev, mdk_rdev_t *rdev) 2311 - { 2312 - raid6_conf_t *conf = mddev->private; 2313 - int found = 0; 2314 - int disk; 2315 - struct disk_info *p; 2316 - 2317 - if (mddev->degraded > 2) 2318 - /* no point adding a device */ 2319 - return 0; 2320 - /* 2321 - * find the disk ... but prefer rdev->saved_raid_disk 2322 - * if possible. 2323 - */ 2324 - if (rdev->saved_raid_disk >= 0 && 2325 - conf->disks[rdev->saved_raid_disk].rdev == NULL) 2326 - disk = rdev->saved_raid_disk; 2327 - else 2328 - disk = 0; 2329 - for ( ; disk < mddev->raid_disks; disk++) 2330 - if ((p=conf->disks + disk)->rdev == NULL) { 2331 - clear_bit(In_sync, &rdev->flags); 2332 - rdev->raid_disk = disk; 2333 - found = 1; 2334 - if (rdev->saved_raid_disk != disk) 2335 - conf->fullsync = 1; 2336 - rcu_assign_pointer(p->rdev, rdev); 2337 - break; 2338 - } 2339 - print_raid6_conf(conf); 2340 - return found; 2341 - } 2342 - 2343 - static int raid6_resize(mddev_t *mddev, sector_t sectors) 2344 - { 2345 - /* no resync is happening, and there is enough space 2346 - * on all devices, so we can resize. 2347 - * We need to make sure resync covers any new space. 2348 - * If the array is shrinking we should possibly wait until 2349 - * any io in the removed space completes, but it hardly seems 2350 - * worth it. 2351 - */ 2352 - sectors &= ~((sector_t)mddev->chunk_size/512 - 1); 2353 - mddev->array_size = (sectors * (mddev->raid_disks-2))>>1; 2354 - set_capacity(mddev->gendisk, mddev->array_size << 1); 2355 - mddev->changed = 1; 2356 - if (sectors/2 > mddev->size && mddev->recovery_cp == MaxSector) { 2357 - mddev->recovery_cp = mddev->size << 1; 2358 - set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 2359 - } 2360 - mddev->size = sectors /2; 2361 - mddev->resync_max_sectors = sectors; 2362 - return 0; 2363 - } 2364 - 2365 - static void raid6_quiesce(mddev_t *mddev, int state) 2366 - { 2367 - raid6_conf_t *conf = mddev_to_conf(mddev); 2368 - 2369 - switch(state) { 2370 - case 1: /* stop all writes */ 2371 - spin_lock_irq(&conf->device_lock); 2372 - conf->quiesce = 1; 2373 - wait_event_lock_irq(conf->wait_for_stripe, 2374 - atomic_read(&conf->active_stripes) == 0, 2375 - conf->device_lock, /* nothing */); 2376 - spin_unlock_irq(&conf->device_lock); 2377 - break; 2378 - 2379 - case 0: /* re-enable writes */ 2380 - spin_lock_irq(&conf->device_lock); 2381 - conf->quiesce = 0; 2382 - wake_up(&conf->wait_for_stripe); 2383 - spin_unlock_irq(&conf->device_lock); 2384 - break; 2385 - } 2386 - } 2387 - 2388 - static struct mdk_personality raid6_personality = 2389 - { 2390 - .name = "raid6", 2391 - .level = 6, 2392 - .owner = THIS_MODULE, 2393 - .make_request = make_request, 2394 - .run = run, 2395 - .stop = stop, 2396 - .status = status, 2397 - .error_handler = error, 2398 - .hot_add_disk = raid6_add_disk, 2399 - .hot_remove_disk= raid6_remove_disk, 2400 - .spare_active = raid6_spare_active, 2401 - .sync_request = sync_request, 2402 - .resize = raid6_resize, 2403 - .quiesce = raid6_quiesce, 2404 - }; 2405 - 2406 - static int __init raid6_init(void) 2407 - { 2408 - int e; 2409 - 2410 - e = raid6_select_algo(); 2411 - if ( e ) 2412 - return e; 2413 - 2414 - return register_md_personality(&raid6_personality); 2415 - } 2416 - 2417 - static void raid6_exit (void) 2418 - { 2419 - unregister_md_personality(&raid6_personality); 2420 - } 2421 - 2422 - module_init(raid6_init); 2423 - module_exit(raid6_exit); 2424 - MODULE_LICENSE("GPL"); 2425 - MODULE_ALIAS("md-personality-8"); /* RAID6 */ 2426 - MODULE_ALIAS("md-raid6"); 2427 - MODULE_ALIAS("md-level-6");
+1
include/linux/raid/raid5.h
··· 212 212 mddev_t *mddev; 213 213 struct disk_info *spare; 214 214 int chunk_size, level, algorithm; 215 + int max_degraded; 215 216 int raid_disks, working_disks, failed_disks; 216 217 int max_nr_stripes; 217 218