From c4e2965a4b83f39927e1cfc47ff6941cac76afb7 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 14 Feb 2019 18:21:38 -0600 Subject: [PATCH] mgr: hold GIL while generating a typed option value 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 --- src/mgr/ActivePyModules.cc | 5 +++-- src/mgr/BaseMgrModule.cc | 2 -- src/mgr/PyModule.cc | 2 ++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index dca77dc60398..e90d877b852b 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -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; } diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index e4e0a1c388bb..eaff6b031134 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -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; } diff --git a/src/mgr/PyModule.cc b/src/mgr/PyModule.cc index 2ece13be8436..d8c5f8eee26e 100644 --- a/src/mgr/PyModule.cc +++ b/src/mgr/PyModule.cc @@ -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) { -- 2.47.3