From 1933acdd3602abaa12bbeedda9b4b113c1b0c096 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Fri, 8 Mar 2019 19:19:23 +0100 Subject: [PATCH] msg/async, v2: reintroduce segment aligment. It's compile-time now. Signed-off-by: Radoslaw Zarzynski --- src/msg/async/frames_v2.h | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/msg/async/frames_v2.h b/src/msg/async/frames_v2.h index 0a915338ddc..de344f534f1 100644 --- a/src/msg/async/frames_v2.h +++ b/src/msg/async/frames_v2.h @@ -163,13 +163,17 @@ static ceph::bufferlist segment_onwire_bufferlist(ceph::bufferlist&& bl) return bl; } -template +template struct Frame { + static constexpr size_t SegmentsNumV = sizeof...(SegmentAlignmentVs); static_assert(SegmentsNumV > 0 && SegmentsNumV <= MAX_NUM_SEGMENTS); protected: std::array segments; private: + static constexpr std::array alignments { + SegmentAlignmentVs... + }; ceph::bufferlist::contiguous_filler preamble_filler; // craft the main preamble. It's always present regardless of the number @@ -188,16 +192,15 @@ private: // just our private detail. main_preamble.segments.front().length = segments.front().length() - FRAME_PREAMBLE_SIZE; - main_preamble.segments.front().alignment = segment_t::DEFAULT_ALIGNMENT; + main_preamble.segments.front().alignment = alignments.front(); if constexpr(SegmentsNumV > 1) { - for (__u8 idx = 1; idx < std::size(segments); idx++) { + for (__u8 idx = 1; idx < SegmentsNumV; idx++) { main_preamble.segments[idx].length = segments[idx].length(); - // TODO: arg pack for Frame carrying alignments - main_preamble.segments[idx].alignment = segment_t::DEFAULT_ALIGNMENT; + main_preamble.segments[idx].alignment = alignments[idx]; } } - main_preamble.num_segments = std::size(segments); + main_preamble.num_segments = SegmentsNumV; main_preamble.crc = ceph_crc32c(0, reinterpret_cast(&main_preamble), @@ -260,7 +263,7 @@ public: epilogue.crc_values[SegmentIndex::Control::PAYLOAD] = hdriter.crc32c(hdriter.get_remaining(), -1); if constexpr(SegmentsNumV > 1) { - for (__u8 idx = 1; idx < std::size(segments); idx++) { + for (__u8 idx = 1; idx < SegmentsNumV; idx++) { epilogue.crc_values[idx] = segments[idx].crc32c(-1); } } @@ -287,7 +290,7 @@ public: // marshalling facilities -- derived classes specify frame structure through // Args pack while ControlFrame provides common encode/decode machinery. template -class ControlFrame : public Frame { +class ControlFrame : public Frame { protected: ceph::bufferlist &get_payload_segment() { return this->segments[SegmentIndex::Control::PAYLOAD]; @@ -349,7 +352,9 @@ protected: return std::get(_values); } - ControlFrame() : Frame() {} + ControlFrame() + : Frame() { + } void _encode(const Args &... args) { (_encode_payload_each(args), ...); @@ -656,8 +661,12 @@ protected: // This class is used for encoding/decoding header of the message frame. // Body is processed almost independently with the sole junction point // being the `extra_payload_len` passed to get_buffer(). -struct MessageFrame - : public Frame { +struct MessageFrame : public Frame { static const Tag tag = Tag::MESSAGE; static MessageFrame Encode(const ceph_msg_header2 &msg_header, -- 2.39.5