Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
python/example.py | 3 ++-
python/sanlock.c | 19 +++++++++++++------
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/python/example.py b/python/example.py
index 28b5180..354579e 100644
--- a/python/example.py
+++ b/python/example.py
@@ -29,7 +29,8 @@ def main():
try:
print "Acquiring '%s' on '%s'" % (RESOURCE_NAME,
LOCKSPACE_NAME)
- sanlock.acquire(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd)
+ sanlock.acquire(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd,
+ version=0)
print "Releasing '%s' on '%s'" % (RESOURCE_NAME,
LOCKSPACE_NAME)
sanlock.release(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd)
finally:
diff --git a/python/sanlock.c b/python/sanlock.c
index c5999d3..79bc8d2 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -779,28 +779,29 @@ exit_fail:
/* acquire */
PyDoc_STRVAR(pydoc_acquire, "\
-acquire(lockspace, resource, disks [, slkfd=fd, pid=owner, shared=False])\n\
+acquire(lockspace, resource, disks \
+[, slkfd=fd, pid=owner, shared=False, version=0])\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). If shared is True the resource will be acquired in the shared\n\
-mode.\n\
+mode. The version is the version of the lease that must be acquired or fail.\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, shared = 0;
+ int rv, sanlockfd = -1, pid = -1, shared = 0, version = 0;
const char *lockspace, *resource;
struct sanlk_resource *res;
PyObject *disks;
static char *kwlist[] = {"lockspace", "resource",
"disks", "slkfd",
- "pid", "shared", NULL};
+ "pid", "shared", "version",
NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iii", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iiii", kwlist,
&lockspace, &resource, &PyList_Type, &disks, &sanlockfd,
&pid,
- &shared)) {
+ &shared, &version)) {
return NULL;
}
@@ -824,6 +825,12 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject
*keywds)
res->flags |= SANLK_RES_SHARED;
}
+ /* prepare the resource version */
+ if (version) {
+ res->flags |= SANLK_RES_LVER;
+ res->lver = version;
+ }
+
/* acquire sanlock resource (gil disabled) */
Py_BEGIN_ALLOW_THREADS
rv = sanlock_acquire(sanlockfd, pid, 0, 1, &res, 0);
--
1.7.1