From 74928b306fc7c7f750cd35918795dcc049642577 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Fri, 29 Aug 2025 09:35:15 -0400 Subject: [PATCH] msg/async: move v1 member init to header Signed-off-by: Patrick Donnelly --- src/msg/async/ProtocolV1.cc | 31 ++++++++++--------------------- src/msg/async/ProtocolV1.h | 25 +++++++++++++------------ 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/msg/async/ProtocolV1.cc b/src/msg/async/ProtocolV1.cc index fc4f2b483d7..9e0e740ec80 100644 --- a/src/msg/async/ProtocolV1.cc +++ b/src/msg/async/ProtocolV1.cc @@ -62,28 +62,16 @@ static void alloc_aligned_buffer(ceph::buffer::list &data, unsigned len, unsigne **/ ProtocolV1::ProtocolV1(AsyncConnection *connection) - : Protocol(1, connection), - temp_buffer(nullptr), - can_write(WriteStatus::NOWRITE), - keepalive(false), - connect_seq(0), - peer_global_seq(0), - msg_left(0), - cur_msg_size(0), - replacing(false), - is_reset_from_peer(false), - once_ready(false), - state(NONE), - global_seq(0), - wait_for_seq(false) { - temp_buffer = new char[4096]; -} - -ProtocolV1::~ProtocolV1() { + : Protocol(1, connection) +{ + ldout(cct, 5) << "con" << dendl; +} + +ProtocolV1::~ProtocolV1() +{ + ldout(cct, 5) << "des" << dendl; ceph_assert(out_q.empty()); ceph_assert(sent.empty()); - - delete[] temp_buffer; } void ProtocolV1::connect() { @@ -439,7 +427,8 @@ void ProtocolV1::run_continuation(CtPtr pcontinuation) { CtPtr ProtocolV1::read(CONTINUATION_RX_TYPE &next, int len, char *buffer) { if (!buffer) { - buffer = temp_buffer; + /* FIXME: why not len = sizeof temp_buffer??? */ + buffer = temp_buffer.data(); } ssize_t r = connection->read(len, buffer, [&next, this](char *buffer, int r) { diff --git a/src/msg/async/ProtocolV1.h b/src/msg/async/ProtocolV1.h index 200d01ad35c..01a3c66b903 100644 --- a/src/msg/async/ProtocolV1.h +++ b/src/msg/async/ProtocolV1.h @@ -104,10 +104,10 @@ protected: return statenames[state]; } - char *temp_buffer; + std::array temp_buffer; enum class WriteStatus { NOWRITE, REPLACING, CANWRITE, CLOSED }; - std::atomic can_write; + std::atomic can_write = WriteStatus::NOWRITE; std::deque sent; // the first ceph::buffer::list need to inject seq //struct for outbound msgs struct out_q_entry_t { @@ -122,10 +122,11 @@ protected: */ std::map, std::greater> out_q; - bool keepalive; + bool keepalive = false; bool write_in_progress = false; - __u32 connect_seq, peer_global_seq; + __u32 connect_seq = 0; + __u32 peer_global_seq = 0; std::atomic in_seq{0}; std::atomic out_seq{0}; std::atomic ack_left{0}; @@ -141,23 +142,23 @@ protected: utime_t backoff; // backoff time utime_t recv_stamp; utime_t throttle_stamp; - unsigned msg_left; - uint64_t cur_msg_size; + unsigned msg_left = 0; + uint64_t cur_msg_size = 0; ceph_msg_header current_header; ceph::buffer::list data_buf; ceph::buffer::list::iterator data_blp; ceph::buffer::list front, middle, data; - bool replacing; // when replacing process happened, we will reply connect + bool replacing = false; // when replacing process happened, we will reply connect // side with RETRY tag and accept side will clear replaced // connection. So when connect side reissue connect_msg, // there won't exists conflicting connection so we use // "replacing" to skip RESETSESSION to avoid detect wrong // presentation - bool is_reset_from_peer; - bool once_ready; + bool is_reset_from_peer = false; + bool once_ready = false; - State state; + State state = NONE; void run_continuation(CtPtr pcontinuation); CtPtr read(CONTINUATION_RX_TYPE &next, int len, @@ -243,7 +244,7 @@ public: // Client Protocol private: - int global_seq; + int global_seq = 0; CONTINUATION_DECL(ProtocolV1, send_client_banner); WRITE_HANDLER_CONTINUATION_DECL(ProtocolV1, handle_client_banner_write); @@ -275,7 +276,7 @@ private: // Server Protocol protected: - bool wait_for_seq; + bool wait_for_seq = false; CONTINUATION_DECL(ProtocolV1, send_server_banner); WRITE_HANDLER_CONTINUATION_DECL(ProtocolV1, handle_server_banner_write); -- 2.47.3