return -1;
 }
 
+static bool rdev_in_recovery(struct md_rdev *rdev, struct r1bio *r1_bio)
+{
+       return !test_bit(In_sync, &rdev->flags) &&
+              rdev->recovery_offset < r1_bio->sector + r1_bio->sectors;
+}
+
 static int choose_bb_rdev(struct r1conf *conf, struct r1bio *r1_bio,
                          int *max_sectors)
 {
 
                rdev = conf->mirrors[disk].rdev;
                if (!rdev || test_bit(Faulty, &rdev->flags) ||
+                   rdev_in_recovery(rdev, r1_bio) ||
                    test_bit(WriteMostly, &rdev->flags))
                        continue;
 
 
                rdev = conf->mirrors[disk].rdev;
                if (!rdev || test_bit(Faulty, &rdev->flags) ||
-                   !test_bit(WriteMostly, &rdev->flags))
+                   !test_bit(WriteMostly, &rdev->flags) ||
+                   rdev_in_recovery(rdev, r1_bio))
                        continue;
 
                /* there are no bad blocks, we can use this disk */
        if (!rdev || test_bit(Faulty, &rdev->flags))
                return false;
 
-       /* still in recovery */
-       if (!test_bit(In_sync, &rdev->flags) &&
-           rdev->recovery_offset < r1_bio->sector + r1_bio->sectors)
+       if (rdev_in_recovery(rdev, r1_bio))
                return false;
 
        /* don't read from slow disk unless have to */