]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
MD: fix invalid stored role for a disk
authorShaohua Li <shli@fb.com>
Tue, 2 Oct 2018 01:36:36 +0000 (18:36 -0700)
committerJuerg Haefliger <juergh@canonical.com>
Wed, 24 Jul 2019 01:56:52 +0000 (19:56 -0600)
BugLink: https://bugs.launchpad.net/bugs/1836802
[ Upstream commit d595567dc4f0c1d90685ec1e2e296e2cad2643ac ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/md/md.c

index 6c1e080aa45218115dab7158006185b2d2c0b31f..828c84d1e4b69ec07130b5787f61f004212be567 100644 (file)
@@ -1765,6 +1765,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)