public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: yukuai@kernel.org
To: song@kernel.org, yukuai3@huawei.com
Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	yi.zhang@hauwei.com, yangerkun@huawei.com,
	Yu Kuai <yukuai@kernel.org>
Subject: [PATCH v2 md-6.14 4/5] md/raid5: implement pers->bitmap_sector()
Date: Wed, 18 Dec 2024 20:17:44 +0800	[thread overview]
Message-ID: <20241218121745.2459-5-yukuai@kernel.org> (raw)
In-Reply-To: <20241218121745.2459-1-yukuai@kernel.org>

From: Yu Kuai <yukuai3@huawei.com>

Bitmap is used for the whole array for raid1/raid10, hence IO for the
array can be used directly for bitmap. However, bitmap is used for
underlying disks for raid5, hence IO for the array can't be used
directly for bitmap.

Implement pers->bitmap_sector() for raid5 to convert IO ranges from the
array to the underlying disks.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Yu Kuai <yukuai@kernel.org>
---
 drivers/md/raid5.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 6eb2841ce28c..b2fe201b599d 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2950,6 +2950,23 @@ static void raid5_error(struct mddev *mddev, struct md_rdev *rdev)
 	r5c_update_on_rdev_error(mddev, rdev);
 }
 
+static void raid5_bitmap_sector(struct mddev *mddev, sector_t *offset,
+				unsigned long *sectors)
+{
+	struct r5conf *conf = mddev->private;
+	int sectors_per_chunk = conf->chunk_sectors * (conf->raid_disks -
+						       conf->max_degraded);
+	sector_t start = *offset;
+	sector_t end = start + *sectors;
+	int dd_idx;
+
+	start = round_down(start, sectors_per_chunk);
+	end = round_up(end, sectors_per_chunk);
+
+	*offset = raid5_compute_sector(conf, start, 0, &dd_idx, NULL);
+	*sectors = raid5_compute_sector(conf, end, 0, &dd_idx, NULL) - *offset;
+}
+
 /*
  * Input: a 'big' sector number,
  * Output: index of the data and parity disk, and the sector # in them.
@@ -8972,6 +8989,7 @@ static struct md_personality raid6_personality =
 	.takeover	= raid6_takeover,
 	.change_consistency_policy = raid5_change_consistency_policy,
 	.prepare_suspend = raid5_prepare_suspend,
+	.bitmap_sector	= raid5_bitmap_sector,
 };
 static struct md_personality raid5_personality =
 {
@@ -8997,6 +9015,7 @@ static struct md_personality raid5_personality =
 	.takeover	= raid5_takeover,
 	.change_consistency_policy = raid5_change_consistency_policy,
 	.prepare_suspend = raid5_prepare_suspend,
+	.bitmap_sector	= raid5_bitmap_sector,
 };
 
 static struct md_personality raid4_personality =
@@ -9023,6 +9042,7 @@ static struct md_personality raid4_personality =
 	.takeover	= raid4_takeover,
 	.change_consistency_policy = raid5_change_consistency_policy,
 	.prepare_suspend = raid5_prepare_suspend,
+	.bitmap_sector	= raid5_bitmap_sector,
 };
 
 static int __init raid5_init(void)
-- 
2.43.0


  parent reply	other threads:[~2024-12-18 12:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-18 12:17 [PATCH v2 md-6.14 0/5] md/md-bitmap: move bitmap_{start, end}write to md upper layer yukuai
2024-12-18 12:17 ` [PATCH v2 md-6.14 1/5] md/md-bitmap: factor behind write counters out from bitmap_{start/end}write() yukuai
2024-12-18 12:17 ` [PATCH v2 md-6.14 2/5] md/md-bitmap: remove the last parameter for bimtap_ops->endwrite() yukuai
2024-12-23  7:31   ` Xiao Ni
2024-12-23  7:50     ` Yu Kuai
2024-12-30  5:01       ` Xiao Ni
2025-01-02  1:17         ` Yu Kuai
2024-12-18 12:17 ` [PATCH v2 md-6.14 3/5] md: add a new callback pers->bitmap_sector() yukuai
2024-12-18 12:17 ` yukuai [this message]
2025-01-01  5:36   ` [PATCH v2 md-6.14 4/5] md/raid5: implement pers->bitmap_sector() Xiao Ni
2025-01-02  1:21     ` Yu Kuai
2024-12-18 12:17 ` [PATCH v2 md-6.14 5/5] md/md-bitmap: move bitmap_{start, end}write to md upper layer yukuai
2025-01-02  4:36   ` Xiao Ni
  -- strict thread matches above, loose matches on Subject: below --
2025-01-09  1:51 [PATCH v2 md-6.14 0/5] " Yu Kuai
2025-01-09  1:51 ` [PATCH v2 md-6.14 4/5] md/raid5: implement pers->bitmap_sector() Yu Kuai
2025-01-09 18:36   ` 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=20241218121745.2459-5-yukuai@kernel.org \
    --to=yukuai@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=song@kernel.org \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@hauwei.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