]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
src/: parser returns up to one error
authorKefu Chai <kchai@redhat.com>
Tue, 18 Jun 2019 12:59:17 +0000 (20:59 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 25 Jun 2019 07:10:07 +0000 (15:10 +0800)
since config parser bails out at seeing the first error, there is no
need to offer the interfaces to report multiple errors.

Signed-off-by: Kefu Chai <kchai@redhat.com>
12 files changed:
src/common/common_init.cc
src/common/common_init.h
src/common/config.cc
src/common/config.h
src/common/config_proxy.h
src/global/global_init.cc
src/libcephfs.cc
src/librados/librados_c.cc
src/test/confutils.cc
src/test/librados_test_stub/LibradosTestStub.cc
src/tools/ceph_conf.cc
src/tools/rbd_mirror/PoolReplayer.cc

index 092804931be0b8d40a7021687c17ed6a3ccf0b88..3c823bddf5ff07dfc3be635ef46503eab74a804a 100644 (file)
@@ -71,25 +71,13 @@ CephContext *common_preinit(const CephInitParameters &iparams,
 }
 #endif // #ifndef WITH_SEASTAR
 
-void complain_about_parse_errors(CephContext *cct,
-                                std::deque<std::string> *parse_errors)
+void complain_about_parse_error(CephContext *cct,
+                               const string& parse_error)
 {
-  if (parse_errors->empty())
+  if (parse_error.empty())
     return;
   lderr(cct) << "Errors while parsing config file!" << dendl;
-  int cur_err = 0;
-  static const int MAX_PARSE_ERRORS = 20;
-  for (std::deque<std::string>::const_iterator p = parse_errors->begin();
-       p != parse_errors->end(); ++p)
-  {
-    lderr(cct) << *p << dendl;
-    if (cur_err == MAX_PARSE_ERRORS) {
-      lderr(cct) << "Suppressed " << (parse_errors->size() - MAX_PARSE_ERRORS)
-          << " more errors." << dendl;
-      break;
-    }
-    ++cur_err;
-  }
+  lderr(cct) << parse_error << dendl;
 }
 
 #ifndef WITH_SEASTAR
index ee315e7643416001d436975642e0b7cc9ece18b5..175dc5df672a82210acbcac132fb42efb5ce9f32 100644 (file)
@@ -68,9 +68,9 @@ CephContext *common_preinit(const CephInitParameters &iparams,
                            enum code_environment_t code_env, int flags);
 #endif // #ifndef WITH_SEASTAR
 
-/* Print out some parse errors. */
-void complain_about_parse_errors(CephContext *cct,
-                                std::deque<std::string> *parse_errors);
+/* Print out some parse error. */
+void complain_about_parse_error(CephContext *cct,
+                               const std::string& parse_error);
 
 /* This function is called after you have done your last
  * fork. When you make this call, the system will initialize everything that
index f3a6eebaf9f713326c53123bb35a56cf1df4f00d..df0bd5ac4fe8d610e60eeca53638a1a5704576bd 100644 (file)
@@ -374,13 +374,11 @@ int md_config_t::parse_config_files(ConfigValues& values,
   for (c = conf_files.begin(); c != conf_files.end(); ++c) {
     cf.clear();
     string fn = *c;
-
     ostringstream oss;
     int ret = cf.parse_file(fn.c_str(), &oss);
-    if (ret == 0)
+    parse_error = oss.str();
+    if (ret == 0) {
       break;
-    if (ret) {
-      parse_errors.push_back(oss.str());
     }
     if (ret != -ENOENT)
       return ret;
@@ -1472,7 +1470,7 @@ void md_config_t::diff(
   });
 }
 
-void md_config_t::complain_about_parse_errors(CephContext *cct)
+void md_config_t::complain_about_parse_error(CephContext *cct)
 {
-  ::complain_about_parse_errors(cct, &parse_errors);
+  ::complain_about_parse_error(cct, parse_error);
 }
index 9f88d686758d237dc39e01cd845bc3e0b13ea29a..097db9c0ffb917f70b64f3196a6c9ca5d5b34b8b 100644 (file)
@@ -237,7 +237,7 @@ public:
            std::string name = {}) const;
 
   /// print/log warnings/errors from parsing the config
-  void complain_about_parse_errors(CephContext *cct);
+  void complain_about_parse_error(CephContext *cct);
 
 private:
   // we use this to avoid variable expansion loops
@@ -330,7 +330,7 @@ private:
   // The configuration file we read, or NULL if we haven't read one.
   ConfFile cf;
 public:
-  std::deque<std::string> parse_errors;
+  std::string parse_error;
 private:
 
   // This will be set to true when it is safe to start threads.
index c587fcad60b8cd1f1a7746b6b929c515725df82e..8fdf17a07ceb8c9459a193f23fcbd125e659ab85 100644 (file)
@@ -319,11 +319,11 @@ public:
     return config.parse_config_files(values, obs_mgr,
                                     conf_files, warnings, flags);
   }
-  size_t num_parse_errors() const {
-    return config.parse_errors.size();
+  bool has_parse_error() const {
+    return !config.parse_error.empty();
   }
-  void complain_about_parse_errors(CephContext *cct) {
-    return config.complain_about_parse_errors(cct);
+  void complain_about_parse_error(CephContext *cct) {
+    return config.complain_about_parse_error(cct);
   }
   void do_argv_commands() const {
     std::lock_guard l{lock};
index a4f42dd01c0a0c621c6000a5952530333d195707..1b3b816acbe99616fad74c17cbebde48643a8c87 100644 (file)
@@ -167,7 +167,7 @@ void global_pre_init(
   conf.do_argv_commands();
 
   // Now we're ready to complain about config file parse errors
-  g_conf().complain_about_parse_errors(g_ceph_context);
+  g_conf().complain_about_parse_error(g_ceph_context);
 }
 
 boost::intrusive_ptr<CephContext>
@@ -349,7 +349,7 @@ global_init(const std::map<std::string,std::string> *defaults,
   }
 
   // Now we're ready to complain about config file parse errors
-  g_conf().complain_about_parse_errors(g_ceph_context);
+  g_conf().complain_about_parse_error(g_ceph_context);
 
   // test leak checking
   if (g_conf()->debug_deliberately_leak_memory) {
index 0f23fa8e120a8350b2530e3587ea0588caa58cb2..0f6e84d73a40dae894184cd7fe105d741707840b 100755 (executable)
@@ -235,7 +235,7 @@ public:
     if (ret)
       return ret;
     cct->_conf.apply_changes(nullptr);
-    cct->_conf.complain_about_parse_errors(cct);
+    cct->_conf.complain_about_parse_error(cct);
     return 0;
   }
 
index ea20879823f6e650c2d1e66bf7e7f343f7de581b..40183c28f9ca8710e05118a7f0804f9cc992bf60 100644 (file)
@@ -244,14 +244,14 @@ extern "C" int _rados_conf_read_file(rados_t cluster, const char *path_list)
   if (ret) {
     if (warnings.tellp() > 0)
       lderr(client->cct) << warnings.str() << dendl;
-    client->cct->_conf.complain_about_parse_errors(client->cct);
+    client->cct->_conf.complain_about_parse_error(client->cct);
     tracepoint(librados, rados_conf_read_file_exit, ret);
     return ret;
   }
   conf.parse_env(client->cct->get_module_type()); // environment variables override
 
   conf.apply_changes(nullptr);
-  client->cct->_conf.complain_about_parse_errors(client->cct);
+  client->cct->_conf.complain_about_parse_error(client->cct);
   tracepoint(librados, rados_conf_read_file_exit, 0);
   return 0;
 }
index 981232716c45fd6fa0af35106b0256dd6271aa26..029dd5dbb43a1f6b09900987c5a7087f0fbc7740 100644 (file)
@@ -474,17 +474,17 @@ TEST(ConfUtils, Overrides) {
 
   conf->name.set(CEPH_ENTITY_TYPE_MON, "0");
   conf.parse_config_files(override_conf_1_f.c_str(), &warn, 0);
-  ASSERT_EQ(conf.num_parse_errors(), 0U);
+  ASSERT_FALSE(conf.has_parse_error());
   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(), &warn, 0);
-  ASSERT_EQ(conf.num_parse_errors(), 0U);
+  ASSERT_FALSE(conf.has_parse_error());
   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(), &warn, 0);
-  ASSERT_EQ(conf.num_parse_errors(), 0U);
+  ASSERT_FALSE(conf.has_parse_error());
   ASSERT_EQ(conf->log_file, "osd0_log");
 }
 
@@ -495,7 +495,7 @@ TEST(ConfUtils, DupKey) {
 
   conf->name.set(CEPH_ENTITY_TYPE_MDS, "a");
   conf.parse_config_files(dup_key_config_f.c_str(), &warn, 0);
-  ASSERT_EQ(conf.num_parse_errors(), 0U);
+  ASSERT_FALSE(conf.has_parse_error());
   ASSERT_EQ(conf->log_file, string("3"));
 }
 
index 7b7093f857158fa20d1ce2e1e65cabae6b073200..dfc52b5e413a69969ee43d56209849fcbe4e7e90 100644 (file)
@@ -168,7 +168,7 @@ extern "C" int rados_conf_read_file(rados_t cluster, const char *path) {
   if (ret == 0) {
     conf.parse_env(client->cct()->get_module_type());
     conf.apply_changes(NULL);
-    conf.complain_about_parse_errors(client->cct());
+    conf.complain_about_parse_error(client->cct());
   } else if (ret == -ENOENT) {
     // ignore missing client config
     return 0;
index d7d341481ce3af860033b4dffc73394ea9386379..9d8ad222d8f9f4bbd83ea32d1a9157b72358345e 100644 (file)
@@ -186,7 +186,7 @@ int main(int argc, const char **argv)
   };
 
   g_conf().apply_changes(nullptr);
-  g_conf().complain_about_parse_errors(g_ceph_context);
+  g_conf().complain_about_parse_error(g_ceph_context);
 
   // do not common_init_finish(); do not start threads; do not do any of thing
   // wonky things the daemon whose conf we are examining would do (like initialize
index 7f9f224a025af81d5ee57fd69f585621c950571f..c41dffaa93c1498fc811d5b8150413a8957a81c6 100644 (file)
@@ -518,7 +518,7 @@ int PoolReplayer<I>::init_rados(const std::string &cluster_name,
   // disable unnecessary librbd cache
   cct->_conf.set_val_or_die("rbd_cache", "false");
   cct->_conf.apply_changes(nullptr);
-  cct->_conf.complain_about_parse_errors(cct);
+  cct->_conf.complain_about_parse_error(cct);
 
   r = (*rados_ref)->init_with_context(cct);
   ceph_assert(r == 0);