Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / messenger / simple_dispatcher.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2013 CohortFS, LLC
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software
11  * Foundation.  See file COPYING.
12  *
13  */
14
15 #include "include/compat.h"
16
17 #include "simple_dispatcher.h"
18 #include "messages/MPing.h"
19 #include "messages/MDataPing.h"
20
21 SimpleDispatcher::SimpleDispatcher(Messenger *msgr) :
22   Dispatcher(msgr->cct),
23   active(false),
24   messenger(msgr),
25   dcount(0)
26 {
27   // nothing
28 }
29
30 SimpleDispatcher::~SimpleDispatcher() {
31   // nothing
32 }
33
34 bool SimpleDispatcher::ms_dispatch(Message *m)
35 {
36   uint64_t dc = 0;
37
38   dc = dcount++;
39
40   ConnectionRef con = m->get_connection();
41   Messenger* msgr = con->get_messenger();
42
43   switch (m->get_type()) {
44   case CEPH_MSG_PING:
45     break;
46   case MSG_DATA_PING:
47   {
48     MDataPing* mdp __attribute__((unused)) = static_cast<MDataPing*>(m);
49     //cout << "MDataPing " << mdp->tag << " " << mdp->counter << std::endl;
50     //mdp->get_data().hexdump(cout);
51     ConnectionRef con = m->get_connection();
52     con->send_message(m);
53   }
54     break;
55   default:
56     abort();
57   }
58
59   if (unlikely(msgr->get_magic() & MSG_MAGIC_TRACE_CTR)) {
60     if (unlikely(dc % 65536) == 0) {
61       struct timespec ts;
62       clock_gettime(CLOCK_REALTIME_COARSE, &ts);
63       std::cout << "ping " << dc << " nanos: " <<
64         ts.tv_nsec + (ts.tv_sec * 1000000000)  << std::endl;
65     }
66   } /* trace ctr */
67
68
69   con->send_message(m);
70
71   //m->put();
72
73   return true;
74 }
75
76 bool SimpleDispatcher::ms_handle_reset(Connection *con)
77 {
78   return true;
79 }
80
81 void SimpleDispatcher::ms_handle_remote_reset(Connection *con)
82 {
83   // nothing
84 }
85