From 583e7976cc1131ed1bf662f20a913cf7e0ebe270 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Tue, 14 Aug 2018 13:00:38 -0700 Subject: [PATCH] msg: add msgref cast method Signed-off-by: Patrick Donnelly --- src/mds/Beacon.cc | 2 +- src/mds/Locker.cc | 16 ++++++++-------- src/mds/MDBalancer.cc | 2 +- src/mds/MDCache.cc | 30 +++++++++++++++--------------- src/mds/MDSDaemon.cc | 4 ++-- src/mds/MDSRank.cc | 2 +- src/mds/Migrator.cc | 26 +++++++++++++------------- src/mds/Server.cc | 10 +++++----- src/msg/Message.h | 14 ++++++++++++++ 9 files changed, 60 insertions(+), 46 deletions(-) diff --git a/src/mds/Beacon.cc b/src/mds/Beacon.cc index 6603ca3eb6ba6..18562976b80a1 100644 --- a/src/mds/Beacon.cc +++ b/src/mds/Beacon.cc @@ -92,7 +92,7 @@ bool Beacon::ms_dispatch2(const Message::ref& m) { if (m->get_type() == MSG_MDS_BEACON) { if (m->get_connection()->get_peer_type() == CEPH_ENTITY_TYPE_MON) { - handle_mds_beacon(boost::static_pointer_cast::type::element_type>(m)); + handle_mds_beacon(MMDSBeacon::msgref_cast(m)); } return true; } diff --git a/src/mds/Locker.cc b/src/mds/Locker.cc index 97f92c1938b69..84eaa75311858 100644 --- a/src/mds/Locker.cc +++ b/src/mds/Locker.cc @@ -95,21 +95,21 @@ void Locker::dispatch(const Message::const_ref &m) switch (m->get_type()) { // inter-mds locking case MSG_MDS_LOCK: - handle_lock(boost::static_pointer_cast::type::element_type>(m)); + handle_lock(MLock::msgref_cast(m)); break; // inter-mds caps case MSG_MDS_INODEFILECAPS: - handle_inode_file_caps(boost::static_pointer_cast::type::element_type>(m)); + handle_inode_file_caps(MInodeFileCaps::msgref_cast(m)); break; // client sync case CEPH_MSG_CLIENT_CAPS: - handle_client_caps(boost::static_pointer_cast::type::element_type>(m)); + handle_client_caps(MClientCaps::msgref_cast(m)); break; case CEPH_MSG_CLIENT_CAPRELEASE: - handle_client_cap_release(boost::static_pointer_cast::type::element_type>(m)); + handle_client_cap_release(MClientCapRelease::msgref_cast(m)); break; case CEPH_MSG_CLIENT_LEASE: - handle_client_lease(boost::static_pointer_cast::type::element_type>(m)); + handle_client_lease(MClientLease::msgref_cast(m)); break; default: derr << "locker unknown message " << m->get_type() << dendl; @@ -2644,7 +2644,7 @@ void Locker::handle_client_caps(const MClientCaps::const_ref &m) << " op " << ceph_cap_op_name(op) << " flags 0x" << std::hex << m->flags << std::dec << dendl; - Session *session = mds->get_session(boost::static_pointer_cast::type::element_type>(m)); + Session *session = mds->get_session(m); if (!mds->is_clientreplay() && !mds->is_active() && !mds->is_stopping()) { if (!session) { dout(5) << " no session, dropping " << *m << dendl; @@ -3371,7 +3371,7 @@ bool Locker::_do_cap_update(CInode *in, Capability *cap, if (!dirty && !change_max) return false; - Session *session = mds->get_session(boost::static_pointer_cast::type::element_type>(m)); + Session *session = mds->get_session(m); if (session->check_access(in, MAY_WRITE, m->caller_uid, m->caller_gid, NULL, 0, 0) < 0) { dout(10) << "check_access failed, dropping cap update on " << *in << dendl; @@ -3466,7 +3466,7 @@ void Locker::handle_client_cap_release(const MClientCapRelease::const_ref &m) mds->set_osd_epoch_barrier(m->osd_epoch_barrier); } - Session *session = mds->get_session(boost::static_pointer_cast::type::element_type>(m)); + Session *session = mds->get_session(m); for (const auto &cap : m->caps) { _do_cap_release(client, inodeno_t((uint64_t)cap.ino) , cap.cap_id, cap.migrate_seq, cap.seq); diff --git a/src/mds/MDBalancer.cc b/src/mds/MDBalancer.cc index c5374999b3229..66ddbd69fe9c6 100644 --- a/src/mds/MDBalancer.cc +++ b/src/mds/MDBalancer.cc @@ -64,7 +64,7 @@ int MDBalancer::proc_message(const Message::const_ref &m) switch (m->get_type()) { case MSG_MDS_HEARTBEAT: - handle_heartbeat(boost::static_pointer_cast::type::element_type>(m)); + handle_heartbeat(MHeartbeat::msgref_cast(m)); break; default: diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index c797d7e9f78ee..d7a44f5f11f97 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -7854,59 +7854,59 @@ void MDCache::dispatch(const Message::const_ref &m) // RESOLVE case MSG_MDS_RESOLVE: - handle_resolve(boost::static_pointer_cast::type::element_type>(m)); + handle_resolve(MMDSResolve::msgref_cast(m)); break; case MSG_MDS_RESOLVEACK: - handle_resolve_ack(boost::static_pointer_cast::type::element_type>(m)); + handle_resolve_ack(MMDSResolveAck::msgref_cast(m)); break; // REJOIN case MSG_MDS_CACHEREJOIN: - handle_cache_rejoin(boost::static_pointer_cast::type::element_type>(m)); + handle_cache_rejoin(MMDSCacheRejoin::msgref_cast(m)); break; case MSG_MDS_DISCOVER: - handle_discover(boost::static_pointer_cast::type::element_type>(m)); + handle_discover(MDiscover::msgref_cast(m)); break; case MSG_MDS_DISCOVERREPLY: - handle_discover_reply(boost::static_pointer_cast::type::element_type>(m)); + handle_discover_reply(MDiscoverReply::msgref_cast(m)); break; case MSG_MDS_DIRUPDATE: - handle_dir_update(boost::static_pointer_cast::type::element_type>(m)); + handle_dir_update(MDirUpdate::msgref_cast(m)); break; case MSG_MDS_CACHEEXPIRE: - handle_cache_expire(boost::static_pointer_cast::type::element_type>(m)); + handle_cache_expire(MCacheExpire::msgref_cast(m)); break; case MSG_MDS_DENTRYLINK: - handle_dentry_link(boost::static_pointer_cast::type::element_type>(m)); + handle_dentry_link(MDentryLink::msgref_cast(m)); break; case MSG_MDS_DENTRYUNLINK: - handle_dentry_unlink(boost::static_pointer_cast::type::element_type>(m)); + handle_dentry_unlink(MDentryUnlink::msgref_cast(m)); break; case MSG_MDS_FRAGMENTNOTIFY: - handle_fragment_notify(boost::static_pointer_cast::type::element_type>(m)); + handle_fragment_notify(MMDSFragmentNotify::msgref_cast(m)); break; case MSG_MDS_FINDINO: - handle_find_ino(boost::static_pointer_cast::type::element_type>(m)); + handle_find_ino(MMDSFindIno::msgref_cast(m)); break; case MSG_MDS_FINDINOREPLY: - handle_find_ino_reply(boost::static_pointer_cast::type::element_type>(m)); + handle_find_ino_reply(MMDSFindInoReply::msgref_cast(m)); break; case MSG_MDS_OPENINO: - handle_open_ino(boost::static_pointer_cast::type::element_type>(m)); + handle_open_ino(MMDSOpenIno::msgref_cast(m)); break; case MSG_MDS_OPENINOREPLY: - handle_open_ino_reply(boost::static_pointer_cast::type::element_type>(m)); + handle_open_ino_reply(MMDSOpenInoReply::msgref_cast(m)); break; case MSG_MDS_SNAPUPDATE: - handle_snap_update(boost::static_pointer_cast::type::element_type>(m)); + handle_snap_update(MMDSSnapUpdate::msgref_cast(m)); break; default: diff --git a/src/mds/MDSDaemon.cc b/src/mds/MDSDaemon.cc index 9422e165e200e..763b3b2d03308 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -1184,12 +1184,12 @@ bool MDSDaemon::handle_core_message(const Message::const_ref &m) // MDS case CEPH_MSG_MDS_MAP: ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MON | CEPH_ENTITY_TYPE_MDS); - handle_mds_map(boost::static_pointer_cast::type::element_type>(m)); + handle_mds_map(MMDSMap::msgref_cast(m)); break; // OSD case MSG_COMMAND: - handle_command(boost::static_pointer_cast::type::element_type>(m)); + handle_command(MCommand::msgref_cast(m)); break; case CEPH_MSG_OSD_MAP: ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MON | CEPH_ENTITY_TYPE_OSD); diff --git a/src/mds/MDSRank.cc b/src/mds/MDSRank.cc index 97fcef51b177e..5563d33245afb 100644 --- a/src/mds/MDSRank.cc +++ b/src/mds/MDSRank.cc @@ -769,7 +769,7 @@ bool MDSRank::handle_deferrable_message(const Message::const_ref &m) case MSG_MDS_TABLE_REQUEST: ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MDS); { - const MMDSTableRequest::const_ref &req = boost::static_pointer_cast::type::element_type>(m); + const MMDSTableRequest::const_ref &req = MMDSTableRequest::msgref_cast(m); if (req->op < 0) { MDSTableClient *client = get_table_client(req->table); client->handle_request(req); diff --git a/src/mds/Migrator.cc b/src/mds/Migrator.cc index 1150ff31b0d81..d529645c3381d 100644 --- a/src/mds/Migrator.cc +++ b/src/mds/Migrator.cc @@ -96,54 +96,54 @@ void Migrator::dispatch(const Message::const_ref &m) switch (m->get_type()) { // import case MSG_MDS_EXPORTDIRDISCOVER: - handle_export_discover(boost::static_pointer_cast::type::element_type>(m)); + handle_export_discover(MExportDirDiscover::msgref_cast(m)); break; case MSG_MDS_EXPORTDIRPREP: - handle_export_prep(boost::static_pointer_cast::type::element_type>(m)); + handle_export_prep(MExportDirPrep::msgref_cast(m)); break; case MSG_MDS_EXPORTDIR: if (unlikely(inject_session_race)) { dout(0) << "waiting for inject_session_race" << dendl; mds->wait_for_any_client_connection(new C_MDS_RetryMessage(mds, m)); } else { - handle_export_dir(boost::static_pointer_cast::type::element_type>(m)); + handle_export_dir(MExportDir::msgref_cast(m)); } break; case MSG_MDS_EXPORTDIRFINISH: - handle_export_finish(boost::static_pointer_cast::type::element_type>(m)); + handle_export_finish(MExportDirFinish::msgref_cast(m)); break; case MSG_MDS_EXPORTDIRCANCEL: - handle_export_cancel(boost::static_pointer_cast::type::element_type>(m)); + handle_export_cancel(MExportDirCancel::msgref_cast(m)); break; // export case MSG_MDS_EXPORTDIRDISCOVERACK: - handle_export_discover_ack(boost::static_pointer_cast::type::element_type>(m)); + handle_export_discover_ack(MExportDirDiscoverAck::msgref_cast(m)); break; case MSG_MDS_EXPORTDIRPREPACK: - handle_export_prep_ack(boost::static_pointer_cast::type::element_type>(m)); + handle_export_prep_ack(MExportDirPrepAck::msgref_cast(m)); break; case MSG_MDS_EXPORTDIRACK: - handle_export_ack(boost::static_pointer_cast::type::element_type>(m)); + handle_export_ack(MExportDirAck::msgref_cast(m)); break; case MSG_MDS_EXPORTDIRNOTIFYACK: - handle_export_notify_ack(boost::static_pointer_cast::type::element_type>(m)); + handle_export_notify_ack(MExportDirNotifyAck::msgref_cast(m)); break; // export 3rd party (dir_auth adjustments) case MSG_MDS_EXPORTDIRNOTIFY: - handle_export_notify(boost::static_pointer_cast::type::element_type>(m)); + handle_export_notify(MExportDirNotify::msgref_cast(m)); break; // caps case MSG_MDS_EXPORTCAPS: - handle_export_caps(boost::static_pointer_cast::type::element_type>(m)); + handle_export_caps(MExportCaps::msgref_cast(m)); break; case MSG_MDS_EXPORTCAPSACK: - handle_export_caps_ack(boost::static_pointer_cast::type::element_type>(m)); + handle_export_caps_ack(MExportCapsAck::msgref_cast(m)); break; case MSG_MDS_GATHERCAPS: - handle_gather_caps(boost::static_pointer_cast::type::element_type>(m)); + handle_gather_caps(MGatherCaps::msgref_cast(m)); break; default: diff --git a/src/mds/Server.cc b/src/mds/Server.cc index e9ff4a5278b96..008a1ebacc87b 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -184,14 +184,14 @@ void Server::dispatch(const Message::const_ref &m) { switch (m->get_type()) { case CEPH_MSG_CLIENT_RECONNECT: - handle_client_reconnect(boost::static_pointer_cast::type::element_type>(m)); + handle_client_reconnect(MClientReconnect::msgref_cast(m)); return; } // active? // handle_slave_request()/handle_client_session() will wait if necessary if (m->get_type() == CEPH_MSG_CLIENT_REQUEST && !mds->is_active()) { - const auto &req = boost::static_pointer_cast::type::element_type>(m); + const auto &req = MClientRequest::msgref_cast(m); if (mds->is_reconnect() || mds->get_want_state() == CEPH_MDS_STATE_RECONNECT) { Session *session = mds->get_session(req); if (!session || session->is_closed()) { @@ -242,13 +242,13 @@ void Server::dispatch(const Message::const_ref &m) switch (m->get_type()) { case CEPH_MSG_CLIENT_SESSION: - handle_client_session(boost::static_pointer_cast::type::element_type>(m)); + handle_client_session(MClientSession::msgref_cast(m)); return; case CEPH_MSG_CLIENT_REQUEST: - handle_client_request(boost::static_pointer_cast::type::element_type>(m)); + handle_client_request(MClientRequest::msgref_cast(m)); return; case MSG_MDS_SLAVE_REQUEST: - handle_slave_request(boost::static_pointer_cast::type::element_type>(m)); + handle_slave_request(MMDSSlaveRequest::msgref_cast(m)); return; default: derr << "server unknown message " << m->get_type() << dendl; diff --git a/src/msg/Message.h b/src/msg/Message.h index b0005ff470bbd..008723c7557ed 100644 --- a/src/msg/Message.h +++ b/src/msg/Message.h @@ -534,6 +534,13 @@ public: typedef boost::intrusive_ptr ref; typedef boost::intrusive_ptr const_ref; + static auto msgref_cast(typename M::ref const& m) { + return boost::static_pointer_cast::type::element_type>(m); + } + static auto msgref_cast(typename M::const_ref const& m) { + return boost::static_pointer_cast::type::element_type>(m); + } + protected: template MessageSubType(Args&&... args) : M(std::forward(args)...) {} @@ -546,6 +553,13 @@ class MessageInstance : public MessageSubType { public: using factory = MessageFactory; + static auto msgref_cast(typename Message::ref const& m) { + return boost::static_pointer_cast::type::element_type>(m); + } + static auto msgref_cast(typename Message::const_ref const& m) { + return boost::static_pointer_cast::type::element_type>(m); + } + protected: template MessageInstance(Args&&... args) : MessageSubType(std::forward(args)...) {} -- 2.39.5