]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
MDS: add stubs for an AdminSocketHook
authorGreg Farnum <greg@inktank.com>
Thu, 8 May 2014 19:13:58 +0000 (12:13 -0700)
committerGreg Farnum <greg@inktank.com>
Mon, 12 May 2014 21:39:57 +0000 (14:39 -0700)
Signed-off-by: Greg Farnum <greg@inktank.com>
src/mds/MDS.cc
src/mds/MDS.h

index 1d9015a22eb613635030771d552a43c5701419a3..7fd1bf29c53ea0ddbd9f454e0d9c2e3ff19f08f6 100644 (file)
@@ -105,7 +105,7 @@ MDS::MDS(const std::string &n, Messenger *m, MonClient *mc) :
   messenger(m),
   monc(mc),
   clog(m->cct, messenger, &mc->monmap, LogClient::NO_FLAGS),
-  sessionmap(this) {
+  sessionmap(this), asok_hook(NULL) {
 
   orig_argc = 0;
   orig_argv = NULL;
@@ -195,6 +195,47 @@ MDS::~MDS() {
     delete messenger;
 }
 
+class MDSSocketHook : public AdminSocketHook {
+  MDS *mds;
+public:
+  MDSSocketHook(MDS *m) : mds(m) {}
+  bool call(std::string command, cmdmap_t& cmdmap, std::string format,
+           bufferlist& out) {
+    stringstream ss;
+    bool r = mds->asok_command(command, cmdmap, format, ss);
+    out.append(ss);
+    return r;
+  }
+};
+
+bool MDS::asok_command(string command, cmdmap_t& cmdmap, string format,
+                   ostream& ss)
+{
+  Formatter *f = new_formatter(format);
+  if (!f)
+    f = new_formatter("json-pretty");
+  if (command == "status") {
+    f->open_object_section("status");
+    f->dump_stream("cluster_fsid") << monc->get_fsid();
+    f->dump_unsigned("whoami", whoami);
+    f->dump_string("state", ceph_mds_state_name(get_state()));
+    f->dump_unsigned("mdsmap_epoch", mdsmap->get_epoch());
+    f->close_section(); // status
+  }
+  f->flush(ss);
+  delete f;
+  return true;
+}
+
+void MDS::set_up_admin_socket()
+{
+  int r;
+  AdminSocket *admin_socket = g_ceph_context->get_admin_socket();
+  asok_hook = new MDSSocketHook(this);
+  r = admin_socket->register_command("status", "status", asok_hook, "high-level status of MDS");
+  assert(0 == r);
+}
+
 void MDS::create_logger()
 {
   dout(10) << "create_logger" << dendl;
@@ -550,6 +591,7 @@ int MDS::init(int wanted_state)
   reset_tick();
 
   create_logger();
+  set_up_admin_socket();
 
   mds_lock.Unlock();
 
index 1cd6096b46d13af367328ec65f0d4900bc4905b6..2649f449d09fded1bc7678ebf7a3c5ab134c8853 100644 (file)
@@ -362,6 +362,11 @@ class MDS : public Dispatcher {
   // start up, shutdown
   int init(int wanted_state=MDSMap::STATE_BOOT);
 
+  friend class MDSSocketHook;
+  class MDSSocketHook *asok_hook;
+  bool asok_command(string command, cmdmap_t& cmdmap, string format,
+                   ostream& ss);
+  void set_up_admin_socket();
   void create_logger();
 
   void bcast_mds_map();  // to mounted clients