python/sanlock.py | 4 ++--
python/sanlockmod.c | 29 +++++++++++++++--------------
2 files changed, 17 insertions(+), 16 deletions(-)
New commits:
commit d21078688dd7f14117d47976a4c1c4d6ac5de67f
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Jul 8 15:51:26 2011 +0000
python: improve error reporting
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlockmod.c b/python/sanlockmod.c
index 4bd3495..1e1c4c4 100644
--- a/python/sanlockmod.c
+++ b/python/sanlockmod.c
@@ -22,9 +22,11 @@ static PyObject *sanlockmod_exception;
static void
__set_exception(int en, char *msg)
{
+ char *err_name;
PyObject *exc_tuple;
- exc_tuple = Py_BuildValue("(is)", en, msg);
+ err_name = strerror(en);
+ exc_tuple = Py_BuildValue("(iss)", en, msg, err_name);
if (exc_tuple == NULL) {
PyErr_NoMemory();
commit c3e3958aa851c1d6abd354793c96ea1ea5c3763b
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Jul 8 15:51:25 2011 +0000
python: expose sanlock file descriptor
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlockmod.c b/python/sanlockmod.c
index 7e5f2af..4bd3495 100644
--- a/python/sanlockmod.c
+++ b/python/sanlockmod.c
@@ -14,7 +14,6 @@
#define SKERRNO(x) (-x)
-int __sanlockmod_fd = -1;
PyObject *py_module;
/* SANLock exception */
@@ -84,17 +83,17 @@ __parse_resource(char *resource, struct sanlk_resource **ret_res)
static PyObject *
py_register(PyObject *self, PyObject *args)
{
- if (__sanlockmod_fd < 0) {
- __sanlockmod_fd = sanlock_register();
- }
+ int sanlockfd;
+
+ sanlockfd = sanlock_register();
- if (__sanlockmod_fd < 0) {
- __set_exception(SKERRNO(__sanlockmod_fd),
+ if (sanlockfd < 0) {
+ __set_exception(SKERRNO(sanlockfd),
"SANLock registration failed");
return NULL;
}
- Py_RETURN_NONE;
+ return PyInt_FromLong(sanlockfd);
}
static PyObject *py_init_lockspace(PyObject *self, PyObject *args)
@@ -220,12 +219,12 @@ py_rem_lockspace(PyObject *self, PyObject *args)
static PyObject *
py_acquire(PyObject *self, PyObject *args)
{
- int rv;
+ int rv, sanlockfd;
char *resource;
struct sanlk_resource *res;
/* parse python tuple */
- if (!PyArg_ParseTuple(args, "s", &resource)) {
+ if (!PyArg_ParseTuple(args, "is", &sanlockfd, &resource)) {
return NULL;
}
@@ -236,7 +235,7 @@ py_acquire(PyObject *self, PyObject *args)
/* acquire sanlock resource (gil disabled) */
Py_BEGIN_ALLOW_THREADS
- rv = sanlock_acquire(__sanlockmod_fd, -1, 0, 1, &res, 0);
+ rv = sanlock_acquire(sanlockfd, -1, 0, 1, &res, 0);
Py_END_ALLOW_THREADS
if (rv != 0) {
@@ -255,12 +254,12 @@ exit_fail:
static PyObject *
py_release(PyObject *self, PyObject *args)
{
- int rv;
+ int rv, sanlockfd;
char *resource;
struct sanlk_resource *res;
/* parse python tuple */
- if (!PyArg_ParseTuple(args, "s", &resource)) {
+ if (!PyArg_ParseTuple(args, "is", &sanlockfd, &resource)) {
return NULL;
}
@@ -271,7 +270,7 @@ py_release(PyObject *self, PyObject *args)
/* release sanlock resource (gil disabled) */
Py_BEGIN_ALLOW_THREADS
- rv = sanlock_release(__sanlockmod_fd, -1, 0, 1, &res);
+ rv = sanlock_release(sanlockfd, -1, 0, 1, &res);
Py_END_ALLOW_THREADS
if (rv != 0) {
commit 105f7cbc96f70c68997d0d2369d5b1f35281497d
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Jul 8 15:51:24 2011 +0000
python: align num_hosts and max_hosts defaults
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.py b/python/sanlock.py
index 0909cc8..d9542c6 100644
--- a/python/sanlock.py
+++ b/python/sanlock.py
@@ -18,8 +18,8 @@ for skfun in SANLOCK_FUNCTIONS:
setattr(sys.modules[__name__], skfun, getattr(sanlockmod, skfun))
del skfun
-def init_lockspace(lockspace, max_hosts=2000, use_aio=True):
+def init_lockspace(lockspace, max_hosts=0, use_aio=True):
sanlockmod.init_lockspace(lockspace, max_hosts, 0, use_aio)
-def init_resource(resource, num_hosts, max_hosts=2000, use_aio=True):
+def init_resource(resource, num_hosts=0, max_hosts=0, use_aio=True):
sanlockmod.init_resource(resource, max_hosts, num_hosts, use_aio)