From: Kefu Chai Date: Mon, 15 Apr 2019 06:01:00 +0000 (+0800) Subject: mgr/DaemonServer: use ref_t X-Git-Tag: v15.1.0~2896^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a075639ce746fe12cde1a3df8ad7b13c3fd9baf6;p=ceph.git mgr/DaemonServer: use ref_t to avoid explicit use of RefCountedObj interface. and let intrusive_ptr<> to take care of the life cycle of messages. Signed-off-by: Kefu Chai --- diff --git a/src/messages/MMgrOpen.h b/src/messages/MMgrOpen.h index a55ebaa7661f..c5061a281cae 100644 --- a/src/messages/MMgrOpen.h +++ b/src/messages/MMgrOpen.h @@ -88,6 +88,8 @@ private: MMgrOpen() : Message{MSG_MGR_OPEN, HEAD_VERSION, COMPAT_VERSION} {} + using RefCountedObject::put; + using RefCountedObject::get; template friend boost::intrusive_ptr ceph::make_message(Args&&... args); }; diff --git a/src/messages/MMgrReport.h b/src/messages/MMgrReport.h index 3de4720a9a9a..150c1c1c1892 100644 --- a/src/messages/MMgrReport.h +++ b/src/messages/MMgrReport.h @@ -164,10 +164,12 @@ public: out << ")"; } +private: MMgrReport() : Message{MSG_MGR_REPORT, HEAD_VERSION, COMPAT_VERSION} {} -private: + using RefCountedObject::put; + using RefCountedObject::get; template friend boost::intrusive_ptr ceph::make_message(Args&&... args); }; diff --git a/src/mgr/ClusterState.cc b/src/mgr/ClusterState.cc index 7e073a58bcc0..a74fa4feb141 100644 --- a/src/mgr/ClusterState.cc +++ b/src/mgr/ClusterState.cc @@ -64,7 +64,7 @@ void ClusterState::load_digest(MMgrDigest *m) mon_status_json = std::move(m->mon_status_json); } -void ClusterState::ingest_pgstats(MPGStats *stats) +void ClusterState::ingest_pgstats(ref_t stats) { std::lock_guard l(lock); diff --git a/src/mgr/ClusterState.h b/src/mgr/ClusterState.h index c5d46fa1abfd..4d43cddbe896 100644 --- a/src/mgr/ClusterState.h +++ b/src/mgr/ClusterState.h @@ -53,7 +53,7 @@ protected: public: void load_digest(MMgrDigest *m); - void ingest_pgstats(MPGStats *stats); + void ingest_pgstats(ceph::ref_t stats); void update_delta_stats(); diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index de867c620d77..c8db6652e616 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -252,25 +252,24 @@ bool DaemonServer::ms_handle_refused(Connection *con) return false; } -bool DaemonServer::ms_dispatch(Message *m) +bool DaemonServer::ms_dispatch2(const ref_t& m) { // Note that we do *not* take ::lock here, in order to avoid // serializing all message handling. It's up to each handler // to take whatever locks it needs. switch (m->get_type()) { case MSG_PGSTATS: - cluster_state.ingest_pgstats(static_cast(m)); + cluster_state.ingest_pgstats(ref_cast(m)); maybe_ready(m->get_source().num()); - m->put(); return true; case MSG_MGR_REPORT: - return handle_report(static_cast(m)); + return handle_report(ref_cast(m)); case MSG_MGR_OPEN: - return handle_open(static_cast(m)); + return handle_open(ref_cast(m)); case MSG_MGR_CLOSE: - return handle_close(static_cast(m)); + return handle_close(ref_cast(m)); case MSG_COMMAND: - return handle_command(static_cast(m)); + return handle_command(ref_cast(m)); default: dout(1) << "Unhandled message type " << m->get_type() << dendl; return false; @@ -406,7 +405,7 @@ static bool key_from_string( return true; } -bool DaemonServer::handle_open(MMgrOpen *m) +bool DaemonServer::handle_open(const ref_t& m) { std::lock_guard l(lock); @@ -477,11 +476,10 @@ bool DaemonServer::handle_open(MMgrOpen *m) daemon_connections.insert(m->get_connection()); } - m->put(); return true; } -bool DaemonServer::handle_close(MMgrClose *m) +bool DaemonServer::handle_close(const ref_t& m) { std::lock_guard l(lock); @@ -503,11 +501,11 @@ bool DaemonServer::handle_close(MMgrClose *m) } // send same message back as a reply - m->get_connection()->send_message(m); + m->get_connection()->send_message2(m); return true; } -bool DaemonServer::handle_report(MMgrReport *m) +bool DaemonServer::handle_report(const ref_t& m) { DaemonKey key; if (!m->service_name.empty()) { @@ -526,7 +524,6 @@ bool DaemonServer::handle_report(MMgrReport *m) dout(4) << "rejecting report from non-daemon client " << m->daemon_name << dendl; m->get_connection()->mark_down(); - m->put(); return true; } @@ -635,7 +632,6 @@ bool DaemonServer::handle_report(MMgrReport *m) osd_perf_metric_collector.process_reports(m->osd_perf_metric_reports); } - m->put(); return true; } @@ -715,16 +711,12 @@ bool DaemonServer::_allowed_command( */ class CommandContext { public: - MCommand *m; + ceph::ref_t m; bufferlist odata; cmdmap_t cmdmap; - explicit CommandContext(MCommand *m_) - : m(m_) { - } - - ~CommandContext() { - m->put(); + explicit CommandContext(ceph::ref_t m) + : m{std::move(m)} { } void reply(int r, const std::stringstream &ss) { @@ -772,10 +764,10 @@ public: } }; -bool DaemonServer::handle_command(MCommand *m) +bool DaemonServer::handle_command(const ref_t& m) { std::lock_guard l(lock); - std::shared_ptr cmdctx = std::make_shared(m); + auto cmdctx = std::make_shared(m); try { return _handle_command(m, cmdctx); } catch (const bad_cmd_get& e) { @@ -785,7 +777,7 @@ bool DaemonServer::handle_command(MCommand *m) } bool DaemonServer::_handle_command( - MCommand *m, + const ref_t& m, std::shared_ptr& cmdctx) { auto priv = m->get_connection()->get_priv(); diff --git a/src/mgr/DaemonServer.h b/src/mgr/DaemonServer.h index 310a030b1b59..b728fabad8d6 100644 --- a/src/mgr/DaemonServer.h +++ b/src/mgr/DaemonServer.h @@ -137,7 +137,7 @@ public: LogChannelRef auditcl); ~DaemonServer() override; - bool ms_dispatch(Message *m) override; + bool ms_dispatch2(const ceph::ref_t& m) override; int ms_handle_authentication(Connection *con) override; bool ms_handle_reset(Connection *con) override; void ms_handle_remote_reset(Connection *con) override {} @@ -145,11 +145,12 @@ public: bool ms_get_authorizer(int dest_type, AuthAuthorizer **authorizer) override; KeyStore *ms_get_auth1_authorizer_keystore() override; - bool handle_open(MMgrOpen *m); - bool handle_close(MMgrClose *m); - bool handle_report(MMgrReport *m); - bool handle_command(MCommand *m); - bool _handle_command(MCommand *m, std::shared_ptr& cmdctx); + bool handle_open(const ceph::ref_t& m); + bool handle_close(const ceph::ref_t& m); + bool handle_report(const ceph::ref_t& m); + bool handle_command(const ceph::ref_t& m); + bool _handle_command(const ceph::ref_t& m, + std::shared_ptr& cmdctx); void send_report(); void got_service_map(); void got_mgr_map();