Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / messages / MMonProbe.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 #ifndef CEPH_MMONPROBE_H
17 #define CEPH_MMONPROBE_H
18
19 #include "include/ceph_features.h"
20 #include "msg/Message.h"
21 #include "mon/MonMap.h"
22
23 class MMonProbe : public Message {
24 public:
25   static const int HEAD_VERSION = 6;
26   static const int COMPAT_VERSION = 5;
27
28   enum {
29     OP_PROBE = 1,
30     OP_REPLY = 2,
31     OP_SLURP = 3,
32     OP_SLURP_LATEST = 4,
33     OP_DATA = 5,
34     OP_MISSING_FEATURES = 6,
35   };
36
37   static const char *get_opname(int o) {
38     switch (o) {
39     case OP_PROBE: return "probe";
40     case OP_REPLY: return "reply";
41     case OP_SLURP: return "slurp";
42     case OP_SLURP_LATEST: return "slurp_latest";
43     case OP_DATA: return "data";
44     case OP_MISSING_FEATURES: return "missing_features";
45     default: ceph_abort(); return 0;
46     }
47   }
48   
49   uuid_d fsid;
50   int32_t op = 0;
51   string name;
52   set<int32_t> quorum;
53   bufferlist monmap_bl;
54   version_t paxos_first_version = 0;
55   version_t paxos_last_version = 0;
56   bool has_ever_joined = 0;
57   uint64_t required_features = 0;
58
59   MMonProbe()
60     : Message(MSG_MON_PROBE, HEAD_VERSION, COMPAT_VERSION) {}
61   MMonProbe(const uuid_d& f, int o, const string& n, bool hej)
62     : Message(MSG_MON_PROBE, HEAD_VERSION, COMPAT_VERSION),
63       fsid(f),
64       op(o),
65       name(n),
66       paxos_first_version(0),
67       paxos_last_version(0),
68       has_ever_joined(hej),
69       required_features(0) {}
70 private:
71   ~MMonProbe() override {}
72
73 public:  
74   const char *get_type_name() const override { return "mon_probe"; }
75   void print(ostream& out) const override {
76     out << "mon_probe(" << get_opname(op) << " " << fsid << " name " << name;
77     if (quorum.size())
78       out << " quorum " << quorum;
79     if (op == OP_REPLY) {
80       out << " paxos("
81         << " fc " << paxos_first_version
82         << " lc " << paxos_last_version
83         << " )";
84     }
85     if (!has_ever_joined)
86       out << " new";
87     if (required_features)
88       out << " required_features " << required_features;
89     out << ")";
90   }
91   
92   void encode_payload(uint64_t features) override {
93     if (monmap_bl.length() &&
94         ((features & CEPH_FEATURE_MONENC) == 0 ||
95          (features & CEPH_FEATURE_MSG_ADDR2) == 0)) {
96       // reencode old-format monmap
97       MonMap t;
98       t.decode(monmap_bl);
99       monmap_bl.clear();
100       t.encode(monmap_bl, features);
101     }
102
103     ::encode(fsid, payload);
104     ::encode(op, payload);
105     ::encode(name, payload);
106     ::encode(quorum, payload);
107     ::encode(monmap_bl, payload);
108     ::encode(has_ever_joined, payload);
109     ::encode(paxos_first_version, payload);
110     ::encode(paxos_last_version, payload);
111     ::encode(required_features, payload);
112   }
113   void decode_payload() override {
114     bufferlist::iterator p = payload.begin();
115     ::decode(fsid, p);
116     ::decode(op, p);
117     ::decode(name, p);
118     ::decode(quorum, p);
119     ::decode(monmap_bl, p);
120     ::decode(has_ever_joined, p);
121     ::decode(paxos_first_version, p);
122     ::decode(paxos_last_version, p);
123     if (header.version >= 6)
124       ::decode(required_features, p);
125     else
126       required_features = 0;
127   }
128 };
129
130 #endif