summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Mick <dan.mick@inktank.com>2013-07-18 14:38:33 -0700
committerDan Mick <dan.mick@inktank.com>2013-07-25 22:18:09 -0700
commit3f598e8c65731c3451c1aecf8ec0925e34b0bec8 (patch)
tree6e5fa8b75daf7e0c9227ae1db99ebdd20fd40f9e
parent4aeb73a5e6d46f970dbd684a58f795d379a04bd9 (diff)
downloadceph-3f598e8c65731c3451c1aecf8ec0925e34b0bec8.tar.gz
AdminSocket users: use generic formatting
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>
-rw-r--r--src/client/Client.cc14
-rw-r--r--src/client/Client.h3
-rw-r--r--src/common/admin_socket.cc41
-rw-r--r--src/common/admin_socket.h3
-rw-r--r--src/common/ceph_context.cc35
-rw-r--r--src/common/ceph_context.h3
-rw-r--r--src/common/perf_counters.cc100
-rw-r--r--src/common/perf_counters.h4
-rw-r--r--src/mon/Monitor.cc11
-rw-r--r--src/mon/Monitor.h3
-rw-r--r--src/osd/OSD.cc78
-rw-r--r--src/osd/OSD.h2
-rw-r--r--src/osd/OpRequest.cc28
-rw-r--r--src/osd/OpRequest.h4
-rw-r--r--src/osdc/Objecter.cc164
-rw-r--r--src/osdc/Objecter.h17
-rw-r--r--src/test/bench/small_io_bench_fs.cc4
17 files changed, 267 insertions, 247 deletions
diff --git a/src/client/Client.cc b/src/client/Client.cc
index ba036ad9980..5a9c5fdafcc 100644
--- a/src/client/Client.cc
+++ b/src/client/Client.cc
@@ -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;
}
diff --git a/src/client/Client.h b/src/client/Client.h
index ade0b8f29c8..bc1fbc0401b 100644
--- a/src/client/Client.h
+++ b/src/client/Client.h
@@ -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;
diff --git a/src/common/admin_socket.cc b/src/common/admin_socket.cc
index f7ab3501dff..5ebb3e040db 100644
--- a/src/common/admin_socket.cc
+++ b/src/common/admin_socket.cc
@@ -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");
diff --git a/src/common/admin_socket.h b/src/common/admin_socket.h
index c390bca0382..30c5eb96ab8 100644
--- a/src/common/admin_socket.h
+++ b/src/common/admin_socket.h
@@ -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() {};
};
diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc
index cad980bb2a6..e0fcf530222 100644
--- a/src/common/ceph_context.cc
+++ b/src/common/ceph_context.cc
@@ -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;
};
diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h
index 1678680fa6d..85618e35219 100644
--- a/src/common/ceph_context.h
+++ b/src/common/ceph_context.h
@@ -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
diff --git a/src/common/perf_counters.cc b/src/common/perf_counters.cc
index 67a777497b3..46f55fae51b 100644
--- a/src/common/perf_counters.cc
+++ b/src/common/perf_counters.cc
@@ -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))
diff --git a/src/common/perf_counters.h b/src/common/perf_counters.h
index 269a32f2c46..125d84c04e3 100644
--- a/src/common/perf_counters.h
+++ b/src/common/perf_counters.h
@@ -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;
diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc
index bf500dff218..119ef740aa8 100644
--- a/src/mon/Monitor.cc
+++ b/src/mon/Monitor.cc
@@ -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")
diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h
index 82b08816702..bed48ecee34 100644
--- a/src/mon/Monitor.h
+++ b/src/mon/Monitor.h
@@ -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
diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc
index bc3aa604fec..dd9a5b7293f 100644
--- a/src/osd/OSD.cc
+++ b/src/osd/OSD.cc
@@ -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);
diff --git a/src/osd/OSD.h b/src/osd/OSD.h
index f9ceaf81bf3..5bcff7442d7 100644
--- a/src/osd/OSD.h
+++ b/src/osd/OSD.h
@@ -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;
diff --git a/src/osd/OpRequest.cc b/src/osd/OpRequest.cc
index 3b8a8714d92..c0d167a5f0a 100644
--- a/src/osd/OpRequest.cc
+++ b/src/osd/OpRequest.cc
@@ -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)
diff --git a/src/osd/OpRequest.h b/src/osd/OpRequest.h
index 47b050b8538..67ee26b02ec 100644
--- a/src/osd/OpRequest.h
+++ b/src/osd/OpRequest.h
@@ -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);
diff --git a/src/osdc/Objecter.cc b/src/osdc/Objecter.cc
index a5a023cb33e..e07d0626d21 100644
--- a/src/osdc/Objecter.cc
+++ b/src/osdc/Objecter.cc
@@ -2180,154 +2180,154 @@ void Objecter::dump_active()
}
}
-void Objecter::dump_requests(Formatter& fmt) 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(Formatter& fmt) 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(Formatter& fmt) 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(Formatter& fmt) 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(Formatter& fmt) 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(Formatter& fmt) 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(Formatter& fmt) 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;
}
diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h
index c1cac88b60e..aa4a20d8b0b 100644
--- a/src/osdc/Objecter.h
+++ b/src/osdc/Objecter.h
@@ -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(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;
+ 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; }
diff --git a/src/test/bench/small_io_bench_fs.cc b/src/test/bench/small_io_bench_fs.cc
index 61fbacc5570..138757f7304 100644
--- a/src/test/bench/small_io_bench_fs.cc
+++ b/src/test/bench/small_io_bench_fs.cc
@@ -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;
}