int Client::CommandHook::call(
std::string_view command,
const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out)
{
- std::unique_ptr<Formatter> f(Formatter::create(format));
f->open_object_section("result");
{
std::lock_guard l{m_client->client_lock};
if (command == "mds_requests")
- m_client->dump_mds_requests(f.get());
+ m_client->dump_mds_requests(f);
else if (command == "mds_sessions")
- m_client->dump_mds_sessions(f.get());
+ m_client->dump_mds_sessions(f);
else if (command == "dump_cache")
- m_client->dump_cache(f.get());
+ m_client->dump_cache(f);
else if (command == "kick_stale_sessions")
m_client->_kick_stale_sessions();
else if (command == "status")
- m_client->dump_status(f.get());
+ m_client->dump_status(f);
else
ceph_abort_msg("bad command registered");
}
f->close_section();
- f->flush(out);
return 0;
}
public:
explicit CommandHook(Client *client);
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override;
private:
return on_finish(-EINVAL, "invalid json, missing format and/or prefix",
empty);
}
- if (format != "json" && format != "json-pretty" &&
- format != "xml" && format != "xml-pretty")
- format = "json-pretty";
+
+ Formatter *f = Formatter::create(format, "json-pretty", "json-pretty");
std::unique_lock l(lock);
decltype(hooks)::iterator p;
if (p == hooks.cend()) {
lderr(m_cct) << "AdminSocket: request '" << cmdvec
<< "' not defined" << dendl;
+ delete f;
return on_finish(-EINVAL, "unknown command prefix "s + prefix, empty);
}
while (!validate_cmd(m_cct, p->second.desc, cmdmap, errss)) {
++p;
if (p->first != prefix) {
+ delete f;
return on_finish(-EINVAL, "invalid command json", empty);
}
}
in_hook = true;
auto hook = p->second.hook;
l.unlock();
- hook->call_async(prefix, cmdmap, format, inbl, on_finish);
+ hook->call_async(
+ prefix, cmdmap, f, inbl,
+ [f, on_finish](int r, const std::string& err, bufferlist& out) {
+ // handle either existing output in bufferlist *or* via formatter
+ if (r >= 0 && out.length() == 0) {
+ f->flush(out);
+ }
+ delete f;
+ on_finish(r, err, out);
+ });
l.lock();
in_hook = false;
class VersionHook : public AdminSocketHook {
public:
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override {
if (command == "0"sv) {
out.append(CEPH_ADMIN_SOCK_VERSION);
} else {
- JSONFormatter jf;
- jf.open_object_section("version");
+ f->open_object_section("version");
if (command == "version") {
- jf.dump_string("version", ceph_version_to_str());
- jf.dump_string("release", ceph_release_to_str());
- jf.dump_string("release_type", ceph_release_type());
+ f->dump_string("version", ceph_version_to_str());
+ f->dump_string("release", ceph_release_to_str());
+ f->dump_string("release_type", ceph_release_type());
} else if (command == "git_version") {
- jf.dump_string("git_version", git_version_to_str());
+ f->dump_string("git_version", git_version_to_str());
}
ostringstream ss;
- jf.close_section();
- jf.enable_line_break();
- jf.flush(ss);
- out.append(ss.str());
+ f->close_section();
}
return 0;
}
public:
explicit HelpHook(AdminSocket *as) : m_as(as) {}
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override {
- std::unique_ptr<Formatter> f(Formatter::create(format, "json-pretty"sv,
- "json-pretty"sv));
f->open_object_section("help");
for (const auto& [command, info] : m_as->hooks) {
if (info.help.length())
f->dump_string(command.c_str(), info.help);
}
f->close_section();
- ostringstream ss;
- f->flush(ss);
- out.append(ss.str());
return 0;
}
};
public:
explicit GetdescsHook(AdminSocket *as) : m_as(as) {}
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override {
int cmdnum = 0;
- JSONFormatter jf;
- jf.open_object_section("command_descriptions");
+ f->open_object_section("command_descriptions");
for (const auto& [command, info] : m_as->hooks) {
// GCC 8 actually has [[maybe_unused]] on a structured binding
// do what you'd expect. GCC 7 does not.
(void)command;
ostringstream secname;
secname << "cmd" << setfill('0') << std::setw(3) << cmdnum;
- dump_cmd_and_help_to_json(&jf,
+ dump_cmd_and_help_to_json(f,
CEPH_FEATURES_ALL,
secname.str().c_str(),
info.desc,
info.help);
cmdnum++;
}
- jf.close_section(); // command_descriptions
- jf.enable_line_break();
- ostringstream ss;
- jf.flush(ss);
- out.append(ss.str());
+ f->close_section(); // command_descriptions
return 0;
}
};
virtual int call(
std::string_view command,
const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
ceph::buffer::list& out) = 0;
+
virtual void call_async(
std::string_view command,
const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
const bufferlist& inbl,
std::function<void(int,const std::string&,bufferlist&)> on_finish) {
// by default, call the synchronous handler and then finish
bufferlist out;
std::ostringstream errss;
- int r = call(command, cmdmap, format, errss, out);
+ int r = call(command, cmdmap, f, errss, out);
on_finish(r, errss.str(), out);
}
virtual ~AdminSocketHook() {}
// AdminSocketHook
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override {
if (command == "dump_mempools") {
- std::unique_ptr<Formatter> f(Formatter::create(format));
f->open_object_section("mempools");
- mempool::dump(f.get());
+ mempool::dump(f);
f->close_section();
- f->flush(out);
return 0;
}
return -ENOSYS;
explicit CephContextHook(CephContext *cct) : m_cct(cct) {}
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override {
try {
- return m_cct->do_command(command, cmdmap, format, errss, &out);
+ return m_cct->do_command(command, cmdmap, f, errss, &out);
} catch (const bad_cmd_get& e) {
return -EINVAL;
}
};
int CephContext::do_command(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist *out)
{
try {
- return _do_command(command, cmdmap, format, ss, out);
+ return _do_command(command, cmdmap, f, ss, out);
} catch (const bad_cmd_get& e) {
ss << e.what();
return -EINVAL;
int CephContext::_do_command(
std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist *out)
{
- Formatter *f = Formatter::create(format, "json-pretty", "json-pretty");
int r = 0;
lgeneric_dout(this, 1) << "do_command '" << command << "' '" << cmdmap << "'"
<< dendl;
}
f->close_section();
}
- if (r >= 0) {
- f->flush(*out);
- }
- delete f;
lgeneric_dout(this, 1) << "do_command '" << command << "' '" << cmdmap
<< "' result is " << out->length() << " bytes" << dendl;
return r;
* process an admin socket command
*/
int do_command(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
ceph::bufferlist *out);
int _do_command(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
ceph::bufferlist *out);
class LibrbdAdminSocketCommand {
public:
virtual ~LibrbdAdminSocketCommand() {}
- virtual bool call(stringstream *ss) = 0;
+ virtual int call(Formatter *f) = 0;
};
class FlushCacheCommand : public LibrbdAdminSocketCommand {
public:
explicit FlushCacheCommand(ImageCtx *ictx) : ictx(ictx) {}
- bool call(stringstream *ss) override {
- int r = ictx->io_work_queue->flush();
- if (r < 0) {
- *ss << "flush: " << cpp_strerror(r);
- return false;
- }
- return true;
+ int call(Formatter *f) override {
+ return ictx->io_work_queue->flush();
}
private:
public:
explicit InvalidateCacheCommand(ImageCtx *ictx) : ictx(ictx) {}
- bool call(stringstream *ss) override {
- int r = invalidate_cache(ictx);
- if (r < 0) {
- *ss << "invalidate_cache: " << cpp_strerror(r);
- return false;
- }
- return true;
+ int call(Formatter *f) override {
+ return invalidate_cache(ictx);
}
private:
int LibrbdAdminSocketHook::call(std::string_view command,
const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) {
Commands::const_iterator i = commands.find(command);
ceph_assert(i != commands.end());
- stringstream outss;
- int r = i->second->call(&outss);
- out.append(outss);
- return r;
+ return i->second->call(f);
}
} // namespace librbd
~LibrbdAdminSocketHook() override;
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override;
public:
explicit MDSSocketHook(MDSDaemon *m) : mds(m) {}
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& out) override {
stringstream outss;
- int r = mds->asok_command(command, cmdmap, format, outss);
+ int r = mds->asok_command(command, cmdmap, f, outss);
out.append(outss);
return r;
}
};
int MDSDaemon::asok_command(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format, std::ostream& ss)
+ Formatter *f, std::ostream& ss)
{
dout(1) << "asok_command: " << command << " (starting...)" << dendl;
- Formatter *f = Formatter::create(format, "json-pretty", "json-pretty");
int r = -ENOSYS;
if (command == "status") {
dump_status(f);
}
}
}
- f->flush(ss);
- delete f;
-
dout(1) << "asok_command: " << command << " (complete)" << dendl;
-
return r;
}
void clean_up_admin_socket();
void check_ops_in_flight(); // send off any slow ops to monitor
int asok_command(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format, ostream& ss);
+ Formatter *f, ostream& ss);
void dump_status(Formatter *f);
public:
explicit ClusterSocketHook(ClusterState *o) : cluster_state(o) {}
int call(std::string_view admin_command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override {
stringstream outss;
int r = 0;
try {
- r = cluster_state->asok_command(admin_command, cmdmap, format, outss);
+ r = cluster_state->asok_command(admin_command, cmdmap, f, outss);
out.append(outss);
} catch (const bad_cmd_get& e) {
errss << e.what();
asok_hook = NULL;
}
-bool ClusterState::asok_command(std::string_view admin_command, const cmdmap_t& cmdmap,
- std::string_view format, ostream& ss)
+bool ClusterState::asok_command(
+ std::string_view admin_command,
+ const cmdmap_t& cmdmap,
+ Formatter *f,
+ ostream& ss)
{
std::lock_guard l(lock);
- Formatter *f = Formatter::create(format, "json-pretty", "json-pretty");
if (admin_command == "dump_osd_network") {
int64_t value = 0;
// Default to health warning level if nothing specified
} else {
ceph_abort_msg("broken asok registration");
}
- f->flush(ss);
- delete f;
return true;
}
}
void final_init();
void shutdown();
- bool asok_command(std::string_view admin_command, const cmdmap_t& cmdmap,
- std::string_view format, ostream& ss);
+ bool asok_command(std::string_view admin_command,
+ const cmdmap_t& cmdmap,
+ Formatter *f,
+ ostream& ss);
};
#endif
public:
explicit AdminHook(Monitor *m) : mon(m) {}
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override {
stringstream outss;
- mon->do_admin_command(command, cmdmap, format, outss);
+ mon->do_admin_command(command, cmdmap, f, errss, outss);
out.append(outss);
return 0;
}
};
-void Monitor::do_admin_command(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format, std::ostream& ss)
+void Monitor::do_admin_command(
+ std::string_view command,
+ const cmdmap_t& cmdmap,
+ Formatter *f,
+ std::ostream& err,
+ std::ostream& out)
{
std::lock_guard l(lock);
- boost::scoped_ptr<Formatter> f(Formatter::create(format));
-
string args;
for (auto p = cmdmap.begin();
p != cmdmap.end(); ++p) {
<< "cmd='" << command << "' args=" << args << ": dispatch";
if (command == "mon_status") {
- get_mon_status(f.get(), ss);
- if (f)
- f->flush(ss);
+ get_mon_status(f, out);
} else if (command == "quorum_status") {
- _quorum_status(f.get(), ss);
+ _quorum_status(f, out);
} else if (command == "sync_force") {
string validate;
if ((!cmd_getval(g_ceph_context, cmdmap, "validate", validate)) ||
(validate != "--yes-i-really-mean-it")) {
- ss << "are you SURE? this will mean the monitor store will be erased "
- "the next time the monitor is restarted. pass "
- "'--yes-i-really-mean-it' if you really do.";
+ err << "are you SURE? this will mean the monitor store will be erased "
+ "the next time the monitor is restarted. pass "
+ "'--yes-i-really-mean-it' if you really do.";
goto abort;
}
- sync_force(f.get(), ss);
+ sync_force(f, out);
} else if (command.compare(0, 23, "add_bootstrap_peer_hint") == 0 ||
command.compare(0, 24, "add_bootstrap_peer_hintv") == 0) {
- if (!_add_bootstrap_peer_hint(command, cmdmap, ss))
+ if (!_add_bootstrap_peer_hint(command, cmdmap, out))
goto abort;
} else if (command == "quorum enter") {
elector.start_participating();
start_election();
- ss << "started responding to quorum, initiated new election";
+ out << "started responding to quorum, initiated new election";
} else if (command == "quorum exit") {
start_election();
elector.stop_participating();
- ss << "stopped responding to quorum, initiated new election";
+ out << "stopped responding to quorum, initiated new election";
} else if (command == "ops") {
- (void)op_tracker.dump_ops_in_flight(f.get());
- if (f) {
- f->flush(ss);
- }
+ (void)op_tracker.dump_ops_in_flight(f);
} else if (command == "sessions") {
-
- if (f) {
- f->open_array_section("sessions");
- for (auto p : session_map.sessions) {
- f->dump_stream("session") << *p;
- }
- f->close_section();
- f->flush(ss);
+ f->open_array_section("sessions");
+ for (auto p : session_map.sessions) {
+ f->dump_stream("session") << *p;
}
-
+ f->close_section();
} else if (command == "dump_historic_ops") {
- if (op_tracker.dump_historic_ops(f.get())) {
- f->flush(ss);
- } else {
- ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
+ if (!op_tracker.dump_historic_ops(f)) {
+ err << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
please enable \"mon_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
}
} else if (command == "dump_historic_ops_by_duration" ) {
- if (op_tracker.dump_historic_ops(f.get(), true)) {
- f->flush(ss);
- } else {
- ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
+ if (op_tracker.dump_historic_ops(f, true)) {
+ err << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
please enable \"mon_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
}
} else if (command == "dump_historic_slow_ops") {
- if (op_tracker.dump_historic_slow_ops(f.get(), {})) {
- f->flush(ss);
- } else {
- ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
+ if (op_tracker.dump_historic_slow_ops(f, {})) {
+ err << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
please enable \"mon_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
}
} else {
int write_fsid(MonitorDBStore::TransactionRef t);
void do_admin_command(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format, std::ostream& ss);
+ Formatter *f,
+ std::ostream& err,
+ std::ostream& out);
private:
// don't allow copying
}
}
- int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ int call(std::string_view command,
+ const cmdmap_t& cmdmap,
+ Formatter *f,
std::ostream& ss,
bufferlist& out) override {
int r = 0;
if (command == "bluestore allocator dump " + name) {
- Formatter *f = Formatter::create(format, "json-pretty", "json-pretty");
f->open_array_section("free_regions");
auto iterated_allocation = [&](size_t off, size_t len) {
ceph_assert(len > 0);
f->close_section();
};
alloc->dump(iterated_allocation);
-
-
f->close_section();
- f->flush(out);
} else if (command == "bluestore allocator score " + name) {
- Formatter *f = Formatter::create(format, "json-pretty", "json-pretty");
f->open_object_section("fragmentation_score");
f->dump_float("fragmentation_rating", alloc->get_fragmentation_score());
f->close_section();
- f->flush(out);
- delete f;
} else if (command == "bluestore allocator fragmentation " + name) {
- Formatter* f = Formatter::create(format, "json-pretty", "json-pretty");
f->open_object_section("fragmentation");
f->dump_float("fragmentation_rating", alloc->get_fragmentation());
f->close_section();
- f->flush(out);
- delete f;
} else {
ss << "Invalid command" << std::endl;
r = -ENOSYS;
SocketHook(BlueFS* bluefs) :
bluefs(bluefs) {}
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& out) override {
if (command == "bluestore bluefs available") {
}
if (alloc_size == 0)
alloc_size = bluefs->cct->_conf->bluefs_alloc_size;
- Formatter *f = Formatter::create(format, "json-pretty", "json-pretty");
f->open_object_section("bluefs_available_space");
for (unsigned dev = BDEV_WAL; dev <= BDEV_SLOW; dev++) {
if (bluefs->bdev[dev]) {
}
f->dump_int("available_from_bluestore", extra_space);
f->close_section();
- f->flush(out);
- delete f;
} else {
ss << "Invalid command" << std::endl;
return -ENOSYS;
public:
explicit OSDSocketHook(OSD *o) : osd(o) {}
int call(std::string_view prefix, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& out) override {
ceph_abort("should use async hook");
void call_async(
std::string_view prefix,
const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
const bufferlist& inbl,
std::function<void(int,const std::string&,bufferlist&)> on_finish) override {
try {
- osd->asok_command(prefix, cmdmap, format, inbl, on_finish);
+ osd->asok_command(prefix, cmdmap, f, inbl, on_finish);
} catch (const bad_cmd_get& e) {
bufferlist empty;
on_finish(-EINVAL, e.what(), empty);
void OSD::asok_command(
std::string_view prefix, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
const bufferlist& inbl,
std::function<void(int,const std::string&,bufferlist&)> on_finish)
{
- std::unique_ptr<Formatter> f(Formatter::create(
- format, "json-pretty", "json-pretty"));
int ret = 0;
stringstream ss; // stderr error message stream
bufferlist outbl; // if empty at end, we'll dump formatter as output
if (prefix == "dump_ops_in_flight" ||
prefix == "ops") {
- if (!op_tracker.dump_ops_in_flight(f.get(), false, filters)) {
+ if (!op_tracker.dump_ops_in_flight(f, false, filters)) {
ss << error_str;
ret = -EINVAL;
goto out;
}
}
if (prefix == "dump_blocked_ops") {
- if (!op_tracker.dump_ops_in_flight(f.get(), true, filters)) {
+ if (!op_tracker.dump_ops_in_flight(f, true, filters)) {
ss << error_str;
ret = -EINVAL;
goto out;
}
}
if (prefix == "dump_historic_ops") {
- if (!op_tracker.dump_historic_ops(f.get(), false, filters)) {
+ if (!op_tracker.dump_historic_ops(f, false, filters)) {
ss << error_str;
ret = -EINVAL;
goto out;
}
}
if (prefix == "dump_historic_ops_by_duration") {
- if (!op_tracker.dump_historic_ops(f.get(), true, filters)) {
+ if (!op_tracker.dump_historic_ops(f, true, filters)) {
ss << error_str;
ret = -EINVAL;
goto out;
}
}
if (prefix == "dump_historic_slow_ops") {
- if (!op_tracker.dump_historic_slow_ops(f.get(), filters)) {
+ if (!op_tracker.dump_historic_slow_ops(f, filters)) {
ss << error_str;
ret = -EINVAL;
goto out;
}
} else if (prefix == "dump_op_pq_state") {
f->open_object_section("pq");
- op_shardedwq.dump(f.get());
+ op_shardedwq.dump(f);
f->close_section();
} else if (prefix == "dump_blacklist") {
list<pair<entity_addr_t,utime_t> > bl;
it != bl.end(); ++it) {
f->open_object_section("entry");
f->open_object_section("entity_addr_t");
- it->first.dump(f.get());
+ it->first.dump(f);
f->close_section(); //entity_addr_t
it->second.localtime(f->dump_stream("expire_time"));
f->close_section(); //entry
f->dump_string("object", it->obj.oid.name);
f->open_object_section("entity_name");
- it->wi.name.dump(f.get());
+ it->wi.name.dump(f);
f->close_section(); //entity_name_t
f->dump_unsigned("cookie", it->wi.cookie);
f->dump_unsigned("timeout", it->wi.timeout_seconds);
f->open_object_section("entity_addr_t");
- it->wi.addr.dump(f.get());
+ it->wi.addr.dump(f);
f->close_section(); //entity_addr_t
f->close_section(); //watch
} else if (prefix == "dump_recovery_reservations") {
f->open_object_section("reservations");
f->open_object_section("local_reservations");
- service.local_reserver.dump(f.get());
+ service.local_reserver.dump(f);
f->close_section();
f->open_object_section("remote_reservations");
- service.remote_reserver.dump(f.get());
+ service.remote_reserver.dump(f);
f->close_section();
f->close_section();
} else if (prefix == "dump_scrub_reservations") {
f->dump_int("value", value);
f->close_section();
} else if (prefix == "dump_objectstore_kv_stats") {
- store->get_db_statistics(f.get());
+ store->get_db_statistics(f);
} else if (prefix == "dump_scrubs") {
- service.dumps_scrub(f.get());
+ service.dumps_scrub(f);
} else if (prefix == "calc_objectstore_db_histogram") {
- store->generate_db_histogram(f.get());
+ store->generate_db_histogram(f);
} else if (prefix == "flush_store_cache") {
store->flush_cache(&ss);
} else if (prefix == "dump_pgstate_history") {
f->open_object_section("pg");
f->dump_stream("pg") << pg->pg_id;
f->dump_string("currently", pg->get_current_state());
- pg->dump_pgstate_history(f.get());
+ pg->dump_pgstate_history(f);
f->close_section();
}
f->close_section();
string s = stringify(pg->pg_id);
f->open_array_section(s.c_str());
pg->lock();
- pg->dump_missing(f.get());
+ pg->dump_missing(f);
pg->unlock();
f->close_section();
}
else if (prefix == "dump_pg_recovery_stats") {
lock_guard l(osd_lock);
- pg_recovery_stats.dump_formatted(f.get());
+ pg_recovery_stats.dump_formatted(f);
}
else if (prefix == "reset_pg_recovery_stats") {
cmd_getval(cct, cmdmap, "logger", logger);
cmd_getval(cct, cmdmap, "counter", counter);
cct->get_perfcounters_collection()->dump_formatted_histograms(
- f.get(), false, logger, counter);
+ f, false, logger, counter);
}
else if (prefix == "cache drop") {
}
f->open_object_section("cache_status");
f->dump_int("object_ctx", obj_ctx_count);
- store->dump_cache_stats(f.get());
+ store->dump_cache_stats(f);
f->close_section();
}
}
out:
- if (ret >= 0 && outbl.length() == 0) {
- f->flush(outbl);
- }
on_finish(ret, ss.str(), outbl);
}
public:
TestOpsSocketHook(OSDService *s, ObjectStore *st) : service(s), store(st) {}
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override {
int r = 0;
void asok_command(
std::string_view prefix,
const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
const bufferlist& inbl,
std::function<void(int,const std::string&,bufferlist&)> on_finish);
public:
explicit RequestStateHook(Objecter *objecter);
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
ceph::buffer::list& out) override;
};
int Objecter::RequestStateHook::call(std::string_view command,
const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
ceph::buffer::list& out)
{
- Formatter *f = Formatter::create(format, "json-pretty", "json-pretty");
shared_lock rl(m_objecter->rwlock);
m_objecter->dump_requests(f);
- f->flush(out);
- delete f;
return 0;
}
if (m_dump_perf_counters) {
string command = "perf dump";
cmdmap_t cmdmap;
- string format = "json-pretty";
+ JSONFormatter jf(true);
bufferlist out;
stringstream ss;
- g_ceph_context->do_command(command, cmdmap, format, ss, &out);
- out.write_stream(cout);
+ g_ceph_context->do_command(command, cmdmap, &jf, ss, &out);
+ jf.flush(cout);
cout << std::endl;
cout.flush();
}
if (m_dump_perf_counters && !m_images.empty()) {
string command = "perf dump";
cmdmap_t cmdmap;
- string format = "json-pretty";
+ JSONFormatter jf(true);
bufferlist out;
stringstream ss;
- g_ceph_context->do_command(command, cmdmap, format, ss, &out);
- out.write_stream(cout);
+ g_ceph_context->do_command(command, cmdmap, &jf, ss, &out);
+ jf.flush(cout);
cout << std::endl;
+ cout.flush();
}
for (auto& p : m_images) {
delete p.second;
int RGWCoroutinesManagerRegistry::call(std::string_view command,
const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& out) {
std::shared_lock rl{lock};
- JSONFormatter f;
- ::encode_json("cr_managers", *this, &f);
- f.flush(out);
+ ::encode_json("cr_managers", *this, f);
return 0;
}
int hook_to_admin_command(const string& command);
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& out) override;
return 0;
}
-static void dump_node(RGWSyncTraceNode *entry, bool show_history, JSONFormatter& f)
+static void dump_node(RGWSyncTraceNode *entry, bool show_history, Formatter *f)
{
- f.open_object_section("entry");
- ::encode_json("status", entry->to_str(), &f);
+ f->open_object_section("entry");
+ ::encode_json("status", entry->to_str(), f);
if (show_history) {
- f.open_array_section("history");
+ f->open_array_section("history");
for (auto h : entry->get_history()) {
- ::encode_json("entry", h, &f);
+ ::encode_json("entry", h, f);
}
- f.close_section();
+ f->close_section();
}
- f.close_section();
+ f->close_section();
}
string RGWSyncTraceManager::get_active_names()
}
int RGWSyncTraceManager::call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& out) {
shunique_lock rl(lock, ceph::acquire_shared);
- JSONFormatter f(true);
-
- f.open_object_section("result");
- f.open_array_section("running");
+ f->open_object_section("result");
+ f->open_array_section("running");
for (auto n : nodes) {
auto& entry = n.second;
if (show_short) {
const string& name = entry->get_resource_name();
if (!name.empty()) {
- ::encode_json("entry", name, &f);
+ ::encode_json("entry", name, f);
}
} else {
dump_node(entry.get(), show_history, f);
}
- f.flush(out);
+ f->flush(out);
}
- f.close_section();
+ f->close_section();
- f.open_array_section("complete");
+ f->open_array_section("complete");
for (auto& entry : complete_nodes) {
if (!search.empty() && !entry->match(search, show_history)) {
continue;
continue;
}
dump_node(entry.get(), show_history, f);
- f.flush(out);
+ f->flush(out);
}
- f.close_section();
+ f->close_section();
- f.close_section();
- f.flush(out);
+ f->close_section();
return 0;
}
int hook_to_admin_command();
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& out) override;
string get_active_names();
void shutdown();
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& out) override;
};
int RGWSI_SysObj_Cache_ASocketHook::call(
std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& out)
{
if (auto i = cmdmap.find("filter"); i != cmdmap.cend()) {
filter = boost::get<std::string>(i->second);
}
- std::unique_ptr<Formatter> f(ceph::Formatter::create(format, "table"));
- if (f) {
- f->open_array_section("cache_entries");
- svc->asocket.call_list(filter, f.get());
- f->close_section();
- f->flush(out);
- return 0;
- } else {
- ss << "Unable to create Formatter.\n";
- return -EINVAL;
- }
+ f->open_array_section("cache_entries");
+ svc->asocket.call_list(filter, f);
+ f->close_section();
+ return 0;
} else if (command == "cache inspect"sv) {
- std::unique_ptr<Formatter> f(ceph::Formatter::create(format, "json-pretty"));
- if (f) {
- const auto& target = boost::get<std::string>(cmdmap.at("target"));
- if (svc->asocket.call_inspect(target, f.get())) {
- f->flush(out);
- return 0;
- } else {
- ss << "Unable to find entry "s + target + ".\n";
- return -ENOENT;
- }
+ const auto& target = boost::get<std::string>(cmdmap.at("target"));
+ if (svc->asocket.call_inspect(target, f)) {
+ return 0;
} else {
- ss << "Unable to create Formatter.\n";
- return -EINVAL;
+ ss << "Unable to find entry "s + target + ".\n";
+ return -ENOENT;
}
} else if (command == "cache erase"sv) {
const auto& target = boost::get<std::string>(cmdmap.at("target"));
class MyTest : public AdminSocketHook {
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& result) override {
std::vector<std::string> args;
class MyTest2 : public AdminSocketHook {
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& result) override {
std::vector<std::string> args;
BlockingHook() = default;
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& result) override {
std::unique_lock l{_lock};
{
stringstream ss;
bufferlist out;
- cct->do_command("config get", cmdmap, "xml", ss, &out);
+ std::unique_ptr<Formatter> f(Formatter::create("xml", "xml"));
+ cct->do_command("config get", cmdmap, f.get(), ss, &out);
+ f->flush(out);
string s(out.c_str(), out.length());
EXPECT_EQ("<config_get><key>" + value + "</key></config_get>", s);
}
stringstream ss;
bufferlist out;
cmdmap_t bad_cmdmap; // no 'var' field
- int r = cct->do_command("config get", bad_cmdmap, "xml", ss, &out);
+ std::unique_ptr<Formatter> f(Formatter::create("xml", "xml"));
+ int r = cct->do_command("config get", bad_cmdmap, f.get(), ss, &out);
+ if (r >= 0) {
+ f->flush(out);
+ }
string s(out.c_str(), out.length());
EXPECT_EQ(-EINVAL, r);
EXPECT_EQ("", s);
bufferlist out;
cmdmap_t bad_cmdmap;
bad_cmdmap["var"] = string("doesnotexist123");
- int r = cct->do_command("config help", bad_cmdmap, "xml", ss, &out);
+ std::unique_ptr<Formatter> f(Formatter::create("xml", "xml"));
+ int r = cct->do_command("config help", bad_cmdmap, f.get(), ss, &out);
+ if (r >= 0) {
+ f->flush(out);
+ }
string s(out.c_str(), out.length());
EXPECT_EQ(-ENOENT, r);
EXPECT_EQ("", s);
{
stringstream ss;
bufferlist out;
- cct->do_command("config get", cmdmap, "UNSUPPORTED", ss, &out);
- string s(out.c_str(), out.length());
- EXPECT_EQ("{\n \"key\": \"value\"\n}\n", s);
- }
-
- {
- stringstream ss;
- bufferlist out;
- cct->do_command("config diff get", cmdmap, "xml", ss, &out);
+ std::unique_ptr<Formatter> f(Formatter::create("xml", "xml"));
+ cct->do_command("config diff get", cmdmap, f.get(), ss, &out);
+ f->flush(out);
string s(out.c_str(), out.length());
EXPECT_EQ("<config_diff_get><diff><key><default></default><override>" + value + "</override><final>value</final></key><rbd_default_features><default>61</default><final>61</final></rbd_default_features></diff></config_diff_get>", s);
}
MOCK_METHOD2(stop, void(Context *, bool));
MOCK_METHOD0(restart, void());
MOCK_METHOD0(flush, void());
- MOCK_METHOD2(print_status, void(Formatter *, stringstream *));
+ MOCK_METHOD1(print_status, void(Formatter *));
MOCK_METHOD2(add_peer, void(const std::string &, librados::IoCtx &));
MOCK_METHOD0(get_global_image_id, const std::string &());
MOCK_METHOD0(get_local_image_id, const std::string &());
#include "tools/rbd_mirror/PoolReplayer.h"
#include "tools/rbd_mirror/ServiceDaemon.h"
#include "tools/rbd_mirror/Threads.h"
+#include "common/Formatter.h"
namespace librbd {
s_instance = nullptr;
}
- MOCK_METHOD2(print_status, void(Formatter*, std::stringstream*));
+ MOCK_METHOD1(print_status, void(Formatter*));
};
Throttler<librbd::MockTestImageCtx>* Throttler<librbd::MockTestImageCtx>::s_instance = nullptr;
MOCK_METHOD1(handle_instances_added, void(const std::vector<std::string> &));
MOCK_METHOD1(handle_instances_removed, void(const std::vector<std::string> &));
- MOCK_METHOD2(print_status, void(Formatter*, std::stringstream*));
+ MOCK_METHOD1(print_status, void(Formatter*));
MOCK_METHOD0(start, void());
MOCK_METHOD0(stop, void());
MOCK_METHOD0(restart, void());
class ImageDeleterAdminSocketCommand {
public:
virtual ~ImageDeleterAdminSocketCommand() {}
- virtual bool call(Formatter *f, stringstream *ss) = 0;
+ virtual int call(Formatter *f) = 0;
};
template <typename I>
public:
explicit StatusCommand(ImageDeleter<I> *image_del) : image_del(image_del) {}
- bool call(Formatter *f, stringstream *ss) override {
- image_del->print_status(f, ss);
- return true;
+ int call(Formatter *f) override {
+ image_del->print_status(f);
+ return 0;
}
private:
}
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override {
Commands::const_iterator i = commands.find(command);
ceph_assert(i != commands.end());
- Formatter *f = Formatter::create(format);
- stringstream dss;
- int r = i->second->call(f, &dss);
- delete f;
- out.append(dss);
- return r;
+ return i->second->call(f);
}
private:
}
template <typename I>
-void ImageDeleter<I>::print_status(Formatter *f, stringstream *ss) {
+void ImageDeleter<I>::print_status(Formatter *f) {
dout(20) << dendl;
- if (f) {
- f->open_object_section("image_deleter_status");
- f->open_array_section("delete_images_queue");
- }
+ f->open_object_section("image_deleter_status");
+ f->open_array_section("delete_images_queue");
std::lock_guard l{m_lock};
for (const auto& image : m_delete_queue) {
- image->print_status(f, ss);
- }
-
- if (f) {
- f->close_section();
- f->open_array_section("failed_deletes_queue");
+ image->print_status(f);
}
+ f->close_section();
+ f->open_array_section("failed_deletes_queue");
for (const auto& image : m_retry_delete_queue) {
- image->print_status(f, ss, true);
+ image->print_status(f, true);
}
- if (f) {
- f->close_section();
- f->close_section();
- f->flush(*ss);
- }
+ f->close_section();
+ f->close_section();
}
template <typename I>
}
template <typename I>
-void ImageDeleter<I>::DeleteInfo::print_status(Formatter *f, stringstream *ss,
+void ImageDeleter<I>::DeleteInfo::print_status(Formatter *f,
bool print_failure_info) {
- if (f) {
- f->open_object_section("delete_info");
- f->dump_string("image_id", image_id);
- if (print_failure_info) {
- f->dump_string("error_code", cpp_strerror(error_code));
- f->dump_int("retries", retries);
- }
- f->close_section();
- f->flush(*ss);
- } else {
- *ss << *this;
+ f->open_object_section("delete_info");
+ f->dump_string("image_id", image_id);
+ if (print_failure_info) {
+ f->dump_string("error_code", cpp_strerror(error_code));
+ f->dump_int("retries", retries);
}
+ f->close_section();
}
} // namespace mirror
void init(Context* on_finish);
void shut_down(Context* on_finish);
- void print_status(Formatter *f, std::stringstream *ss);
+ void print_status(Formatter *f);
// for testing purposes
void wait_for_deletion(const std::string &image_id,
return os;
}
- void print_status(Formatter *f, std::stringstream *ss,
+ void print_status(Formatter *f,
bool print_failure_info=false);
};
typedef std::shared_ptr<DeleteInfo> DeleteInfoRef;
: desc(desc), replayer(replayer) {
}
virtual ~ImageReplayerAdminSocketCommand() {}
- virtual bool call(Formatter *f, stringstream *ss) = 0;
+ virtual int call(Formatter *f) = 0;
std::string desc;
ImageReplayer<I> *replayer;
: ImageReplayerAdminSocketCommand<I>(desc, replayer) {
}
- bool call(Formatter *f, stringstream *ss) override {
- this->replayer->print_status(f, ss);
- return true;
+ int call(Formatter *f) override {
+ this->replayer->print_status(f);
+ return 0;
}
};
: ImageReplayerAdminSocketCommand<I>(desc, replayer) {
}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
this->replayer->start(nullptr, true);
- return true;
+ return 0;
}
};
: ImageReplayerAdminSocketCommand<I>(desc, replayer) {
}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
this->replayer->stop(nullptr, true);
- return true;
+ return 0;
}
};
: ImageReplayerAdminSocketCommand<I>(desc, replayer) {
}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
this->replayer->restart();
- return true;
+ return 0;
}
};
: ImageReplayerAdminSocketCommand<I>(desc, replayer) {
}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
this->replayer->flush();
- return true;
+ return 0;
}
};
}
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override {
auto i = commands.find(command);
ceph_assert(i != commands.end());
- Formatter *f = Formatter::create(format);
- stringstream dss;
- int r = i->second->call(f, &dss);
- delete f;
- out.append(dss);
- return r;
+ return i->second->call(f);
}
private:
}
template <typename I>
-void ImageReplayer<I>::print_status(Formatter *f, stringstream *ss)
+void ImageReplayer<I>::print_status(Formatter *f)
{
dout(10) << dendl;
std::lock_guard l{m_lock};
- if (f) {
- f->open_object_section("image_replayer");
- f->dump_string("name", m_name);
- f->dump_string("state", to_string(m_state));
- f->close_section();
- f->flush(*ss);
- } else {
- *ss << m_name << ": state: " << to_string(m_state);
- }
+ f->open_object_section("image_replayer");
+ f->dump_string("name", m_name);
+ f->dump_string("state", to_string(m_state));
+ f->close_section();
}
template <typename I>
void resync_image(Context *on_finish=nullptr);
- void print_status(Formatter *f, stringstream *ss);
+ void print_status(Formatter *f);
virtual void handle_replay_ready();
virtual void handle_replay_complete(int r, const std::string &error_desc);
}
template <typename I>
-void InstanceReplayer<I>::print_status(Formatter *f, stringstream *ss) {
+void InstanceReplayer<I>::print_status(Formatter *f) {
dout(10) << dendl;
- if (!f) {
- return;
- }
-
std::lock_guard locker{m_lock};
f->open_array_section("image_replayers");
for (auto &kv : m_image_replayers) {
auto &image_replayer = kv.second;
- image_replayer->print_status(f, ss);
+ image_replayer->print_status(f);
}
f->close_section();
}
void release_all(Context *on_finish);
- void print_status(Formatter *f, stringstream *ss);
+ void print_status(Formatter *f);
void start();
void stop();
void restart();
class MirrorAdminSocketCommand {
public:
virtual ~MirrorAdminSocketCommand() {}
- virtual bool call(Formatter *f, stringstream *ss) = 0;
+ virtual int call(Formatter *f) = 0;
};
class StatusCommand : public MirrorAdminSocketCommand {
public:
explicit StatusCommand(Mirror *mirror) : mirror(mirror) {}
- bool call(Formatter *f, stringstream *ss) override {
- mirror->print_status(f, ss);
- return true;
+ int call(Formatter *f) override {
+ mirror->print_status(f);
+ return 0;
}
private:
public:
explicit StartCommand(Mirror *mirror) : mirror(mirror) {}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
mirror->start();
- return true;
+ return 0;
}
private:
public:
explicit StopCommand(Mirror *mirror) : mirror(mirror) {}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
mirror->stop();
- return true;
+ return 0;
}
private:
public:
explicit RestartCommand(Mirror *mirror) : mirror(mirror) {}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
mirror->restart();
- return true;
+ return 0;
}
private:
public:
explicit FlushCommand(Mirror *mirror) : mirror(mirror) {}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
mirror->flush();
- return true;
+ return 0;
}
private:
public:
explicit LeaderReleaseCommand(Mirror *mirror) : mirror(mirror) {}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
mirror->release_leader();
- return true;
+ return 0;
}
private:
}
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& errss,
bufferlist& out) override {
Commands::const_iterator i = commands.find(command);
ceph_assert(i != commands.end());
- Formatter *f = Formatter::create(format);
- stringstream dss;
- int r = i->second->call(f, &dss);
- delete f;
- out.append(dss);
- return r;
+ return i->second->call(f);
}
private:
dout(20) << "return" << dendl;
}
-void Mirror::print_status(Formatter *f, stringstream *ss)
+void Mirror::print_status(Formatter *f)
{
dout(20) << "enter" << dendl;
return;
}
- if (f) {
- f->open_object_section("mirror_status");
- f->open_array_section("pool_replayers");
- };
-
+ f->open_object_section("mirror_status");
+ f->open_array_section("pool_replayers");
for (auto &pool_replayer : m_pool_replayers) {
- pool_replayer.second->print_status(f, ss);
- }
-
- if (f) {
- f->close_section();
+ pool_replayer.second->print_status(f);
}
+ f->close_section();
+ f->close_section();
}
void Mirror::start()
void run();
void handle_signal(int signum);
- void print_status(Formatter *f, stringstream *ss);
+ void print_status(Formatter *f);
void start();
void stop();
void restart();
}
template <typename I>
-void NamespaceReplayer<I>::print_status(Formatter *f, stringstream *ss)
+void NamespaceReplayer<I>::print_status(Formatter *f)
{
dout(20) << dendl;
std::lock_guard locker{m_lock};
- m_instance_replayer->print_status(f, ss);
+ m_instance_replayer->print_status(f);
if (m_image_deleter) {
f->open_object_section("image_deleter");
- m_image_deleter->print_status(f, ss);
+ m_image_deleter->print_status(f);
f->close_section();
}
}
void handle_instances_added(const std::vector<std::string> &instance_ids);
void handle_instances_removed(const std::vector<std::string> &instance_ids);
- void print_status(Formatter *f, stringstream *ss);
+ void print_status(Formatter *f);
void start();
void stop();
void restart();
: pool_replayer(pool_replayer) {
}
virtual ~PoolReplayerAdminSocketCommand() {}
- virtual bool call(Formatter *f, stringstream *ss) = 0;
+ virtual int call(Formatter *f) = 0;
protected:
PoolReplayer<I> *pool_replayer;
};
: PoolReplayerAdminSocketCommand<I>(pool_replayer) {
}
- bool call(Formatter *f, stringstream *ss) override {
- this->pool_replayer->print_status(f, ss);
- return true;
+ int call(Formatter *f) override {
+ this->pool_replayer->print_status(f);
+ return 0;
}
};
: PoolReplayerAdminSocketCommand<I>(pool_replayer) {
}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
this->pool_replayer->start();
- return true;
+ return 0;
}
};
: PoolReplayerAdminSocketCommand<I>(pool_replayer) {
}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
this->pool_replayer->stop(true);
- return true;
+ return 0;
}
};
: PoolReplayerAdminSocketCommand<I>(pool_replayer) {
}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
this->pool_replayer->restart();
- return true;
+ return 0;
}
};
: PoolReplayerAdminSocketCommand<I>(pool_replayer) {
}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
this->pool_replayer->flush();
- return true;
+ return 0;
}
};
: PoolReplayerAdminSocketCommand<I>(pool_replayer) {
}
- bool call(Formatter *f, stringstream *ss) override {
+ int call(Formatter *f) override {
this->pool_replayer->release_leader();
- return true;
+ return 0;
}
};
}
int call(std::string_view command, const cmdmap_t& cmdmap,
- std::string_view format,
+ Formatter *f,
std::ostream& ss,
bufferlist& out) override {
auto i = commands.find(command);
ceph_assert(i != commands.end());
- Formatter *f = Formatter::create(format);
- stringstream dss;
- int r = i->second->call(f, &dss);
- delete f;
- out.append(dss);
- return r;
+ return i->second->call(f);
}
private:
}
template <typename I>
-void PoolReplayer<I>::print_status(Formatter *f, stringstream *ss) {
+void PoolReplayer<I>::print_status(Formatter *f) {
dout(20) << dendl;
- if (!f) {
- return;
- }
+ assert(f);
std::lock_guard l{m_lock};
if (m_image_sync_throttler) {
f->open_object_section("sync_throttler");
- m_image_sync_throttler->print_status(f, ss);
+ m_image_sync_throttler->print_status(f);
f->close_section(); // sync_throttler
}
if (m_image_deletion_throttler) {
f->open_object_section("deletion_throttler");
- m_image_deletion_throttler->print_status(f, ss);
+ m_image_deletion_throttler->print_status(f);
f->close_section(); // deletion_throttler
}
- m_default_namespace_replayer->print_status(f, ss);
+ m_default_namespace_replayer->print_status(f);
f->open_array_section("namespaces");
for (auto &it : m_namespace_replayers) {
f->open_object_section("namespace");
f->dump_string("name", it.first);
- it.second->print_status(f, ss);
+ it.second->print_status(f);
f->close_section(); // namespace
}
f->close_section(); // namespaces
f->close_section(); // pool_replayer_status
- f->flush(*ss);
}
template <typename I>
void run();
- void print_status(Formatter *f, stringstream *ss);
+ void print_status(Formatter *f);
void start();
void stop(bool manual);
void restart();
}
template <typename I>
-void Throttler<I>::print_status(ceph::Formatter *f, std::stringstream *ss) {
+void Throttler<I>::print_status(ceph::Formatter *f) {
dout(20) << dendl;
std::lock_guard locker{m_lock};
- if (f) {
- f->dump_int("max_parallel_requests", m_max_concurrent_ops);
- f->dump_int("running_requests", m_inflight_ops.size());
- f->dump_int("waiting_requests", m_queue.size());
- f->flush(*ss);
- } else {
- *ss << "[ ";
- *ss << "max_parallel_requests=" << m_max_concurrent_ops << ", ";
- *ss << "running_requests=" << m_inflight_ops.size() << ", ";
- *ss << "waiting_requests=" << m_queue.size() << " ]";
- }
+ f->dump_int("max_parallel_requests", m_max_concurrent_ops);
+ f->dump_int("running_requests", m_inflight_ops.size());
+ f->dump_int("waiting_requests", m_queue.size());
}
template <typename I>
void finish_op(const std::string &ns, const std::string &id);
void drain(const std::string &ns, int r);
- void print_status(ceph::Formatter *f, std::stringstream *ss);
+ void print_status(ceph::Formatter *f);
private:
typedef std::pair<std::string, std::string> Id;