From: Zhang Song Date: Mon, 3 Apr 2023 11:29:27 +0000 (+0800) Subject: crimson/os/seastore: avoid segment nonce collision X-Git-Tag: v18.1.0~80^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=beb4812fa5b27999940e025fde8d591349c321bf;p=ceph-ci.git crimson/os/seastore: avoid segment nonce collision Signed-off-by: Zhang Song (cherry picked from commit 367577efa7440d6d7414b9772a3b130109852535) --- 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));