public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Qu Wenruo <wqu@suse.com>,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	David Sterba <dsterba@suse.com>, Sasha Levin <sashal@kernel.org>,
	clm@fb.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org
Subject: [PATCH AUTOSEL 6.10 05/13] btrfs: factor out stripe length calculation into a helper
Date: Tue, 13 Aug 2024 22:14:36 -0400	[thread overview]
Message-ID: <20240814021451.4129952-5-sashal@kernel.org> (raw)
In-Reply-To: <20240814021451.4129952-1-sashal@kernel.org>

From: Qu Wenruo <wqu@suse.com>

[ Upstream commit 33eb1e5db351e2c0e652d878b66b8a6d4d013135 ]

Currently there are two locations which need to calculate the real
length of a stripe (which can be at the end of a chunk, and the chunk
size may not always be 64K aligned).

Factor them into a helper as we're going to have a third user soon.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/btrfs/scrub.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index d7caa3732f074..9712169593980 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1648,14 +1648,20 @@ static void scrub_reset_stripe(struct scrub_stripe *stripe)
 	}
 }
 
+static u32 stripe_length(const struct scrub_stripe *stripe)
+{
+	ASSERT(stripe->bg);
+
+	return min(BTRFS_STRIPE_LEN,
+		   stripe->bg->start + stripe->bg->length - stripe->logical);
+}
+
 static void scrub_submit_extent_sector_read(struct scrub_ctx *sctx,
 					    struct scrub_stripe *stripe)
 {
 	struct btrfs_fs_info *fs_info = stripe->bg->fs_info;
 	struct btrfs_bio *bbio = NULL;
-	unsigned int nr_sectors = min(BTRFS_STRIPE_LEN, stripe->bg->start +
-				      stripe->bg->length - stripe->logical) >>
-				  fs_info->sectorsize_bits;
+	unsigned int nr_sectors = stripe_length(stripe) >> fs_info->sectorsize_bits;
 	u64 stripe_len = BTRFS_STRIPE_LEN;
 	int mirror = stripe->mirror_num;
 	int i;
@@ -1729,9 +1735,7 @@ static void scrub_submit_initial_read(struct scrub_ctx *sctx,
 {
 	struct btrfs_fs_info *fs_info = sctx->fs_info;
 	struct btrfs_bio *bbio;
-	unsigned int nr_sectors = min(BTRFS_STRIPE_LEN, stripe->bg->start +
-				      stripe->bg->length - stripe->logical) >>
-				  fs_info->sectorsize_bits;
+	unsigned int nr_sectors = stripe_length(stripe) >> fs_info->sectorsize_bits;
 	int mirror = stripe->mirror_num;
 
 	ASSERT(stripe->bg);
-- 
2.43.0


  parent reply	other threads:[~2024-08-14  2:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-14  2:14 [PATCH AUTOSEL 6.10 01/13] ASoC: amd: yc: Support mic on HP 14-em0002la Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 02/13] spi: hisi-kunpeng: Add validation for the minimum value of speed_hz Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 03/13] platform/x86/amd: pmf: Add quirk for ROG Ally X Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 04/13] platform/x86/amd/pmf: Add new ACPI ID AMDI0107 Sasha Levin
2024-08-14  2:14 ` Sasha Levin [this message]
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 06/13] btrfs: scrub: update last_physical after scrubbing one stripe Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 07/13] btrfs: fix qgroup reserve leaks in cow_file_range Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 08/13] i2c: Fix conditional for substituting empty ACPI functions Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 09/13] virtio-net: check feature before configuring the vq coalescing command Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 10/13] dma-debug: avoid deadlock between dma debug vs printk and netconsole Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 11/13] net: usb: qmi_wwan: add MeiG Smart SRM825L Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 12/13] ASoC: amd: yc: Support mic on Lenovo Thinkpad E14 Gen 6 Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 13/13] ASoC: codecs: ES8326: button detect issue Sasha Levin

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=20240814021451.4129952-5-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=wqu@suse.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