]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Fix handling of CEPH_CONF
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 30 Jun 2011 20:42:48 +0000 (13:42 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 30 Jun 2011 21:43:01 +0000 (14:43 -0700)
Formerly, CEPH_CONF was not respected by libraries. But now it is.
It overrides the default when reading the config file.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/common/ceph_argparse.cc
src/common/ceph_argparse.h
src/common/config.cc
src/common/config.h
src/global/global_init.cc
src/include/ceph/libceph.h
src/libceph.cc
src/librados.cc
src/rgw/librgw.cc
src/test/confutils.cc

index a085bb9533a215ddc0cb8a652afc39857ae9f0f5..7481f91a93ef7623e16a5ee2c0c0c80af9a5ea32 100644 (file)
@@ -221,24 +221,12 @@ bool parse_ip_port_vec(const char *s, vector<entity_addr_t>& vec)
 }
 
 // The defaults for CephInitParameters
-CephInitParameters::CephInitParameters(uint32_t module_type_, const char *conf_file_)
-  : module_type(module_type_),
-    conf_file(conf_file_)
+CephInitParameters::CephInitParameters(uint32_t module_type_)
+  : module_type(module_type_)
 {
-  const char *c = getenv("CEPH_CONF");
-  if (c)
-    conf_file = c;
   name.set(module_type, "admin");
 }
 
-std::list<std::string> CephInitParameters::
-get_conf_files() const
-{
-  std::list<std::string> ret;
-  get_str_list(conf_file, ret);
-  return ret;
-}
-
 static void dashes_to_underscores(const char *input, char *output)
 {
   char c = 0;
@@ -330,11 +318,10 @@ bool ceph_argparse_witharg(std::vector<const char*> &args,
 }
 
 CephInitParameters ceph_argparse_early_args
-         (std::vector<const char*>& args, uint32_t module_type, int flags)
+         (std::vector<const char*>& args, uint32_t module_type, int flags,
+          std::string *conf_file_list)
 {
-  const char *conf = (flags & CINIT_FLAG_NO_DEFAULT_CONFIG_FILE) ?
-    "" : CEPH_CONF_FILE_DEFAULT;
-  CephInitParameters iparams(module_type, conf);
+  CephInitParameters iparams(module_type);
   std::string val;
   for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
     if (strcmp(*i, "--") == 0)
@@ -344,7 +331,7 @@ CephInitParameters ceph_argparse_early_args
       _exit(0);
     }
     else if (ceph_argparse_witharg(args, i, &val, "--conf", "-c", (char*)NULL)) {
-      iparams.conf_file = val;
+      *conf_file_list = val;
     }
     else if ((module_type != CEPH_ENTITY_TYPE_CLIENT) &&
             (ceph_argparse_witharg(args, i, &val, "-i", (char*)NULL))) {
index 8f3ce93c309856b702175f4715089704327c5352..91f9981b908f092bd651215252bfe9ed1fe692e9 100644 (file)
@@ -74,11 +74,10 @@ extern bool ceph_argparse_cmd_equals(const char *cmd, const char *opt,
 class CephInitParameters
 {
 public:
-  CephInitParameters(uint32_t module_type_, const char *conf_file_);
+  CephInitParameters(uint32_t module_type_);
   std::list<std::string> get_conf_files() const;
 
   uint32_t module_type;
-  std::string conf_file;
   EntityName name;
 };
 
@@ -98,7 +97,8 @@ bool ceph_argparse_flag(std::vector<const char*> &args,
 bool ceph_argparse_witharg(std::vector<const char*> &args,
        std::vector<const char*>::iterator &i, std::string *ret, ...);
 extern CephInitParameters ceph_argparse_early_args
-           (std::vector<const char*>& args, uint32_t module_type, int flags);
+           (std::vector<const char*>& args, uint32_t module_type, int flags,
+            std::string *conf_file_list);
 extern void generic_server_usage();
 extern void generic_client_usage();
 
index 03a08eeaa05b8d66de2a9cde84814c42db1b02c7..9dde520f0cf0470e6f5084a2c2bc23a0788e28e5 100644 (file)
@@ -490,7 +490,20 @@ remove_observer(md_config_obs_t* observer_)
 }
 
 int md_config_t::
-parse_config_files(const std::list<std::string> &conf_files,
+parse_config_files(const char *conf_files,
+                  std::deque<std::string> *parse_errors)
+{
+  if (!conf_files) {
+    const char *c = getenv("CEPH_CONF");
+    conf_files = c ? c : CEPH_CONF_FILE_DEFAULT;
+  }
+  std::list<std::string> cfl;
+  get_str_list(conf_files, cfl);
+  return parse_config_files_impl(cfl, parse_errors);
+}
+
+int md_config_t::
+parse_config_files_impl(const std::list<std::string> &conf_files,
                   std::deque<std::string> *parse_errors)
 {
   // open new conf
index af14ffa324b48f2485b73dd5d0bf8b7cce231e45..2d447e64737804bbb6b959fcde9c05766f0efa5b 100644 (file)
@@ -71,7 +71,7 @@ public:
   void remove_observer(md_config_obs_t* observer_);
 
   // Parse a config file
-  int parse_config_files(const std::list<std::string> &conf_files,
+  int parse_config_files(const char *conf_files,
                         std::deque<std::string> *parse_errors);
 
   // Absorb config settings from the environment
@@ -114,6 +114,9 @@ public:
   bool expand_meta(std::string &val) const;
 
 private:
+  int parse_config_files_impl(const std::list<std::string> &conf_files,
+                  std::deque<std::string> *parse_errors);
+
   // Private function for setting a default for a config option
   void set_val_from_default(const config_option *opt);
 
index b99bb22c262f96c5933f8998ad2e1947a11dd7e9..7edd4c57bc9fdc88da8e02caae8d59a848787f01 100644 (file)
@@ -48,20 +48,27 @@ static void output_ceph_version()
   generic_dout(0) << buf << dendl;
 }
 
+static const char* c_str_or_null(const std::string &str)
+{
+  if (str.empty())
+    return NULL;
+  return str.c_str();
+}
+
 void global_init(std::vector < const char* >& args,
               uint32_t module_type, code_environment_t code_env, int flags)
 {
   // You can only call global_init once.
   assert(!g_ceph_context);
-
-  CephInitParameters iparams =
-    ceph_argparse_early_args(args, module_type, flags);
+  std::string conf_file_list;
+  CephInitParameters iparams = ceph_argparse_early_args(args, module_type, flags,
+                                                       &conf_file_list);
   CephContext *cct = common_preinit(iparams, code_env, flags);
   global_init_set_globals(cct);
   md_config_t *conf = cct->_conf;
 
   std::deque<std::string> parse_errors;
-  int ret = conf->parse_config_files(iparams.get_conf_files(), &parse_errors);
+  int ret = conf->parse_config_files(c_str_or_null(conf_file_list), &parse_errors);
   if (ret == -EDOM) {
     dout_emergency("global_init: error parsing config file.\n");
     _exit(1);
index 597a9d9e3695d09b1b6cb5f1e0c626516c960c03..b5796f9b19d16c35a66876bf321bd0a700ce101f 100644 (file)
@@ -49,7 +49,7 @@ void ceph_shutdown(struct ceph_mount_info *cmount);
  *
  * Functions for manipulating the Ceph configuration at runtime.
  */
-int ceph_conf_read_file(struct ceph_mount_info *cmount, const char *path);
+int ceph_conf_read_file(struct ceph_mount_info *cmount, const char *path_list);
 
 void ceph_conf_parse_argv(struct ceph_mount_info *cmount, int argc, const char **argv);
 
index 7dbd7bb40b51d146c47a30d02cd0e1a7f0d81818..ca35b507157198693b162990ef1d69aea15c81c4 100644 (file)
@@ -129,19 +129,12 @@ public:
     }
   }
 
-  int conf_read_file(const char *path)
+  int conf_read_file(const char *path_list)
   {
-    if (!path)
-      path = CEPH_CONF_FILE_DEFAULT;
-
-    std::list<std::string> conf_files;
-    get_str_list(path, conf_files);
     std::deque<std::string> parse_errors;
-    int ret = cct->_conf->parse_config_files(conf_files, &parse_errors);
+    int ret = cct->_conf->parse_config_files(path_list, &parse_errors);
     if (ret)
       return ret;
-    cct->_conf->parse_env(); // environment variables override
-
     cct->_conf->apply_changes();
     complain_about_parse_errors(cct, &parse_errors);
     return 0;
@@ -222,8 +215,7 @@ extern "C" int ceph_create_with_context(struct ceph_mount_info **cmount, CephCon
 
 extern "C" int ceph_create(struct ceph_mount_info **cmount, const char * const id)
 {
-  CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT, CEPH_CONF_FILE_DEFAULT);
-  iparams.conf_file = "";
+  CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
   if (id) {
     iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
   }
index 25e56f4745b6f8698e8ffdd5f4101950cec80891..54af457e1a1c7b817d45e81a4750cb6b6b4cfdee 100644 (file)
@@ -3159,8 +3159,7 @@ librados::ObjectOperation::~ObjectOperation()
 ///////////////////////////// C API //////////////////////////////
 extern "C" int rados_create(rados_t *pcluster, const char * const id)
 {
-  CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT, CEPH_CONF_FILE_DEFAULT);
-  iparams.conf_file = "";
+  CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
   if (id) {
     iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
   }
@@ -3210,17 +3209,12 @@ extern "C" void rados_version(int *major, int *minor, int *extra)
 
 
 // -- config --
-extern "C" int rados_conf_read_file(rados_t cluster, const char *path)
+extern "C" int rados_conf_read_file(rados_t cluster, const char *path_list)
 {
-  if (!path)
-    path = CEPH_CONF_FILE_DEFAULT;
-
   librados::RadosClient *client = (librados::RadosClient *)cluster;
   md_config_t *conf = client->cct->_conf;
-  std::list<std::string> conf_files;
-  get_str_list(path, conf_files);
   std::deque<std::string> parse_errors;
-  int ret = conf->parse_config_files(conf_files, &parse_errors);
+  int ret = conf->parse_config_files(path_list, &parse_errors);
   if (ret)
     return ret;
   conf->parse_env(); // environment variables override
index 5f5bad95790391b3eef9a1d09fa49fdcd7eb3f35..e571035e6c3fa87d2e159257a327af125f4c3b0c 100644 (file)
@@ -27,8 +27,7 @@
 
 int librgw_create(librgw_t *rgw, const char * const id)
 {
-  CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT, CEPH_CONF_FILE_DEFAULT);
-  iparams.conf_file = "";
+  CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
   if (id) {
     iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
   }
index 90674b45da70cf75321948b5b4a8ada137859ea3..22ddf437342576625c5dc4af032ed5e8b25fa01e 100644 (file)
@@ -463,20 +463,18 @@ TEST(Overrides, ConfUtils) {
   std::deque<std::string> err;
   std::string override_conf_1_f(next_tempfile(override_config_1));
 
-  std::list<std::string> conf_files;
-  conf_files.push_back(override_conf_1_f);
   conf.name.set(CEPH_ENTITY_TYPE_MON, "0");
-  conf.parse_config_files(conf_files, &err);
+  conf.parse_config_files(override_conf_1_f.c_str(), &err);
   ASSERT_EQ(err.size(), 0U);
   ASSERT_EQ(conf.log_file, "global_log");
 
   conf.name.set(CEPH_ENTITY_TYPE_MDS, "a");
-  conf.parse_config_files(conf_files, &err);
+  conf.parse_config_files(override_conf_1_f.c_str(), &err);
   ASSERT_EQ(err.size(), 0U);
   ASSERT_EQ(conf.log_file, "mds_log");
 
   conf.name.set(CEPH_ENTITY_TYPE_OSD, "0");
-  conf.parse_config_files(conf_files, &err);
+  conf.parse_config_files(override_conf_1_f.c_str(), &err);
   ASSERT_EQ(err.size(), 0U);
   ASSERT_EQ(conf.log_file, "osd0_log");
 }