All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: zoned: don't read beyond write pointer for scrub
@ 2023-07-03 11:47 Johannes Thumshirn
  2023-07-03 12:03 ` Qu Wenruo
  0 siblings, 1 reply; 7+ messages in thread
From: Johannes Thumshirn @ 2023-07-03 11:47 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Johannes Thumshirn, Qu Wenruo

As an optimization scrub_simple_mirror() performs reads in 64k chunks, if
at least one block of this chunk is has an extent allocated to it.

For zoned devices, this can lead to a read beyond the zone's write
pointer. But as there can't be any data beyond the write pointer, there's
no point in reading from it.

Cc: Qu Wenruo <wqu@suse.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

---
While this is only a marginal optimization for the current code, it will
become necessary for RAID on zoned drives using the RAID strip tree.
---
 fs/btrfs/scrub.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 38c103f13fd5..250317da1730 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -2060,13 +2060,19 @@ static int scrub_simple_stripe(struct scrub_ctx *sctx,
 	int ret = 0;
 
 	while (cur_logical < bg->start + bg->length) {
+		u64 length = BTRFS_STRIPE_LEN;
+
+		if (btrfs_is_zoned(bg->fs_info) &&
+		    cur_logical + BTRFS_STRIPE_LEN > bg->alloc_offset) {
+			length = bg->alloc_offset - cur_logical;
+		}
 		/*
 		 * Inside each stripe, RAID0 is just SINGLE, and RAID10 is
 		 * just RAID1, so we can reuse scrub_simple_mirror() to scrub
 		 * this stripe.
 		 */
 		ret = scrub_simple_mirror(sctx, bg, map, cur_logical,
-					  BTRFS_STRIPE_LEN, device, cur_physical,
+					  length, device, cur_physical,
 					  mirror_num);
 		if (ret)
 			return ret;
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-07-05  9:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03 11:47 [PATCH] btrfs: zoned: don't read beyond write pointer for scrub Johannes Thumshirn
2023-07-03 12:03 ` Qu Wenruo
2023-07-03 15:48   ` Johannes Thumshirn
2023-07-03 22:41     ` Qu Wenruo
2023-07-05  8:42       ` Johannes Thumshirn
2023-07-05  8:54         ` Qu Wenruo
2023-07-05  9:06           ` Johannes Thumshirn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.