Linux RAID subsystem development
 help / color / mirror / Atom feed
From: "Li Youhong" <dayou5941@163.com>
To: song@kernel.org, yukuai@fygo.io
Cc: magiclinan@didiglobal.com, xiao@kernel.org,
	linux-raid@vger.kernel.org, Li Youhong <liyouhong@kylinos.cn>
Subject: [PATCH 2/3] md/raid1-10: add rdev_bb_block_sectors() helper
Date: Thu, 27 Aug 2026 15:56:19 +0800	[thread overview]
Message-ID: <20260827075620.3599227-3-dayou5941@163.com> (raw)
In-Reply-To: <20260827075620.3599227-1-dayou5941@163.com>

From: Li Youhong <liyouhong@kylinos.cn>

raid1 and raid10 narrow_write_error() use the same logic to compute the
badblocks-aligned block size. Factor it into an inline helper in
raid1-10.c. No functional change.

Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
---
 drivers/md/raid1-10.c | 10 ++++++++++
 drivers/md/raid1.c    |  7 +------
 drivers/md/raid10.c   |  7 +------
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index 3b0e230692ba..c7ddf136771d 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -155,6 +155,16 @@ static inline bool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio,
 	return true;
 }
 
+/* Block size used when narrowing a write error down to badblocks granularity. */
+static inline int rdev_bb_block_sectors(struct md_rdev *rdev)
+{
+	int lbs = bdev_logical_block_size(rdev->bdev) >> 9;
+
+	if (rdev->badblocks.shift < 0)
+		return lbs;
+	return roundup(1 << rdev->badblocks.shift, lbs);
+}
+
 /*
  * current->bio_list will be set under submit_bio() context, in this case bitmap
  * io will be added to the list and wait for current io submission to finish,
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 9d8441348f14..8a40c69d70a3 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2465,16 +2465,11 @@ static void narrow_write_error(struct r1bio *r1_bio, int i)
 	 * We currently own a reference on the rdev.
 	 */
 
-	int block_sectors, lbs = bdev_logical_block_size(rdev->bdev) >> 9;
+	int block_sectors = rdev_bb_block_sectors(rdev);
 	sector_t sector;
 	int sectors;
 	int sect_to_write = r1_bio->sectors;
 
-	if (rdev->badblocks.shift < 0)
-		block_sectors = lbs;
-	else
-		block_sectors = roundup(1 << rdev->badblocks.shift, lbs);
-
 	sector = r1_bio->sector;
 	sectors = ((sector + block_sectors)
 		   & ~(sector_t)(block_sectors - 1))
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index c4218d6483ed..5b1dbb0b7f5a 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -2762,16 +2762,11 @@ static void narrow_write_error(struct r10bio *r10_bio, int i)
 	 * We currently own a reference to the rdev.
 	 */
 
-	int block_sectors, lbs = bdev_logical_block_size(rdev->bdev) >> 9;
+	int block_sectors = rdev_bb_block_sectors(rdev);
 	sector_t sector;
 	int sectors;
 	int sect_to_write = r10_bio->sectors;
 
-	if (rdev->badblocks.shift < 0)
-		block_sectors = lbs;
-	else
-		block_sectors = roundup(1 << rdev->badblocks.shift, lbs);
-
 	sector = r10_bio->sector;
 	sectors = ((r10_bio->sector + block_sectors)
 		   & ~(sector_t)(block_sectors - 1))
-- 
2.25.1


  parent reply	other threads:[~2026-08-27  7:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27  7:56 [PATCH 0/3] md: raid helper cleanups Li Youhong
2026-08-27  7:56 ` [PATCH 1/3] md: add rdev_record_write_error() helper Li Youhong
2026-08-27  7:56 ` Li Youhong [this message]
2026-08-27  8:15   ` [PATCH 2/3] md/raid1-10: add rdev_bb_block_sectors() helper sashiko-bot
2026-08-27  7:56 ` [PATCH 3/3] md/raid1-10: share flush_bio_list between raid1 and raid10 Li Youhong
2026-09-05  2:43 ` [PATCH 0/3] md: raid helper cleanups yu kuai

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=20260827075620.3599227-3-dayou5941@163.com \
    --to=dayou5941@163.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=liyouhong@kylinos.cn \
    --cc=magiclinan@didiglobal.com \
    --cc=song@kernel.org \
    --cc=xiao@kernel.org \
    --cc=yukuai@fygo.io \
    /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