1 From 67cc2b8165857ba019920d1f00d64bcc4140075d Mon Sep 17 00:00:00 2001
2 From: NeilBrown <neilb@suse.de>
3 Date: Tue, 31 Mar 2009 14:39:38 +1100
4 Subject: [PATCH] md/raid5: finish support for DDF/raid6
6 DDF requires RAID6 calculations over different devices in a different
8 For md/raid6, we calculate over just the data devices, starting
9 immediately after the 'Q' block.
10 For ddf/raid6 we calculate over all devices, using zeros in place of
13 This requires unfortunately complex loops...
15 Signed-off-by: NeilBrown <neilb@suse.de>
17 drivers/md/raid5.c | 58 +++++++++++++++++++++++++++++++--------------
18 include/linux/raid/raid5.h | 1
19 2 files changed, 41 insertions(+), 18 deletions(-)
21 --- linux-2.6.27-SLE11_BRANCH.orig/drivers/md/raid5.c
22 +++ linux-2.6.27-SLE11_BRANCH/drivers/md/raid5.c
23 @@ -138,6 +138,10 @@ static inline void raid5_set_bi_hw_segme
24 /* Find first data disk in a raid6 stripe */
25 static inline int raid6_d0(struct stripe_head *sh)
28 + /* ddf always start from first device */
30 + /* md starts just after Q block */
31 if (sh->qd_idx == sh->disks - 1)
34 @@ -154,13 +158,15 @@ static inline int raid6_next_disk(int di
35 * 0 .. raid_disks-3, the parity disk is raid_disks-2 and the Q disk
36 * is raid_disks-1. This help does that mapping.
38 -static int raid6_idx_to_slot(int idx, struct stripe_head *sh, int *count)
39 +static int raid6_idx_to_slot(int idx, struct stripe_head *sh,
40 + int *count, int syndrome_disks)
44 if (idx == sh->pd_idx)
45 - return sh->disks - 2;
46 + return syndrome_disks;
47 if (idx == sh->qd_idx)
48 - return sh->disks - 1;
49 + return syndrome_disks + 1;
53 @@ -1269,6 +1275,7 @@ static sector_t raid5_compute_sector(rai
54 unsigned long chunk_number;
55 unsigned int chunk_offset;
59 int sectors_per_chunk = conf->chunk_size >> 9;
60 int raid_disks = previous ? conf->previous_raid_disks
61 @@ -1388,6 +1395,7 @@ static sector_t raid5_compute_sector(rai
63 } else if (*dd_idx >= pd_idx)
64 (*dd_idx) += 2; /* D D P Q D */
68 case ALGORITHM_ROTATING_N_RESTART:
69 @@ -1402,6 +1410,7 @@ static sector_t raid5_compute_sector(rai
71 } else if (*dd_idx >= pd_idx)
72 (*dd_idx) += 2; /* D D P Q D */
76 case ALGORITHM_ROTATING_N_CONTINUE:
77 @@ -1409,6 +1418,7 @@ static sector_t raid5_compute_sector(rai
78 pd_idx = raid_disks - 1 - (stripe % raid_disks);
79 qd_idx = (pd_idx + raid_disks - 1) % raid_disks;
80 *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks;
84 case ALGORITHM_LEFT_ASYMMETRIC_6:
85 @@ -1456,6 +1466,7 @@ static sector_t raid5_compute_sector(rai
89 + sh->ddf_layout = ddf_layout;
92 * Finally, compute the new sector number
93 @@ -1644,9 +1655,10 @@ static void compute_parity6(struct strip
95 raid6_conf_t *conf = sh->raid_conf;
96 int i, pd_idx, qd_idx, d0_idx, disks = sh->disks, count;
97 + int syndrome_disks = sh->ddf_layout ? disks : (disks - 2);
99 /**** FIX THIS: This could be very bad if disks is close to 256 ****/
101 + void *ptrs[syndrome_disks+2];
105 @@ -1689,23 +1701,28 @@ static void compute_parity6(struct strip
108 /* Note that unlike RAID-5, the ordering of the disks matters greatly.*/
109 - /* FIX: Is this ordering of drives even remotely optimal? */
111 + for (i = 0; i < disks; i++)
112 + ptrs[i] = (void *)raid6_empty_zero_page;
117 - int slot = raid6_idx_to_slot(i, sh, &count);
118 + int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks);
120 ptrs[slot] = page_address(sh->dev[i].page);
121 - if (slot < sh->disks - 2 &&
122 + if (slot < syndrome_disks &&
123 !test_bit(R5_UPTODATE, &sh->dev[i].flags)) {
124 printk(KERN_ERR "block %d/%d not uptodate "
125 "on parity calc\n", i, count);
129 i = raid6_next_disk(i, disks);
130 } while (i != d0_idx);
131 - BUG_ON(count+2 != disks);
132 + BUG_ON(count != syndrome_disks);
134 - raid6_call.gen_syndrome(disks, STRIPE_SIZE, ptrs);
135 + raid6_call.gen_syndrome(syndrome_disks+2, STRIPE_SIZE, ptrs);
138 case RECONSTRUCT_WRITE:
139 @@ -1763,24 +1780,28 @@ static void compute_block_1(struct strip
140 static void compute_block_2(struct stripe_head *sh, int dd_idx1, int dd_idx2)
142 int i, count, disks = sh->disks;
143 + int syndrome_disks = sh->ddf_layout ? disks : disks-2;
144 int d0_idx = raid6_d0(sh);
145 int faila = -1, failb = -1;
146 /**** FIX THIS: This could be very bad if disks is close to 256 ****/
148 + void *ptrs[syndrome_disks+2];
150 + for (i = 0; i < disks ; i++)
151 + ptrs[i] = (void *)raid6_empty_zero_page;
156 - slot = raid6_idx_to_slot(i, sh, &count);
157 + int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks);
159 ptrs[slot] = page_address(sh->dev[i].page);
165 i = raid6_next_disk(i, disks);
166 } while (i != d0_idx);
167 - BUG_ON(count+2 != disks);
168 + BUG_ON(count != syndrome_disks);
170 BUG_ON(faila == failb);
171 if ( failb < faila ) { int tmp = faila; faila = failb; failb = tmp; }
172 @@ -1789,9 +1810,9 @@ static void compute_block_2(struct strip
173 (unsigned long long)sh->sector, dd_idx1, dd_idx2,
176 - if ( failb == disks-1 ) {
177 + if (failb == syndrome_disks+1) {
178 /* Q disk is one of the missing disks */
179 - if ( faila == disks-2 ) {
180 + if (faila == syndrome_disks) {
181 /* Missing P+Q, just recompute */
182 compute_parity6(sh, UPDATE_PARITY);
184 @@ -1806,12 +1827,13 @@ static void compute_block_2(struct strip
187 /* We're missing D+P or D+D; */
188 - if (failb == disks-2) {
189 + if (failb == syndrome_disks) {
190 /* We're missing D+P. */
191 - raid6_datap_recov(disks, STRIPE_SIZE, faila, ptrs);
192 + raid6_datap_recov(syndrome_disks+2, STRIPE_SIZE, faila, ptrs);
194 /* We're missing D+D. */
195 - raid6_2data_recov(disks, STRIPE_SIZE, faila, failb, ptrs);
196 + raid6_2data_recov(syndrome_disks+2, STRIPE_SIZE, faila, failb,
200 /* Both the above update both missing blocks */
201 --- linux-2.6.27-SLE11_BRANCH.orig/include/linux/raid/raid5.h
202 +++ linux-2.6.27-SLE11_BRANCH/include/linux/raid/raid5.h
203 @@ -202,6 +202,7 @@ struct stripe_head {
204 sector_t sector; /* sector of this row */
205 short pd_idx; /* parity disk index */
206 short qd_idx; /* 'Q' disk index for raid6 */
207 + short ddf_layout;/* use DDF ordering to calculate Q */
208 unsigned long state; /* state flags */
209 atomic_t count; /* nr of active thread/requests */