Merge pull request #50840 from zhscn/segment-nonce-collision

crimson/os/seatore: avoid segment nonce collision

Reviewed-by: Yingxin Cheng <yingxin.cheng@intel.com>
This commit is contained in:
Yingxin 2023-04-12 14:22:56 +08:00 committed by GitHub
commit 094206c554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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;

View 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));