]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
config: more parse_errors into md_config_t
authorSage Weil <sage@redhat.com>
Thu, 3 Mar 2016 16:13:15 +0000 (11:13 -0500)
committerSage Weil <sage@redhat.com>
Thu, 3 Mar 2016 16:13:15 +0000 (11:13 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/config.cc
src/common/config.h
src/global/global_init.cc
src/libcephfs.cc
src/librados/librados.cc
src/test/confutils.cc
src/test/librados_test_stub/LibradosTestStub.cc

index 37758d4d2047a324e06dba77667dc1694ad2168f..d0789366393228323d7ba2b927dc90c9e686434f 100644 (file)
@@ -199,7 +199,6 @@ void md_config_t::remove_observer(md_config_obs_t* observer_)
 }
 
 int md_config_t::parse_config_files(const char *conf_files,
-                                   std::deque<std::string> *parse_errors,
                                    std::ostream *warnings,
                                    int flags)
 {
@@ -219,11 +218,10 @@ int md_config_t::parse_config_files(const char *conf_files,
   }
   std::list<std::string> cfl;
   get_str_list(conf_files, cfl);
-  return parse_config_files_impl(cfl, parse_errors, warnings);
+  return parse_config_files_impl(cfl, warnings);
 }
 
 int md_config_t::parse_config_files_impl(const std::list<std::string> &conf_files,
-                                        std::deque<std::string> *parse_errors,
                                         std::ostream *warnings)
 {
   assert(lock.is_locked());
@@ -234,7 +232,7 @@ int md_config_t::parse_config_files_impl(const std::list<std::string> &conf_file
     cf.clear();
     string fn = *c;
     expand_meta(fn, warnings);
-    int ret = cf.parse_file(fn.c_str(), parse_errors, warnings);
+    int ret = cf.parse_file(fn.c_str(), &parse_errors, warnings);
     if (ret == 0)
       break;
     else if (ret != -ENOENT)
@@ -285,15 +283,14 @@ int md_config_t::parse_config_files_impl(const std::list<std::string> &conf_file
   }
   if (!old_style_section_names.empty()) {
     ostringstream oss;
-    oss << "ERROR! old-style section name(s) found: ";
+    cerr << "ERROR! old-style section name(s) found: ";
     string sep;
     for (std::deque < std::string >::const_iterator os = old_style_section_names.begin();
         os != old_style_section_names.end(); ++os) {
-      oss << sep << *os;
+      cerr << sep << *os;
       sep = ", ";
     }
-    oss << ". Please use the new style section names that include a period.";
-    parse_errors->push_back(oss.str());
+    cerr << ". Please use the new style section names that include a period.";
   }
   return 0;
 }
@@ -1173,3 +1170,8 @@ void md_config_t::diff(
       diff->insert(make_pair(opt->name, make_pair(local_val, other_val)));
   }
 }
+
+void md_config_t::complain_about_parse_errors(CephContext *cct)
+{
+  ::complain_about_parse_errors(cct, &parse_errors);
+}
index 262dc7153bae6a315f4972910168ec84742fa75d..10d3c095cb5e74c52c3b9cdd5fcb50e0f1423de1 100644 (file)
@@ -106,7 +106,6 @@ public:
 
   // Parse a config file
   int parse_config_files(const char *conf_files,
-                        std::deque<std::string> *parse_errors,
                         std::ostream *warnings, int flags);
 
   // Absorb config settings from the environment
@@ -162,6 +161,9 @@ public:
   void diff(const md_config_t *other,
             map<string,pair<string,string> > *diff, set<string> *unknown);
 
+  /// print/log warnings/errors from parsing the config
+  void complain_about_parse_errors(CephContext *cct);
+
 private:
   void _show_config(std::ostream *out, Formatter *f);
 
@@ -176,7 +178,6 @@ private:
   int parse_injectargs(std::vector<const char*>& args,
                      std::ostream *oss);
   int parse_config_files_impl(const std::list<std::string> &conf_files,
-                             std::deque<std::string> *parse_errors,
                              std::ostream *warnings);
 
   int set_val_impl(const char *val, const config_option *opt);
@@ -197,6 +198,9 @@ private:
 
   // The configuration file we read, or NULL if we haven't read one.
   ConfFile cf;
+public:
+  std::deque<std::string> parse_errors;
+private:
 
   obs_map_t observers;
   changed_set_t changed;
index 596f0d2f4ca9a151e87f9c87a986286995ee85f3..b6b57b85b81046af528b0128fdbf3568ee8211ae 100644 (file)
@@ -79,8 +79,8 @@ void global_pre_init(std::vector < const char * > *alt_def_args,
   if (alt_def_args)
     conf->parse_argv(*alt_def_args);  // alternative default args
 
-  std::deque<std::string> parse_errors;
-  int ret = conf->parse_config_files(c_str_or_null(conf_file_list), &parse_errors, &cerr, flags);
+  int ret = conf->parse_config_files(c_str_or_null(conf_file_list),
+                                    &cerr, flags);
   if (ret == -EDOM) {
     dout_emergency("global_init: error parsing config file.\n");
     _exit(1);
@@ -108,7 +108,7 @@ void global_pre_init(std::vector < const char * > *alt_def_args,
   conf->parse_argv(args); // argv override
 
   // Now we're ready to complain about config file parse errors
-  complain_about_parse_errors(cct, &parse_errors);
+  g_conf->complain_about_parse_errors(g_ceph_context);
 }
 
 void global_init(std::vector < const char * > *alt_def_args,
index 400669abbaa8872287df0049f469ba69de121adc..dd6e91e40f8e981f620bf95cbd1f517077d5e32c 100644 (file)
@@ -173,12 +173,11 @@ public:
 
   int conf_read_file(const char *path_list)
   {
-    std::deque<std::string> parse_errors;
-    int ret = cct->_conf->parse_config_files(path_list, &parse_errors, NULL, 0);
+    int ret = cct->_conf->parse_config_files(path_list, NULL, 0);
     if (ret)
       return ret;
     cct->_conf->apply_changes(NULL);
-    complain_about_parse_errors(cct, &parse_errors);
+    cct->_conf->complain_about_parse_errors(cct);
     return 0;
   }
 
index e66d17b638aca3e91aeeeb236127be552810b9a6..e740aa4fa8cc0591ce7538488e4167d3e827696d 100644 (file)
@@ -2456,8 +2456,7 @@ extern "C" int rados_conf_read_file(rados_t cluster, const char *path_list)
   tracepoint(librados, rados_conf_read_file_enter, cluster, path_list);
   librados::RadosClient *client = (librados::RadosClient *)cluster;
   md_config_t *conf = client->cct->_conf;
-  std::deque<std::string> parse_errors;
-  int ret = conf->parse_config_files(path_list, &parse_errors, NULL, 0);
+  int ret = conf->parse_config_files(path_list, NULL, 0);
   if (ret) {
     tracepoint(librados, rados_conf_read_file_exit, ret);
     return ret;
@@ -2465,7 +2464,7 @@ extern "C" int rados_conf_read_file(rados_t cluster, const char *path_list)
   conf->parse_env(); // environment variables override
 
   conf->apply_changes(NULL);
-  complain_about_parse_errors(client->cct, &parse_errors);
+  client->cct->_conf->complain_about_parse_errors(client->cct);
   tracepoint(librados, rados_conf_read_file_exit, 0);
   return 0;
 }
index 90e8372dff0bcb6952d6ba948306f8f75c2de4da..f323c6859c65c1999b055cdbd19dd1a58715adfe 100644 (file)
@@ -471,35 +471,33 @@ TEST(ConfUtils, EscapingFiles) {
 
 TEST(ConfUtils, Overrides) {
   md_config_t conf;
-  std::deque<std::string> err;
   std::ostringstream warn;
   std::string override_conf_1_f(next_tempfile(override_config_1));
 
   conf.name.set(CEPH_ENTITY_TYPE_MON, "0");
-  conf.parse_config_files(override_conf_1_f.c_str(), &err, &warn, 0);
-  ASSERT_EQ(err.size(), 0U);
+  conf.parse_config_files(override_conf_1_f.c_str(), &warn, 0);
+  ASSERT_EQ(conf.parse_errors.size(), 0U);
   ASSERT_EQ(conf.log_file, "global_log");
 
   conf.name.set(CEPH_ENTITY_TYPE_MDS, "a");
-  conf.parse_config_files(override_conf_1_f.c_str(), &err, &warn, 0);
-  ASSERT_EQ(err.size(), 0U);
+  conf.parse_config_files(override_conf_1_f.c_str(), &warn, 0);
+  ASSERT_EQ(conf.parse_errors.size(), 0U);
   ASSERT_EQ(conf.log_file, "mds_log");
 
   conf.name.set(CEPH_ENTITY_TYPE_OSD, "0");
-  conf.parse_config_files(override_conf_1_f.c_str(), &err, &warn, 0);
-  ASSERT_EQ(err.size(), 0U);
+  conf.parse_config_files(override_conf_1_f.c_str(), &warn, 0);
+  ASSERT_EQ(conf.parse_errors.size(), 0U);
   ASSERT_EQ(conf.log_file, "osd0_log");
 }
 
 TEST(ConfUtils, DupKey) {
   md_config_t conf;
-  std::deque<std::string> err;
   std::ostringstream warn;
   std::string dup_key_config_f(next_tempfile(dup_key_config_1));
 
   conf.name.set(CEPH_ENTITY_TYPE_MDS, "a");
-  conf.parse_config_files(dup_key_config_f.c_str(), &err, &warn, 0);
-  ASSERT_EQ(err.size(), 0U);
+  conf.parse_config_files(dup_key_config_f.c_str(), &warn, 0);
+  ASSERT_EQ(conf.parse_errors.size(), 0U);
   ASSERT_EQ(conf.log_file, string("3"));
 }
 
index 99a8f444be2ded5ed1b062af1d1b0fcfca5cffbe..b2ddb0593080c8cbb54945f4256e8b297c323777 100644 (file)
@@ -153,12 +153,11 @@ extern "C" int rados_conf_read_file(rados_t cluster, const char *path) {
   librados::TestRadosClient *client =
     reinterpret_cast<librados::TestRadosClient*>(cluster);
   md_config_t *conf = client->cct()->_conf;
-  std::deque<std::string> parse_errors;
-  int ret = conf->parse_config_files(path, &parse_errors, NULL, 0);
+  int ret = conf->parse_config_files(path, NULL, 0);
   if (ret == 0) {
     conf->parse_env();
     conf->apply_changes(NULL);
-    complain_about_parse_errors(client->cct(), &parse_errors);
+    conf->complain_about_parse_errors(client->cct());
   } else if (ret == -EINVAL) {
     // ignore missing client config
     return 0;