]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephcontext: generalize admin socket hook
authorSage Weil <sage@inktank.com>
Tue, 29 May 2012 17:09:31 +0000 (10:09 -0700)
committerSage Weil <sage@inktank.com>
Tue, 29 May 2012 17:09:31 +0000 (10:09 -0700)
We'll process non-perfcounter commands too.

Signed-off-by: Sage Weil <sage@inktank.com>
src/common/ceph_context.cc
src/common/ceph_context.h

index 68f1a8c3976f690fe14bf9df5fb657c5c1d2157c..1f64372bef895680dba09cf3b8422ec2eb3b085e 100644 (file)
@@ -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<char> 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<char> 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;
 
index 38100ab736297d1c3426fe07700d68e2a350cfc4..fb5dc5bccdca252e20cdad1cc7fef7c369bf46ed 100644 (file)
 #include <iostream>
 #include <stdint.h>
 
+#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;
 };