From 94486a9fb6827157bee2d2483f20222126083b22 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 1 Mar 2019 11:00:55 -0600 Subject: [PATCH] mgr/BaseMgrModule: drop GIL for ceph_send_command Otherwise, we can easily deadlock, since other bits of the code hold the objecter lock and then take the GIL. Fixes: http://tracker.ceph.com/issues/38537 Signed-off-by: Sage Weil --- src/mgr/BaseMgrModule.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index 9976733c9267..f7aff7fe07bd 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -139,6 +139,9 @@ ceph_send_command(BaseMgrModule *self, PyObject *args) MonCommandCompletion *command_c = new MonCommandCompletion(self->py_modules, completion, tag, PyThreadState_Get()); + + PyThreadState *tstate = PyEval_SaveThread(); + if (std::string(type) == "mon") { // Wait for the latest OSDMap after each command we send to @@ -170,6 +173,7 @@ ceph_send_command(BaseMgrModule *self, PyObject *args) delete command_c; string msg("invalid osd_id: "); msg.append("\"").append(name).append("\""); + PyEval_RestoreThread(tstate); PyErr_SetString(PyExc_ValueError, msg.c_str()); return nullptr; } @@ -194,6 +198,7 @@ ceph_send_command(BaseMgrModule *self, PyObject *args) if (r != 0) { string msg("failed to send command to mds: "); msg.append(cpp_strerror(r)); + PyEval_RestoreThread(tstate); PyErr_SetString(PyExc_RuntimeError, msg.c_str()); return nullptr; } @@ -203,6 +208,7 @@ ceph_send_command(BaseMgrModule *self, PyObject *args) delete command_c; string msg("invalid pgid: "); msg.append("\"").append(name).append("\""); + PyEval_RestoreThread(tstate); PyErr_SetString(PyExc_ValueError, msg.c_str()); return nullptr; } @@ -216,15 +222,18 @@ ceph_send_command(BaseMgrModule *self, PyObject *args) &command_c->outbl, &command_c->outs, command_c); + PyEval_RestoreThread(tstate); return nullptr; } else { delete command_c; string msg("unknown service type: "); msg.append(type); + PyEval_RestoreThread(tstate); PyErr_SetString(PyExc_ValueError, msg.c_str()); return nullptr; } + PyEval_RestoreThread(tstate); Py_RETURN_NONE; } -- 2.47.3