]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: move supported_commands fields, methods into Monitor, and fix leak 954/head
authorSage Weil <sage@inktank.com>
Tue, 17 Dec 2013 00:09:44 +0000 (16:09 -0800)
committerSage Weil <sage@inktank.com>
Tue, 17 Dec 2013 00:09:44 +0000 (16:09 -0800)
We were leaking the static leader_supported_mon_commands.  Move this into
the class so that we can clean up in the destructor.

Rename get_command_descriptions -> format_command_descriptions.

Fixes: #7009
Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/Elector.cc
src/mon/Monitor.cc
src/mon/Monitor.h
src/test/common/get_command_descriptions.cc

index f31ef54c499b32ee03bf77d93a86b7167ffb75ee..44c9485730ec81de903922bf2b9872bbbaeae47d 100644 (file)
@@ -180,10 +180,10 @@ void Elector::victory()
   const MonCommand *cmds;
   int cmdsize;
   if (use_classic_commands) {
-    get_classic_monitor_commands(&cmds, &cmdsize);
+    mon->get_classic_monitor_commands(&cmds, &cmdsize);
     cmds_bl = &mon->get_classic_commands_bl();
   } else {
-    get_locally_supported_monitor_commands(&cmds, &cmdsize);
+    mon->get_locally_supported_monitor_commands(&cmds, &cmdsize);
     cmds_bl = &mon->get_supported_commands_bl();
   }
   
@@ -324,12 +324,12 @@ void Elector::handle_victory(MMonElection *m)
     int cmdsize;
     bufferlist::iterator bi = m->commands.begin();
     MonCommand::decode_array(&new_cmds, &cmdsize, bi);
-    set_leader_supported_commands(new_cmds, cmdsize);
+    mon->set_leader_supported_commands(new_cmds, cmdsize);
   } else { // they are a legacy monitor; use known legacy command set
     const MonCommand *new_cmds;
     int cmdsize;
-    get_classic_monitor_commands(&new_cmds, &cmdsize);
-    set_leader_supported_commands(new_cmds, cmdsize);
+    mon->get_classic_monitor_commands(&new_cmds, &cmdsize);
+    mon->set_leader_supported_commands(new_cmds, cmdsize);
   }
 
   m->put();
index 4ac90a629b196619de9b4ee438ed147124854963..c0d7b6f349d856f89c00c306319e2fdf0b445261 100644 (file)
@@ -94,6 +94,18 @@ static ostream& _prefix(std::ostream *_dout, const Monitor *mon) {
 const string Monitor::MONITOR_NAME = "monitor";
 const string Monitor::MONITOR_STORE_PREFIX = "monitor_store";
 
+
+#undef COMMAND
+MonCommand mon_commands[] = {
+#define COMMAND(parsesig, helptext, modulename, req_perms, avail) \
+  {parsesig, helptext, modulename, req_perms, avail},
+#include <mon/MonCommands.h>
+};
+MonCommand classic_mon_commands[] = {
+#include <mon/DumplingMonCommands.h>
+};
+
+
 long parse_pos_long(const char *s, ostream *pss)
 {
   if (*s == '-' || *s == '+') {
@@ -137,6 +149,8 @@ Monitor::Monitor(CephContext* cct_, string nm, MonitorDBStore *s,
   auth_service_required(cct,
                        cct->_conf->auth_supported.length() ?
                        cct->_conf->auth_supported : cct->_conf->auth_service_required),
+  leader_supported_mon_commands(NULL),
+  leader_supported_mon_commands_size(0),
   store(s),
   
   state(STATE_PROBING),
@@ -213,6 +227,9 @@ Monitor::~Monitor()
   delete paxos;
   assert(session_map.sessions.empty());
   delete mon_caps;
+  if (leader_supported_mon_commands != mon_commands &&
+      leader_supported_mon_commands != classic_mon_commands)
+    delete[] leader_supported_mon_commands;
 }
 
 
@@ -1892,18 +1909,6 @@ void Monitor::get_status(stringstream &ss, Formatter *f)
   }
 }
 
-#undef COMMAND
-MonCommand mon_commands[] = {
-#define COMMAND(parsesig, helptext, modulename, req_perms, avail) \
-  {parsesig, helptext, modulename, req_perms, avail},
-#include <mon/MonCommands.h>
-};
-MonCommand classic_mon_commands[] = {
-#include <mon/DumplingMonCommands.h>
-};
-const MonCommand *leader_supported_mon_commands = NULL;
-int leader_supported_mon_commands_size = 0;
-
 void Monitor::_generate_command_map(map<string,cmd_vartype>& cmdmap,
                                     map<string,string> &param_str_map)
 {
@@ -1957,10 +1962,11 @@ bool Monitor::_allowed_command(MonSession *s, string &module, string &prefix,
   return capable;
 }
 
-void get_command_descriptions(const MonCommand *commands,
-                             unsigned commands_size,
-                             Formatter *f,
-                             bufferlist *rdata) {
+void Monitor::format_command_descriptions(const MonCommand *commands,
+                                         unsigned commands_size,
+                                         Formatter *f,
+                                         bufferlist *rdata)
+{
   int cmdnum = 0;
   f->open_object_section("command_descriptions");
   for (const MonCommand *cp = commands;
@@ -1978,22 +1984,23 @@ void get_command_descriptions(const MonCommand *commands,
   f->flush(*rdata);
 }
 
-void get_locally_supported_monitor_commands(const MonCommand **cmds, int *count)
+void Monitor::get_locally_supported_monitor_commands(const MonCommand **cmds,
+                                                    int *count)
 {
   *cmds = mon_commands;
   *count = ARRAY_SIZE(mon_commands);
 }
-void get_leader_supported_commands(const MonCommand **cmds, int *count)
+void Monitor::get_leader_supported_commands(const MonCommand **cmds, int *count)
 {
   *cmds = leader_supported_mon_commands;
   *count = leader_supported_mon_commands_size;
 }
-void get_classic_monitor_commands(const MonCommand **cmds, int *count)
+void Monitor::get_classic_monitor_commands(const MonCommand **cmds, int *count)
 {
   *cmds = classic_mon_commands;
   *count = ARRAY_SIZE(classic_mon_commands);
 }
-void set_leader_supported_commands(const MonCommand *cmds, int size)
+void Monitor::set_leader_supported_commands(const MonCommand *cmds, int size)
 {
   if (leader_supported_mon_commands != mon_commands &&
       leader_supported_mon_commands != classic_mon_commands)
@@ -2047,8 +2054,8 @@ void Monitor::handle_command(MMonCommand *m)
   if (prefix == "get_command_descriptions") {
     bufferlist rdata;
     Formatter *f = new_formatter("json");
-    get_command_descriptions(leader_supported_mon_commands,
-                             leader_supported_mon_commands_size, f, &rdata);
+    format_command_descriptions(leader_supported_mon_commands,
+                               leader_supported_mon_commands_size, f, &rdata);
     delete f;
     reply_command(m, 0, "", rdata, 0);
     return;
index 4f142b37525c52f5cb934303ba20a55f00117c1d..eb6776bd7578798f93df75c54685bf485749f0ed 100644 (file)
@@ -140,6 +140,9 @@ public:
 
   CompatSet features;
 
+  const MonCommand *leader_supported_mon_commands;
+  int leader_supported_mon_commands_size;
+
 private:
   void new_tick();
   friend class C_Mon_Tick;
@@ -866,6 +869,16 @@ public:
     void _convert_machines();
     void _convert_paxos();
   };
+
+  static void format_command_descriptions(const MonCommand *commands,
+                                         unsigned commands_size,
+                                         Formatter *f,
+                                         bufferlist *rdata);
+  void get_locally_supported_monitor_commands(const MonCommand **cmds, int *count);
+  void get_classic_monitor_commands(const MonCommand **cmds, int *count);
+  void get_leader_supported_commands(const MonCommand **cmds, int *count);
+  /// the Monitor owns this pointer once you pass it in
+  void set_leader_supported_commands(const MonCommand *cmds, int size);
 };
 
 #define CEPH_MON_FEATURE_INCOMPAT_BASE CompatSet::Feature (1, "initial feature set (~v.18)")
@@ -929,15 +942,4 @@ struct MonCommand {
 };
 WRITE_CLASS_ENCODER(MonCommand);
 
-void get_command_descriptions(const MonCommand *commands,
-                             unsigned commands_size,
-                             Formatter *f,
-                             bufferlist *rdata);
-void get_locally_supported_monitor_commands(const MonCommand **cmds, int *count);
-void get_classic_monitor_commands(const MonCommand **cmds, int *count);
-void get_leader_supported_commands(const MonCommand **cmds, int *count);
-/// the Monitor owns this pointer once you pass it in
-void set_leader_supported_commands(const MonCommand *cmds, int size);
-
-
 #endif
index 9f20102f705e54eb19df1b4de563f7d29fff8643..c35e47ba6bdb7788b8abf4672932fd430fa0a89a 100644 (file)
@@ -45,7 +45,7 @@ static void json_print(const MonCommand *mon_commands, int size)
 {
   bufferlist rdata;
   Formatter *f = new_formatter("json");
-  get_command_descriptions(mon_commands, size, f, &rdata);
+  Monitor::format_command_descriptions(mon_commands, size, f, &rdata);
   delete f;
   string data(rdata.c_str(), rdata.length());
   cout << data << std::endl;