]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: move init_g_conf into md_config_t ctor
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 1 Feb 2011 17:18:31 +0000 (09:18 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 1 Feb 2011 17:25:02 +0000 (09:25 -0800)
Make sure that g_conf is initialized with default values before anything
else happens.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/common/debug.cc
src/config.cc
src/config.h

index fc58ff218681e526a9de3c7e72ffd497c316ccab..249e55699c2b5c006511749074cb9dca6bdb4e2b 100644 (file)
@@ -19,7 +19,7 @@ bool _dout_need_open = true;
  * By using an early init_priority, we ensure that the dout lock is
  * initialized first and destroyed last.
  */
-Mutex _dout_lock __attribute__((init_priority(101)))
+Mutex _dout_lock __attribute__((init_priority(110)))
     ("_dout_lock", false, false /* no lockdep */);
 
 #define _STR(x) #x
index 50263aca10e90c09447d52a753337a674999b94c..1135f4abebbd464e7fbc9cbf24433c05684fcf16 100644 (file)
  *
  */
 
-
+#include "auth/Auth.h"
+#include "auth/ExportControl.h"
 #include "ceph_ver.h"
-#include "config.h"
-#include "include/types.h"
-
+#include "common/BackTrace.h"
 #include "common/Clock.h"
-#include "common/DoutStreambuf.h"
+#include "common/ConfUtils.h"
 #include "common/Logger.h"
-#include "common/BackTrace.h"
 #include "common/common_init.h"
+#include "common/dyn_snprintf.h"
+#include "config.h"
+#include "include/atomic.h"
+#include "include/str_list.h"
+#include "include/types.h"
+#include "msg/msg_types.h"
+#include "osd/osd_types.h"
 
+#include <fcntl.h>
 #include <fstream>
 #include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
+#include <string.h>
 #include <sys/stat.h>
-#include <fcntl.h>
-#include <signal.h>
-
-#include "include/atomic.h"
-#include "include/str_list.h"
-
-#include "osd/osd_types.h"
+#include <sys/types.h>
 
-#include "common/ConfUtils.h"
-#include "common/dyn_snprintf.h"
+/* Don't use standard Ceph logging in this file.
+ * We can't use logging until it's initialized, and a lot of the necessary
+ * initialization happens here.
+ */
+#undef dout
+#undef pdout
+#undef derr
+#undef generic_dout
+#undef dendl
 
-#include "auth/ExportControl.h"
-#include "auth/Auth.h"
+/* The Ceph configuration. */
+md_config_t g_conf __attribute__((init_priority(103)));
 
+/* These should be moved into md_config_t eventually, grrr */
 static ConfFile *cf = NULL;
 static ExportControl *ec = NULL;
 
-static void fini_g_conf();
-
-static void env_override(char **ceph_var, const char * const env_var)
-{
-  char *e = getenv(env_var);
-  if (!e)
-    return;
-  if (*ceph_var)
-    free(*ceph_var);
-  *ceph_var = strdup(e);
-}
-
-class ConfFileDestructor
-{
-public:
-  ConfFileDestructor() {}
-  ~ConfFileDestructor() {
-    if (cf) {
-      delete cf;
-      cf = NULL;
-      fini_g_conf();
-    }
-  }
-};
-
-static ConfFileDestructor cfd;
-
-
 atomic_t _num_threads(0);
 
 // file layouts
@@ -84,10 +63,15 @@ struct ceph_file_layout g_default_file_layout = {
  fl_object_stripe_unit: init_le32(0),
 };
 
-md_config_t g_conf;
-
-#include <stdlib.h>
-#include <string.h>
+static void env_override(char **ceph_var, const char * const env_var)
+{
+  char *e = getenv(env_var);
+  if (!e)
+    return;
+  if (*ceph_var)
+    free(*ceph_var);
+  *ceph_var = strdup(e);
+}
 
 void env_to_vec(std::vector<const char*>& args)
 {
@@ -676,7 +660,6 @@ static bool conf_reset_val(void *field, opt_type_t type)
   return true;
 }
 
-
 static void set_conf_name(config_option *opt)
 {
   char *newsection = (char *)opt->section;
@@ -712,36 +695,6 @@ static void set_conf_name(config_option *opt)
     opt->conf_name = (const char *)newconf;
 }
 
-static bool init_g_conf()
-{
-  int len = sizeof(config_optionsp)/sizeof(config_option);
-  int i;
-  config_option *opt;
-
-  memset(&g_conf, 0, sizeof(g_conf));
-
-  for (i = 0; i<len; i++) {
-    opt = &config_optionsp[i];
-    if (opt->val_ptr) {
-      conf_reset_val(opt->val_ptr, opt->type);
-    }
-    if (!conf_set_conf_val(opt->val_ptr,
-                          opt->type,
-                          opt->def_str,
-                          opt->def_longlong,
-                          opt->def_double)) {
-      cerr << "error initializing g_conf value num " << i << std::endl;
-      return false;
-    }
-
-    set_conf_name(opt);
-  }
-
-  g_conf.id = strdup("default");
-
-  return true;
-}
-
 static int def_conf_to_str(config_option *opt, char *buf, int len)
 {
   int ret = 0;
@@ -794,23 +747,6 @@ int ceph_def_conf_by_name(const char *name, char *buf, int buflen)
   return ret;
 }
 
-static void fini_g_conf()
-{
-  int len = sizeof(config_optionsp)/sizeof(config_option);
-  int i;
-  config_option *opt;
-
-  for (i = 0; i<len; i++) {
-    opt = &config_optionsp[i];
-    if (opt->type == OPT_STR) {
-      free(*(char **)opt->val_ptr);
-    }
-    free((void *)opt->conf_name);
-  }
-}
-
-static bool g_conf_initialized = init_g_conf();
-
 static bool cmd_is_char(const char *cmd)
 {
        return ((cmd[0] == '-') &&
@@ -1280,3 +1216,58 @@ bool ceph_resolve_file_search(string& filename_list, string& result)
 
   return false;
 }
+
+md_config_t::md_config_t()
+{
+       //
+       // Note: because our md_config_t structure is a global, the memory used to
+       // store it will start out zeroed. So there is no need to manually initialize
+       // everything to 0 here.
+       //
+       // However, it's good practice to add your new config option to config_optionsp
+       // so that its default value is explicit rather than implicit.
+       //
+
+  int len = sizeof(config_optionsp)/sizeof(config_option);
+  int i;
+  config_option *opt;
+
+  for (i = 0; i<len; i++) {
+    opt = &config_optionsp[i];
+    if (opt->val_ptr) {
+      conf_reset_val(opt->val_ptr, opt->type);
+    }
+    if (!conf_set_conf_val(opt->val_ptr,
+                          opt->type,
+                          opt->def_str,
+                          opt->def_longlong,
+                          opt->def_double)) {
+                       std::ostringstream oss;
+                       oss << "error initializing g_conf value num " << i;
+                       assert(oss.str().c_str() == 0);
+    }
+
+    set_conf_name(opt);
+  }
+
+  g_conf.id = strdup("default");
+}
+
+md_config_t::~md_config_t()
+{
+  int len = sizeof(config_optionsp)/sizeof(config_option);
+  int i;
+  config_option *opt;
+
+  for (i = 0; i<len; i++) {
+    opt = &config_optionsp[i];
+    if (opt->type == OPT_STR) {
+      free(*(char **)opt->val_ptr);
+    }
+    free((void *)opt->conf_name);
+  }
+
+  delete cf;
+  cf = NULL;
+}
+
index 243e792a40ca542e180da91a3c620ec01dd438c6..3170b273865ef97ff99dbbfbaf9a5bfddbed3256 100644 (file)
@@ -44,6 +44,9 @@ enum log_to_stderr_t {
 };
 
 struct md_config_t {
+  md_config_t();
+  ~md_config_t();
+
   char *type;
   char *id;
   char *name;