]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
msg: add func is_blackhole to reduce duplicated code.
authorJianpeng Ma <jianpeng.ma@intel.com>
Fri, 13 Sep 2019 00:00:13 +0000 (08:00 +0800)
committerJianpeng Ma <jianpeng.ma@intel.com>
Fri, 13 Sep 2019 00:00:13 +0000 (08:00 +0800)
Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
src/msg/CMakeLists.txt
src/msg/Connection.cc [new file with mode: 0644]
src/msg/Connection.h
src/msg/async/AsyncConnection.cc
src/msg/async/ProtocolV1.cc
src/msg/async/ProtocolV2.cc

index 9ac9bcfdf26d75d68e25d2dafba160d183235022..ce6550a57f6b13656cdc1118ce7aaad1da64ff3c 100644 (file)
@@ -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 (file)
index 0000000..21f147b
--- /dev/null
@@ -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));
+}
index e892a68431e2a9f5b77b1d3d8ea64d4aef5ac172..840a3fba67f15d7e7171a16553214c4f0ccfb137 100644 (file)
@@ -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<Connection> ConnectionRef;
index 6e771a99e15236fca1e767f58e6b81ca474c36c7..b86035eca26cccbe1868f21c987596c1fc0af5bc 100644 (file)
@@ -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;
   }
index 9f6160d7ef0844bda6a637a147b7a50e969825be..a953620aab0c9e59bf0c54e33ac3ebc59a3d1097 100644 (file)
@@ -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;
index af02cc2d7291d2bfb24db7d299c86fe1c13089bc..5f90422631434538e4d83a68edfcc6d12d27fa6a 100644 (file)
@@ -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;