python/example.py | 8 +++++--- python/sanlock.c | 37 ++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 16 deletions(-)
New commits: commit d506f7f445cf2e8106b93989ed7f24fe3c9ec881 Author: Federico Simoncelli fsimonce@redhat.com Date: Wed Mar 7 16:28:01 2012 +0000
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 fsimonce@redhat.com
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} };
commit ea97a5f1d4f04f63f9a30985f725216ca88addf1 Author: Federico Simoncelli fsimonce@redhat.com Date: Wed Mar 7 16:28:00 2012 +0000
python: add shared resource parameter to acquire
Signed-off-by: Federico Simoncelli fsimonce@redhat.com
diff --git a/python/sanlock.c b/python/sanlock.c index 48d75be..25791fd 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -387,26 +387,28 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args)
/* acquire */ PyDoc_STRVAR(pydoc_acquire, "\ -acquire(lockspace, resource, disks [, slkfd=fd, pid=owner])\n\ +acquire(lockspace, resource, disks [, slkfd=fd, pid=owner, shared=False])\n\ Acquire a resource lease for the current process (using the slkfd argument\n\ to specify the sanlock file descriptor) or for an other process (using the\n\ -pid argument).\n\ +pid argument). If shared is True the resource will be acquired in the shared\n\ +mode.\n\ The disks must be in the format: [(path, offset), ... ]\n");
static PyObject * py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds) { - int rv, sanlockfd = -1, pid = -1; + int rv, sanlockfd = -1, pid = -1, shared = 0; const char *lockspace, *resource; struct sanlk_resource *res; PyObject *disks;
static char *kwlist[] = {"lockspace", "resource", "disks", "slkfd", - "pid", NULL}; + "pid", "shared", NULL};
/* parse python tuple */ - if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|ii", kwlist, - &lockspace, &resource, &PyList_Type, &disks, &sanlockfd, &pid)) { + if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iii", kwlist, + &lockspace, &resource, &PyList_Type, &disks, &sanlockfd, &pid, + &shared)) { return NULL; }
@@ -425,6 +427,11 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds) strncpy(res->lockspace_name, lockspace, SANLK_NAME_LEN); strncpy(res->name, resource, SANLK_NAME_LEN);
+ /* prepare sanlock flags */ + if (shared) { + res->flags |= SANLK_RES_SHARED; + } + /* acquire sanlock resource (gil disabled) */ Py_BEGIN_ALLOW_THREADS rv = sanlock_acquire(sanlockfd, pid, 0, 1, &res, 0);