From: Jianpeng Ma Date: Fri, 13 Sep 2019 00:00:13 +0000 (+0800) Subject: msg: add func is_blackhole to reduce duplicated code. X-Git-Tag: v15.1.0~1543^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=16d0eb93c62199ce922313e22c5d3669e5ee9acd;p=ceph.git msg: add func is_blackhole to reduce duplicated code. Signed-off-by: Jianpeng Ma --- diff --git a/src/msg/CMakeLists.txt b/src/msg/CMakeLists.txt index 9ac9bcfdf26d..ce6550a57f6b 100644 --- a/src/msg/CMakeLists.txt +++ b/src/msg/CMakeLists.txt @@ -3,6 +3,7 @@ set(msg_srcs Message.cc Messenger.cc QueueStrategy.cc + Connection.cc msg_types.cc) list(APPEND msg_srcs diff --git a/src/msg/Connection.cc b/src/msg/Connection.cc new file mode 100644 index 000000000000..21f147b80349 --- /dev/null +++ b/src/msg/Connection.cc @@ -0,0 +1,14 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "msg/Connection.h" +#include "msg/Messenger.h" + + +bool Connection::is_blackhole() const { + auto& conf = msgr->cct->_conf; + return ((conf->ms_blackhole_mon && peer_type == CEPH_ENTITY_TYPE_MON) || + (conf->ms_blackhole_osd && peer_type == CEPH_ENTITY_TYPE_OSD) || + (conf->ms_blackhole_mds && peer_type == CEPH_ENTITY_TYPE_MDS) || + (conf->ms_blackhole_client && peer_type == CEPH_ENTITY_TYPE_CLIENT)); +} diff --git a/src/msg/Connection.h b/src/msg/Connection.h index e892a68431e2..840a3fba67f1 100644 --- a/src/msg/Connection.h +++ b/src/msg/Connection.h @@ -31,7 +31,6 @@ #include "common/item_history.h" #include "msg/MessageRef.h" - // ====================================================== // abstract Connection, for keeping per-connection state @@ -254,7 +253,7 @@ public: std::lock_guard l{lock}; last_keepalive_ack = t; } - + bool is_blackhole() const; }; typedef boost::intrusive_ptr ConnectionRef; diff --git a/src/msg/async/AsyncConnection.cc b/src/msg/async/AsyncConnection.cc index 6e771a99e152..b86035eca26c 100644 --- a/src/msg/async/AsyncConnection.cc +++ b/src/msg/async/AsyncConnection.cc @@ -524,14 +524,9 @@ int AsyncConnection::send_message(Message *m) << this << dendl; - auto cct = async_msgr->cct; - if ((cct->_conf->ms_blackhole_mon && peer_type == CEPH_ENTITY_TYPE_MON)|| - (cct->_conf->ms_blackhole_osd && peer_type == CEPH_ENTITY_TYPE_OSD)|| - (cct->_conf->ms_blackhole_mds && peer_type == CEPH_ENTITY_TYPE_MDS)|| - (cct->_conf->ms_blackhole_client && - peer_type == CEPH_ENTITY_TYPE_CLIENT)) { - lgeneric_subdout(cct, ms, 0) << __func__ << ceph_entity_type_name(peer_type) - << " blackhole " << *m << dendl; + if (is_blackhole()) { + lgeneric_subdout(async_msgr->cct, ms, 0) << __func__ << ceph_entity_type_name(peer_type) + << " blackhole " << *m << dendl; m->put(); return 0; } diff --git a/src/msg/async/ProtocolV1.cc b/src/msg/async/ProtocolV1.cc index 9f6160d7ef08..a953620aab0c 100644 --- a/src/msg/async/ProtocolV1.cc +++ b/src/msg/async/ProtocolV1.cc @@ -1009,12 +1009,7 @@ CtPtr ProtocolV1::handle_message_footer(char *buffer, int r) { ceph::mono_time fast_dispatch_time; - auto& conf = cct->_conf; - if ((conf->ms_blackhole_mon && connection->peer_type == CEPH_ENTITY_TYPE_MON)|| - (conf->ms_blackhole_osd && connection->peer_type == CEPH_ENTITY_TYPE_OSD)|| - (conf->ms_blackhole_mds && connection->peer_type == CEPH_ENTITY_TYPE_MDS)|| - (conf->ms_blackhole_client && - connection->peer_type == CEPH_ENTITY_TYPE_CLIENT)) { + if (connection->is_blackhole()) { ldout(cct, 10) << __func__ << " blackhole " << *message << dendl; message->put(); goto out; diff --git a/src/msg/async/ProtocolV2.cc b/src/msg/async/ProtocolV2.cc index af02cc2d7291..5f9042263143 100644 --- a/src/msg/async/ProtocolV2.cc +++ b/src/msg/async/ProtocolV2.cc @@ -1487,12 +1487,7 @@ CtPtr ProtocolV2::handle_message() { ceph::mono_time fast_dispatch_time; - auto& conf = cct->_conf; - if ((conf->ms_blackhole_mon && connection->peer_type == CEPH_ENTITY_TYPE_MON)|| - (conf->ms_blackhole_osd && connection->peer_type == CEPH_ENTITY_TYPE_OSD)|| - (conf->ms_blackhole_mds && connection->peer_type == CEPH_ENTITY_TYPE_MDS)|| - (conf->ms_blackhole_client && - connection->peer_type == CEPH_ENTITY_TYPE_CLIENT)) { + if (connection->is_blackhole()) { ldout(cct, 10) << __func__ << " blackhole " << *message << dendl; message->put(); goto out;