From e5efd882e7eba360158c2218bbd197766d082b02 Mon Sep 17 00:00:00 2001 From: Joao Eduardo Luis Date: Wed, 30 Oct 2013 12:29:32 +0000 Subject: [PATCH 1/2] mon: MonmapMonitor: support 'mon getmap [epoch]' Fixes: #6683 Signed-off-by: Joao Eduardo Luis --- src/mon/MonmapMonitor.cc | 73 ++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/src/mon/MonmapMonitor.cc b/src/mon/MonmapMonitor.cc index ca855592445..18c07bcc515 100644 --- a/src/mon/MonmapMonitor.cc +++ b/src/mon/MonmapMonitor.cc @@ -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 f(new_formatter(format)); if (f) { - f->open_object_section("monmap"); - p->dump(f.get()); - f->open_array_section("quorum"); - for (set::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::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); From be12f7f5824a9b7bb8e5d353a45729a7ac4db040 Mon Sep 17 00:00:00 2001 From: Joao Eduardo Luis Date: Wed, 30 Oct 2013 12:30:18 +0000 Subject: [PATCH 2/2] mon: OSDMonitor: proper error msg on invalid epoch on 'osd getmap/dump' Signed-off-by: Joao Eduardo Luis --- src/mon/OSDMonitor.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index d036f42a83c..9bc9ba1850d 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -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);