Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / messages / MRoute.h
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) 2004-2006 Sage Weil <sage@newdream.net>
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
16
17 #ifndef CEPH_MROUTE_H
18 #define CEPH_MROUTE_H
19
20 #include "msg/Message.h"
21 #include "include/encoding.h"
22
23 struct MRoute : public Message {
24
25   static const int HEAD_VERSION = 3;
26   static const int COMPAT_VERSION = 3;
27
28   uint64_t session_mon_tid;
29   Message *msg;
30   entity_inst_t dest;
31   epoch_t send_osdmap_first;
32   
33   MRoute() : Message(MSG_ROUTE, HEAD_VERSION, COMPAT_VERSION),
34              session_mon_tid(0),
35              msg(NULL),
36              send_osdmap_first(0) {}
37   MRoute(uint64_t t, Message *m)
38     : Message(MSG_ROUTE, HEAD_VERSION, COMPAT_VERSION),
39       session_mon_tid(t),
40       msg(m),
41       send_osdmap_first(0) {}
42   MRoute(bufferlist bl, const entity_inst_t& i)
43     : Message(MSG_ROUTE, HEAD_VERSION, COMPAT_VERSION),
44       session_mon_tid(0),
45       dest(i),
46       send_osdmap_first(0) {
47     bufferlist::iterator p = bl.begin();
48     msg = decode_message(NULL, 0, p);
49   }
50 private:
51   ~MRoute() override {
52     if (msg)
53       msg->put();
54   }
55
56 public:
57   void decode_payload() override {
58     bufferlist::iterator p = payload.begin();
59     ::decode(session_mon_tid, p);
60     ::decode(dest, p);
61     bool m;
62     ::decode(m, p);
63     if (m)
64       msg = decode_message(NULL, 0, p);
65     ::decode(send_osdmap_first, p);
66   }
67   void encode_payload(uint64_t features) override {
68     ::encode(session_mon_tid, payload);
69     ::encode(dest, payload, features);
70     bool m = msg ? true : false;
71     ::encode(m, payload);
72     if (msg)
73       encode_message(msg, features, payload);
74     ::encode(send_osdmap_first, payload);
75   }
76
77   const char *get_type_name() const override { return "route"; }
78   void print(ostream& o) const override {
79     if (msg)
80       o << "route(" << *msg;
81     else
82       o << "route(no-reply";
83     if (send_osdmap_first)
84       o << " send_osdmap_first " << send_osdmap_first;
85     if (session_mon_tid)
86       o << " tid " << session_mon_tid << ")";
87     else
88       o << " to " << dest << ")";
89   }
90 };
91
92 #endif