From 1277a465b1b6c024e1a20ba6f948233c5995eac8 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 29 May 2012 10:09:31 -0700 Subject: [PATCH] cephcontext: generalize admin socket hook We'll process non-perfcounter commands too. Signed-off-by: Sage Weil --- src/common/ceph_context.cc | 42 +++++++++++++++++++++----------------- src/common/ceph_context.h | 13 ++++++++++-- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index 68f1a8c3976f6..1f64372bef895 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -146,27 +146,31 @@ public: // perfcounter hooks -class PerfCountersHook : public AdminSocketHook { - PerfCountersCollection *m_coll; +class CephContextHook : public AdminSocketHook { + CephContext *m_cct; public: - PerfCountersHook(PerfCountersCollection *c) : m_coll(c) {} + CephContextHook(CephContext *cct) : m_cct(cct) {} bool call(std::string command, bufferlist& out) { - std::vector v; - if (command == "perfcounters_dump" || - command == "1") - m_coll->write_json_to_buf(v, false); - else if (command == "perfcounters_schema" || - command == "2") - m_coll->write_json_to_buf(v, true); - else - assert(0 == "registered under wrong command?"); - out.append(&v[0], v.size()); + m_cct->do_command(command, &out); return true; } }; +void CephContext::do_command(std::string command, bufferlist *out) +{ + std::vector v; + + if (command == "perfcounters_dump" || command == "1") + _perf_counters_collection->write_json_to_buf(v, false); + else if (command == "perfcounters_schema" || command == "2") + _perf_counters_collection->write_json_to_buf(v, true); + else + assert(0 == "registered under wrong command?"); + out->append(&v[0], v.size()); +}; + CephContext::CephContext(uint32_t module_type_) : _conf(new md_config_t()), @@ -192,11 +196,11 @@ CephContext::CephContext(uint32_t module_type_) _conf->add_observer(_admin_socket); _heartbeat_map = new HeartbeatMap(this); - _perf_counters_hook = new PerfCountersHook(_perf_counters_collection); - _admin_socket->register_command("perfcounters_dump", _perf_counters_hook, "dump perfcounters value"); - _admin_socket->register_command("1", _perf_counters_hook, ""); - _admin_socket->register_command("perfcounters_schema", _perf_counters_hook, "dump perfcounters schema"); - _admin_socket->register_command("2", _perf_counters_hook, ""); + _admin_hook = new CephContextHook(this); + _admin_socket->register_command("perfcounters_dump", _admin_hook, "dump perfcounters value"); + _admin_socket->register_command("1", _admin_hook, ""); + _admin_socket->register_command("perfcounters_schema", _admin_hook, "dump perfcounters schema"); + _admin_socket->register_command("2", _admin_hook, ""); } CephContext::~CephContext() @@ -207,7 +211,7 @@ CephContext::~CephContext() _admin_socket->unregister_command("1"); _admin_socket->unregister_command("perfcounters_schema"); _admin_socket->unregister_command("2"); - delete _perf_counters_hook; + delete _admin_hook; delete _heartbeat_map; diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h index 38100ab736297..fb5dc5bccdca2 100644 --- a/src/common/ceph_context.h +++ b/src/common/ceph_context.h @@ -18,12 +18,14 @@ #include #include +#include "include/buffer.h" + class AdminSocket; class CephContextServiceThread; class PerfCountersCollection; class md_config_obs_t; class md_config_t; -class PerfCountersHook; +class CephContextHook; namespace ceph { class HeartbeatMap; @@ -32,6 +34,8 @@ namespace ceph { } } +using ceph::bufferlist; + /* A CephContext represents the context held by a single library user. * There can be multiple CephContexts in the same process. * @@ -73,6 +77,11 @@ public: */ AdminSocket *get_admin_socket(); + /** + * process an admin socket command + */ + void do_command(std::string command, bufferlist *out); + private: CephContext(const CephContext &rhs); CephContext &operator=(const CephContext &rhs); @@ -100,7 +109,7 @@ private: md_config_obs_t *_perf_counters_conf_obs; - PerfCountersHook *_perf_counters_hook; + CephContextHook *_admin_hook; ceph::HeartbeatMap *_heartbeat_map; }; -- 2.39.5