From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751743AbeDZEqn (ORCPT ); Thu, 26 Apr 2018 00:46:43 -0400 Received: from mx2.suse.de ([195.135.220.15]:48762 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750924AbeDZEqk (ORCPT ); Thu, 26 Apr 2018 00:46:40 -0400 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "Cc" From: NeilBrown To: Shaohua Li Date: Thu, 26 Apr 2018 14:46:29 +1000 Cc: Goldwyn Rodrigues Subject: [PATCH] md: fix two problems with setting the "re-add" device state. cc: Linux RAID Mailing List , LKML Message-ID: <87efj2mv6i.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable If "re-add" is written to the "state" file for a device which is faulty, this has an effect similar to removing and re-adding the device. It should take up the same slot in the array that it previously had, and an accelerated (e.g. bitmap-based) rebuild should happen. The slot that "it previously had" is determined by rdev->saved_raid_disk. However this is not set when a device fails (only when a device is added), and it is cleared when resync completes. This means that "re-add" will normally work once, but may not work a second time. This patch includes two fixes. 1/ when a device fails, record the ->raid_disk value in ->saved_raid_disk before clearing ->raid_disk 2/ when "re-add" is written to a device for which ->saved_raid_disk is not set, fail. I think this is suitable for stable as it can cause re-adding a device to be forced to do a full resync which takes a lot longer and so puts data at more risk. Cc: (v4.1) Fixes: 97f6cd39da22 ("md-cluster: re-add capabilities") Signed-off-by: NeilBrown =2D-- drivers/md/md.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 3bea45e8ccff..ecd4235c6e30 100644 =2D-- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -2853,7 +2853,8 @@ state_store(struct md_rdev *rdev, const char *buf, si= ze_t len) err =3D 0; } } else if (cmd_match(buf, "re-add")) { =2D if (test_bit(Faulty, &rdev->flags) && (rdev->raid_disk =3D=3D -1)) { + if (test_bit(Faulty, &rdev->flags) && (rdev->raid_disk =3D=3D -1) && + rdev->saved_raid_disk >=3D 0) { /* clear_bit is performed _after_ all the devices * have their local Faulty bit cleared. If any writes * happen in the meantime in the local node, they @@ -8641,6 +8642,7 @@ static int remove_and_add_spares(struct mddev *mddev, if (mddev->pers->hot_remove_disk( mddev, rdev) =3D=3D 0) { sysfs_unlink_rdev(mddev, rdev); + rdev->saved_raid_disk =3D rdev->raid_disk; rdev->raid_disk =3D -1; removed++; } =2D-=20 2.14.0.rc0.dirty --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlrhWacACgkQOeye3VZi gbnh6xAAwFgySWHCe6ljmhD+Qu/+qbFw9MJIWlp0SoyjpZJ+ruH1Uxpa4GV7XCH4 HrP/M5esTbd2+IjjuMzIGYYCLSdIpaO09COFTJGJwI1oaQ3Ia14kBskLYrlEoAhS i8UtWMOrdzUWaamcn6kc6dtCRd73U39jiZLykq0n5QBxAibTBWP/Kb0nFjx6Utw5 SBesdJMdExYv0sI+3MiF2vrcHWgapfzOYrQtQqXGK7BemwZ0fEaN3D9us4S1LwPE s43rJ/N0DNlW9yBYMPTE6yMuIPm3xvXzBUM00GUDwPDDQcvwMYTNkX2neQRJQfZT cu0fkgs//1/ZvNp+P6LjpSuNbd0QrtKX6+YWhX9GyCsM09DXbU5cSSRGifd+PPV/ 3710Gt7LurjrubsBwUnJxR5fpYMzGIpcaOaGv/bVNNe4bTecIe/PB522ONN+MKoc UwITKhXScmyZ11Me4Tz0KrWU8CMRonOM6dpIGuB2JPs6hh+KEFvIrmSD6Q7DGezr JqvNwsy6DK/fLeeTgtAHndJKNLR3cD21tW7YN5PK9LByVQbxAB4AeRBoMiCrdK79 zv67lsm5Y0LcIumZ2wJT7CT8Fj1VvQHEBt/uHa3IK22fzWNDfS/tHk5rCFxQa7L9 SFooTamiJ6mCY+wjGyecv9kIgLyD2+X7Pf53VJ1VSnMvBVvBzwA= =cysZ -----END PGP SIGNATURE----- --=-=-=--