]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
config: Add templated _get_val for use in observers
authorAdam C. Emerson <aemerson@redhat.com>
Thu, 5 Oct 2017 22:32:32 +0000 (18:32 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Sat, 7 Oct 2017 00:49:53 +0000 (20:49 -0400)
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 <aemerson@redhat.com>
src/common/config.cc
src/common/config.h

index 564039b9c81ec2e0ca016493755263891ca4a511..4883418c03ab512fee4e5646947c60fe3f12f418 100644 (file)
@@ -726,8 +726,16 @@ void md_config_t::_apply_changes(std::ostream *oss)
 void md_config_t::call_all_observers()
 {
   std::map<md_config_obs_t*,std::set<std::string> > 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();
 
index 1e573f5e11b28832ee77b3cb3b1fb5cd29a1d573..768521f9489eaa2ed8ca40bfc383f9e7d8158e2d 100644 (file)
@@ -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<typename T> T get_val(const std::string &key) const;
+  template<typename T> T _get_val(const std::string &key) const;
 
   void get_all_keys(std::vector<std::string> *keys) const;
 
@@ -338,6 +339,12 @@ template<typename T> T md_config_t::get_val(const std::string &key) const {
   return boost::apply_visitor(gtv, generic_val);
 }
 
+template<typename T> T md_config_t::_get_val(const std::string &key) const {
+  Option::value_t generic_val = this->_get_val(key);
+  get_typed_value_visitor<T> gtv;
+  return boost::apply_visitor(gtv, generic_val);
+}
+
 inline std::ostream& operator<<(std::ostream& o, const boost::blank& ) {
       return o << "INVALID_CONFIG_VALUE";
 }