From 5b74986e9ac15ccc9ead73faf2bb5830faa97670 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 8 Dec 2008 10:11:12 -0800 Subject: [PATCH] mon: 'osd dump' command; refactor sstream->bufferlist code a bit --- src/include/buffer.h | 8 ++++++++ src/mon/OSDMonitor.cc | 7 +++++++ src/mon/PGMonitor.cc | 20 ++++++-------------- src/mon/PGMonitor.h | 2 -- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/include/buffer.h b/src/include/buffer.h index 8e260279cb0da..5319ad83cb6d8 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -828,6 +828,14 @@ public: ++p) _buffers.push_back(*p); } + void append(istream& in) { + while (!in.eof()) { + string s; + getline(in, s); + append(s.c_str(), s.length()); + append("\n", 1); + } + } void append_zero(unsigned len) { ptr bp(len); diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 050bc86c4a67b..4f08788d0c39e 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -878,6 +878,13 @@ bool OSDMonitor::preprocess_command(MMonCommand *m) ss << *this; r = 0; } + else if (m->cmd[1] == "dump") { + ss << "ok"; + r = 0; + stringstream ds; + osdmap.print(ds); + rdata.append(ds); + } else if (m->cmd[1] == "getmap") { osdmap.encode(rdata); ss << "got osdmap epoch " << osdmap.get_epoch(); diff --git a/src/mon/PGMonitor.cc b/src/mon/PGMonitor.cc index d70e234b54496..2a35c276cac22 100644 --- a/src/mon/PGMonitor.cc +++ b/src/mon/PGMonitor.cc @@ -169,8 +169,10 @@ bool PGMonitor::update_from_paxos() // dump pgmap summaries? (useful for debugging) if (1) { + stringstream ds; + pg_map.dump(ds); bufferlist d; - dump(d); + d.append(ds); mon->store->put_bl_sn(d, "pgmap_dump", paxosv); } @@ -593,18 +595,6 @@ void PGMonitor::send_pg_creates() } } -void PGMonitor::dump(bufferlist& bl) -{ - stringstream ss; - pg_map.dump(ss); - while (!ss.eof()) { - string s; - getline(ss, s); - bl.append(s.c_str(), s.length()); - bl.append("\n", 1); - } -} - bool PGMonitor::preprocess_command(MMonCommand *m) { int r = -1; @@ -627,9 +617,11 @@ bool PGMonitor::preprocess_command(MMonCommand *m) r = 0; } else if (m->cmd[1] == "dump") { - dump(rdata); ss << "ok"; r = 0; + stringstream ds; + pg_map.dump(ds); + rdata.append(ds); } else if (m->cmd[1] == "scrub" && m->cmd.size() == 3) { pg_t pgid; diff --git a/src/mon/PGMonitor.h b/src/mon/PGMonitor.h index 5ac9e2ead4a78..d8b0005f4d3ab 100644 --- a/src/mon/PGMonitor.h +++ b/src/mon/PGMonitor.h @@ -39,8 +39,6 @@ class PGMonitor : public PaxosService { public: PGMap pg_map; - void dump(bufferlist& bl); - private: PGMap::Incremental pending_inc; -- 2.39.5