From: Dan Mick Date: Sat, 20 Jul 2013 01:04:29 +0000 (-0700) Subject: PG: add formatted output to pg query, list_missing X-Git-Tag: v0.67-rc3~39^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bcbb807c018f89d473a252d87e8d48b5220b3a61;p=ceph.git PG: add formatted output to pg query, list_missing Signed-off-by: Dan Mick --- diff --git a/src/osd/PG.h b/src/osd/PG.h index 5525c7f46dd2..10e9a2544a9b 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -43,6 +43,7 @@ #include "msg/Messenger.h" #include "messages/MOSDRepScrub.h" #include "messages/MOSDPGLog.h" +#include "common/cmdparse.h" #include "common/tracked_int_ptr.hpp" #include "common/WorkQueue.h" #include "include/str_list.h" @@ -109,7 +110,6 @@ struct PGRecoveryStats { << i.total_time << "\t" << i.min_time << "\t" << i.max_time << "\t" << p->first << "\n"; - } } @@ -1814,7 +1814,7 @@ public: virtual void do_push_reply(OpRequestRef op) = 0; virtual void snap_trimmer() = 0; - virtual int do_command(vector& cmd, ostream& ss, + virtual int do_command(cmdmap_t cmdmap, ostream& ss, bufferlist& idata, bufferlist& odata) = 0; virtual bool same_for_read_since(epoch_t e) = 0; diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index 298d38d6ace6..4a59a23cdb79 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -268,23 +268,12 @@ int ReplicatedPG::get_pgls_filter(bufferlist::iterator& iter, PGLSFilter **pfilt // ========================================================== -int ReplicatedPG::do_command(vector& cmd, ostream& ss, +int ReplicatedPG::do_command(cmdmap_t cmdmap, ostream& ss, bufferlist& idata, bufferlist& odata) { const pg_missing_t &missing = pg_log.get_missing(); - map cmdmap; string prefix; - - if (cmd.empty()) { - ss << "no command given"; - return -EINVAL; - } - - stringstream ss2; - if (!cmdmap_from_json(cmd, &cmdmap, ss2)) { - ss << ss2.str(); - return -EINVAL; - } + string format; cmd_getval(g_ceph_context, cmdmap, "prefix", prefix); if (prefix != "pg") { @@ -292,33 +281,36 @@ int ReplicatedPG::do_command(vector& cmd, ostream& ss, return -EINVAL; } + cmd_getval(g_ceph_context, cmdmap, "format", format); + boost::scoped_ptr f(new_formatter(format)); + // demand that we have a formatter + if (!f) + f.reset(new_formatter("json")); + string command; cmd_getval(g_ceph_context, cmdmap, "cmd", command); if (command == "query") { - JSONFormatter jsf(true); - jsf.open_object_section("pg"); - jsf.dump_string("state", pg_state_string(get_state())); - jsf.dump_unsigned("epoch", get_osdmap()->get_epoch()); - jsf.open_array_section("up"); + f->open_object_section("pg"); + f->dump_string("state", pg_state_string(get_state())); + f->dump_unsigned("epoch", get_osdmap()->get_epoch()); + f->open_array_section("up"); for (vector::iterator p = up.begin(); p != up.end(); ++p) - jsf.dump_unsigned("osd", *p); - jsf.close_section(); - jsf.open_array_section("acting"); + f->dump_unsigned("osd", *p); + f->close_section(); + f->open_array_section("acting"); for (vector::iterator p = acting.begin(); p != acting.end(); ++p) - jsf.dump_unsigned("osd", *p); - jsf.close_section(); - jsf.open_object_section("info"); - info.dump(&jsf); - jsf.close_section(); - - jsf.open_array_section("recovery_state"); - handle_query_state(&jsf); - jsf.close_section(); - - jsf.close_section(); - stringstream dss; - jsf.flush(dss); - odata.append(dss); + f->dump_unsigned("osd", *p); + f->close_section(); + f->open_object_section("info"); + info.dump(f.get()); + f->close_section(); + + f->open_array_section("recovery_state"); + handle_query_state(f.get()); + f->close_section(); + + f->close_section(); + f->flush(odata); return 0; } else if (command == "mark_unfound_lost") { @@ -352,7 +344,6 @@ int ReplicatedPG::do_command(vector& cmd, ostream& ss, return 0; } else if (command == "list_missing") { - JSONFormatter jf(true); hobject_t offset; string offset_json; if (cmd_getval(g_ceph_context, cmdmap, "offset", offset_json)) { @@ -366,50 +357,48 @@ int ReplicatedPG::do_command(vector& cmd, ostream& ss, return -EINVAL; } } - jf.open_object_section("missing"); + f->open_object_section("missing"); { - jf.open_object_section("offset"); - offset.dump(&jf); - jf.close_section(); + f->open_object_section("offset"); + offset.dump(f.get()); + f->close_section(); } - jf.dump_int("num_missing", missing.num_missing()); - jf.dump_int("num_unfound", get_num_unfound()); + f->dump_int("num_missing", missing.num_missing()); + f->dump_int("num_unfound", get_num_unfound()); map::const_iterator p = missing.missing.upper_bound(offset); { - jf.open_array_section("objects"); + f->open_array_section("objects"); int32_t num = 0; bufferlist bl; while (p != missing.missing.end() && num < g_conf->osd_command_max_records) { - jf.open_object_section("object"); + f->open_object_section("object"); { - jf.open_object_section("oid"); - p->first.dump(&jf); - jf.close_section(); + f->open_object_section("oid"); + p->first.dump(f.get()); + f->close_section(); } - p->second.dump(&jf); // have, need keys + p->second.dump(f.get()); // have, need keys { - jf.open_array_section("locations"); + f->open_array_section("locations"); map >::iterator q = missing_loc.find(p->first); if (q != missing_loc.end()) for (set::iterator r = q->second.begin(); r != q->second.end(); ++r) - jf.dump_int("osd", *r); - jf.close_section(); + f->dump_int("osd", *r); + f->close_section(); } - jf.close_section(); + f->close_section(); ++p; num++; } - jf.close_section(); + f->close_section(); } - jf.dump_int("more", p != missing.missing.end()); - jf.close_section(); - stringstream jss; - jf.flush(jss); - odata.append(jss); + f->dump_int("more", p != missing.missing.end()); + f->close_section(); + f->flush(odata); return 0; }; - ss << "unknown command " << cmd; + ss << "unknown pg command " << prefix; return -EINVAL; } diff --git a/src/osd/ReplicatedPG.h b/src/osd/ReplicatedPG.h index 9dafe23faa1f..7b70b4381ea4 100644 --- a/src/osd/ReplicatedPG.h +++ b/src/osd/ReplicatedPG.h @@ -17,6 +17,7 @@ #include #include "include/assert.h" +#include "common/cmdparse.h" #include "PG.h" #include "OSD.h" @@ -930,7 +931,8 @@ public: const hobject_t& ioid); ~ReplicatedPG() {} - int do_command(vector& cmd, ostream& ss, bufferlist& idata, bufferlist& odata); + int do_command(cmdmap_t cmdmap, ostream& ss, bufferlist& idata, + bufferlist& odata); void do_op(OpRequestRef op); bool pg_op_must_wait(MOSDOp *op);