Linux-Raid Archives mirror
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai1@huaweicloud.com>
To: paul.e.luse@linux.intel.com, song@kernel.org, neilb@suse.com,
	shli@fb.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 04/10] md/raid1-10: add a helper raid1_check_read_range()
Date: Thu, 22 Feb 2024 15:58:00 +0800	[thread overview]
Message-ID: <20240222075806.1816400-5-yukuai1@huaweicloud.com> (raw)
In-Reply-To: <20240222075806.1816400-1-yukuai1@huaweicloud.com>

From: Yu Kuai <yukuai3@huawei.com>

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 <paul.e.luse@linux.intel.com>
Signed-off-by: Paul Luse <paul.e.luse@linux.intel.com>
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 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;
+}
-- 
2.39.2


  parent reply	other threads:[~2024-02-22  8:03 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-22  7:57 [PATCH md-6.9 00/10] md/raid1: refactor read_balance() and some minor fix Yu Kuai
2024-02-22  7:57 ` [PATCH md-6.9 01/10] md: add a new helper rdev_has_badblock() Yu Kuai
2024-02-26  9:01   ` Xiao Ni
2024-02-22  7:57 ` [PATCH md-6.9 02/10] md: record nonrot rdevs while adding/removing rdevs to conf Yu Kuai
2024-02-26 13:12   ` Xiao Ni
2024-02-26 13:25     ` Yu Kuai
2024-02-26 13:27       ` Xiao Ni
2024-02-22  7:57 ` [PATCH md-6.9 03/10] md/raid1: fix choose next idle in read_balance() Yu Kuai
2024-02-26  8:55   ` Xiao Ni
2024-02-26  9:12     ` Yu Kuai
2024-02-26  9:24       ` Xiao Ni
2024-02-26  9:40         ` Yu Kuai
2024-02-26 13:20           ` Xiao Ni
2024-02-27  2:23   ` Xiao Ni
2024-02-27  2:38     ` Yu Kuai
2024-02-27  4:49       ` Xiao Ni
2024-02-27 14:26         ` Luse, Paul E
2024-02-22  7:58 ` Yu Kuai [this message]
2024-02-26  9:15   ` [PATCH md-6.9 04/10] md/raid1-10: add a helper raid1_check_read_range() Xiao Ni
2024-02-22  7:58 ` [PATCH md-6.9 05/10] md/raid1-10: factor out a new helper raid1_should_read_first() Yu Kuai
2024-02-26 13:46   ` Xiao Ni
2024-02-22  7:58 ` [PATCH md-6.9 06/10] md/raid1: factor out read_first_rdev() from read_balance() Yu Kuai
2024-02-26 14:16   ` Xiao Ni
2024-02-27  1:06     ` Yu Kuai
2024-02-27  1:23       ` Xiao Ni
2024-02-27  1:42         ` Xiao Ni
2024-02-27  1:43         ` Yu Kuai
2024-02-27  2:50           ` Xiao Ni
2024-02-27  2:50   ` Xiao Ni
2024-02-22  7:58 ` [PATCH md-6.9 07/10] md/raid1: factor out choose_slow_rdev() " Yu Kuai
2024-02-26 14:44   ` Xiao Ni
2024-02-22  7:58 ` [PATCH md-6.9 08/10] md/raid1: factor out choose_bb_rdev() " Yu Kuai
2024-02-27  1:50   ` Xiao Ni
2024-02-22  7:58 ` [PATCH md-6.9 09/10] md/raid1: factor out the code to manage sequential IO Yu Kuai
2024-02-27  2:04   ` Xiao Ni
2024-02-22  7:58 ` [PATCH md-6.9 10/10] md/raid1: factor out helpers to choose the best rdev from read_balance() Yu Kuai
2024-02-27  4:47   ` Xiao Ni
2024-02-22  8:40 ` [PATCH md-6.9 00/10] md/raid1: refactor read_balance() and some minor fix Paul Menzel
2024-02-22  9:08   ` Yu Kuai
2024-02-22 13:04     ` Luse, Paul E
2024-02-22 15:30       ` Paul Menzel
2024-02-27  0:27 ` Song Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240222075806.1816400-5-yukuai1@huaweicloud.com \
    --to=yukuai1@huaweicloud.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.com \
    --cc=paul.e.luse@linux.intel.com \
    --cc=shli@fb.com \
    --cc=song@kernel.org \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).