]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: call config_notify method when mgr's config has changed
authorSage Weil <sage@redhat.com>
Sat, 17 Nov 2018 13:15:19 +0000 (07:15 -0600)
committerSage Weil <sage@redhat.com>
Sat, 17 Nov 2018 13:15:19 +0000 (07:15 -0600)
This provides a hook for the module to refresh any config values it has
cached in module-local variables.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mgr/ActivePyModule.cc
src/mgr/ActivePyModule.h
src/mgr/ActivePyModules.cc
src/mgr/ActivePyModules.h
src/mgr/MgrStandby.cc
src/mgr/PyModuleRegistry.cc
src/mgr/PyModuleRegistry.h
src/pybind/mgr/mgr_module.py

index d8a416bfde578af3267b4ef5e6f3b8c0d251b94e..4d07222b7d7fe2471d05ad0dcc5da161f3dff934 100644 (file)
@@ -155,7 +155,17 @@ PyObject *ActivePyModule::dispatch_remote(
   return remoteResult;
 }
 
-
+void ActivePyModule::config_notify()
+{
+  Gil gil(py_module->pMyThreadState, true);
+  dout(20) << "Calling " << py_module->get_name() << ".config_notify..."
+          << dendl;
+  auto remoteResult = PyObject_CallMethod(pClassInstance, "config_notify",
+                                         (char*)NULL);
+  if (remoteResult != nullptr) {
+    Py_DECREF(remoteResult);
+  }
+}
 
 int ActivePyModule::handle_command(
   const cmdmap_t &cmdmap,
index 149d297faf13ef37e2872dc6eb43569dcad5d903..c3780269ee047bc6d1f0f0ff4f15a164dde82e4e 100644 (file)
@@ -76,6 +76,7 @@ public:
     return changed;
   }
   void get_health_checks(health_check_map_t *checks);
+  void config_notify();
 
   void set_uri(const std::string &str)
   {
index 81dbe30705ce5ef3d16aa58b360a8260de2213e3..e8fcf9fa725e0a1a87120e0f6ed0d3ebd96937f9 100644 (file)
@@ -880,6 +880,19 @@ void ActivePyModules::get_health_checks(health_check_map_t *checks)
   }
 }
 
+void ActivePyModules::config_notify()
+{
+  std::lock_guard l(lock);
+  for (auto& i : modules) {
+    auto module = i.second.get();
+    // Send all python calls down a Finisher to avoid blocking
+    // C++ code, and avoid any potential lock cycles.
+    finisher.queue(new FunctionContext([module](int r){
+                                        module->config_notify();
+                                      }));
+  }
+}
+
 void ActivePyModules::set_uri(const std::string& module_name,
                         const std::string &uri)
 {
index ae834039717db663519f8ca91b66f52564c6fdde..bccf821aee0b8ae490538c63a1ff73124a49a3ad 100644 (file)
@@ -111,6 +111,8 @@ public:
                         health_check_map_t&& checks);
   void get_health_checks(health_check_map_t *checks);
 
+  void config_notify();
+
   void set_uri(const std::string& module_name, const std::string &uri);
 
   int handle_command(
index 9265c4ff1d5ef4f654075d592cebd59ba89ec731..70e504c701001919c0511445df6b30ca2e773560 100644 (file)
@@ -138,6 +138,9 @@ int MgrStandby::init()
       }
       return false;
     });
+  monc.register_config_notify_callback([this]() {
+      py_module_registry.handle_config_notify();
+    });
   dout(4) << "Registered monc callback" << dendl;
 
   int r = monc.init();
index 87bf6a1d5321675309ec287a40da4587246ad597..d7cea7fddedc500207778d5915e618c5e0668861 100644 (file)
@@ -422,6 +422,14 @@ void PyModuleRegistry::handle_config(const std::string &k, const std::string &v)
   }
 }
 
+void PyModuleRegistry::handle_config_notify()
+{
+  std::lock_guard l(lock);
+  if (active_modules) {
+    active_modules->config_notify();
+  }
+}
+
 void PyModuleRegistry::upgrade_config(
     MonClient *monc,
     const std::map<std::string, std::string> &old_config)
index d0cbe1881a9ce0e61a822d0bc9ef3d01a695b1ec..8c46ab2923dc0451903984ce136a576bc656efc7 100644 (file)
@@ -61,6 +61,7 @@ private:
 
 public:
   void handle_config(const std::string &k, const std::string &v);
+  void handle_config_notify();
 
   /**
    * Get references to all modules (whether they have loaded and/or
index 3c9510fbdabb7c36e1bd7ecf37ce914cb6ddce1f..a657515368d200508362feb5ac980a26efc08765 100644 (file)
@@ -349,6 +349,14 @@ class MgrModule(ceph_module.BaseMgrModule):
         """
         pass
 
+    def config_notify(self):
+        """
+        Called by the ceph-mgr service to notify the Python plugin
+        that the configuration may have changed.  Modules will want to
+        refresh any configuration values stored in config variables.
+        """
+        pass
+
     def serve(self):
         """
         Called by the ceph-mgr service to start any server that