From: Kefu Chai Date: Thu, 30 Jul 2020 06:00:32 +0000 (+0800) Subject: common/config: extract check_old_style_section_names() X-Git-Tag: v16.1.0~1497^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=129658b5f9b19aa39bd8399cdfe42e21de2a1d33;p=ceph.git common/config: extract check_old_style_section_names() extract check_old_style_section_names() out from md_config_t::parse_config_files() into ConfFile class. for two reasons: * so it can be reused * for smaller md_config_t::parse_config_files(), hence better readability Signed-off-by: Kefu Chai --- diff --git a/src/common/ConfUtils.cc b/src/common/ConfUtils.cc index 70367c093153..ab41e9ead647 100644 --- a/src/common/ConfUtils.cc +++ b/src/common/ConfUtils.cc @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -303,6 +304,27 @@ std::string ConfFile::normalize_key_name(std::string_view key) return k; } +void ConfFile::check_old_style_section_names(const std::vector& prefixes, + std::ostream& os) +{ + // Warn about section names that look like old-style section names + std::vector old_style_section_names; + for (auto& [name, section] : *this) { + for (auto& prefix : prefixes) { + if (name.find(prefix) == 0 && name.size() > 3 && name[3] != '.') { + old_style_section_names.push_back(name); + } + } + } + if (!old_style_section_names.empty()) { + os << "ERROR! old-style section name(s) found: "; + std::copy(std::begin(old_style_section_names), + std::end(old_style_section_names), + std::experimental::make_ostream_joiner(os, ", ")); + os << ". Please use the new style section names that include a period."; + } +} + std::ostream &operator<<(std::ostream &oss, const ConfFile &cf) { for (auto& [name, section] : cf) { diff --git a/src/common/ConfUtils.h b/src/common/ConfUtils.h index 80dd8df86629..1541d371d7bc 100644 --- a/src/common/ConfUtils.h +++ b/src/common/ConfUtils.h @@ -73,6 +73,13 @@ public: int read(const std::string& section, std::string_view key, std::string &val) const; static std::string normalize_key_name(std::string_view key); + // print warnings to os if any old-style section name is found + // + // consider a section name as old-style name if it starts with any of the + // given prefixes, but does not follow with a "." + void check_old_style_section_names(const std::vector& prefixes, + std::ostream& os); + private: bool load_from_buffer(std::string_view buf, std::ostream* warning); }; diff --git a/src/common/config.cc b/src/common/config.cc index fc52433be40a..2a5eeed0f913 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -401,29 +401,8 @@ int md_config_t::parse_config_files(ConfigValues& values, } } } - - // Warn about section names that look like old-style section names - std::deque < std::string > old_style_section_names; - for (auto& [name, section] : cf) { - if (((name.find("mds") == 0) || (name.find("mon") == 0) || - (name.find("osd") == 0)) && (name.size() > 3) && (name[3] != '.')) { - old_style_section_names.push_back(name); - } - } - if (!old_style_section_names.empty()) { - ostringstream oss; - 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) { - cerr << sep << *os; - sep = ", "; - } - cerr << ". Please use the new style section names that include a period."; - } - + cf.check_old_style_section_names({"mds", "mon", "osd"}, cerr); update_legacy_vals(values); - return 0; }