From: Adam C. Emerson Date: Thu, 5 Oct 2017 22:32:32 +0000 (-0400) Subject: config: Add templated _get_val for use in observers X-Git-Tag: v13.0.1~638^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a0a4c483bc1f4e50d5e7cde622aad01acbdec204;p=ceph.git config: Add templated _get_val for use in observers When notified by a config observer, the config lock is already held, create a _get_val template to manipulate newstyle options when notified. Signed-off-by: Adam C. Emerson --- diff --git a/src/common/config.cc b/src/common/config.cc index 564039b9c81e..4883418c03ab 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -726,8 +726,16 @@ void md_config_t::_apply_changes(std::ostream *oss) void md_config_t::call_all_observers() { std::map > obs; + // Have the scope of the lock extend to the scope of + // handle_conf_change since that function expects to be called with + // the lock held. (And the comment in config.h says that is the + // expected behavior.) + // + // An alternative might be to pass a std::unique_lock to + // handle_conf_change and have a version of get_var that can take it + // by reference and lock as appropriate. + Mutex::Locker l(lock); { - Mutex::Locker l(lock); expand_all_meta(); diff --git a/src/common/config.h b/src/common/config.h index 1e573f5e11b2..768521f9489e 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -162,6 +162,7 @@ public: int _get_val(const std::string &key, char **buf, int len) const; Option::value_t get_val_generic(const std::string &key) const; template T get_val(const std::string &key) const; + template T _get_val(const std::string &key) const; void get_all_keys(std::vector *keys) const; @@ -338,6 +339,12 @@ template T md_config_t::get_val(const std::string &key) const { return boost::apply_visitor(gtv, generic_val); } +template T md_config_t::_get_val(const std::string &key) const { + Option::value_t generic_val = this->_get_val(key); + get_typed_value_visitor gtv; + return boost::apply_visitor(gtv, generic_val); +} + inline std::ostream& operator<<(std::ostream& o, const boost::blank& ) { return o << "INVALID_CONFIG_VALUE"; }