From patchwork Wed Feb 28 11:43:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 207811 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3298742dyb; Wed, 28 Feb 2024 04:05:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU8LEzROPzWVB1SZbv4Tg2MZU5GITlXAm1POXlhCgzZ55qBNUWa3HCUD44vP9lTFwP6SEVI3s+TVXdBFdAFt6jtO7kNew== X-Google-Smtp-Source: AGHT+IHcH980vQEgitJoN6B7zxQnt4EISlN5wM2MwdErLlWTk0O59ejty5/5qaCWr1D9lofKvAgD X-Received: by 2002:a17:902:db01:b0:1dc:adad:f54b with SMTP id m1-20020a170902db0100b001dcadadf54bmr7435074plx.44.1709121927577; Wed, 28 Feb 2024 04:05:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709121927; cv=pass; d=google.com; s=arc-20160816; b=DRbkZTKX3F7vbUlmNBOdXXYCjSUnjQgEo1uDyC5EFlZ4m0MJPp9yKTcr9T/5nWyglk rj4n0SCjv6EWlV3Pqq44BR7gCMw3SYgNUFC76Dk3H1EtEjn+ijOy8IGIvjL+y9vzUm9S OOfhWcGK0fuFVaZpR9VcnqUHuCwrk1CiKtCdOJIqZwUMTpPZCIIGfSvCpNjwWHZjLBBX aQTITKVPhv4y64xpYbPXjZXazjXKWfRNfFuAsJlJxbRd2vqivYv0sIQtU1P5P+sNWlhn btkGrhN2i1mjn75wGL+CcoQy5U+jz7apR9Bwin6k10eL6X9CWFdM6Kf9TG7xAttn5tOd xpuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=AYI14mbTiQ5uTwOzEYZMcKeL8x961l4a6aNfhBWGGBQ=; fh=Ytj0OQL2yyVgRSgKlJizbwNzVtV64xy+1TGtb7SiHpY=; b=UY9ETLm3UQwzR0ncmFFDCsVaQpN3DeFHG5oEOzRPz2eG78wG0yvT9smSeU8opbZsWL OHRG/cBJxbU1GrFIRmrbCEtAF7cEr75RaXS/C9/Usd4Ks0Z1kxHPUzDhvpPxhjweQXBJ a/kuPlq/5QjgreLCATGPKrplYSCEh/KuYNfXRvEEPZX/U3Sw+kdV1fdfXnYgsWkCVGLx 9mvCRxCxr8sR6tU0X+EtI1R65gLFS0xPByfeeQhgeOc/9ApPQ7Agl2ZX/o1g4LgLg85z SjBSu8XP/KjjkClexXckPCw7VmBEgjHQRmG1jNJWntHsWHeDlLTl7emvMqtTr8WrGD6A zTWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-84961-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84961-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y16-20020a17090322d000b001db29e3ba29si3422800plg.77.2024.02.28.04.05.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 04:05:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84961-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-84961-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84961-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 350B8287CE7 for ; Wed, 28 Feb 2024 11:55:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD051158D98; Wed, 28 Feb 2024 11:49:42 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F19F06CDCD; Wed, 28 Feb 2024 11:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709120980; cv=none; b=fwmmIFrJYOomEx80d40T7nF8L7vySuYdYzWRWCZdfHyZZKghFC8Ggp4re2UNLQwbEO0rz8aGBwM00/KJckmj4+AB6CObmwh/cKpIDsk7AcUC2qptlPXCiQT409FM+Do2Ry157WKY3LoYhm0soZBCoOTGETVRzccLQMEwqMydgH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709120980; c=relaxed/simple; bh=QYOlqih7BF6kX5BYdwF9n3/QSS94mDOA3t9MJUII4Qw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QCL988FAR4eKU09DpTpg2Cd7wWUaVVRO45y0W2z5pm3OjC04CumJp9ofbelDCzHh6OGXZtlh2H4uTiKLnensIt4VMorroUF8lXqozT06/ShYceaukaGp0X/cbngWdd3oeJfQV9f8nmMalmhJIsKz8LnRyUiMJB+dcQYgriC8r/4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TlCLt59BMz4f3lgF; Wed, 28 Feb 2024 19:49:26 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 10EB11A0232; Wed, 28 Feb 2024 19:49:34 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g7IHd9l+eamFQ--.6969S9; Wed, 28 Feb 2024 19:49:33 +0800 (CST) From: Yu Kuai To: xni@redhat.com, paul.e.luse@linux.intel.com, song@kernel.org, shli@fb.com, neilb@suse.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH md-6.9 v3 05/11] md/raid1-10: add a helper raid1_check_read_range() Date: Wed, 28 Feb 2024 19:43:27 +0800 Message-Id: <20240228114333.527222-6-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240228114333.527222-1-yukuai1@huaweicloud.com> References: <20240228114333.527222-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn9g7IHd9l+eamFQ--.6969S9 X-Coremail-Antispam: 1UD129KBjvJXoW7AFy8Zw15tF1rurW5CF4kWFg_yoW8KFy5pr 4Yya43tr1UK3y3W3W3uF1xC34FyayfWFW8GrWfX3WDWry5Ga9akF97JryjgFyDWry3Xw12 qa1j9rWxua47CaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbmZ X7UUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792144234349032348 X-GMAIL-MSGID: 1792144234349032348 From: Yu Kuai The checking and handler of bad blocks appear many timers during read_balance() in raid1 and raid10. This helper will be used in later patches to simplify read_balance() a lot. Co-developed-by: Paul Luse Signed-off-by: Paul Luse Signed-off-by: Yu Kuai Reviewed-by: Xiao Ni --- drivers/md/raid1-10.c | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c index 512746551f36..9bc0f0022a6c 100644 --- a/drivers/md/raid1-10.c +++ b/drivers/md/raid1-10.c @@ -227,3 +227,52 @@ static inline bool exceed_read_errors(struct mddev *mddev, struct md_rdev *rdev) return false; } + +/** + * raid1_check_read_range() - check a given read range for bad blocks, + * available read length is returned; + * @rdev: the rdev to read; + * @this_sector: read position; + * @len: read length; + * + * helper function for read_balance() + * + * 1) If there are no bad blocks in the range, @len is returned; + * 2) If the range are all bad blocks, 0 is returned; + * 3) If there are partial bad blocks: + * - If the bad block range starts after @this_sector, the length of first + * good region is returned; + * - If the bad block range starts before @this_sector, 0 is returned and + * the @len is updated to the offset into the region before we get to the + * good blocks; + */ +static inline int raid1_check_read_range(struct md_rdev *rdev, + sector_t this_sector, int *len) +{ + sector_t first_bad; + int bad_sectors; + + /* no bad block overlap */ + if (!is_badblock(rdev, this_sector, *len, &first_bad, &bad_sectors)) + return *len; + + /* + * bad block range starts offset into our range so we can return the + * number of sectors before the bad blocks start. + */ + if (first_bad > this_sector) + return first_bad - this_sector; + + /* read range is fully consumed by bad blocks. */ + if (this_sector + *len <= first_bad + bad_sectors) + return 0; + + /* + * final case, bad block range starts before or at the start of our + * range but does not cover our entire range so we still return 0 but + * update the length with the number of sectors before we get to the + * good ones. + */ + *len = first_bad + bad_sectors - this_sector; + return 0; +}