mirror of
https://github.com/ceph/ceph
synced 2025-01-15 07:23:16 +00:00
src/: parser returns up to one error
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>
This commit is contained in:
parent
b128929024
commit
a19194a63d
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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};
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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"));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user