Commit 2f73d3c5 authored by NeilBrown's avatar NeilBrown

md/raid1: make sure resync waits for conflicting writes to complete.

The resync/recovery process for raid1 was recently changed
so that writes could happen in parallel with resync providing
they were in different regions of the device.

There is a problem though:  While a write request will always
wait for conflicting resync to complete, a resync request
will *not* always wait for conflicting writes to complete.

Two changes are needed to fix this:

1/ raise_barrier (which waits until it is safe to do resync)
   must wait until current_window_requests is zero
2/ wait_battier (which waits at the start of a new write request)
   must update current_window_requests if the request could
   possible conflict with a concurrent resync.

As concurrent writes and resync can lead to data loss,
this patch is suitable for -stable.

Fixes: 79ef3a8a
Cc: stable@vger.kernel.org (v3.13+)
Cc: majianpeng <majianpeng@gmail.com>
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
parent 669cc7ba
...@@ -845,10 +845,12 @@ static void raise_barrier(struct r1conf *conf) ...@@ -845,10 +845,12 @@ static void raise_barrier(struct r1conf *conf)
* C: next_resync + RESYNC_SECTORS > start_next_window, meaning * C: next_resync + RESYNC_SECTORS > start_next_window, meaning
* next resync will reach to the window which normal bios are * next resync will reach to the window which normal bios are
* handling. * handling.
* D: while there are any active requests in the current window.
*/ */
wait_event_lock_irq(conf->wait_barrier, wait_event_lock_irq(conf->wait_barrier,
!conf->array_frozen && !conf->array_frozen &&
conf->barrier < RESYNC_DEPTH && conf->barrier < RESYNC_DEPTH &&
conf->current_window_requests == 0 &&
(conf->start_next_window >= (conf->start_next_window >=
conf->next_resync + RESYNC_SECTORS), conf->next_resync + RESYNC_SECTORS),
conf->resync_lock); conf->resync_lock);
...@@ -915,8 +917,8 @@ static sector_t wait_barrier(struct r1conf *conf, struct bio *bio) ...@@ -915,8 +917,8 @@ static sector_t wait_barrier(struct r1conf *conf, struct bio *bio)
} }
if (bio && bio_data_dir(bio) == WRITE) { if (bio && bio_data_dir(bio) == WRITE) {
if (conf->next_resync + NEXT_NORMALIO_DISTANCE if (bio->bi_iter.bi_sector >=
<= bio->bi_iter.bi_sector) { conf->next_resync) {
if (conf->start_next_window == MaxSector) if (conf->start_next_window == MaxSector)
conf->start_next_window = conf->start_next_window =
conf->next_resync + conf->next_resync +
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment