]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
11fdf7f2 | 23 | class MMonProbe : public MessageInstance<MMonProbe> { |
7c673cae | 24 | public: |
11fdf7f2 TL |
25 | friend factory; |
26 | ||
27 | static constexpr int HEAD_VERSION = 7; | |
28 | static constexpr int COMPAT_VERSION = 5; | |
7c673cae FG |
29 | |
30 | enum { | |
31 | OP_PROBE = 1, | |
32 | OP_REPLY = 2, | |
33 | OP_SLURP = 3, | |
34 | OP_SLURP_LATEST = 4, | |
35 | OP_DATA = 5, | |
36 | OP_MISSING_FEATURES = 6, | |
37 | }; | |
38 | ||
39 | static const char *get_opname(int o) { | |
40 | switch (o) { | |
41 | case OP_PROBE: return "probe"; | |
42 | case OP_REPLY: return "reply"; | |
43 | case OP_SLURP: return "slurp"; | |
44 | case OP_SLURP_LATEST: return "slurp_latest"; | |
45 | case OP_DATA: return "data"; | |
46 | case OP_MISSING_FEATURES: return "missing_features"; | |
47 | default: ceph_abort(); return 0; | |
48 | } | |
49 | } | |
50 | ||
51 | uuid_d fsid; | |
d2e6a577 | 52 | int32_t op = 0; |
7c673cae FG |
53 | string name; |
54 | set<int32_t> quorum; | |
55 | bufferlist monmap_bl; | |
d2e6a577 FG |
56 | version_t paxos_first_version = 0; |
57 | version_t paxos_last_version = 0; | |
58 | bool has_ever_joined = 0; | |
59 | uint64_t required_features = 0; | |
11fdf7f2 | 60 | uint8_t mon_release = 0; |
7c673cae FG |
61 | |
62 | MMonProbe() | |
11fdf7f2 TL |
63 | : MessageInstance(MSG_MON_PROBE, HEAD_VERSION, COMPAT_VERSION) {} |
64 | MMonProbe(const uuid_d& f, int o, const string& n, bool hej, uint8_t mr) | |
65 | : MessageInstance(MSG_MON_PROBE, HEAD_VERSION, COMPAT_VERSION), | |
7c673cae FG |
66 | fsid(f), |
67 | op(o), | |
68 | name(n), | |
69 | paxos_first_version(0), | |
70 | paxos_last_version(0), | |
71 | has_ever_joined(hej), | |
11fdf7f2 TL |
72 | required_features(0), |
73 | mon_release(mr) {} | |
7c673cae FG |
74 | private: |
75 | ~MMonProbe() override {} | |
76 | ||
77 | public: | |
11fdf7f2 | 78 | std::string_view get_type_name() const override { return "mon_probe"; } |
7c673cae FG |
79 | void print(ostream& out) const override { |
80 | out << "mon_probe(" << get_opname(op) << " " << fsid << " name " << name; | |
81 | if (quorum.size()) | |
82 | out << " quorum " << quorum; | |
83 | if (op == OP_REPLY) { | |
84 | out << " paxos(" | |
85 | << " fc " << paxos_first_version | |
86 | << " lc " << paxos_last_version | |
87 | << " )"; | |
88 | } | |
89 | if (!has_ever_joined) | |
90 | out << " new"; | |
91 | if (required_features) | |
92 | out << " required_features " << required_features; | |
11fdf7f2 TL |
93 | if (mon_release) |
94 | out << " mon_release " << (int)mon_release; | |
7c673cae FG |
95 | out << ")"; |
96 | } | |
97 | ||
98 | void encode_payload(uint64_t features) override { | |
11fdf7f2 | 99 | using ceph::encode; |
7c673cae FG |
100 | if (monmap_bl.length() && |
101 | ((features & CEPH_FEATURE_MONENC) == 0 || | |
102 | (features & CEPH_FEATURE_MSG_ADDR2) == 0)) { | |
103 | // reencode old-format monmap | |
104 | MonMap t; | |
105 | t.decode(monmap_bl); | |
106 | monmap_bl.clear(); | |
107 | t.encode(monmap_bl, features); | |
108 | } | |
109 | ||
11fdf7f2 TL |
110 | encode(fsid, payload); |
111 | encode(op, payload); | |
112 | encode(name, payload); | |
113 | encode(quorum, payload); | |
114 | encode(monmap_bl, payload); | |
115 | encode(has_ever_joined, payload); | |
116 | encode(paxos_first_version, payload); | |
117 | encode(paxos_last_version, payload); | |
118 | encode(required_features, payload); | |
119 | encode(mon_release, payload); | |
7c673cae FG |
120 | } |
121 | void decode_payload() override { | |
11fdf7f2 TL |
122 | auto p = payload.cbegin(); |
123 | decode(fsid, p); | |
124 | decode(op, p); | |
125 | decode(name, p); | |
126 | decode(quorum, p); | |
127 | decode(monmap_bl, p); | |
128 | decode(has_ever_joined, p); | |
129 | decode(paxos_first_version, p); | |
130 | decode(paxos_last_version, p); | |
7c673cae | 131 | if (header.version >= 6) |
11fdf7f2 | 132 | decode(required_features, p); |
7c673cae FG |
133 | else |
134 | required_features = 0; | |
11fdf7f2 TL |
135 | if (header.version >= 7) |
136 | decode(mon_release, p); | |
137 | else | |
138 | mon_release = 0; | |
7c673cae FG |
139 | } |
140 | }; | |
141 | ||
142 | #endif |