From: Nir Soffer <nsoffer(a)redhat.com>
In the current implementation, sanlock_register shouldn't block, but we
should not take any chance, since blocking will hang all threads in the
caller process.
It is also easier to maintain when we decouple the implementation from
the python glue layer; we don't want to modify locking in the python
binding when we we modify the underlying library.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/python/sanlock.c b/python/sanlock.c
index 0ef1174..3142b2a 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -54,6 +54,7 @@ __set_exception(int en, char *msg)
en = -en;
err_name = strerror(en);
} else {
+ /* Safe to call without releasing the GIL. */
err_name = sanlock_strerror(en);
}
@@ -213,7 +214,11 @@ py_register(PyObject *self __unused, PyObject *args)
{
int sanlockfd;
+ /* This sholdn't block, but we don't want to take any chance, as blocking
+ * hangs all threads in the caller process. */
+ Py_BEGIN_ALLOW_THREADS
sanlockfd = sanlock_register();
+ Py_END_ALLOW_THREADS
if (sanlockfd < 0) {
__set_exception(sanlockfd, "Sanlock registration failed");
--
2.9.5