Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs: scrub: fix an error in stripe offset calculation
@ 2023-02-22  2:30 Qu Wenruo
  2023-02-22  7:16 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Qu Wenruo @ 2023-02-22  2:30 UTC (permalink / raw)
  To: linux-btrfs

[BUG]
After commit "btrfs: replace btrfs_io_context::raid_map with a fixed u64
value", btrfs/261 fails:

 QA output created by 261
 ERROR: there are uncorrectable errors
 scrub failed to fix the fs for profile -m raid5 -d raid5
 ERROR: there are uncorrectable errors
 scrub failed to fix the fs for profile -m raid6 -d raid6
 Silence is golden

[CAUSE]
In commit "btrfs: replace btrfs_io_context::raid_map with a fixed u64
value", there is a call site using raid_map[i]:

		*stripe_offset = logical - raid_map[i];

That location is to calculate the offset inside the stripe.
But unfortunately the offending commit is using a wrong value:

		*stripe_offset = logical - full_stripe_logical;

The above line is change the behavior to "logical - raid_map[0]", not
"logical - raid_map[i]".

Thus causing wrong offset returned to the caller for raid56 replace.

[FIX]
Thankfully the call site itself doesn't really need to access
raid_map[i], since what we need is the offset inside the stripe.

So we can use BTRFS_STRIPE_LEN_MASK to calculate the offset inside the
stripe.

Please fold this one into the offending commit "btrfs: replace
btrfs_io_context::raid_map with a fixed u64 value".

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/scrub.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 8961dceae18b..26c6ea41821a 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1447,7 +1447,8 @@ static inline void scrub_stripe_index_and_offset(u64 logical, u64 map_type,
 		}
 
 		*stripe_index = i;
-		*stripe_offset = logical - full_stripe_logical;
+		*stripe_offset = (logical - full_stripe_logical) &
+				 BTRFS_STRIPE_LEN_MASK;
 	} else {
 		/* The other RAID type */
 		*stripe_index = mirror;
-- 
2.39.1


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

end of thread, other threads:[~2023-02-23 19:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-22  2:30 [PATCH] btrfs: scrub: fix an error in stripe offset calculation Qu Wenruo
2023-02-22  7:16 ` kernel test robot
2023-02-22  8:58 ` kernel test robot
2023-02-23 19:51 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox