From cae5939ab7cdec189fc34f0179da8b92255db51f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 21 May 2021 18:49:33 -0400 Subject: [PATCH] common/config: track the path to the conf file we loaded Signed-off-by: Sage Weil (cherry picked from commit 340c799bf924d61b355abb9c5e3e34b66634eb45) --- src/common/config.cc | 7 +++---- src/common/config.h | 5 +++++ src/common/config_proxy.h | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/common/config.cc b/src/common/config.cc index b110e99772715..4916858676675 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -361,7 +361,6 @@ int md_config_t::parse_config_files(ConfigValues& values, values.cluster = get_cluster_name(nullptr); } // open new conf - string conffile; for (auto& fn : get_conffile_paths(values, conf_files_str, warnings, flags)) { bufferlist bl; std::string error; @@ -373,7 +372,7 @@ int md_config_t::parse_config_files(ConfigValues& values, int ret = parse_buffer(values, tracker, bl.c_str(), bl.length(), &oss); if (ret == 0) { parse_error.clear(); - conffile = fn; + conf_path = fn; break; } parse_error = oss.str(); @@ -382,11 +381,11 @@ int md_config_t::parse_config_files(ConfigValues& values, } } // it must have been all ENOENTs, that's the only way we got here - if (conffile.empty()) { + if (conf_path.empty()) { return -ENOENT; } if (values.cluster.empty()) { - values.cluster = get_cluster_name(conffile.c_str()); + values.cluster = get_cluster_name(conf_path.c_str()); } update_legacy_vals(values); return 0; diff --git a/src/common/config.h b/src/common/config.h index bb3410e617d15..ef7d5b34fdc6b 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -319,10 +319,15 @@ public: // for global_init const char *conf_files, std::ostream *warnings, int flags) const; + + const std::string& get_conf_path() const { + return conf_path; + } private: static std::string get_cluster_name(const char* conffile_path); // The configuration file we read, or NULL if we haven't read one. ConfFile cf; + std::string conf_path; public: std::string parse_error; private: diff --git a/src/common/config_proxy.h b/src/common/config_proxy.h index 0cf53935241ac..cb30a2d7f1fa2 100644 --- a/src/common/config_proxy.h +++ b/src/common/config_proxy.h @@ -341,6 +341,9 @@ public: std::lock_guard l{lock}; config.get_defaults_bl(values, bl); } + const std::string& get_conf_path() const { + return config.get_conf_path(); + } }; } -- 2.39.5