Skip to content

Commit 423f04d

Browse files
author
NeilBrown
committed
md/raid1: extend spinlock to protect raid1_end_read_request against inconsistencies
raid1_end_read_request() assumes that the In_sync bits are consistent with the ->degaded count. raid1_spare_active updates the In_sync bit before the ->degraded count and so exposes an inconsistency, as does error() So extend the spinlock in raid1_spare_active() and error() to hide those inconsistencies. This should probably be part of Commit: 34cab6f ("md/raid1: fix test for 'was read error from last working device'.") as it addresses the same issue. It fixes the same bug and should go to -stable for same reasons. Fixes: 7607305 ("md/raid1: clean up read_balance.") Cc: [email protected] (v3.0+) Signed-off-by: NeilBrown <[email protected]>
1 parent 74d3329 commit 423f04d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/md/raid1.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,7 @@ static void error(struct mddev *mddev, struct md_rdev *rdev)
14761476
{
14771477
char b[BDEVNAME_SIZE];
14781478
struct r1conf *conf = mddev->private;
1479+
unsigned long flags;
14791480

14801481
/*
14811482
* If it is not operational, then we have already marked it as dead
@@ -1495,14 +1496,13 @@ static void error(struct mddev *mddev, struct md_rdev *rdev)
14951496
return;
14961497
}
14971498
set_bit(Blocked, &rdev->flags);
1499+
spin_lock_irqsave(&conf->device_lock, flags);
14981500
if (test_and_clear_bit(In_sync, &rdev->flags)) {
1499-
unsigned long flags;
1500-
spin_lock_irqsave(&conf->device_lock, flags);
15011501
mddev->degraded++;
15021502
set_bit(Faulty, &rdev->flags);
1503-
spin_unlock_irqrestore(&conf->device_lock, flags);
15041503
} else
15051504
set_bit(Faulty, &rdev->flags);
1505+
spin_unlock_irqrestore(&conf->device_lock, flags);
15061506
/*
15071507
* if recovery is running, make sure it aborts.
15081508
*/
@@ -1568,7 +1568,10 @@ static int raid1_spare_active(struct mddev *mddev)
15681568
* Find all failed disks within the RAID1 configuration
15691569
* and mark them readable.
15701570
* Called under mddev lock, so rcu protection not needed.
1571+
* device_lock used to avoid races with raid1_end_read_request
1572+
* which expects 'In_sync' flags and ->degraded to be consistent.
15711573
*/
1574+
spin_lock_irqsave(&conf->device_lock, flags);
15721575
for (i = 0; i < conf->raid_disks; i++) {
15731576
struct md_rdev *rdev = conf->mirrors[i].rdev;
15741577
struct md_rdev *repl = conf->mirrors[conf->raid_disks + i].rdev;
@@ -1599,7 +1602,6 @@ static int raid1_spare_active(struct mddev *mddev)
15991602
sysfs_notify_dirent_safe(rdev->sysfs_state);
16001603
}
16011604
}
1602-
spin_lock_irqsave(&conf->device_lock, flags);
16031605
mddev->degraded -= count;
16041606
spin_unlock_irqrestore(&conf->device_lock, flags);
16051607

0 commit comments

Comments
 (0)