]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mempool: attach mempool asok commands to all ccts
authorSage Weil <sage@redhat.com>
Tue, 8 Nov 2016 22:29:03 +0000 (17:29 -0500)
committerSage Weil <sage@redhat.com>
Fri, 11 Nov 2016 19:59:53 +0000 (14:59 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/ceph_context.cc
src/global/global_init.cc

index a9208cf6c2a01510cf847037cf18e515d35744a5..75946839169aa5d5a0962916a6ff867c27e17692 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <boost/algorithm/string.hpp>
 
+#include "include/mempool.h"
 #include "common/admin_socket.h"
 #include "common/perf_counters.h"
 #include "common/Thread.h"
@@ -75,6 +76,55 @@ private:
   bool m_registered;
 };
 
+class MempoolObs : public md_config_obs_t,
+                 public AdminSocketHook {
+  CephContext *cct;
+
+public:
+  explicit MempoolObs(CephContext *cct) : cct(cct) {
+    cct->_conf->add_observer(this);
+    int r = cct->get_admin_socket()->register_command(
+      "dump_mempools",
+      "dump_mempools",
+      this,
+      "get mempool stats");
+    assert(r == 0);
+  }
+  ~MempoolObs() {
+    cct->_conf->remove_observer(this);
+    cct->get_admin_socket()->unregister_command("dump_mempools");
+  }
+
+  // md_config_obs_t
+  const char** get_tracked_conf_keys() const {
+    static const char *KEYS[] = {
+      "mempool_debug",
+      NULL
+    };
+    return KEYS;
+  }
+
+  void handle_conf_change(const md_config_t *conf,
+                          const std::set <std::string> &changed) {
+    if (changed.count("mempool_debug")) {
+      mempool::set_debug_mode(cct->_conf->mempool_debug);
+    }
+  }
+
+  // AdminSocketHook
+  bool call(std::string command, cmdmap_t& cmdmap, std::string format,
+           bufferlist& out) {
+    if (command == "dump_mempools") {
+      std::unique_ptr<Formatter> f(Formatter::create(format));
+      f->open_object_section("mempools");
+      mempool::dump(f.get());
+      f->close_section();
+      f->flush(out);
+      return true;
+    }
+    return false;
+  }
+};
 
 } // anonymous namespace
 
@@ -515,6 +565,9 @@ CephContext::CephContext(uint32_t module_type_, int init_flags_)
 
   _crypto_none = CryptoHandler::create(CEPH_CRYPTO_NONE);
   _crypto_aes = CryptoHandler::create(CEPH_CRYPTO_AES);
+
+  MempoolObs *mempool_obs = 0;
+  lookup_or_create_singleton_object(mempool_obs, "mempool_obs");
 }
 
 CephContext::~CephContext()
index e16c776dfc19c39c1c6b901d3b8070ddf7b27cb6..c2b64ad52223bf5df414a17ad3dab04ce48c3af9 100644 (file)
@@ -12,7 +12,6 @@
  *
  */
 
-#include "include/mempool.h"
 #include "common/ceph_argparse.h"
 #include "common/code_environment.h"
 #include "common/config.h"
 
 #define dout_subsys ceph_subsys_
 
-class GlobalObs : public md_config_obs_t,
-                 public AdminSocketHook {
-  CephContext *cct;
-
-public:
-  explicit GlobalObs(CephContext *cct) : cct(cct) {
-    cct->_conf->add_observer(this);
-    int r = cct->get_admin_socket()->register_command(
-      "dump_mempools",
-      "dump_mempools",
-      this,
-      "get mempool stats");
-    assert(r == 0);
-  }
-  ~GlobalObs() {
-    cct->_conf->remove_observer(this);
-    cct->get_admin_socket()->unregister_command("dump_mempools");
-  }
-
-  // md_config_obs_t
-  const char** get_tracked_conf_keys() const {
-    static const char *KEYS[] = {
-      "mempool_debug",
-      NULL
-    };
-    return KEYS;
-  }
-
-  void handle_conf_change(const md_config_t *conf,
-                          const std::set <std::string> &changed) {
-    if (changed.count("mempool_debug")) {
-      mempool::set_debug_mode(cct->_conf->mempool_debug);
-    }
-  }
-
-  // AdminSocketHook
-  bool call(std::string command, cmdmap_t& cmdmap, std::string format,
-           bufferlist& out) {
-    if (command == "dump_mempools") {
-      std::unique_ptr<Formatter> f(Formatter::create(format));
-      f->open_object_section("mempools");
-      mempool::dump(f.get());
-      f->close_section();
-      f->flush(out);
-      return true;
-    }
-    return false;
-  }
-};
-
 static void global_init_set_globals(CephContext *cct)
 {
   g_ceph_context = cct;
@@ -149,10 +98,6 @@ void global_pre_init(std::vector < const char * > *alt_def_args,
   if (alt_def_args)
     conf->parse_argv(*alt_def_args);  // alternative default args
 
-  // set up global config observer
-  GlobalObs *obs = 0;
-  g_ceph_context->lookup_or_create_singleton_object(obs, "global_obs");
-
   int ret = conf->parse_config_files(c_str_or_null(conf_file_list),
                                     &cerr, flags);
   if (ret == -EDOM) {