Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp170731imd; Wed, 31 Oct 2018 16:44:49 -0700 (PDT) X-Google-Smtp-Source: AJdET5eY87NEwepJThEOaalLlQo6IABKkLbAJGBUDwoaVGNw2p6fbS/JrGdK3bEdIeJZdAlJsQrO X-Received: by 2002:a62:1f13:: with SMTP id f19-v6mr5391076pff.168.1541029489910; Wed, 31 Oct 2018 16:44:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029489; cv=none; d=google.com; s=arc-20160816; b=rFXDXs+Bbqu9fToX790kTDrKKTPt2PlEhQk8gti5M33TLcKDoZJVRTFd0jt3EKut9Q CGKdAnG112vom/ohlNQyKdMOcjpTqklLZ6fus4wtMKz3rsArwNSqdbD20JPsVPEjIuzR GPce3ICpDbnIGuKY1u0DTGIDKrNqKfJ1iOlwQL6NklVKP+P0Ln2FyuzIiYS3JfPmaaOd vt0vegrqf1PuW9orYHCH9f/xvmQbDh2dTiPQXEpx3pMTmCB6fe8S9nrCYwLPSrfQc1jL AWFQxJe925y9BNwpBENag0vlPvHYJG2wMFRBpRtlfI8LkLbfB0nh5kD3xSRa3X47iP70 sMbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=T80n85SAmw2x2PhotQbmIOppXYHOPLyL9QLrykQ8Its=; b=itGQhwpXi1EAV2+XrZmCfOyXkZrlrw3yiv7zIRiGxSNbJV6z2793tzvjX1jc7LKpO5 jmvN01lMzaKeKELyKPE4oYB7HjX0JmP3VafnzSw0AIc9XMchzvX5w/2/49Yq2zc9k0Lq GeLs/zT7aVLlF2cEIu3wu3BgCY8Ip9y1WsNw0nlbkajYa/s/mXuz/59Mwzusmr4zKooM lSvJR7YdLxc0xP2+Ps43lOjZvl/YMLdejqXugMoxFsxHRHPbEmBkJwaOW5nCAEHRFStN YrLgPVRYVGNUk3hztuapveKRZUwpie0Ogo754DEZLqNCg1Q2wRN5ALF2TAAwMohLWzOe h66A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WSbKyshi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33-v6si11655038plg.96.2018.10.31.16.44.35; Wed, 31 Oct 2018 16:44:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WSbKyshi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729054AbeKAIHk (ORCPT + 99 others); Thu, 1 Nov 2018 04:07:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:55622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729010AbeKAIHj (ORCPT ); Thu, 1 Nov 2018 04:07:39 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 49F0D2064C; Wed, 31 Oct 2018 23:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027248; bh=fPNt1fLPY/M2cFSppIkgLY6AvDWzZ04HAbWQpGRe/C4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WSbKyshiE6it7iLhkxRGMclzHyuRfIA9cdimS/FepllshC0VMMX7VHw8wOdAjBtm4 0WfD7/u/VkTO2gvY24ewavYNZwOCoI+yJX+dh0/B+Ubkxi+nWl9ltbOGMzJnTd2uTI rFRhDGjo8aGB2RrZAhjm7kHYip9PyLLdtww0UXEM= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Shaohua Li , Sasha Levin Subject: [PATCH AUTOSEL 4.19 118/146] MD: fix invalid stored role for a disk Date: Wed, 31 Oct 2018 19:05:13 -0400 Message-Id: <20181031230541.28822-118-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shaohua Li [ 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 Tested-by: Gioh Kim Acked-by: Guoqing Jiang Signed-off-by: Shaohua Li Signed-off-by: Sasha Levin --- drivers/md/md.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/md/md.c b/drivers/md/md.c index 8668793262d0..85459c17cc60 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -1776,6 +1776,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) -- 2.17.1