]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/os/seastore: avoid segment nonce collision
authorZhang Song <zhangsong325@gmail.com>
Mon, 3 Apr 2023 11:29:27 +0000 (19:29 +0800)
committerMatan Breizman <mbreizma@redhat.com>
Sun, 21 May 2023 09:11:55 +0000 (09:11 +0000)
Signed-off-by: Zhang Song <zhangsong325@gmail.com>
(cherry picked from commit 367577efa7440d6d7414b9772a3b130109852535)

src/crimson/os/seastore/journal/segment_allocator.cc

index 5aeaad05c942b36efa0339f6a2bc29f132ea3302..7ecbf486763125ef5c2df521226f681d3289926a 100644 (file)
@@ -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<uint32_t>::max() >> 1;
+  crc |= static_cast<uint32_t>(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<const unsigned char *>(meta.seastore_id.bytes()),
     sizeof(meta.seastore_id.uuid));