md/raid10: ensure device failure recorded before write request returns.
authorNeilBrown <neilb@suse.com>
Fri, 14 Aug 2015 01:26:17 +0000 (11:26 +1000)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 17 Nov 2015 15:54:45 +0000 (15:54 +0000)
commitc1fba1c813b9135565aa01bd8470b94f315078ac
tree5cb0269f6d423d43ef2d35ccba850f1fd1fb5980
parent1f6c748a9d212708e2e0b5a43570fc22fc856689
md/raid10: ensure device failure recorded before write request returns.

commit 95af587e95aacb9cfda4a9641069a5244a540dc8 upstream.

When a write to one of the legs of a RAID10 fails, the failure is
recorded in the metadata of the other legs so that after a restart
the data on the failed drive wont be trusted even if that drive seems
to be working again (maybe a cable was unplugged).

Currently there is no interlock between the write request completing
and the metadata update.  So it is possible that the write will
complete, the app will confirm success in some way, and then the
machine will crash before the metadata update completes.

This is an extremely small hole for a racy to fit in, but it is
theoretically possible and so should be closed.

So:
 - set MD_CHANGE_PENDING when requesting a metadata update for a
   failed device, so we can know with certainty when it completes
 - queue requests that experienced an error on a new queue which
   is only processed after the metadata update completes
 - call raid_end_bio_io() on bios in that queue when the time comes.

Signed-off-by: NeilBrown <neilb@suse.com>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/md/raid10.c
drivers/md/raid10.h