summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2012-05-14 21:01:58 -0700
committerSage Weil <sage@inktank.com>2012-05-14 21:01:58 -0700
commita9f5d7740632e91bcdaa826fa78e2bff4523dc7f (patch)
tree51735e1738fd31dd45bbbc37909fe546616db5b0 /src
parent31dc3945f5876bf1df2eedabf5797a0c89b6ee30 (diff)
downloadceph-a9f5d7740632e91bcdaa826fa78e2bff4523dc7f.tar.gz
monmap: use feature bits and single encode() method
Instead of selecting an encode method in the caller, use a normal features argument to encode() and branch there. Leave behavior of all callers untouched. We continue to assume, for example, that all monitors have the same features, and that 'ceph mon getmap' should return the fully-featured encoding. Signed-off-by: Sage Weil <sage@inktank.com>
Diffstat (limited to 'src')
-rw-r--r--src/ceph_mon.cc2
-rw-r--r--src/messages/MMonElection.h2
-rw-r--r--src/mon/MonMap.cc34
-rw-r--r--src/mon/MonMap.h6
-rw-r--r--src/mon/Monitor.cc9
-rw-r--r--src/mon/MonmapMonitor.cc4
6 files changed, 27 insertions, 30 deletions
diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc
index 6474685d9d2..e24046c4045 100644
--- a/src/ceph_mon.cc
+++ b/src/ceph_mon.cc
@@ -278,7 +278,7 @@ int main(int argc, const char **argv)
tmp.set_epoch(v);
}
bufferlist mapbl;
- tmp.encode(mapbl);
+ tmp.encode(mapbl, -1);
bufferlist final;
::encode(v, final);
::encode(mapbl, final);
diff --git a/src/messages/MMonElection.h b/src/messages/MMonElection.h
index 7594c49cc17..5adf6ff432b 100644
--- a/src/messages/MMonElection.h
+++ b/src/messages/MMonElection.h
@@ -48,7 +48,7 @@ public:
MMonElection(int o, epoch_t e, MonMap *m) :
Message(MSG_MON_ELECTION, HEAD_VERSION),
fsid(m->fsid), op(o), epoch(e) {
- m->encode(monmap_bl);
+ m->encode(monmap_bl, -1);
}
private:
~MMonElection() {}
diff --git a/src/mon/MonMap.cc b/src/mon/MonMap.cc
index 4e90f8c69df..ca5f40ea28b 100644
--- a/src/mon/MonMap.cc
+++ b/src/mon/MonMap.cc
@@ -7,10 +7,26 @@
#include "common/Formatter.h"
+#include "include/ceph_features.h"
+
using ceph::Formatter;
-void MonMap::encode(bufferlist& blist) const
+void MonMap::encode(bufferlist& blist, uint64_t features) const
{
+ if ((features & CEPH_FEATURE_MONNAMES) == 0) {
+ __u16 v = 1;
+ ::encode(v, blist);
+ ::encode_raw(fsid, blist);
+ ::encode(epoch, blist);
+ vector<entity_inst_t> mon_inst(mon_addr.size());
+ for (unsigned n = 0; n < mon_addr.size(); n++)
+ mon_inst[n] = get_inst(n);
+ ::encode(mon_inst, blist);
+ ::encode(last_changed, blist);
+ ::encode(created, blist);
+ return;
+ }
+
__u16 v = 2;
::encode(v, blist);
::encode_raw(fsid, blist);
@@ -20,20 +36,6 @@ void MonMap::encode(bufferlist& blist) const
::encode(created, blist);
}
-void MonMap::encode_v1(bufferlist& blist) const
-{
- __u16 v = 1;
- ::encode(v, blist);
- ::encode_raw(fsid, blist);
- ::encode(epoch, blist);
- vector<entity_inst_t> mon_inst(mon_addr.size());
- for (unsigned n = 0; n < mon_addr.size(); n++)
- mon_inst[n] = get_inst(n);
- ::encode(mon_inst, blist);
- ::encode(last_changed, blist);
- ::encode(created, blist);
-}
-
void MonMap::decode(bufferlist::iterator &p)
{
__u16 v;
@@ -72,7 +74,7 @@ int MonMap::write(const char *fn)
{
// encode
bufferlist bl;
- encode(bl);
+ encode(bl, -1);
return bl.write_file(fn);
}
diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h
index 10c3f137dd9..f294b497145 100644
--- a/src/mon/MonMap.h
+++ b/src/mon/MonMap.h
@@ -171,9 +171,7 @@ class MonMap {
return i;
}
- void encode(bufferlist& blist) const;
- void encode_v1(bufferlist& blist) const;
-
+ void encode(bufferlist& blist, uint64_t features) const;
void decode(bufferlist& blist) {
bufferlist::iterator p = blist.begin();
decode(p);
@@ -194,7 +192,7 @@ class MonMap {
static void generate_test_instances(list<MonMap*>& o);
};
-WRITE_CLASS_ENCODER(MonMap)
+WRITE_CLASS_ENCODER_FEATURES(MonMap)
inline ostream& operator<<(ostream& out, MonMap& m) {
m.print_summary(out);
diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc
index 91f65dab396..f376980acf1 100644
--- a/src/mon/Monitor.cc
+++ b/src/mon/Monitor.cc
@@ -524,7 +524,7 @@ void Monitor::handle_probe_probe(MMonProbe *m)
MMonProbe *r = new MMonProbe(monmap->fsid, MMonProbe::OP_REPLY, name);
r->name = name;
r->quorum = quorum;
- monmap->encode(r->monmap_bl);
+ monmap->encode(r->monmap_bl, -1);
for (vector<Paxos*>::iterator p = paxos.begin(); p != paxos.end(); ++p)
r->paxos_versions[(*p)->get_machine_name()] = (*p)->get_version();
messenger->send_message(r, m->get_connection());
@@ -1722,10 +1722,7 @@ void Monitor::check_sub(Subscription *sub)
void Monitor::send_latest_monmap(Connection *con)
{
bufferlist bl;
- if (!con->has_feature(CEPH_FEATURE_MONNAMES))
- monmap->encode_v1(bl);
- else
- monmap->encode(bl);
+ monmap->encode(bl, con->get_features());
messenger->send_message(new MMonMap(bl), con);
}
@@ -1828,7 +1825,7 @@ int Monitor::mkfs(bufferlist& osdmapbl)
// save monmap, osdmap, keyring.
bufferlist monmapbl;
- monmap->encode(monmapbl);
+ monmap->encode(monmapbl, -1);
monmap->set_epoch(0); // must be 0 to avoid confusing first MonmapMonitor::update_from_paxos()
store->put_bl_ss(monmapbl, "mkfs", "monmap");
diff --git a/src/mon/MonmapMonitor.cc b/src/mon/MonmapMonitor.cc
index 3d7d775f860..f9e029ffcaa 100644
--- a/src/mon/MonmapMonitor.cc
+++ b/src/mon/MonmapMonitor.cc
@@ -102,7 +102,7 @@ void MonmapMonitor::encode_pending(bufferlist& bl)
assert(mon->monmap->epoch + 1 == pending_map.epoch ||
pending_map.epoch == 1); // special case mkfs!
- pending_map.encode(bl);
+ pending_map.encode(bl, -1);
}
bool MonmapMonitor::preprocess_query(PaxosServiceMessage *m)
@@ -137,7 +137,7 @@ bool MonmapMonitor::preprocess_command(MMonCommand *m)
r = 0;
}
else if (m->cmd.size() == 2 && m->cmd[1] == "getmap") {
- mon->monmap->encode(rdata);
+ mon->monmap->encode(rdata, -1);
r = 0;
ss << "got latest monmap";
}