@@ -131,8 +131,8 @@ async_mult(struct page *dest, struct page *src, u8 coef, size_t len,
131131}
132132
133133static struct dma_async_tx_descriptor *
134- __2data_recov_4 (size_t bytes , int faila , int failb , struct page * * blocks ,
135- struct async_submit_ctl * submit )
134+ __2data_recov_4 (int disks , size_t bytes , int faila , int failb ,
135+ struct page * * blocks , struct async_submit_ctl * submit )
136136{
137137 struct dma_async_tx_descriptor * tx = NULL ;
138138 struct page * p , * q , * a , * b ;
@@ -143,8 +143,8 @@ __2data_recov_4(size_t bytes, int faila, int failb, struct page **blocks,
143143 void * cb_param = submit -> cb_param ;
144144 void * scribble = submit -> scribble ;
145145
146- p = blocks [4 - 2 ];
147- q = blocks [4 - 1 ];
146+ p = blocks [disks - 2 ];
147+ q = blocks [disks - 1 ];
148148
149149 a = blocks [faila ];
150150 b = blocks [failb ];
@@ -170,8 +170,8 @@ __2data_recov_4(size_t bytes, int faila, int failb, struct page **blocks,
170170}
171171
172172static struct dma_async_tx_descriptor *
173- __2data_recov_5 (size_t bytes , int faila , int failb , struct page * * blocks ,
174- struct async_submit_ctl * submit )
173+ __2data_recov_5 (int disks , size_t bytes , int faila , int failb ,
174+ struct page * * blocks , struct async_submit_ctl * submit )
175175{
176176 struct dma_async_tx_descriptor * tx = NULL ;
177177 struct page * p , * q , * g , * dp , * dq ;
@@ -181,21 +181,22 @@ __2data_recov_5(size_t bytes, int faila, int failb, struct page **blocks,
181181 dma_async_tx_callback cb_fn = submit -> cb_fn ;
182182 void * cb_param = submit -> cb_param ;
183183 void * scribble = submit -> scribble ;
184- int uninitialized_var (good );
185- int i ;
184+ int good_srcs , good , i ;
186185
187- for (i = 0 ; i < 3 ; i ++ ) {
186+ good_srcs = 0 ;
187+ good = -1 ;
188+ for (i = 0 ; i < disks - 2 ; i ++ ) {
189+ if (blocks [i ] == NULL )
190+ continue ;
188191 if (i == faila || i == failb )
189192 continue ;
190- else {
191- good = i ;
192- break ;
193- }
193+ good = i ;
194+ good_srcs ++ ;
194195 }
195- BUG_ON (i >= 3 );
196+ BUG_ON (good_srcs > 1 );
196197
197- p = blocks [5 - 2 ];
198- q = blocks [5 - 1 ];
198+ p = blocks [disks - 2 ];
199+ q = blocks [disks - 1 ];
199200 g = blocks [good ];
200201
201202 /* Compute syndrome with zero for the missing data pages
@@ -323,6 +324,8 @@ struct dma_async_tx_descriptor *
323324async_raid6_2data_recov (int disks , size_t bytes , int faila , int failb ,
324325 struct page * * blocks , struct async_submit_ctl * submit )
325326{
327+ int non_zero_srcs , i ;
328+
326329 BUG_ON (faila == failb );
327330 if (failb < faila )
328331 swap (faila , failb );
@@ -334,12 +337,11 @@ async_raid6_2data_recov(int disks, size_t bytes, int faila, int failb,
334337 */
335338 if (!submit -> scribble ) {
336339 void * * ptrs = (void * * ) blocks ;
337- int i ;
338340
339341 async_tx_quiesce (& submit -> depend_tx );
340342 for (i = 0 ; i < disks ; i ++ )
341343 if (blocks [i ] == NULL )
342- ptrs [i ] = (void * ) raid6_empty_zero_page ;
344+ ptrs [i ] = (void * ) raid6_empty_zero_page ;
343345 else
344346 ptrs [i ] = page_address (blocks [i ]);
345347
@@ -350,19 +352,30 @@ async_raid6_2data_recov(int disks, size_t bytes, int faila, int failb,
350352 return NULL ;
351353 }
352354
353- switch (disks ) {
354- case 4 :
355+ non_zero_srcs = 0 ;
356+ for (i = 0 ; i < disks - 2 && non_zero_srcs < 4 ; i ++ )
357+ if (blocks [i ])
358+ non_zero_srcs ++ ;
359+ switch (non_zero_srcs ) {
360+ case 0 :
361+ case 1 :
362+ /* There must be at least 2 sources - the failed devices. */
363+ BUG ();
364+
365+ case 2 :
355366 /* dma devices do not uniformly understand a zero source pq
356367 * operation (in contrast to the synchronous case), so
357- * explicitly handle the 4 disk special case
368+ * explicitly handle the special case of a 4 disk array with
369+ * both data disks missing.
358370 */
359- return __2data_recov_4 (bytes , faila , failb , blocks , submit );
360- case 5 :
371+ return __2data_recov_4 (disks , bytes , faila , failb , blocks , submit );
372+ case 3 :
361373 /* dma devices do not uniformly understand a single
362374 * source pq operation (in contrast to the synchronous
363- * case), so explicitly handle the 5 disk special case
375+ * case), so explicitly handle the special case of a 5 disk
376+ * array with 2 of 3 data disks missing.
364377 */
365- return __2data_recov_5 (bytes , faila , failb , blocks , submit );
378+ return __2data_recov_5 (disks , bytes , faila , failb , blocks , submit );
366379 default :
367380 return __2data_recov_n (disks , bytes , faila , failb , blocks , submit );
368381 }
@@ -388,6 +401,7 @@ async_raid6_datap_recov(int disks, size_t bytes, int faila,
388401 dma_async_tx_callback cb_fn = submit -> cb_fn ;
389402 void * cb_param = submit -> cb_param ;
390403 void * scribble = submit -> scribble ;
404+ int good_srcs , good , i ;
391405 struct page * srcs [2 ];
392406
393407 pr_debug ("%s: disks: %d len: %zu\n" , __func__ , disks , bytes );
@@ -397,7 +411,6 @@ async_raid6_datap_recov(int disks, size_t bytes, int faila,
397411 */
398412 if (!scribble ) {
399413 void * * ptrs = (void * * ) blocks ;
400- int i ;
401414
402415 async_tx_quiesce (& submit -> depend_tx );
403416 for (i = 0 ; i < disks ; i ++ )
@@ -413,6 +426,20 @@ async_raid6_datap_recov(int disks, size_t bytes, int faila,
413426 return NULL ;
414427 }
415428
429+ good_srcs = 0 ;
430+ good = -1 ;
431+ for (i = 0 ; i < disks - 2 ; i ++ ) {
432+ if (i == faila )
433+ continue ;
434+ if (blocks [i ]) {
435+ good = i ;
436+ good_srcs ++ ;
437+ if (good_srcs > 1 )
438+ break ;
439+ }
440+ }
441+ BUG_ON (good_srcs == 0 );
442+
416443 p = blocks [disks - 2 ];
417444 q = blocks [disks - 1 ];
418445
@@ -423,11 +450,10 @@ async_raid6_datap_recov(int disks, size_t bytes, int faila,
423450 blocks [faila ] = NULL ;
424451 blocks [disks - 1 ] = dq ;
425452
426- /* in the 4 disk case we only need to perform a single source
427- * multiplication
453+ /* in the 4- disk case we only need to perform a single source
454+ * multiplication with the one good data block.
428455 */
429- if (disks == 4 ) {
430- int good = faila == 0 ? 1 : 0 ;
456+ if (good_srcs == 1 ) {
431457 struct page * g = blocks [good ];
432458
433459 init_async_submit (submit , ASYNC_TX_FENCE , tx , NULL , NULL ,
0 commit comments