mirror of
https://github.com/ceph/ceph
synced 2025-01-01 08:32:24 +00:00
Merge pull request #789 from ceph/wip-6683
mon: MonmapMonitor: support 'mon getmap [epoch]' Reviewed-by: Sage Weil <sage@inktank.com>
This commit is contained in:
commit
b2acac02c6
@ -177,58 +177,67 @@ bool MonmapMonitor::preprocess_command(MMonCommand *m)
|
||||
ss.str("");
|
||||
r = 0;
|
||||
|
||||
} else if (prefix == "mon getmap") {
|
||||
mon->monmap->encode(rdata, CEPH_FEATURES_ALL);
|
||||
r = 0;
|
||||
ss << "got latest monmap";
|
||||
} else if (prefix == "mon getmap" ||
|
||||
prefix == "mon dump") {
|
||||
|
||||
} else if (prefix == "mon dump") {
|
||||
string format;
|
||||
cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
|
||||
epoch_t epoch = 0;
|
||||
int64_t epochval;
|
||||
if (cmd_getval(g_ceph_context, cmdmap, "epoch", epochval))
|
||||
epoch = epochval;
|
||||
epoch_t epoch;
|
||||
int64_t epochnum;
|
||||
cmd_getval(g_ceph_context, cmdmap, "epoch", epochnum, (int64_t)0);
|
||||
epoch = epochnum;
|
||||
|
||||
MonMap *p = mon->monmap;
|
||||
if (epoch) {
|
||||
bufferlist b;
|
||||
r = get_version(epoch, b);
|
||||
bufferlist bl;
|
||||
r = get_version(epoch, bl);
|
||||
if (r == -ENOENT) {
|
||||
p = 0;
|
||||
} else {
|
||||
p = new MonMap;
|
||||
p->decode(b);
|
||||
ss << "there is no map for epoch " << epoch;
|
||||
goto reply;
|
||||
}
|
||||
assert(r == 0);
|
||||
assert(bl.length() > 0);
|
||||
p = new MonMap;
|
||||
p->decode(bl);
|
||||
}
|
||||
if (p) {
|
||||
|
||||
assert(p != NULL);
|
||||
|
||||
if (prefix == "mon getmap") {
|
||||
p->encode(rdata, CEPH_FEATURES_ALL);
|
||||
r = 0;
|
||||
ss << "got monmap epoch " << p->get_epoch();
|
||||
} else if (prefix == "mon dump") {
|
||||
string format;
|
||||
cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
|
||||
stringstream ds;
|
||||
boost::scoped_ptr<Formatter> f(new_formatter(format));
|
||||
if (f) {
|
||||
f->open_object_section("monmap");
|
||||
p->dump(f.get());
|
||||
f->open_array_section("quorum");
|
||||
for (set<int>::iterator q = mon->get_quorum().begin(); q != mon->get_quorum().end(); ++q)
|
||||
f->dump_int("mon", *q);
|
||||
f->close_section();
|
||||
f->close_section();
|
||||
f->flush(ds);
|
||||
r = 0;
|
||||
f->open_object_section("monmap");
|
||||
p->dump(f.get());
|
||||
f->open_array_section("quorum");
|
||||
for (set<int>::iterator q = mon->get_quorum().begin();
|
||||
q != mon->get_quorum().end(); ++q) {
|
||||
f->dump_int("mon", *q);
|
||||
}
|
||||
f->close_section();
|
||||
f->close_section();
|
||||
f->flush(ds);
|
||||
r = 0;
|
||||
} else {
|
||||
p->print(ds);
|
||||
r = 0;
|
||||
}
|
||||
p->print(ds);
|
||||
r = 0;
|
||||
}
|
||||
rdata.append(ds);
|
||||
ss << "dumped monmap epoch " << p->get_epoch();
|
||||
if (p != mon->monmap)
|
||||
delete p;
|
||||
}
|
||||
if (p != mon->monmap)
|
||||
delete p;
|
||||
}
|
||||
else if (prefix == "mon add")
|
||||
return false;
|
||||
else if (prefix == "mon remove")
|
||||
return false;
|
||||
|
||||
reply:
|
||||
if (r != -1) {
|
||||
string rs;
|
||||
getline(ss, rs);
|
||||
|
@ -2021,6 +2021,7 @@ bool OSDMonitor::preprocess_command(MMonCommand *m)
|
||||
int err = get_version_full(epoch, b);
|
||||
if (err == -ENOENT) {
|
||||
r = -ENOENT;
|
||||
ss << "there is no map for epoch " << epoch;
|
||||
goto reply;
|
||||
}
|
||||
assert(err == 0);
|
||||
|
Loading…
Reference in New Issue
Block a user