From 0d1b69a32cf3711d3ad9a1f175248630ec621488 Mon Sep 17 00:00:00 2001 From: Sun Yuechi Date: Thu, 25 Jun 2026 21:39:11 +0800 Subject: [PATCH 1/2] osd/ECUtil: fix slice bounds in slice_map() slice_map() accumulated the slice bounds against the wrong operands, and included parity shards in ro_start and ro_end, which only track data. Introduced by 9e2841ab167 ("osd: Introduce optimized EC"). Signed-off-by: Sun Yuechi --- src/osd/ECUtil.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/osd/ECUtil.cc b/src/osd/ECUtil.cc index 68ae458331a..74b58b1444a 100644 --- a/src/osd/ECUtil.cc +++ b/src/osd/ECUtil.cc @@ -810,14 +810,15 @@ shard_extent_map_t shard_extent_map_t::slice_map( extent_map iemap = emap.intersect(offset, length); if (!iemap.empty()) { + raw_shard_id_t raw_shard = sinfo->get_raw_shard(shard); slice.start_offset = min(slice.start_offset, iemap.get_start_off()); - slice.end_offset = max(slice.start_offset, iemap.get_end_off()); - slice.ro_start = min(slice.start_offset, - calc_ro_offset(sinfo->get_raw_shard(shard), - iemap.get_start_off())); - slice.ro_end = min(slice.ro_end, - calc_ro_end(sinfo->get_raw_shard(shard), - iemap.get_end_off())); + slice.end_offset = max(slice.end_offset, iemap.get_end_off()); + if (raw_shard < sinfo->get_k()) { + slice.ro_start = min(slice.ro_start, + calc_ro_offset(raw_shard, iemap.get_start_off())); + slice.ro_end = max(slice.ro_end, + calc_ro_end(raw_shard, iemap.get_end_off())); + } slice.extent_maps.emplace(shard, iemap); } } From 84fc350a1fa877e28aed36f87654d144e549be06 Mon Sep 17 00:00:00 2001 From: Alex Ainscow Date: Tue, 14 Jul 2026 02:08:02 -0700 Subject: [PATCH 2/2] test/osd: check the offset cache after slice_map() Recompute ro_start and ro_end with compute_ro_range() and compare them against the cached values, and cover single-shard maps. Signed-off-by: Sun Yuechi --- src/test/osd/TestECUtil.cc | 46 +++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/test/osd/TestECUtil.cc b/src/test/osd/TestECUtil.cc index 38b4b625b93..d576cfb9186 100644 --- a/src/test/osd/TestECUtil.cc +++ b/src/test/osd/TestECUtil.cc @@ -24,6 +24,17 @@ using namespace std; using namespace ECUtil; +namespace { + +void verify_offset_cache(const shard_extent_map_t& sem) +{ + shard_extent_map_t cached = sem; + cached.compute_ro_range(); + ASSERT_EQ(cached, sem); +} + +} // anonymous namespace + TEST(ECUtil, stripe_info_t) { const uint64_t swidth = 4096; @@ -1051,28 +1062,31 @@ TEST(ECUtil, slice) { auto slice_map = sem.slice_map(512, 1024); ASSERT_EQ(4, slice_map.get_extent_maps().size()); - ASSERT_EQ(512, slice_map.get_start_offset()); - ASSERT_EQ(512+1024, slice_map.get_end_offset()); + verify_offset_cache(slice_map); + } - for (int i=1; i<5; i++) { - ASSERT_EQ(512, slice_map.get_extent_map(shard_id_t(i)).get_start_off()); - ASSERT_EQ(512+1024, slice_map.get_extent_map(shard_id_t(i)).get_end_off()); - } + { + shard_extent_map_t single(&sinfo); + single.insert_in_shard(shard_id_t(1), 512, bl1k); + + auto slice_map = single.slice_map(512, 1024); + ASSERT_EQ(1, slice_map.get_extent_maps().size()); + verify_offset_cache(slice_map); + } + + { + shard_extent_map_t single(&sinfo); + single.insert_in_shard(shard_id_t(1), 512, bl1k); + + auto slice_map = single.slice_map(0, 4096); + ASSERT_EQ(1, slice_map.get_extent_maps().size()); + verify_offset_cache(slice_map); } { auto slice_map = sem.slice_map(0, 4096); ASSERT_EQ(4, slice_map.get_extent_maps().size()); - ASSERT_EQ(5, slice_map.get_start_offset()); - ASSERT_EQ(4096, slice_map.get_end_offset()); - ASSERT_EQ(512, slice_map.get_extent_map(shard_id_t(1)).get_start_off()); - ASSERT_EQ(512 + 1024, slice_map.get_extent_map(shard_id_t(1)).get_end_off()); - ASSERT_EQ(5, slice_map.get_extent_map(shard_id_t(2)).get_start_off()); - ASSERT_EQ(4096, slice_map.get_extent_map(shard_id_t(2)).get_end_off()); - ASSERT_EQ(256, slice_map.get_extent_map(shard_id_t(3)).get_start_off()); - ASSERT_EQ(4096, slice_map.get_extent_map(shard_id_t(3)).get_end_off()); - ASSERT_EQ(5, slice_map.get_extent_map(shard_id_t(4)).get_start_off()); - ASSERT_EQ(4096, slice_map.get_extent_map(shard_id_t(4)).get_end_off()); + verify_offset_cache(slice_map); } {