]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
AdminSocket users: use generic formatting
authorDan Mick <dan.mick@inktank.com>
Thu, 18 Jul 2013 21:38:33 +0000 (14:38 -0700)
committerDan Mick <dan.mick@inktank.com>
Fri, 26 Jul 2013 05:18:09 +0000 (22:18 -0700)
All call() routines get a format parameter; all places where
JSONFormatter was created get a new_formatter() instead.
'plain' formatting is unsupported, and help is forced to be
'json-pretty' as it was.

Signed-off-by: Dan Mick <dan.mick@inktank.com>
17 files changed:
src/client/Client.cc
src/client/Client.h
src/common/admin_socket.cc
src/common/admin_socket.h
src/common/ceph_context.cc
src/common/ceph_context.h
src/common/perf_counters.cc
src/common/perf_counters.h
src/mon/Monitor.cc
src/mon/Monitor.h
src/osd/OSD.cc
src/osd/OSD.h
src/osd/OpRequest.cc
src/osd/OpRequest.h
src/osdc/Objecter.cc
src/osdc/Objecter.h
src/test/bench/small_io_bench_fs.cc

index ba036ad998036415cf94ae3b3a5d6dd6ec7ba649..5a9c5fdafcca2087a7ba8fa2dbe307b4f6e28cab 100644 (file)
@@ -102,22 +102,24 @@ Client::CommandHook::CommandHook(Client *client) :
 {
 }
 
-bool Client::CommandHook::call(std::string command, std::string args, bufferlist& out)
+bool Client::CommandHook::call(std::string command, std::string args,
+                              std::string format, bufferlist& out)
 {
   stringstream ss;
-  JSONFormatter formatter(true);
+  Formatter *f = new_formatter(format);
   m_client->client_lock.Lock();
   if (command == "mds_requests")
-    m_client->dump_mds_requests(&formatter);
+    m_client->dump_mds_requests(f);
   else if (command == "mds_sessions")
-    m_client->dump_mds_sessions(&formatter);
+    m_client->dump_mds_sessions(f);
   else if (command == "dump_cache")
-    m_client->dump_cache(&formatter);
+    m_client->dump_cache(f);
   else
     assert(0 == "bad command registered");
   m_client->client_lock.Unlock();
-  formatter.flush(ss);
+  f->flush(ss);
   out.append(ss);
+  delete f;
   return true;
 }
 
index ade0b8f29c84d0f46c5ac1da5d0b8c30c1c4077d..bc1fbc0401b5c1a3a559686904c0c67fd02a57c9 100644 (file)
@@ -196,7 +196,8 @@ class Client : public Dispatcher {
     Client *m_client;
   public:
     CommandHook(Client *client);
-    bool call(std::string command, std::string args, bufferlist& out);
+    bool call(std::string command, std::string args, std::string format,
+             bufferlist& out);
   };
   CommandHook m_command_hook;
 
index f7ab3501dfff903303f87b86c6db1a86f224f1ff..5ebb3e040db8d75821e7f9f7bf863a6305beafa6 100644 (file)
@@ -310,6 +310,25 @@ bool AdminSocket::do_accept()
 
   bool rval = false;
 
+  map<string, cmd_vartype> cmdmap;
+  string format;
+  vector<string> cmdvec;
+  stringstream errss;
+  cmdvec.push_back(cmd);
+  if (!cmdmap_from_json(cmdvec, &cmdmap, errss)) {
+    ldout(m_cct, 0) << "AdminSocket: " << errss << dendl;
+    return false;
+  }
+  cmd_getval(m_cct, cmdmap, "format", format);
+  cmd_getval(m_cct, cmdmap, "prefix", c);
+
+  // we don't do plain here
+  if (format != "json" &&
+      format != "json-pretty" &&
+      format != "xml" &&
+      format != "xml-pretty")
+    format = "json";
+
   string firstword;
   if (c.find(" ") == string::npos)
     firstword = c;
@@ -341,7 +360,7 @@ bool AdminSocket::do_accept()
     string args;
     if (match != c)
       args = c.substr(match.length() + 1);
-    bool success = p->second->call(match, args, out);
+    bool success = p->second->call(match, args, format, out);
     if (!success) {
       ldout(m_cct, 0) << "AdminSocket: request '" << match << "' args '" << args
                      << "' to " << p->second << " failed" << dendl;
@@ -406,7 +425,8 @@ int AdminSocket::unregister_command(std::string command)
 
 class VersionHook : public AdminSocketHook {
 public:
-  virtual bool call(std::string command, std::string args, bufferlist& out) {
+  virtual bool call(std::string command, std::string args, std::string format,
+                   bufferlist& out) {
     if (command == "0") {
       out.append(CEPH_ADMIN_SOCK_VERSION);
     } else {
@@ -429,18 +449,21 @@ class HelpHook : public AdminSocketHook {
   AdminSocket *m_as;
 public:
   HelpHook(AdminSocket *as) : m_as(as) {}
-  bool call(string command, string args, bufferlist& out) {
-    JSONFormatter jf(true);
-    jf.open_object_section("help");
+  bool call(string command, string args, string format, bufferlist& out) {
+    // override format here because help should always be pretty and
+    // predictable
+    Formatter *f = new_formatter("json-pretty");
+    f->open_object_section("help");
     for (map<string,string>::iterator p = m_as->m_help.begin();
         p != m_as->m_help.end();
         ++p) {
-      jf.dump_string(p->first.c_str(), p->second);
+      f->dump_string(p->first.c_str(), p->second);
     }
-    jf.close_section();
+    f->close_section();
     ostringstream ss;
-    jf.flush(ss);
+    f->flush(ss);
     out.append(ss.str());
+    delete f;
     return true;
   }
 };
@@ -449,7 +472,7 @@ class GetdescsHook : public AdminSocketHook {
   AdminSocket *m_as;
 public:
   GetdescsHook(AdminSocket *as) : m_as(as) {}
-  bool call(string command, string args, bufferlist& out) {
+  bool call(string command, string args, string format, bufferlist& out) {
     int cmdnum = 0;
     JSONFormatter jf(false);
     jf.open_object_section("command_descriptions");
index c390bca0382c3c7f299704fd553448e2ea0fc3c6..30c5eb96ab8d65c692ee15f06689ba4201776d03 100644 (file)
@@ -29,7 +29,8 @@ class CephContext;
 
 class AdminSocketHook {
 public:
-  virtual bool call(std::string command, std::string args, bufferlist& out) = 0;
+  virtual bool call(std::string command, std::string args, std::string format,
+                   bufferlist& out) = 0;
   virtual ~AdminSocketHook() {};
 };
 
index cad980bb2a6f28b70969a125b2a4cb4bb070047b..e0fcf530222f4cc5ac2dff76ecd4ce4349d49ba0 100644 (file)
@@ -156,44 +156,46 @@ class CephContextHook : public AdminSocketHook {
 public:
   CephContextHook(CephContext *cct) : m_cct(cct) {}
 
-  bool call(std::string command, std::string args, bufferlist& out) {
-    m_cct->do_command(command, args, &out);
+  bool call(std::string command, std::string args, std::string format,
+           bufferlist& out) {
+    m_cct->do_command(command, args, format, &out);
     return true;
   }
 };
 
-void CephContext::do_command(std::string command, std::string args, bufferlist *out)
+void CephContext::do_command(std::string command, std::string args,
+                            std::string format, bufferlist *out)
 {
+  Formatter *f = new_formatter(format);
   lgeneric_dout(this, 1) << "do_command '" << command << "' '" << args << "'" << dendl;
   if (command == "perfcounters_dump" || command == "1" ||
       command == "perf dump") {
-    _perf_counters_collection->write_json_to_buf(*out, false);
+    _perf_counters_collection->dump_formatted(f, *out, false);
   }
   else if (command == "perfcounters_schema" || command == "2" ||
     command == "perf schema") {
-    _perf_counters_collection->write_json_to_buf(*out, true);
+    _perf_counters_collection->dump_formatted(f, *out, true);
   }
   else {
-    JSONFormatter jf(true);
-    jf.open_object_section(command.c_str());
+    f->open_object_section(command.c_str());
     if (command == "config show") {
-      _conf->show_config(&jf);
+      _conf->show_config(f);
     }
     else if (command == "config set") {
       std::string var = args;
       size_t pos = var.find(' ');
       if (pos == string::npos) {
-        jf.dump_string("error", "syntax error: 'config set <var> <value>'");
+        f->dump_string("error", "syntax error: 'config set <var> <value>'");
       } else {
         std::string val = var.substr(pos+1);
         var.resize(pos);
         int r = _conf->set_val(var.c_str(), val.c_str());
         if (r < 0) {
-          jf.dump_stream("error") << "error setting '" << var << "' to '" << val << "': " << cpp_strerror(r);
+          f->dump_stream("error") << "error setting '" << var << "' to '" << val << "': " << cpp_strerror(r);
         } else {
           ostringstream ss;
           _conf->apply_changes(&ss);
-          jf.dump_string("success", ss.str());
+          f->dump_string("success", ss.str());
         }
       }
     } else if (command == "config get") {
@@ -202,9 +204,9 @@ void CephContext::do_command(std::string command, std::string args, bufferlist *
         char *tmp = buf;
         int r = _conf->get_val(args.c_str(), &tmp, sizeof(buf));
         if (r < 0) {
-            jf.dump_stream("error") << "error getting '" << args << "': " << cpp_strerror(r);
+            f->dump_stream("error") << "error getting '" << args << "': " << cpp_strerror(r);
         } else {
-            jf.dump_string(args.c_str(), buf);
+            f->dump_string(args.c_str(), buf);
         }
     } else if (command == "log flush") {
       _log->flush();
@@ -218,11 +220,10 @@ void CephContext::do_command(std::string command, std::string args, bufferlist *
     else {
       assert(0 == "registered under wrong command?");    
     }
-    ostringstream ss;
-    jf.close_section();
-    jf.flush(ss);
-    out->append(ss.str());
+    f->close_section();
+    f->flush(*out);
   }
+  delete f;
   lgeneric_dout(this, 1) << "do_command '" << command << "' '" << args << "' result is " << out->length() << " bytes" << dendl;
 };
 
index 1678680fa6db59e350248754a7fb27a22e67d6ce..85618e35219340b6f59d8feaf6692302afc1135f 100644 (file)
@@ -97,7 +97,8 @@ public:
   /**
    * process an admin socket command
    */
-  void do_command(std::string command, std::string args, bufferlist *out);
+  void do_command(std::string command, std::string args, std::string foramt,
+                 bufferlist *out);
 
   /**
    * get a crypto handler
index 67a777497b38af2812b9f1997bf129be75b6e97f..46f55fae51bfcb7cde0db717e1b54e91c70a9ca4 100644 (file)
@@ -15,6 +15,7 @@
 #include "common/perf_counters.h"
 #include "common/dout.h"
 #include "common/errno.h"
+#include "common/Formatter.h"
 
 #include <errno.h>
 #include <inttypes.h>
@@ -72,21 +73,22 @@ void PerfCountersCollection::clear()
   }
 }
 
-void PerfCountersCollection::write_json_to_buf(bufferlist& bl, bool schema)
+void PerfCountersCollection::dump_formatted(Formatter *f, bufferlist &bl,
+                                           bool schema)
 {
   Mutex::Locker lck(m_lock);
-  bl.append('{');
+  f->open_object_section("perfcounter_collection");
   perf_counters_set_t::iterator l = m_loggers.begin();
   perf_counters_set_t::iterator l_end = m_loggers.end();
   if (l != l_end) {
     while (true) {
-      (*l)->write_json_to_buf(bl, schema);
+      (*l)->dump_formatted(f, schema);
       if (++l == l_end)
        break;
-      bl.append(',');
     }
   }
-  bl.append('}');
+  f->close_section();
+  f->flush(bl);
 }
 
 // ---------------------------
@@ -203,34 +205,54 @@ utime_t PerfCounters::tget(int idx) const
   return utime_t(data.u64 / 1000000000ull, data.u64 % 1000000000ull);
 }
 
-void PerfCounters::write_json_to_buf(bufferlist& bl, bool schema)
+void PerfCounters::dump_formatted(Formatter *f, bool schema)
 {
-  char buf[512];
   Mutex::Locker lck(m_lock);
 
-  snprintf(buf, sizeof(buf), "\"%s\":{", m_name.c_str());
-  bl.append(buf);
-
+  f->open_object_section(m_name.c_str());
   perf_counter_data_vec_t::const_iterator d = m_data.begin();
   perf_counter_data_vec_t::const_iterator d_end = m_data.end();
   if (d == d_end) {
-    bl.append('}');
+    f->close_section();
     return;
   }
   while (true) {
-    const perf_counter_data_any_d &data(*d);
-    buf[0] = '\0';
-    if (schema)
-      data.write_schema_json(buf, sizeof(buf));
-    else
-      data.write_json(buf, sizeof(buf));
-
-    bl.append(buf);
+    if (schema) {
+      f->open_object_section(d->name);
+      f->dump_int("type", d->type);
+      f->close_section();
+    } else {
+      if (d->type & PERFCOUNTER_LONGRUNAVG) {
+       f->open_object_section(d->name);
+       if (d->type & PERFCOUNTER_U64) {
+         f->dump_format("avgcount", "%"PRId64, d->avgcount);
+         f->dump_format("sum", "%"PRId64, d->u64);
+       } else if (d->type & PERFCOUNTER_TIME) {
+         f->dump_format("avgcount", "%"PRId64, d->avgcount);
+         f->dump_format("sum", "%"PRId64"%09"PRId64,
+                        d->u64 / 1000000000ull,
+                        d->u64 % 1000000000ull);
+       } else {
+         assert(0);
+       }
+       f->close_section();
+      } else {
+       if (d->type & PERFCOUNTER_U64) {
+         f->dump_format(d->name, "%"PRId64, d->u64);
+       } else if (d->type & PERFCOUNTER_TIME) {
+         f->dump_format(d->name, "%"PRId64"%09"PRId64,
+                        d->u64 / 1000000000ull,
+                        d->u64 % 1000000000ull);
+       } else {
+         assert(0);
+       }
+      }
+    }
+
     if (++d == d_end)
       break;
-    bl.append(',');
   }
-  bl.append('}');
+  f->close_section();
 }
 
 const std::string &PerfCounters::get_name() const
@@ -258,42 +280,6 @@ PerfCounters::perf_counter_data_any_d::perf_counter_data_any_d()
 {
 }
 
-void  PerfCounters::perf_counter_data_any_d::write_schema_json(char *buf, size_t buf_sz) const
-{
-  snprintf(buf, buf_sz, "\"%s\":{\"type\":%d}", name, type);
-}
-
-void  PerfCounters::perf_counter_data_any_d::write_json(char *buf, size_t buf_sz) const
-{
-  if (type & PERFCOUNTER_LONGRUNAVG) {
-    if (type & PERFCOUNTER_U64) {
-      snprintf(buf, buf_sz, "\"%s\":{\"avgcount\":%" PRId64 ","
-             "\"sum\":%" PRId64 "}", 
-             name, avgcount, u64);
-    }
-    else if (type & PERFCOUNTER_TIME) {
-      snprintf(buf, buf_sz, "\"%s\":{\"avgcount\":%" PRId64 ","
-             "\"sum\":%llu.%09llu}",
-              name, avgcount, u64 / 1000000000ull, u64 % 1000000000ull);
-    }
-    else {
-      assert(0);
-    }
-  }
-  else {
-    if (type & PERFCOUNTER_U64) {
-      snprintf(buf, buf_sz, "\"%s\":%" PRId64,
-              name, u64);
-    }
-    else if (type & PERFCOUNTER_TIME) {
-      snprintf(buf, buf_sz, "\"%s\":%llu.%09llu", name, u64 / 1000000000ull, u64 % 1000000000ull);
-    }
-    else {
-      assert(0);
-    }
-  }
-}
-
 PerfCountersBuilder::PerfCountersBuilder(CephContext *cct, const std::string &name,
                   int first, int last)
   : m_perf_counters(new PerfCounters(cct, name, first, last))
index 269a32f2c46f8e2821d9eff5d9d23bcfc11641b7..125d84c04e34a0f28a58e7164277ae64064a7286 100644 (file)
@@ -76,7 +76,7 @@ public:
   void tinc(int idx, utime_t v);
   utime_t tget(int idx) const;
 
-  void write_json_to_buf(ceph::bufferlist& bl, bool schema);
+  void dump_formatted(ceph::Formatter *f, bool schema);
 
   const std::string& get_name() const;
   void set_name(std::string s) {
@@ -136,7 +136,7 @@ public:
   void add(class PerfCounters *l);
   void remove(class PerfCounters *l);
   void clear();
-  void write_json_to_buf(ceph::bufferlist& bl, bool schema);
+  void dump_formatted(ceph::Formatter *f, bufferlist &bl, bool schema);
 private:
   CephContext *m_cct;
 
index bf500dff218fc24ebdd17d7e063fa4308b559731..119ef740aa83405517b47e135a458531c5a59c59 100644 (file)
@@ -225,21 +225,20 @@ class AdminHook : public AdminSocketHook {
   Monitor *mon;
 public:
   AdminHook(Monitor *m) : mon(m) {}
-  bool call(std::string command, std::string args, bufferlist& out) {
+  bool call(std::string command, std::string args, std::string format,
+           bufferlist& out) {
     stringstream ss;
-    mon->do_admin_command(command, args, ss);
+    mon->do_admin_command(command, args, format, ss);
     out.append(ss);
     return true;
   }
 };
 
-void Monitor::do_admin_command(string command, string args, ostream& ss)
+void Monitor::do_admin_command(string command, string args, string format,
+                              ostream& ss)
 {
   Mutex::Locker l(lock);
 
-  map<string, cmd_vartype> cmdmap;
-  string format;
-  cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
   boost::scoped_ptr<Formatter> f(new_formatter(format));
 
   if (command == "mon_status")
index 82b08816702b0d00f01d6b5295a91e35917c8d2a..bed48ecee3436093858f8af979e2805972088bcc 100644 (file)
@@ -745,7 +745,8 @@ public:
   int write_fsid();
   int write_fsid(MonitorDBStore::Transaction &t);
 
-  void do_admin_command(std::string command, std::string args, ostream& ss);
+  void do_admin_command(std::string command, std::string args,
+                       std::string format, ostream& ss);
 
 private:
   // don't allow copying
index bc3aa604fecf6085b04ae05469b22735f5498b10..dd9a5b7293f33a36a6374a433de67265cdd083c4 100644 (file)
@@ -997,44 +997,46 @@ class OSDSocketHook : public AdminSocketHook {
   OSD *osd;
 public:
   OSDSocketHook(OSD *o) : osd(o) {}
-  bool call(std::string command, std::string args, bufferlist& out) {
+  bool call(std::string command, std::string args, std::string format,
+           bufferlist& out) {
     stringstream ss;
-    bool r = osd->asok_command(command, args, ss);
+    bool r = osd->asok_command(command, args, format, ss);
     out.append(ss);
     return r;
   }
 };
 
-bool OSD::asok_command(string command, string args, ostream& ss)
+bool OSD::asok_command(string command, string args, string format, ostream& ss)
 {
+  if (format == "")
+    format = "json-pretty";
+  Formatter *f = new_formatter(format);
   if (command == "dump_ops_in_flight") {
-    op_tracker.dump_ops_in_flight(ss);
+    op_tracker.dump_ops_in_flight(f, ss);
   } else if (command == "dump_historic_ops") {
-    op_tracker.dump_historic_ops(ss);
+    op_tracker.dump_historic_ops(f, ss);
   } else if (command == "dump_op_pq_state") {
-    JSONFormatter f(true);
-    f.open_object_section("pq");
-    op_wq.dump(&f);
-    f.close_section();
-    f.flush(ss);
+    f->open_object_section("pq");
+    op_wq.dump(f);
+    f->close_section();
+    f->flush(ss);
   } else if (command == "dump_blacklist") {
     list<pair<entity_addr_t,utime_t> > bl;
     OSDMapRef curmap = service.get_osdmap();
 
-    JSONFormatter f(true);
-    f.open_array_section("blacklist");
+    f->open_array_section("blacklist");
     curmap->get_blacklist(&bl);
     for (list<pair<entity_addr_t,utime_t> >::iterator it = bl.begin();
        it != bl.end(); ++it) {
-      f.open_array_section("entry");
-      f.open_object_section("entity_addr_t");
-      it->first.dump(&f);
-      f.close_section(); //entity_addr_t
-      it->second.localtime(f.dump_stream("expire_time"));
-      f.close_section(); //entry
-    }
-    f.close_section(); //blacklist
-    f.flush(ss);
+      f->open_array_section("entry");
+      f->open_object_section("entity_addr_t");
+      it->first.dump(f);
+      f->close_section(); //entity_addr_t
+      it->second.localtime(f->dump_stream("expire_time"));
+      f->close_section(); //entry
+    }
+    f->close_section(); //blacklist
+    f->flush(ss);
   } else if (command == "dump_watchers") {
     list<obj_watch_item_t> watchers;
     osd_lock.Lock();
@@ -1052,32 +1054,31 @@ bool OSD::asok_command(string command, string args, ostream& ss)
     }
     osd_lock.Unlock();
 
-    JSONFormatter f(true);
-    f.open_array_section("watchers");
+    f->open_array_section("watchers");
     for (list<obj_watch_item_t>::iterator it = watchers.begin();
        it != watchers.end(); ++it) {
 
-      f.open_array_section("watch");
+      f->open_array_section("watch");
 
-      f.dump_string("namespace", it->obj.nspace);
-      f.dump_string("object", it->obj.oid.name);
+      f->dump_string("namespace", it->obj.nspace);
+      f->dump_string("object", it->obj.oid.name);
 
-      f.open_object_section("entity_name");
-      it->wi.name.dump(&f);
-      f.close_section(); //entity_name_t
+      f->open_object_section("entity_name");
+      it->wi.name.dump(f);
+      f->close_section(); //entity_name_t
 
-      f.dump_int("cookie", it->wi.cookie);
-      f.dump_int("timeout", it->wi.timeout_seconds);
+      f->dump_int("cookie", it->wi.cookie);
+      f->dump_int("timeout", it->wi.timeout_seconds);
 
-      f.open_object_section("entity_addr_t");
-      it->wi.addr.dump(&f);
-      f.close_section(); //entity_addr_t
+      f->open_object_section("entity_addr_t");
+      it->wi.addr.dump(f);
+      f->close_section(); //entity_addr_t
 
-      f.close_section(); //watch
+      f->close_section(); //watch
     }
 
-    f.close_section(); //watches
-    f.flush(ss);
+    f->close_section(); //watches
+    f->flush(ss);
   } else {
     assert(0 == "broken asok registration");
   }
@@ -1089,7 +1090,8 @@ class TestOpsSocketHook : public AdminSocketHook {
   ObjectStore *store;
 public:
   TestOpsSocketHook(OSDService *s, ObjectStore *st) : service(s), store(st) {}
-  bool call(std::string command, std::string args, bufferlist& out) {
+  bool call(std::string command, std::string args, std::string format,
+           bufferlist& out) {
     stringstream ss;
     test_ops(service, store, command, args, ss);
     out.append(ss);
index f9ceaf81bf391556f3a0783f5bda482c3f2265f6..5bcff7442d7a62d628808a7405910a9ca2b12c72 100644 (file)
@@ -622,7 +622,7 @@ protected:
   // asok
   friend class OSDSocketHook;
   class OSDSocketHook *asok_hook;
-  bool asok_command(string command, string args, ostream& ss);
+  bool asok_command(string command, string args, string format, ostream& ss);
 
 public:
   ClassHandler  *class_handler;
index 3b8a8714d92217d64de0582bb171b8668a26303d..c0d167a5f0ad1aeb049a6c295a5b8af0b78bd7e0 100644 (file)
@@ -76,31 +76,29 @@ void OpHistory::dump_ops(utime_t now, Formatter *f)
   f->close_section();
 }
 
-void OpTracker::dump_historic_ops(ostream &ss)
+void OpTracker::dump_historic_ops(Formatter *f, ostream &ss)
 {
-  JSONFormatter jf(true);
   Mutex::Locker locker(ops_in_flight_lock);
   utime_t now = ceph_clock_now(g_ceph_context);
-  history.dump_ops(now, &jf);
-  jf.flush(ss);
+  history.dump_ops(now, f);
+  f->flush(ss);
 }
 
-void OpTracker::dump_ops_in_flight(ostream &ss)
+void OpTracker::dump_ops_in_flight(Formatter *f, ostream &ss)
 {
-  JSONFormatter jf(true);
   Mutex::Locker locker(ops_in_flight_lock);
-  jf.open_object_section("ops_in_flight"); // overall dump
-  jf.dump_int("num_ops", ops_in_flight.size());
-  jf.open_array_section("ops"); // list of OpRequests
+  f->open_object_section("ops_in_flight"); // overall dump
+  f->dump_int("num_ops", ops_in_flight.size());
+  f->open_array_section("ops"); // list of OpRequests
   utime_t now = ceph_clock_now(g_ceph_context);
   for (xlist<OpRequest*>::iterator p = ops_in_flight.begin(); !p.end(); ++p) {
-    jf.open_object_section("op");
-    (*p)->dump(now, &jf);
-    jf.close_section(); // this OpRequest
+    f->open_object_section("op");
+    (*p)->dump(now, f);
+    f->close_section(); // this OpRequest
   }
-  jf.close_section(); // list of OpRequests
-  jf.close_section(); // overall dump
-  jf.flush(ss);
+  f->close_section(); // list of OpRequests
+  f->close_section(); // overall dump
+  f->flush(ss);
 }
 
 void OpTracker::register_inflight_op(xlist<OpRequest*>::item *i)
index 47b050b85381536ef6059d61d768e9c27e3e3755..67ee26b02ec140e2346053d50e7c5737a315e8d9 100644 (file)
@@ -59,8 +59,8 @@ class OpTracker {
 
 public:
   OpTracker() : seq(0), ops_in_flight_lock("OpTracker mutex") {}
-  void dump_ops_in_flight(std::ostream& ss);
-  void dump_historic_ops(std::ostream& ss);
+  void dump_ops_in_flight(Formatter *f, std::ostream& ss);
+  void dump_historic_ops(Formatter *f, std::ostream& ss);
   void register_inflight_op(xlist<OpRequest*>::item *i);
   void unregister_inflight_op(OpRequest *i);
 
index a5a023cb33e66e8628ea66fa7495a9b66df20558..e07d0626d21e4e0507be358f809ccabbd53232c3 100644 (file)
@@ -2180,154 +2180,154 @@ void Objecter::dump_active()
   }
 }
 
-void Objecter::dump_requests(Formatterfmt) const
+void Objecter::dump_requests(Formatter *fmt) const
 {
   assert(client_lock.is_locked());
 
-  fmt.open_object_section("requests");
+  fmt->open_object_section("requests");
   dump_ops(fmt);
   dump_linger_ops(fmt);
   dump_pool_ops(fmt);
   dump_pool_stat_ops(fmt);
   dump_statfs_ops(fmt);
   dump_command_ops(fmt);
-  fmt.close_section(); // requests object
+  fmt->close_section(); // requests object
 }
 
-void Objecter::dump_ops(Formatterfmt) const
+void Objecter::dump_ops(Formatter *fmt) const
 {
-  fmt.open_array_section("ops");
+  fmt->open_array_section("ops");
   for (map<tid_t,Op*>::const_iterator p = ops.begin();
        p != ops.end();
        ++p) {
     Op *op = p->second;
-    fmt.open_object_section("op");
-    fmt.dump_unsigned("tid", op->tid);
-    fmt.dump_stream("pg") << op->pgid;
-    fmt.dump_int("osd", op->session ? op->session->osd : -1);
-    fmt.dump_stream("last_sent") << op->stamp;
-    fmt.dump_int("attempts", op->attempts);
-    fmt.dump_stream("object_id") << op->oid;
-    fmt.dump_stream("object_locator") << op->oloc;
-    fmt.dump_stream("snapid") << op->snapid;
-    fmt.dump_stream("snap_context") << op->snapc;
-    fmt.dump_stream("mtime") << op->mtime;
-
-    fmt.open_array_section("osd_ops");
+    fmt->open_object_section("op");
+    fmt->dump_unsigned("tid", op->tid);
+    fmt->dump_stream("pg") << op->pgid;
+    fmt->dump_int("osd", op->session ? op->session->osd : -1);
+    fmt->dump_stream("last_sent") << op->stamp;
+    fmt->dump_int("attempts", op->attempts);
+    fmt->dump_stream("object_id") << op->oid;
+    fmt->dump_stream("object_locator") << op->oloc;
+    fmt->dump_stream("snapid") << op->snapid;
+    fmt->dump_stream("snap_context") << op->snapc;
+    fmt->dump_stream("mtime") << op->mtime;
+
+    fmt->open_array_section("osd_ops");
     for (vector<OSDOp>::const_iterator it = op->ops.begin();
         it != op->ops.end();
         ++it) {
-      fmt.dump_stream("osd_op") << *it;
+      fmt->dump_stream("osd_op") << *it;
     }
-    fmt.close_section(); // osd_ops array
+    fmt->close_section(); // osd_ops array
 
-    fmt.close_section(); // op object
+    fmt->close_section(); // op object
   }
-  fmt.close_section(); // ops array
+  fmt->close_section(); // ops array
 }
 
-void Objecter::dump_linger_ops(Formatterfmt) const
+void Objecter::dump_linger_ops(Formatter *fmt) const
 {
-  fmt.open_array_section("linger_ops");
+  fmt->open_array_section("linger_ops");
   for (map<uint64_t, LingerOp*>::const_iterator p = linger_ops.begin();
        p != linger_ops.end();
        ++p) {
     LingerOp *op = p->second;
-    fmt.open_object_section("linger_op");
-    fmt.dump_unsigned("linger_id", op->linger_id);
-    fmt.dump_stream("pg") << op->pgid;
-    fmt.dump_int("osd", op->session ? op->session->osd : -1);
-    fmt.dump_stream("object_id") << op->oid;
-    fmt.dump_stream("object_locator") << op->oloc;
-    fmt.dump_stream("snapid") << op->snap;
-    fmt.dump_stream("registering") << op->snap;
-    fmt.dump_stream("registered") << op->snap;
-    fmt.close_section(); // linger_op object
+    fmt->open_object_section("linger_op");
+    fmt->dump_unsigned("linger_id", op->linger_id);
+    fmt->dump_stream("pg") << op->pgid;
+    fmt->dump_int("osd", op->session ? op->session->osd : -1);
+    fmt->dump_stream("object_id") << op->oid;
+    fmt->dump_stream("object_locator") << op->oloc;
+    fmt->dump_stream("snapid") << op->snap;
+    fmt->dump_stream("registering") << op->snap;
+    fmt->dump_stream("registered") << op->snap;
+    fmt->close_section(); // linger_op object
   }
-  fmt.close_section(); // linger_ops array
+  fmt->close_section(); // linger_ops array
 }
 
-void Objecter::dump_command_ops(Formatterfmt) const
+void Objecter::dump_command_ops(Formatter *fmt) const
 {
-  fmt.open_array_section("command_ops");
+  fmt->open_array_section("command_ops");
   for (map<uint64_t, CommandOp*>::const_iterator p = command_ops.begin();
        p != command_ops.end();
        ++p) {
     CommandOp *op = p->second;
-    fmt.open_object_section("command_op");
-    fmt.dump_unsigned("command_id", op->tid);
-    fmt.dump_int("osd", op->session ? op->session->osd : -1);
-    fmt.open_array_section("command");
+    fmt->open_object_section("command_op");
+    fmt->dump_unsigned("command_id", op->tid);
+    fmt->dump_int("osd", op->session ? op->session->osd : -1);
+    fmt->open_array_section("command");
     for (vector<string>::const_iterator q = op->cmd.begin(); q != op->cmd.end(); ++q)
-      fmt.dump_string("word", *q);
-    fmt.close_section();
+      fmt->dump_string("word", *q);
+    fmt->close_section();
     if (op->target_osd >= 0)
-      fmt.dump_int("target_osd", op->target_osd);
+      fmt->dump_int("target_osd", op->target_osd);
     else
-      fmt.dump_stream("target_pg") << op->target_pg;
-    fmt.close_section(); // command_op object
+      fmt->dump_stream("target_pg") << op->target_pg;
+    fmt->close_section(); // command_op object
   }
-  fmt.close_section(); // command_ops array
+  fmt->close_section(); // command_ops array
 }
 
-void Objecter::dump_pool_ops(Formatterfmt) const
+void Objecter::dump_pool_ops(Formatter *fmt) const
 {
-  fmt.open_array_section("pool_ops");
+  fmt->open_array_section("pool_ops");
   for (map<tid_t, PoolOp*>::const_iterator p = pool_ops.begin();
        p != pool_ops.end();
        ++p) {
     PoolOp *op = p->second;
-    fmt.open_object_section("pool_op");
-    fmt.dump_unsigned("tid", op->tid);
-    fmt.dump_int("pool", op->pool);
-    fmt.dump_string("name", op->name);
-    fmt.dump_int("operation_type", op->pool_op);
-    fmt.dump_unsigned("auid", op->auid);
-    fmt.dump_unsigned("crush_rule", op->crush_rule);
-    fmt.dump_stream("snapid") << op->snapid;
-    fmt.dump_stream("last_sent") << op->last_submit;
-    fmt.close_section(); // pool_op object
+    fmt->open_object_section("pool_op");
+    fmt->dump_unsigned("tid", op->tid);
+    fmt->dump_int("pool", op->pool);
+    fmt->dump_string("name", op->name);
+    fmt->dump_int("operation_type", op->pool_op);
+    fmt->dump_unsigned("auid", op->auid);
+    fmt->dump_unsigned("crush_rule", op->crush_rule);
+    fmt->dump_stream("snapid") << op->snapid;
+    fmt->dump_stream("last_sent") << op->last_submit;
+    fmt->close_section(); // pool_op object
   }
-  fmt.close_section(); // pool_ops array
+  fmt->close_section(); // pool_ops array
 }
 
-void Objecter::dump_pool_stat_ops(Formatterfmt) const
+void Objecter::dump_pool_stat_ops(Formatter *fmt) const
 {
-  fmt.open_array_section("pool_stat_ops");
+  fmt->open_array_section("pool_stat_ops");
   for (map<tid_t, PoolStatOp*>::const_iterator p = poolstat_ops.begin();
        p != poolstat_ops.end();
        ++p) {
     PoolStatOp *op = p->second;
-    fmt.open_object_section("pool_stat_op");
-    fmt.dump_unsigned("tid", op->tid);
-    fmt.dump_stream("last_sent") << op->last_submit;
+    fmt->open_object_section("pool_stat_op");
+    fmt->dump_unsigned("tid", op->tid);
+    fmt->dump_stream("last_sent") << op->last_submit;
 
-    fmt.open_array_section("pools");
+    fmt->open_array_section("pools");
     for (list<string>::const_iterator it = op->pools.begin();
         it != op->pools.end();
         ++it) {
-      fmt.dump_string("pool", *it);
+      fmt->dump_string("pool", *it);
     }
-    fmt.close_section(); // pool_op object
+    fmt->close_section(); // pool_op object
 
-    fmt.close_section(); // pool_stat_op object
+    fmt->close_section(); // pool_stat_op object
   }
-  fmt.close_section(); // pool_stat_ops array
+  fmt->close_section(); // pool_stat_ops array
 }
 
-void Objecter::dump_statfs_ops(Formatterfmt) const
+void Objecter::dump_statfs_ops(Formatter *fmt) const
 {
-  fmt.open_array_section("statfs_ops");
+  fmt->open_array_section("statfs_ops");
   for (map<tid_t, StatfsOp*>::const_iterator p = statfs_ops.begin();
        p != statfs_ops.end();
        ++p) {
     StatfsOp *op = p->second;
-    fmt.open_object_section("statfs_op");
-    fmt.dump_unsigned("tid", op->tid);
-    fmt.dump_stream("last_sent") << op->last_submit;
-    fmt.close_section(); // pool_stat_op object
+    fmt->open_object_section("statfs_op");
+    fmt->dump_unsigned("tid", op->tid);
+    fmt->dump_stream("last_sent") << op->last_submit;
+    fmt->close_section(); // pool_stat_op object
   }
-  fmt.close_section(); // pool_stat_ops array
+  fmt->close_section(); // pool_stat_ops array
 }
 
 Objecter::RequestStateHook::RequestStateHook(Objecter *objecter) :
@@ -2335,14 +2335,16 @@ Objecter::RequestStateHook::RequestStateHook(Objecter *objecter) :
 {
 }
 
-bool Objecter::RequestStateHook::call(std::string command, std::string args, bufferlist& out)
+bool Objecter::RequestStateHook::call(std::string command, std::string args,
+                                     std::string format, bufferlist& out)
 {
   stringstream ss;
-  JSONFormatter formatter(true);
+  Formatter *f = new_formatter(format);
   m_objecter->client_lock.Lock();
-  m_objecter->dump_requests(formatter);
+  m_objecter->dump_requests(f);
   m_objecter->client_lock.Unlock();
-  formatter.flush(ss);
+  f->flush(ss);
+  delete f;
   out.append(ss);
   return true;
 }
index c1cac88b60e4fd2f54735133b269ceb46c82651e..aa4a20d8b0bec9999c4303b78a894b1ade3360e7 100644 (file)
@@ -726,7 +726,8 @@ class Objecter {
     Objecter *m_objecter;
   public:
     RequestStateHook(Objecter *objecter);
-    bool call(std::string command, std::string args, bufferlist& out);
+    bool call(std::string command, std::string args, std::string format,
+             bufferlist& out);
   };
 
   RequestStateHook *m_request_state_hook;
@@ -1236,13 +1237,13 @@ private:
    * Output in-flight requests
    */
   void dump_active();
-  void dump_requests(Formatterfmt) const;
-  void dump_ops(Formatterfmt) const;
-  void dump_linger_ops(Formatterfmt) const;
-  void dump_command_ops(Formatterfmt) const;
-  void dump_pool_ops(Formatterfmt) const;
-  void dump_pool_stat_ops(Formatterfmt) const;
-  void dump_statfs_ops(Formatterfmt) const;
+  void dump_requests(Formatter *fmt) const;
+  void dump_ops(Formatter *fmt) const;
+  void dump_linger_ops(Formatter *fmt) const;
+  void dump_command_ops(Formatter *fmt) const;
+  void dump_pool_ops(Formatter *fmt) const;
+  void dump_pool_stat_ops(Formatter *fmt) const;
+  void dump_statfs_ops(Formatter *fmt) const;
 
   int get_client_incarnation() const { return client_inc; }
   void set_client_incarnation(int inc) { client_inc = inc; }
index 61fbacc5570cabb7f1a114a8e945ff0b163b578b..138757f7304c11e3370f28ecd5b4988104458b55 100644 (file)
@@ -32,7 +32,9 @@ struct MorePrinting : public DetailedStatCollector::AdditionalPrinting {
   MorePrinting(CephContext *cct) : cct(cct) {}
   void operator()(std::ostream *out) {
     bufferlist bl;
-    cct->get_perfcounters_collection()->write_json_to_buf(bl, 0);
+    Formatter *f = new_formatter("json-pretty");
+    cct->get_perfcounters_collection()->dump_formatted(f, bl, 0);
+    delete f;
     bl.append('\0');
     *out << bl.c_str() << std::endl;
   }