]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: restore format fallback semantic
authorLoic Dachary <ldachary@redhat.com>
Thu, 15 Jan 2015 11:28:12 +0000 (12:28 +0100)
committerLoic Dachary <ldachary@redhat.com>
Thu, 15 Jan 2015 12:26:26 +0000 (13:26 +0100)
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 <ldachary@redhat.com>
src/common/Formatter.cc
src/common/Formatter.h
src/common/admin_socket.cc
src/common/ceph_context.cc
src/mds/MDS.cc
src/mon/OSDMonitor.cc
src/osd/OSD.cc
src/osd/ReplicatedPG.cc
src/osdc/Objecter.cc

index 0bd6520063ca066a478efc6661cb532733bb0c0e..40a6bda76d98f1a937bdf327328a59ea5416f8ca 100644 (file)
@@ -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;
 }
index 4929a2f091c29fdfbd23abbb0e0cacad319ba7e0..b0dac7e0b1de8750795c3ff00b3d7a2f9518814e 100644 (file)
@@ -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();
index 248228bd5405a65d4e7fce6d9a74878c1a5304bf..3220e70ad6c1a7a0cd618b9c5dae9429d8d273f3 100644 (file)
@@ -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<string,string>::iterator p = m_as->m_help.begin();
         p != m_as->m_help.end();
index d649aa952a6098ffa119d639f1ef00cbd59e9dc9..bec006bfdf5485e01b7838fed0edf3673237495b 100644 (file)
@@ -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") {
index 10b33bf5260c3460112519828a57213c931b491b..0b840e08674de0f51b47122f46c938c5f292a223 100644 (file)
@@ -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();
index 963185c87af37a4b047c4ff158868793c6376ad7..5e9ea17c880f9022e031ddc7217b591d93e0a938 100644 (file)
@@ -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<Formatter> f(Formatter::create(format));
+    cmd_getval(g_ceph_context, cmdmap, "format", format);
+    boost::scoped_ptr<Formatter> 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<Formatter> f(Formatter::create(format));
+    cmd_getval(g_ceph_context, cmdmap, "format", format);
+    boost::scoped_ptr<Formatter> 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<Formatter> f(Formatter::create(format));
+    cmd_getval(g_ceph_context, cmdmap, "format", format);
+    boost::scoped_ptr<Formatter> 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<Formatter> f(Formatter::create(format));
+    cmd_getval(g_ceph_context, cmdmap, "format", format);
+    boost::scoped_ptr<Formatter> 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<Formatter> f(Formatter::create(format));
+    cmd_getval(g_ceph_context, cmdmap, "format", format);
+    boost::scoped_ptr<Formatter> 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<Formatter> f(Formatter::create(format));
+    cmd_getval(g_ceph_context, cmdmap, "format", format);
+    boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", "json-pretty"));
     f->open_object_section("crush_map_tunables");
     osdmap.crush->dump_tunables(f.get());
     f->close_section();
index bc56c7c7f75309336ca2dd4992f984d99abdd95d..d21f3b8441ec5d925d12daf7bad858ef850f46e2 100644 (file)
@@ -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;
index 7031d209cb12701181eda157b0a8fb9d80cd1d6f..3ece9be97d4d5968aa6e0bae6c53002af022b0d3 100644 (file)
@@ -603,7 +603,7 @@ int ReplicatedPG::do_command(cmdmap_t cmdmap, ostream& ss,
   string format;
 
   cmd_getval(cct, cmdmap, "format", format);
-  boost::scoped_ptr<Formatter> f(Formatter::create(format, "json"));
+  boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", "json"));
 
   string command;
   cmd_getval(cct, cmdmap, "cmd", command);
index ca472a693888ccc208998dfa7073ec4322aaf394..c79ca39b26745589f8b2554cd4eed21ba5e047ab 100644 (file)
@@ -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);