From d506f7f445cf2e8106b93989ed7f24fe3c9ec881 Mon Sep 17 00:00:00 2001 From: Federico Simoncelli Date: Mar 12 2012 14:49:32 +0000 Subject: python: release leases for other processes The python binding was lacking the support for releasing leases on behalf of other processes. Signed-off-by: Federico Simoncelli --- diff --git a/python/example.py b/python/example.py index 1f2f3a7..ef1c957 100644 --- a/python/example.py +++ b/python/example.py @@ -13,6 +13,8 @@ def main(): offset = sanlock.get_alignment(disk) + SNLK_DISKS = [(disk, offset)] + print "Registering to sanlock" fd = sanlock.register() @@ -20,16 +22,16 @@ def main(): sanlock.init_lockspace(LOCKSPACE_NAME, disk) print "Initializing '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME) - sanlock.init_resource(LOCKSPACE_NAME, RESOURCE_NAME, [(disk, offset)]) + sanlock.init_resource(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS) print "Acquiring the id '%i' on '%s'" % (HOST_ID, LOCKSPACE_NAME) sanlock.add_lockspace(LOCKSPACE_NAME, HOST_ID, disk) try: print "Acquiring '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME) - sanlock.acquire(fd, LOCKSPACE_NAME, RESOURCE_NAME, [(disk, offset)]) + sanlock.acquire(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd) print "Releasing '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME) - sanlock.release(fd, LOCKSPACE_NAME, RESOURCE_NAME, [(disk, offset)]) + sanlock.release(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd) finally: print "Releasing the id '%i' on '%s'" % (HOST_ID, LOCKSPACE_NAME) sanlock.rem_lockspace(LOCKSPACE_NAME, HOST_ID, disk) diff --git a/python/sanlock.c b/python/sanlock.c index 25791fd..cef3bff 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -452,21 +452,24 @@ exit_fail: /* release */ PyDoc_STRVAR(pydoc_release, "\ -release(fd, lockspace, resource, disks)\n\ +release(lockspace, resource, disks [, slkfd=fd, pid=owner])\n\ Release a resource lease for the current process.\n\ The disks must be in the format: [(path, offset), ... ]"); static PyObject * -py_release(PyObject *self __unused, PyObject *args) +py_release(PyObject *self __unused, PyObject *args, PyObject *keywds) { - int rv, sanlockfd; + int rv, sanlockfd = -1, pid = -1; const char *lockspace, *resource; struct sanlk_resource *res; PyObject *disks; + static char *kwlist[] = {"lockspace", "resource", "disks", "slkfd", + "pid", NULL}; + /* parse python tuple */ - if (!PyArg_ParseTuple(args, "issO!", - &sanlockfd, &lockspace, &resource, &PyList_Type, &disks)) { + if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|ii", kwlist, + &lockspace, &resource, &PyList_Type, &disks, &sanlockfd, &pid)) { return NULL; } @@ -481,7 +484,7 @@ py_release(PyObject *self __unused, PyObject *args) /* release sanlock resource (gil disabled) */ Py_BEGIN_ALLOW_THREADS - rv = sanlock_release(sanlockfd, -1, 0, 1, &res); + rv = sanlock_release(sanlockfd, pid, 0, 1, &res); Py_END_ALLOW_THREADS if (rv != 0) { @@ -527,7 +530,8 @@ sanlock_methods[] = { {"rem_lockspace", py_rem_lockspace, METH_VARARGS, pydoc_rem_lockspace}, {"acquire", (PyCFunction) py_acquire, METH_VARARGS|METH_KEYWORDS, pydoc_acquire}, - {"release", py_release, METH_VARARGS, pydoc_release}, + {"release", (PyCFunction) py_release, + METH_VARARGS|METH_KEYWORDS, pydoc_release}, {NULL, NULL, 0, NULL} };