]>
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_MMONELECTION_H | |
17 | #define CEPH_MMONELECTION_H | |
18 | ||
19 | #include "msg/Message.h" | |
20 | #include "mon/MonMap.h" | |
21 | #include "mon/mon_types.h" | |
22 | ||
23 | class MMonElection : public Message { | |
24 | ||
224ce89b | 25 | static const int HEAD_VERSION = 7; |
7c673cae FG |
26 | static const int COMPAT_VERSION = 5; |
27 | ||
28 | public: | |
29 | static const int OP_PROPOSE = 1; | |
30 | static const int OP_ACK = 2; | |
31 | static const int OP_NAK = 3; | |
32 | static const int OP_VICTORY = 4; | |
33 | static const char *get_opname(int o) { | |
34 | switch (o) { | |
35 | case OP_PROPOSE: return "propose"; | |
36 | case OP_ACK: return "ack"; | |
37 | case OP_NAK: return "nak"; | |
38 | case OP_VICTORY: return "victory"; | |
39 | default: ceph_abort(); return 0; | |
40 | } | |
41 | } | |
42 | ||
43 | uuid_d fsid; | |
44 | int32_t op; | |
45 | epoch_t epoch; | |
46 | bufferlist monmap_bl; | |
47 | set<int32_t> quorum; | |
48 | uint64_t quorum_features; | |
49 | mon_feature_t mon_features; | |
50 | bufferlist sharing_bl; | |
224ce89b | 51 | map<string,string> metadata; |
7c673cae FG |
52 | |
53 | MMonElection() : Message(MSG_MON_ELECTION, HEAD_VERSION, COMPAT_VERSION), | |
54 | op(0), epoch(0), | |
55 | quorum_features(0), | |
224ce89b | 56 | mon_features(0) |
7c673cae FG |
57 | { } |
58 | ||
59 | MMonElection(int o, epoch_t e, MonMap *m) | |
60 | : Message(MSG_MON_ELECTION, HEAD_VERSION, COMPAT_VERSION), | |
61 | fsid(m->fsid), op(o), epoch(e), | |
62 | quorum_features(0), | |
224ce89b | 63 | mon_features(0) |
7c673cae FG |
64 | { |
65 | // encode using full feature set; we will reencode for dest later, | |
66 | // if necessary | |
67 | m->encode(monmap_bl, CEPH_FEATURES_ALL); | |
68 | } | |
69 | private: | |
70 | ~MMonElection() override {} | |
71 | ||
72 | public: | |
73 | const char *get_type_name() const override { return "election"; } | |
74 | void print(ostream& out) const override { | |
75 | out << "election(" << fsid << " " << get_opname(op) << " " << epoch << ")"; | |
76 | } | |
77 | ||
78 | void encode_payload(uint64_t features) override { | |
79 | if (monmap_bl.length() && (features != CEPH_FEATURES_ALL)) { | |
80 | // reencode old-format monmap | |
81 | MonMap t; | |
82 | t.decode(monmap_bl); | |
83 | monmap_bl.clear(); | |
84 | t.encode(monmap_bl, features); | |
85 | } | |
86 | ||
87 | ::encode(fsid, payload); | |
88 | ::encode(op, payload); | |
89 | ::encode(epoch, payload); | |
90 | ::encode(monmap_bl, payload); | |
91 | ::encode(quorum, payload); | |
92 | ::encode(quorum_features, payload); | |
224ce89b WB |
93 | ::encode((version_t)0, payload); // defunct |
94 | ::encode((version_t)0, payload); // defunct | |
7c673cae FG |
95 | ::encode(sharing_bl, payload); |
96 | ::encode(mon_features, payload); | |
224ce89b | 97 | ::encode(metadata, payload); |
7c673cae FG |
98 | } |
99 | void decode_payload() override { | |
100 | bufferlist::iterator p = payload.begin(); | |
101 | ::decode(fsid, p); | |
102 | ::decode(op, p); | |
103 | ::decode(epoch, p); | |
104 | ::decode(monmap_bl, p); | |
105 | ::decode(quorum, p); | |
106 | ::decode(quorum_features, p); | |
224ce89b WB |
107 | { |
108 | version_t v; // defunct fields from old encoding | |
109 | ::decode(v, p); | |
110 | ::decode(v, p); | |
111 | } | |
7c673cae FG |
112 | ::decode(sharing_bl, p); |
113 | if (header.version >= 6) | |
114 | ::decode(mon_features, p); | |
224ce89b WB |
115 | if (header.version >= 7) |
116 | ::decode(metadata, p); | |
7c673cae FG |
117 | } |
118 | ||
119 | }; | |
120 | ||
121 | #endif |