md: be extra careful not to take a reference to a Faulty device.
authorNeilBrown <neilb@suse.com>
Thu, 2 Jun 2016 06:19:53 +0000 (16:19 +1000)
committerShaohua Li <shli@fb.com>
Mon, 13 Jun 2016 18:54:21 +0000 (11:54 -0700)
commitf5b67ae86ee317db20c0e10d54f16a0bbbd3207d
tree8db4539e9c9f05624f2b198ddd1ccce54b281ce6
parent40cf2123c57928c3ec0626c49bef97ebdbce008e
md: be extra careful not to take a reference to a Faulty device.

It is important that we never increment rdev->nr_pending on a Faulty
device as ->hot_remove_disk() assumes that once the Faulty flag is visible
no code will take a new reference.

Some places take a new reference after only check In_sync.  This should
be safe as the two are changed together.  However to make the code more
obviously safe, add checks for 'Faulty' as well.

Note: the actual rule is:
  Never increment nr_pending if  Faulty is set and Blocked is clear,
  never clear Faulty, and never set Blocked without holding a reference
  through nr_pending.

fix build error (Shaohua)
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
drivers/md/multipath.c
drivers/md/raid10.c
drivers/md/raid5.c