md: fix bug with re-adding of partially recovered device.

With v0.90 metadata, a hot-spare does not become a full member of the
array until recovery is complete. So if we re-add such a device to
the array, we know that all of it is as up-to-date as the event count
would suggest, and so it a bitmap-based recovery is possible.

However with v1.x metadata, the hot-spare immediately becomes a full
member of the array, but it record how much of the device has been
recovered. If the array is stopped and re-assembled recovery starts
from this point.

When such a device is hot-added to an array we currently lose the 'how
much is recovered' information and incorrectly included it as a full
in-sync member (after bitmap-based fixup).
This is wrong and unsafe and could corrupt data.

So be more careful about setting saved_raid_disk - which is what
guides the re-adding of devices back into an array.
The new code matches the code in slot_store which does a similar
thing, which is encouraging.

This is suitable for any -stable kernel.

Reported-by: "Dailey, Nate" <Nate.Dailey@stratus.com>
Cc: stable@kernel.org
Signed-off-by: NeilBrown <neilb@suse.de>

NeilBrown 1a855a06 a035fc3e

+5 -2
+5 -2
drivers/md/md.c
··· 5159 5159 PTR_ERR(rdev)); 5160 5160 return PTR_ERR(rdev); 5161 5161 } 5162 - /* set save_raid_disk if appropriate */ 5162 + /* set saved_raid_disk if appropriate */ 5163 5163 if (!mddev->persistent) { 5164 5164 if (info->state & (1<<MD_DISK_SYNC) && 5165 5165 info->raid_disk < mddev->raid_disks) ··· 5169 5169 } else 5170 5170 super_types[mddev->major_version]. 5171 5171 validate_super(mddev, rdev); 5172 - rdev->saved_raid_disk = rdev->raid_disk; 5172 + if (test_bit(In_sync, &rdev->flags)) 5173 + rdev->saved_raid_disk = rdev->raid_disk; 5174 + else 5175 + rdev->saved_raid_disk = -1; 5173 5176 5174 5177 clear_bit(In_sync, &rdev->flags); /* just to be sure */ 5175 5178 if (info->state & (1<<MD_DISK_WRITEMOSTLY))