Skip to content

Commit

Permalink
MD: fix invalid stored role for a disk
Browse files Browse the repository at this point in the history
If we change the number of array's device after device is removed from array,
then add the device back to array, we can see that device is added as active
role instead of spare which we expected.

Please see the below link for details:
https://marc.info/?l=linux-raid&m=153736982015076&w=2

This is caused by that we prefer to use device's previous role which is
recorded by saved_raid_disk, but we should respect the new number of
conf->raid_disks since it could be changed after device is removed.

Reported-by: Gioh Kim <gi-oh.kim@profitbricks.com>
Tested-by: Gioh Kim <gi-oh.kim@profitbricks.com>
Acked-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
  • Loading branch information
Shaohua Li committed Oct 2, 2018
1 parent ee37d73 commit d595567
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,10 @@ static int super_1_validate(struct mddev *mddev, struct md_rdev *rdev)
} else
set_bit(In_sync, &rdev->flags);
rdev->raid_disk = role;
if (role >= mddev->raid_disks) {
rdev->saved_raid_disk = -1;
rdev->raid_disk = -1;
}
break;
}
if (sb->devflags & WriteMostly1)
Expand Down

0 comments on commit d595567

Please sign in to comment.