]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
global: introduce mempool_debug config option, asok command
authorSage Weil <sage@redhat.com>
Tue, 11 Oct 2016 18:21:56 +0000 (14:21 -0400)
committerSage Weil <sage@redhat.com>
Wed, 2 Nov 2016 17:47:44 +0000 (13:47 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/config_opts.h
src/global/global_init.cc

index 2cf5080d91444d5bf3ea2ccb2fb6a55fb42f23bf..82157561687b64f5ac41efd77107fdf0cf88c46a 100644 (file)
@@ -106,6 +106,8 @@ OPTION(async_compressor_threads, OPT_INT, 2)
 OPTION(async_compressor_thread_timeout, OPT_INT, 5)
 OPTION(async_compressor_thread_suicide_timeout, OPT_INT, 30)
 
+OPTION(mempool_debug, OPT_BOOL, false)
+
 DEFAULT_SUBSYS(0, 5)
 SUBSYS(lockdep, 0, 1)
 SUBSYS(context, 0, 1)
index fcee7d6d2bb8a5d8715afc47a9914c515e504b30..e16c776dfc19c39c1c6b901d3b8070ddf7b27cb6 100644 (file)
@@ -12,6 +12,7 @@
  *
  */
 
+#include "include/mempool.h"
 #include "common/ceph_argparse.h"
 #include "common/code_environment.h"
 #include "common/config.h"
@@ -26,6 +27,7 @@
 #include "global/signal_handler.h"
 #include "include/compat.h"
 #include "include/str_list.h"
+#include "common/admin_socket.h"
 
 #include <pwd.h>
 #include <grp.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;
@@ -97,6 +149,10 @@ 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) {