@@ -9291,8 +9291,11 @@ static bool rdev_removeable(struct md_rdev *rdev)
return false;
/* Fautly rdev is not used, it's safe to remove it. */
- if (test_bit(Faulty, &rdev->flags))
- return true;
+ if (nr_pending_is_percpu_mode(rdev) && test_bit(Faulty, &rdev->flags)) {
+ percpu_ref_switch_to_atomic_sync(&rdev->nr_pending);
+ if (nr_pending_is_zero(rdev))
+ return true;
+ }
/* Journal disk can only be removed if it's faulty. */
if (test_bit(Journal, &rdev->flags))
@@ -9346,6 +9349,11 @@ static bool md_spares_need_change(struct mddev *mddev)
{
struct md_rdev *rdev;
+ rdev_for_each_rcu(rdev, mddev) {
+ if (test_bit(Faulty, &rdev->flags))
+ percpu_ref_switch_to_atomic_sync(&rdev->nr_pending);
+ }
+
rcu_read_lock();
rdev_for_each_rcu(rdev, mddev) {
if (rdev_removeable(rdev) || rdev_addable(rdev)) {