diff --git a/src/common/common_init.cc b/src/common/common_init.cc index 092804931be..3c823bddf5f 100644 --- a/src/common/common_init.cc +++ b/src/common/common_init.cc @@ -71,25 +71,13 @@ CephContext *common_preinit(const CephInitParameters &iparams, } #endif // #ifndef WITH_SEASTAR -void complain_about_parse_errors(CephContext *cct, - std::deque *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::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 diff --git a/src/common/common_init.h b/src/common/common_init.h index ee315e76434..175dc5df672 100644 --- a/src/common/common_init.h +++ b/src/common/common_init.h @@ -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 *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 diff --git a/src/common/config.cc b/src/common/config.cc index f3a6eebaf9f..df0bd5ac4fe 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -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); } diff --git a/src/common/config.h b/src/common/config.h index 9f88d686758..097db9c0ffb 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -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 parse_errors; + std::string parse_error; private: // This will be set to true when it is safe to start threads. diff --git a/src/common/config_proxy.h b/src/common/config_proxy.h index c587fcad60b..8fdf17a07ce 100644 --- a/src/common/config_proxy.h +++ b/src/common/config_proxy.h @@ -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}; diff --git a/src/global/global_init.cc b/src/global/global_init.cc index a4f42dd01c0..1b3b816acbe 100644 --- a/src/global/global_init.cc +++ b/src/global/global_init.cc @@ -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 @@ -349,7 +349,7 @@ global_init(const std::map *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) { diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 0f23fa8e120..0f6e84d73a4 100755 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -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; } diff --git a/src/librados/librados_c.cc b/src/librados/librados_c.cc index ea20879823f..40183c28f9c 100644 --- a/src/librados/librados_c.cc +++ b/src/librados/librados_c.cc @@ -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; } diff --git a/src/test/confutils.cc b/src/test/confutils.cc index 981232716c4..029dd5dbb43 100644 --- a/src/test/confutils.cc +++ b/src/test/confutils.cc @@ -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")); } diff --git a/src/test/librados_test_stub/LibradosTestStub.cc b/src/test/librados_test_stub/LibradosTestStub.cc index 7b7093f8571..dfc52b5e413 100644 --- a/src/test/librados_test_stub/LibradosTestStub.cc +++ b/src/test/librados_test_stub/LibradosTestStub.cc @@ -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; diff --git a/src/tools/ceph_conf.cc b/src/tools/ceph_conf.cc index d7d341481ce..9d8ad222d8f 100644 --- a/src/tools/ceph_conf.cc +++ b/src/tools/ceph_conf.cc @@ -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 diff --git a/src/tools/rbd_mirror/PoolReplayer.cc b/src/tools/rbd_mirror/PoolReplayer.cc index 7f9f224a025..c41dffaa93c 100644 --- a/src/tools/rbd_mirror/PoolReplayer.cc +++ b/src/tools/rbd_mirror/PoolReplayer.cc @@ -518,7 +518,7 @@ int PoolReplayer::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);