md: fix raid5 'repair' operations

commit bd2ab67030e9116f1e4aae1289220255412b37fd "md: close a livelock window
in handle_parity_checks5" introduced a bug in handling 'repair' operations.
After a repair operation completes we clear the state bits tracking this
operation. However, they are cleared too early and this results in the code
deciding to re-run the parity check operation. Since we have done the repair
in memory the second check does not find a mismatch and thus does not do a
writeback.

Test results:
$ echo repair > /sys/block/md0/md/sync_action
$ cat /sys/block/md0/md/mismatch_cnt
51072
$ echo repair > /sys/block/md0/md/sync_action
$ cat /sys/block/md0/md/mismatch_cnt
0

(also fix incorrect indentation)

Cc: <stable@kernel.org>
Tested-by: George Spelvin <linux@horizon.com>
Acked-by: NeilBrown <neilb@suse.de>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Dan Williams and committed by
Linus Torvalds
c8894419 3f275ea3

+13 -12
+13 -12
drivers/md/raid5.c
··· 2369 2369 2370 2370 /* complete a check operation */ 2371 2371 if (test_and_clear_bit(STRIPE_OP_CHECK, &sh->ops.complete)) { 2372 - clear_bit(STRIPE_OP_CHECK, &sh->ops.ack); 2373 - clear_bit(STRIPE_OP_CHECK, &sh->ops.pending); 2372 + clear_bit(STRIPE_OP_CHECK, &sh->ops.ack); 2373 + clear_bit(STRIPE_OP_CHECK, &sh->ops.pending); 2374 2374 if (s->failed == 0) { 2375 2375 if (sh->ops.zero_sum_result == 0) 2376 2376 /* parity is correct (on disc, ··· 2400 2400 canceled_check = 1; /* STRIPE_INSYNC is not set */ 2401 2401 } 2402 2402 2403 - /* check if we can clear a parity disk reconstruct */ 2404 - if (test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete) && 2405 - test_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending)) { 2406 - 2407 - clear_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending); 2408 - clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete); 2409 - clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.ack); 2410 - clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending); 2411 - } 2412 - 2413 2403 /* start a new check operation if there are no failures, the stripe is 2414 2404 * not insync, and a repair is not in flight 2415 2405 */ ··· 2413 2423 s->uptodate--; 2414 2424 } 2415 2425 } 2426 + 2427 + /* check if we can clear a parity disk reconstruct */ 2428 + if (test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete) && 2429 + test_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending)) { 2430 + 2431 + clear_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending); 2432 + clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete); 2433 + clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.ack); 2434 + clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending); 2435 + } 2436 + 2416 2437 2417 2438 /* Wait for check parity and compute block operations to complete 2418 2439 * before write-back. If a failure occurred while the check operation