]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/async: assert existing protocol matches current protocol
authorSage Weil <sage@redhat.com>
Wed, 19 Dec 2018 20:53:43 +0000 (14:53 -0600)
committerSage Weil <sage@redhat.com>
Thu, 3 Jan 2019 17:17:31 +0000 (11:17 -0600)
If we are (potentially) replacing a connection, assert that the protocol
version matches.  If it doesn't, something very weird is going on!

Signed-off-by: Sage Weil <sage@redhat.com>
src/msg/async/Protocol.h
src/msg/async/ProtocolV1.cc
src/msg/async/ProtocolV2.cc

index faa9e127fdeafbc1741f2943c712bff16106284d..4eba36371a5bc878c2014fe826e550fd034e37a0 100644 (file)
@@ -73,12 +73,13 @@ class AsyncMessenger;
 
 class Protocol {
 protected:
+  int proto_type;
   AsyncConnection *connection;
   AsyncMessenger *messenger;
   CephContext *cct;
 
 public:
-  Protocol(AsyncConnection *connection);
+  Protocol(int type, AsyncConnection *connection);
   virtual ~Protocol();
 
   // prepare protocol for connecting to peer
@@ -101,4 +102,4 @@ public:
   virtual bool is_queued() = 0;
 };
 
-#endif /* _MSG_ASYNC_PROTOCOL_ */
\ No newline at end of file
+#endif /* _MSG_ASYNC_PROTOCOL_ */
index a5a90928cccd59a32603a95bed3e71fdef120824..e4d2ca658ad129a5f234e3dfdd4c21dc8aac5b17 100644 (file)
@@ -53,10 +53,11 @@ static void alloc_aligned_buffer(bufferlist &data, unsigned len, unsigned off) {
   data.push_back(std::move(ptr));
 }
 
-Protocol::Protocol(AsyncConnection *connection)
-    : connection(connection),
-      messenger(connection->async_msgr),
-      cct(connection->async_msgr->cct) {}
+Protocol::Protocol(int type, AsyncConnection *connection)
+  : proto_type(type),
+    connection(connection),
+    messenger(connection->async_msgr),
+    cct(connection->async_msgr->cct) {}
 
 Protocol::~Protocol() {}
 
@@ -65,7 +66,7 @@ Protocol::~Protocol() {}
  **/
 
 ProtocolV1::ProtocolV1(AsyncConnection *connection)
-    : Protocol(connection),
+    : Protocol(1, connection),
       temp_buffer(nullptr),
       can_write(WriteStatus::NOWRITE),
       keepalive(false),
@@ -1976,6 +1977,7 @@ CtPtr ProtocolV1::handle_connect_message_2() {
                             // AsyncConnection here)
 
     ProtocolV1 *exproto = dynamic_cast<ProtocolV1 *>(existing->protocol.get());
+    assert(exproto->proto_type == 1);
 
     if (!exproto) {
       ldout(cct, 1) << __func__ << " existing=" << existing << dendl;
index ca8f91a448964682d91785af291e8b0c359c2348..66447c13fe17a333184c73845a5981c3a0edfd29 100644 (file)
@@ -60,7 +60,7 @@ static void alloc_aligned_buffer(bufferlist &data, unsigned len, unsigned off) {
  **/
 
 ProtocolV2::ProtocolV2(AsyncConnection *connection)
-    : Protocol(connection),
+    : Protocol(2, connection),
       temp_buffer(nullptr),
       peer_addr_count(0),
       can_write(WriteStatus::NOWRITE),
@@ -2017,6 +2017,7 @@ CtPtr ProtocolV2::handle_connect_message_2() {
                             // AsyncConnection here)
 
     ProtocolV2 *exproto = dynamic_cast<ProtocolV2 *>(existing->protocol.get());
+    assert(exproto->proto_type == 2);
 
     if (!exproto) {
       ldout(cct, 1) << __func__ << " existing=" << existing << dendl;