python/example.py | 7 ++++---
python/sanlock.c | 27 +++++++++++++++++++++------
2 files changed, 25 insertions(+), 9 deletions(-)
New commits:
commit 986362473b2dc493113dbfa75a88d7669a9c7500
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Wed Apr 10 12:09:45 2013 -0400
python: return lease version in read_resource
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index 888e3b6..7d39deb 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -461,6 +461,14 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (rv != 0)
goto exit_fail;
+ /* fill the dictionary information: version */
+ if ((rs_entry = PyInt_FromLong(rs->lver)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(rs_info, "version", rs_entry);
+ Py_DECREF(rs_entry);
+ if (rv != 0)
+ goto exit_fail;
+
/* success */
free(rs);
return rs_info;
commit 0ce413a53c768b147e0d0b97717e5e7f94479bdf
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Wed Apr 10 12:09:44 2013 -0400
python: add the versioning support to acquire
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
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 750157f..888e3b6 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);
commit 3e1795789a87625bbfbf02e1e83d8bf2db85a51e
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Wed Apr 10 12:09:43 2013 -0400
python: use the write commands in example.py
The init_lockspace/resource commands have been obsoleted, the new ones
are write_lockspace/resource.
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/example.py b/python/example.py
index ef1c957..28b5180 100644
--- a/python/example.py
+++ b/python/example.py
@@ -19,10 +19,10 @@ def main():
fd = sanlock.register()
print "Initializing '%s'" % (LOCKSPACE_NAME,)
- sanlock.init_lockspace(LOCKSPACE_NAME, disk)
+ sanlock.write_lockspace(LOCKSPACE_NAME, disk)
print "Initializing '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME)
- sanlock.init_resource(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS)
+ sanlock.write_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)