From 789635cccd7b023c723a296a18eb4d79dd3dd306 Mon Sep 17 00:00:00 2001 From: Alex Ainscow Date: Fri, 3 Oct 2025 13:53:33 +0100 Subject: [PATCH] osd: Replace unused EC offset translation function with useful one. The old chunk_aligned_shard_offset_to_ro_offset was not only unused, it didn't actually have the correct logic. We replace it here with similar, but more useful function that will be used in sparse reads for EC Signed-off-by: Alex Ainscow --- src/osd/ECUtil.h | 7 ++++--- src/test/osd/TestECBackend.cc | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/osd/ECUtil.h b/src/osd/ECUtil.h index deaf39cd53f..342101829a6 100644 --- a/src/osd/ECUtil.h +++ b/src/osd/ECUtil.h @@ -766,9 +766,10 @@ public: return ((len + stripe_width - 1) / stripe_width) * chunk_size; } - uint64_t chunk_aligned_shard_offset_to_ro_offset(uint64_t offset) const { - ceph_assert(offset % chunk_size == 0); - return (offset / chunk_size) * stripe_width; + uint64_t shard_offset_to_ro_offset(shard_id_t shard, uint64_t offset) const { + raw_shard_id_t raw_shard = get_raw_shard(shard); + auto result = std::lldiv(offset, chunk_size); + return result.quot * stripe_width + (int)raw_shard * chunk_size + result.rem; } std::pair chunk_aligned_ro_range_to_shard_ro_range( diff --git a/src/test/osd/TestECBackend.cc b/src/test/osd/TestECBackend.cc index 082a7dd1d52..697f4a1a995 100644 --- a/src/test/osd/TestECBackend.cc +++ b/src/test/osd/TestECBackend.cc @@ -56,7 +56,7 @@ TEST(ECUtil, stripe_info_t) ASSERT_EQ(s.aligned_ro_offset_to_chunk_offset(2*swidth), 2*s.get_chunk_size()); - ASSERT_EQ(s.chunk_aligned_shard_offset_to_ro_offset(2*s.get_chunk_size()), + ASSERT_EQ(s.shard_offset_to_ro_offset(shard_id_t(0), 2*s.get_chunk_size()), 2*s.get_stripe_width()); // Stripe 1 + 1 chunk for 10 stripes needs to read 11 stripes starting -- 2.39.5