]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: client mon stat, dump commands; add to cmonctl -w
authorSage Weil <sage@newdream.net>
Thu, 13 Nov 2008 18:48:25 +0000 (10:48 -0800)
committerSage Weil <sage@newdream.net>
Thu, 13 Nov 2008 20:45:37 +0000 (12:45 -0800)
src/cmonctl.cc
src/mon/ClientMonitor.cc
src/mon/ClientMonitor.h
src/mon/Monitor.cc

index 6c0635ecc94fa254839c3631dc231201f1697816..990ecfd3c03246748eb07863004ae0274c0a5ca3 100644 (file)
@@ -43,11 +43,11 @@ int watch = 0;
 
 MonMap monmap;
 
-enum { OSD, MON, MDS, LAST };
+enum { OSD, MON, MDS, CLIENT, LAST };
 int which = 0;
 int same = 0;
-const char *prefix[3] = { "mds", "osd", "pg" };
-string status[3];
+const char *prefix[4] = { "mds", "osd", "pg", "client" };
+string status[4];
 
 void get_next_status()
 {
index 615498f693072e2c83e24158d2ba4861767fc5ea..9fd0487433934a2bb83ab1c9279c7fef5ee0fb29 100644 (file)
 #include "messages/MMonMap.h"
 #include "messages/MClientMount.h"
 #include "messages/MClientUnmount.h"
+#include "messages/MMonCommand.h"
 
 #include "common/Timer.h"
 
+#include <sstream>
+
 #include "config.h"
 
 #define DOUT_SUBSYS mon
@@ -154,6 +157,8 @@ bool ClientMonitor::preprocess_query(Message *m)
     }
     return false;
     
+  case MSG_MON_COMMAND:
+    return preprocess_command((MMonCommand*)m);
 
   default:
     assert(0);
@@ -204,6 +209,10 @@ bool ClientMonitor::prepare_update(Message *m)
     }
     return true;
   
+
+  case MSG_MON_COMMAND:
+    return prepare_command((MMonCommand*)m);
+
   default:
     assert(0);
     delete m;
@@ -213,6 +222,68 @@ bool ClientMonitor::prepare_update(Message *m)
 }
 
 
+// COMMAND
+
+bool ClientMonitor::preprocess_command(MMonCommand *m)
+{
+  int r = -1;
+  bufferlist rdata;
+  stringstream ss;
+
+  if (m->cmd.size() > 1) {
+    if (m->cmd[1] == "stat") {
+      ss << *this;
+      r = 0;
+    }
+    else if (m->cmd[1] == "getmap") {
+      client_map.encode(rdata);
+      ss << "got clientmap version " << client_map.version;
+      r = 0;
+    }
+    else if (m->cmd[1] == "dump") {
+      ss << "version " << client_map.version << std::endl;
+      ss << "next_client " << client_map.next_client << std::endl;
+      for (map<uint32_t, entity_addr_t>::iterator p = client_map.client_addr.begin();
+          p != client_map.client_addr.end();
+          p++) {
+       ss << "client" << p->first << "\t" << p->second << std::endl;
+      }
+      while (!ss.eof()) {
+       string s;
+       getline(ss, s);
+       rdata.append(s.c_str(), s.length());
+       rdata.append("\n", 1);
+      }
+      ss << "ok";
+      r = 0;
+    }
+  }
+
+  if (r != -1) {
+    string rs;
+    getline(ss, rs);
+    mon->reply_command(m, r, rs, rdata);
+    return true;
+  } else
+    return false;
+}
+
+
+bool ClientMonitor::prepare_command(MMonCommand *m)
+{
+  stringstream ss;
+  string rs;
+  int err = -EINVAL;
+
+  // nothing here yet
+  ss << "unrecognized command";
+
+  getline(ss, rs);
+  mon->reply_command(m, err, rs);
+  return false;
+}
+
+
 // MOUNT
 
 
index aa3b0ca95772cce52e003ff749c7f1ec74d8595b..722500150bc6e4d5b467600102a9f9ef9c085faf 100644 (file)
@@ -34,6 +34,7 @@ class Monitor;
 class Paxos;
 class MClientMount;
 class MClientUnmount;
+class MMonCommand;
 
 class ClientMonitor : public PaxosService {
 public:
@@ -171,7 +172,9 @@ private:
   bool preprocess_query(Message *m);  // true if processed.
   bool prepare_update(Message *m);
 
-  
+  bool preprocess_command(MMonCommand *m);  // true if processed.
+  bool prepare_command(MMonCommand *m);
+
  public:
   ClientMonitor(Monitor *mn, Paxos *p) : PaxosService(mn, p) { }
   
index 7e6073bf0b1b447160045a5bda5d9ce33ebd2b7a..1e3a2f634a2081f3ebca36a3fad79f97d5d54077 100644 (file)
@@ -236,6 +236,10 @@ void Monitor::handle_command(MMonCommand *m)
       pgmon->dispatch(m);
       return;
     }
+    if (m->cmd[0] == "client") {
+      clientmon->dispatch(m);
+      return;
+    }
     if (m->cmd[0] == "stop") {
       shutdown();
       reply_command(m, 0, "stopping");