From 367577efa7440d6d7414b9772a3b130109852535 Mon Sep 17 00:00:00 2001 From: Zhang Song Date: Mon, 3 Apr 2023 19:29:27 +0800 Subject: [PATCH 1/2] crimson/os/seastore: avoid segment nonce collision Signed-off-by: Zhang Song --- .../os/seastore/journal/segment_allocator.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/crimson/os/seastore/journal/segment_allocator.cc b/src/crimson/os/seastore/journal/segment_allocator.cc index 5aeaad05c94..7ecbf486763 100644 --- a/src/crimson/os/seastore/journal/segment_allocator.cc +++ b/src/crimson/os/seastore/journal/segment_allocator.cc @@ -33,6 +33,17 @@ SegmentAllocator::SegmentAllocator( reset(); } +segment_nonce_t calc_new_nonce( + segment_type_t type, + uint32_t crc, + unsigned char const *data, + unsigned length) +{ + crc &= std::numeric_limits::max() >> 1; + crc |= static_cast(type) << 31; + return ceph_crc32c(crc, data, length); +} + SegmentAllocator::open_ret SegmentAllocator::do_open(bool is_mkfs) { @@ -41,7 +52,8 @@ SegmentAllocator::do_open(bool is_mkfs) segment_seq_t new_segment_seq = segment_seq_allocator.get_and_inc_next_segment_seq(); auto meta = sm_group.get_meta(); - current_segment_nonce = ceph_crc32c( + current_segment_nonce = calc_new_nonce( + type, new_segment_seq, reinterpret_cast(meta.seastore_id.bytes()), sizeof(meta.seastore_id.uuid)); From b890de1c2fe489e05804a2724ad3493c0114732e Mon Sep 17 00:00:00 2001 From: Zhang Song Date: Tue, 4 Apr 2023 09:34:06 +0800 Subject: [PATCH 2/2] crimson/os/seastore: check the type of segment head and segment tail during mount Signed-off-by: Zhang Song --- src/crimson/os/seastore/async_cleaner.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/crimson/os/seastore/async_cleaner.cc b/src/crimson/os/seastore/async_cleaner.cc index e51e499ef8c..4bac744e4a0 100644 --- a/src/crimson/os/seastore/async_cleaner.cc +++ b/src/crimson/os/seastore/async_cleaner.cc @@ -1314,6 +1314,7 @@ SegmentCleaner::mount_ret SegmentCleaner::mount() if (tail.segment_nonce != header.segment_nonce) { return scan_no_tail_segment(header, segment_id); } + ceph_assert(header.get_type() == tail.get_type()); sea_time_point modify_time = mod_to_timepoint(tail.modify_time); std::size_t num_extents = tail.num_extents;