From: Loic Dachary Date: Thu, 15 Jan 2015 11:28:12 +0000 (+0100) Subject: common: restore format fallback semantic X-Git-Tag: v0.93~284^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8d8ce96b586f57cb2a2e50f6453db8201de96b2a;p=ceph.git common: restore format fallback semantic When Formatter::create replaced new_formatter, the handling of an invalid format was also incorrectly changed. When an invalid format (for instance "plain") was specified, new_formatter returned a NULL pointer which was sometime handled by creating a json-pretty formatter and sometimes differently. A new Formatter::create prototype with a fallback argument is added and is used if it is not the empty string and that the format is not known. This prototype is used where new_formatter returning NULL was replaced by a json-pretty formatter. http://tracker.ceph.com/issues/10547 Fixes: #10547 Signed-off-by: Loic Dachary --- diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index 0bd6520063ca..40a6bda76d98 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -64,7 +64,8 @@ Formatter::Formatter() { } Formatter::~Formatter() { } Formatter *Formatter::create(const std::string &type, - const std::string& default_type) + const std::string& default_type, + const std::string& fallback) { std::string mytype = type; if (mytype == "") @@ -82,6 +83,8 @@ Formatter *Formatter::create(const std::string &type, return new TableFormatter(); else if (mytype == "table-kv") return new TableFormatter(true); + else if (fallback != "") + return create(fallback, "", ""); else return (Formatter *) NULL; } diff --git a/src/common/Formatter.h b/src/common/Formatter.h index 4929a2f091c2..b0dac7e0b1de 100644 --- a/src/common/Formatter.h +++ b/src/common/Formatter.h @@ -28,9 +28,14 @@ namespace ceph { class Formatter { public: static Formatter *create(const std::string& type, - const std::string& default_type); + const std::string& default_type, + const std::string& fallback); + static Formatter *create(const std::string& type, + const std::string& default_type) { + return create(type, default_type, ""); + } static Formatter *create(const std::string& type) { - return create(type, "json-pretty"); + return create(type, "json-pretty", ""); } Formatter(); diff --git a/src/common/admin_socket.cc b/src/common/admin_socket.cc index 248228bd5405..3220e70ad6c1 100644 --- a/src/common/admin_socket.cc +++ b/src/common/admin_socket.cc @@ -448,7 +448,7 @@ class HelpHook : public AdminSocketHook { public: HelpHook(AdminSocket *as) : m_as(as) {} bool call(string command, cmdmap_t &cmdmap, string format, bufferlist& out) { - Formatter *f = Formatter::create(format); + Formatter *f = Formatter::create(format, "json-pretty", "json-pretty"); f->open_object_section("help"); for (map::iterator p = m_as->m_help.begin(); p != m_as->m_help.end(); diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index d649aa952a60..bec006bfdf54 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -225,7 +225,7 @@ public: void CephContext::do_command(std::string command, cmdmap_t& cmdmap, std::string format, bufferlist *out) { - Formatter *f = Formatter::create(format); + Formatter *f = Formatter::create(format, "json-pretty", "json-pretty"); stringstream ss; for (cmdmap_t::iterator it = cmdmap.begin(); it != cmdmap.end(); ++it) { if (it->first != "prefix") { diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index 10b33bf5260c..0b840e08674d 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -221,7 +221,7 @@ bool MDS::asok_command(string command, cmdmap_t& cmdmap, string format, { dout(1) << "asok_command: " << command << " (starting...)" << dendl; - Formatter *f = Formatter::create(format); + Formatter *f = Formatter::create(format, "json-pretty", "json-pretty"); if (command == "status") { const OSDMap *osdmap = objecter->get_osdmap_read(); diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 963185c87af3..5e9ea17c880f 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2478,8 +2478,8 @@ bool OSDMonitor::preprocess_command(MMonCommand *m) goto reply; } string format; - cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(Formatter::create(format)); + cmd_getval(g_ceph_context, cmdmap, "format", format); + boost::scoped_ptr f(Formatter::create(format, "json-pretty", "json-pretty")); f->open_object_section("osd_location"); f->dump_int("osd", osd); f->dump_stream("ip") << osdmap.get_addr(osd); @@ -2504,8 +2504,8 @@ bool OSDMonitor::preprocess_command(MMonCommand *m) goto reply; } string format; - cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(Formatter::create(format)); + cmd_getval(g_ceph_context, cmdmap, "format", format); + boost::scoped_ptr f(Formatter::create(format, "json-pretty", "json-pretty")); f->open_object_section("osd_metadata"); r = dump_osd_metadata(osd, f.get(), &ss); if (r < 0) @@ -3001,8 +3001,8 @@ stats_out: } else if (prefix == "osd crush rule list" || prefix == "osd crush rule ls") { string format; - cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(Formatter::create(format)); + cmd_getval(g_ceph_context, cmdmap, "format", format); + boost::scoped_ptr f(Formatter::create(format, "json-pretty", "json-pretty")); f->open_array_section("rules"); osdmap.crush->list_rules(f.get()); f->close_section(); @@ -3014,8 +3014,8 @@ stats_out: string name; cmd_getval(g_ceph_context, cmdmap, "name", name); string format; - cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(Formatter::create(format)); + cmd_getval(g_ceph_context, cmdmap, "format", format); + boost::scoped_ptr f(Formatter::create(format, "json-pretty", "json-pretty")); if (name == "") { f->open_array_section("rules"); osdmap.crush->dump_rules(f.get()); @@ -3035,8 +3035,8 @@ stats_out: rdata.append(rs.str()); } else if (prefix == "osd crush dump") { string format; - cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(Formatter::create(format)); + cmd_getval(g_ceph_context, cmdmap, "format", format); + boost::scoped_ptr f(Formatter::create(format, "json-pretty", "json-pretty")); f->open_object_section("crush_map"); osdmap.crush->dump(f.get()); f->close_section(); @@ -3046,8 +3046,8 @@ stats_out: rdata.append(rs.str()); } else if (prefix == "osd crush show-tunables") { string format; - cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(Formatter::create(format)); + cmd_getval(g_ceph_context, cmdmap, "format", format); + boost::scoped_ptr f(Formatter::create(format, "json-pretty", "json-pretty")); f->open_object_section("crush_map_tunables"); osdmap.crush->dump_tunables(f.get()); f->close_section(); diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index bc56c7c7f753..d21f3b8441ec 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1626,7 +1626,7 @@ public: bool OSD::asok_command(string command, cmdmap_t& cmdmap, string format, ostream& ss) { - Formatter *f = Formatter::create(format); + Formatter *f = Formatter::create(format, "json-pretty", "json-pretty"); if (command == "status") { f->open_object_section("status"); f->dump_stream("cluster_fsid") << superblock.cluster_fsid; diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index 7031d209cb12..3ece9be97d4d 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -603,7 +603,7 @@ int ReplicatedPG::do_command(cmdmap_t cmdmap, ostream& ss, string format; cmd_getval(cct, cmdmap, "format", format); - boost::scoped_ptr f(Formatter::create(format, "json")); + boost::scoped_ptr f(Formatter::create(format, "json-pretty", "json")); string command; cmd_getval(cct, cmdmap, "cmd", command); diff --git a/src/osdc/Objecter.cc b/src/osdc/Objecter.cc index ca472a693888..c79ca39b2674 100644 --- a/src/osdc/Objecter.cc +++ b/src/osdc/Objecter.cc @@ -4225,7 +4225,7 @@ Objecter::RequestStateHook::RequestStateHook(Objecter *objecter) : bool Objecter::RequestStateHook::call(std::string command, cmdmap_t& cmdmap, std::string format, bufferlist& out) { - Formatter *f = Formatter::create(format); + Formatter *f = Formatter::create(format, "json-pretty", "json-pretty"); RWLock::RLocker rl(m_objecter->rwlock); m_objecter->dump_requests(f); f->flush(out);