]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: hold GIL while generating a typed option value 26445/head
authorSage Weil <sage@redhat.com>
Fri, 15 Feb 2019 00:21:38 +0000 (18:21 -0600)
committerSage Weil <sage@redhat.com>
Fri, 15 Feb 2019 13:12:09 +0000 (07:12 -0600)
Drop the GIL while looking up the module and option value.  Retake
it before calling get_typed_option_value(), where we generate the
Python objects for the value.

Fixes: http://tracker.ceph.com/issues/38123
Fixes: http://tracker.ceph.com/issues/38204
Fixes: http://tracker.ceph.com/issues/38292
Signed-off-by: Sage Weil <sage@redhat.com>
src/mgr/ActivePyModules.cc
src/mgr/BaseMgrModule.cc
src/mgr/PyModule.cc

index dca77dc60398bbb90384ab235111019968e514d8..e90d877b852b5eff95f0121d7dee2f9e0dbeb9ee 100644 (file)
@@ -529,19 +529,20 @@ PyObject *ActivePyModules::get_typed_config(
   const std::string &module_name,
   const std::string &key) const
 {
+  PyThreadState *tstate = PyEval_SaveThread();
   std::string value;
   bool found = get_config(module_name, key, &value);
   if (found) {
     PyModuleRef module = py_module_registry.get_module(module_name);
+    PyEval_RestoreThread(tstate);
     if (!module) {
         derr << "Module '" << module_name << "' is not available" << dendl;
         Py_RETURN_NONE;
     }
-
     dout(10) << __func__ << " " << key << " found: " << value << dendl;
     return module->get_typed_option_value(key, value);
   }
-
+  PyEval_RestoreThread(tstate);
   dout(4) << __func__ << " " << key << " not found " << dendl;
   Py_RETURN_NONE;
 }
index e4e0a1c388bbba756ea03cac1c7cc2a3824e97cd..eaff6b031134db774ac1861d3b852bc72040b961 100644 (file)
@@ -395,9 +395,7 @@ ceph_get_module_option_ex(BaseMgrModule *self, PyObject *args)
     derr << "Invalid args!" << dendl;
     return nullptr;
   }
-  PyThreadState *tstate = PyEval_SaveThread();
   auto pResult = self->py_modules->get_typed_config(module, what);
-  PyEval_RestoreThread(tstate);
   return pResult;
 }
 
index 2ece13be843655ea905f7322b70319cee7308791..d8c5f8eee26eac1aef0fa57fdcf78b7f3ab3ccac 100644 (file)
@@ -622,6 +622,8 @@ bool PyModule::is_option(const std::string &option_name)
 PyObject *PyModule::get_typed_option_value(const std::string& name,
                                           const std::string& value)
 {
+  // we don't need to hold a lock here because these MODULE_OPTIONS
+  // are set up exactly once during startup.
   auto p = options.find(name);
   if (p != options.end()) {
     switch (p->second.type) {