From ea97a5f1d4f04f63f9a30985f725216ca88addf1 Mon Sep 17 00:00:00 2001 From: Federico Simoncelli Date: Mar 12 2012 14:49:32 +0000 Subject: python: add shared resource parameter to acquire Signed-off-by: Federico Simoncelli --- 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);