@@ -1317,7 +1317,9 @@ ops_run_compute5(struct stripe_head *sh, struct raid5_percpu *percpu)
13171317 * destination buffer is recorded in srcs[count] and the Q destination
13181318 * is recorded in srcs[count+1]].
13191319 */
1320- static int set_syndrome_sources (struct page * * srcs , struct stripe_head * sh )
1320+ static int set_syndrome_sources (struct page * * srcs ,
1321+ struct stripe_head * sh ,
1322+ int srctype )
13211323{
13221324 int disks = sh -> disks ;
13231325 int syndrome_disks = sh -> ddf_layout ? disks : (disks - 2 );
@@ -1332,8 +1334,15 @@ static int set_syndrome_sources(struct page **srcs, struct stripe_head *sh)
13321334 i = d0_idx ;
13331335 do {
13341336 int slot = raid6_idx_to_slot (i , sh , & count , syndrome_disks );
1337+ struct r5dev * dev = & sh -> dev [i ];
13351338
1336- srcs [slot ] = sh -> dev [i ].page ;
1339+ if (i == sh -> qd_idx || i == sh -> pd_idx ||
1340+ (srctype == SYNDROME_SRC_ALL ) ||
1341+ (srctype == SYNDROME_SRC_WANT_DRAIN &&
1342+ test_bit (R5_Wantdrain , & dev -> flags )) ||
1343+ (srctype == SYNDROME_SRC_WRITTEN &&
1344+ dev -> written ))
1345+ srcs [slot ] = sh -> dev [i ].page ;
13371346 i = raid6_next_disk (i , disks );
13381347 } while (i != d0_idx );
13391348
@@ -1373,7 +1382,7 @@ ops_run_compute6_1(struct stripe_head *sh, struct raid5_percpu *percpu)
13731382 atomic_inc (& sh -> count );
13741383
13751384 if (target == qd_idx ) {
1376- count = set_syndrome_sources (blocks , sh );
1385+ count = set_syndrome_sources (blocks , sh , SYNDROME_SRC_ALL );
13771386 blocks [count ] = NULL ; /* regenerating p is not necessary */
13781387 BUG_ON (blocks [count + 1 ] != dest ); /* q should already be set */
13791388 init_async_submit (& submit , ASYNC_TX_FENCE , NULL ,
@@ -1481,7 +1490,7 @@ ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu)
14811490 tx = async_xor (dest , blocks , 0 , count , STRIPE_SIZE ,
14821491 & submit );
14831492
1484- count = set_syndrome_sources (blocks , sh );
1493+ count = set_syndrome_sources (blocks , sh , SYNDROME_SRC_ALL );
14851494 init_async_submit (& submit , ASYNC_TX_FENCE , tx ,
14861495 ops_complete_compute , sh ,
14871496 to_addr_conv (sh , percpu , 0 ));
@@ -1515,8 +1524,8 @@ static void ops_complete_prexor(void *stripe_head_ref)
15151524}
15161525
15171526static struct dma_async_tx_descriptor *
1518- ops_run_prexor (struct stripe_head * sh , struct raid5_percpu * percpu ,
1519- struct dma_async_tx_descriptor * tx )
1527+ ops_run_prexor5 (struct stripe_head * sh , struct raid5_percpu * percpu ,
1528+ struct dma_async_tx_descriptor * tx )
15201529{
15211530 int disks = sh -> disks ;
15221531 struct page * * xor_srcs = to_addr_page (percpu , 0 );
@@ -1544,6 +1553,26 @@ ops_run_prexor(struct stripe_head *sh, struct raid5_percpu *percpu,
15441553 return tx ;
15451554}
15461555
1556+ static struct dma_async_tx_descriptor *
1557+ ops_run_prexor6 (struct stripe_head * sh , struct raid5_percpu * percpu ,
1558+ struct dma_async_tx_descriptor * tx )
1559+ {
1560+ struct page * * blocks = to_addr_page (percpu , 0 );
1561+ int count ;
1562+ struct async_submit_ctl submit ;
1563+
1564+ pr_debug ("%s: stripe %llu\n" , __func__ ,
1565+ (unsigned long long )sh -> sector );
1566+
1567+ count = set_syndrome_sources (blocks , sh , SYNDROME_SRC_WANT_DRAIN );
1568+
1569+ init_async_submit (& submit , ASYNC_TX_FENCE |ASYNC_TX_PQ_XOR_DST , tx ,
1570+ ops_complete_prexor , sh , to_addr_conv (sh , percpu , 0 ));
1571+ tx = async_gen_syndrome (blocks , 0 , count + 2 , STRIPE_SIZE , & submit );
1572+
1573+ return tx ;
1574+ }
1575+
15471576static struct dma_async_tx_descriptor *
15481577ops_run_biodrain (struct stripe_head * sh , struct dma_async_tx_descriptor * tx )
15491578{
@@ -1746,6 +1775,8 @@ ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu,
17461775 int count , i , j = 0 ;
17471776 struct stripe_head * head_sh = sh ;
17481777 int last_stripe ;
1778+ int synflags ;
1779+ unsigned long txflags ;
17491780
17501781 pr_debug ("%s: stripe %llu\n" , __func__ , (unsigned long long )sh -> sector );
17511782
@@ -1765,14 +1796,23 @@ ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu,
17651796
17661797again :
17671798 blocks = to_addr_page (percpu , j );
1768- count = set_syndrome_sources (blocks , sh );
1799+
1800+ if (sh -> reconstruct_state == reconstruct_state_prexor_drain_run ) {
1801+ synflags = SYNDROME_SRC_WRITTEN ;
1802+ txflags = ASYNC_TX_ACK | ASYNC_TX_PQ_XOR_DST ;
1803+ } else {
1804+ synflags = SYNDROME_SRC_ALL ;
1805+ txflags = ASYNC_TX_ACK ;
1806+ }
1807+
1808+ count = set_syndrome_sources (blocks , sh , synflags );
17691809 last_stripe = !head_sh -> batch_head ||
17701810 list_first_entry (& sh -> batch_list ,
17711811 struct stripe_head , batch_list ) == head_sh ;
17721812
17731813 if (last_stripe ) {
17741814 atomic_inc (& head_sh -> count );
1775- init_async_submit (& submit , ASYNC_TX_ACK , tx , ops_complete_reconstruct ,
1815+ init_async_submit (& submit , txflags , tx , ops_complete_reconstruct ,
17761816 head_sh , to_addr_conv (sh , percpu , j ));
17771817 } else
17781818 init_async_submit (& submit , 0 , tx , NULL , NULL ,
@@ -1843,7 +1883,7 @@ static void ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu
18431883 (unsigned long long )sh -> sector , checkp );
18441884
18451885 BUG_ON (sh -> batch_head );
1846- count = set_syndrome_sources (srcs , sh );
1886+ count = set_syndrome_sources (srcs , sh , SYNDROME_SRC_ALL );
18471887 if (!checkp )
18481888 srcs [count ] = NULL ;
18491889
@@ -1884,8 +1924,12 @@ static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
18841924 async_tx_ack (tx );
18851925 }
18861926
1887- if (test_bit (STRIPE_OP_PREXOR , & ops_request ))
1888- tx = ops_run_prexor (sh , percpu , tx );
1927+ if (test_bit (STRIPE_OP_PREXOR , & ops_request )) {
1928+ if (level < 6 )
1929+ tx = ops_run_prexor5 (sh , percpu , tx );
1930+ else
1931+ tx = ops_run_prexor6 (sh , percpu , tx );
1932+ }
18891933
18901934 if (test_bit (STRIPE_OP_BIODRAIN , & ops_request )) {
18911935 tx = ops_run_biodrain (sh , tx );
@@ -2770,7 +2814,7 @@ static void
27702814schedule_reconstruction (struct stripe_head * sh , struct stripe_head_state * s ,
27712815 int rcw , int expand )
27722816{
2773- int i , pd_idx = sh -> pd_idx , disks = sh -> disks ;
2817+ int i , pd_idx = sh -> pd_idx , qd_idx = sh -> qd_idx , disks = sh -> disks ;
27742818 struct r5conf * conf = sh -> raid_conf ;
27752819 int level = conf -> level ;
27762820
@@ -2806,13 +2850,15 @@ schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s,
28062850 if (!test_and_set_bit (STRIPE_FULL_WRITE , & sh -> state ))
28072851 atomic_inc (& conf -> pending_full_writes );
28082852 } else {
2809- BUG_ON (level == 6 );
28102853 BUG_ON (!(test_bit (R5_UPTODATE , & sh -> dev [pd_idx ].flags ) ||
28112854 test_bit (R5_Wantcompute , & sh -> dev [pd_idx ].flags )));
2855+ BUG_ON (level == 6 &&
2856+ (!(test_bit (R5_UPTODATE , & sh -> dev [qd_idx ].flags ) ||
2857+ test_bit (R5_Wantcompute , & sh -> dev [qd_idx ].flags ))));
28122858
28132859 for (i = disks ; i -- ; ) {
28142860 struct r5dev * dev = & sh -> dev [i ];
2815- if (i == pd_idx )
2861+ if (i == pd_idx || i == qd_idx )
28162862 continue ;
28172863
28182864 if (dev -> towrite &&
@@ -3476,28 +3522,27 @@ static void handle_stripe_dirtying(struct r5conf *conf,
34763522 int rmw = 0 , rcw = 0 , i ;
34773523 sector_t recovery_cp = conf -> mddev -> recovery_cp ;
34783524
3479- /* RAID6 requires 'rcw' in current implementation.
3480- * Otherwise, check whether resync is now happening or should start.
3525+ /* Check whether resync is now happening or should start.
34813526 * If yes, then the array is dirty (after unclean shutdown or
34823527 * initial creation), so parity in some stripes might be inconsistent.
34833528 * In this case, we need to always do reconstruct-write, to ensure
34843529 * that in case of drive failure or read-error correction, we
34853530 * generate correct data from the parity.
34863531 */
3487- if (conf -> max_degraded == 2 ||
3532+ if (conf -> rmw_level == PARITY_DISABLE_RMW ||
34883533 (recovery_cp < MaxSector && sh -> sector >= recovery_cp &&
34893534 s -> failed == 0 )) {
34903535 /* Calculate the real rcw later - for now make it
34913536 * look like rcw is cheaper
34923537 */
34933538 rcw = 1 ; rmw = 2 ;
3494- pr_debug ("force RCW max_degraded =%u, recovery_cp=%llu sh->sector=%llu\n" ,
3495- conf -> max_degraded , (unsigned long long )recovery_cp ,
3539+ pr_debug ("force RCW rmw_level =%u, recovery_cp=%llu sh->sector=%llu\n" ,
3540+ conf -> rmw_level , (unsigned long long )recovery_cp ,
34963541 (unsigned long long )sh -> sector );
34973542 } else for (i = disks ; i -- ; ) {
34983543 /* would I have to read this buffer for read_modify_write */
34993544 struct r5dev * dev = & sh -> dev [i ];
3500- if ((dev -> towrite || i == sh -> pd_idx ) &&
3545+ if ((dev -> towrite || i == sh -> pd_idx || i == sh -> qd_idx ) &&
35013546 !test_bit (R5_LOCKED , & dev -> flags ) &&
35023547 !(test_bit (R5_UPTODATE , & dev -> flags ) ||
35033548 test_bit (R5_Wantcompute , & dev -> flags ))) {
@@ -3507,7 +3552,8 @@ static void handle_stripe_dirtying(struct r5conf *conf,
35073552 rmw += 2 * disks ; /* cannot read it */
35083553 }
35093554 /* Would I have to read this buffer for reconstruct_write */
3510- if (!test_bit (R5_OVERWRITE , & dev -> flags ) && i != sh -> pd_idx &&
3555+ if (!test_bit (R5_OVERWRITE , & dev -> flags ) &&
3556+ i != sh -> pd_idx && i != sh -> qd_idx &&
35113557 !test_bit (R5_LOCKED , & dev -> flags ) &&
35123558 !(test_bit (R5_UPTODATE , & dev -> flags ) ||
35133559 test_bit (R5_Wantcompute , & dev -> flags ))) {
@@ -3520,15 +3566,15 @@ static void handle_stripe_dirtying(struct r5conf *conf,
35203566 pr_debug ("for sector %llu, rmw=%d rcw=%d\n" ,
35213567 (unsigned long long )sh -> sector , rmw , rcw );
35223568 set_bit (STRIPE_HANDLE , & sh -> state );
3523- if (rmw < rcw && rmw > 0 ) {
3569+ if (( rmw < rcw || ( rmw == rcw && conf -> rmw_level == PARITY_ENABLE_RMW )) && rmw > 0 ) {
35243570 /* prefer read-modify-write, but need to get some data */
35253571 if (conf -> mddev -> queue )
35263572 blk_add_trace_msg (conf -> mddev -> queue ,
35273573 "raid5 rmw %llu %d" ,
35283574 (unsigned long long )sh -> sector , rmw );
35293575 for (i = disks ; i -- ; ) {
35303576 struct r5dev * dev = & sh -> dev [i ];
3531- if ((dev -> towrite || i == sh -> pd_idx ) &&
3577+ if ((dev -> towrite || i == sh -> pd_idx || i == sh -> qd_idx ) &&
35323578 !test_bit (R5_LOCKED , & dev -> flags ) &&
35333579 !(test_bit (R5_UPTODATE , & dev -> flags ) ||
35343580 test_bit (R5_Wantcompute , & dev -> flags )) &&
@@ -3547,7 +3593,7 @@ static void handle_stripe_dirtying(struct r5conf *conf,
35473593 }
35483594 }
35493595 }
3550- if (rcw <= rmw && rcw > 0 ) {
3596+ if (( rcw < rmw || ( rcw == rmw && conf -> rmw_level != PARITY_ENABLE_RMW )) && rcw > 0 ) {
35513597 /* want reconstruct write, but need to get some data */
35523598 int qread = 0 ;
35533599 rcw = 0 ;
@@ -6344,10 +6390,16 @@ static struct r5conf *setup_conf(struct mddev *mddev)
63446390 }
63456391
63466392 conf -> level = mddev -> new_level ;
6347- if (conf -> level == 6 )
6393+ if (conf -> level == 6 ) {
63486394 conf -> max_degraded = 2 ;
6349- else
6395+ if (raid6_call .xor_syndrome )
6396+ conf -> rmw_level = PARITY_ENABLE_RMW ;
6397+ else
6398+ conf -> rmw_level = PARITY_DISABLE_RMW ;
6399+ } else {
63506400 conf -> max_degraded = 1 ;
6401+ conf -> rmw_level = PARITY_ENABLE_RMW ;
6402+ }
63516403 conf -> algorithm = mddev -> new_layout ;
63526404 conf -> reshape_progress = mddev -> reshape_position ;
63536405 if (conf -> reshape_progress != MaxSector ) {
0 commit comments